/** * main: Get 10 new unique ids. Remove two. Look up removed ids by ep. * Passes if lookups don't find anything, * otherwise fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { SaHpiEntityPathT ep; guint id[10], i; if (oh_uid_initialize()) return 1; oh_init_ep(&ep); for (i = 0; i < 10; i++) { ep.Entry[0].EntityLocation = i; id[i] = oh_uid_from_entity_path(&ep); } if (oh_uid_remove(id[9])) return 1; if (oh_uid_remove(id[4])) return 1; ep.Entry[0].EntityLocation = 9; if (oh_uid_lookup(&ep)) return 1; ep.Entry[0].EntityLocation = 4; if (oh_uid_lookup(&ep)) return 1; return 0; }
/** * main: Get 10 new unique ids. Remove two. Look up removed ids. * Passes if lookups don't find anything, * otherwise fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { SaHpiEntityPathT ep, rep; guint id[10], i; if (oh_uid_initialize()) return 1; ep_init(&ep); for (i = 0; i < 10; i++) { ep.Entry[0].EntityInstance = i; id[i] = oh_uid_from_entity_path(&ep); } if (oh_uid_remove(id[8])) return 1; if (oh_uid_remove(id[3])) return 1; if (!oh_entity_path_lookup(id+8,&rep)) return 1; if (!oh_entity_path_lookup(id+3,&rep)) return 1; return 0; }
int main( int argc, char *argv[] ) { if ( argc > 2 ) return usage( argv[0] ); const char *config_name = "lan_local"; if ( argc == 2 ) config_name = argv[1]; const char **config = FindConfig( config_name ); if ( config == 0 ) return usage( argv[0] ); void *dummy; struct oh_abi_v2 *abi = 0; GHashTable *params; void *hdl; uuid_t myuid; oh_uid_initialize(); memcpy( &myuid, UUID_OH_ABI_V2, sizeof(myuid) ); if ( ipmidirect_get_interface( &dummy, myuid ) < 0 || dummy == 0 ) { printf( "cannot get interface !\n" ); return 10; } abi = (struct oh_abi_v2 *) dummy; if ( abi->open == 0 ) { printf( "cannot get interface !\n" ); return 10; } params = AllocParams( config ); hdl = abi->open( params ); if ( hdl == 0 ) { printf( "cannot open plugin !\n" ); return 10; } printf( "ready.\n" ); TestInterface( abi, hdl ); abi->close( hdl ); DestryParams( params ); return 0; }
/** * main: Calls oh_entity_path_lookup using a NULL id. * Passes if it returns -1, * otherwise fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { SaHpiEntityPathT ep, rep; ep_init(&ep); if (oh_uid_initialize()) return 1; if (!oh_uid_from_entity_path(&ep)) return 1; if (!oh_entity_path_lookup(NULL, &rep)) return 1; return 0; }
/** * main: Get a new unique id. Get another one with the same entity path. * Passes if returned id is equal to previous one, * otherwise fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { SaHpiEntityPathT ep; guint id, rid; if (oh_uid_initialize()) return 1; ep_init(&ep); id = oh_uid_from_entity_path(&ep); rid = oh_uid_from_entity_path(&ep); if (id != rid) return 1; return 0; }
/** * main: Calls oh_entity_path_lookup using a NULL entity path. * Passes if it returns -1, * otherwise fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { SaHpiEntityPathT ep; guint id; oh_init_ep(&ep); if (oh_uid_initialize()) return 1; id = oh_uid_from_entity_path(&ep); if (!id) return 1; if (!oh_entity_path_lookup(id, NULL)) return 1; return 0; }
/** * main: Get a new unique id. Use id to lookup original entity path. * Passes if returned entity path is equal to original entity path, * otherwise fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { SaHpiEntityPathT ep, rep; guint id; if (oh_uid_initialize()) return 1; ep_init(&ep); id = oh_uid_from_entity_path(&ep); if (oh_entity_path_lookup(&id, &rep)) return 1; if (ep_cmp(&ep, &rep)) return 1; return 0; }
/** * main: Get 10 new unique ids. Get 10 more with the same entity paths. * Passes if returned ids are equal to previous ones, * otherwise fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { SaHpiEntityPathT ep; guint id[10], rid, i; if (oh_uid_initialize()) return 1; oh_init_ep(&ep); for (i = 0; i < 10; i++) { ep.Entry[0].EntityLocation = i; id[i] = oh_uid_from_entity_path(&ep); } for (i = 0; i < 10; i++) { ep.Entry[0].EntityLocation = i; rid = oh_uid_from_entity_path(&ep); if (id[i] != rid) return 1; } return 0; }
/** * oh_init * * Returns: 0 on success otherwise an error code **/ int oh_init(void) { static int initialized = 0; struct oh_global_param param; struct oh_parsed_config config = { NULL, 0, 0 }; SaErrorT rval; if (g_thread_supported() == FALSE) { g_thread_init(0); } data_access_lock(); if (initialized) { /* Don't initialize more than once */ data_access_unlock(); return 0; } /* Initialize event queue */ oh_event_init(); #ifdef HAVE_OPENSSL INFO("Initializing SSL Library."); if (oh_ssl_init()) { CRIT("SSL library intialization failed."); data_access_unlock(); return SA_ERR_HPI_OUT_OF_MEMORY; /* Most likely */ } #endif /* Set openhpi configuration file location */ oh_get_global_param2(OPENHPI_CONF, ¶m); #ifdef _WIN32 char config_file[MAX_PATH]; DWORD cc = ExpandEnvironmentStrings(param.u.conf, config_file, MAX_PATH); if ((cc != 0) && (cc < MAX_PATH)) { INFO("Loading config file %s.", config_file); rval = oh_load_config(config_file, &config); } else { CRIT("Failed to expand config file path: %s", param.u.conf); rval = SA_ERR_HPI_ERROR; } #else INFO("Loading config file %s.", param.u.conf); rval = oh_load_config(param.u.conf, &config); #endif /* _WIN32 */ /* Don't error out if there is no conf file */ if (rval < 0 && rval != -4) { CRIT("Can not load config."); data_access_unlock(); return SA_ERR_HPI_NOT_PRESENT; } /* One particular variable, OPENHPI_UNCONFIGURED, can cause us to exit * immediately, without trying to run the daemon any further. */ oh_get_global_param2(OPENHPI_UNCONFIGURED, ¶m); if (param.u.unconfigured != SAHPI_FALSE) { CRIT("OpenHPI is not configured. See config file."); data_access_unlock(); return SA_ERR_HPI_ERROR; } /* Initialize uid_utils */ INFO("Initializing UID."); rval = oh_uid_initialize(); if( (rval != SA_OK) && (rval != SA_ERR_HPI_ERROR) ) { CRIT("Unique ID intialization failed."); data_access_unlock(); return rval; } /* Initialize handler table */ oh_handlers.table = g_hash_table_new(g_int_hash, g_int_equal); /* Initialize domain table */ oh_domains.table = g_hash_table_new(g_int_hash, g_int_equal); /* Initialize session table */ oh_sessions.table = g_hash_table_new(g_int_hash, g_int_equal); /* Load plugins, create handlers and domains */ oh_process_config(&config); INFO("Creating default domain."); oh_get_global_param2(OPENHPI_AUTOINSERT_TIMEOUT, ¶m); SaHpiTimeoutT ai_timeout = param.u.ai_timeout; INFO("Auto-Insert Timeout is %" PRId64 " nsec.", (int64_t)ai_timeout); oh_get_global_param2(OPENHPI_AUTOINSERT_TIMEOUT_READONLY, ¶m); SaHpiDomainCapabilitiesT caps = 0; if ( param.u.ai_timeout_readonly != SAHPI_FALSE ) { INFO("Auto-Insert Timeout is READ-ONLY."); caps = SAHPI_DOMAIN_CAP_AUTOINSERT_READ_ONLY; } rval = oh_create_domain(OH_DEFAULT_DOMAIN_ID, "DEFAULT", SAHPI_UNSPECIFIED_DOMAIN_ID, SAHPI_UNSPECIFIED_DOMAIN_ID, caps, ai_timeout); if (rval != SA_OK) { data_access_unlock(); CRIT("Could not create first domain!"); return SA_ERR_HPI_ERROR; } /* * Wipes away configuration lists (plugin_names and handler_configs). * global_params is not touched. */ oh_clean_config(&config); /* * If any handlers were defined in the config file AND * all of them failed to load, Then return with an error. */ if (config.handlers_defined > 0 && config.handlers_loaded == 0) { WARN("Warning: Handlers were defined, but none loaded."); } else if (config.handlers_defined > 0 && config.handlers_loaded < config.handlers_defined) { WARN("*Warning*: Not all handlers defined loaded." " Check previous messages."); } /* Start discovery and event threads */ oh_threaded_start(); initialized = 1; data_access_unlock(); INFO("OpenHPI has been initialized."); /* infrastructure initialization has completed at this point */ /* Check if there are any handlers loaded */ if (config.handlers_defined == 0) { WARN("*Warning*: No handler definitions found in config file." " Check configuration file and previous messages" ); } /* * HACK: wait a second before returning * to give the threads time to populate the RPT */ g_usleep(G_USEC_PER_SEC); /* Do not use SA_OK here in case it is ever changed to something * besides zero, The runtime stuff depends on zero being returned here * in order for the shared library to be completely initialized. */ return 0; }
/** * _init * * Returns: 0 on success otherwise an error code **/ int _init(void) { struct oh_parsed_config config = {NULL, NULL, 0, 0, 0, 0}; struct oh_global_param config_param = { .type = OPENHPI_CONF }; SaErrorT rval; SaHpiDomainCapabilitiesT capabilities = 0x00000000; SaHpiTextBufferT tag; data_access_lock(); /* Initialize thread engine */ oh_threaded_init(); /* Set openhpi configuration file location */ oh_get_global_param(&config_param); rval = oh_load_config(config_param.u.conf, &config); /* Don't error out if there is no conf file */ if (rval < 0 && rval != -4) { dbg("Can not load config."); data_access_unlock(); return SA_ERR_HPI_NOT_PRESENT; } /* Initialize uid_utils */ rval = oh_uid_initialize(); if( (rval != SA_OK) && (rval != SA_ERR_HPI_ERROR) ) { dbg("Unique ID intialization failed."); data_access_unlock(); return rval; } trace("Initialized UID."); /* Initialize handler table */ oh_handlers.table = g_hash_table_new(g_int_hash, g_int_equal); trace("Initialized handler table"); /* Initialize domain table */ oh_domains.table = g_hash_table_new(g_int_hash, g_int_equal); trace("Initialized domain table"); /* Create first domain */ oh_init_textbuffer(&tag); oh_append_textbuffer(&tag,"First Domain"); if (!oh_create_domain(capabilities, SAHPI_TIMEOUT_IMMEDIATE, &tag)) { data_access_unlock(); dbg("Could not create first domain!"); return SA_ERR_HPI_ERROR; } trace("Created first domain"); /* Initialize session table */ oh_sessions.table = g_hash_table_new(g_int_hash, g_int_equal); trace("Initialized session table"); /* Load plugins and create handlers*/ oh_process_config(&config); /* * Wipes away configuration lists (plugin_names and handler_configs). * global_params is not touched. */ oh_clean_config(&config); /* * If any handlers were defined in the config file AND * all of them failed to load, Then return with an error. */ if (config.handlers_defined > 0 && config.handlers_loaded == 0) { data_access_unlock(); dbg("Error: Handlers were defined, but none loaded."); return SA_ERR_HPI_ERROR; } else if (config.handlers_defined > 0 && config.handlers_loaded < config.handlers_defined) { dbg("*Warning*: Not all handlers defined loaded." " Check previous messages."); } /* this only does something if the config says to */ struct oh_global_param my_global_param; my_global_param.type = OPENHPI_DAEMON_MODE; oh_get_global_param(&my_global_param); if (!my_global_param.u.daemon_mode) { oh_threaded_start(); dbg("### We ARE Starting infrastructure threads in _init() ###\n"); } else { dbg("### We ARE NOT Starting infrastructure threads in _init() ###\n"); } trace("Set init state"); data_access_unlock(); /* infrastructure initialization has completed at this point */ /* Check if there are any handlers loaded */ if (config.handlers_defined == 0) { dbg("*Warning*: No handler definitions found in config file." " Check configuration file %s and previous messages", config_param.u.conf); } /* * HACK: If threaded mode is on, wait a second before returning * to give the threads time to populate the RPT */ if (oh_threaded_mode()) { struct timespec waittime = { .tv_sec = 1, .tv_nsec = 1000L}; nanosleep(&waittime, NULL); } /* Do not use SA_OK here in case it is ever changed to something * besides zero, The runtime stuff depends on zero being returned here * in order for the shared library to be completely initialized. */ return 0; } /** * _fini * * Returns: always returns 0 **/ int _fini(void) { data_access_lock(); oh_close_handlers(); data_access_unlock(); return 0; }
/** * oh_init * * Returns: 0 on success otherwise an error code **/ int oh_init(void) { static int initialized = 0; struct oh_parsed_config config = { NULL, NULL, 0, 0, 0, 0, FALSE }; struct oh_global_param config_param = { .type = OPENHPI_CONF }; oh_entitypath_pattern epp; SaErrorT rval; data_access_lock(); if (initialized) { /* Don't initialize more than once */ data_access_unlock(); return 0; } /* Initialize thread engine */ oh_threaded_init(); /* Set openhpi configuration file location */ oh_get_global_param(&config_param); rval = oh_load_config(config_param.u.conf, &config); /* Don't error out if there is no conf file */ if (rval < 0 && rval != -4) { dbg("Can not load config."); data_access_unlock(); return SA_ERR_HPI_NOT_PRESENT; } /* Initialize uid_utils */ rval = oh_uid_initialize(); if( (rval != SA_OK) && (rval != SA_ERR_HPI_ERROR) ) { dbg("Unique ID intialization failed."); data_access_unlock(); return rval; } trace("Initialized UID."); /* Initialize handler table */ oh_handlers.table = g_hash_table_new(g_int_hash, g_int_equal); trace("Initialized handler table"); /* Initialize domain table */ oh_domains.table = g_hash_table_new(g_int_hash, g_int_equal); trace("Initialized domain table"); /* Initialize session table */ oh_sessions.table = g_hash_table_new(g_int_hash, g_int_equal); trace("Initialized session table"); /* Load plugins, create handlers and domains */ oh_process_config(&config); /* Create default domain if it does not exist yet. */ if (!config.default_domain) { if (oh_compile_entitypath_pattern("*", &epp)) { data_access_unlock(); dbg("Could not compile entitypath pattern."); return SA_ERR_HPI_ERROR; } if (oh_create_domain(OH_DEFAULT_DOMAIN_ID, &epp, "DEFAULT", SAHPI_UNSPECIFIED_DOMAIN_ID, SAHPI_UNSPECIFIED_DOMAIN_ID, SAHPI_DOMAIN_CAP_AUTOINSERT_READ_ONLY, SAHPI_TIMEOUT_IMMEDIATE)) { data_access_unlock(); dbg("Could not create first domain!"); return SA_ERR_HPI_ERROR; } trace("Created DEFAULT domain"); } /* * Wipes away configuration lists (plugin_names and handler_configs). * global_params is not touched. */ oh_clean_config(&config); /* * If any handlers were defined in the config file AND * all of them failed to load, Then return with an error. */ if (config.handlers_defined > 0 && config.handlers_loaded == 0) { dbg("Warning: Handlers were defined, but none loaded."); } else if (config.handlers_defined > 0 && config.handlers_loaded < config.handlers_defined) { dbg("*Warning*: Not all handlers defined loaded." " Check previous messages."); } if (config.domains_defined != config.domains_loaded) { dbg("*Warning*: Not all domains defined where created." " Check previous messages."); } /* this only does something if the config says to */ oh_threaded_start(); trace("Set init state"); initialized = 1; data_access_unlock(); /* infrastructure initialization has completed at this point */ /* Check if there are any handlers loaded */ if (config.handlers_defined == 0) { dbg("*Warning*: No handler definitions found in config file." " Check configuration file %s and previous messages", config_param.u.conf); } /* * HACK: wait a second before returning * to give the threads time to populate the RPT */ struct timespec waittime = { .tv_sec = 1, .tv_nsec = 1000L}; nanosleep(&waittime, NULL); /* Do not use SA_OK here in case it is ever changed to something * besides zero, The runtime stuff depends on zero being returned here * in order for the shared library to be completely initialized. */ return 0; } /** * oh_finit * * Returns: always returns 0 **/ int oh_finit(void) { data_access_lock(); oh_close_handlers(); data_access_unlock(); return 0; }