예제 #1
0
파일: session.c 프로젝트: openhpi1/testrepo
static void* get_event(void *unused)
{
	SaHpiEventT	event;
	SaErrorT	rv;        

	rv = saHpiSubscribe(Domain->sessionId);
	if (rv != SA_OK) {
		printf("OpenHPI>Fail to Subscribe event\n");
		return (void *)0;
	}	
	
	while(1) {
		for(;;) {
			memset(&event, 0xF, sizeof(event));
			rv = saHpiEventGet(Domain->sessionId,
				SAHPI_TIMEOUT_IMMEDIATE, &event,
				NULL, NULL, NULL);		
			if (rv != SA_OK ) {
				break;
			}
			if (prt_flag == 1) {
				if (show_event_short)
					show_short_event(&event, ui_print);
				else
					oh_print_event(&event, NULL, 1);
			}
		}/*the loop for retrieving event*/
		sleep(1);
	}
	return (void *)1;
}
예제 #2
0
bool
cHpiEventRoot::getEvent( cHpiResourceRoot *r )
{
  SaHpiEventT event;
  SaHpiRdrT rdr;
  SaHpiRptEntryT rpt_entry;

  SaErrorT err = saHpiEventGet( theApp->m_session_id, 0, &event, &rdr, &rpt_entry );

  if ( err != SA_OK )
     {
       if ( err != SA_ERR_HPI_TIMEOUT )
            theApp->LogError( "saHpiEventGet: ", err );

       return false;
     }

  theApp->Log( "new event.\n" );

  new cHpiEvent( this, QString( "%1 %2" )
                 .arg( m_current++ )
                 .arg( hpiEventType2String( event.EventType ) ), event, rdr, rpt_entry );

  if ( event.EventType == SAHPI_ET_HOTSWAP )
       r->discoverResources();

  return false;
}
예제 #3
0
파일: session.c 프로젝트: openhpi1/testrepo
static void* get_event(void *unused)
{
	SaHpiEventT	event;
	SaErrorT	rv;        

	rv = saHpiSubscribe(sessionid);
	if (rv != SA_OK) {
		printf("OpenHPI>Fail to Subscribe event\n");
		return (void *)0;
	}	
	
	for(;;) {
		memset(&event, 0xF, sizeof(event));

		rv = saHpiEventGet(sessionid, SAHPI_TIMEOUT_BLOCK, &event, NULL, NULL, NULL);		
		if (rv != SA_OK ) {
			saHpiUnsubscribe(sessionid);
			return (void *)1;
		}
		if (prt_flag == 1) {
			if (show_event_short)
				show_short_event(&event);
			else
				oh_print_event(&event, 1);
		}
	} /*the loop for retrieving event*/
	return (void *)1;
}
예제 #4
0
파일: session.c 프로젝트: openhpi1/testrepo
static void* get_event(void *unused)
{
	SaHpiEventT	event;
	SaErrorT	rv;        
	
	
	rv = saHpiSubscribe(sessionid, SAHPI_FALSE);
	if (rv != SA_OK) {
		printf("OpenHPI>Fail to Subscribe event\n");
		return (void *)0;
	}	
		
	for(;;){
		memset(&event, 0xF, sizeof(event));

		rv = saHpiEventGet(sessionid, SAHPI_TIMEOUT_BLOCK, &event, NULL, NULL);		
		if (rv != SA_OK ) {
			goto out;
		}
		
		if ( prt_flag == 1 ) 
			print_event(sessionid,&event);
	} /*the loop for retrieving event*/

out:
	printf( "Unsubscribe\n");
	rv = saHpiUnsubscribe( sessionid );

	return (void *)1;
}
예제 #5
0
SaErrorT findEvent(SaHpiSessionIdT sessionId, SaHpiEventT * event,
		   SaHpiBoolT * found)
{
	SaErrorT status = SA_OK;
	SaHpiEventT e;

	*found = SAHPI_FALSE;
	while (!(*found) && status == SA_OK) {
		status =
		    saHpiEventGet(sessionId, D_TIMEOUT, &e, NULL, NULL, NULL);
		if (status == SA_OK) {
			*found = sameEvent(event, &e);
		} else if (status != SA_ERR_HPI_TIMEOUT) {
			e_print(saHpiEventGet, SA_OK, status);
		}
	}

	// For a timeout, found will be set to false.
	// Therefore, return OK to indicate that nothing abnormal happened.

	if (status == SA_ERR_HPI_TIMEOUT) {
		status = SA_OK;
	}

	return status;
}
예제 #6
0
파일: session.c 프로젝트: openhpi1/testrepo
static void* get_event(void *unused)
{
	SaHpiEventT	event;
	SaErrorT	rv;        
        SaHpiRptEntryT rptentry;
        SaHpiRdrT rdr;
        SaHpiEntryIdT rptentryid;
        SaHpiEntryIdT nextrptentryid;

	rv = saHpiSubscribe(Domain->sessionId);
	if (rv != SA_OK) {
		printf("OpenHPI>Fail to Subscribe event\n");
		return (void *)0;
	}	
	
	while(1) {
		for(;;) {
                        rdr.RdrType = SAHPI_NO_RECORD;
                        rptentry.ResourceId = 0;
			memset(&event, 0xF, sizeof(event));
			rv = saHpiEventGet(Domain->sessionId,
				SAHPI_TIMEOUT_BLOCK, &event,
				NULL, NULL, NULL);		
			if (rv != SA_OK ) {
				printf("saHpiEventGet failed with error <%d>", rv);
				break;
			}
			if (prt_flag == 1) {
				if (show_event_short)
					show_short_event(&event, ui_print);
                                else if (rdr.RdrType != SAHPI_NO_RECORD)
                                        oh_print_event(&event, &rdr.Entity, 4);
                                else if (rptentry.ResourceId != 0)
                                        oh_print_event(&event, &rptentry.ResourceEntity, 4);
                                else {
                                        rptentryid = event.Source;
                                        rv = saHpiRptEntryGet(Domain->sessionId,
                                                              rptentryid,
                                                              &nextrptentryid, &rptentry);
                                        if(rv == SA_OK)
                                                oh_print_event(&event, &rptentry.ResourceEntity, 4);
                                        else {
                                                printf("saHpiRptEntryGet failed for resource Id <%d> with error <%d>",
                                                        event.Source, rv);
                                                printf("Wrong resource Id <%d> detected", event.Source);
                                                oh_print_event(&event, NULL, 4);
                                        }
                                }
			}
		}/*the loop for retrieving event*/
		sleep(1);
	}
	return (void *)1;
}
예제 #7
0
파일: session.c 프로젝트: openhpi1/testrepo
static void* get_event(void *unused)
{
	SaHpiEventT	event;
	SaErrorT	rv;        
        SaHpiRptEntryT rptentry;
        SaHpiRdrT rdr;

	rv = saHpiSubscribe(Domain->sessionId);
	if (rv != SA_OK) {
		printf("hpi_shell>Fail to Subscribe event\n");
		return (void *)0;
	}	
	
	while(1) {
		for(;;) {
                        rdr.RdrType = SAHPI_NO_RECORD;
                        rptentry.ResourceId = 0;
			memset(&event, 0xF, sizeof(event));
			rv = saHpiEventGet(Domain->sessionId,
				SAHPI_TIMEOUT_BLOCK, &event,
				&rdr, &rptentry, NULL);		
                        if ((rv == SA_ERR_HPI_INVALID_SESSION) && (Domain->session_opened == 0)) {
				break;
                        } else if (rv != SA_OK ) {
				printf("saHpiEventGet failed with error <%d>\n", rv);
				break;
			}
			if (prt_flag == 1) {
				if (show_event_short) {
					show_short_event(&event, ui_print);
                                } else {
                                        const SaHpiEntityPathT * ep;
                                        ep = get_event_ep( &event, &rptentry, &rdr);
                                        if ((!ep) && (event.Source != SAHPI_UNSPECIFIED_RESOURCE_ID)) {
                                                rv = saHpiRptEntryGetByResourceId(Domain->sessionId,
                                                                                  event.Source,
                                                                                  &rptentry);
                                                if ( rv == SA_OK ) {
                                                        ep = get_event_ep(&event, &rptentry, &rdr);
                                                }
                                        }
                                        oh_print_event(&event, ep, 4);
                                }
			}
		}/*the loop for retrieving event*/
		if (rv == SA_ERR_HPI_INVALID_SESSION) {
		        break;
		}
		g_usleep(G_USEC_PER_SEC);
	}
	return (void *)1;
}
예제 #8
0
int checkForEvents(SaHpiSessionIdT sessionId)
{
    int i;
    int retval = SAF_TEST_PASS;
    SaErrorT status;
    SaHpiEventT event;
    SaHpiSensorNumT sensorNum;
    SaHpiBoolT assertion;

    while (SAHPI_TRUE && retval == SAF_TEST_PASS) {
         status = saHpiEventGet(sessionId, SAHPI_TIMEOUT_IMMEDIATE, &event, NULL, NULL, NULL);
         if (status == SA_ERR_HPI_TIMEOUT) {
              break;
         } else if (status != SA_OK) {
              retval = SAF_TEST_UNRESOLVED;
              e_print(saHpiEventGet, SA_OK, status);
              break;
         } else if ((event.EventType == SAHPI_ET_SENSOR) &&
                    (event.EventDataUnion.SensorEvent.EventState == SAHPI_ES_UPPER_MINOR)) {

              assertion = event.EventDataUnion.SensorEvent.Assertion;
              sensorNum = event.EventDataUnion.SensorEvent.SensorNum;
              for (i = 0; i < sensorCount; i++) {
                  if ((sensorData[i].resourceId == event.Source) &&
                      (sensorData[i].sensorNum == sensorNum)) {

                          if (assertion) {
                                  sensorData[i].assert = SAHPI_TRUE;
                                  // restore threshold which should kick off a deassert event
                                  status = saHpiSensorThresholdsSet(sessionId, 
                                                                    sensorData[i].resourceId,
                                                                    sensorData[i].sensorNum,
                                                                    &sensorData[i].thresholds);
                                  if (status != SA_OK) {
                                          e_print(saHpiSensorThresholdsSet, SA_OK, status);
                                          retval = SAF_TEST_UNRESOLVED;
                                  }
                          } else {
                                  sensorData[i].deassert = SAHPI_TRUE;
                          }
                          break;
                  }
              }
         }
    }

    return retval;
}
예제 #9
0
int checkForEvents(SaHpiSessionIdT sessionId)
{
    int i;
    int retval = SAF_TEST_PASS;
    SaErrorT status;
    SaHpiEventT event;
    SaHpiSensorNumT sensorNum;

    while (SAHPI_TRUE && retval == SAF_TEST_PASS) {
         status = saHpiEventGet(sessionId, SAHPI_TIMEOUT_IMMEDIATE, &event, NULL, NULL, NULL);
         if (status == SA_ERR_HPI_TIMEOUT) {
              break;
         } else if (status != SA_OK) {
              retval = SAF_TEST_UNRESOLVED;
              e_print(saHpiEventGet, SA_OK, status);
              break;
         } else if (event.EventType == SAHPI_ET_SENSOR_ENABLE_CHANGE) {
              sensorNum = event.EventDataUnion.SensorEnableChangeEvent.SensorNum;
              for (i = 0; i < sensorCount; i++) {
                  if ((sensorData[i].resourceId == event.Source) &&
                      (sensorData[i].sensorNum == sensorNum)) {

                      sensorData[i].stateIndex++;
                      int index = sensorData[i].stateIndex;
                      if (index < 2) {
                          if (sensorData[i].state[index] == STATE_ADD) {
                              retval = change_event_masks(sessionId, sensorData[i].resourceId, 
                                                          sensorData[i].sensorNum,
                                                          SAHPI_SENS_ADD_EVENTS_TO_MASKS);
                          } else if (sensorData[i].state[index] == STATE_REMOVE) {
                              retval = change_event_masks(sessionId, sensorData[i].resourceId, 
                                                          sensorData[i].sensorNum,
                                                          SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS);
                          }
                      }
                      break;
                  }
              }
         }
    }

    return retval;
}
예제 #10
0
static
void DoEvent(
   SaHpiSessionIdT sessionid,
   SaHpiResourceIdT resourceid,
   SaHpiSensorRecT *sensorrec )
{
   SaHpiSensorNumT sensornum;
   SaHpiSensorReadingT reading;
   SaHpiSensorReadingT conv_reading;
   SaHpiSensorThresholdsT senstbuff1;
   SaHpiSensorThresholdsT senstbuff2;

   SaHpiTimeoutT timeout = (SaHpiInt64T)(12 * HPI_NSEC_PER_SEC); /* 12 seconds */
   SaHpiEventT event;
   SaHpiRptEntryT rptentry;
   SaHpiRdrT rdr;
   char *unit;
   int eventflag = 0;
   int i;

   sensornum = sensorrec->Num;

/* Get current sensor reading */

   rv = saHpiSensorReadingGet( sessionid, resourceid, sensornum, &reading);
   if (rv != SA_OK)  {
	printf( "\n");
/*	printf("ReadingGet ret=%d\n", rv); */
	return;
   }

   if ((reading.ValuesPresent & SAHPI_SRF_INTERPRETED) == 0 &&
       (reading.ValuesPresent & SAHPI_SRF_RAW)) {

        /* only try convert if intrepreted not available. */

        rv = saHpiSensorReadingConvert(sessionid, resourceid, sensornum,
					&reading, &conv_reading);
        if (rv != SA_OK) {
		printf("raw=%x conv_ret=%d\n", reading.Raw, rv);
	     /* printf("conv_rv=%s\n", decode_error(rv)); */
		return;
        } else {
	   reading.Interpreted.Type = conv_reading.Interpreted.Type;
	   reading.Interpreted.Value.SensorUint32 = 
		   conv_reading.Interpreted.Value.SensorUint32;
	}
   }
   /* Determine units of interpreted reading */

   i = sensorrec->DataFormat.BaseUnits;

   if (i > NSU) i = 0;
   unit = units[i];

   printf(" = %05.2f %s \n", 
	reading.Interpreted.Value.SensorFloat32, unit);

/* Retrieve current threshold setings, twice */
/* once for backup and once for modification */

   /* Get backup copy */
   rv = saHpiSensorThresholdsGet(
	sessionid, resourceid, sensornum, &senstbuff1);
   if (rv != SA_OK) return;

   /* Get modification copy */
   rv = saHpiSensorThresholdsGet(
	sessionid, resourceid, sensornum, &senstbuff2);
   if (rv != SA_OK) return;

   /* Display current thresholds */ 
   if (rv == SA_OK) {
     printf( "   Current\n");
     ShowThresh( &senstbuff2 );
   }

/* Set new threshold to current reading + 10% */
   senstbuff2.LowMajor.Interpreted.Value.SensorFloat32 =
        reading.Interpreted.Value.SensorFloat32 * (SaHpiFloat32T)1.10;

printf( "ValuesPresent = %x\n", senstbuff2.LowMajor.ValuesPresent);
printf( "Values Mask   = %x\n", (SAHPI_SRF_RAW));
   senstbuff2.LowMajor.ValuesPresent =
        senstbuff2.LowMajor.ValuesPresent ^ (SAHPI_SRF_RAW);
printf( "ValuesPresent = %x\n", senstbuff2.LowMajor.ValuesPresent);

   /* Display new current thresholds */ 
   if (rv == SA_OK) {
     printf( "   New\n");
      ShowThresh( &senstbuff2 );
   }

   /* See what Events are Enabled */

   rv = saHpiSensorEventEnablesGet(
		sessionid, resourceid, sensornum, &enables1);
   if (rv != SA_OK) return;

   printf( "Sensor Event Enables: \n");
   printf( "  Sensor Status = %x\n", enables1.SensorStatus);
   printf( "  Assert Events = %x\n", enables1.AssertEvents);
   printf( "  Deassert Events = %x\n", enables1.DeassertEvents);

/* 
   enables1.AssertEvents = 0x0400;
   enables1.DeassertEvents = 0x0400;
   rv = saHpiSensorEventEnablesSet(
		sessionid, resourceid, sensornum, &enables1);
   if (rv != SA_OK) return;
*/


/************************
   Temporary exit */
/*
 return;
*/

/* Subscribe to New Events, only */
printf( "Subscribe to events\n");
   rv = saHpiSubscribe( sessionid, (SaHpiBoolT)0 );
   if (rv != SA_OK) return;

/* Set new thresholds */
printf( "Set new thresholds\n");

   rv = saHpiSensorThresholdsSet(
	sessionid, resourceid, sensornum, &senstbuff2);
   if (rv != SA_OK) return;

/* Go wait on event to occur */
printf( "Go and get the event\n");
   eventflag = 0;
   while ( eventflag == 0) {
     rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry );
     if (rv != SA_OK) { 
	if (rv != SA_ERR_HPI_TIMEOUT) {
	  printf( "Error during EventGet - Test FAILED\n");
	  return;
        } else {
	  printf( "Time expired during EventGet - Test FAILED\n");
            /* Reset to the original thresholds */
            printf( "Reset thresholds\n");
               rv = saHpiSensorThresholdsSet(
                    sessionid, resourceid, sensornum, &senstbuff1);
               if (rv != SA_OK) return;

            /* Re-read threshold values */
               rv = saHpiSensorThresholdsGet(
                    sessionid, resourceid, sensornum, &senstbuff2);
               if (rv != SA_OK) return;

	  return;
	}
     }
/* Decode the event information */
printf( "Decode event info\n");

     if (event.EventType == SAHPI_ET_SENSOR) {
       printf( "Sensor # = %2d  Severity = %2x\n", 
	    event.EventDataUnion.SensorEvent.SensorNum, event.Severity );
       if (event.EventDataUnion.SensorEvent.SensorNum == sensornum) {
	 eventflag = 1;
	 printf( "Got it - Test PASSED\n");
       }
     }
   }
/* Reset to the original thresholds */
printf( "Reset thresholds\n");
   rv = saHpiSensorThresholdsSet(
	sessionid, resourceid, sensornum, &senstbuff1);
   if (rv != SA_OK) return;

/* Re-read threshold values */
   rv = saHpiSensorThresholdsGet(
	sessionid, resourceid, sensornum, &senstbuff2);
   if (rv != SA_OK) return;

/* Display reset thresholds */ 
   if (rv == SA_OK) {
     printf( "   Reset\n");
     ShowThresh( &senstbuff2 );
   }
/* Unsubscribe to future events */
printf( "Unsubscribe\n");
   rv = saHpiUnsubscribe( sessionid );

   return;
}  /*end DoEvent*/
예제 #11
0
int main(int argc, char **argv)
{
	int c, test_fail = 0, wait = 0;
	char *timeout_str= (char *)NULL;
	int do_discover_after_subscribe = 0;
	SaErrorT rv;
	SaHpiSessionIdT sessionid;
	SaHpiDomainInfoT domainInfo;
	SaHpiRptEntryT rptentry;
	SaHpiEntryIdT rptentryid;
	SaHpiEntryIdT nextrptentryid;
	SaHpiResourceIdT resourceid;
	SaHpiEventLogInfoT info;
	SaHpiRdrT rdr;
	SaHpiTimeoutT timeout; 
	SaHpiEventT event;

	memset(&rptentry, 0, sizeof(rptentry));

	printf("%s: version %s\n", argv[0], progver); 

	while ( (c = getopt( argc, argv,"t:xd?")) != EOF ) {
		switch(c) {
			case 't':
				timeout_str = optarg;
				break;
			case 'd': 
				do_discover_after_subscribe = 1; 
				break;
			case 'x': 
				fdebug = 1; 
				break;
			default:
				Usage(argv);
				exit(1);
		}
	}

	if (timeout_str != (char *)NULL) {
		if ((strcmp(timeout_str, "SAHPI_TIMEOUT_BLOCK") == 0) ||
		    (strcmp(timeout_str, "BLOCK") == 0)) {
			timeout = SAHPI_TIMEOUT_BLOCK;
		} else {
			wait = atoi(timeout_str);
                	timeout = (SaHpiTimeoutT)(wait * HPI_NSEC_PER_SEC);
		}
	} else
		timeout = (SaHpiTimeoutT) SAHPI_TIMEOUT_IMMEDIATE;

	printf("************** timeout:[%lld] ****************\n", timeout);    

	rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
	if (rv != SA_OK) {
		if (rv == SA_ERR_HPI_ERROR) 
			printf("saHpiSessionOpen: error %d, SpiLibd not running\n", rv);
		else
			printf("saHpiSessionOpen: %s\n", oh_lookup_error(rv));
		exit(-1);
	}
 
	if (fdebug) printf("saHpiDiscover\n");
	rv = saHpiDiscover(sessionid);
	if (rv != SA_OK) {
		printf("saHpiDiscover: %s\n", oh_lookup_error(rv));
		exit(-1);
	}
	
        if (fdebug) printf( "Subscribe to events\n");
        rv = saHpiSubscribe( sessionid );
	if (rv != SA_OK) {
		printf("saHpiSubscribe: %s\n", oh_lookup_error(rv));
		exit(-1);
	}

	if (do_discover_after_subscribe) {
		if (fdebug) printf("saHpiDiscover after saHpiSubscribe\n");
		rv = saHpiDiscover(sessionid);
		if (rv != SA_OK) {
			printf("saHpiDiscover after saHpiSubscribe: %s\n", oh_lookup_error(rv));
			exit(-1);
		}
	}

	rv = saHpiDomainInfoGet(sessionid, &domainInfo);

	if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv));
	printf("DomainInfo: UpdateCount = %d, UpdateTime = %lx\n",
		domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp);

	/* walk the RPT list */
	rptentryid = SAHPI_FIRST_ENTRY;
	while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) {       
		printf("**********************************************\n");

		rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry);
		if (fdebug) printf("saHpiRptEntryGet %s\n", oh_lookup_error(rv));

		if (rv == SA_OK) {
			resourceid = rptentry.ResourceId;
			if (fdebug)
				printf("RPT %x capabilities = %x\n", resourceid,
					rptentry.ResourceCapabilities);

			if ( (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) {
				/* Using EventLogInfo to build up event queue - for now */
				rv = saHpiEventLogInfoGet(sessionid, resourceid, &info);
				if (fdebug) 
					printf("saHpiEventLogInfoGet %s\n", oh_lookup_error(rv));
				if (rv == SA_OK) 
					oh_print_eventloginfo(&info, 4);
			} else {
				if (fdebug) 
					printf("RPT doesn't have SEL\n");
			}

			rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; 
			printf("rptentry[%d] tag: %s\n", resourceid, rptentry.ResourceTag.Data);

			rptentryid = nextrptentryid;
		}
		printf("**********************************************\n");
	}

	printf( "Go and get the event\n");
	while (1) {
		rdr.RdrType = SAHPI_NO_RECORD;

		rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry, NULL);
		if (rv != SA_OK) {
			if (rv != SA_ERR_HPI_TIMEOUT) {
				printf("ERROR during EventGet : %s\n", oh_lookup_error(rv));
				test_fail = 1;
			} else {
				if (timeout == SAHPI_TIMEOUT_BLOCK) {
					printf("ERROR: Timeout while infinite wait\n");
					test_fail = 1;
				} else if (timeout != SAHPI_TIMEOUT_IMMEDIATE) {
					printf("ERROR: Time, %d seconds, expired waiting"
						" for event\n", wait);
					test_fail = 1;
				}
			}
			break;
		} else {
			oh_print_event(&event, 4);
		}
	}

	if (test_fail == 0)
		printf("	Test PASS.\n");
	else
		printf("	Test FAILED.\n");

	/* Unsubscribe to future events */
	if (fdebug) printf( "Unsubscribe\n");
	rv = saHpiUnsubscribe( sessionid );

	rv = saHpiSessionClose(sessionid);
        
	return(0);
}
예제 #12
0
SaErrorT populate_saHpiEventTable(SaHpiSessionIdT sessionid)
{
        SaErrorT rv = SA_OK;

        SaHpiEventT          event;         
        SaHpiRdrT            rdr;            
        SaHpiRptEntryT       rpt_entry;       
        SaHpiEvtQueueStatusT event_queue_status;

	oid event_oid[MAX_OID_LEN];
	netsnmp_index event_index;
	saHpiEventTable_context *event_context;

        oid child_oid[MAX_OID_LEN];
        size_t child_oid_len;

        int i;

        printf( "populate_saHpiEventTable, called\n");
        printf(" ***************************************\n");
        printf(" ***************************************\n");
        printf(" EVENT TABLES \n");

        rv = saHpiEventGet (sessionid, 
                            SAHPI_TIMEOUT_IMMEDIATE, 
                            &event, 
                            &rdr, 
                            &rpt_entry, 
                            &event_queue_status);

        while (rv == SA_OK) {

                printf("rpt_entry.ResourceId [%d]\n", rpt_entry.ResourceId);
                printf( "Event Type [%s]\n", oh_lookup_eventtype(event.EventType));

                switch (event.EventType) {
                case SAHPI_ET_RESOURCE:
                        printf("SAHPI_ET_RESOURCE: rv [%d]\n", rv);
                        printf("        Event Type: [%s]\n", 
                        oh_lookup_resourceeventtype(event.EventDataUnion.ResourceEvent.ResourceEventType));
                        printf("        Resource: [%d]\n",event.Source);
                        printf("        Severity: [%s]\n\n",oh_lookup_severity(event.Severity));
                        populate_saHpiResourceEventTable(sessionid, &event,                                           
                                                         child_oid, 
                                                         &child_oid_len);
                        rv = async_resource_add(sessionid, &event, &rdr, &rpt_entry);
                        break;
                case SAHPI_ET_DOMAIN:
                        printf("SAHPI_ET_DOMAIN: rv [%d]\n", rv);
                        printf("        Event Type: [%s]\n\n", 
                        oh_lookup_domaineventtype(event.EventDataUnion.DomainEvent.Type));
                        populate_saHpiDomainEventTable(sessionid, &event,                                           
                                                       child_oid, 
                                                       &child_oid_len);
                        break;
                case SAHPI_ET_SENSOR:
                        printf("SAHPI_ET_SENSOR: rv [%d]\n", rv);
                        printf("        Sensor Type: [%s]\n\n",
                        oh_lookup_sensortype(event.EventDataUnion.SensorEvent.SensorType));
                        populate_saHpiSensorEventTable(sessionid, &event,                                           
                                                       child_oid, 
                                                       &child_oid_len);
                        break;
                case SAHPI_ET_SENSOR_ENABLE_CHANGE:
                        printf("SAHPI_ET_SENSOR_ENABLE_CHANGE: rv [%d]\n\n", rv);
                        populate_saHpiSensorEnableChangeEventTable(sessionid, &event,                                           
                                                       child_oid, 
                                                       &child_oid_len);
                        break;
                case SAHPI_ET_HOTSWAP:
                        printf("SAHPI_ET_HOTSWAP: rv [%d]\n\n", rv);
                        populate_saHpiHotSwapEventTable(sessionid, &event,
                                                        child_oid, 
                                                        &child_oid_len);
                        break;
                case SAHPI_ET_WATCHDOG:
                        printf("SAHPI_ET_WATCHDOG: rv [%d]\n\n", rv);
                        populate_saHpiWatchdogEventTable(sessionid, &event,
                                                         child_oid, 
                                                         &child_oid_len);
                        break;
                case SAHPI_ET_HPI_SW:
                        printf("SAHPI_ET_HPI_SW: rv [%d]\n\n", rv);
                        populate_saHpiSoftwareEventTable(sessionid, &event,
                                                         child_oid, 
                                                         &child_oid_len);
                        break;
                case SAHPI_ET_OEM:
                        printf("SAHPI_ET_OEM: rv [%d]\n\n", rv);
                        populate_saHpiOemEventTable(sessionid, &event,                                           
                                                    child_oid, 
                                                    &child_oid_len);
                        break;
                case SAHPI_ET_USER:
                        printf("SAHPI_ET_USER: rv [%d]\n\n", rv);
                        populate_saHpiUserEventTable(sessionid, &event,                                           
                                                    child_oid, 
                                                    &child_oid_len);
                        break;
                default:
                        printf("********* unknown event type *********\n");
                        break;        
                }

                event_index.len = child_oid_len;
                for (i=0; i < child_oid_len; i++) 
                        event_oid[i] = child_oid[i];
                event_index.oids = (oid *) & event_oid;
	
                /* See if it exists. */
                event_context = NULL;
                event_context = CONTAINER_FIND (cb.container, &event_index);
		
                if (!event_context) { 
                        // New entry. Add it
                        event_context = 
                                saHpiEventTable_create_row (&event_index);
                }
                if (!event_context) {
                        snmp_log (LOG_ERR, "Not enough memory for a Event row!");
                        return AGENT_ERR_INTERNAL_ERROR;
                }


                /** RowPointer = ASN_OBJECT_ID */
		event_context->saHpiEventRowPointer_len = 
                        child_oid_len * sizeof (oid);
		memcpy (event_context->saHpiEventRowPointer, 
			child_oid, 
			event_context->saHpiEventRowPointer_len);

                /** SaHpiSeverity = ASN_INTEGER */
                event_context->saHpiEventSeverity = event.Severity + 1;

                /** SaHpiTime = ASN_COUNTER64 */
                event_context->saHpiEventSaHpiTime = event.Timestamp;

                /** INTEGER = ASN_INTEGER */
                event_context->saHpiEventType = event.EventType + 1;


                CONTAINER_INSERT (cb.container, event_context);

                event_entry_count = CONTAINER_SIZE (cb.container);
		
                /* get next event if available */
                memset(&event, 0, sizeof(event));
                memset(&rdr, 0, sizeof(rdr));
                memset(&rpt_entry, 0, sizeof(rpt_entry));
                memset(&event_queue_status, 0, sizeof(event_queue_status));
            
                rv = saHpiEventGet (sessionid, 
                                    SAHPI_TIMEOUT_IMMEDIATE, 
                                    &event, 
                                    &rdr, 
                                    &rpt_entry, 
                                    &event_queue_status);
        }

        return rv;
}
예제 #13
0
int main(int argc, char **argv)
{
	int c, wait = 0;
	SaErrorT rv;
	SaHpiVersionT hpiVer;
	SaHpiSessionIdT sessionid;
	SaHpiRptInfoT rptinfo;
	SaHpiRptEntryT rptentry;
	SaHpiEntryIdT rptentryid;
	SaHpiEntryIdT nextrptentryid;
	SaHpiResourceIdT resourceid;
	SaHpiSelInfoT info;
	SaHpiRdrT rdr;
	SaHpiTimeoutT timeout; 
	SaHpiEventT event;
        
	printf("%s: version %s\n",argv[0],progver); 
        
        while ( (c = getopt( argc, argv,"t:x?")) != EOF )
                switch(c) {
			case 't':
				ftimer = 1;
				wait = atoi(optarg);
				break;
			case 'x': fdebug = 1; break;
			default:
				printf("Usage %s [-tx]\n",argv[0]);
				printf("      -t <value>:wait <value> seconds for event\n");
				printf("      -x	:displays eXtra debug messages\n");
				exit(1);
		}


	if (ftimer) 
		timeout = (SaHpiInt64T)(wait * HPI_NSEC_PER_SEC);  
	else
		timeout = (SaHpiInt64T) SAHPI_TIMEOUT_IMMEDIATE;

        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, SpiLibd 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);
        
	printf( "Subscribe to events\n");
	rv = saHpiSubscribe( sessionid, (SaHpiBoolT)0 );
	if (rv != SA_OK) return rv;


        /* 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) {
                        resourceid = rptentry.ResourceId;
                        if (fdebug) printf("RPT %x capabilities = %x\n", resourceid,
                                           rptentry.ResourceCapabilities);
                        if (!(rptentry.ResourceCapabilities & SAHPI_CAPABILITY_SEL)) {
                                if (fdebug) printf("RPT doesn't have SEL\n");
                                rptentryid = nextrptentryid;
                                continue;  /* no SEL here, try next RPT */
                        }
                        rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; 
                        printf("rptentry[%d] tag: %s\n", resourceid,rptentry.ResourceTag.Data);
                        
			/* Using EventLogInfo to build up event queue - for now */
                        rv = saHpiEventLogInfoGet(sessionid,resourceid,&info);
                        if (fdebug) printf("saHpiEventLogInfoGet %s\n",decode_error(rv));
                        if (rv == SA_OK) {
				break;
                        }
                        
                        rptentryid = nextrptentryid;
                }
        }
        
	printf( "Go and get the event\n");
	while (1) {
		rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry );
     		if (rv != SA_OK) { 
			if (rv != SA_ERR_HPI_TIMEOUT) {
	  			printf( "Error during EventGet - Test FAILED\n");
	  			break;
        		} else {
	  			printf( "\n\n****** Time, %d seconds, expired waiting for event.\n", wait);
	  			break;
			}
		} else {
			print_event(&event);
		}
     	}

	
	
	/* Unsubscribe to future events */
	printf( "Unsubscribe\n");
	rv = saHpiUnsubscribe( sessionid );

	rv = saHpiSessionClose(sessionid);
        rv = saHpiFinalize();
        
        exit(0);
        return(0);
}
예제 #14
0
static void mod_sen(void)
{
	int			i, rpt, rdr, num;
	char			buf[READ_BUF_SIZE], *S;
	Rpt_t			*Rpt;
	Rdr_t			*Rdr;
	SaHpiSensorThresholdsT	thres;
	SaErrorT		rv;
	ThresTypes_t		type = UNKNOWN_TYPE;
	float			f;
	SaHpiEventT		event;

	i = get_number("RPT number: ", &rpt);
	if (i != 1) {
		printf("ERROR: no RPT number\n");
		return;
	};
	i = find_rpt_by_id(rpt);
	if (i < 0) {
		printf("ERROR: invalid RPT number\n");
		return;
	};
	rpt = i;
	Rpt = Rpts + rpt;
	show_sens_for_rpt(Rpt);
	i = get_number("Sensor number: ", &num);
	if (i != 1) {
		printf("ERROR: no Sensor number\n");
		return;
	};
	rdr = find_sensor_by_num(Rpt, num);
	if (rdr < 0) {
		printf("ERROR: invalid sensor number\n");
		return;
	};
	Rdr = Rpt->rdrs + rdr;
	oh_print_rdr(&(Rdr->Rdr), 2);
	show_reading_value(Rpt, Rdr);
	rv = saHpiSensorThresholdsGet(sessionid, Rpt->Rpt.ResourceId,
		Rdr->Rdr.RdrTypeUnion.SensorRec.Num, &thres);
	if (rv != SA_OK) {
		printf("ERROR: %s\n", oh_lookup_error(rv));
		return;
	};
	printf("  Thresholds:\n");
	ShowThres(&thres);
	if (Rdr->is_value == 0) {
		Rdr->thresholds = thres;
		Rdr->is_value = 1;
	};
	printf("threshold type (lc, la, li, uc, ua, ui, ph, nh): ");
	fgets(buf, READ_BUF_SIZE, stdin);
	S = buf;
	while (*S == ' ') S++;
	if (strlen(S) < 2) {
		printf("ERROR: invalid threshold type: %s\n", S);
		return;
	};

	if (strncmp(S, "lc", 2) == 0) type = LOWER_CRIT;
	if (strncmp(S, "la", 2) == 0) type = LOWER_MAJOR;
	if (strncmp(S, "li", 2) == 0) type = LOWER_MINOR;
	if (strncmp(S, "uc", 2) == 0) type = UPPER_CRIT;
	if (strncmp(S, "ua", 2) == 0) type = UPPER_MAJOR;
	if (strncmp(S, "ui", 2) == 0) type = UPPER_MINOR;
	if (strncmp(S, "ph", 2) == 0) type = POS_HYST;
	if (strncmp(S, "nh", 2) == 0) type = NEG_HYST;

	if (type == UNKNOWN_TYPE) {
		printf("ERROR: unknown threshold type: %s\n", S);
		return;
	};
	
	printf("new value: ");
	fgets(buf, READ_BUF_SIZE, stdin);
	i = sscanf(buf, "%f", &f);
	if (i == 0) {
		printf("ERROR: no value\n");
		return;
	};
	switch (type) {
		case LOWER_CRIT:
			set_thres_value(&(thres.LowCritical), (double)f);
			break;
		case LOWER_MAJOR:
			set_thres_value(&(thres.LowMajor), (double)f);
			break;
		case LOWER_MINOR:
			set_thres_value(&(thres.LowMinor), (double)f);
			break;
		case UPPER_CRIT:
			set_thres_value(&(thres.UpCritical), (double)f);
			break;
		case UPPER_MAJOR:
			set_thres_value(&(thres.UpMajor), (double)f);
			break;
		case UPPER_MINOR:
			set_thres_value(&(thres.UpMinor), (double)f);
			break;
		case POS_HYST:
			set_thres_value(&(thres.PosThdHysteresis), (double)f);
			break;
		case NEG_HYST:
			set_thres_value(&(thres.NegThdHysteresis), (double)f);
			break;
		default:
			printf("ERROR: unknown threshold\n");
	};
	printf("\n  Nem threshold:\n");
	ShowThres(&thres);
	printf("Is it correct (yes, no)?:");
	fgets(buf, READ_BUF_SIZE, stdin);
	S = buf;
	while (*S == ' ') S++;
	if (strncmp(S, "yes", 3) != 0)
		return;
	rv = saHpiSensorThresholdsSet(sessionid, Rpt->Rpt.ResourceId,
		Rdr->Rdr.RdrTypeUnion.SensorRec.Num, &thres);
	if (rv != SA_OK) {
		printf("ERROR: saHpiSensorThresholdsSet: %s\n", oh_lookup_error(rv));
		return;
	};
	Rdr->modify = 1;
	for (i = 0; i < 10; i++) {
		rv = saHpiEventGet(sessionid, SAHPI_TIMEOUT_IMMEDIATE, &event,
			NULL, NULL, NULL);
		if (rv == SA_OK)
			break;
		if (fdebug) printf("sleep before saHpiEventGet\n");
		sleep(1);
	};
	saHpiSensorThresholdsGet(sessionid, Rpt->Rpt.ResourceId,
		Rdr->Rdr.RdrTypeUnion.SensorRec.Num, &thres);
	printf("Current thresholds:\n");
	ShowThres(&thres);
}
예제 #15
0
cOpenHpiDaemon::tResult
cOpenHpiDaemon::HandleMsg( cConnection *c, 
			   const cMessageHeader &header, const void *data,
			   cMessageHeader &rh, void *&rd )
{
  cHpiMarshal *hm = HpiMarshalFind( header.m_id );

  // check for function and data length
  if ( !hm || hm->m_request_len < header.m_len )
     {
       //MessageHeaderInit( &rh, eMhError, header.m_seq, 0, 0 );
       //rd = 0;

       fprintf( stderr, "wrong message length: id %d !\n", header.m_id );

       return eResultError;
     }

  assert( hm->m_reply_len );

  // init reply header
  MessageHeaderInit( &rh, eMhReply, header.m_seq, header.m_id, hm->m_reply_len );

  // alloc reply buffer
  rd = calloc( 1, hm->m_reply_len );

  SaErrorT ret;

  switch( header.m_id )
     {
       case eFsaHpiSessionOpen:
	    {
	      SaHpiDomainIdT domain_id;
	      SaHpiSessionIdT session_id = 0;

	      HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, (void *)&domain_id );

	      ret = saHpiSessionOpen( domain_id, &session_id, 0 );

	      DbgFunc( "saHpiSessionOpen( %x, %x ) = %d\n",
                       domain_id, session_id, ret );

	      if ( ret == SA_OK )
		   c->AddSession( session_id );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &session_id );
	    }
 
	    break;

       case eFsaHpiSessionClose:
	    {
	      SaHpiSessionIdT session_id;

	      HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id );

	      ret = saHpiSessionClose( session_id );

	      DbgFunc( "saHpiSessionClose( %x ) = %d\n", session_id, ret );

	      if ( ret == SA_OK )
		   c->RemSession( session_id );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiResourcesDiscover:
	    {
	      SaHpiSessionIdT session_id;

	      HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id );

	      ret = saHpiResourcesDiscover( session_id );

	      DbgFunc( "saHpiResourcesDiscover( %x ) = %d\n", session_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;
    
       case eFsaHpiRptInfoGet:
	    {
	      SaHpiSessionIdT session_id;
              SaHpiRptInfoT rpt_info;

	      HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data, &session_id );

	      ret = saHpiRptInfoGet( session_id, &rpt_info );

	      DbgFunc( "saHpiRptInfoGet( %x ) = %d\n", session_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &rpt_info );
	    }

	    break;

       case eFsaHpiRptEntryGet:
	    {
	      SaHpiSessionIdT session_id;
              SaHpiEntryIdT   entry_id;
              SaHpiEntryIdT   next_entry_id;
              SaHpiRptEntryT  rpt_entry;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
                                    &session_id, &entry_id );

	      ret = saHpiRptEntryGet( session_id, entry_id, &next_entry_id, &rpt_entry );

	      DbgFunc( "saHpiRptEntryGet( %x, %x, %x ) = %d\n",
                       session_id, entry_id, next_entry_id, ret );

	      rh.m_len = HpiMarshalReply2( hm, rd, &ret, &next_entry_id, &rpt_entry );
	    }

	    break;

       case eFsaHpiRptEntryGetByResourceId:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiRptEntryT   rpt_entry;
	      
	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id );

	      ret = saHpiRptEntryGetByResourceId( session_id, resource_id, &rpt_entry );

	      DbgFunc( "saHpiRptEntryGetByResourceId( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &rpt_entry );
	    }

	    break;

       case eFsaHpiResourceSeveritySet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSeverityT   severity;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &severity );

	      ret = saHpiResourceSeveritySet( session_id,
					      resource_id, severity );

	      DbgFunc( "saHpiResourceSeveritySet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiResourceTagSet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiTextBufferT resource_tag;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &resource_tag );

	      ret = saHpiResourceTagSet( session_id, resource_id,
					 &resource_tag );

	      DbgFunc( "saHpiResourceTagSet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiResourceIdGet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id = 0;

	      HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data,
				    &session_id );

	      ret = saHpiResourceIdGet( session_id, &resource_id );

	      DbgFunc( "saHpiResourceIdGet( %x ) = %d, %x\n",
                       session_id, ret, resource_id );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &resource_id );
	    }

	    break;

       case eFsaHpiEntitySchemaGet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiUint32T    schema_id = 0;

	      HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data,
				   &session_id );

	      ret = saHpiEntitySchemaGet( session_id, &schema_id );
	      
	      DbgFunc( "saHpiEntitySchemaGet( %x ) = %d, %x\n",
                       session_id, ret, schema_id );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &schema_id );
	    }
	    
	    break;

       case eFsaHpiEventLogInfoGet:
 	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSelInfoT    info;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id );

	      ret = saHpiEventLogInfoGet( session_id, resource_id, &info );

	      DbgFunc( "saHpiEventLogInfoGet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &info );
	    }

	    break;

       case eFsaHpiEventLogEntryGet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSelEntryIdT entry_id;
	      SaHpiSelEntryIdT prev_entry_id = 0;
	      SaHpiSelEntryIdT next_entry_id = 0;
	      SaHpiSelEntryT   event_log_entry;
	      SaHpiRdrT        rdr;
	      SaHpiRptEntryT   rpt_entry;

	      memset( &rdr, 0, sizeof( SaHpiRdrT ) );
	      memset( &rpt_entry, 0, sizeof( SaHpiRptEntryT ) );

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &entry_id );

	      ret = saHpiEventLogEntryGet( session_id, resource_id, entry_id,
					   &prev_entry_id, &next_entry_id,
					   &event_log_entry, &rdr, &rpt_entry );

	      DbgFunc( "saHpiEventLogEntryGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, entry_id, ret );

	      rh.m_len = HpiMarshalReply5( hm, rd, &ret, &prev_entry_id, &next_entry_id,
				&event_log_entry, &rdr, &rpt_entry );
	    }

	    break;

       case eFsaHpiEventLogEntryAdd:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSelEntryT   evt_entry;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &evt_entry );

	      ret = saHpiEventLogEntryAdd( session_id, resource_id,
					   &evt_entry );
	      
	      DbgFunc( "saHpiEventLogEntryAdd( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiEventLogEntryDelete:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSelEntryIdT entry_id;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &entry_id );

	      ret = saHpiEventLogEntryDelete( session_id, resource_id, entry_id );

	      DbgFunc( "saHpiEventLogEntryDelete( %x, %x, %x ) = %d\n",
                       session_id, resource_id, entry_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    
	    break;

       case eFsaHpiEventLogClear:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id );

	      ret = saHpiEventLogClear( session_id, resource_id );

	      DbgFunc( "saHpiEventLogClear( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiEventLogTimeGet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiTimeT       ti;
	      
	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id );

	      ret = saHpiEventLogTimeGet( session_id, resource_id, &ti );

	      DbgFunc( "saHpiEventLogTimeGet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &ti );
	    }

	    break;

       case eFsaHpiEventLogTimeSet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiTimeT       ti;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id , &ti );

	      ret = saHpiEventLogTimeSet( session_id, resource_id, ti );
 
	      DbgFunc( "saHpiEventLogTimeSet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiEventLogStateGet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiBoolT       enable;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id );

	      ret = saHpiEventLogStateGet( session_id, resource_id, &enable );

	      DbgFunc( "saHpiEventLogStateGet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &enable );
	    }

	    break;

       case eFsaHpiEventLogStateSet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiBoolT       enable;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &enable );

	      ret = saHpiEventLogStateSet( session_id, resource_id, enable );
	      
	      DbgFunc( "saHpiEventLogStateSet( %x, %x, %s ) = %d\n",
                       session_id, resource_id, enable ? "true" : "false", ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiSubscribe:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiBoolT      provide_active_alarms;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &provide_active_alarms );

	      ret = saHpiSubscribe( session_id, provide_active_alarms );

	      DbgFunc( "saHpiSubscribe( %x, %s ) = %d\n",
                       session_id,  provide_active_alarms ? "true" : "false",
		       ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiUnsubscribe:
	    {
	      SaHpiSessionIdT session_id;

	      HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data,
				    &session_id );

	      ret = saHpiUnsubscribe( session_id );

	      DbgFunc( "saHpiUnsubscribe( %x ) = %d\n",
                       session_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiEventGet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiTimeoutT   timeout;
	      SaHpiEventT     event;
	      SaHpiRdrT       rdr;
	      SaHpiRptEntryT  rpt_entry;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &timeout );

	      if ( timeout == 0 )
		 {
		   ret = saHpiEventGet( session_id, timeout, &event, &rdr, &rpt_entry );

		   DbgFunc( "saHpiEventGet( %x ) = %d\n",
			    session_id, ret );

		   rh.m_len = HpiMarshalReply3( hm, rd, &ret, &event, &rdr, &rpt_entry );
		 }
	      else
		 {
		   cSession *s = c->FindSession( session_id );

		   if ( s && !s->IsEventGet() )
		      {
			s->EventGet( true );

			SaHpiTimeT end;
			gettimeofday1( &end );

			if ( timeout == SAHPI_TIMEOUT_BLOCK )
			     end += (SaHpiTimeT)10000*1000000000; //set a long time
			else
			     end += timeout;

			s->Timeout() = end;

			s->Seq() = header.m_seq;

			DbgEvent( "saHpiEventGet( %x ): add to event listener.\n",
				  s->SessionId() );

			return eResultOk;
		      }

		   // error
		   ret = SA_ERR_HPI_BUSY;
		   rh.m_len = HpiMarshalReply3( hm, rd, &ret, &event, &rdr, &rpt_entry );
		 }
	    }

	    break;

       case eFsaHpiRdrGet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiEntryIdT    entry_id;
	      SaHpiEntryIdT    next_entry_id;
	      SaHpiRdrT        rdr;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &entry_id );

	      ret = saHpiRdrGet( session_id, resource_id, entry_id,
				 &next_entry_id, &rdr );

	      DbgFunc( "saHpiRdrGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, entry_id, ret );

	      rh.m_len = HpiMarshalReply2( hm, rd, &ret, &next_entry_id, &rdr );
	    }

	    break;

       case eFsaHpiSensorReadingGet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSensorNumT  sensor_num;
	      SaHpiSensorReadingT reading;
	      
	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &sensor_num );

	      ret = saHpiSensorReadingGet( session_id, resource_id,
					   sensor_num, &reading );
	      
	      DbgFunc( "saHpiSensorReadingGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, sensor_num, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &reading );
	    }

	    break;

       case eFsaHpiSensorReadingConvert:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSensorNumT  sensor_num;
	      SaHpiSensorReadingT reading_input;
	      SaHpiSensorReadingT converted_reading;

	      HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &sensor_num,
				    &reading_input );

	      ret = saHpiSensorReadingConvert( session_id,
					       resource_id, sensor_num,
					       &reading_input,
					       &converted_reading );

	      DbgFunc( "saHpiSensorReadingConvert( %x, %x, %x ) = %d\n",
                       session_id, resource_id, sensor_num, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &converted_reading );
	    }

	    break;

       case eFsaHpiSensorThresholdsGet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSensorNumT  sensor_num;
	      SaHpiSensorThresholdsT sensor_thresholds;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &sensor_num );

	      ret = saHpiSensorThresholdsGet( session_id,
					      resource_id, sensor_num,
					      &sensor_thresholds);

	      DbgFunc( "saHpiSensorThresholdsGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, sensor_num,  ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &sensor_thresholds );
	    }

	    break;

       case eFsaHpiSensorThresholdsSet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSensorNumT  sensor_num;
	      SaHpiSensorThresholdsT sensor_thresholds;

	      HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &sensor_num,
				   &sensor_thresholds );

	      ret = saHpiSensorThresholdsSet( session_id, resource_id,
					      sensor_num,
					      &sensor_thresholds );

	      DbgFunc( "saHpiSensorThresholdsSet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, sensor_num, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiSensorTypeGet:
	    {
	      SaHpiResourceIdT resource_id;
	      SaHpiSessionIdT  session_id;
	      SaHpiSensorNumT  sensor_num;
	      SaHpiSensorTypeT type;
	      SaHpiEventCategoryT category;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &sensor_num );

	      ret = saHpiSensorTypeGet( session_id, resource_id,
					sensor_num, &type, &category );

	      DbgFunc( "saHpiSensorTypeGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, sensor_num, ret );

	      rh.m_len = HpiMarshalReply2( hm, rd, &ret, &type, &category );
	    }

	    break;

       case eFsaHpiSensorEventEnablesGet:
	    {
	      SaHpiSessionIdT        session_id;
	      SaHpiResourceIdT       resource_id;
	      SaHpiSensorNumT        sensor_num;
	      SaHpiSensorEvtEnablesT enables;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &sensor_num );

	      ret = saHpiSensorEventEnablesGet( session_id, resource_id,
						sensor_num, &enables );

	      DbgFunc( "saHpiSensorEventEnablesGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, sensor_num, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &enables );
	    }

	    break;

       case eFsaHpiSensorEventEnablesSet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiSensorNumT  sensor_num;
	      SaHpiSensorEvtEnablesT enables;

	      HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &sensor_num,
				    &enables );

	      ret = saHpiSensorEventEnablesSet( session_id, resource_id,
						sensor_num, &enables );
	      
	      DbgFunc( "saHpiSensorEventEnablesSet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, sensor_num, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    
	    break;

       case eFsaHpiControlTypeGet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiCtrlNumT    ctrl_num;
	      SaHpiCtrlTypeT   type;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &ctrl_num );

	      ret = saHpiControlTypeGet( session_id, resource_id, ctrl_num,
					 &type );

	      DbgFunc( "saHpiControlTypeGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, ctrl_num, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &type );
	    }

	    break;

       case eFsaHpiControlStateGet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiCtrlNumT    ctrl_num;
	      SaHpiCtrlStateT  ctrl_state;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &ctrl_num );

	      ret = saHpiControlStateGet( session_id, resource_id,
					  ctrl_num, &ctrl_state );

	      DbgFunc( "saHpiControlStateGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, ctrl_num, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &ctrl_state );
	    }

	    break;

       case eFsaHpiControlStateSet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiCtrlNumT    ctrl_num;
	      SaHpiCtrlStateT  ctrl_state;

	      HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &ctrl_num,
				    &ctrl_state );

	      ret = saHpiControlStateSet( session_id, resource_id,
					  ctrl_num, &ctrl_state );

	      DbgFunc( "saHpiControlStateSet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, ctrl_num, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiEntityInventoryDataRead:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiEirIdT      eir_id;
	      SaHpiUint32T     buffer_size;
	      unsigned char   *buffer = 0;
	      SaHpiUint32T     actual_size;

	      HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &eir_id, &buffer_size );

	      if ( buffer_size )
		   buffer = new unsigned char [buffer_size];

	      ret = saHpiEntityInventoryDataRead( session_id, resource_id, eir_id,
						  buffer_size, (SaHpiInventoryDataT *)(void *)buffer,
						  &actual_size );

	      DbgFunc( "saHpintityInventoryDataRead( %x, %x, %x, %d ) = %d\n",
                       session_id, resource_id, eir_id, buffer_size, ret );

	      const cMarshalType *reply[4];
	      reply[0] = &SaErrorType; // SA_OK
	      reply[1] = &SaHpiUint32Type;  // actual size

	      const void *params[3];
	      params[0] = &ret;
	      params[1] = &actual_size;

	      if ( ret != SA_OK || buffer == 0 )
		   reply[2] = 0;		   
	      else
		 {
  		   reply[2] = &SaHpiInventoryDataType, // inventory data
		   reply[3] = 0;		   

		   params[2] = buffer;		   
		 }

	      rh.m_len = MarshalArray( reply, params, rd );

	      if ( buffer )
		   delete [] buffer;
	    }

	    break;

       case eFsaHpiEntityInventoryDataWrite:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiEirIdT      eir_id;
	      unsigned char    buffer[10240];

	      HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &eir_id, buffer );

	      ret = saHpiEntityInventoryDataWrite( session_id, resource_id, eir_id,
						   (SaHpiInventoryDataT *)(void *)buffer );

	      DbgFunc( "saHpintityInventoryDataWrite( %x, %x, %x ) = %d\n",
                       session_id, resource_id, eir_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    break;

       case eFsaHpiWatchdogTimerGet:
	    {
	      SaHpiSessionIdT   session_id;
	      SaHpiResourceIdT  resource_id;
	      SaHpiWatchdogNumT watchdog_num;
	      SaHpiWatchdogT    watchdog;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &watchdog_num );

	      ret = saHpiWatchdogTimerGet( session_id, resource_id,
					   watchdog_num, &watchdog );

	      DbgFunc( "saHpiWatchdogTimerGet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, watchdog_num, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &watchdog );
	    }

	    break;

       case eFsaHpiWatchdogTimerSet:
	    {
	      SaHpiSessionIdT   session_id;
	      SaHpiResourceIdT  resource_id;
	      SaHpiWatchdogNumT watchdog_num;
	      SaHpiWatchdogT    watchdog;

	      HpiDemarshalRequest4( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &watchdog_num,
				    &watchdog );

	      ret = saHpiWatchdogTimerSet( session_id, resource_id,
					   watchdog_num, &watchdog );
	      
	      DbgFunc( "saHpiWatchdogTimerSet( %x, %x, %x ) = %d\n",
                       session_id, resource_id, watchdog_num, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    
	    break;

       case eFsaHpiWatchdogTimerReset:
	    {
	      SaHpiSessionIdT   session_id;
	      SaHpiResourceIdT  resource_id;
	      SaHpiWatchdogNumT watchdog_num;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &watchdog_num );

	      ret = saHpiWatchdogTimerReset( session_id, resource_id,
					     watchdog_num );

	      DbgFunc( "eFsaHpiWatchdogTimerReset( %x, %x, %x ) = %d\n",
                       session_id, resource_id, watchdog_num, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    
	    break;

       case eFsaHpiHotSwapControlRequest:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id );

	      ret = saHpiHotSwapControlRequest( session_id, resource_id );

	      DbgFunc( "saHpiHotSwapControlRequest( %x, %x ) = %d\n",
                       session_id, resource_id , ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiResourceActiveSet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id );

	      ret = saHpiResourceActiveSet( session_id, resource_id );
	      
	      DbgFunc( "saHpiResourceActiveSet( %x, %x ) = %d\n",
                       session_id, resource_id , ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    
	    break;

       case eFsaHpiResourceInactiveSet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id );

	      ret = saHpiResourceInactiveSet( session_id, resource_id );

	      DbgFunc( "saHpiResourceInactiveSet( %x, %x ) = %d\n",
                       session_id, resource_id , ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiAutoInsertTimeoutGet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiTimeoutT   timeout;
	      
	      HpiDemarshalRequest1( header.m_flags & dMhEndianBit, hm, data,
				   &session_id );

	      ret = saHpiAutoInsertTimeoutGet( session_id, &timeout );
	      
	      DbgFunc( "saHpiAutoInsertTimeoutGet( %x ) = %d\n",
                       session_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &timeout );
	    }

	    break;

       case eFsaHpiAutoInsertTimeoutSet:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiTimeoutT   timeout;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &timeout );

	      ret = saHpiAutoInsertTimeoutSet( session_id, timeout );
	      
	      DbgFunc( "saHpiAutoInsertTimeoutSet( %x ) = %d\n",
                       session_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    
	    break;

       case eFsaHpiAutoExtractTimeoutGet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiTimeoutT    timeout;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id );

	      ret = saHpiAutoExtractTimeoutGet( session_id, resource_id, &timeout );

	      DbgFunc( "saHpiAutoExtractTimeoutGet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &timeout );
	    }

	    break;

       case eFsaHpiAutoExtractTimeoutSet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiTimeoutT    timeout;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &timeout );

	      ret = saHpiAutoExtractTimeoutSet( session_id, resource_id, timeout );

	      DbgFunc( "saHpiAutoExtractTimeoutSet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiHotSwapStateGet:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiHsStateT    state;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id );

	      ret = saHpiHotSwapStateGet( session_id, resource_id, &state );

	      DbgFunc( "saHpiHotSwapStateGet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &state );
	    }
	    
	    break;

       case eFsaHpiHotSwapActionRequest:
	    {
	      SaHpiSessionIdT session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiHsActionT   action;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &action );

	      ret = saHpiHotSwapActionRequest( session_id, resource_id, action );

	      DbgFunc( "saHpiHotSwapActionRequest( %x, %x ) = %d\n",
                       session_id, resource_id , ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    
	    break;

       case eFsaHpiResourcePowerStateGet:
	    {
	      SaHpiSessionIdT    session_id;
	      SaHpiResourceIdT   resource_id;
	      SaHpiHsPowerStateT state;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id );

	      ret = saHpiResourcePowerStateGet( session_id, resource_id, &state );
	      
	      DbgFunc( "saHpiResourcePowerStateGet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &state );
	    }
	    
	    break;

       case eFsaHpiResourcePowerStateSet:
	    {
	      SaHpiSessionIdT    session_id;
	      SaHpiResourceIdT   resource_id;
	      SaHpiHsPowerStateT state;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id, &state  );

	      ret = saHpiResourcePowerStateSet( session_id, resource_id, state );

	      DbgFunc( "(saHpiResourcePowerStateSet %x, %x ) = %d\n",
                       session_id, resource_id , ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       case eFsaHpiHotSwapIndicatorStateGet:
	    {
	      SaHpiSessionIdT        session_id;
	      SaHpiResourceIdT       resource_id;
	      SaHpiHsIndicatorStateT state;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				   &session_id, &resource_id );

	      ret = saHpiHotSwapIndicatorStateGet( session_id, resource_id, &state );

	      DbgFunc( "saHpiHotSwapIndicatorStateGet( %x, %x ) = %d\n",
                       session_id, resource_id , ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &state );
	    }

	    break;

       case eFsaHpiHotSwapIndicatorStateSet:
	    {
	      SaHpiSessionIdT        session_id;
	      SaHpiResourceIdT       resource_id;
	      SaHpiHsIndicatorStateT state;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &state );

	      ret = saHpiHotSwapIndicatorStateSet( session_id, resource_id, state );

	      DbgFunc( "saHpiHotSwapIndicatorStateSet( %x, %x ) = %d\n",
                       session_id, resource_id , ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }
	    
	    break;

       case eFsaHpiParmControl:
	    {
	      SaHpiSessionIdT  session_id;
	      SaHpiResourceIdT resource_id;
	      SaHpiParmActionT action;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &action );

	      ret = saHpiParmControl( session_id, resource_id, action );

	      DbgFunc( "saHpiParmControl( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret  );
	    }

	    break;

       case eFsaHpiResourceResetStateGet:
	    {
	      SaHpiSessionIdT   session_id;
	      SaHpiResourceIdT  resource_id;
	      SaHpiResetActionT reset_action;

	      HpiDemarshalRequest2( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id );

	      ret = saHpiResourceResetStateGet( session_id, resource_id,
						&reset_action );

	      DbgFunc( "saHpiResourceResetStateGet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply1( hm, rd, &ret, &reset_action );
	    }

	    break;

       case eFsaHpiResourceResetStateSet:
	    {
	      SaHpiSessionIdT   session_id;
	      SaHpiResourceIdT  resource_id;
	      SaHpiResetActionT reset_action;

	      HpiDemarshalRequest3( header.m_flags & dMhEndianBit, hm, data,
				    &session_id, &resource_id, &reset_action );

	      ret = saHpiResourceResetStateSet( session_id, resource_id, reset_action );

	      DbgFunc( "saHpiResourceResetStateSet( %x, %x ) = %d\n",
                       session_id, resource_id, ret );

	      rh.m_len = HpiMarshalReply0( hm, rd, &ret );
	    }

	    break;

       default:
	    assert( 0 );
	    break;
     }

  assert( rh.m_len <= hm->m_reply_len );

  return eResultReply;
}
예제 #16
0
void
cOpenHpiDaemon::Idle()
{
  // read events to keep auto insertion/extraction running
  SaHpiEventT    event;
  SaHpiRdrT      rdr;
  SaHpiRptEntryT rpt_entry;

  SaErrorT ret = saHpiEventGet( m_session, SAHPI_TIMEOUT_IMMEDIATE, &event, &rdr, &rpt_entry );

  if ( ret == SA_OK )
     {
       DbgEvent( "idle: saHpiEventGet read event\n" );

       if ( m_debug & dDebugEvent )
	    print_event( &event );
     }
  else if ( ret == SA_ERR_HPI_TIMEOUT )
       DbgEvent( "idle: saHpiEventGet timeout.\n", ret );
  else
       DbgEvent( "idle: saHpiEventGet %s.\n", decode_error( ret ) );

  SaHpiTimeT now;
  gettimeofday1( &now );

  // check for pending event get
  for( int i = m_num_connections - 1; i >= 0; i-- )
     {
       cConnection *c = m_connections[i];

       // ping
       if ( now > c->PingTimer() )
	  {
	    if ( c->OutstandingPings() )
	       {
		 // ping timeout
		 DbgPing( "ping timeout !\n" );
		 CloseConnection( i );
		 continue;
	       }
	    else if ( now > c->PingTimer() )
	       {
		 // send ping
		 cMessageHeader header;
		 MessageHeaderInit( &header, eMhPing, 1, 0, 0 );

		 int rv = ConnectionWriteHeader( c->Fd(), &header );

		 if ( rv )
		    {
		      DbgPing( "cannot send ping !\n" );
		      CloseConnection( i );
		      continue;
		    }

		 DbgPing( "send ping.\n" );

		 c->OutstandingPings() = 1;

		 // set ping timer
		 SaHpiTimeT ti;
		 
		 gettimeofday1( &ti );
		 ti += dPingTimeout;

		 c->PingTimer() = ti;
	       }
	  }

       for( GList *e = c->Sessions(); e; e = g_list_next( e ) )
	  {
	    cSession *s = (cSession *)e->data;

	    if ( !s->IsEventGet() )
		 continue;

	    // check for event
	    ret = saHpiEventGet( s->SessionId(), SAHPI_TIMEOUT_IMMEDIATE,
					  &event, &rdr, &rpt_entry );

	    if (    ret == SA_ERR_HPI_TIMEOUT
		 && now < s->Timeout() )
		 continue;

	    if ( ret == SA_ERR_HPI_TIMEOUT )
		 DbgEvent( "saHpiEventGet( %x ): TIMEOUT\n",
			   s->SessionId() );
	    else
		 DbgEvent( "saHpiEventGet( %x ): send event\n",
			   s->SessionId() );

	    s->EventGet( false );

	    // send response
	    cHpiMarshal *hm = HpiMarshalFind( eFsaHpiEventGet );
	    assert( hm );

	    cMessageHeader rh;
	    MessageHeaderInit( &rh, eMhReply, s->Seq(), eFsaHpiEventGet,
			       hm->m_reply_len );

	    // alloc reply buffer
	    void *rd = calloc( 1, hm->m_reply_len );

	    rh.m_len = HpiMarshalReply3( hm, rd, &ret, &event, &rdr, &rpt_entry );

	    int rv = ConnectionWriteMsg( c->Fd(), &rh, rd );

	    if ( rd )
		 free( rd );

	    // cannot send message => close connection
	    if ( rv )
		 CloseConnection( i );
	  }
     }
}
예제 #17
0
int main()
{
	SaHpiSessionIdT sid;
	SaHpiEventT event;
	SaHpiRptEntryT rpt_entry;
	SaHpiResourceIdT rid;
	SaHpiSeverityT severity_old, severity_new;
	int i;
	SaErrorT status;
	int ret = SAF_TEST_UNKNOWN;

	printf("\n*****************Domain func begin***************\n");

	status = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sid, NULL);

	if (status != SA_OK) {
		e_print(saHpiSessionOpen, SA_OK, status);
		ret = SAF_TEST_UNRESOLVED;
	} else {

		status = saHpiSubscribe(sid);

		if (status != SA_OK) {
			e_print(saHpiSubscribe, SA_OK, status);
			ret = SAF_TEST_UNRESOLVED;
		} else {
			/* User inserts a FRU manually */
			read_prompt("Now pls. insert a FRU in the domain ...\n"
				    "Then press Enter key to continue ...\n");

			for (i = 0;;) {
				status =
				    saHpiEventGet(sid, TIMEOUT, &event, NULL,
						  &rpt_entry, NULL);

				if (status == SA_ERR_HPI_TIMEOUT
				    && ++i == TIMES) {
					m_print
					    ("The timeout value has been reached, but the user did not enter an FRU.");
					ret = SAF_TEST_UNRESOLVED;
					break;
				} else if (status != SA_OK) {
					e_print(saHpiEventGet, SA_OK, status);
					ret = SAF_TEST_UNRESOLVED;
					break;
				} else if ((event.EventType == SAHPI_ET_HOTSWAP) &&
					       ((event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_ACTIVE) ||
					        (event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_INSERTION_PENDING))) {
					rid = rpt_entry.ResourceId;
					severity_old = rpt_entry.ResourceSeverity;
					break;
				}
			}

			if (ret == SAF_TEST_UNKNOWN) {

				if (severity_old != SAHPI_CRITICAL)
					severity_new = SAHPI_CRITICAL;
				else
					severity_new = SAHPI_MAJOR;

				status = saHpiResourceSeveritySet(sid, rid, severity_new);

				if (status != SA_OK) {
					e_print(saHpiResourceSeveritySet, SA_OK, status);
					ret = SAF_TEST_UNRESOLVED;
				} else {

					read_prompt
					    ("Now please create a \"surprise extraction\" by removing the\n"
						 "the same FRU you just inserted to identify its ResourceId ...\n"
					     "Then press the Enter key to continue ...\n");

					for (i = 0;;) {
						status = saHpiEventGet(sid, TIMEOUT, &event, NULL,
								               &rpt_entry, NULL);

						if (status == SA_ERR_HPI_TIMEOUT) {
							if (++i == TIMES) {
								m_print
							   	 ("The timeout value has been reached, but the user did not plug out an FRU.");
								ret = SAF_TEST_UNRESOLVED;
								break;
							}
						} else if (status != SA_OK) {
							e_print(saHpiEventGet, SA_OK, status);
							ret = SAF_TEST_UNRESOLVED;
							break;
						} else if (event.EventType == SAHPI_ET_HOTSWAP && 
								   event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_NOT_PRESENT &&
								   rpt_entry.ResourceId == rid && event.Severity == severity_new) {
							ret = SAF_TEST_PASS;
							break;
						}
					}
				}

				if (ret == SAF_TEST_UNKNOWN) {
					ret = SAF_TEST_FAIL;
				}

				saHpiResourceSeveritySet(sid, rid, severity_old);
			}

			status = saHpiUnsubscribe(sid);
		}

		status = saHpiSessionClose(sid);
	}

	printf("\n  return=%s\n",get_test_result(ret));
	printf("\n*****************Domain func end*****************\n");

	return ret;
}
예제 #18
0
static gpointer event_thread_loop(gpointer data)
{
        SaErrorT rv;
        SaHpiEventT          event;
        SaHpiRdrT            rdr;
        SaHpiRptEntryT       rpt_entry;
        SaHpiEvtQueueStatusT event_queue_status;
	
	int counter = 0;

        SaHpiSessionIdT sessionid = *(SaHpiSessionIdT *)data;

        while(get_run_threaded()) {
	
		memset(&event, 0, sizeof(event));
                DEBUGMSGTL ((AGENT, "event_thread_loop started ---- sessionid [%d]\n", sessionid));
                rv = saHpiEventGet (get_session_id(SAHPI_UNSPECIFIED_DOMAIN_ID),
                                    timeout,
                                    &event,
                                    &rdr,
                                    &rpt_entry,
                                    &event_queue_status);

                DEBUGMSGTL ((AGENT, "rv [%s]\n", oh_lookup_error(rv)));

                counter++;

                /* serialize access */
                g_mutex_lock(thread_mutex);

		if (rv == SA_OK) { // NEW
		
		 	DEBUGMSGTL ((AGENT, "Event Type [%s]\n", 
                                     oh_lookup_eventtype(event.EventType)));
               	 	oh_print_event(&event, 0);
                	
			switch (event.EventType) {
                		case SAHPI_ET_RESOURCE:
                        		DEBUGMSGTL ((AGENT, "SAHPI_ET_RESOURCE, [%s]\n",
                                     	oh_lookup_resourceeventtype(
                                             	event.EventDataUnion.ResourceEvent.ResourceEventType)));
                        		break;
                		case SAHPI_ET_DOMAIN:
                      		DEBUGMSGTL ((AGENT, "SAHPI_ET_DOMAIN, [%s]\n",
                                   oh_lookup_domaineventtype(
                                           event.EventDataUnion.DomainEvent.Type)));
                       			break;
                		case SAHPI_ET_SENSOR:              
                        		break;
                		case SAHPI_ET_SENSOR_ENABLE_CHANGE:
                        		break;
               		 	case SAHPI_ET_HOTSWAP:
                       			break;
                		case SAHPI_ET_WATCHDOG:            
                        		break;
                		case SAHPI_ET_HPI_SW:  
                        		DEBUGMSGTL ((AGENT, "SAHPI_ET_HPI_SW, [%s]\n",
                                     		oh_lookup_sweventtype(
                                             		event.EventDataUnion.HpiSwEvent.Type)));
                        		break;
                		case SAHPI_ET_OEM:              
                        		DEBUGMSGTL ((AGENT, "SAHPI_ET_HPI_SW, [%s]\n",
                                     		oh_lookup_sweventtype(
                                             		event.EventDataUnion.HpiSwEvent.Type)));
                        		break;
                		case SAHPI_ET_USER: 
                        		break;
                		default:
                       		 	break;
               	 	}

                	rv = async_event_add(sessionid, &event, &rdr, &rpt_entry);
						

		} // NEW
                /* serialize access */
		
		// Now check for updates to the event logs
		rv = event_log_info_update(sessionid);
		
		if (rediscover == SAHPI_TRUE)
		{
		     repopulate_tables(get_session_id(SAHPI_UNSPECIFIED_DOMAIN_ID));
		     rediscover = SAHPI_FALSE;
		}     
		
		
		if (counter == 30) { //check for new announcements every minute.
              		update_announcements(get_session_id(SAHPI_UNSPECIFIED_DOMAIN_ID));
			counter = 0;
		}
                g_mutex_unlock(thread_mutex);

        }
        g_thread_exit(0);
        return data;
}