/** * main: Starts with an RPTable of 10 resources, multiple rdrs * on some resources. Remove resource. Check if resource was removed * searching for it in sequence. If not fail, else passed test. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); SaHpiRptEntryT *tmpentry = NULL; guint i = 0; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, rdrs + i, NULL,0)) return 1; } for (; i < 7; i++) { if (oh_add_rdr(rptable, rptentries[9].ResourceId, rdrs + i, NULL,0)) return 1; } oh_remove_resource(rptable, rptentries[0].ResourceId); for (tmpentry = oh_get_resource_by_id(rptable, SAHPI_FIRST_ENTRY); tmpentry; tmpentry = oh_get_resource_next(rptable, tmpentry->ResourceId)) { if (tmpentry->ResourceId == rptentries[0].ResourceId) return 1; } return 0; }
/** * main: Starts with an RPTable of 10 resources (one with data), adds 5 rdr * to first resource and 2 to the last one. * Invokes oh_flush on the table. * Should return without crashing and there should be no resources left * in the table. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); guint i; gchar *data = "My data."; if (oh_add_resource(rptable, rptentries, data, 1)) return 1; for (i = 1; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, rdrs + i, NULL, 0)) return 1; } for (; i < 7; i++) { if (oh_add_rdr(rptable, rptentries[9].ResourceId, rdrs + i, NULL, 0)) return 1; } oh_flush_rpt(rptable); if (oh_get_resource_by_id(rptable, SAHPI_FIRST_ENTRY)) return 1; return 0; }
static void AddInventoryDataEvent( cIpmiEntity *ent, cIpmiFru *fru, const SaHpiRptEntryT &resource ) { struct oh_event *e; e = (oh_event *)g_malloc0( sizeof( struct oh_event ) ); if ( !e ) { IpmiLog( "Out of space !\n" ); return; } memset( e, 0, sizeof( struct oh_event ) ); e->type = oh_event::OH_ET_RDR; AddFruEventRdr( fru, e->u.rdr_event.rdr, resource ); // SaHpiResourceIdT rid = oh_uid_lookup( &e->u.rdr_event.rdr.Entity ); oh_add_rdr( ent->Domain()->GetHandler()->rptcache, resource.ResourceId, &e->u.rdr_event.rdr, fru, 1); // assign the hpi record id to fru, so we can find // the rdr for a given fru. // the id comes from oh_add_rdr. fru->m_record_id = e->u.rdr_event.rdr.RecordId; ent->Domain()->AddHpiEvent( e ); }
/** * main: Starts with an RPTable of 10 resources, adds 5 rdr * to first resource. Fetches sensors ++in sequence by record id and compares * with original. A failed comparison means the test failed, * otherwise the test passed. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); SaHpiRdrT *tmprdr = NULL; guint i = 0; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, sensors + i, NULL,0)) return 1; } for (i = 0, tmprdr = oh_get_rdr_by_id(rptable, SAHPI_FIRST_ENTRY, SAHPI_FIRST_ENTRY); tmprdr; tmprdr = oh_get_rdr_next(rptable, SAHPI_FIRST_ENTRY, tmprdr->RecordId)) { if (memcmp(sensors + (i++), tmprdr, sizeof(SaHpiRdrT))) return 1; } return 0; }
/** * main: Starts with an RPTable of 10 resources, adds 1 rdr * to first resource. Fetches rdr by its type and num and compares * with original. A failed comparison means the test failed, * otherwise the test passed. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); SaHpiEntryIdT record_id; SaHpiRdrT *tmprdr = NULL; guint i = 0; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, sensors, NULL,0)) return 1; record_id = get_rdr_uid(sensors[0].RdrType, sensors[0].RdrTypeUnion.SensorRec.Num); sensors[0].RecordId = record_id; tmprdr = oh_get_rdr_by_type(rptable, SAHPI_FIRST_ENTRY, sensors[0].RdrType, sensors[0].RdrTypeUnion.SensorRec.Num); if (!tmprdr || memcmp(sensors, tmprdr, sizeof(SaHpiRdrT))) return 1; return 0; }
/* * add_alarm_rdr */ static void add_alarm_rdr( char *name, int num, SaHpiResourceIdT rptid, SaHpiEntityPathT parent_ent, ipmi_control_id_t *control_id, struct oh_handler_state *handler) { SaHpiRdrT rdr_temp; SaHpiRdrT *rdr; rdr = &rdr_temp; rdr->RecordId = 0; rdr->RdrType = SAHPI_CTRL_RDR; rdr->Entity = parent_ent; rdr->IdString.DataType = SAHPI_TL_TYPE_ASCII6; rdr->IdString.Language = SAHPI_LANG_ENGLISH; rdr->IdString.DataLength = strlen(name); memcpy(rdr->IdString.Data, name, strlen(name)); rdr->RdrTypeUnion.CtrlRec.Num = num; rdr->RdrTypeUnion.CtrlRec.Type = SAHPI_CTRL_TYPE_DIGITAL; rdr->RdrTypeUnion.CtrlRec.OutputType = SAHPI_CTRL_LED; rdr->RdrTypeUnion.CtrlRec.Oem = OEM_ALARM_BASE + num; oh_add_rdr(handler->rptcache, rptid, rdr, control_id, 1); dbg("add_alarm_rdr: %s\n",name); }
static void add_control_event(ipmi_entity_t *ent, ipmi_control_t *control, struct oh_handler_state *handler, SaHpiEntityPathT parent_ep, SaHpiResourceIdT rid) { ipmi_control_id_t *control_id; struct oh_event *e; control_id = malloc(sizeof(*control_id)); if (!control_id) { dbg("Out of memory"); return; } *control_id = ipmi_control_convert_to_id(control); e = malloc(sizeof(*e)); if (!e) { free(control_id); dbg("Out of space"); return; } memset(e, 0, sizeof(*e)); e->type = OH_ET_RDR; add_control_event_rdr(control, &e->u.rdr_event.rdr, parent_ep, rid); rid = oh_uid_lookup(&e->u.rdr_event.rdr.Entity); oh_add_rdr(handler->rptcache, rid, &e->u.rdr_event.rdr, control_id, 0); }
// assumptions about the input SaHpiRdrT *data entry // - all fields are assumed to have valid values // - no checking of the data is performed // assuptions about the input *privdata entry // - no checking of the data is performed SaErrorT sim_inject_rdr(struct oh_handler_state *state, struct oh_event *ohe, SaHpiRdrT *rdr, void *data) { SaErrorT rc; SaHpiResourceIdT rid; /* check arguments */ if (state == NULL || ohe == NULL || rdr == NULL) { return SA_ERR_HPI_INVALID_PARAMS; } rid = ohe->resource.ResourceId; /* perform the injection */ dbg("Injecting rdr for ResourceId %d", rid); rc = oh_add_rdr(state->rptcache, rid, rdr, data, 0); if (rc) { err("Error %s injecting rdr for ResourceId %d", oh_lookup_error(rc), rid); return rc; } /* now add rdr to event */ ohe->rdrs = g_slist_append(ohe->rdrs, (void *)rdr); return SA_OK; }
/** * snmp_bc_discover_inventory: * @handler: Pointer to handler's data. * @inventory_array: Pointer to resource's static inventory data array. * @res_oh_event: Pointer to resource's event structure. * * Discovers resource's available inventory data records. * * Return values: * Adds inventory RDRs to internal Infra-structure queues - normal case * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory **/ SaErrorT snmp_bc_discover_inventories(struct oh_handler_state *handle, struct snmp_bc_inventory *inventory_array, struct oh_event *res_oh_event) { int i; SaHpiBoolT valid_idr; SaErrorT err; struct oh_event *e; struct snmp_bc_hnd *custom_handle; struct InventoryInfo *inventory_info_ptr; custom_handle = (struct snmp_bc_hnd *)handle->data; /* Assumming OidManufacturer is defined and determines readable of other VPD */ for (i=0; inventory_array[i].inventory_info.mib.oid.OidManufacturer != NULL; i++) { e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e == NULL) { dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } valid_idr = rdr_exists(custom_handle, &(res_oh_event->u.res_event.entry.ResourceEntity), 0, inventory_array[i].inventory_info.mib.oid.OidManufacturer, 0, 0); /* Add inventory RDR, if inventory can be read */ if (valid_idr) { e->type = OH_ET_RDR; e->did = oh_get_default_domain_id(); e->u.rdr_event.parent = res_oh_event->u.res_event.entry.ResourceId; e->u.rdr_event.rdr.RdrType = SAHPI_INVENTORY_RDR; e->u.rdr_event.rdr.Entity = res_oh_event->u.res_event.entry.ResourceEntity; e->u.rdr_event.rdr.RdrTypeUnion.InventoryRec = inventory_array[i].inventory; oh_init_textbuffer(&(e->u.rdr_event.rdr.IdString)); oh_append_textbuffer(&(e->u.rdr_event.rdr.IdString), inventory_array[i].comment); trace("Discovered inventory: %s.", e->u.rdr_event.rdr.IdString.Data); inventory_info_ptr = g_memdup(&(inventory_array[i].inventory_info), sizeof(struct InventoryInfo)); err = oh_add_rdr(custom_handle->tmpcache, res_oh_event->u.res_event.entry.ResourceId, &(e->u.rdr_event.rdr), inventory_info_ptr, 0); if (err) { dbg("Cannot add RDR. Error=%s.", oh_lookup_error(err)); g_free(e); } else { custom_handle->tmpqueue = g_slist_append(custom_handle->tmpqueue, e); } } else { g_free(e); } } return(SA_OK); }
/** * snmp_bc_discover_controls: * @handler: Pointer to handler's data. * @control_array: Pointer to resource's static control data array. * @res_oh_event: Pointer to resource's event structure. * * Discovers resource's available controls. * * Return values: * Adds control RDRs to internal Infra-structure queues - normal case * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory **/ SaErrorT snmp_bc_discover_controls(struct oh_handler_state *handle, struct snmp_bc_control *control_array, struct oh_event *res_oh_event) { int i; SaErrorT err; SaHpiBoolT valid_control; SaHpiRdrT *rdrptr; struct snmp_bc_hnd *custom_handle; struct ControlInfo *control_info_ptr; custom_handle = (struct snmp_bc_hnd *)handle->data; for (i=0; control_array[i].index != 0; i++) { rdrptr = (SaHpiRdrT *)g_malloc0(sizeof(SaHpiRdrT)); if (rdrptr == NULL) { dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } valid_control = rdr_exists(custom_handle, &(res_oh_event->resource.ResourceEntity), control_array[i].control_info.mib.loc_offset, control_array[i].control_info.mib.oid, control_array[i].control_info.mib.not_avail_indicator_num, control_array[i].control_info.mib.write_only); /* Add control RDR, if control can be read */ if (valid_control) { rdrptr->RdrType = SAHPI_CTRL_RDR; rdrptr->Entity = res_oh_event->resource.ResourceEntity; rdrptr->RdrTypeUnion.CtrlRec = control_array[i].control; oh_init_textbuffer(&(rdrptr->IdString)); oh_append_textbuffer(&(rdrptr->IdString), control_array[i].comment); trace("Discovered control: %s.", rdrptr->IdString.Data); control_info_ptr = g_memdup(&(control_array[i].control_info), sizeof(struct ControlInfo)); err = oh_add_rdr(handle->rptcache, res_oh_event->resource.ResourceId, rdrptr, control_info_ptr, 0); if (err) { dbg("Cannot add RDR. Error=%s.", oh_lookup_error(err)); g_free(rdrptr); } else { res_oh_event->rdrs = g_slist_append(res_oh_event->rdrs, rdrptr); } } else { g_free(rdrptr); } } return(SA_OK); }
/** * snmp_bc_discover_controls: * @handler: Pointer to handler's data. * @control_array: Pointer to resource's static control data array. * @res_oh_event: Pointer to resource's event structure. * * Discovers resource's available controls. * * Return values: * Adds control RDRs to internal Infra-structure queues - normal case * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory **/ SaErrorT snmp_bc_discover_controls(struct oh_handler_state *handle, struct snmp_bc_control *control_array, struct oh_event *res_oh_event) { int i; SaErrorT err; SaHpiBoolT valid_control; struct oh_event *e; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; struct ControlInfo *control_info_ptr; for (i=0; control_array[i].control.Num != 0; i++) { e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e == NULL) { dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } valid_control = rdr_exists(custom_handle, &(res_oh_event->u.res_event.entry.ResourceEntity), control_array[i].control_info.mib.oid, control_array[i].control_info.mib.not_avail_indicator_num, control_array[i].control_info.mib.write_only); /* Add control RDR, if control can be read */ if (valid_control) { e->type = OH_ET_RDR; e->did = oh_get_default_domain_id(); e->u.rdr_event.parent = res_oh_event->u.res_event.entry.ResourceId; e->u.rdr_event.rdr.RdrType = SAHPI_CTRL_RDR; e->u.rdr_event.rdr.Entity = res_oh_event->u.res_event.entry.ResourceEntity; e->u.rdr_event.rdr.RdrTypeUnion.CtrlRec = control_array[i].control; oh_init_textbuffer(&(e->u.rdr_event.rdr.IdString)); oh_append_textbuffer(&(e->u.rdr_event.rdr.IdString), control_array[i].comment); trace("Discovered control: %s.", e->u.rdr_event.rdr.IdString.Data); control_info_ptr = g_memdup(&(control_array[i].control_info), sizeof(struct ControlInfo)); err = oh_add_rdr(custom_handle->tmpcache, res_oh_event->u.res_event.entry.ResourceId, &(e->u.rdr_event.rdr), control_info_ptr, 0); if (err) { dbg("Cannot add RDR. Error=%s.", oh_lookup_error(err)); g_free(e); } else { custom_handle->tmpqueue = g_slist_append(custom_handle->tmpqueue, e); } } else { g_free(e); } } return(SA_OK); }
/* * add_alarm_rdr */ static void add_alarm_rdr(char *name, int num, SaHpiResourceIdT rptid, SaHpiEntityPathT parent_ent, SaHpiCtrlDefaultModeT *def_mode, SaHpiBoolT wo, ipmi_control_id_t *control_id, struct oh_handler_state *handler) { SaHpiRdrT rdr_temp; SaHpiRdrT *rdr; int name_len; struct ohoi_control_info *ctrl_info; ctrl_info = malloc(sizeof(struct ohoi_control_info)); if (!ctrl_info) { dbg("Out of memory"); return; } ctrl_info->type = OHOI_CTRL_ORIGINAL; ctrl_info->info.orig_ctrl_info.ctrl_id = *control_id; ctrl_info->mode = SAHPI_CTRL_MODE_AUTO; ctrl_info->ohoii.get_control_state = orig_get_control_state; ctrl_info->ohoii.set_control_state = orig_set_control_state; rdr = &rdr_temp; rdr->RecordId = 0; rdr->RdrType = SAHPI_CTRL_RDR; rdr->Entity = parent_ent; name_len = strlen(name); if (name_len >= SAHPI_MAX_TEXT_BUFFER_LENGTH) name_len = SAHPI_MAX_TEXT_BUFFER_LENGTH - 1; rdr->IdString.DataType = SAHPI_TL_TYPE_TEXT; rdr->IdString.Language = SAHPI_LANG_ENGLISH; rdr->IdString.DataLength = strlen(name); memset(rdr->IdString.Data, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH); memcpy(rdr->IdString.Data, name, strlen(name)); rdr->RdrTypeUnion.CtrlRec.Num = num; rdr->RdrTypeUnion.CtrlRec.Type = SAHPI_CTRL_TYPE_DIGITAL; rdr->RdrTypeUnion.CtrlRec.TypeUnion.Digital.Default = SAHPI_CTRL_STATE_OFF; rdr->RdrTypeUnion.CtrlRec.OutputType = SAHPI_CTRL_LED; rdr->RdrTypeUnion.CtrlRec.Oem = OEM_ALARM_BASE + num; /* FIXME: OpenIPMI does not provide a reading */ rdr->RdrTypeUnion.CtrlRec.WriteOnly = wo; rdr->RdrTypeUnion.CtrlRec.DefaultMode.Mode = def_mode->Mode; rdr->RdrTypeUnion.CtrlRec.DefaultMode.ReadOnly = def_mode->ReadOnly; if(oh_add_rdr(handler->rptcache, rptid, rdr, ctrl_info, 1)) { dbg("couldn't add alarm control"); free(ctrl_info); return; } trace_ipmi("add_alarm_rdr: %s\n",name); }
/** * snmp_bc_discover_inventory: * @handler: Pointer to handler's data. * @inventory_array: Pointer to resource's static inventory data array. * @res_oh_event: Pointer to resource's event structure. * * Discovers resource's available inventory data records. * * Return values: * Adds inventory RDRs to internal Infra-structure queues - normal case * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory **/ SaErrorT snmp_bc_discover_inventories(struct oh_handler_state *handle, struct snmp_bc_inventory *inventory_array, struct oh_event *res_oh_event) { int i; SaHpiBoolT valid_idr; SaErrorT err; SaHpiRdrT *rdrptr; struct snmp_bc_hnd *custom_handle; struct InventoryInfo *inventory_info_ptr; custom_handle = (struct snmp_bc_hnd *)handle->data; /* Assumming OidManufacturer is defined and determines readable of other VPD */ for (i=0; inventory_array[i].inventory_info.mib.oid.OidManufacturer != NULL; i++) { rdrptr = (SaHpiRdrT *)g_malloc0(sizeof(SaHpiRdrT)); if (rdrptr == NULL) { dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } valid_idr = rdr_exists(custom_handle, &(res_oh_event->resource.ResourceEntity), 0, inventory_array[i].inventory_info.mib.oid.OidManufacturer, 0, 0); /* Add inventory RDR, if inventory can be read */ if (valid_idr) { rdrptr->RdrType = SAHPI_INVENTORY_RDR; rdrptr->Entity = res_oh_event->resource.ResourceEntity; rdrptr->RdrTypeUnion.InventoryRec = inventory_array[i].inventory; oh_init_textbuffer(&(rdrptr->IdString)); oh_append_textbuffer(&(rdrptr->IdString), inventory_array[i].comment); trace("Discovered inventory: %s.", rdrptr->IdString.Data); inventory_info_ptr = g_memdup(&(inventory_array[i].inventory_info), sizeof(struct InventoryInfo)); err = oh_add_rdr(handle->rptcache, res_oh_event->resource.ResourceId, rdrptr, inventory_info_ptr, 0); if (err) { dbg("Cannot add RDR. Error=%s.", oh_lookup_error(err)); g_free(rdrptr); } else { res_oh_event->rdrs = g_slist_append(res_oh_event->rdrs, rdrptr); } } else { g_free(rdrptr); } } return(SA_OK); }
/** * main: Starting with an empty RPTable, adds 1 resource to it * and then adds 1 NULL rdr to it using a NULL table. * Passes the test if the interface returns an error, else it fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); if (oh_add_resource(rptable, rptentries, NULL, 0)) return 1; if (!oh_add_rdr(NULL, rptentries[0].ResourceId, NULL, NULL, 1)) return 1; return 0; }
static int add_control_event(ipmi_entity_t *ent, ipmi_control_t *control, struct oh_handler_state *handler, SaHpiEntityPathT parent_ep, SaHpiResourceIdT rid) { struct ohoi_resource_info *info; struct ohoi_control_info *ctrl_info; SaHpiRdrT rdr; ctrl_info = malloc(sizeof(struct ohoi_control_info)); if (!ctrl_info) { dbg("Out of memory"); return 1; } memset(&rdr, 0, sizeof(rdr)); ctrl_info->type = OHOI_CTRL_ORIGINAL; ctrl_info->info.orig_ctrl_info.ctrl_id = ipmi_control_convert_to_id(control); ctrl_info->mode = SAHPI_CTRL_MODE_AUTO; ctrl_info->ohoii.get_control_state = orig_get_control_state; ctrl_info->ohoii.set_control_state = orig_set_control_state; rdr.RecordId = 0; rdr.Entity = parent_ep; rdr.RdrTypeUnion.CtrlRec.OutputType = _control_type_from_ipmi_to_hpi(control); rdr.RdrTypeUnion.CtrlRec.Type = SAHPI_CTRL_TYPE_OEM; set_idstring(control, &rdr); info = oh_get_resource_data(handler->rptcache, rid); if (!info) { free(ctrl_info); dbg("No info in resource(%d)\n", rid); return 1; } rdr.RdrTypeUnion.CtrlRec.Num = info->ctrl_count; info->ctrl_count++; rid = oh_uid_lookup(&rdr.Entity); if (oh_add_rdr(handler->rptcache, rid, &rdr, ctrl_info, 1) != SA_OK) { dbg("couldn't add control rdr"); free(ctrl_info); return 1; } return 0; }
/** * main: Starting with an empty RPTable, adds 10 resources to it * and then adds 1 rdr to it using a Resource Id not present in the table. * Passes the test if the interface returns an error, else it fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); guint i; for (i = 0; rptentries[i].ResourceId; i++) { if (oh_add_resource(rptable, rptentries+i, NULL, 0)) return 1; } if (!oh_add_rdr(rptable, 1234567, rdrs, NULL, 1)) return 1; return 0; }
/** * main: Starts with an RPTable of 1 resource, adds 1 rdr with data * to first resource. Fetches data using a SAHPI_FIRST_ENTRY as the Record Id. * Success if the interface returns an ok, otherwise there was a failure. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); gchar *data = "My data"; if (oh_add_resource(rptable, rptentries, NULL, 1)) return 1; if (oh_add_rdr(rptable, rptentries[0].ResourceId, rdrs, data, 1)) return 1; if (!oh_get_rdr_data(rptable, rptentries[0].ResourceId, SAHPI_FIRST_ENTRY)) return 1; return 0; }
/** * main: Starts with an RPTable of 1 resource, adds 1 rdr with data * to first resource. Fetches data using a Resource Id not present in the table. * Success if the interface returns an error, otherwise there was a failure. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); gchar *data = "My data"; if (oh_add_resource(rptable, rptentries, NULL, 1)) return 1; if (oh_add_rdr(rptable, rptentries[0].ResourceId, sensors, data, 1)) return 1; if (oh_get_rdr_data(rptable, 1234567, sensors[0].RecordId)) return 1; return 0; }
static int process_rdr_event(struct oh_handler *h, RPTable *rpt, struct oh_event *e) { int rv; SaHpiResourceIdT rid; if (e->type == OH_ET_RDR_DEL) { rid = oh_uid_lookup(&(e->u.rdr_del_event.parent_entity)); rv = (rid)? oh_remove_rdr(rpt,rid,e->u.rdr_del_event.record_id) : -1; } else { rid = oh_uid_lookup(&(e->u.rdr_event.rdr.Entity)); rv = (rid)? oh_add_rdr(rpt,rid,&(e->u.rdr_event.rdr),NULL) : -1; } if (rv) dbg("Could not process rdr event. Parent resource not found."); return rv; }
static void add_sensor_event(ipmi_entity_t *ent, ipmi_sensor_t *sensor, struct oh_handler_state *handler, SaHpiEntityPathT parent_ep, SaHpiResourceIdT rid) { struct ohoi_sensor_info *sensor_info; struct oh_event *e; struct ohoi_resource_info *info; sensor_info = malloc(sizeof(*sensor_info)); if (!sensor_info) { dbg("Out of memory for sensor info"); return; } sensor_info->sensor_id = ipmi_sensor_convert_to_id(sensor); sensor_info->valid = 0; sensor_info->enable = SAHPI_TRUE; e = malloc(sizeof(*e)); if (!e) { free(sensor_info); dbg("Out of space"); return; } memset(e, 0, sizeof(*e)); e->type = OH_ET_RDR; add_sensor_event_rdr(sensor, &e->u.rdr_event.rdr, parent_ep, rid); info = oh_get_resource_data(handler->rptcache, rid); if (!info) { free(e); dbg("No info in resource(%d)\n", rid); return; } e->u.rdr_event.rdr.RdrTypeUnion.SensorRec.Num = info->sensor_count; info->sensor_count++; rid = oh_uid_lookup(&e->u.rdr_event.rdr.Entity); oh_add_rdr(handler->rptcache, rid, &e->u.rdr_event.rdr, sensor_info, 1); }
/** * main: Starts with an RPTable of 10 resources, adds 5 rdr * to first resource. Fetches rdrs randomly by type and compares * with original. A failed comparison means the test failed, * otherwise the test passed. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); GSList *records = NULL; guint i = 0; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, rdrs + i, NULL,0)) return 1; else records = g_slist_append(records, rdrs + i); } for (; records; i--) { SaHpiRdrT *tmprdr = NULL, *randrdr = NULL; GSList *tmpnode = NULL; guint k = (guint) (((gfloat)i)*rand()/(RAND_MAX+1.0)); tmpnode = g_slist_nth(records, k); randrdr = (SaHpiRdrT *)tmpnode->data; randrdr->RecordId = get_rdr_uid(randrdr->RdrType, randrdr->RdrTypeUnion.SensorRec.Num); tmprdr = oh_get_rdr_by_type(rptable, SAHPI_FIRST_ENTRY, randrdr->RdrType, randrdr->RdrTypeUnion.SensorRec.Num); if (!tmprdr || memcmp(randrdr, tmprdr, sizeof(SaHpiRdrT))) return 1; else { records = g_slist_remove_link(records, tmpnode); g_slist_free_1(tmpnode); } } return 0; }
/** * main: resource must NOT have SAHPI_CAPABILITY_AGGREGATE_STATUS capability, * sensor num should be between SAHPI_STANDARD_SENSOR_MIN and * SAHPI_STANDARD_SENSOR_MAX and less than SENSOR_AGGREGATE_MAX. * With these conditions, oh_add_rdr is expected to return an error. * This is because for a sensor to have a num in the reserved range, * the resource must have SAHPI_CAPABILITY_AGGREGATE_STATUS capability * set. * If so, the test passes, otherwise it failed. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); guint i; rptentries[0].ResourceCapabilities = rptentries[0].ResourceCapabilities & 0xFFFFDFFF; for (i = 0; rptentries[i].ResourceId; i++) { if (oh_add_resource(rptable, rptentries+i, NULL, 0)) return 1; } rdrs[0].RdrTypeUnion.SensorRec.Num = SAHPI_STANDARD_SENSOR_MIN; if (!oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, rdrs, NULL, 1)) return 1; return 0; }
/** * main: Starting with an empty RPTable, adds 1 resource to it * and then adds 1 rdr to it. Removes rdr using a special value like * SAHPI_FIRST_ENTRY. * Passes the test if the interface returns ok, else it fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); guint i; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries+i, NULL, 0)) return 1; } if (oh_add_rdr(rptable, rptentries[0].ResourceId, rdrs, NULL, 1)) return 1; if (oh_remove_rdr(rptable, rptentries[0].ResourceId, SAHPI_FIRST_ENTRY)) return 1; return 0; }
/** * main: Starts with an RPTable of 1 resource, adds 5 rdrs to first resource. * Fetches an rdr by id using a NULL table. * Success if the interface returns an error, otherwise there was a failure. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); guint i; if (oh_add_resource(rptable, rptentries, NULL, 1)) return 1; for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, rptentries[0].ResourceId, rdrs+i, NULL, 1)) return 1; } if (oh_get_rdr_by_id(NULL, rptentries[0].ResourceId, rdrs[0].RecordId)) return 1; return 0; }
/** * main: Starting with an empty RPTable, adds 1 resource to it * and then adds 1 rdr to it. Removes rdr using a Resource Id not present * in the table. * Passes the test if the interface returns an error, else it fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); guint i; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries+i, NULL, 0)) return 1; } if (oh_add_rdr(rptable, rptentries[0].ResourceId, sensors, NULL, 1)) return 1; if (!oh_remove_rdr(rptable, 1234567, sensors[0].RecordId)) return 1; return 0; }
/** * main: Starts with an RPTable of 1 resource, adds 5 rdrs to first resource. * Fetches an rdr using get_next with the Record Id as SAHPI_FIRST_ENTRY. * Success if the interface returns a valid pointer, otherwise there was a failure. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); guint i; if (oh_add_resource(rptable, rptentries, NULL, 1)) return 1; for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, rptentries[0].ResourceId, rdrs+i, NULL, 1)) return 1; } if (!oh_get_rdr_next(rptable, rptentries[0].ResourceId, SAHPI_FIRST_ENTRY)) return 1; return 0; }
bool cIpmiRdr::Populate(GSList **list) { if ( m_populate ) return true; // find resource SaHpiRptEntryT *resource = Domain()->FindResource( Resource()->m_resource_id ); if ( !resource ) { stdlog << "Resource not found: Can't populate RDR !\n"; return false; } // create rdr SaHpiRdrT *rdr = (SaHpiRdrT *)g_malloc0(sizeof(SaHpiRdrT)); CreateRdr( *resource, *rdr ); int rv = oh_add_rdr( Domain()->GetHandler()->rptcache, resource->ResourceId, rdr, this, 1 ); if ( rv != 0 ) { stdlog << "Can't add RDR to plugin cache !\n"; g_free( rdr ); return false; } // assign the hpi record id to sensor, so we can find // the rdr for a given sensor. // the id comes from oh_add_rdr. RecordId() = rdr->RecordId; stdlog << "cIpmiRdr::Populate RDR for resource " << resource->ResourceId << " RDR " << RecordId() << "\n"; *list = g_slist_append(*list, rdr); m_populate = true; return true; }
static void add_inventory_event(struct ohoi_resource_info *res_info, ipmi_entity_t *ent, struct oh_handler_state *handler, SaHpiRptEntryT *rpt_entry) { SaHpiResourceIdT rid = rpt_entry->ResourceId; SaHpiRdrT rdr; int rv; init_inventory_info(handler, res_info, ent); if (res_info->fru == NULL) { err("Out of memory"); return; } memset(&rdr, 0, sizeof(rdr)); rdr.RecordId = 0; rdr.RdrType = SAHPI_INVENTORY_RDR; rdr.Entity = rpt_entry->ResourceEntity; rdr.IsFru = SAHPI_TRUE; /* One Fru has only one inventory, so IdrId always is 0 */ rdr.RdrTypeUnion.InventoryRec.IdrId = 0; rdr.RdrTypeUnion.InventoryRec.Persistent = SAHPI_TRUE; rdr.RdrTypeUnion.InventoryRec.Oem = 0; oh_init_textbuffer(&rdr.IdString); oh_append_textbuffer(&rdr.IdString, "FRU Inventory data"); rid = oh_uid_lookup(&rdr.Entity); rv = oh_add_rdr(handler->rptcache, rid, &rdr, NULL, 0); if (rv == SA_OK) { rpt_entry->ResourceCapabilities |= SAHPI_CAPABILITY_INVENTORY_DATA | SAHPI_CAPABILITY_RDR; } else { free(res_info->fru); res_info->fru = NULL; err("couldn't add inventory. rv = %d", rv); } }
/** * main: Starts with an RPTable of 1 resource, adds 5 rdrs to first resource. * Fetches an rdr by type using a NULL table. * Success if the interface returns an error, otherwise there was a failure. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); guint i; if (oh_add_resource(rptable, rptentries, NULL, 1)) return 1; for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, rptentries[0].ResourceId, rdrs+i, NULL, 1)) return 1; } if (oh_get_rdr_by_type(NULL, rptentries[0].ResourceId, rdrs[0].RdrType, rdrs[0].RdrTypeUnion.SensorRec.Num)) return 1; return 0; }
static void add_control_event(ipmi_entity_t *ent, ipmi_control_t *control, struct oh_handler_state *handler, SaHpiEntityPathT parent_ep, SaHpiResourceIdT rid) { ipmi_control_id_t *control_id; struct oh_event *e; struct ohoi_resource_info *info; control_id = malloc(sizeof(*control_id)); if (!control_id) { dbg("Out of memory"); return; } *control_id = ipmi_control_convert_to_id(control); e = malloc(sizeof(*e)); if (!e) { free(control_id); dbg("Out of space"); return; } memset(e, 0, sizeof(*e)); e->type = OH_ET_RDR; add_control_event_rdr(control, &e->u.rdr_event.rdr, parent_ep, rid); info = oh_get_resource_data(handler->rptcache, rid); if (!info) { free(e); dbg("No info in resource(%d)\n", rid); return; } e->u.rdr_event.rdr.RdrTypeUnion.SensorRec.Num = info->ctrl_count; info->ctrl_count++; rid = oh_uid_lookup(&e->u.rdr_event.rdr.Entity); oh_add_rdr(handler->rptcache, rid, &e->u.rdr_event.rdr, control_id, 1); }