version 1.190, 2006/10/03 18:16:04
|
version 1.190.2.8, 2006/10/27 12:22:47
|
|
|
#include <Pegasus/Client/CIMClient.h> | #include <Pegasus/Client/CIMClient.h> |
#endif | #endif |
| |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
#include "SLPAttrib.h" |
|
#endif |
|
|
#include "CIMServer.h" | #include "CIMServer.h" |
#include "CIMOperationRequestDispatcher.h" | #include "CIMOperationRequestDispatcher.h" |
#include "CIMOperationResponseEncoder.h" | #include "CIMOperationResponseEncoder.h" |
|
|
#include <Pegasus/ControlProviders/InteropProvider/InteropProvider.h> | #include <Pegasus/ControlProviders/InteropProvider/InteropProvider.h> |
#endif | #endif |
| |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
#include <slp/slp_client/src/cmd-utils/slp_client/lslp-linux.h> |
|
#include <slp/slp_client/src/cmd-utils/slp_client/lslp.h> |
|
#include <slp/slp_client/src/cmd-utils/slp_client/lslp-common-defs.h> |
|
#include <slp/slp_client/src/cmd-utils/slp_client/slp_client.h> |
|
#endif |
|
|
// l10n | // l10n |
#include <Pegasus/Common/MessageLoader.h> | #include <Pegasus/Common/MessageLoader.h> |
| |
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
ThreadReturnType PEGASUS_THREAD_CDECL _advertisePegasus(void *parm); |
|
//Definig maximum life of registration as the reregistration interval |
|
# define MAX_LIFE PEGASUS_SLP_REG_TIMEOUT * 60 |
|
# define SLP_PORT 427 |
|
# define LOCALHOST_IP "127.0.0.1" |
|
#endif |
| |
static CIMServer *_cimserver = NULL; | static CIMServer *_cimserver = NULL; |
| |
|
|
| |
#ifdef PEGASUS_ENABLE_SLP | #ifdef PEGASUS_ENABLE_SLP |
_runSLP = true; // Boolean cannot be set in definition. | _runSLP = true; // Boolean cannot be set in definition. |
|
|
#endif | #endif |
| |
#if (defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX)) \ | #if (defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX)) \ |
|
|
void CIMServer::runForever() | void CIMServer::runForever() |
{ | { |
// Note: Trace code in this method will be invoked frequently. | // Note: Trace code in this method will be invoked frequently. |
|
|
if(!_dieNow) | if(!_dieNow) |
{ | { |
|
struct timeval now; |
|
Time::gettimeofday(&now); |
#ifdef PEGASUS_ENABLE_SLP | #ifdef PEGASUS_ENABLE_SLP |
// Note - this func prevents multiple starting of slp provider |
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
static struct timeval lastReregistrationTime = {0,0}; |
|
// units of PEGASUS_SLP_REG_TIMEOUT is minutes. Multiplying PEGASUS_SLP_REG_TIMEOUT |
|
// to convert in to seconds. |
|
if (now.tv_sec - lastReregistrationTime.tv_sec > (PEGASUS_SLP_REG_TIMEOUT * 60)) |
|
{ |
|
lastReregistrationTime.tv_sec = now.tv_sec; |
|
#endif |
startSLPProvider(); | startSLPProvider(); |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
} |
|
#endif |
#endif | #endif |
|
|
_monitor->run(500000); | _monitor->run(500000); |
| |
static struct timeval lastIdleCleanupTime = {0, 0}; | static struct timeval lastIdleCleanupTime = {0, 0}; |
struct timeval now; |
|
|
|
Time::gettimeofday(&now); |
|
| |
if (now.tv_sec - lastIdleCleanupTime.tv_sec > 300) |
if (now.tv_sec - lastIdleCleanupTime.tv_sec >= 300) |
{ | { |
lastIdleCleanupTime.tv_sec = now.tv_sec; | lastIdleCleanupTime.tv_sec = now.tv_sec; |
|
|
try | try |
{ | { |
_providerManager->unloadIdleProviders(); | _providerManager->unloadIdleProviders(); |
|
|
{ | { |
} | } |
} | } |
|
|
if (handleShutdownSignal) | if (handleShutdownSignal) |
{ | { |
Tracer::trace(TRC_SERVER, Tracer::LEVEL3, | Tracer::trace(TRC_SERVER, Tracer::LEVEL3, |
|
|
void CIMServer::shutdown() | void CIMServer::shutdown() |
{ | { |
PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::shutdown()"); | PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::shutdown()"); |
|
|
#ifdef PEGASUS_DEBUG | #ifdef PEGASUS_DEBUG |
_repository->DisplayCacheStatistics(); | _repository->DisplayCacheStatistics(); |
#endif | #endif |
|
|
{ | { |
| |
PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "CIMServer::startSLPProvider"); | PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "CIMServer::startSLPProvider"); |
|
#ifndef PEGASUS_SLP_REG_TIMEOUT |
|
|
// This is a onetime function. If already issued, or config is not to use simply | // This is a onetime function. If already issued, or config is not to use simply |
// return | // return |
if (!_runSLP) | if (!_runSLP) |
{ | { |
return; | return; |
} | } |
|
#endif |
// Get Config parameter to determine if we should start SLP. | // Get Config parameter to determine if we should start SLP. |
ConfigManager* configManager = ConfigManager::getInstance(); | ConfigManager* configManager = ConfigManager::getInstance(); |
_runSLP = ConfigManager::parseBooleanValue( | _runSLP = ConfigManager::parseBooleanValue( |
|
|
{ | { |
return; | return; |
} | } |
|
#ifndef PEGASUS_SLP_REG_TIMEOUT |
//SLP startup is onetime function; reset the switch so this | //SLP startup is onetime function; reset the switch so this |
// function does not get called a second time. | // function does not get called a second time. |
_runSLP = false; | _runSLP = false; |
|
#endif |
|
// Start SLPProvider for Built-in SA and Open SLP SA. If the |
|
// PEGASUS_SLP_REG_TIMEOUT is defined and if Open SLP is not used, start a |
|
// thread which advertises CIMOM with a external SLP SA( i.e . IBM SA). |
|
#if defined( PEGASUS_SLP_REG_TIMEOUT ) && !defined( PEGASUS_USE_OPENSLP ) |
|
Thread SLPThread(_advertisePegasus,0,true); |
|
SLPThread.run(); |
|
#else |
// Create a separate thread, detach and call function to execute the startup. | // Create a separate thread, detach and call function to execute the startup. |
|
printf("%s %d\n", __FUNCTION__, __LINE__); |
Thread t( _callSLPProvider, 0, true ); | Thread t( _callSLPProvider, 0, true ); |
t.run(); | t.run(); |
|
#endif |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return; | return; |
} | } |
| |
| |
|
|
// startSLPProvider is a function to get the slp provider kicked off | // startSLPProvider is a function to get the slp provider kicked off |
// during startup. It is placed in the provider manager simply because | // during startup. It is placed in the provider manager simply because |
// the provider manager is the only component of the system is | // the provider manager is the only component of the system is |
|
|
// open connection to CIMOM | // open connection to CIMOM |
// | // |
String hostStr = System::getHostName(); | String hostStr = System::getHostName(); |
|
|
try | try |
{ | { |
// | // |
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return( (ThreadReturnType)32 ); | return( (ThreadReturnType)32 ); |
} | } |
#endif |
|
| |
PEGASUS_NAMESPACE_END |
// This thread advertises pegasus to a listening SA. The attributes for |
|
// the Pegasus advertisement is obtained from CIM classes with the help |
|
// of SLPAttrib class methods. |
|
ThreadReturnType PEGASUS_THREAD_CDECL _advertisePegasus(void* parm) |
|
{ |
|
|
|
PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::_advertisePegasus()"); |
|
SLPAttrib SLPHttpAttribObj; |
|
SLPAttrib SLPHttpsAttribObj; |
|
struct slp_client *client; |
|
time_t now,last; |
|
lslpMsg msg_list; |
|
char *scopes; |
|
Uint16 life = MAX_LIFE, port=SLP_PORT; |
|
char *addr = strdup(LOCALHOST_IP); |
|
char *type = (char *)NULL;; |
|
char *iface = NULL; |
|
char *httpUrl = (char *)NULL;; |
|
char *httpsUrl = (char *)NULL;; |
|
char *httpAttrs = (char *)NULL; |
|
char *httpsAttrs = (char *)NULL; |
|
|
|
// Comes here only if the cimserver is not terminated. |
|
// Get all the SLP attributes and data for the Pegasus cimserver. |
|
SLPHttpAttribObj.fillData("http"); |
|
SLPHttpsAttribObj.fillData("https"); |
|
SLPHttpAttribObj.formAttributes(); |
|
SLPHttpsAttribObj.formAttributes(); |
|
|
|
scopes = strdup("DEFAULT"); |
|
|
|
//Populate datastructures required for registering a service with External SLP SA (i.e IBM SLP SA) |
|
type = strdup(SLPHttpAttribObj.getServiceType().getCString()); |
|
httpUrl = strdup(SLPHttpAttribObj.getServiceUrl().getCString()); |
|
httpsUrl = strdup(SLPHttpsAttribObj.getServiceUrl().getCString()); |
|
httpAttrs = strdup(SLPHttpAttribObj.getAttributes().getCString()); |
|
httpsAttrs = strdup(SLPHttpsAttribObj.getAttributes().getCString()); |
|
if(NULL != (client = create_slp_client(addr, |
|
iface, |
|
SLP_PORT, |
|
"DSA", |
|
scopes, |
|
FALSE, |
|
FALSE))) |
|
{ |
|
int rc_http = client->srv_reg_local(client, httpUrl, httpAttrs, type, scopes, life); |
|
int rc_https = client->srv_reg_local(client, httpsUrl, httpsAttrs, type, scopes, life); |
|
if (!rc_http) |
|
{ |
|
PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2, |
|
"CIMServer http registration is FAILED with External SLP"); |
|
} |
|
if (!rc_https) |
|
{ |
|
PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2, |
|
"CIMServer https registration is FAILED with External SLP"); |
|
} |
|
destroy_slp_client(client); |
|
} |
| |
|
if(type != NULL) |
|
free(type); |
|
if(httpUrl != NULL) |
|
free(httpUrl); |
|
if(httpsUrl != NULL) |
|
free(httpsUrl); |
|
if(httpAttrs != NULL) |
|
free(httpAttrs); |
|
if(httpsAttrs != NULL) |
|
free(httpsAttrs); |
|
if(addr != NULL) |
|
free(addr); |
|
if(scopes != NULL) |
|
free(scopes); |
|
if(iface != NULL) |
|
free(iface); |
| |
|
PEG_METHOD_EXIT(); |
|
return( (ThreadReturnType)32 ); |
|
} |
|
|
|
// This routine deregisters the CIM Server registration with external SLP SA. |
|
|
|
void deregPegasus() |
|
{ |
|
|
|
PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::deregPegasus()"); |
| |
|
SLPAttrib SLPHttpAttribObj1; |
|
SLPAttrib SLPHttpsAttribObj1; |
|
struct slp_client *client; |
|
time_t now,last; |
|
lslpMsg msg_list; |
|
char *scopes; |
|
Uint16 life = MAX_LIFE, port=SLP_PORT; |
|
char *addr = strdup(LOCALHOST_IP); |
|
char *type = (char *)NULL;; |
|
char *iface = NULL; |
|
char *httpUrl = (char *)NULL;; |
|
char *httpsUrl = (char *)NULL;; |
|
char *httpAttrs = (char *)NULL; |
|
char *httpsAttrs = (char *)NULL; |
|
|
|
|
|
// Get all the SLP attributes and data for the Pegasus cimserver. |
|
SLPHttpAttribObj1.fillData("http"); |
|
SLPHttpsAttribObj1.fillData("https"); |
|
SLPHttpAttribObj1.formAttributes(); |
|
SLPHttpsAttribObj1.formAttributes(); |
|
|
|
scopes = strdup("DEFAULT"); |
|
|
|
type = strdup(SLPHttpAttribObj1.getServiceType().getCString()); |
|
httpUrl = strdup(SLPHttpAttribObj1.getServiceUrl().getCString()); |
|
httpsUrl = strdup(SLPHttpsAttribObj1.getServiceUrl().getCString()); |
|
httpAttrs = strdup(SLPHttpAttribObj1.getAttributes().getCString()); |
|
httpsAttrs = strdup(SLPHttpsAttribObj1.getAttributes().getCString()); |
|
if(NULL != (client = create_slp_client(addr, |
|
iface, |
|
SLP_PORT, |
|
"DSA", |
|
scopes, |
|
FALSE, |
|
FALSE))) |
|
{ |
|
client->srv_reg_local(client, httpUrl, httpAttrs, type, scopes, 0); |
|
client->srv_reg_local(client, httpsUrl, httpsAttrs, type, scopes,0); |
|
destroy_slp_client(client); |
|
} |
|
if(type != NULL) |
|
free(type); |
|
if(httpUrl != NULL) |
|
free(httpUrl); |
|
if(httpsUrl != NULL) |
|
free(httpsUrl); |
|
if(httpAttrs != NULL) |
|
free(httpAttrs); |
|
if(httpsAttrs != NULL) |
|
free(httpsAttrs); |
|
if(addr != NULL) |
|
free(addr); |
|
if(scopes != NULL) |
|
free(scopes); |
|
if(iface != NULL) |
|
free(iface); |
|
|
|
PEG_METHOD_EXIT(); |
|
return; |
|
} |
|
#endif |
|
PEGASUS_NAMESPACE_END |