Пример #1
0
/**
 * ep_concat test5.
 *   concatenate two 3 element entity path and verify result
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
        SaHpiEntityPathT ep1 = {{{SAHPI_ENT_PERIPHERAL_BAY,55},
                                 {SAHPI_ENT_SYS_MGMNT_MODULE,66},
                                 {SAHPI_ENT_SYSTEM_BOARD,77},
                                 {SAHPI_ENT_ROOT,0}}};
        SaHpiEntityPathT ep2 = {{{SAHPI_ENT_MEMORY_MODULE,88},
                                 {SAHPI_ENT_PROCESSOR_MODULE,99},
                                 {SAHPI_ENT_POWER_SUPPLY,101},
                                 {SAHPI_ENT_ROOT,0}}};
        SaHpiEntityPathT ep3 = {{{SAHPI_ENT_PERIPHERAL_BAY,55},
                                 {SAHPI_ENT_SYS_MGMNT_MODULE,66},
                                 {SAHPI_ENT_SYSTEM_BOARD,77},
                                 {SAHPI_ENT_MEMORY_MODULE,88},
                                 {SAHPI_ENT_PROCESSOR_MODULE,99},
                                 {SAHPI_ENT_POWER_SUPPLY,101},
                                 {SAHPI_ENT_ROOT,0}}};
        int mydebug = 0;

        if (ep_concat(&ep1, &ep2)) {
                if (mydebug) printf("ep_concat test5 checkpoint 1 failed\n");
                return 1;
        }
        if (ep_cmp(&ep1, &ep3)) {
                if (mydebug) printf("ep_concat test5 checkpoint 2 failed\n");
                return 1;
        }
        if (mydebug) printf("ep_concat test5 OK\n");
        return 0;
}
Пример #2
0
/*
 * oh_entity_path_equal: used by g_hash_table_new() 
 * in oh_uid_initialize(). See glib library for
 * further details.
 */
gboolean oh_entity_path_equal(gconstpointer a, gconstpointer b)
{
        if (!ep_cmp(a,b)) {
                return 1;
        }
        else {
                return 0;
        }
}
Пример #3
0
static int sa_list_sensor(void)
{
        SaErrorT rv = SA_OK;
        SaHpiEntryIdT rptentryid;
        SaHpiRptEntryT rptentry;
        SaHpiEntryIdT nextrptentryid;
        SaHpiEntryIdT entryid;
        SaHpiEntryIdT nextentryid;
        SaHpiResourceIdT resourceid;
        SaHpiRdrT rdr;
        SaHpiEntityPathT ep_target;
        char *ep_string = NULL;

        /* walk the RPT list */
        rptentryid = SAHPI_FIRST_ENTRY;
        while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY))
        {
                rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
                if (rv == SA_OK) {
                        /* Walk the RDR list for this RPT entry */

                        /* Filter by entity path if specified */
                        if (ep_string && ep_cmp(&ep_target,&(rptentry.ResourceEntity))) {
                                rptentryid = nextrptentryid;
                                continue;
                        }

                        entryid = SAHPI_FIRST_ENTRY;
                        resourceid = rptentry.ResourceId;
                        rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0;
                        while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY))
                        {
                                rv = saHpiRdrGet(sessionid,resourceid,
                                                 entryid,&nextentryid, &rdr);
                                if (rv == SA_OK) {
                                        if (rdr.RdrType == SAHPI_SENSOR_RDR &&
                                                rdr.RdrTypeUnion.SensorRec.Ignore != TRUE) {
						printf("Resource Id: %d, Sensor Id: %d\n",
							resourceid, rdr.RdrTypeUnion.SensorRec.Num);
                                        } 

                                        entryid = nextentryid;
                                } else {
                                        rv = SA_OK;
                                        entryid = SAHPI_LAST_ENTRY;
                                }
                        }
                        rptentryid = nextrptentryid;
                }
        }
	return rv;
}
Пример #4
0
/**
 * ep_concat test7.
 *   concatenate a 4 and a 12 element entity path and verify result
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
        SaHpiEntityPathT ep1 = {{{SAHPI_ENT_POWER_UNIT,199},
                                 {SAHPI_ENT_CHASSIS_BACK_PANEL_BOARD,202},
                                 {SAHPI_ENT_SYSTEM_CHASSIS,211},
                                 {SAHPI_ENT_SUB_CHASSIS,222},
                                 {SAHPI_ENT_ROOT,0}}};
        SaHpiEntityPathT ep2 = {{{SAHPI_ENT_OTHER_CHASSIS_BOARD,233},
                                 {SAHPI_ENT_DISK_DRIVE_BAY,244},
                                 {SAHPI_ENT_PERIPHERAL_BAY_2,255},
                                 {SAHPI_ENT_DEVICE_BAY,255},
                                 {SAHPI_ENT_COOLING_DEVICE,277},
                                 {SAHPI_ENT_COOLING_UNIT,288},
                                 {SAHPI_ENT_INTERCONNECT,299},
                                 {SAHPI_ENT_MEMORY_DEVICE,303},
                                 {SAHPI_ENT_SYS_MGMNT_SOFTWARE,311},
                                 {SAHPI_ENT_BIOS,322},
                                 {SAHPI_ENT_OPERATING_SYSTEM,333},
                                 {SAHPI_ENT_SYSTEM_BUS,344},
                                 {SAHPI_ENT_ROOT,0}}};
        SaHpiEntityPathT ep3 = {{{SAHPI_ENT_POWER_UNIT,199},
                                 {SAHPI_ENT_CHASSIS_BACK_PANEL_BOARD,202},
                                 {SAHPI_ENT_SYSTEM_CHASSIS,211},
                                 {SAHPI_ENT_SUB_CHASSIS,222},
                                 {SAHPI_ENT_OTHER_CHASSIS_BOARD,233},
                                 {SAHPI_ENT_DISK_DRIVE_BAY,244},
                                 {SAHPI_ENT_PERIPHERAL_BAY_2,255},
                                 {SAHPI_ENT_DEVICE_BAY,255},
                                 {SAHPI_ENT_COOLING_DEVICE,277},
                                 {SAHPI_ENT_COOLING_UNIT,288},
                                 {SAHPI_ENT_INTERCONNECT,299},
                                 {SAHPI_ENT_MEMORY_DEVICE,303},
                                 {SAHPI_ENT_SYS_MGMNT_SOFTWARE,311},
                                 {SAHPI_ENT_BIOS,322},
                                 {SAHPI_ENT_OPERATING_SYSTEM,333},
                                 {SAHPI_ENT_SYSTEM_BUS,344}}};
        int mydebug = 0;

        if (ep_concat(&ep1, &ep2)) {
                if (mydebug) printf("ep_concat test7 checkpoint 1 failed\n");
                return 1;
        }
        if (ep_cmp(&ep1, &ep3)) {
                if (mydebug) printf("ep_concat test7 checkpoint 2 failed\n");
                return 1;
        }

        if (mydebug) printf("ep_concat test7 OK\n");
        return 0;
}
Пример #5
0
/**
 * ep_cmp test2
 *    single element entity path comparison, expect success
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
        SaHpiEntityPathT ep1 = {{{SAHPI_ENT_ADD_IN_CARD,1111},
                                 {SAHPI_ENT_ROOT, 0}}};
        SaHpiEntityPathT ep2 = {{{SAHPI_ENT_ADD_IN_CARD,1111},
                                 {SAHPI_ENT_ROOT, 0}}};
        int mydebug = 0;

        if (ep_cmp(&ep1, &ep2)) {
                if (mydebug) printf("ep_cmp test2 failed\n");
                return 1;
        }

        if (mydebug) printf("ep_cmp test2 OK\n");
        return 0;
}
Пример #6
0
/**
 * ep_cmp test9
 *   compare multi to zero element entity path, expect failure
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
        SaHpiEntityPathT ep1 = {{{SAHPI_ENT_FAN,4},
                                 {SAHPI_ENT_SBC_BLADE,3},
                                 {SAHPI_ENT_RACK,2},
                                 {SAHPI_ENT_ROOT,0}}};
        SaHpiEntityPathT ep2 = {{{SAHPI_ENT_ROOT, 0}}};
        int mydebug = 0;

        if (ep_cmp(&ep1, &ep2) == 0) {
                if (mydebug) printf("ep_cmp test9 failed\n");
                return 1;
        }

        if (mydebug) printf("ep_cmp test9 OK\n");
        return 0;
}
Пример #7
0
/**
 * main: Get a new unique id. Use id to lookup original entity path. 
 * Passes if returned entity path is equal to original entity path,
 * otherwise fails.
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
	SaHpiEntityPathT ep, rep;
	guint id;

	if (oh_uid_initialize())
		return 1;
	
	ep_init(&ep);

	id = oh_uid_from_entity_path(&ep);

	if (oh_entity_path_lookup(&id, &rep))
		return 1;
	
	if (ep_cmp(&ep, &rep))
		return 1;

	return 0;
}
Пример #8
0
/**
 * ep_concat test15.
 *   concatenate a 5 element entity path that has garbage beyond end element with a 5 element,
 *   verify result, the garbage should be gone at end result.
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
        SaHpiEntityPathT ep1 = {{{SAHPI_ENT_GROUP,1},
                                 {SAHPI_ENT_REMOTE,2},
                                 {SAHPI_ENT_EXTERNAL_ENVIRONMENT,3},
                                 {SAHPI_ENT_BATTERY,4},
                                 {SAHPI_ENT_CHASSIS_SPECIFIC,5},
                                 {SAHPI_ENT_ROOT,0},
                                 {SAHPI_ENT_FAN,11},
                                 {SAHPI_ENT_RACK,12}}};
        SaHpiEntityPathT ep2 = {{{SAHPI_ENT_GROUP,101},
                                 {SAHPI_ENT_REMOTE,102},
                                 {SAHPI_ENT_EXTERNAL_ENVIRONMENT,103},
                                 {SAHPI_ENT_BATTERY,104},
                                 {SAHPI_ENT_CHASSIS_SPECIFIC,105},
                                 {SAHPI_ENT_ROOT,0}}};
        SaHpiEntityPathT ep3 = {{{SAHPI_ENT_GROUP,1},
                                 {SAHPI_ENT_REMOTE,2},
                                 {SAHPI_ENT_EXTERNAL_ENVIRONMENT,3},
                                 {SAHPI_ENT_BATTERY,4},
                                 {SAHPI_ENT_CHASSIS_SPECIFIC,5},
                                 {SAHPI_ENT_GROUP,101},
                                 {SAHPI_ENT_REMOTE,102},
                                 {SAHPI_ENT_EXTERNAL_ENVIRONMENT,103},
                                 {SAHPI_ENT_BATTERY,104},
                                 {SAHPI_ENT_CHASSIS_SPECIFIC,105},
                                 {SAHPI_ENT_ROOT,0}}};
        int mydebug = 0;

        if (ep_concat(&ep1, &ep2)) {
                if (mydebug) printf("ep_concat test15 checkpoint 1 failed\n");
                return 1;
        }
        if (ep_cmp(&ep1, &ep3)) {
                if (mydebug) printf("ep_concat test15 checkpoint 2 failed\n");
                return 1;
        }

        if (mydebug) printf("ep_concat test15 OK\n");
        return 0;
}
Пример #9
0
/**
 * ep_cmp test3
 *   multi element entity path comarison, expect success
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
        SaHpiEntityPathT ep1 = {{{SAHPI_ENT_ADD_IN_CARD,11},
                                 {SAHPI_ENT_FRONT_PANEL_BOARD,22},
                                 {SAHPI_ENT_BACK_PANEL_BOARD,33},
                                 {SAHPI_ENT_POWER_SYSTEM_BOARD,44},
                                 {SAHPI_ENT_ROOT, 0}}};
        SaHpiEntityPathT ep2 = {{{SAHPI_ENT_ADD_IN_CARD,11},
                                 {SAHPI_ENT_FRONT_PANEL_BOARD,22},
                                 {SAHPI_ENT_BACK_PANEL_BOARD,33},
                                 {SAHPI_ENT_POWER_SYSTEM_BOARD,44},
                                 {SAHPI_ENT_ROOT, 0}}};
        int mydebug = 0;

        if (ep_cmp(&ep1, &ep2)) {
                if (mydebug) printf("ep_cmp test3 failed\n");
                return 1;
        }

        if (mydebug) printf("ep_cmp test3 OK\n");
        return 0;
}
Пример #10
0
static int snmp_rsa_discover_resources(void *hnd)
{
        SaHpiEntityPathT entity_root;        
        guint i;
        struct oh_event *e;
	struct snmp_value get_value;
//	struct snmp_value get_active;
        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;
        struct snmp_rsa_hnd *custom_handle = (struct snmp_rsa_hnd *)handle->data;
        RPTable *tmpcache = (RPTable *)g_malloc0(sizeof(RPTable));
        GSList *tmpqueue = NULL;
        char *root_tuple = (char *)g_hash_table_lookup(handle->config,"entity_root");        
                
        string2entitypath(root_tuple, &entity_root);

        /* see if the chassis exists by querying system health */
        if(snmp_get(custom_handle->ss,".1.3.6.1.4.1.2.3.51.1.2.7.1.0",&get_value) != 0) {
                /* If we get here, something is hosed. No need to do more discovery */
                dbg("Couldn't fetch SNMP RSA system health.\n");
                dbg("There is no chassis.");
                g_free(tmpcache);
                return -1;
        }

        /* discover the chassis */
        e = snmp_rsa_discover_chassis(handle, &entity_root);
        if(e != NULL) {
                struct ResourceMibInfo *res_mib =
                        g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_CHASSIS].rsa_res_info.mib),
                                 sizeof(struct snmp_rpt));
                oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0);
                tmpqueue = g_slist_append(tmpqueue, e);
                SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId;
                SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity;
		find_sensors(snmp_rsa_chassis_sensors);                        
		find_controls(snmp_rsa_chassis_controls);
		find_inventories(snmp_rsa_chassis_inventories);
        }

        /* discover all cpus */
        for (i = 0; i < RSA_MAX_CPU; i++) {
                /* see if the cpu exists by querying the thermal sensor */
                if((snmp_get(custom_handle->ss,
                             snmp_rsa_cpu_thermal_sensors[i].rsa_sensor_info.mib.oid,
                             &get_value) != 0) ||
                   (get_value.type != ASN_OCTET_STR) ||
                   (strcmp(get_value.string, "Not Readable!") == 0)) {
                        /* If we get here the CPU is not installed */
                        dbg("CPU %d not found.\n", i+RSA_HPI_INSTANCE_BASE);
                        continue;
                }

                e = snmp_rsa_discover_cpu(handle, &entity_root, i);
                if(e != NULL) {
                        struct ResourceMibInfo *res_mib =
                                g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_CPU].rsa_res_info.mib),
                                         sizeof(struct snmp_rpt));
                        oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0);
                        tmpqueue = g_slist_append(tmpqueue, e);
                        SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId;
                        SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity;
                        /* add the CPU thermal sensor */
                        e = snmp_rsa_discover_sensors(handle,
                                                      parent_ep,
                                                      &snmp_rsa_cpu_thermal_sensors[i]);
                        if(e != NULL) {
                                struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_cpu_thermal_sensors[i].rsa_sensor_info),
                                                                           sizeof(struct RSA_SensorInfo));
                                oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0);
                                tmpqueue = g_slist_append(tmpqueue, e);
                        }
                }
        }

        /* discover all dasd */
        for (i = 0; i < RSA_MAX_DASD; i++) {
                /* see if the dasd exists by querying the thermal sensor */
                if((snmp_get(custom_handle->ss,
                             snmp_rsa_dasd_thermal_sensors[i].rsa_sensor_info.mib.oid,
                             &get_value) != 0) ||
                   (get_value.type != ASN_OCTET_STR) ||
                   (strcmp(get_value.string, "Not Readable!") == 0)) {
                        /* If we get here the DASD is not installed */
                        dbg("DASD %d not found.\n", i+RSA_HPI_INSTANCE_BASE);
                        continue;
                }

                e = snmp_rsa_discover_dasd(handle, &entity_root, i);
                if(e != NULL) {
                        struct ResourceMibInfo *res_mib =
                                g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_DASD].rsa_res_info.mib),
                                         sizeof(struct snmp_rpt));
                        oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0);
                        tmpqueue = g_slist_append(tmpqueue, e);
                        SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId;
                        SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity;
                        /* add the DASD thermal sensor */
                        e = snmp_rsa_discover_sensors(handle,
                                                      parent_ep,
                                                      &snmp_rsa_dasd_thermal_sensors[i]);
                        if(e != NULL) {
                                struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_dasd_thermal_sensors[i].rsa_sensor_info),
                                                                           sizeof(struct RSA_SensorInfo));
                                oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0);
                                tmpqueue = g_slist_append(tmpqueue, e);
                        }
                }
        }

        /* discover all fans */
        for (i = 0; i < RSA_MAX_FAN; i++) {
                /* see if the fan exists by querying the  sensor */
                if((snmp_get(custom_handle->ss,
                             snmp_rsa_fan_sensors[i].rsa_sensor_info.mib.oid,
                             &get_value) != 0) ||
                   (get_value.type != ASN_OCTET_STR) ||
                   (strcmp(get_value.string, "Not Readable!") == 0)) {
                        /* If we get here the fan is not installed */
                        dbg("Fan %d not found.\n", i+RSA_HPI_INSTANCE_BASE);
                        continue;
                }

                e = snmp_rsa_discover_fan(handle, &entity_root, i);
                if(e != NULL) {
                        struct ResourceMibInfo *res_mib =
                                g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_FAN].rsa_res_info.mib),
                                         sizeof(struct snmp_rpt));
                        oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0);
                        tmpqueue = g_slist_append(tmpqueue, e);
                        SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId;
                        SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity;
                        /* add the fan sensor */
                        e = snmp_rsa_discover_sensors(handle,
                                                      parent_ep,
                                                      &snmp_rsa_fan_sensors[i]);
                        if(e != NULL) {
                                struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_fan_sensors[i].rsa_sensor_info),
                                                                           sizeof(struct RSA_SensorInfo));
                                oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0);
                                tmpqueue = g_slist_append(tmpqueue, e);
                        }
                }
        }

        /*
        Rediscovery: Get difference between current rptcache and tmpcache. Delete
        obsolete items from rptcache and add new items in.        
        */
        GSList *res_new = NULL, *rdr_new = NULL, *res_gone = NULL, *rdr_gone = NULL;
        GSList *node = NULL;
        
       	rpt_diff(handle->rptcache, tmpcache, &res_new, &rdr_new, &res_gone, &rdr_gone);
	dbg("%d resources have gone away.", g_slist_length(res_gone));
	dbg("%d resources are new or have changed", g_slist_length(res_new));

        for (node = rdr_gone; node != NULL; node = node->next) {
                SaHpiRdrT *rdr = (SaHpiRdrT *)node->data;
                SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity));
                /* Create remove rdr event and add to event queue */
                struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event));
                if (e) {
                        e->type = OH_ET_RDR_DEL;
                        e->u.rdr_del_event.record_id = rdr->RecordId;
                        e->u.rdr_del_event.parent_entity = rdr->Entity;
                        handle->eventq = g_slist_append(handle->eventq, e);
                } else dbg("Could not allocate more memory to create event.");
                /* Remove rdr from plugin's rpt cache */
                if (rdr && res)
                        oh_remove_rdr(handle->rptcache, res->ResourceId, rdr->RecordId);
                else dbg("No valid resource or rdr at hand. Could not remove rdr.");
                
        }
        g_slist_free(rdr_gone);

        for (node = res_gone; node != NULL; node = node->next) {
                SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data;
		/* Create remove resource event and add to event queue */
		struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event));
                if (e) {
                        e->type = OH_ET_RESOURCE_DEL;
                        e->u.res_del_event.resource_id = res->ResourceId;
                        handle->eventq = g_slist_append(handle->eventq, e);
                } else dbg("Could not allocate more memory to create event.");
		/* Remove resource from plugin's rpt cache */
                if (res)
                        oh_remove_resource(handle->rptcache, res->ResourceId);
                else dbg("No valid resource at hand. Could not remove resource.");
        }
        g_slist_free(res_gone);

        for (node = res_new; node != NULL; node = node->next) {
                GSList *tmpnode = NULL;
                SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data;
                if (!res) {
                        dbg("No valid resource at hand. Could not process new resource.");
                        continue;
                }
                gpointer data = oh_get_resource_data(tmpcache, res->ResourceId);
                oh_add_resource(handle->rptcache, res, g_memdup(data, sizeof(struct snmp_rpt)),0);
                /* Add new/changed resources to the event queue */
                for (tmpnode = tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) {
                        struct oh_event *e = (struct oh_event *)tmpnode->data;
                        if (e->type == OH_ET_RESOURCE &&
                            e->u.res_event.entry.ResourceId == res->ResourceId) {
                                handle->eventq = g_slist_append(handle->eventq, e);
                                tmpqueue = g_slist_remove_link(tmpqueue, tmpnode);
				g_slist_free_1(tmpnode);
                                break;
                        }
                }
        }
        g_slist_free(res_new);
        
        for (node = rdr_new; node != NULL; node = node->next) {
                guint rdr_data_size = 0;
                GSList *tmpnode = NULL;
                SaHpiRdrT *rdr = (SaHpiRdrT *)node->data;
                SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity));
                if (!res || !rdr) {
                        dbg("No valid resource or rdr at hand. Could not process new rdr.");
                        continue;
                }
                gpointer data = oh_get_rdr_data(tmpcache, res->ResourceId, rdr->RecordId);
                /* Need to figure out the size of the data associated with the rdr */
                if (rdr->RdrType == SAHPI_SENSOR_RDR) rdr_data_size = sizeof(struct RSA_SensorMibInfo);
                else if (rdr->RdrType == SAHPI_CTRL_RDR)
                        rdr_data_size = sizeof(struct RSA_ControlMibInfo);
                else if (rdr->RdrType == SAHPI_INVENTORY_RDR)
                        rdr_data_size = sizeof(struct RSA_InventoryMibInfo);
                oh_add_rdr(handle->rptcache, res->ResourceId, rdr, g_memdup(data, rdr_data_size),0);
                /* Add new/changed rdrs to the event queue */
                for (tmpnode = tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) {
                        struct oh_event *e = (struct oh_event *)tmpnode->data;
                        if (e->type == OH_ET_RDR &&                            
                            ep_cmp(&(e->u.rdr_event.rdr.Entity),&(rdr->Entity)) == 0 &&
                            e->u.rdr_event.rdr.RecordId == rdr->RecordId) {
                                handle->eventq = g_slist_append(handle->eventq, e);
                                tmpqueue =  g_slist_remove_link(tmpqueue, tmpnode);
				g_slist_free_1(tmpnode);
                                break;
                        }
                }
        }        
        g_slist_free(rdr_new);
        
        /* Clean up tmpqueue and tmpcache */
        g_slist_free(tmpqueue);
        oh_flush_rpt(tmpcache);
        g_free(tmpcache);
        
        return SA_OK;        
}
Пример #11
0
/* Return 1 on failure in finding the destination, 0 on success */
void
try_path(int dir, ep_t *src, ep_t *dest, int **arr, int size)
{
    ep_t new_src;

    tp_cc++;
    switch(dir) {
    case NORTH:
        new_src.ep_row = src->ep_row - 1;
        new_src.ep_col = src->ep_col;
        break;
    case EAST:
        new_src.ep_row = src->ep_row;
        new_src.ep_col = src->ep_col + 1;
        break;
    case WEST:
        new_src.ep_row = src->ep_row;
        new_src.ep_col = src->ep_col - 1;
        break;
    case SOUTH:
        new_src.ep_row = src->ep_row + 1;
        new_src.ep_col = src->ep_col;
        break;
    }

    if (ep_cmp(&new_src, dest) == 0) {
        /* Found */
        ep_t next_src, next_dest;

        DPRINT("TRACE: Found destination %C(%d) at (%d, %d)\n",
               dest->ep_id, dir, new_src.ep_row, new_src.ep_col);
        set_ep_completed(dest->ep_id, arr, size);

        /* Finished with the current ep pair. Process next set */
        if (pop_eps(&next_src, &next_dest) == 1) {
            /* No more endpoints to find routes between */
            if (arr_full(arr, size)) {
                /* Solved */
                solution_count++;
                print_arr(arr, size);
            } else {
                DPRINT("No solution in this route\n");
                failure_count++;
            }
            return;
        }

        /* Continue with the next set of endpoints */
        find_next_path(&next_src, &next_dest, arr, size);

        /* Add back path to stack */
        push_eps(&next_src, &next_dest);
        unset_ep_completed(next_dest.ep_id, arr, size);
    } else if (is_feasible_move(arr, new_src, size)) {
        DPRINT("TRACE: Old path for %C(%d)  - (%d, %d)\n",
               dest->ep_id, dir, src->ep_row, src->ep_col);
        DPRINT("TRACE: New path for %C(%d)  - (%d, %d)\n",
               dest->ep_id, dir, new_src.ep_row, new_src.ep_col);

        /*
         * UI related. Set the path to the ep_id of the src/dest so
         * that the path is highlighted with the same ID. Mask is used
         * to differentiate the actual endpoints and the path between
         * them. If the third byte in the ep_id is set to 0xFF, it is a
         * path.
         */
        arr[new_src.ep_row][new_src.ep_col] =
            (0x00FF0000 | dest->ep_id);
        find_next_path(&new_src, dest, arr, size);
        arr[new_src.ep_row][new_src.ep_col] = 0;
    }
}
Пример #12
0
int main(int argc, char **argv)
{
        int c;
        SaErrorT rv;
        SaHpiVersionT hpiVer;
        SaHpiSessionIdT sessionid;
        SaHpiRptInfoT rptinfo;
        SaHpiRptEntryT rptentry;
        SaHpiEntryIdT rptentryid;
        SaHpiEntryIdT nextrptentryid;
        SaHpiEntryIdT entryid;
        SaHpiEntryIdT nextentryid;
        SaHpiResourceIdT resourceid;
        SaHpiRdrT rdr;
        SaHpiEntityPathT ep_target;
        char *ep_string = NULL;
                
        
        printf("%s: version %s\n",argv[0],progver); 
        
        while ( (c = getopt( argc, argv,"te:x?")) != EOF )
                switch(c) {
                case 't': fshowthr = 1; break;
                case 'x': fdebug = 1; break;
                case 'e':
                        if (optarg) {
                                ep_string = (char *)strdup(optarg);
                        }
                        string2entitypath(ep_string,&ep_target);
                        break;
                default:
                        printf("Usage %s [-t -x]\n",argv[0]);
                        printf("where -t = show Thresholds also\n");
                        printf("      -x = show eXtra debug messages\n");
                        exit(1);
                }
        rv = saHpiInitialize(&hpiVer);
        if (rv != SA_OK) {
                printf("saHpiInitialize: %s\n",decode_error(rv));
                exit(-1);
        }
        rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,&sessionid,NULL);
        if (rv != SA_OK) {
                if (rv == SA_ERR_HPI_ERROR) 
                        printf("saHpiSessionOpen: error %d, daemon not running\n",rv);
                else
                        printf("saHpiSessionOpen: %s\n",decode_error(rv));
                exit(-1);
        }
        
        rv = saHpiResourcesDiscover(sessionid);
        if (fdebug) printf("saHpiResourcesDiscover %s\n",decode_error(rv));
        rv = saHpiRptInfoGet(sessionid,&rptinfo);
        if (fdebug) printf("saHpiRptInfoGet %s\n",decode_error(rv));
        printf("RptInfo: UpdateCount = %d, UpdateTime = %lx\n",
               rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);
        
#ifdef BUGGY
        /* ARC: Bug here in OpenHPI requires re-doing discovery (workaround). */
        { 
                int updcnt;
                int i = 0;
                updcnt = rptinfo.UpdateCount;
                while (rptinfo.UpdateCount == updcnt) {
                        rv = saHpiResourcesDiscover(sessionid);
                        if (fdebug) printf("saHpiResourcesDiscover %s\n",decode_error(rv));
                        rv = saHpiRptInfoGet(sessionid,&rptinfo);
                        if (fdebug) printf("saHpiRptInfoGet %s\n",decode_error(rv));
                        printf("RptInfo/%d: UpdateCount = %d, UpdateTime = %lx\n",
                               ++i,rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);
                }
        }  /*end openhpi bug workaround*/
#endif
        /* walk the RPT list */
        rptentryid = SAHPI_FIRST_ENTRY;
        while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY))
        {
                rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
                if (fdebug) printf("saHpiRptEntryGet %s\n",decode_error(rv));
                                                
                if (rv == SA_OK) {
                        /* Walk the RDR list for this RPT entry */

                        /* Filter by entity path if specified */
                        if (ep_string && ep_cmp(&ep_target,&(rptentry.ResourceEntity))) {
                                rptentryid = nextrptentryid;
                                continue;
                        }
                        
                        entryid = SAHPI_FIRST_ENTRY;
                        resourceid = rptentry.ResourceId;
                        rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; 
                        printf("RPTEntry[%d] tag: %s\n",
                               resourceid,rptentry.ResourceTag.Data);
			print_ep(&rptentry.ResourceEntity);
                        while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY))
                        {
                                rv = saHpiRdrGet(sessionid,resourceid,
                                                 entryid,&nextentryid, &rdr);
                                if (fdebug) printf("saHpiRdrGet[%d] rv = %d\n",entryid,rv);
                                if (rv == SA_OK) {
                                        char *eol;
                                        rdr.IdString.Data[rdr.IdString.DataLength] = 0;
                                        if (rdr.RdrType == SAHPI_SENSOR_RDR) eol = "";
                                        else eol = "\n";
                                        printf("    RDR[%6d]: %s %s %s",rdr.RecordId,
                                               rtypes[rdr.RdrType],rdr.IdString.Data,eol);
                                        if (rdr.RdrType == SAHPI_SENSOR_RDR &&
						rdr.RdrTypeUnion.SensorRec.Ignore != TRUE) {
                                                ShowSensor(sessionid,resourceid,
                                                           &rdr.RdrTypeUnion.SensorRec);
                                        } else {
						printf("Sensor ignored probably due to Resource not present\n");
					}

                                        entryid = nextentryid;
                                } else {
                                        rv = SA_OK;
                                        entryid = SAHPI_LAST_ENTRY;
                                }
                        }
                        rptentryid = nextrptentryid;
                }
        }
        
        rv = saHpiSessionClose(sessionid);
        rv = saHpiFinalize();
        
        exit(0);
        return(0);
}
Пример #13
0
/**
 * snmp_bc_discover_resources:
 * @hnd: Handler data pointer.
 *
 * Discover all the resources, sensors, controls, etc. for this instance 
 * of the plugin. Found entities are compared with what the HPI 
 * Infra-structure thinks is there and any new, deleted, or changed
 * entities are updated.
 *
 * Return values:
 * Builds/updates internal RPT cache - normal operation.
 * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory
 **/
SaErrorT snmp_bc_discover_resources(void *hnd)
{

	if (!hnd) 
		return(SA_ERR_HPI_INVALID_PARAMS);
		
        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;		
        struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;
        char *root_tuple;
	SaErrorT err = SA_OK;
        SaHpiEntityPathT ep_root;

	/* Find root Entity Path */
	root_tuple = (char *)g_hash_table_lookup(handle->config, "entity_root");
        if (root_tuple == NULL) {
                dbg("Cannot find configuration parameter.");
                return(SA_ERR_HPI_INTERNAL_ERROR);
        }
        err = string2entitypath(root_tuple, &ep_root);
        if (err) {
                dbg("Cannot convert entity path to string. Error=%s.", oh_lookup_error(err));
                return(SA_ERR_HPI_INTERNAL_ERROR);
        }

	/* Allocate space for temporary RPT cache */
	custom_handle->tmpcache = (RPTable *)g_malloc0(sizeof(RPTable));
	if (custom_handle->tmpcache == NULL) {
		dbg("Out of memory.");
		return(SA_ERR_HPI_OUT_OF_SPACE);
	}

	/* Initialize tmpqueue */
	custom_handle->tmpqueue = NULL;

	/* Individual platform discovery */
	if (custom_handle->platform == SNMP_BC_PLATFORM_RSA) {
		err = snmp_bc_discover_rsa(handle, &ep_root);
	}
	else {
		err = snmp_bc_discover(handle, &ep_root);
	}
 	if (err) {
		dbg("Discovery failed. Error=%s.", oh_lookup_error(err));
		goto CLEANUP;
	}

	/**********************************************************************
	 * Rediscovery:
	 * Get difference between current rptcache and custom_handle->tmpcache.
	 * Delete obsolete items from rptcache and add new items in.
	 **********************************************************************/
        GSList *res_new = NULL, *rdr_new = NULL, *res_gone = NULL, *rdr_gone = NULL;
        GSList *node = NULL;
        
       	rpt_diff(handle->rptcache, custom_handle->tmpcache, &res_new, &rdr_new, &res_gone, &rdr_gone);
	trace("%d resources have gone away.", g_slist_length(res_gone));
	trace("%d resources are new or have changed", g_slist_length(res_new));

        for (node = rdr_gone; node != NULL; node = node->next) {
                SaHpiRdrT *rdr = (SaHpiRdrT *)node->data;
                SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity));
                /* Create remove RDR event and add to event queue */
                struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event));
                if (e) {
			e->did = oh_get_default_domain_id();
                        e->type = OH_ET_RDR_DEL;
                        e->u.rdr_event.parent = res->ResourceId;			
			memcpy(&(e->u.rdr_event.rdr), rdr, sizeof(SaHpiRdrT));
                        handle->eventq = g_slist_append(handle->eventq, e);
                } 
		else { dbg("Out of memory."); }
                /* Remove RDR from plugin's RPT cache */
                if (rdr && res)
                        oh_remove_rdr(handle->rptcache, res->ResourceId, rdr->RecordId);
                else { dbg("No valid resource or rdr at hand. Could not remove rdr."); }
        }

        g_slist_free(rdr_gone);

        for (node = res_gone; node != NULL; node = node->next) {
                SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data;
		/* Create remove resource event and add to event queue */
		struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event));
                if (e) {
			e->did = oh_get_default_domain_id();
                        e->type = OH_ET_RESOURCE_DEL;

                        e->u.res_event.entry.ResourceId = res->ResourceId;
                        handle->eventq = g_slist_append(handle->eventq, e);
                } else { dbg("Out of memory."); }
		/* Remove resource from plugin's RPT cache */
                if (res)
                        oh_remove_resource(handle->rptcache, res->ResourceId);
                else dbg("No valid resource at hand. Could not remove resource.");
        }

        g_slist_free(res_gone);

        for (node = res_new; node != NULL; node = node->next) {
                GSList *tmpnode = NULL;
                SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data;
                if (!res) {
                        dbg("No valid resource at hand. Could not process new resource.");
                        continue;
                }
                gpointer data = oh_get_resource_data(custom_handle->tmpcache, res->ResourceId);
                oh_add_resource(handle->rptcache, res, g_memdup(data, sizeof(struct snmp_rpt)),0);
                /* Add new/changed resources to the event queue */
                for (tmpnode = custom_handle->tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) {
                        struct oh_event *e = (struct oh_event *)tmpnode->data;
                        if (e->type == OH_ET_RESOURCE &&
                            e->u.res_event.entry.ResourceId == res->ResourceId) {
                                handle->eventq = g_slist_append(handle->eventq, e);
                                custom_handle->tmpqueue = g_slist_remove_link(custom_handle->tmpqueue, tmpnode);
				g_slist_free_1(tmpnode);
                                break;
                        }
                }
        }
        g_slist_free(res_new);
        
        for (node = rdr_new; node != NULL; node = node->next) {
                guint rdr_data_size = 0;
                GSList *tmpnode = NULL;
                SaHpiRdrT *rdr = (SaHpiRdrT *)node->data;
                SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity));
                if (!res || !rdr) {
                        dbg("No valid resource or rdr at hand. Could not process new rdr.");
                        continue;
                }
                gpointer data = oh_get_rdr_data(custom_handle->tmpcache, res->ResourceId, rdr->RecordId);
                /* Need to figure out the size of the data associated with the rdr */
                if (rdr->RdrType == SAHPI_SENSOR_RDR) rdr_data_size = sizeof(struct SensorInfo);
                else if (rdr->RdrType == SAHPI_CTRL_RDR)
                        rdr_data_size = sizeof(struct ControlInfo);
                else if (rdr->RdrType == SAHPI_INVENTORY_RDR)
                        rdr_data_size = sizeof(struct InventoryInfo);
                oh_add_rdr(handle->rptcache, res->ResourceId, rdr, g_memdup(data, rdr_data_size),0);
                /* Add new/changed rdrs to the event queue */
                for (tmpnode = custom_handle->tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) {
                        struct oh_event *e = (struct oh_event *)tmpnode->data;
                        if (e->type == OH_ET_RDR &&
                            ep_cmp(&(e->u.rdr_event.rdr.Entity),&(rdr->Entity)) == 0 &&
                            e->u.rdr_event.rdr.RecordId == rdr->RecordId) {
                                handle->eventq = g_slist_append(handle->eventq, e);
                                custom_handle->tmpqueue = g_slist_remove_link(custom_handle->tmpqueue, tmpnode);
				g_slist_free_1(tmpnode);
                                break;
                        }
                }
        }        
        g_slist_free(rdr_new);

	/* FIXME:: RSA doesn't have??? */
	/* Build cache copy of SEL */
	snmp_bc_check_selcache(handle, 1, SAHPI_NEWEST_ENTRY);

 CLEANUP:        
        g_slist_free(custom_handle->tmpqueue);
        oh_flush_rpt(custom_handle->tmpcache);  
	g_free(custom_handle->tmpcache);

        return(err);
}