Ejemplo n.º 1
0
static SaErrorT exechandlercreate (int argc, char **argv, int i)
{
   SaErrorT rv = SA_OK;
   oHpiHandlerIdT handlerid = 0;
   GHashTable * createparams = g_hash_table_new_full (
      g_str_hash, g_str_equal, g_free, g_free);
   SaHpiBoolT pluginnamegiven = SAHPI_FALSE;

   if (copt.debug) DBG ("createhandler started\n");

   while (i<argc){
      if (strcmp(argv[i],"-f")==0) {
         CRIT("input from file not implemented yet");
         return (SA_OK);
      }
      else if (++i<argc) {
         if (strcmp(argv[i-1],"plugin")==0) pluginnamegiven = SAHPI_TRUE;
         g_hash_table_insert( createparams,
            g_strdup( argv[i-1] ), 
            g_strdup( argv[i] ));
          if (copt.debug) DBG ("Pair of arguments: %s - %s\n",
            g_strdup( argv[i-1] ), 
            g_strdup( argv[i] ));
      }
      else // parameters not in pairs
         return (SA_ERR_HPI_INVALID_PARAMS);
      i++;
   }

   if (!pluginnamegiven) {
      CRIT("You must enter a valid plugin name");
      return (SA_ERR_HPI_INVALID_PARAMS);
   }

   rv = ohc_session_open_by_option ( &copt, &sessionid);
   if (rv != SA_OK) return rv;

   if (copt.debug) DBG("Calling oHpiHandlerCreate!");
   rv = oHpiHandlerCreate(sessionid, createparams, &handlerid );

   if ( rv != SA_OK ) {
      CRIT("oHpiHandlerCreate returned %s", oh_lookup_error(rv));
      saHpiSessionClose(sessionid);
      return(rv);
   }
   
   printf("Handler %u successfully created!\n", handlerid);

   rv = saHpiSessionClose(sessionid);
        
   return(SA_OK);

}
Ejemplo n.º 2
0
int main (int argc, char *argv []) {
	SaErrorT 		err;
	SaHpiSessionIdT 	session_id;

	err =  saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &session_id, NULL);
	if (err != SA_OK) {
		printf("%s: saHpiSessionOpen failed\n", argv[0]);
		printf("%s: the daemon may not be running\n", argv[0]);
		return (-1);
	}

	err =  saHpiDiscover(session_id);
	if (err != SA_OK) {
		printf("%s: saHpiDiscover failed\n", argv[0]);
		return (-1);
	}

	err =  saHpiSessionClose(session_id);
	if (err != SA_OK) {
		printf("%s: saHpiSessionClose failed\n", argv[0]);
		return (-1);
	}

	return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    SaHpiSessionIdT sid = 0;
    SaErrorT rc = SA_OK;
    int retc;

    rc = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sid, NULL);
	if(rc != SA_OK)
		return -1;

	rc = saHpiDiscover(sid);
	if (rc != SA_OK)
		return -1;

    /* inject an event */
    retc = inject_event("simulator");
    if (retc != 0) {
        return -1;
    }

    /* sleep so the msg thread gets a chance to process the msg */
    g_usleep(100000);

    saHpiSessionClose(sid);

    return 0;
}
Ejemplo n.º 4
0
static void
bladehpi_destroy(StonithPlugin *s)
{
	struct pluginDevice *	dev;

	if (Debug) {
		LOG(PIL_DEBUG, "%s: called", __FUNCTION__);
	}

	VOIDERRIFWRONGDEV(s);

	dev = (struct pluginDevice *)s;

	dev->pluginid = NOTpluginID;
	if (dev->device) {
		FREE(dev->device);
		dev->device = NULL;
	}
	if (dev->idinfo) {
		FREE(dev->idinfo);
		dev->idinfo = NULL;
	}
	free_bladehpi_hostlist(dev);

	if (dev->ohsession) {
		saHpiSessionClose(dev->ohsession);
		dev->ohsession = 0;
	}
	
	FREE(dev);
}
Ejemplo n.º 5
0
SaErrorT tsetup (SaHpiSessionIdT *sessionid_ptr)
{

        SaErrorT err = SA_OK;	
        /* ************************	 	 
	 * Hook in simulation environment
	 * ***********************/
        
        err = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, sessionid_ptr, NULL);
        if (err != SA_OK) {
                printf("Error! Can not open session.\n");
		printf("  File=%s, Line=%d\n", __FILE__, __LINE__);
                printf("  Received error=%s\n", oh_lookup_error(err));
        }
        
        if (!err) err = saHpiDiscover(*sessionid_ptr);
        if (err != SA_OK) {
                printf("Error! Can not discover resources.\n");
		printf("   File=%s, Line=%d\n", __FILE__, __LINE__);
                printf("   Received error=%s\n", oh_lookup_error(err));
                err = saHpiSessionClose(*sessionid_ptr);
        }
        
        return err;	 
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
        SaErrorT err;
        SaHpiSessionIdT sessionid;

        err = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
        if (err) {
	  printf("  Error! Testcase failed. Line=%d\n", __LINE__);
	  printf("  Received error=%s\n", oh_lookup_error(err));
	  return -1;
        }
	// regular sim_init is part of saHpiSessionOpen, here we close it
	sim_close();
	// env variable OPENHPI_SIMTEST_FILE is now defined in Makefile.am
	// setenv("OPENHPI_SIMTEST_FILE","./sim_test_file", 1);
	// create hash table based on input file
	err = sim_file();
	if (err != SA_OK) {
	  printf(" Error! sim_file failed\n");
	  return -1;
	} 

	/****************** 
	 * End of testcases 
         ******************/

        err = saHpiSessionClose(sessionid);
        if (err) {
	  printf("Error! saHpiSessionClose: err=%d\n", err);
	  return -1;
        }

        return 0;
}
Ejemplo n.º 7
0
static void
close_hpi_session(struct pluginDevice *dev)
{
	if (dev && dev->ohsession) {
		saHpiSessionClose(dev->ohsession);
		dev->ohsession = 0;
	}
}
Ejemplo n.º 8
0
SaErrorT closeSession(SaHpiSessionIdT sessionId)
{
	SaErrorT status;

	status = saHpiSessionClose(sessionId);
	if (status != SA_OK) {
		e_print(saHpiSessionClose, SA_OK, status);
	}
	return status;
}
Ejemplo n.º 9
0
SaErrorT tcleanup(SaHpiSessionIdT *sessionid_ptr)
{

	SaErrorT err = SA_OK;
	/***************************
	 * Close session, free memory
	 ***************************/
	 err = saHpiSessionClose(*sessionid_ptr);
	 return(err);

}
Ejemplo n.º 10
0
int close_session()
{
	SaErrorT rv;

	pthread_kill(ge_thread, SIGKILL);
	
	rv = saHpiSessionClose(sessionid);
	if (rv != SA_OK) {
                printf("saHpiSessionClose error %s\n", oh_lookup_error(rv));
                return -1;
        }
	return 0;
}
Ejemplo n.º 11
0
int main(int argc, char **argv)
{
	int		c, i;
	SaErrorT	rv;
	char		buf[READ_BUF_SIZE];
	char		*S;

	printf("%s  ver %s\n", argv[0], progver);
	while ( (c = getopt( argc, argv,"x?")) != EOF )
		switch(c)  {
			case 'x':
				fdebug = 1;
				break;
			default:
				printf("Usage: %s [-x]\n", argv[0]);
				printf("   -x  Display debug messages\n");
				return(1);
		}

	rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);

	if (rv != SA_OK) {
		printf("saHpiSessionOpen: %s\n", oh_lookup_error(rv));
		return(-1);
	}
 
	rv = saHpiDiscover(sessionid);

	if (fdebug) printf("saHpiDiscover: %s\n", oh_lookup_error(rv));

	rv = saHpiSubscribe(sessionid);
	if (rv != SA_OK) {
		printf( "saHpiSubscribe error %d\n",rv);
		return(-1);
	}	
	
	/* make the RPT list */
	get_rpts();
	/* get rdrs for the RPT list */
	for (i = 0; i < nrpts; i++)
		get_rdrs(Rpts + i);

	help();
	for (;;) {
		printf("==> ");
		S = fgets(buf, READ_BUF_SIZE, stdin);
		if (parse_command(S) < 0) break;
	};
	rv = saHpiSessionClose(sessionid);
	return(0);
}
Ejemplo n.º 12
0
/* 
 * Main                
 */
int
main(int argc, char **argv)
{
	SaErrorT 	rv = SA_OK;
	SaHpiSessionIdT sessionid;
        GOptionContext *context;
	    
        /* Print version strings */
        oh_prog_version(argv[0]);

        /* Parsing options */
        static char usetext[]="- Display system topology\n  "
                              OH_SVN_REV; 
        OHC_PREPARE_REVISION(usetext);
        context = g_option_context_new (usetext);
        g_option_context_add_main_entries (context, my_options, NULL);

        if (!ohc_option_parse(&argc, argv, 
                context, &copt, 
                OHC_ALL_OPTIONS 
                    - OHC_ENTITY_PATH_OPTION  //TODO: Feature 880127?
                    - OHC_VERBOSE_OPTION )) { // no verbose mode implemented
                g_option_context_free (context);
		return 1;
	}
        g_option_context_free (context);
 
	if (f_rpt || f_sensor || f_inv || f_ctrl || f_rdr || f_wdog) 
           f_listall = TRUE;
	if (f_resourceid != 0) f_allres = FALSE;

        rv = ohc_session_open_by_option ( &copt, &sessionid);
	if (rv != SA_OK) return rv;

	/*
	 * Resource discovery
	 */
	if (copt.debug) DBG("saHpiDiscover");
	rv = saHpiDiscover(sessionid);
	if (rv != SA_OK) {
		CRIT("saHpiDiscover returns %s",oh_lookup_error(rv));
		return rv;
	}

	printf("Discovery done\n");
	list_resources(sessionid, (SaHpiResourceIdT) f_resourceid);

	rv = saHpiSessionClose(sessionid);
	
	return 0;
}
Ejemplo n.º 13
0
int close_session()
{
	SaErrorT rv;

	/* Bug 2171901, replace pthread_kill(ge_thread, SIGKILL); */
	pthread_cancel(ge_thread);
	
	rv = saHpiSessionClose(Domain->sessionId);
	if (rv != SA_OK) {
                printf("saHpiSessionClose error %s\n", oh_lookup_error(rv));
                return -1;
        }
	return 0;
}
Ejemplo n.º 14
0
int close_session()
{
	SaErrorT rv;

	Domain->session_opened = 0;
	rv = saHpiSessionClose(Domain->sessionId);
	if (rv != SA_OK) {
                printf("saHpiSessionClose error %s\n", oh_lookup_error(rv));
                return -1;
        }
	// Wait a bit for get_event thread completion
	g_usleep(G_USEC_PER_SEC / 4);
	return 0;
}
Ejemplo n.º 15
0
cConnection::~cConnection()
{
  if ( m_con )
       ServerConnectionClose( m_con );

  while( m_sessions )
     {
       cSession *s = (cSession *)m_sessions->data;
       saHpiSessionClose( s->SessionId() );

       m_sessions = g_list_remove( m_sessions, s );
       delete s;
     }
}
Ejemplo n.º 16
0
int main(int argc, char **argv)
{
        int number_resources=0;
        SaErrorT rv;
        SaHpiSessionIdT sessionid;
        SaHpiResourceIdT resourceid;
        SaHpiIdrIdT IdrId = SAHPI_DEFAULT_INVENTORY_ID;
        SaHpiIdrInfoT IdrInfo;
        SaHpiResourceIdT resourceid_list[RESOURCE_CAP_LENGTH] = {0};
        SaHpiCapabilitiesT capability = SAHPI_CAPABILITY_INVENTORY_DATA;

        printf("saHpiIdrInfoGet: Test for hpi IDR info get function\n");

        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
        if (rv != SA_OK) {
                printf("saHpiSessionOpen failed with error: %s\n",
                       oh_lookup_error(rv));
                return rv;
        }

        /* Discover the resources with IDR capability */
        printf("\nListing the resource with IDR capability \n");
        rv = discover_resources(sessionid, capability, resourceid_list,
                                &number_resources);
        if (rv != SA_OK) {
                exit(-1);
        }

        printf("\nPlease enter the resource id whose idr area header "
               "is required: ");
        scanf("%d", &resourceid);

        rv = saHpiIdrInfoGet(sessionid, resourceid, IdrId,&IdrInfo);
        if (rv != SA_OK) {
                printf("saHpiIdrInfoGet failed with error: %s\n",
                       oh_lookup_error(rv));
                printf("Test case - FAIL\n");
        }
        else {
                oh_print_idrinfo(&IdrInfo,6);
                printf("Test case - PASS\n");
        }

        rv = saHpiSessionClose(sessionid);
        return 0;
}
Ejemplo n.º 17
0
int close_session()
{
	SaErrorT rv;

	pthread_kill(ge_thread, SIGKILL);
	
	rv = saHpiSessionClose(sessionid);
	if (rv != SA_OK) {
                printf("saHpiSessionClose error %d\n", rv);
                return -1;
        }
	rv = saHpiFinalize();
	 if (rv != SA_OK) {
                printf("saHpiFinalize error %d\n", rv);
                return -1;
        }
	return 0;
}
Ejemplo n.º 18
0
void
cOpenHpiDaemon::Finalize()
{  
  while( m_num_connections )
       CloseConnection( 0 );

  if ( m_pollfd )
       delete [] m_pollfd;

  if ( m_main_socket )
     {
       ServerConnectionMainClose(  m_main_socket );
       m_main_socket = 0;
     }

  saHpiUnsubscribe( m_session );
  saHpiSessionClose( m_session );
  saHpiFinalize();
}
Ejemplo n.º 19
0
int main(int argc, char **argv)
{
        SaErrorT        rv = SA_OK;
        SaHpiSessionIdT sessionid;
        SaHpiResourceIdT resourceId = SAHPI_UNSPECIFIED_RESOURCE_ID;
        SaHpiEventLogEntryIdT currentId = SAHPI_FIRST_ENTRY, prevId, nextId;
        SaHpiEventLogEntryT entry;
        SaHpiRdrT rdr;
        SaHpiRptEntryT rptentry;
        SaHpiEntityPathT *ep = NULL;

        printf("saHpiEventLogEntyGet: Test for hpi eventlog "
               "entry get function\n");
        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
        if (rv != SA_OK) {
                printf("saHpiSessionOpen failed with error: %s\n",
                       oh_lookup_error(rv));
                exit(-1);
        }

        do {
                rv = saHpiEventLogEntryGet(sessionid, resourceId, currentId,
                                           &prevId, &nextId, &entry, &rdr,
                                           &rptentry);
                if (rv != SA_OK) {
                        printf("Get event log entry failed with error: %s\n",
                               oh_lookup_error(rv));
                        printf("Test case - FAIL\n");
                        exit (-1);
                }

                if (rptentry.ResourceCapabilities) {
                        ep = &rptentry.ResourceEntity;
                        oh_print_eventlogentry(&entry, ep, 6);
                }
                currentId = nextId;
        } while (nextId != SAHPI_NO_MORE_ENTRIES);

        printf("Test case - PASS\n");
        rv = saHpiSessionClose(sessionid);
        return 0;
}
Ejemplo n.º 20
0
/**********************************************************
*
*   Open a new session passing a buffer for security parameters.
*
*   Expected return:  saHpiSessionOpen() returns 
*                     SA_ERR_HPI_INVALID_PARAMS.
*
*   Main Function
*      takes no arguments
*      
*       returns: SAF_TEST_PASS when successfull
*                SAF_TEST_FAIL when an unexpected error occurs
*************************************************************/
int main(int argc, char **argv)
{
	SaHpiSessionIdT session;
	SaErrorT status;
	int retval = SAF_TEST_UNKNOWN;
	void *allocation;

	// Create an allocation to hold an undeterminable amount of data
	// In case the function succeeds

	allocation = malloc(1024);
	if (allocation == NULL) {
		retval = SAF_TEST_UNRESOLVED;
		m_print("Failed to allocate memory!");
	} else {
		//
		// Pass in a buffer pointer for the security parameters
		//
		status =
		    saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &session,
				     allocation);

		if (status == SA_ERR_HPI_INVALID_PARAMS) {
			retval = SAF_TEST_PASS;
		} else {
			retval = SAF_TEST_FAIL;
			e_print(saHpiSessionOpen,
				SA_ERR_HPI_INVALID_PARAMS, status);
		}

		// If by chance the call did work, then clean up
		if (status == SA_OK) {
			status = saHpiSessionClose(session);
		}

		free(allocation);
	}

	return (retval);
}
Ejemplo n.º 21
0
/**
 * main: main program loop
 *
 *
 *
 * Return value: int 0
 **/
int main(int arc, const char *argv[])
{
        SaErrorT 		err;
        SaHpiVersionT		version;
        SaHpiSessionIdT 	session_id;
        SaHpiRptEntryT		entry;
        //SaHpiSelInfoT		Info;
        
	
	/* First step in HPI and openhpi */
        err = saHpiInitialize(&version);
        if (SA_OK != err) {
                error("saHpiInitialize", err);
                exit(-1);
        }
        
	/* Every domain requires a new session */
	/* This example is for one domain, one session */
        err = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID, &session_id, NULL);
        if (SA_OK != err) {
                error("saHpiSessionOpen", err);
                return err;
        }
        
        err = discover_domain(SAHPI_DEFAULT_DOMAIN_ID, session_id, entry);
        if (SA_OK != err) {
                warn("an error was encountered, results may be incomplete");
        }

        saHpiSessionClose(session_id);

        err = saHpiFinalize();
        if (SA_OK != err) {
                error("saHpiFinalize", err);
                exit(-1);

	}
	return 0;
}
Ejemplo n.º 22
0
int
main(int argc, char **argv)
{
  int c;
  SaHpiVersionT hpiVer;
  SaHpiSessionIdT sessionid;
  SaHpiRptInfoT rptinfo;
  SaHpiRptEntryT rptentry;
  SaHpiEntryIdT rptentryid;
  SaHpiEntryIdT nextrptentryid;
  SaHpiEntryIdT entryid;
  SaHpiEntryIdT nextentryid;
  SaHpiResourceIdT resourceid;
  SaHpiRdrT rdr;

  printf("%s  ver %s\n", progname,progver);
  sensor_name = (char *)strdup(s_name);
  while ( (c = getopt( argc, argv,"ms:xz?")) != EOF )
  switch(c)
  {
    case 'z': fxdebug = 1; /* fall thru to include next setting */
    case 'x': fdebug = 1; break;
	      /*
    case 'l': slist = 1; break;
	      */
    case 'm': 
	      sensor_name = (char *)strdup(sm_name);
	      break;
    case 's':
	  fsensor = 1;
          if (optarg) {
	    sensor_name = (char *)strdup(optarg);
	  }
          break;
    default:
          printf("Usage: %s [-xm] [-s sensor_descriptor]\n", progname);
          printf("   -s  Sensor descriptor\n");
          printf("   -m  use Mullins sensor descriptor\n");
	  /*
          printf("   -l  Display entire sensor list\n");
	  */
          printf("   -x  Display debug messages\n");
          printf("   -z  Display extra debug messages\n");
          exit(1);
  }

  rv = saHpiInitialize(&hpiVer);

  if (rv != SA_OK) {
    printf("saHpiInitialize error %d\n",rv);
    exit(-1);
  }
  rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,&sessionid,NULL);

  if (rv != SA_OK) {
    printf("saHpiSessionOpen error %d\n",rv);
    exit(-1);
  }
 
  rv = saHpiResourcesDiscover(sessionid);

  if (fxdebug) printf("saHpiResourcesDiscover rv = %d\n",rv);

  rv = saHpiRptInfoGet(sessionid,&rptinfo);

  if (fxdebug) printf("saHpiRptInfoGet rv = %d\n",rv);
  if (fdebug) printf("RptInfo: UpdateCount = %d, UpdateTime = %lx\n",
         rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);
 
  /* walk the RPT list */
  rptentryid = SAHPI_FIRST_ENTRY;
  while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY))
  {
    rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
    if (rv == SA_OK)
    {
      /* walk the RDR list for this RPT entry */
      entryid = SAHPI_FIRST_ENTRY;
      rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0;
      resourceid = rptentry.ResourceId;
      
      if (fdebug) printf("rptentry[%d] resourceid=%d\n", entryid,resourceid);

      printf("Resource Tag: %s\n", rptentry.ResourceTag.Data);
      while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY))
      {
        rv = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr);

  	if (fxdebug) printf("saHpiRdrGet[%d] rv = %d\n",entryid,rv);

	if (rv == SA_OK)
	{
	  if (rdr.RdrType == SAHPI_SENSOR_RDR)
	  { 
	    /*type 2 includes sensor and control records*/
	    rdr.IdString.Data[rdr.IdString.DataLength] = 0;
	    if (strncmp(rdr.IdString.Data, sensor_name,
		rdr.IdString.DataLength) == 0)
	    {
	      printf( "%02d %s\t", rdr.RecordId, rdr.IdString.Data);
	      DoEvent( sessionid, resourceid, &rdr.RdrTypeUnion.SensorRec);
	      if (rv != SA_OK)
	        printf( "Returned Error from DoEvent: rv=%d\n", rv);
	    }
	  } 
	  if (rv != SA_OK)
	      printf( "Returned HPI Error: rv=%d\n", rv);
	  entryid = nextentryid;
        }
      }
      rptentryid = nextrptentryid;
    }
  }
  rv = saHpiSessionClose(sessionid);
  rv = saHpiFinalize();
  exit(0);
}
Ejemplo n.º 23
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);
}
Ejemplo n.º 24
0
int main(int argc, char **argv)
{
   int c;
   SaErrorT rv;
   SaErrorT rvx;
   SaHpiVersionT hpiVer;
   SaHpiSessionIdT sessionid;
   SaHpiRptInfoT rptinfo;
   SaHpiRptEntryT rptentry;
   SaHpiEntryIdT rptentryid;
   SaHpiEntryIdT nextrptentryid;
   SaHpiResourceIdT resourceid;

   char input[255], *p;
   pthread_t discover_thread;
   void *thread_done;
   int valid = 0;

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

   while ((c = getopt(argc, argv, "x?")) != EOF) {
        switch (c) {
                case 'x':
                        debug = 1;
                        break;
                default:
                        printf("Usage: %s [-x]\n", progname);
                        printf("   -x  Display debug messages\n");
                        exit(1);
        }
   }

   rv = saHpiInitialize(&hpiVer);
   
   if (rv != SA_OK) {
     	printf("saHpiInitialize error %d\n", rv);
	exit(-1);
   }

   rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID, &sessionid, NULL);
   if (rv != SA_OK) {
     	printf("saHpiSessionOpen error %d\n", rv);
	exit(-1);
   }

   rv = saHpiResourcesDiscover(sessionid);
   if (debug)
     	printf("saHpiResourcesDiscover rv = %d\n", rv);

restart:
   rv = saHpiRptInfoGet(sessionid, &rptinfo);
   if (debug)
     	printf("saHpiRptInfoGet rv = %d\n", rv);

   printf("RptInfo: UpdateCount = %d, UpdateTime = %lx\n",
	  rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);
   
   /* walk the RPT list */

   rptentryid = SAHPI_FIRST_ENTRY;
   rvx = SA_OK;

   while ((rvx == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) {
        rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid,
                              &rptentry);
	if (rvx != SA_OK)
	  	printf("RptEntryGet: rv = %d\n", rv);

	if (rvx == SA_OK && (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_RDR)
	    		&& (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA)) {

                resourceid = rptentry.ResourceId;

                list_inv(sessionid, resourceid);

        }

        rptentryid = nextrptentryid;
   }

   printf("Initial discovery done\n");
   printf("\tEnter a command or \"help\" for list of commands\n");
   printf("Command> ");

   rv = pthread_create(&discover_thread, NULL, sahpi_discover_thread,
		      (void *)sessionid);

   if (rv)
     printf("Error creating event thread\n");

   while (!valid) {
        
        fflush(stdout);
        
        p = fgets(input, 255, stdin);
        
        if ((p = strchr(input, '\n')) != NULL)
            *p = '\0';
        
        if (!strcmp(input, "list_all_inv")) {
            goto restart;
        }
     
        if (!strcmp(input, "list_inv")) {
            list_rpt(sessionid);
            printf("Enter resource id:");
            
            p = fgets(input, 255, stdin);
            if ((p = strchr(input, '\n')) != NULL)
                *p = '\0';

            list_inv(sessionid, (SaHpiResourceIdT) atoi(input));
        }

        if (!strcmp(input, "set_tag")) {
            rv = set_resource_tag(sessionid);
            if (rv)
                printf("Error setting tag\n");
        }

        if (!strcmp(input, "list_rpt")) {
            list_rpt(sessionid);
        }

        if (!strcmp(input, "help")) {
            usage();
        }

        if (!strcmp(input, "quit")) {
            valid = 1;
            thread = 0;

            rv = pthread_join(discover_thread, &thread_done);
            if (rv)
                printf("Error joining thread\n");

            printf("Discovery %s\n", (char *)thread_done);
            break;

        } else {
            printf("Type command (help for list) or \"quit\" to exit\n");
            printf("Command> ");
        }
   }

   rv = saHpiSessionClose(sessionid);
   rv = saHpiFinalize();

   exit(0);
}
Ejemplo n.º 25
0
int main(int argc, char **argv)
{
        char c;
        SaErrorT rv;
        SaHpiVersionT hpiVer;
        SaHpiSessionIdT sessionid;
        SaHpiRptInfoT rptinfo;
        SaHpiRptEntryT rptentry;
        SaHpiEntryIdT rptentryid;
        SaHpiEntryIdT nextrptentryid;
        SaHpiEntryIdT entryid;
        SaHpiEntryIdT nextentryid;
        SaHpiResourceIdT resourceid;
        SaHpiRdrT rdr;
        
        printf("%s: version %s\n",argv[0],progver); 
        
        while ( (c = getopt( argc, argv,"tx?")) != EOF )
                switch(c) {
                case 't': fshowthr = 1; break;
                case 'x': fdebug = 1; break;
                default:
                        printf("Usage %s [-t -x]\n",argv[0]);
                        printf("where -t = show Thresholds also\n");
                        printf("      -x = show eXtra debug messages\n");
                        exit(1);
                }
        rv = saHpiInitialize(&hpiVer);
        if (rv != SA_OK) {
                printf("saHpiInitialize: %s\n",decode_error(rv));
                exit(-1);
        }
        rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,&sessionid,NULL);
        if (rv != SA_OK) {
                if (rv == SA_ERR_HPI_ERROR) 
                        printf("saHpiSessionOpen: error %d, 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);
        
#ifdef BUGGY
        /* ARC: Bug here in OpenHPI requires re-doing discovery (workaround). */
        { 
                int updcnt;
                int i = 0;
                updcnt = rptinfo.UpdateCount;
                while (rptinfo.UpdateCount == updcnt) {
                        rv = saHpiResourcesDiscover(sessionid);
                        if (fdebug) printf("saHpiResourcesDiscover %s\n",decode_error(rv));
                        rv = saHpiRptInfoGet(sessionid,&rptinfo);
                        if (fdebug) printf("saHpiRptInfoGet %s\n",decode_error(rv));
                        printf("RptInfo/%d: UpdateCount = %d, UpdateTime = %lx\n",
                               ++i,rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);
                }
        }  /*end openhpi bug workaround*/
#endif
        
        /* walk the RPT list */
        rptentryid = SAHPI_FIRST_ENTRY;
        while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY))
        {
                rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
                if (fdebug) printf("saHpiRptEntryGet %s\n",decode_error(rv));
                if (rv == SA_OK) {
                        /* walk the RDR list for this RPT entry */
                        entryid = SAHPI_FIRST_ENTRY;
                        resourceid = rptentry.ResourceId;
                        rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; 
                        printf("rptentry[%d] resourceid=%d tag: %s\n",
                               entryid,resourceid, rptentry.ResourceTag.Data);
                        while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY))
                        {
                                rv = saHpiRdrGet(sessionid,resourceid,
                                                 entryid,&nextentryid, &rdr);
                                if (fdebug) printf("saHpiRdrGet[%d] rv = %d\n",entryid,rv);
                                if (rv == SA_OK) {
                                        char *eol;
                                        rdr.IdString.Data[rdr.IdString.DataLength] = 0;
                                        if (rdr.RdrType == SAHPI_SENSOR_RDR) eol = "    \t";
                                        else eol = "\n";
                                        printf("RDR[%02d]: %s %s %s",rdr.RecordId,
                                               rtypes[rdr.RdrType],rdr.IdString.Data,eol);
                                        if (rdr.RdrType == SAHPI_SENSOR_RDR) {
                                                ShowSensor(sessionid,resourceid,
                                                           &rdr.RdrTypeUnion.SensorRec);
                                        } 
                                        entryid = nextentryid;
                                } else {
                                        rv = SA_OK;
                                        entryid = SAHPI_LAST_ENTRY;
                                }
                        }
                        rptentryid = nextrptentryid;
                }
        }
        
        rv = saHpiSessionClose(sessionid);
        rv = saHpiFinalize();
        
        exit(0);
        return(0);
}
Ejemplo n.º 26
0
/* 
 * Main                
 */
int
main(int argc, char **argv)
{
	SaErrorT 	rv = SA_OK;
	
	SaHpiVersionT	hpiVer;
	SaHpiSessionIdT sessionid;
	SaHpiResourceIdT resourceid = all_resources;

	int c;
	    
	printf("\n\n%s ver %s\n",argv[0],progver);
	while ( (c = getopt( argc, argv,"adrsoiwcn:x?")) != EOF ) {
		switch(c) {
			case 'a': f_listall = 1; break;
			case 'c': f_ctrl    = 1; break;
			case 'd': f_rdr     = 1; break;
			case 'i': f_inv     = 1; break;
			case 'r': f_rpt     = 1; break;
			case 's': f_sensor  = 1; break; 
			case 'w': f_wdog    = 1; break;
			case 'o': f_overview = 1; break; 			 
			case 'n':
				if (optarg)
					resourceid = atoi(optarg);
				else 
					resourceid = all_resources;
				break;
			case 'x': fdebug = 1; break;
			default:
				printf("\n\tUsage: %s [-option]\n\n", progname);
				printf("\t      (No Option) Display all rpts and rdrs\n");
				printf("\t           -a     Display all rpts and rdrs\n");
				printf("\t           -c     Display only controls\n");
				printf("\t           -d     Display rdr records\n");
				printf("\t           -i     Display only inventories\n");
				printf("\t           -o     Display system overview: rpt & rdr headers\n");				
				printf("\t           -r     Display only rpts\n");
				printf("\t           -s     Display only sensors\n");
				printf("\t           -w     Display only watchdog\n");				
				printf("\t           -n     Select particular resource id to display\n");
				printf("\t                  (Used with [-cdirs] options)\n");
				printf("\t           -x     Display debug messages\n");
				printf("\n\n\n\n");
				exit(1);
		}
	}
 
	if (argc == 1) f_listall = 1;

	/* 
	 * House keeping:
	 * 	-- get (check?) hpi implementation version
	 *      -- open hpi session	
	 */
	if (fdebug) printf("saHpiVersionGet\n");
	hpiVer = saHpiVersionGet();
	printf("Hpi Version %d Implemented.\n", hpiVer);

	if (fdebug) printf("saHpiSessionOpen\n");
        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
	if (rv != SA_OK) {
		printf("saHpiSessionOpen returns %s\n",oh_lookup_error(rv));
		exit(-1);
	}
	if (fdebug)
	       	printf("saHpiSessionOpen returns with SessionId %d\n", sessionid);

	/*
	 * Resource discovery
	 */
	if (fdebug) printf("saHpiDiscover\n");
	rv = saHpiDiscover(sessionid);
	if (rv != SA_OK) {
		printf("saHpiDiscover returns %s\n",oh_lookup_error(rv));
		exit(-1);
	}

	printf("Discovery done\n");
	list_resources(sessionid, resourceid);

	rv = saHpiSessionClose(sessionid);
	
	exit(0);
}
Ejemplo n.º 27
0
int main(int argc, char **argv)
{
        int number_resources=0, j;
        SaErrorT rv;
        SaHpiSessionIdT sessionid;
        SaHpiResourceIdT resourceid;
        SaHpiResourceIdT resourceid_list[RESOURCE_CAP_LENGTH] = {0};
        SaHpiSensorNumT sensor_num;
        SaHpiSensorDataFormatT format;
        SaHpiCapabilitiesT capability = SAHPI_CAPABILITY_SENSOR;
        SaHpiBoolT val = SAHPI_TRUE;

        memset(&format, 0, sizeof(format));
        printf("saHpiSensorReadingGet: Test for hpi sensor reading "
               "get function\n");

        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
        if (rv != SA_OK) {
                printf("saHpiSessionOpen failed with error: %s\n",
                       oh_lookup_error(rv));
                return rv;
        }

        /* Discover the resources with sensor capability */
        printf("\nListing the resource with sensor capability \n");
        rv = discover_resources(sessionid, capability, resourceid_list,
                                &number_resources);
        if (rv != SA_OK) {
                exit(-1);
        }

        printf("\nPlease enter the resource id: ");
        scanf("%d", &resourceid);

        printf("Press 1 for TEMPERATURE sensor\n");
        printf("Press 2 for POWER sensor\n");
        printf("Press 3 for FAN SPEED sensor\n");
        printf("Enter your choice: ");
        scanf("%d", &sensor_num);

        switch (sensor_num) {
                case 1:
                        sensor_num = OA_SOAP_RES_SEN_TEMP_NUM;
                        format.BaseUnits = SAHPI_SU_DEGREES_C;
                        break;
                case 2:
                        sensor_num = OA_SOAP_RES_SEN_POWER_NUM;
                        format.BaseUnits = SAHPI_SU_WATTS;
                        break;
                case 3:
                        sensor_num = OA_SOAP_RES_SEN_FAN_NUM;
                        format.BaseUnits = SAHPI_SU_RPM;
                        break;
                default :
                        printf("Wrong choice. Exiting");
                        exit (-1);
        }

        printf("\nPlease enter whether you want to enable or disable "
               "this sensor for reading\n");
        printf("Press 1 for Enable\n");
        printf("Press 2 for Disable\n");
        printf("Enter your choice:");
        scanf("%d",&j);

        if (j == 1){
                val=SAHPI_TRUE;
        }else if (j == 2){
                val= SAHPI_FALSE;
        }
        format.ReadingType = SAHPI_SENSOR_READING_TYPE_FLOAT64;

        rv = saHpiSensorEnableSet(sessionid, resourceid, sensor_num, val);
        if (rv != SA_OK) {
                printf("saHpiSensorEnableSet failed with error: %s\n",
                       oh_lookup_error(rv));
                printf("Test case - FAIL\n");
                exit(-1);
        }
        printf("\nTest case - PASS\n");

        rv = saHpiSessionClose(sessionid);
        return 0;
}
Ejemplo n.º 28
0
int
main(int argc, char **argv)
{
  int c;
  SaErrorT rv,rv_rdr;
  SaHpiSessionIdT sessionid;
  SaHpiDomainInfoT rptinfo;
  SaHpiRptEntryT rptentry;
  SaHpiEntryIdT rptentryid;
  SaHpiEntryIdT nextrptentryid;
  SaHpiEntryIdT entryid;
  SaHpiEntryIdT nextentryid;
  SaHpiResourceIdT resourceid;
  SaHpiRdrT rdr;
  SaHpiIdrInfoT idrInfo;
  SaHpiIdrIdT 	idrid;
  int invfound = 0;
  int nloops = 0;

  oh_prog_version(argv[0], OH_SVN_REV);
  atag.tlen = 0;

  while ( (c = getopt( argc, argv,"a:vxz?")) != EOF )
  switch(c) {
    case 'z': fzdebug = 1; /* fall thru to include next setting */
    case 'x': fdebug = 1; break;
    case 'v': fverbose = 1; break;
    case 'a':
          fasset = 1;
          if (optarg) {
	    atag.tag  = (char *)strdup(optarg);
	    atag.tlen = strlen(optarg);
	  }
          break;
    default:
          printf("Usage: %s [-x] [-a asset_tag]\n", argv[0]);
          printf("   -a  Sets the asset tag\n");
          printf("   -x  Display debug messages\n");
          printf("   -z  Display extra debug messages\n");
          exit(1);
  }

	/* compile error */
//  inv = (SaHpiIdrAreaHeaderT *)&inbuff[0];
  inv = (SaHpiIdrAreaHeaderT *)(void *)&inbuff[0];
  rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
  if (fdebug) printf("saHpiSessionOpen rv = %d sessionid = %x\n",rv,sessionid);
  if (rv != SA_OK) {
    printf("saHpiSessionOpen error %d\n",rv);
    exit(-1);
  }
 
  rv = saHpiDomainInfoGet(sessionid,&rptinfo);
  if (fdebug) printf("saHpiDomainInfoGet rv = %d\n",rv);
  // if (fdebug) printf("RptInfo: UpdateCount = %x, UpdateTime = %lx\n",
  //      rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);

  while (!invfound && (nloops < 7)) 
  {
    /*
     * The OpenHPI ipmi plugin has a bug whereby the FRU RDR is added 
     * much later, and always requires a rediscovery. (bug #1095256)
     * This should not apply to other well-behaved plugins.
     */
    nloops++;
    if (fdebug) printf("Starting Discovery, pass %d ...\n",nloops);
    rv = saHpiDiscover(sessionid);
    if (fdebug) printf("saHpiDiscover rv = %d\n",rv);
    if (rv != SA_OK) {
        printf("saHpiDiscover error %d\n",rv);
        break;
    }
 
  /* walk the RPT list */
  rptentryid = SAHPI_FIRST_ENTRY;
  while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY))
  {
    rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
    if (rv != SA_OK) printf("RptEntryGet: rid=%d rv = %d\n",rptentryid,rv);
    if (rv == SA_OK)
    {
      /* walk the RDR list for this RPT entry */
      entryid = SAHPI_FIRST_ENTRY;
      /* OpenHPI plugin sometimes has bad RPT Tag DataLength here. */
      // rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0;
      resourceid = rptentry.ResourceId;
      if (fdebug) printf("rptentry[%d] resourceid=%d\n", rptentryid,resourceid);
      if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA)
      {
        printf("Resource[%d] Tag: %s \thas inventory capability\n", rptentryid,rptentry.ResourceTag.Data);
	rv_rdr = SA_OK;
	while ((rv_rdr == SA_OK) && (entryid != SAHPI_LAST_ENTRY))
	{
          rv_rdr = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr);
  	  if (fdebug) printf("saHpiRdrGet[%x] rv = %d\n",entryid,rv_rdr);
	  if (rv_rdr == SA_OK)
	  {
  	    if (fdebug) printf("Rdr[%x] type = %d tag = %s\n",entryid,
				rdr.RdrType,rdr.IdString.Data);
	    if (rdr.RdrType == SAHPI_INVENTORY_RDR)
	    { 
	      invfound = 1;
	      /*type 3 includes inventory records*/
	      rdr.IdString.Data[rdr.IdString.DataLength] = 0;	    
	      idrid = rdr.RdrTypeUnion.InventoryRec.IdrId;
	      buffersize = sizeof(inbuff);
	      if (fdebug) {
		 printf("Rdr[%x] is inventory, IdrId=%x\n",rdr.RecordId,idrid);
		 printf("Inv BufferSize=%d\n", buffersize);
	      }
	      if ( IsTagBmc((char *)rdr.IdString.Data, rdr.IdString.DataLength) )
	      {
		/* Get all of the inventory data areas and fields */
		memset(inv,0,buffersize);
		rv_rdr = saHpiIdrInfoGet(sessionid, resourceid, idrid, &idrInfo);
		if (rv_rdr != SA_OK) {
		   printf("IDR Info error: rv_rdr = %d\n",rv_rdr);
		} else {  /* idrInfo is ok */
		   if (fdebug) printf("IDR Info: ok \n");
		   print_epath(&rptentry.ResourceEntity, 1);
	           printf("RDR[%x]: Inventory, IdrId=%x %s\n",rdr.RecordId,
			idrid,rdr.IdString.Data);
		   print_idrinfo(&idrInfo,4);
		   rv_rdr = walkInventory(sessionid, resourceid, &idrInfo);
		   if (fdebug) printf("walkInventory rv_rdr = %d\n",rv_rdr);
		}
		
		if (!ent_writable(&rptentry.ResourceEntity,&idrInfo))
			foundasset = 0;
		if ((fasset == 1) && (foundasset == 1)) {
			SaHpiIdrFieldT  atagField;
			atagField.Type = SAHPI_IDR_FIELDTYPE_ASSET_TAG;
			atagField.ReadOnly = SAHPI_FALSE;
			atagField.AreaId = atag.areaid;
			atagField.FieldId = atag.fieldid;
			strptr=&(atagField.Field);
			strptr->DataType = SAHPI_TL_TYPE_TEXT; 
			strptr->Language = SAHPI_LANG_ENGLISH;
			strptr->DataLength = (SaHpiUint8T)atag.tlen;
			strncpy((char *)strptr->Data, atag.tag, atag.tlen);
			strptr->Data[atag.tlen] = 0;
			printf( "Writing new asset tag: %s\n",strptr->Data);
		        rv_rdr = saHpiIdrFieldSet(sessionid, resourceid, 
						atag.idrid, &atagField);
			printf("Return Write Status = %d\n", rv_rdr);
			if (rv_rdr == SA_OK) {
			   printf ("Good write - re-reading!\n");
			   rv_rdr = walkInventory(sessionid, resourceid, &idrInfo);
			   if (fdebug) printf("walkInventory rv_rdr = %d\n",rv_rdr);
			} /* Good write - re-read */
		   }  /*endif fasset*/
  		}  /*endif RDR tag ok*/
	      } /* Inventory Data Records - Type 3 */ 
	      else if (fdebug) printf("rdr type = %d\n", rdr.RdrType);
	    }  /*endif RdrGet ok*/
	    entryid = nextentryid;
          } /*end while rdr*/
        } /*endif rpt invent capab*/
        else 
	  if (fdebug) printf("Resource[%d] Tag: %s\n", rptentryid,
				rptentry.ResourceTag.Data);
      }  /*endif rpt ok*/
      rptentryid = nextrptentryid;
  }  /*end rpt loop */
    if (fdebug) printf("loop %d inventory found = %d\n",nloops,invfound);
  }  /*end while no inv */
  rv = saHpiSessionClose(sessionid);
  exit(0);
}
Ejemplo n.º 29
0
ret_code_t domain_proc(void)
{
	SaHpiDomainInfoT	info;
	SaHpiEntryIdT		entryid, nextentryid;
	SaHpiDrtEntryT		drtentry;
	SaErrorT		rv;
	SaHpiDomainIdT		id;
	SaHpiSessionIdT		sessionId;
	int			i, n, first;
	gpointer		ptr;
	Domain_t		*domain = (Domain_t *)NULL;
	Domain_t		*new_domain;
	term_def_t		*term;

	term = get_next_term();
	if (term == NULL) {
		printf("Domain list:\n");
		printf("    ID: %d   SessionId: %d", Domain->domainId,
			Domain->sessionId);
		rv = saHpiDomainInfoGet(Domain->sessionId, &info);
		if (rv == SA_OK) {
			print_text_buffer_text("    Tag: ",
				&(info.DomainTag), NULL, ui_print);
		};
		printf("\n");
		entryid = SAHPI_FIRST_ENTRY;
		first = 1;
		while (entryid != SAHPI_LAST_ENTRY) {
			rv = saHpiDrtEntryGet(Domain->sessionId, entryid,
				&nextentryid, &drtentry);
			if (rv != SA_OK) break;
			if (first) {
				first = 0;
				printf("        Domain Reference Table:\n");
			};
			printf("            ID: %d", drtentry.DomainId);
			entryid = nextentryid;
			rv = saHpiSessionOpen(drtentry.DomainId,
						&sessionId, NULL);
			if (rv != SA_OK) {
				printf("\n");
				continue;
			};
			rv = saHpiDomainInfoGet(sessionId, &info);
			if (rv == SA_OK) {
				print_text_buffer_text("    Tag: ",  &(info.DomainTag), NULL, ui_print);
			};
			saHpiSessionClose(sessionId);
			printf("\n");
		}
		return(HPI_SHELL_OK);
	};

	if (isdigit(term->term[0]))
		id = (int)atoi(term->term);
	else
		return HPI_SHELL_PARM_ERROR;
	n = g_slist_length(domainlist);
	for (i = 0; i < n; i++) {
		ptr = g_slist_nth_data(domainlist, i);
		if (ptr == (gpointer)NULL) break;
		domain = (Domain_t *)ptr;
		if (domain->domainId == id) break;
	};
	if (i >= n) {
		new_domain = (Domain_t *)malloc(sizeof(Domain_t));
		memset(new_domain, 0, sizeof(Domain_t));
		new_domain->domainId = id;
		if (add_domain(new_domain) < 0) {
			free(new_domain);
			printf("Can not open domain: %d\n", id);
			return HPI_SHELL_PARM_ERROR;
		};
		domain = new_domain;
	};
	Domain = domain;
	set_Subscribe(Domain, prt_flag);
	add_domain(Domain);
	return(HPI_SHELL_OK);
}
Ejemplo n.º 30
0
int     main(int argc, char **argv)
{
        int number_resources=0;
        SaErrorT rv;
        SaHpiSessionIdT sessionid;
        SaHpiResourceIdT resourceid;
        SaHpiIdrIdT IdrId = SAHPI_DEFAULT_INVENTORY_ID;
        SaHpiEntryIdT areaId;
        SaHpiIdrFieldTypeT fieldType =SAHPI_IDR_FIELDTYPE_UNSPECIFIED;
        SaHpiEntryIdT fieldId=SAHPI_FIRST_ENTRY , nextFieldId;
        SaHpiIdrFieldT field;
        SaHpiResourceIdT resourceid_list[RESOURCE_CAP_LENGTH] = {0};
        SaHpiCapabilitiesT capability = SAHPI_CAPABILITY_INVENTORY_DATA;

        printf("saHpiIdrFieldGet: Test for hpi IDR field get function\n");

        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
        if (rv != SA_OK) {
                printf("saHpiSessionOpen failed with error: %s\n",
                       oh_lookup_error(rv));
                return rv;
        }

        /* Discover the resources with IDR capability */
        printf("\nListing the resource with IDR capability \n");
        rv = discover_resources(sessionid, capability, resourceid_list,
                                &number_resources);
        if (rv != SA_OK) {
                exit(-1);
        }

        printf("\nPlease enter the resource id: ");
        scanf("%d", &resourceid);
        printf("Please enter the area id: ");
        scanf("%d", &areaId);
        printf("Getting the Field for all the fieldTypes for the resource..\n");

        rv = saHpiIdrFieldGet(sessionid, resourceid,IdrId, areaId, fieldType,
                              fieldId, &nextFieldId, &field);
        if (rv != SA_OK) {
                printf("saHpiIdrFieldGet failed with error: %s\n",
                       oh_lookup_error(rv));
                printf("Test case - FAIL\n");
                exit (-1);
        }
        oh_print_idrfield(&field,6);

        while (nextFieldId != SAHPI_LAST_ENTRY) {
                fieldId=nextFieldId;
                rv = saHpiIdrFieldGet(sessionid, resourceid, IdrId,
                                      areaId, fieldType, fieldId,
                                      &nextFieldId, &field);
                if (rv != SA_OK) {
                        printf("saHpiIdrFieldGet failed with error: %s\n",
                               oh_lookup_error(rv));
                        printf("Test case - FAIL\n");
                        exit (-1);
                }
                oh_print_idrfield(&field,6);
        }

        printf("Test case - PASS\n");
        rv = saHpiSessionClose(sessionid);
        return 0;
}