📄 oopprovidermanagerrouter.cpp
字号:
"Failed to write message to pipe. writeStatus = %d.", writeStatus); request->messageId = originalMessageId; if (doProviderModuleOptimization) { request->operationContext.set(*origProviderId.get()); } // Remove this OutstandingRequestTable entry { AutoMutex tableLock(_outstandingRequestTableMutex); Boolean removed = _outstandingRequestTable.remove(uniqueMessageId); PEGASUS_ASSERT(removed); } // A response value of _REQUEST_NOT_PROCESSED indicates // that the request was not processed by the provider // agent, so it can be retried safely. PEG_METHOD_EXIT(); return _REQUEST_NOT_PROCESSED; } if (updateProviderModuleCache) { _providerModuleCache = origProviderId->getModule(); } } catch (...) { request->messageId = originalMessageId; if (doProviderModuleOptimization) { request->operationContext.set(*origProviderId.get()); } Tracer::trace(TRC_PROVIDERMANAGER, Tracer::LEVEL2, "Failed to write message to pipe."); // Remove the OutstandingRequestTable entry for this request { AutoMutex tableLock(_outstandingRequestTableMutex); Boolean removed = _outstandingRequestTable.remove(uniqueMessageId); PEGASUS_ASSERT(removed); } PEG_METHOD_EXIT(); throw; } } // // Wait for the response // try { // Must not hold _agentMutex while waiting for the response waitSemaphore.wait(); } catch (...) { // Remove the OutstandingRequestTable entry for this request { AutoMutex tableLock(_outstandingRequestTableMutex); Boolean removed = _outstandingRequestTable.remove(uniqueMessageId); PEGASUS_ASSERT(removed); } PEG_METHOD_EXIT(); throw; } // A response value of _REQUEST_NOT_PROCESSED indicates that the // provider agent process was terminating when the request was sent. // The request was not processed by the provider agent, so it can be // retried safely. if (response == _REQUEST_NOT_PROCESSED) { PEG_METHOD_EXIT(); return response; } // A null response is returned when an agent connection is closed // while requests remain outstanding. if (response == 0) { response = request->buildResponse(); response->cimException = PEGASUS_CIM_EXCEPTION( CIM_ERR_FAILED, MessageLoaderParms( "ProviderManager.OOPProviderManagerRouter." "CIMPROVAGT_CONNECTION_LOST", "Lost connection with cimprovagt \"$0\".", _moduleName)); } } catch (CIMException& e) { PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2, String("Caught exception: ") + e.getMessage()); response = request->buildResponse(); response->cimException = e; } catch (Exception& e) { PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2, String("Caught exception: ") + e.getMessage()); response = request->buildResponse(); response->cimException = PEGASUS_CIM_EXCEPTION( CIM_ERR_FAILED, e.getMessage()); } catch (...) { PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2, "Caught unknown exception"); response = request->buildResponse(); response->cimException = PEGASUS_CIM_EXCEPTION( CIM_ERR_FAILED, String::EMPTY); } response->messageId = originalMessageId; PEG_METHOD_EXIT(); return response;}void ProviderAgentContainer::unloadIdleProviders(){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "ProviderAgentContainer::unloadIdleProviders"); AutoMutex lock(_agentMutex); if (_isInitialized) { // Send a "wake up" message to the Provider Agent. // Don't bother checking whether the operation is successful. Uint32 messageLength = 0; _pipeToAgent->writeBuffer((const char*)&messageLength, sizeof(Uint32)); } PEG_METHOD_EXIT();}void ProviderAgentContainer::_processResponses(){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "ProviderAgentContainer::_processResponses"); // // Process responses until the pipe is closed // while (1) { try { CIMMessage* message; // // Read a response from the Provider Agent // AnonymousPipe::Status readStatus = _pipeFromAgent->readMessage(message); // Ignore interrupts if (readStatus == AnonymousPipe::STATUS_INTERRUPT) { continue; } // Handle an error the same way as a closed connection if ((readStatus == AnonymousPipe::STATUS_ERROR) || (readStatus == AnonymousPipe::STATUS_CLOSED)) { AutoMutex lock(_agentMutex); _uninitialize(false); return; } // A null message indicates that the provider agent process has // finished its processing and is ready to exit. if (message == 0) { AutoMutex lock(_agentMutex); _uninitialize(true); return; } if (message->getType() == CIM_PROCESS_INDICATION_REQUEST_MESSAGE) { // Forward indications to the indication callback _indicationCallback( reinterpret_cast<CIMProcessIndicationRequestMessage*>( message)); } else if (!message->isComplete()) { CIMResponseMessage* response; response = dynamic_cast<CIMResponseMessage*>(message); PEGASUS_ASSERT(response != 0); // Get the OutstandingRequestEntry for this response chunk OutstandingRequestEntry* _outstandingRequestEntry = 0; { AutoMutex tableLock(_outstandingRequestTableMutex); Boolean foundEntry = _outstandingRequestTable.lookup( response->messageId, _outstandingRequestEntry); PEGASUS_ASSERT(foundEntry); } // Put the original message ID into the response response->messageId = _outstandingRequestEntry->originalMessageId; // Call the response chunk callback to process the chunk _responseChunkCallback( _outstandingRequestEntry->requestMessage, response); } else { CIMResponseMessage* response; response = dynamic_cast<CIMResponseMessage*>(message); PEGASUS_ASSERT(response != 0); // Give the response to the waiting OutstandingRequestEntry OutstandingRequestEntry* _outstandingRequestEntry = 0; { AutoMutex tableLock(_outstandingRequestTableMutex); Boolean foundEntry = _outstandingRequestTable.lookup( response->messageId, _outstandingRequestEntry); PEGASUS_ASSERT(foundEntry); // Remove the completed request from the table Boolean removed = _outstandingRequestTable.remove(response->messageId); PEGASUS_ASSERT(removed); } _outstandingRequestEntry->responseMessage = response; _outstandingRequestEntry->responseReady->signal(); } } catch (Exception& e) { PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, String("Ignoring exception: ") + e.getMessage()); } catch (...) { PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, "Ignoring exception"); } }}ThreadReturnType PEGASUS_THREAD_CDECLProviderAgentContainer::_responseProcessor(void* arg){ ProviderAgentContainer* pa = reinterpret_cast<ProviderAgentContainer*>(arg); pa->_processResponses(); return ThreadReturnType(0);}/////////////////////////////////////////////////////////////////////////////// OOPProviderManagerRouter/////////////////////////////////////////////////////////////////////////////OOPProviderManagerRouter::OOPProviderManagerRouter( PEGASUS_INDICATION_CALLBACK_T indicationCallback, PEGASUS_RESPONSE_CHUNK_CALLBACK_T responseChunkCallback, PEGASUS_PROVIDERMODULEFAIL_CALLBACK_T providerModuleFailCallback){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "OOPProviderManagerRouter::OOPProviderManagerRouter"); _indicationCallback = indicationCallback; _responseChunkCallback = responseChunkCallback; _providerModuleFailCallback = providerModuleFailCallback; _subscriptionInitComplete = false; PEG_METHOD_EXIT();}OOPProviderManagerRouter::~OOPProviderManagerRouter(){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "OOPProviderManagerRouter::~OOPProviderManagerRouter"); try { // Clean up the ProviderAgentContainers AutoMutex lock(_providerAgentTableMutex); ProviderAgentTable::Iterator i = _providerAgentTable.start(); for (; i != 0; i++) { delete i.value(); } } catch (...) {} PEG_METHOD_EXIT();}Message* OOPProviderManagerRouter::processMessage(Message* message){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "OOPProviderManagerRouter::processMessage"); CIMRequestMessage* request = dynamic_cast<CIMRequestMessage *>(message); PEGASUS_ASSERT(request != 0); AutoPtr<CIMResponseMessage> response; // // Get the provider information from the request // CIMInstance providerModule; if ((dynamic_cast<CIMOperationRequestMessage*>(request) != 0) || (dynamic_cast<CIMIndicationRequestMessage*>(request) != 0) || (request->getType() == CIM_EXPORT_INDICATION_REQUEST_MESSAGE)) { // Provider information is in the OperationContext ProviderIdContainer pidc = (ProviderIdContainer) request->operationContext.get(ProviderIdContainer::NAME); providerModule = pidc.getModule(); } else if (request->getType() == CIM_ENABLE_MODULE_REQUEST_MESSAGE) { CIMEnableModuleRequestMessage* emReq = dynamic_cast<CIMEnableModuleRequestMessage*>(request); providerModule = emReq->providerModule; } else if (request->getType() == CIM_DISABLE_MODULE_REQUEST_MESSAGE) { CIMDisableModuleRequestMessage* dmReq = dynamic_cast<CIMDisableModuleRequestMessage*>(request); providerModule = dmReq->providerModule; } else if ((request->getType() == CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE) || (request->getType() == CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE) || (request->getType() == CIM_NOTIFY_CONFIG_CHANGE_REQUEST_MESSAGE)) { // This operation is not provider-specific } else { // Unrecognized message type. This should never happen. PEGASUS_ASSERT(0); response.reset(request->buildResponse()); response->cimException = PEGASUS_CIM_EXCEPTION( CIM_ERR_FAILED, "Unrecognized message type."); PEG_METHOD_EXIT(); return response.release(); } // // Process the request message // if (request->getType() == CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE) { // Forward the CIMStopAllProvidersRequest to all providers response.reset(_forwardRequestToAllAgents(request)); // Note: Do not uninitialize the ProviderAgentContainers here. // Just let the selecting thread notice when the agent connections // are closed. } else if (request->getType () == CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE) { _subscriptionInitComplete = true; //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -