version 1.190, 2006/10/03 18:16:04
|
version 1.190.2.2, 2006/10/10 09:49:06
|
|
|
#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" |
|
|
// l10n | // l10n |
#include <Pegasus/Common/MessageLoader.h> | #include <Pegasus/Common/MessageLoader.h> |
| |
|
#include <Pegasus/Common/Threads.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
ThreadReturnType PEGASUS_THREAD_CDECL _advertisePegasus(void *parm); |
|
# define MAX_LIFE 0x0fff |
|
# define SLP_PORT 427 |
|
# define LOCALHOST_IP "127.0.0.1" |
|
#endif |
static CIMServer *_cimserver = NULL; | static CIMServer *_cimserver = NULL; |
| |
// Need a static method to act as a callback for the control provider. | // Need a static method to act as a callback for the control provider. |
|
|
// Signal handler for shutdown signals, currently SIGHUP and SIGTERM | // Signal handler for shutdown signals, currently SIGHUP and SIGTERM |
// | // |
Boolean handleShutdownSignal = false; | Boolean handleShutdownSignal = false; |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
// Signal to shutdown the SLP advertising thread |
|
Boolean handleCloseSLPThread = false; |
|
#endif |
void shutdownSignalHandler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig) | void shutdownSignalHandler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig) |
{ | { |
PEG_METHOD_ENTER(TRC_SERVER, "shutdownSignalHandler"); | PEG_METHOD_ENTER(TRC_SERVER, "shutdownSignalHandler"); |
|
|
{ | { |
PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::shutdownSignal()"); | PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::shutdownSignal()"); |
handleShutdownSignal = true; | handleShutdownSignal = true; |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
handleCloseSLPThread = true; |
|
#endif |
_cimserver->tickle_monitor(); | _cimserver->tickle_monitor(); |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
|
|
PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::CIMServer()"); | PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::CIMServer()"); |
_init(); | _init(); |
_cimserver = this; | _cimserver = this; |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
SLPThread = NULL; |
|
#endif |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
| |
|
|
| |
#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)) \ |
|
|
CIMServer::~CIMServer () | CIMServer::~CIMServer () |
{ | { |
PEG_METHOD_ENTER (TRC_SERVER, "CIMServer::~CIMServer()"); | PEG_METHOD_ENTER (TRC_SERVER, "CIMServer::~CIMServer()"); |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
handleCloseSLPThread = true; |
|
#endif |
| |
// Wait until the Shutdown provider request has cleared through the | // Wait until the Shutdown provider request has cleared through the |
// system. | // system. |
|
|
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) |
{ | { |
#ifdef PEGASUS_ENABLE_SLP | #ifdef PEGASUS_ENABLE_SLP |
|
|
| |
static struct timeval lastIdleCleanupTime = {0, 0}; | static struct timeval lastIdleCleanupTime = {0, 0}; |
struct timeval now; | struct timeval now; |
|
|
Time::gettimeofday(&now); | Time::gettimeofday(&now); |
| |
if (now.tv_sec - lastIdleCleanupTime.tv_sec > 300) |
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
static struct timeval lastReregistrationTime = {0, 0}; |
|
const char * reRegTime = getenv("PEG_SLP_REG_TIMEOUT"); |
|
if (now.tv_sec - lastReregistrationTime.tv_sec > (atoi(reRegTime) * 60)) |
{ | { |
lastIdleCleanupTime.tv_sec = now.tv_sec; |
lastReregistrationTime.tv_sec = now.tv_sec; |
|
startSLPProvider(); |
|
} |
|
#endif |
| |
|
if (now.tv_sec - lastIdleCleanupTime.tv_sec >= 100) |
|
{ |
|
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"); |
| |
|
// onetime check is not needed for re-registration. |
|
//if(!reRegister) |
|
{ |
// 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) |
|
|
//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; |
|
} |
|
// Start SLPProvider for Built-in SA and Open SLP SA. if the PEGASUS_SLP_REG_TIMEOUT is defined |
|
// start a thread which advertises CIMOM with a external SLP SA. |
|
#ifdef PEGASUS_SLP_REG_TIMEOUT |
|
_startAdvThread = true; |
|
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. |
Thread t( _callSLPProvider, 0, true ); | Thread t( _callSLPProvider, 0, true ); |
t.run(); | t.run(); |
|
#endif |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return; | return; |
|
|
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()"); |
|
|
|
static SLPAttrib SLPHttpAttribObj; |
|
static 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; |
|
|
|
if (!handleCloseSLPThread) |
|
{ |
|
// 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"); |
|
|
|
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))) |
|
{ |
|
if (!handleCloseSLPThread) |
|
{ |
|
client->srv_reg_local(client, httpUrl, httpAttrs, type, scopes, life); |
|
client->srv_reg_local(client, httpsUrl, httpsAttrs, type, scopes, life); |
|
} |
|
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. |
|
|
|
int _deregPegasus() |
|
{ |
|
|
|
PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::deregPegasus()"); |
| |
|
static SLPAttrib SLPHttpAttribObj1; |
|
static 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( 32 ); |
|
} |
|
#endif |
|
PEGASUS_NAMESPACE_END |