⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimserver.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    AuditLogger::logCurrentConfig(propertyNames, propertyValues);    // get currently registered provider module instances    Array<CIMInstance> moduleInstances;    moduleInstances =        _cimserver->_providerRegistrationManager->enumerateInstancesForClass(        CIMObjectPath("PG_ProviderModule"));    AuditLogger::logCurrentRegProvider(moduleInstances);    AuditLogger::logCurrentEnvironmentVar();#endif}#ifdef PEGASUS_ENABLE_SLPThreadReturnType PEGASUS_THREAD_CDECL _callSLPProvider(void* parm);// This is a control function that starts a new thread which issues a// cim operation to start the slp provider.//// If PEGASUS_ENABLE_SLP is defined, then startSLPProvider is called for// each iteration of the runForever "loop". The _runSLP variable will be// set from the "slp" configuration variable, and if true, SLP registration// will occur, but only once. After registering, _runSLP is set to false// and remains so for the life of this process.//// If *both* PEGASUS_ENABLE_SLP and PEGASUS_SLP_REG_TIMEOUT are defined,// then the first call to startSLPProvider is for the initial SLP// registration, and each subsequent call is to "reregister" or update our// SLP registration based on the timeout interval. In this case _runSLP// will still be set from the "slp" configuration variable, and tested,// but it will retain this setting for the life of this process.//// Note that the SLP registration needs to be performed from within the// runForever "loop" because it will actually call connectLocal() and// client.invokeMethod() to perform the SLP registration, so the CIM// Server needs to be able to accept connectLocal requestsvoid 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 return    if (!_runSLP)    {        return;    }#endif    // Get Config parameter to determine if we should start SLP.    ConfigManager* configManager = ConfigManager::getInstance();    _runSLP = ConfigManager::parseBooleanValue(         configManager->getCurrentValue("slp"));    // If false, do not start slp provider    if (!_runSLP)    {        return;    }#ifndef PEGASUS_SLP_REG_TIMEOUT    //SLP startup is onetime function; reset the switch so this    // function does not get called a second time.    _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(registerPegasusWithSLP,0,true);     SLPThread.run();#else    // Create a separate thread, detach and call function to execute the    // startup.    Thread t( _callSLPProvider, 0, true );    t.run();#endif    PEG_METHOD_EXIT();    return;}// startSLPProvider is a function to get the slp provider kicked off// during startup.  It is placed in the provider manager simply because// the provider manager is the only component of the system is// driven by a timer after startup.  It should never be here and must be// moved to somewhere more logical or really replaced. We simply needed// something that was run shortly after system startup.// This function is assumed to operate in a separate thread and// KS 15 February 2004.ThreadReturnType PEGASUS_THREAD_CDECL _callSLPProvider(void* parm){    PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::_callSLPProvider()");    //    // Create CIMClient object    //    CIMClient client;    //    // open connection to CIMOM    //    String hostStr = System::getHostName();    try    {        //        client.connectLocal();        //        // set client timeout to 2 seconds        //        client.setTimeout(40000);        // construct CIMObjectPath        //        String referenceStr = "//";        referenceStr.append(hostStr);        referenceStr.append("/");        referenceStr.append(PEGASUS_NAMESPACENAME_INTERNAL.getString());        referenceStr.append(":");        referenceStr.append(PEGASUS_CLASSNAME_WBEMSLPTEMPLATE.getString());        CIMObjectPath reference(referenceStr);        //        // issue the invokeMethod request on the register method        //        Array<CIMParamValue> inParams;        Array<CIMParamValue> outParams;        CIMValue retValue = client.invokeMethod(            PEGASUS_NAMESPACENAME_INTERNAL,            reference,            CIMName("register"),            inParams,            outParams);        _slpRegistrationComplete = true;        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,            "Pegasus.Server.SLP.SLP_REGISTRATION_INITIATED",            "SLP Registration Initiated");    }    catch(Exception& e)    {        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,            "Pegasus.Server.SLP.INTERNAL_SLP_REGISTRATION_FAILED_EXCEPTION",            "CIM Server registration with Internal SLP Failed. Exception: $0",            e.getMessage());    }    catch(...)    {        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,            "Pegasus.Server.SLP.INTERNAL_SLP_REGISTRATION_FAILED_ERROR",            "CIM Server registration with Internal SLP Failed.");    }    client.disconnect();    PEG_METHOD_EXIT();    return( (ThreadReturnType)32 );}#ifdef PEGASUS_SLP_REG_TIMEOUT// 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 registerPegasusWithSLP(void* parm){     PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::registerPegasusWithSLP()");     Boolean foundHttpProtocol=false, foundHttpsProtocol=false;     SLPAttrib SLPHttpAttribObj;     SLPAttrib SLPHttpsAttribObj;     struct slp_client *client;     const char *scopes = "DEFAULT";     Uint16 life = PEGASUS_SLP_REG_TIMEOUT * 60, port=SLP_DEFAULT_PORT;     const char *addr = LOCALHOST_IP;     const char *iface = NULL;     CString type, httpUrl, httpsUrl, httpAttrs, httpsAttrs;     try     {         // Get all the SLP attributes and data for the Pegasus cimserver.         foundHttpProtocol = SLPHttpAttribObj.fillData("http");         foundHttpsProtocol = SLPHttpsAttribObj.fillData("https");         if (!foundHttpProtocol && !foundHttpsProtocol)         {             Logger::put_l(                 Logger::STANDARD_LOG,                  System::CIMSERVER,                  Logger::WARNING,                 "Pegasus.Server.SLP.PROTOCOLS_NOT_ENABLED",                 "Both Http and Https protocols are disabled, "                     "SLP registration skipped.");             PEG_METHOD_EXIT();             return( (ThreadReturnType)32 );         }         // Populate datastructures required for registering a service with SLP         if (foundHttpProtocol)         {             SLPHttpAttribObj.formAttributes();             type = SLPHttpAttribObj.getServiceType().getCString();             httpUrl = SLPHttpAttribObj.getServiceUrl().getCString();             httpAttrs = SLPHttpAttribObj.getAttributes().getCString();         }         if (foundHttpsProtocol)         {             SLPHttpsAttribObj.formAttributes();             if (!foundHttpProtocol)             {                 type = SLPHttpsAttribObj.getServiceType().getCString();             }             httpsUrl = SLPHttpsAttribObj.getServiceUrl().getCString();             httpsAttrs = SLPHttpsAttribObj.getAttributes().getCString();         }         if (NULL != (client = create_slp_client(addr,                                                 iface,                                                 SLP_DEFAULT_PORT,                                                 "DSA",                                                 scopes,                                                 FALSE,                                                 FALSE)))         {             if (foundHttpProtocol &&                 (!client->srv_reg_local(client,                                          (const char*)httpUrl,                                         (const char*)httpAttrs,                                          (const char*)type,                                          scopes,                                          life)))             {                 Logger::put_l(                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,                     "Pegasus.Server.SLP.EXTERNAL_SLP_REGISTRATION_FAILED_ERROR",                     "CIM Server registration with External SLP Failed.");             }             if (foundHttpsProtocol &&                 (!client->srv_reg_local(client,                                          (const char*)httpsUrl,                                         (const char*)httpsAttrs,                                          (const char*)type,                                          scopes,                                          life)))             {                 Logger::put_l(                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,                     "Pegasus.Server.SLP.EXTERNAL_SLP_REGISTRATION_FAILED_ERROR",                     "CIM Server registration with External SLP Failed.");             }         }     }     catch(Exception& e)     {         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,             "Pegasus.Server.SLP.EXTERNAL_SLP_REGISTRATION_FAILED_EXCEPTION",             "CIM Server registration with External SLP Failed. Exception: $0",             e.getMessage());     }     catch(...)     {         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,             "Pegasus.Server.SLP.EXTERNAL_SLP_REGISTRATION_FAILED_ERROR",             "CIM Server registration with External SLP Failed.");     }     destroy_slp_client(client);    PEG_METHOD_EXIT();    return (ThreadReturnType)32;}// This routine deregisters the CIM Server registration with external SLP SA.void PEGASUS_SERVER_LINKAGE unregisterPegasusFromSLP(){    PEG_METHOD_ENTER(TRC_SERVER, "unregisterPegasusFromSLP()");    Boolean foundHttpProtocol=false, foundHttpsProtocol=false;    SLPAttrib SLPHttpAttribObj;    SLPAttrib SLPHttpsAttribObj;    struct slp_client *client;    const char *scopes = "DEFAULT";    Uint16 port=SLP_DEFAULT_PORT;    const char *addr = LOCALHOST_IP;    const char *iface = NULL;    CString type, httpUrl, httpsUrl, httpAttrs, httpsAttrs;    // If Pegasus did not successfully register with SLP, just return    if (!_slpRegistrationComplete)    {        PEG_METHOD_EXIT();        return;    }  // Get all the SLP attributes and data for the Pegasus cimserver.    foundHttpProtocol = SLPHttpAttribObj.fillData("http");    foundHttpsProtocol = SLPHttpsAttribObj.fillData("https");    if (!foundHttpProtocol && !foundHttpsProtocol)    {        PEG_METHOD_EXIT();        return;    }    if (foundHttpProtocol)    {        SLPHttpAttribObj.formAttributes();        type = SLPHttpAttribObj.getServiceType().getCString();        httpUrl = SLPHttpAttribObj.getServiceUrl().getCString();        httpAttrs = SLPHttpAttribObj.getAttributes().getCString();    }    if (foundHttpsProtocol)    {        SLPHttpsAttribObj.formAttributes();        if (!foundHttpProtocol)        {            type = SLPHttpsAttribObj.getServiceType().getCString();        }        httpsUrl = SLPHttpsAttribObj.getServiceUrl().getCString();        httpsAttrs = SLPHttpsAttribObj.getAttributes().getCString();    }    if (NULL != (client = create_slp_client(addr,                                            iface,                                            SLP_DEFAULT_PORT,                                            "DSA",                                            scopes,                                            FALSE,                                            FALSE)))    {        if (foundHttpProtocol)        {            client->srv_reg_local(client, (const char*)httpUrl,                                  (const char*)httpAttrs, (const char*)type, scopes, 0);        }        if (foundHttpsProtocol)        {            client->srv_reg_local(client, (const char*)httpsUrl,                                   (const char*)httpsAttrs, (const char*)type, scopes, 0);        }        destroy_slp_client(client);    }    PEG_METHOD_EXIT();    return; }#endif // PEGASUS_SLP_REG_TIMEOUT#endifPEGASUS_NAMESPACE_END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -