📄 remote_broker.c
字号:
__rb->use_count++; TRACE_INFO(("use count increased to: %d", __rb->use_count )); CMPI_BrokerExt_Ftab->unlockMutex(__rb->lock);}static void __releaseMI ( remote_broker * rb ){ struct __remote_broker * __rb = (struct __remote_broker *) rb; TRACE_NORMAL(("releasing remote broker handle.")); CMPI_BrokerExt_Ftab->lockMutex(__rb->lock); gettimeofday ( &__rb->last_used, NULL ); __rb->use_count--; TRACE_INFO(("use count decreased to: %d", __rb->use_count )); CMPI_BrokerExt_Ftab->unlockMutex(__rb->lock);}static unsigned int __get_use_count ( remote_broker * rb ){ struct __remote_broker * __rb = (struct __remote_broker *) rb; return __rb->use_count;}static void __cleanup_remote_broker ( struct __remote_broker * __rb ){ TRACE_VERBOSE(("entered function.")); TRACE_NORMAL(("Deactivating remote provider."));#ifdef CMPI_VER_100 CMPIBoolean term = 0;#endif if ( __rb->instanceMI != NULL ) { TRACE_INFO(("Calling cleanup() on instanceMI handle.")); __rb->instanceMI->ft->cleanup ( __rb->instanceMI, __remote_brokers_context#ifdef CMPI_VER_100 ,term#endif ); } if ( __rb->associationMI != NULL ) { TRACE_INFO(("Calling cleanup() on associationMI handle.")); __rb->associationMI->ft->cleanup ( __rb->associationMI, __remote_brokers_context#ifdef CMPI_VER_100 ,term#endif ); } if ( __rb->methodMI != NULL ) { TRACE_INFO(("Calling cleanup() on methodMI handle.")); __rb->methodMI->ft->cleanup ( __rb->methodMI, __remote_brokers_context#ifdef CMPI_VER_100 ,term#endif ); } if ( __rb->propertyMI != NULL ) { TRACE_INFO(("Calling cleanup() on propertyMI handle.")); __rb->propertyMI->ft->cleanup ( __rb->propertyMI, __remote_brokers_context #ifdef CMPI_VER_100 ,term#endif ); } if ( __rb->indicationMI != NULL ) { TRACE_INFO(("Calling cleanup() on indicationMI handle.")); __rb->indicationMI->ft->cleanup ( __rb->indicationMI, __remote_brokers_context #ifdef CMPI_VER_100 ,term#endif ); } tool_mm_flush (); TRACE_INFO(("Closing provider module library."));#ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM dlclose ( __rb->library );#else dllfree ( (dllhandle *) __rb->library);#endif __rb->library = NULL; TRACE_INFO(("Freeing allocated memory.")); free ( __rb->comm_layer_id ); free ( __rb->broker_address ); free ( __rb->provider ); free ( __rb->provider_module ); CMPI_BrokerExt_Ftab->destroyMutex(__rb->lock); free ( __rb ); TRACE_VERBOSE(("leaving function."));}static CMPIInstanceMI * __get_instanceMI ( remote_broker * rb ){ struct __remote_broker * __rb = (struct __remote_broker *) rb; TRACE_NORMAL(("Retrieving instanceMI handle.")); if ( __rb->instanceMI == NULL ) { __rb->instanceMI = tool_load_InstanceMI ( __rb->provider, __rb->library, (CMPIBroker *) rb, __remote_brokers_context ); } return __rb->instanceMI;}static CMPIAssociationMI * __get_associationMI ( remote_broker * rb ){ struct __remote_broker * __rb = (struct __remote_broker *) rb; TRACE_NORMAL(("Retrieving associationMI handle.")); if ( __rb->associationMI == NULL ) { __rb->associationMI = tool_load_AssociationMI ( __rb->provider, __rb->library, (CMPIBroker *) rb, __remote_brokers_context ); } return __rb->associationMI;}static CMPIMethodMI * __get_methodMI ( remote_broker * rb ){ struct __remote_broker * __rb = (struct __remote_broker *) rb; TRACE_NORMAL(("Retrieving methodMI handle.")); if ( __rb->methodMI == NULL ) { __rb->methodMI = tool_load_MethodMI ( __rb->provider, __rb->library, (CMPIBroker *) rb, __remote_brokers_context ); } return __rb->methodMI;}static CMPIPropertyMI * __get_propertyMI ( remote_broker * rb ){ struct __remote_broker * __rb = (struct __remote_broker *) rb; TRACE_NORMAL(("Retrieving propertyMI handle.")); if ( __rb->propertyMI == NULL ) { __rb->propertyMI = tool_load_PropertyMI ( __rb->provider, __rb->library, (CMPIBroker *) rb, __remote_brokers_context ); } return __rb->propertyMI;}static CMPIIndicationMI * __get_indicationMI ( remote_broker * rb ){ struct __remote_broker * __rb = (struct __remote_broker *) rb; CMPIIndicationMI * mi; TRACE_NORMAL(("Retrieving indicationMI handle.")); if ( __rb->indicationMI == NULL && ( mi = tool_load_IndicationMI ( __rb->provider, __rb->library, (CMPIBroker *) rb, __remote_brokers_context ) ) != NULL ) { __rb->indicationMI = __track_indicationMI ( mi, (remote_broker *) __rb ); } return __rb->indicationMI;}static struct __remote_broker *__new_remote_broker ( const char * comm_layer_id, const char * broker_address, const char * provider, const char * provider_module, const comm_ticket * ticket, CMPIBrokerFT * brokerFT ){ static struct remote_brokerFT rbFT = { __get_broker_address, __get_provider, __get_ticket, __acquireMI, __releaseMI, __get_use_count, __get_instanceMI, __get_associationMI, __get_methodMI, __get_propertyMI, __get_indicationMI }; struct __remote_broker * __rb; TRACE_VERBOSE(("entered function.")); __rb = (struct __remote_broker *) calloc ( 1, sizeof ( struct __remote_broker ) ); __rb->lock=CMPI_BrokerExt_Ftab->newMutex(0); TRACE_NORMAL(("Setting up new remote broker structure.")); TRACE_INFO(("Storing:\ncomm_layer_id: %s\nbroker_address: %s\n" "provider: %s\nprovider_module: %s", comm_layer_id, broker_address, provider, provider_module)); __rb->rb.ft = &rbFT; __rb->rb.broker.bft = brokerFT; __rb->rb.broker.eft = &native_brokerEncFT; __rb->rb.broker.xft = CMPI_BrokerExt_Ftab; __rb->comm_layer_id = ( comm_layer_id )? strdup ( comm_layer_id ): NULL; __rb->broker_address = ( broker_address )? strdup ( broker_address ): NULL; __rb->provider = ( provider )? strdup ( provider ): NULL; __rb->provider_module = ( provider_module )? strdup ( provider_module ): NULL; __rb->ticket = *ticket; gettimeofday ( &__rb->last_used, NULL ); { char dlName[512]; #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC) strcpy(dlName,provider_module); strcat(dlName,".dll"); #elif defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) strcpy(dlName,"lib"); strcat(dlName,provider_module); strcat(dlName,".so"); #elif defined(PEGASUS_OS_HPUX) #ifdef PEGASUS_PLATFORM_HPUX_PARISC_ACC strcpy(dlName,"lib"); strcat(dlName,provider_module); strcat(dlName,".sl"); #else strcpy(dlName,"lib"); strcat(dlName,provider_module); strcat(dlName,".so"); #endif #elif defined(PEGASUS_OS_OS400) strcpy(dlName,provider_module); #elif defined(PEGASUS_OS_DARWIN) strcpy(dlName,"lib"); strcat(dlName,provider_module); strcat(dlName,".dylib"); #else strcpy(dlName,"lib"); strcat(dlName,provider_module); strcat(dlName,".so"); #endif TRACE_INFO(("loading provider module: %s.", provider_module ));#ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM __rb->library = dlopen ( dlName, RTLD_NOW );#else __rb->library = (void *) dllload ( dlName ); if (__rb->library == 0) TRACE_CRITICAL(("Trying to load library %s failed with %s\n",dlName, strerror(errno)));#endif } TRACE_VERBOSE(("leaving function.")); return __rb;}remote_broker * find_remote_broker ( const char * comm_layer_id, const char * broker_address, const char * provider, const char * provider_module, const comm_ticket * ticket, CMPIBrokerFT * brokerFT ){ struct __remote_broker * __rb; TRACE_VERBOSE(("entered function.")); TRACE_NORMAL(("Looking up remote broker handle.")); TRACE_INFO(("Matching:\n" "comm_layer_id: %s\nbroker_address: %s\n" "provider: %s\nprovider_module: %s", comm_layer_id, broker_address, provider, provider_module)); INIT_LOCK(__remote_brokers_lock); CMPI_BrokerExt_Ftab->lockMutex(__remote_brokers_lock); for ( __rb = __remote_brokers; __rb != NULL; __rb = __rb->next ) { if ( strcmp ( comm_layer_id, __rb->comm_layer_id ) == 0 && strcmp ( broker_address, __rb->broker_address ) == 0 && strcmp ( provider, __rb->provider ) == 0 && strcmp ( provider_module,__rb->provider_module) == 0 && compare_ticket ( ticket, &__rb->ticket ) ) { CMPI_BrokerExt_Ftab->unlockMutex(__remote_brokers_lock); TRACE_INFO(("returning existing handle.")); RBAcquireMI ( (remote_broker *) __rb ); TRACE_VERBOSE(("leaving function.")); return (remote_broker *) __rb; } } __rb = __new_remote_broker ( comm_layer_id, broker_address, provider, provider_module, ticket, brokerFT ); __rb->next = __remote_brokers; __remote_brokers = __rb; CMPI_BrokerExt_Ftab->unlockMutex(__remote_brokers_lock); TRACE_INFO(("returning fresh handle.")); RBAcquireMI ( (remote_broker *) __rb ); TRACE_VERBOSE(("leaving function.")); return (remote_broker *) __rb;}//! Cleans up unused remote brokers in specified time intervals./*! This function iterates through the list of currently maintained remote_broker handles, and deactivates those matching the following criteria: - the associated MI is currently active, i.e. its MI library is loaded - its use_count is zero - the time of its last usage has elapsed a specified timeout interval \param timeout the elapsed time (sec) before providers are being deactivated. \param check_interval the time interval between two checks. \return never. \sa __deactivate_remote_broker() */void cleanup_remote_brokers ( long timeout, time_t check_interval ){ CMPI_COND_TYPE c = NULL; CMPI_MUTEX_TYPE m = NULL; struct timespec wait = {0,0}; struct timeval t; struct __remote_broker ** __rb, * tmp; int rc = 0; TRACE_VERBOSE(("entered function.")); TRACE_NORMAL(("Cleaning up remote providers.")); TRACE_INFO(("timeout interval: %ld (secs)", timeout)); TRACE_INFO(("check interval: %ld (secs)", check_interval)); c=CMPI_BrokerExt_Ftab->newCondition(0); m=CMPI_BrokerExt_Ftab->newMutex(0); do { TRACE_NORMAL(("Looking for remote providers " "to be cleaned up.")); INIT_LOCK(__remote_brokers_lock); CMPI_BrokerExt_Ftab->lockMutex(__remote_brokers_lock); gettimeofday ( &t, NULL ); for ( __rb = &__remote_brokers; *__rb != NULL; ) { if ( (*__rb)->use_count == 0 && t.tv_sec >= (*__rb)->last_used.tv_sec + timeout) { tmp = *__rb; *__rb = tmp->next; __cleanup_remote_broker ( tmp ); } else __rb = &(*__rb)->next; } CMPI_BrokerExt_Ftab->unlockMutex(__remote_brokers_lock); wait.tv_sec = t.tv_sec + check_interval; wait.tv_nsec = 0; CMPI_BrokerExt_Ftab->lockMutex(m); rc = CMPI_BrokerExt_Ftab->timedCondWait( c, m, &wait ); CMPI_BrokerExt_Ftab->unlockMutex(m); } while ( rc ); CMPI_BrokerExt_Ftab->destroyMutex(m); CMPI_BrokerExt_Ftab->destroyCondition(c); TRACE_CRITICAL(("Timed wait failed, leaving function."));}//! Initializes the CMPIContext to be used for activation of remote providers./*! The context given as argument is used to activate and deactivate providers respectively, since both calls expect a CMPIContext as argument. \sa __deactivate_remote_broker() \sa __get_instanceMI() \sa __get_associationMI() \sa __get_methodMI() \sa __get_propertyMI() \sa __get_indicationMI() */void init_activation_context ( CMPIContext * ctx ){ __remote_brokers_context = ctx;}/****************************************************************************//*** Local Variables: ***//*** mode: C ***//*** c-basic-offset: 8 ***//*** End: ***/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -