Esempio n. 1
0
/**
 * rpt_diff
 * @cur_rpt: IN. Pointer to RPTable that represents the current state of resources
 * and rdrs.
 * @new_rpt: IN. Pointer to RPTable that contains rpt entries and rdrs just recently
 * discovered.
 * @res_new: OUT. List of new or changed rpt entries
 * @rdr_new: OUT. List of new or changed rdrs
 * @res_gone: OUT. List of old and not present resources.
 * @rdr_gone: OUT. List of old and not present rdrs.
 *
 * Extracts from current the resources and rdrs that are not found
 * in new and puts them in res_gone and rdr_gone. Also, puts in res_new and rdr_new
 * the resources and rdrs that are not already in current Or that are not identical
 * to the ones in current.
 *
 * Returns: void.
 **/
void rpt_diff(RPTable *cur_rpt, RPTable *new_rpt,
              GSList **res_new, GSList **rdr_new,
              GSList **res_gone, GSList **rdr_gone) {

        SaHpiRptEntryT *res = NULL;

        if (!cur_rpt || !new_rpt ||
            !res_new || !rdr_new || !res_gone || !rdr_gone) return;

        /* Look for absent resources and rdrs */
        for (res = oh_get_resource_by_id(cur_rpt, SAHPI_FIRST_ENTRY);
             res != NULL;
             res = oh_get_resource_next(cur_rpt, res->ResourceId)) {

                SaHpiRptEntryT *tmp_res = oh_get_resource_by_id(new_rpt, res->ResourceId);

                if (tmp_res == NULL) *res_gone = g_slist_append(*res_gone, (gpointer)res);
                else {
                        SaHpiRdrT *rdr = NULL;

                        for (rdr = oh_get_rdr_by_id(cur_rpt, res->ResourceId, SAHPI_FIRST_ENTRY);
                             rdr != NULL;
                             rdr = oh_get_rdr_next(cur_rpt, res->ResourceId, rdr->RecordId)) {

                                SaHpiRdrT *tmp_rdr =
                                        oh_get_rdr_by_id(new_rpt, res->ResourceId, rdr->RecordId);

                                if (tmp_rdr == NULL)
                                        *rdr_gone = g_slist_append(*rdr_gone, (gpointer)rdr);
                        }
                }
        }

        /* Look for new resources and rdrs*/
        for (res = oh_get_resource_by_id(new_rpt, SAHPI_FIRST_ENTRY);
             res != NULL;
             res = oh_get_resource_next(new_rpt, res->ResourceId)) {

                SaHpiRptEntryT *tmp_res = oh_get_resource_by_id(cur_rpt, res->ResourceId);
                SaHpiRdrT *rdr = NULL;
                if (tmp_res == NULL || memcmp(res, tmp_res, sizeof(SaHpiRptEntryT))) {
                        *res_new = g_slist_append(*res_new, (gpointer)res);
                }

                for (rdr = oh_get_rdr_by_id(new_rpt, res->ResourceId, SAHPI_FIRST_ENTRY);
                     rdr != NULL;
                     rdr = oh_get_rdr_next(new_rpt, res->ResourceId, rdr->RecordId)) {

                        SaHpiRdrT *tmp_rdr = NULL;

                        if (tmp_res != NULL)
                                tmp_rdr = oh_get_rdr_by_id(cur_rpt, res->ResourceId, rdr->RecordId);

                        if (tmp_rdr == NULL || memcmp(rdr, tmp_rdr, sizeof(SaHpiRdrT)))
                                *rdr_new = g_slist_append(*rdr_new, (gpointer)rdr);

                }
        }
}
Esempio n. 2
0
/**
 * main: Starts with an RPTable of 10 resources, adds 1 rdr
 * to first resource. Fetches rdr 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));
        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, rdrs, NULL,0))
                return 1;

        record_id =
                get_rdr_uid(rdrs[0].RdrType, rdrs[0].RdrTypeUnion.SensorRec.Num);
        rdrs[0].RecordId = record_id;
                
        tmprdr = oh_get_rdr_by_id(rptable, SAHPI_FIRST_ENTRY, record_id);
        if (!tmprdr ||
            memcmp(rdrs, tmprdr, sizeof(SaHpiRdrT)))
                return 1;

        return 0;
}
Esempio n. 3
0
/**
 * 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;
}
Esempio n. 4
0
/**
 * oh_remove_resource
 * @table: Pointer to the RPT from which an RPT entry will be removed.
 * @rid: Resource id of the RPT entry to be removed.
 *
 * Remove a resource from the RPT. If the @rid is
 * %SAHPI_FIRST_ENTRY, the first RPT entry in the table will be removed.
 * The void data will be freed if @owndata was false (%FREE_RPT_DATA) when adding
 * the resource, otherwise if @owndata was true (%KEEP_RPT_DATA) it will not be freed.
 *
 * Returns: SA_OK on success Or minus SA_OK on error.
 **/
SaErrorT oh_remove_resource(RPTable *table, SaHpiResourceIdT rid)
{
        RPTEntry *rptentry;

        rptentry = get_rptentry_by_rid(table, rid);
        if (!rptentry) {
                dbg("Failed to remove RPT entry. No Resource found by that id");
                return SA_ERR_HPI_NOT_PRESENT;
        } else {
                SaHpiRdrT *tmp_rdr;
                /* Remove all RDRs for the resource first */
                while ((tmp_rdr = oh_get_rdr_by_id(table, rid, SAHPI_FIRST_ENTRY)) != NULL) {
                        oh_remove_rdr(table, rid, SAHPI_FIRST_ENTRY);
                }
                /* then remove the resource itself. */
                table->rptlist = g_slist_remove(table->rptlist, (gpointer)rptentry);
                if (!rptentry->owndata) g_free(rptentry->data);
                g_hash_table_remove(table->rptable, &(rptentry->rpt_entry.EntryId));
                g_free((gpointer)rptentry);
                if (!table->rptlist) {
                        g_hash_table_destroy(table->rptable);
                        table->rptable = NULL;
                }
        }

        update_rptable(table);

        return SA_OK;
}
Esempio n. 5
0
/**
 * oh_remove_resource
 * @table: Pointer to the RPT from which an RPT entry will be removed.
 * @rid: Resource id of the RPT entry to be removed.
 *
 * Remove a resource from the RPT. If the @rid is
 * %SAHPI_FIRST_ENTRY, the first RPT entry in the table will be removed.
 * The void data will be freed if @owndata was false (%FREE_RPT_DATA) when adding
 * the resource, otherwise if @owndata was true (%KEEP_RPT_DATA) it will not be freed.
 * 
 * Returns:
 * 0 - Successful removal from the RPT.
 * -1 - table pointer is NULL.
 * -2 - Failure. No resource found by that id.
 **/
int oh_remove_resource(RPTable *table, SaHpiResourceIdT rid)
{
        RPTEntry *rptentry;

        if (!table) {
                dbg("ERROR: Cannot work on a null table pointer.");
                return -1;
        }

        rptentry = get_rptentry_by_rid(table, rid);
        if (!rptentry) {
                dbg("Failed to remove RPT entry. No Resource found by that id");
                return -2;
        } else {
                SaHpiRdrT *tmp_rdr;
                /* Remove all RDRs for the resource first */
                while ((tmp_rdr = oh_get_rdr_by_id(table, rid, SAHPI_FIRST_ENTRY)) != NULL) {
                        oh_remove_rdr(table, rid, SAHPI_FIRST_ENTRY);
                }
                /* then remove the resource itself. */
                table->rptable = g_slist_remove(table->rptable, (gpointer)rptentry);
                if (!rptentry->owndata) g_free(rptentry->data);
                g_free((gpointer)rptentry);
        }

        update_rptable(table);

        return 0;
}
Esempio n. 6
0
/**
 * Generate an event if the enabling / mask of the sensor was changed 
 **/
void NewSimulatorSensor::CreateEnableChangeEvent()
{
  NewSimulatorResource *res = Resource();
  if( !res )
     {
       stdlog << "CreateEnableChangeEvent: No resource !\n";
       return;
     }

  oh_event *e = (oh_event *)g_malloc0( sizeof( struct oh_event ) );
  
  e->event.EventType = SAHPI_ET_SENSOR_ENABLE_CHANGE;

  SaHpiRptEntryT *rptentry = oh_get_resource_by_id( res->Domain()->GetHandler()->rptcache, res->ResourceId() );
  SaHpiRdrT *rdrentry = oh_get_rdr_by_id( res->Domain()->GetHandler()->rptcache, res->ResourceId(), m_record_id );

  if ( rptentry )
      e->resource = *rptentry;
  else
      e->resource.ResourceCapabilities = 0;

  if ( rdrentry )
      e->rdrs = g_slist_append(e->rdrs, g_memdup(rdrentry, sizeof(SaHpiRdrT)));
  else
      e->rdrs = NULL;

  // hpi events
  e->event.Source    = res->ResourceId();
  e->event.EventType = SAHPI_ET_SENSOR_ENABLE_CHANGE;
  e->event.Severity  = SAHPI_INFORMATIONAL;
  
  oh_gettimeofday(&e->event.Timestamp);
  
  // sensor enable event
  SaHpiSensorEnableChangeEventT *se = &e->event.EventDataUnion.SensorEnableChangeEvent;
  se->SensorNum     = m_sensor_record.Num;
  se->SensorType    = Type();
  se->EventCategory = EventCategory();
  se->SensorEnable  = m_enabled;
  se->SensorEventEnable = m_events_enabled;
  se->AssertEventMask   = m_assert_mask;
  se->DeassertEventMask = m_deassert_mask;
  
  stdlog << "NewSimulatorSensor::CreateEnableChangeEvent OH_ET_HPI Event enable change resource " << res-> ResourceId() << "\n";
  res->Domain()->AddHpiEvent( e );

  return;
}
Esempio n. 7
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;
}
Esempio n. 8
0
/**
 * main: Starts with an RPTable of 10 resources, adds 5 rdr
 * to first resource. Fetches sensors ++randomly 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);
        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, sensors + i, NULL,0))
                        return 1;
                else
                        records = g_slist_append(records, sensors + 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_id(rptable, SAHPI_FIRST_ENTRY,
                                          randrdr->RecordId);

                if (!tmprdr ||
                    memcmp(randrdr, tmprdr, sizeof(SaHpiRdrT)))
                        return 1;
                else {
                        records = g_slist_remove_link(records, tmpnode);
                        g_slist_free_1(tmpnode);
                }
        }

        return 0;
}
Esempio n. 9
0
/**
 * main: Starts with an RPTable of 1 resource, adds 5 sensors ++to first resource.
 * Fetches an rdr by id using SAHPI_FIRST_ENTRY for the Record Id.
 * Success if the interface returns 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));
        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, sensors+i, NULL, 1))
                        return 1;
        }

        if (!oh_get_rdr_by_id(rptable, rptentries[0].ResourceId, SAHPI_FIRST_ENTRY))
                return 1;

        return 0;
}
Esempio n. 10
0
/**
 * Send a watchdog event
 * 
 * @param wdtaction watchdog action event flag to be set
 * @param sev severity of event to be set 
 **/
void NewSimulatorWatchdog::SendEvent( SaHpiWatchdogActionEventT wdtaction, SaHpiSeverityT sev ) {

   NewSimulatorResource *res = Resource();
   if( !res ) {
      stdlog << "DBG: Watchdog::TriggerAction: No resource !\n";
      return;
   }
  
   oh_event *e = (oh_event *)g_malloc0( sizeof( struct oh_event ) );

   e->event.EventType = SAHPI_ET_WATCHDOG;

   SaHpiRptEntryT *rptentry = oh_get_resource_by_id( res->Domain()->GetHandler()->rptcache, res->ResourceId() );
   SaHpiRdrT *rdrentry = oh_get_rdr_by_id( res->Domain()->GetHandler()->rptcache, res->ResourceId(), m_record_id );

   if ( rptentry )
      e->resource = *rptentry;
   else
      e->resource.ResourceCapabilities = 0;

   if ( rdrentry )
      e->rdrs = g_slist_append(e->rdrs, g_memdup(rdrentry, sizeof(SaHpiRdrT)));
   else
      e->rdrs = NULL;

   // hpi events
   e->event.Source    = res->ResourceId();
   e->event.EventType = SAHPI_ET_WATCHDOG;
   e->event.Severity  = sev;
  
   oh_gettimeofday(&e->event.Timestamp);
  
   SaHpiWatchdogEventT *wdte = &e->event.EventDataUnion.WatchdogEvent;
   wdte->WatchdogNum            = m_wdt_rec.WatchdogNum;
   wdte->WatchdogAction         = wdtaction;
   wdte->WatchdogPreTimerAction = m_wdt_data.PretimerInterrupt;
   wdte->WatchdogUse            = m_wdt_data.TimerUse;
  
   stdlog << "DBG: NewSimWatchdog::SendEvent Wdt for resource " << res->ResourceId() << "\n";
   res->Domain()->AddHpiEvent( e );

}
Esempio n. 11
0
/**
 * oh_remove_resource: Remove a resource from the RPT. If the rid is
 * RPT_ENTRY_BEGIN (0xffffffff), the first RPT entry in the table will be removed.
 * @table: Pointer to the RPT from which an RPT entry will be removed.
 * @rid: Resource id of the RPT entry to be removed.
 *
 * Return value:
 * 0 - Successful removal from the RPT.
 * -2 - Failure. No resource found by that id.
 **/
int oh_remove_resource(RPTable *table, SaHpiResourceIdT rid)
{
        RPTEntry *rptentry;

        rptentry = get_rptentry_by_rid(table, rid);
        if (!rptentry) {
                dbg("Failed to remove RPT entry. No Resource found by that id");
                return -2;
        } else {
                SaHpiRdrT *tmp_rdr;
                /* Remove all RDRs for the resource first */
                while ((tmp_rdr = oh_get_rdr_by_id(table, rid, RDR_BEGIN)) != NULL) {
                        oh_remove_rdr(table, rid, RDR_BEGIN);
                }
                /* then remove the resource itself. */
                table->rptable = g_slist_remove(table->rptable, (gpointer)rptentry);
                g_free((gpointer)rptentry);
        }

        update_rptable(table, RPT_DECREMENT);

        return 0;
}
Esempio n. 12
0
/**
 * snmp_bc_add_entry_to_elcache
 * @hnd: Pointer to handler's data.
 * @id: Resource's ID that owns Event Log.
 * @current: Current Event Log entry ID.
 *
 *  Add event to Event Log.
 *
 * Return values:
 * SA_OK - normal operation.
 * SA_ERR_HPI_INVALID_PARAMS - @hnd is NULL.
 **/
SaErrorT snmp_bc_add_entry_to_elcache(struct oh_handler_state *handle,
                                      SaHpiEventT *tmpevent,
                                      SaHpiBoolT prepend)
{

    SaHpiEntryIdT rdrid;
    SaHpiRdrT rdr, *rdr_ptr;
    struct snmp_bc_hnd *custom_handle;
    SaHpiResourceIdT id;
    SaErrorT err;


    if (!handle) {
        err("Invalid parameter.");
        return(SA_ERR_HPI_INVALID_PARAMS);
    }

    rdrid=0;
    rdr_ptr=NULL;
    custom_handle = (struct snmp_bc_hnd *)handle->data;

    /* See feature 1077241 */
    switch (tmpevent->EventType) {
    case SAHPI_ET_OEM:
    case SAHPI_ET_HOTSWAP:
    case SAHPI_ET_USER:
        memset(&rdr, 0, sizeof(SaHpiRdrT));
        /* There is no RDR associated to OEM event */
        rdr.RdrType = SAHPI_NO_RECORD;
        /* Set RDR Type to SAHPI_NO_RECORD, spec B-01.01 */
        /* It is redundant because SAHPI_NO_RECORD == 0  */
        /* This code is here for clarity.                */
        rdr_ptr = &rdr;

        break;
    case SAHPI_ET_SENSOR:
        rdrid = oh_get_rdr_uid(SAHPI_SENSOR_RDR,
                               tmpevent->EventDataUnion.SensorEvent.SensorNum);
        rdr_ptr = oh_get_rdr_by_id(handle->rptcache, tmpevent->Source, rdrid);
        break;
    case SAHPI_ET_WATCHDOG:
        rdrid = oh_get_rdr_uid(SAHPI_WATCHDOG_RDR,
                               tmpevent->EventDataUnion.WatchdogEvent.WatchdogNum);
        rdr_ptr = oh_get_rdr_by_id(handle->rptcache, tmpevent->Source, rdrid);
        break;
    default:
        err("Unrecognized Event Type=%d.", tmpevent->EventType);
        return(SA_ERR_HPI_INTERNAL_ERROR);
        break;
    }


    /* Since oh_el_append() does a copy of RES and RDR into it own data struct, */
    /* just pass the pointers to it.                                            */
    id = tmpevent->Source;
    if (NULL == oh_get_resource_by_id(handle->rptcache, id)) {
        dbg("Warning: NULL RPT for rid %d.", id);
    }

    if (prepend)
        err = oh_el_prepend(handle->elcache, tmpevent,
                            rdr_ptr, oh_get_resource_by_id(handle->rptcache, id));
    else
        err = oh_el_append(handle->elcache, tmpevent,
                           rdr_ptr, oh_get_resource_by_id(handle->rptcache, id));


    /* If can not add el entry to elcache, do not add entry to eventq */
    /* If entry is not added to elcache and is added to eventq, there */
    /* will be an indefinite loop:                                    */
    /*        1. get_event is called. get_event call elcache_sync     */
    /*        2. elcache_sync finds new el entry                      */
    /*        3a. adding new el entry to elcache fails                */
    /*	  3b. adding new el entry to eventq                       */
    /*	  4. new event is propergate to infrastructure            */
    /*	  5. infrastructure consume new event                     */
    /*	  		*and*  call get_event for any more        */
    /*	  6. we repeat step 1 ... indefinite loop                 */

    if (!err) {
        if (custom_handle->isFirstDiscovery == SAHPI_FALSE)
            err = snmp_bc_add_to_eventq(handle, tmpevent, prepend);
        if (err)
            err("Cannot add el entry to eventq. Error=%s.", oh_lookup_error(err));
    } else {
        err("Cannot add el entry to elcache. Error=%s.", oh_lookup_error(err));
    }

    return(err);


}
Esempio n. 13
0
/**
 * snmp_bc_sel_read_add:
 * @hnd: Pointer to handler's data. 
 * @id: Resource's ID that owns Event Log.
 * @current: Current Event Log entry ID.
 * 
 *  Add event to Event Log.
 * 
 * Return values:
 * SA_OK - normal operation.
 * SA_ERR_HPI_INVALID_PARAMS - @hnd is NULL.
 **/
SaErrorT snmp_bc_sel_read_add (struct oh_handler_state *handle,
			       SaHpiResourceIdT id, 
			       SaHpiEventLogEntryIdT current, 
			       SaHpiBoolT prepend)
{
	int isdst=0;
        char oid[SNMP_BC_MAX_OID_LENGTH];
	sel_entry sel_entry;

	SaErrorT err;
        SaHpiEventT tmpevent;
	SaHpiEntryIdT rdrid=0;
	SaHpiRdrT rdr, *rdr_ptr=NULL; 

        struct snmp_value get_value;

	if (!handle) {
		dbg("Invalid parameter.");
		return(SA_ERR_HPI_INVALID_PARAMS);
	}
        struct snmp_bc_hnd *custom_handle = handle->data;

	if (custom_handle->platform == SNMP_BC_PLATFORM_RSA) {
		snprintf(oid, SNMP_BC_MAX_OID_LENGTH, "%s.%d",
			 SNMP_BC_SEL_ENTRY_OID_RSA, current);
	}
	else {
		snprintf(oid, SNMP_BC_MAX_OID_LENGTH, "%s.%d",
			 SNMP_BC_SEL_ENTRY_OID, current);
	}

	err = snmp_bc_snmp_get(custom_handle, oid, &get_value, SAHPI_TRUE);
	if (err != SA_OK)
		 return(err); 
	else if ((err == SA_OK) && (get_value.type != ASN_OCTET_STR)) {
		dbg("Cannot get EL entry");
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}

	err = snmp_bc_parse_sel_entry(handle,get_value.string, &sel_entry);
	if (err != SA_OK) return(err);
		
	if (strncmp(get_value.string, EVT_EN_LOG_FULL, sizeof(EVT_EN_LOG_FULL)) == 0 )
		 handle->elcache->overflow = SAHPI_TRUE;
		 
	isdst = sel_entry.time.tm_isdst;
	snmp_bc_log2event(handle, get_value.string, &tmpevent, isdst);
	
	/* See feature 1077241 */
	switch (tmpevent.EventType) {
		case SAHPI_ET_OEM:
		case SAHPI_ET_HOTSWAP:
		case SAHPI_ET_USER:
                        memset(&rdr, 0, sizeof(SaHpiRdrT));
                                        /* There is no RDR associated to OEM event */
                        rdr.RdrType = SAHPI_NO_RECORD;
                                          /* Set RDR Type to SAHPI_NO_RECORD, spec B-01.01 */
                                          /* It is redundant because SAHPI_NO_RECORD == 0  */
                                          /* This code is here for clarity.                */
                        rdr_ptr = &rdr;

			break;		  
		case SAHPI_ET_SENSOR:
			rdrid = get_rdr_uid(SAHPI_SENSOR_RDR,
					    tmpevent.EventDataUnion.SensorEvent.SensorNum); 
			rdr_ptr = oh_get_rdr_by_id(handle->rptcache, tmpevent.Source, rdrid);
			break;
		case SAHPI_ET_WATCHDOG:
			rdrid = get_rdr_uid(SAHPI_WATCHDOG_RDR,
					    tmpevent.EventDataUnion.WatchdogEvent.WatchdogNum);
			rdr_ptr = oh_get_rdr_by_id(handle->rptcache, tmpevent.Source, rdrid);
			break;
		default:
			dbg("Unrecognized Event Type=%d.", tmpevent.EventType);
			return(SA_ERR_HPI_INTERNAL_ERROR);
			break;
	} 

	/* Since oh_el_append() does a copy of RES and RDR into it own data struct, */ 
	/* just pass the pointers to it.                                            */
	id = tmpevent.Source;
	if (NULL == oh_get_resource_by_id(handle->rptcache, id))
					dbg("NULL RPT for rid %d.", id);
	if (prepend) 
		err = oh_el_prepend(handle->elcache, &tmpevent,
			    rdr_ptr, oh_get_resource_by_id(handle->rptcache, id));
	else 
		err = oh_el_append(handle->elcache, &tmpevent,
			    rdr_ptr, oh_get_resource_by_id(handle->rptcache, id));
	
	
	/* If can not add el entry to elcache, do not add entry to eventq */
	/* If entry is not added to elcache and is added to eventq, there */
	/* will be an indefinite loop:                                    */
	/*        1. get_event is called. get_event call elcache_sync     */
	/*        2. elcache_sync finds new el entry                      */
	/*        3a. adding new el entry to elcache fails                */
	/*	  3b. adding new el entry to eventq                       */
	/*	  4. new event is propergate to infrastructure            */
	/*	  5. infrastructure consume new event                     */
	/*	  		*and*  call get_event for any more        */
	/*	  6. we repeat step 1 ... indefinite loop                 */   
	
	if (!err) {
		err = snmp_bc_add_to_eventq(handle, &tmpevent);
		if (err) 
		 dbg("Cannot add el entry to eventq. Error=%s.", oh_lookup_error(err));
	} else { 
	 	dbg("Cannot add el entry to elcache. Error=%s.", oh_lookup_error(err));
	}
			
        return(err);
}
Esempio n. 14
0
/**
 * snmp_bc_sel_read_add:
 * @hnd: Pointer to handler's data. 
 * @id: Resource's ID that owns Event Log.
 * @current: Current Event Log entry ID.
 * 
 *  Add event to Event Log.
 * 
 * Return values:
 * SA_OK - normal operation.
 * SA_ERR_HPI_INVALID_PARAMS - @hnd is NULL.
 **/
SaErrorT snmp_bc_sel_read_add (struct oh_handler_state *handle,
			       SaHpiResourceIdT id, 
			       SaHpiEventLogEntryIdT current)
{
	int isdst=0;
        char oid[SNMP_BC_MAX_OID_LENGTH];
	sel_entry sel_entry;

	SaErrorT err;
        SaHpiEventT tmpevent;
	SaHpiEntryIdT rdrid=0;
	SaHpiRdrT rdr, *rdr_ptr=NULL; 

        struct snmp_value get_value;

	if (!handle) {
		dbg("Invalid parameter.");
		return(SA_ERR_HPI_INVALID_PARAMS);
	}
        struct snmp_bc_hnd *custom_handle = handle->data;

	snprintf(oid, SNMP_BC_MAX_OID_LENGTH, "%s.%d", SNMP_BC_SEL_ENTRY_OID, current);
	err = snmp_get(custom_handle->ss, oid, &get_value);
	if (err != SA_OK)
		 return(err); 
	else if ((err == SA_OK) && (get_value.type != ASN_OCTET_STR)) {
		dbg("Cannot get EL entry");
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}

	err = snmp_bc_parse_sel_entry(handle,get_value.string, &sel_entry);
	if (err != SA_OK) return(err);
		
	if (strncmp(get_value.string, EVT_EN_LOG_FULL, sizeof(EVT_EN_LOG_FULL) == 0))
		 handle->elcache->overflow = SAHPI_TRUE;
		 
	isdst = sel_entry.time.tm_isdst;
	snmp_bc_log2event(handle, get_value.string, &tmpevent, isdst);
		
/* FIXME:: Nice to have an event to rdr pointer function - this same code appears in snmp_bc_event.c */
/* in rpt_utils.c ??? */		
/* FIXME:: Add B.1.1. types */		
	switch (tmpevent.EventType) {
		case SAHPI_ET_OEM:
		case SAHPI_ET_HOTSWAP:
		case SAHPI_ET_USER:
                        memset(&rdr, 0, sizeof(SaHpiRdrT));
                                        /* There is no RDR associated to OEM event */
                        rdr.RdrType = SAHPI_NO_RECORD;
                                          /* Set RDR Type to SAHPI_NO_RECORD, spec B-01.01 */
                                          /* It is redundant because SAHPI_NO_RECORD == 0  */
                                          /* This code is here for clarity.                */
                        rdr_ptr = &rdr;

			break;		  
		case SAHPI_ET_SENSOR:
			rdrid = get_rdr_uid(SAHPI_SENSOR_RDR,
					    tmpevent.EventDataUnion.SensorEvent.SensorNum); 
			rdr_ptr = oh_get_rdr_by_id(handle->rptcache, tmpevent.Source, rdrid);
			break;
		case SAHPI_ET_WATCHDOG:
			rdrid = get_rdr_uid(SAHPI_WATCHDOG_RDR,
					    tmpevent.EventDataUnion.WatchdogEvent.WatchdogNum);
			rdr_ptr = oh_get_rdr_by_id(handle->rptcache, tmpevent.Source, rdrid);
			break;
		default:
			dbg("Unrecognized Event Type=%d.", tmpevent.EventType);
			return(SA_ERR_HPI_INTERNAL_ERROR);
			break;
	} 

	/* Since oh_el_append() does a copy of RES and RDR into it own data struct, */ 
	/* just pass the pointers to it.                                            */
	id = tmpevent.Source;
	if (NULL == oh_get_resource_by_id(handle->rptcache, id))
					dbg("NULL RPT for rid %d.", id);
	err = oh_el_append(handle->elcache, &tmpevent,
			rdr_ptr, oh_get_resource_by_id(handle->rptcache, id));
	
	if (err) dbg("Cannot add entry to elcache. Error=%s.", oh_lookup_error(err));
		
	err = snmp_bc_add_to_eventq(handle, &tmpevent);
			
        return(err);
}
Esempio n. 15
0
 /**
 * snmp_bc_add_to_eventq
 * @handle: Pointer to handler's data.
 * @thisEvent: Location to store event.
 *
 * Add event to Infrastructure's event queue.
 *
 * Return values:
 * SA_OK - normal case.
 * SA_ERR_HPI_INVALID_PARAMS - @handle or @thisEvent is NULL.
 **/
SaErrorT snmp_bc_add_to_eventq(struct oh_handler_state *handle, SaHpiEventT *thisEvent)
{
	SaHpiEntryIdT rdrid=0;
        struct oh_event working;
        struct oh_event *e = NULL;
	SaHpiRptEntryT *thisRpt;
	
        memset(&working, 0, sizeof(struct oh_event));

	working.did = oh_get_default_domain_id();
	working.type = OH_ET_HPI;
	
	thisRpt = oh_get_resource_by_id(handle->rptcache, thisEvent->Source);
        if (thisRpt) 
		working.u.hpi_event.res = *thisRpt;
	else 
		dbg("NULL Rpt pointer for rid %d\n", thisEvent->Source);

        memcpy(&working.u.hpi_event.event, thisEvent, sizeof(SaHpiEventT));

	/* FIXME:: Merged with same type of code in snmp_bc_sel.c 
           to create common function???? */
	   
	/* FIXME:: Add other B.1.1 event types */
	/*   SAHPI_ET_RESOURCE                 */
	/*   SAHPI_ET_DOMAIN                   */
	/*   SAHPI_ET_SENSOR_ENABLE_CHANGE     */
	/*   SAHPI_ET_HPI_SW                   */
	/* ----------------------------------- */

	/* Setting RDR ID to event struct */	
	switch (thisEvent->EventType) {
		case SAHPI_ET_OEM:
		case SAHPI_ET_HOTSWAP:
		case SAHPI_ET_USER:
			/* FIXME:: this case a bit differ than snmp_bc_sel.c - have function 
		   	just return NULL. If need to set RecordId = 0, let caller do this */
			working.u.hpi_event.rdr.RecordId = 0; /* There is no RDR associated to OEM event */
			break;			              /* Set RDR ID to invalid value of 0        */
		case SAHPI_ET_SENSOR:
			rdrid = get_rdr_uid(SAHPI_SENSOR_RDR,
				    thisEvent->EventDataUnion.SensorEvent.SensorNum); 
			working.u.hpi_event.rdr = *(oh_get_rdr_by_id(handle->rptcache, thisEvent->Source, rdrid));
			break;
		case SAHPI_ET_WATCHDOG:
			rdrid = get_rdr_uid(SAHPI_WATCHDOG_RDR,
				    thisEvent->EventDataUnion.WatchdogEvent.WatchdogNum);
			working.u.hpi_event.rdr = *(oh_get_rdr_by_id(handle->rptcache, thisEvent->Source, rdrid));
			break;
		default:
			dbg("Unrecognized Event Type=%d.", thisEvent->EventType);
			return(SA_ERR_HPI_INTERNAL_ERROR);
			break;
	} 

        /* Insert entry to eventq for processing */
        e = g_malloc0(sizeof(struct oh_event));
        if (!e) {
                dbg("Out of memory.");
                return(SA_ERR_HPI_OUT_OF_SPACE);
        }
        memcpy(e, &working, sizeof(struct oh_event));
        handle->eventq = g_slist_append(handle->eventq, e);

        return(SA_OK);
}
Esempio n. 16
0
/**
 * snmp_bc_sel_read_add:
 * @hnd: Pointer to handler's data. 
 * @id: Resource's ID that owns Event Log.
 * @current: Current Event Log entry ID.
 * 
 *  Add event to Event Log.
 * 
 * Return values:
 * SA_OK - normal operation.
 * SA_ERR_HPI_INVALID_PARAMS - @hnd is NULL.
 **/
SaErrorT snmp_bc_sel_read_add (struct oh_handler_state *handle,
			       SaHpiResourceIdT id, 
			       SaHpiEventLogEntryIdT current)
{

	int isdst=0;
	int event_enabled;
        char oid[SNMP_BC_MAX_OID_LENGTH];
	bc_sel_entry sel_entry;

	SaErrorT err;
        SaHpiEventT tmpevent;
	SaHpiEntryIdT rdrid=0;
	SaHpiRdrT *rdr_ptr=NULL; 

        struct snmp_value get_value;
        struct snmp_bc_hnd *custom_handle = handle->data;

	if (!handle) {
		dbg("Invalid parameters.");
		return(SA_ERR_HPI_INVALID_PARAMS);
	}

	snprintf(oid, SNMP_BC_MAX_OID_LENGTH, "%s.%d", SNMP_BC_SEL_ENTRY_OID, current);
	err = snmp_get(custom_handle->ss, oid, &get_value);
	if (err != SA_OK)
		 return(err); 
	else if ((err == SA_OK) && (get_value.type != ASN_OCTET_STR)) {
		dbg("Cannot get EL entry");
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}

	err = snmp_bc_parse_sel_entry(handle,get_value.string, &sel_entry);
	if (err != SA_OK) return(err);
		
	isdst = sel_entry.time.tm_isdst;
	snmp_bc_log2event(handle, get_value.string, &tmpevent, isdst, &event_enabled);
		
/* FIXME:: Nice to have an event to rdr pointer function - this same code appears in snmp_bc_event.c */
/* in rpt_utils.c ??? */		
/* FIXME:: Add B.1.1. types */		
	switch (tmpevent.EventType) {
		case SAHPI_ET_OEM:
		case SAHPI_ET_HOTSWAP:
		case SAHPI_ET_USER:
			/* FIXME:: Why do this - just set rdr_ptr = NULL ??? */
			/* rdr storage is temporary */
			#if 0
			rdr.RecordId = 0; /* There is no RDR associated to OEM event */
                                          /* Set RDR ID to invalid value of 0        */
			#endif
			rdr_ptr = NULL;
			break;		  
		case SAHPI_ET_SENSOR:
			rdrid = get_rdr_uid(SAHPI_SENSOR_RDR,
					    tmpevent.EventDataUnion.SensorEvent.SensorNum); 
			rdr_ptr = oh_get_rdr_by_id(handle->rptcache, tmpevent.Source, rdrid);
			break;
		case SAHPI_ET_WATCHDOG:
			rdrid = get_rdr_uid(SAHPI_WATCHDOG_RDR,
					    tmpevent.EventDataUnion.WatchdogEvent.WatchdogNum);
			rdr_ptr = oh_get_rdr_by_id(handle->rptcache, tmpevent.Source, rdrid);
			break;
		default:
			dbg("Unrecognized Event Type=%d.", tmpevent.EventType);
			return(SA_ERR_HPI_INTERNAL_ERROR);
			break;
	} 

	/* Since oh_el_append() does a copy of RES and RDR into it own data struct, */ 
	/* just pass the pointers to it.                                            */
	err = oh_el_append(handle->elcache, &tmpevent,
			rdr_ptr, oh_get_resource_by_id(handle->rptcache, id));
	
	if (err != SA_OK)
		 dbg("Err adding entry to elcache, error %s\n", oh_lookup_error(err));
		
	if (event_enabled)
		err = snmp_bc_add_to_eventq(handle, &tmpevent);
			
        return(err);
}