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

📄 provideragent.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                          "UNINITIALIZED_SECURITY_SETUP.PEGASUS_OS_ZOS",                          "Security environment could not be initialised. "                          "Assume security fraud. Stopping Provider Agent.");            exit(1);        }#endif        // provider agent is initialised and ready to go        _isInitialised = true;    }    else if (request->getType() == CIM_NOTIFY_CONFIG_CHANGE_REQUEST_MESSAGE)    {        // Process the request in this thread        AutoPtr<CIMNotifyConfigChangeRequestMessage> notifyRequest(            dynamic_cast<CIMNotifyConfigChangeRequestMessage*>(request));        PEGASUS_ASSERT(notifyRequest.get() != 0);        //        // Update the ConfigManager with the new property value        //        ConfigManager* configManager = ConfigManager::getInstance();        CIMException responseException;        try        {            if (notifyRequest->currentValueModified)            {                configManager->updateCurrentValue(                    notifyRequest->propertyName,                    notifyRequest->newPropertyValue,                    false);            }            else            {                configManager->updatePlannedValue(                    notifyRequest->propertyName,                    notifyRequest->newPropertyValue,                    true);            }        }        catch (Exception& e)        {            responseException = PEGASUS_CIM_EXCEPTION(                CIM_ERR_FAILED, e.getMessage());        }        AutoPtr<CIMResponseMessage> response(notifyRequest->buildResponse());        response->cimException = responseException;        // Return response to CIM Server        _writeResponse(response.get());    }    else if ((request->getType() == CIM_DISABLE_MODULE_REQUEST_MESSAGE) ||             (request->getType() == CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE))    {        // Process the request in this thread        AutoPtr<Message> response(_processRequest(request));        _writeResponse(response.get());        CIMResponseMessage * respMsg =            dynamic_cast<CIMResponseMessage*>(response.get());        // If StopAllProviders, terminate the agent process.        // If DisableModule not successful, leave agent process running.        if ((request->getType() == CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE) ||            ((request->getType() == CIM_DISABLE_MODULE_REQUEST_MESSAGE) &&             (!dynamic_cast<CIMDisableModuleRequestMessage*>(request)->                  disableProviderOnly) &&             (respMsg->cimException.getCode() == CIM_ERR_SUCCESS)))        {            // Operation is successful. End the agent process.            _terminating = true;        }        delete request;    }    else if (request->getType () ==              CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE)    {        _subscriptionInitComplete = true;        //        // Process the request in this thread        //        AutoPtr <Message> response (_processRequest (request));        _writeResponse (response.get ());        //        //  Note: the response does not contain interesting data        //        delete request;    }    else    {        // Start a new thread to process the request        ProviderAgentRequest* agentRequest =            new ProviderAgentRequest(this, request);        ThreadStatus rtn = PEGASUS_THREAD_OK;        while ((rtn = _threadPool.allocate_and_awaken(agentRequest,                   ProviderAgent::_processRequestAndWriteResponse)) !=               PEGASUS_THREAD_OK)        {            if (rtn == PEGASUS_THREAD_INSUFFICIENT_RESOURCES)            {                Threads::yield();            }            else            {                Logger::put(                    Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,                    "Not enough threads to process agent request.");                 Tracer::trace(TRC_PROVIDERAGENT, Tracer::LEVEL2,                    "Could not allocate thread to process agent request.");                AutoPtr<CIMResponseMessage> response(request->buildResponse());                response->cimException = PEGASUS_CIM_EXCEPTION_L(                    CIM_ERR_FAILED,                    MessageLoaderParms(                        "ProviderManager.ProviderAgent.ProviderAgent."                            "THREAD_ALLOCATION_FAILED",                        "Failed to allocate a thread in cimprovagt \"$0\".",                        _agentId));                // Return response to CIM Server                _writeResponse(response.get());                delete agentRequest;                delete request;                break;            }        }     }    PEG_METHOD_EXIT();    return true;}Message* ProviderAgent::_processRequest(CIMRequestMessage* request){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT, "ProviderAgent::_processRequest");    Message* response = 0;    try    {        // Forward the request to the ProviderManager        response = _providerManagerRouter.processMessage(request);    }    catch (Exception& e)    {        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,            String("Caught exception while processing request: ") +                e.getMessage());        CIMResponseMessage* cimResponse = request->buildResponse();        cimResponse->cimException = PEGASUS_CIM_EXCEPTION(            CIM_ERR_FAILED, e.getMessage());        response = cimResponse;    }    catch (...)    {        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,            "Caught exception while processing request.");        CIMResponseMessage* cimResponse = request->buildResponse();        cimResponse->cimException = PEGASUS_CIM_EXCEPTION(            CIM_ERR_FAILED, String::EMPTY);        response = cimResponse;    }    PEG_METHOD_EXIT();    return response;}void ProviderAgent::_writeResponse(Message* message){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT, "ProviderAgent::_writeResponse");    CIMMessage* response = dynamic_cast<CIMMessage*>(message);    PEGASUS_ASSERT(response != 0);    //    // Write the response message to the pipe    //    try    {        // Use Mutex to prevent concurrent writes to the same pipe        AutoMutex pipeLock(_pipeToServerMutex);        AnonymousPipe::Status writeStatus =            _pipeToServer->writeMessage(response);        if (writeStatus != AnonymousPipe::STATUS_SUCCESS)        {            PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,                "Error writing response to pipe.");            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;        }    }    catch (...)    {        PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,            "Caught exception while writing response.");        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();}ThreadReturnType PEGASUS_THREAD_CDECLProviderAgent::_processRequestAndWriteResponse(void* arg){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,        "ProviderAgent::_processRequestAndWriteResponse");    AutoPtr<ProviderAgentRequest> agentRequest(        reinterpret_cast<ProviderAgentRequest*>(arg));    PEGASUS_ASSERT(agentRequest.get() != 0);    try    {        // Get the ProviderAgent and request message from the argument        ProviderAgent* agent = agentRequest->agent;        AutoPtr<CIMRequestMessage> request(agentRequest->request);        // Process the request        AutoPtr<Message> response(agent->_processRequest(request.get()));        // Write the response        agent->_writeResponse(response.get());    }    catch (const Exception& e)    {        PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,            "Caught exception: \"" + e.getMessage() +                "\".  Exiting _processRequestAndWriteResponse.");    }    catch (...)    {        PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,            "Caught unrecognized exception.  "                "Exiting _processRequestAndWriteResponse.");    }    PEG_METHOD_EXIT();    return(ThreadReturnType(0));}void ProviderAgent::_indicationCallback(    CIMProcessIndicationRequestMessage* message){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT, "ProviderAgent::_indicationCallback");    // Send request back to the server to process    _providerAgent->_writeResponse(message);    delete message;    PEG_METHOD_EXIT();}void ProviderAgent::_responseChunkCallback(    CIMRequestMessage* request, CIMResponseMessage* response){    PEG_METHOD_ENTER(        TRC_PROVIDERAGENT, "ProviderAgent::_responseChunkCallback");    // Send request back to the server to process    _providerAgent->_writeResponse(response);    delete response;    PEG_METHOD_EXIT();}void ProviderAgent::_unloadIdleProviders(){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT, "ProviderAgent::_unloadIdleProviders");    ThreadStatus rtn = PEGASUS_THREAD_OK;    // Ensure that only one _unloadIdleProvidersHandler thread runs at a time    _unloadIdleProvidersBusy++;    if ((_unloadIdleProvidersBusy.get() == 1) &&        ((rtn =_threadPool.allocate_and_awaken(             (void*)this, ProviderAgent::_unloadIdleProvidersHandler))==PEGASUS_THREAD_OK))    {        // _unloadIdleProvidersBusy is decremented in        // _unloadIdleProvidersHandler    }    else    {        // If we fail to allocate a thread, don't retry now.        _unloadIdleProvidersBusy--;    }    if (rtn != PEGASUS_THREAD_OK)     {         Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,             "Not enough threads to unload idle providers.");          Tracer::trace(TRC_PROVIDERAGENT, Tracer::LEVEL2,             "Could not allocate thread to unload idle providers.");    }    PEG_METHOD_EXIT();}ThreadReturnType PEGASUS_THREAD_CDECLProviderAgent::_unloadIdleProvidersHandler(void* arg) throw(){    try    {        PEG_METHOD_ENTER(TRC_PROVIDERAGENT,            "ProviderAgent::unloadIdleProvidersHandler");        ProviderAgent* myself = reinterpret_cast<ProviderAgent*>(arg);        try        {            myself->_providerManagerRouter.unloadIdleProviders();        }        catch (...)        {            // Ignore errors            PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,                "Unexpected exception in _unloadIdleProvidersHandler");        }        myself->_unloadIdleProvidersBusy--;    }    catch (...)    {        // Ignore errors        try        {            PEG_TRACE_STRING(TRC_PROVIDERAGENT, Tracer::LEVEL2,                "Unexpected exception in _unloadIdleProvidersHandler");        }        catch (...)        {        }    }    // PEG_METHOD_EXIT();    // Note: This statement could throw an exception    return(ThreadReturnType(0));}void ProviderAgent::_terminateSignalHandler(    int s_n, PEGASUS_SIGINFO_T* s_info, void* sig){    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,        "ProviderAgent::_terminateSignalHandler");    if (_providerAgent != 0)    {        _providerAgent->_terminating = true;    }    PEG_METHOD_EXIT();}PEGASUS_NAMESPACE_END

⌨️ 快捷键说明

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