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

📄 provideragent.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Signal.h>#include <Pegasus/Common/Array.h>#include <Pegasus/Common/AutoPtr.h>#include <Pegasus/Common/CIMMessageSerializer.h>#include <Pegasus/Common/CIMMessageDeserializer.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Config/ConfigManager.h>#include <Pegasus/ProviderManager2/Default/DefaultProviderManager.h>#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && defined(PEGASUS_ZOS_SECURITY)// This include file will not be provided in the OpenGroup CVS for now.// Do NOT try to include it in your compile#include <Pegasus/Common/safCheckzOS_inline.h>#endif#include "ProviderAgent.h"PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN///////////////////////////////////////////////////////////////////////////////// ProviderAgentRequest////////////////////////////////////////////////////////////////////////////////**    This class encapsulates the data required by a work thread to process a    request in a Provider Agent. */class ProviderAgentRequest{public:    ProviderAgentRequest(ProviderAgent* agent_, CIMRequestMessage* request_)    {        agent = agent_;        request = request_;    }    ProviderAgent* agent;    CIMRequestMessage* request;};///////////////////////////////////////////////////////////////////////////////// ProviderAgent///////////////////////////////////////////////////////////////////////////////// Time values used in ThreadPool constructionstatic struct timeval deallocateWait = {300, 0};ProviderAgent* ProviderAgent::_providerAgent = 0;ProviderAgent::ProviderAgent(    const String& agentId,    AnonymousPipe* pipeFromServer,    AnonymousPipe* pipeToServer)  : _providerManagerRouter(_indicationCallback, _responseChunkCallback,	DefaultProviderManager::createDefaultProviderManagerCallback),    _threadPool(0, "ProviderAgent", 0, 0, deallocateWait){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT, "ProviderAgent::ProviderAgent");    // Add the DefaultProviderManager to the router.    _terminating = false;    _agentId = agentId;    _pipeFromServer = pipeFromServer;    _pipeToServer = pipeToServer;    _providerAgent = this;    _subscriptionInitComplete = false;    _isInitialised = false;    PEG_METHOD_EXIT();}ProviderAgent::~ProviderAgent(){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT, "ProviderAgent::~ProviderAgent");    _providerAgent = 0;    PEG_METHOD_EXIT();}void ProviderAgent::run(){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT, "ProviderAgent::run");    // Enable the signal handler to terminate gracefully on SIGHUP and SIGTERM    getSigHandle()->registerHandler(PEGASUS_SIGHUP, _terminateSignalHandler);    getSigHandle()->activate(PEGASUS_SIGHUP);    getSigHandle()->registerHandler(PEGASUS_SIGTERM, _terminateSignalHandler);    getSigHandle()->activate(PEGASUS_SIGTERM);    while (!_terminating)    {        Boolean active = true;        try        {            //            // Read and process the next request            //            active = _readAndProcessRequest();        }        catch (Exception& e)        {            PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,                String("Unexpected exception from _readAndProcessRequest(): ") +                    e.getMessage());            _terminating = true;        }        catch (...)        {            PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,                "Unexpected exception from _readAndProcessRequest().");            _terminating = true;        }        if (_terminating)        {            //            // Stop all providers            //            CIMStopAllProvidersRequestMessage stopRequest("0", QueueIdStack(0));            AutoPtr<Message> stopResponse(_processRequest(&stopRequest));        }        else if (!active)        {            //            // Stop agent process when no more providers are loaded            //            try            {                if (!_providerManagerRouter.hasActiveProviders())                {                    PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,                        "No active providers.  Exiting.");                    _terminating = true;                }                else                {                    _threadPool.cleanupIdleThreads();                }            }            catch (...)            {                // Do not terminate the agent on this exception                PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,                    "Unexpected exception from hasActiveProviders()");            }        }    }    // Notify the cimserver that the provider agent is exiting cleanly.    Uint32 messageLength = 0;    _pipeToServer->writeBuffer((const char*)&messageLength, sizeof(Uint32));    PEG_METHOD_EXIT();}Boolean ProviderAgent::_readAndProcessRequest(){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,        "ProviderAgent::_readAndProcessRequest");    CIMRequestMessage* request;    //    // Read the request from CIM Server    //    CIMMessage* cimMessage;    AnonymousPipe::Status readStatus = _pipeFromServer->readMessage(cimMessage);    request = dynamic_cast<CIMRequestMessage*>(cimMessage);    // Read operation was interrupted    if (readStatus == AnonymousPipe::STATUS_INTERRUPT)    {        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,            "Read operation was interrupted.");        PEG_METHOD_EXIT();        return false;    }    if (readStatus == AnonymousPipe::STATUS_CLOSED)    {        // The CIM Server connection is closed        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,            "CIMServer connection closed. Exiting.");        _terminating = true;        PEG_METHOD_EXIT();        return false;    }    if (readStatus == AnonymousPipe::STATUS_ERROR)    {        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,            "Error reading from pipe. Exiting.");        Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,            "ProviderManager.ProviderAgent.ProviderAgent."                "CIMSERVER_COMMUNICATION_FAILED",            "cimprovagt \"$0\" communication with CIM Server failed.  Exiting.",            _agentId);        _terminating = true;        PEG_METHOD_EXIT();        return false;    }    // A "wake up" message means we should unload idle providers    if (request == 0)    {        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL4,            "Got a wake up message.");        try        {            _unloadIdleProviders();        }        catch (...)        {            // Ignore exceptions from idle provider unloading            PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,                "Ignoring exception from _unloadIdleProviders()");        }        PEG_METHOD_EXIT();        return false;    }    PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL3,        String("Received request from server with messageId ") +            request->messageId);    // Get the ProviderIdContainer to complete the provider module instance    // optimization.  If the provider module instance is blank (optimized    // out), fill it in from our cache.  If it is not blank, update our    // cache.  (See the _providerModuleCache member description.)    try    {        ProviderIdContainer pidc = request->operationContext.get(            ProviderIdContainer::NAME);        if (pidc.getModule().isUninitialized())        {            // Provider module is optimized out.  Fill it in from the cache.            request->operationContext.set(ProviderIdContainer(                _providerModuleCache, pidc.getProvider(),                pidc.isRemoteNameSpace(), pidc.getRemoteInfo()));        }        else        {            // Update the cache with the new provider module instance.            _providerModuleCache = pidc.getModule();        }    }    catch (...)    {        // No ProviderIdContainer to optimize    }    //    // It never should be possible to receive a request other than "initialise"    // before the provider agent is in state isInitialised    //    // Bail out.    //    if (!_isInitialised &&        (request->getType() != CIM_INITIALIZE_PROVIDER_AGENT_REQUEST_MESSAGE))    {        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,            "Provider Agent was not yet initialised,"            " prior to receiving a request message.");        Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,            "ProviderManager.ProviderAgent.ProviderAgent."            "PROVIDERAGENT_NOT_INITIALIZED",            "cimprovagt \"$0\" was not yet initialised"            " prior to receiving a request message. Exiting.",            _agentId);        _terminating = true;        PEG_METHOD_EXIT();        return false;    }    //    // Check for messages to be handled by the Agent itself.    //    if (request->getType() == CIM_INITIALIZE_PROVIDER_AGENT_REQUEST_MESSAGE)    {        // Process the request in this thread        AutoPtr<CIMInitializeProviderAgentRequestMessage> ipaRequest(            dynamic_cast<CIMInitializeProviderAgentRequestMessage*>(request));        PEGASUS_ASSERT(ipaRequest.get() != 0);        ConfigManager* configManager = ConfigManager::getInstance();        configManager->setPegasusHome(ipaRequest->pegasusHome);        // Initialize the configuration properties        for (Uint32 i = 0; i < ipaRequest->configProperties.size(); i++)        {            configManager->initCurrentValue(                ipaRequest->configProperties[i].first,                ipaRequest->configProperties[i].second);        }        // Set the default resource bundle directory for the MessageLoader        MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(            configManager->getCurrentValue("messageDir")));        // Set the log file directory#if !defined(PEGASUS_USE_SYSLOGS)        Logger::setHomeDirectory(ConfigManager::getHomedPath(            configManager->getCurrentValue("logdir")));#endif        System::bindVerbose = ipaRequest->bindVerbose;        //        //  Set _subscriptionInitComplete from value in         //  InitializeProviderAgent request        //        _subscriptionInitComplete = ipaRequest->subscriptionInitComplete;        _providerManagerRouter.setSubscriptionInitComplete             (_subscriptionInitComplete);        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,            "Processed the agent initialization message.");        // Notify the cimserver that the provider agent is initialized.        Uint32 messageLength = 0;        _pipeToServer->writeBuffer((const char*)&messageLength, sizeof(Uint32));#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && defined(PEGASUS_ZOS_SECURITY)        // prepare and setup the thread-level security environment on z/OS        // if security initialization fails        startupCheckBPXServer(false);        startupCheckMSC();        if (!isZOSSecuritySetup())        {            Logger::put_l(Logger::ERROR_LOG, ZOS_SECURITY_NAME, Logger::FATAL,                          "ProviderManager.ProviderAgent.ProviderAgent."

⌨️ 快捷键说明

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