📄 oopprovidermanagerrouter.cpp
字号:
// Forward the CIMSubscriptionInitCompleteRequestMessage to // all providers // response.reset (_forwardRequestToAllAgents (request)); } else if (request->getType() == CIM_NOTIFY_CONFIG_CHANGE_REQUEST_MESSAGE) { CIMNotifyConfigChangeRequestMessage* notifyRequest = dynamic_cast<CIMNotifyConfigChangeRequestMessage*>(request); PEGASUS_ASSERT(notifyRequest != 0); if (notifyRequest->currentValueModified) { // Forward the CIMNotifyConfigChangeRequestMessage to all providers response.reset(_forwardRequestToAllAgents(request)); } else { // No need to notify provider agents about changes to planned value response.reset(request->buildResponse()); } } else if (request->getType() == CIM_DISABLE_MODULE_REQUEST_MESSAGE) { // Fan out the request to all Provider Agent processes for this module // Retrieve the provider module name String moduleName; CIMValue nameValue = providerModule.getProperty( providerModule.findProperty("Name")).getValue(); nameValue.get(moduleName); // Look up the Provider Agents for this module Array<ProviderAgentContainer*> paArray = _lookupProviderAgents(moduleName); for (Uint32 i=0; i<paArray.size(); i++) { // // Do not start up an agent process just to disable the module // if (paArray[i]->isInitialized()) { // // Forward the request to the provider agent // response.reset(paArray[i]->processMessage(request)); // Note: Do not uninitialize the ProviderAgentContainer here // when a disable module operation is successful. Just let the // selecting thread notice when the agent connection is closed. // Determine the success of the disable module operation CIMDisableModuleResponseMessage* dmResponse = dynamic_cast<CIMDisableModuleResponseMessage*>( response.get()); PEGASUS_ASSERT(dmResponse != 0); Boolean isStopped = false; for (Uint32 i=0; i < dmResponse->operationalStatus.size(); i++) { if (dmResponse->operationalStatus[i] == CIM_MSE_OPSTATUS_VALUE_STOPPED) { isStopped = true; break; } } // If the operation is unsuccessful, stop and return the error if ((dmResponse->cimException.getCode() != CIM_ERR_SUCCESS) || !isStopped) { break; } } } // Use a default response if no Provider Agents were called if (!response.get()) { response.reset(request->buildResponse()); CIMDisableModuleResponseMessage* dmResponse = dynamic_cast<CIMDisableModuleResponseMessage*>(response.get()); PEGASUS_ASSERT(dmResponse != 0); Array<Uint16> operationalStatus; operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_STOPPED); dmResponse->operationalStatus = operationalStatus; } } else if (request->getType() == CIM_ENABLE_MODULE_REQUEST_MESSAGE) { // Fan out the request to all Provider Agent processes for this module // Retrieve the provider module name String moduleName; CIMValue nameValue = providerModule.getProperty( providerModule.findProperty("Name")).getValue(); nameValue.get(moduleName); // Look up the Provider Agents for this module Array<ProviderAgentContainer*> paArray = _lookupProviderAgents(moduleName); for (Uint32 i=0; i<paArray.size(); i++) { // // Do not start up an agent process just to enable the module // if (paArray[i]->isInitialized()) { // // Forward the request to the provider agent // response.reset(paArray[i]->processMessage(request)); // Determine the success of the enable module operation CIMEnableModuleResponseMessage* emResponse = dynamic_cast<CIMEnableModuleResponseMessage*>( response.get()); PEGASUS_ASSERT(emResponse != 0); Boolean isOk = false; for (Uint32 i=0; i < emResponse->operationalStatus.size(); i++) { if (emResponse->operationalStatus[i] == CIM_MSE_OPSTATUS_VALUE_OK) { isOk = true; break; } } // If the operation is unsuccessful, stop and return the error if ((emResponse->cimException.getCode() != CIM_ERR_SUCCESS) || !isOk) { break; } } } // Use a default response if no Provider Agents were called if (!response.get()) { response.reset(request->buildResponse()); CIMEnableModuleResponseMessage* emResponse = dynamic_cast<CIMEnableModuleResponseMessage*>(response.get()); PEGASUS_ASSERT(emResponse != 0); Array<Uint16> operationalStatus; operationalStatus.append(CIM_MSE_OPSTATUS_VALUE_OK); emResponse->operationalStatus = operationalStatus; } } else { // // Look up the Provider Agent for this module instance and requesting // user // ProviderAgentContainer* pa = _lookupProviderAgent(providerModule, request); PEGASUS_ASSERT(pa != 0); // // Forward the request to the provider agent // response.reset(pa->processMessage(request)); } response->syncAttributes(request); PEG_METHOD_EXIT(); return response.release();}ProviderAgentContainer* OOPProviderManagerRouter::_lookupProviderAgent( const CIMInstance& providerModule, CIMRequestMessage* request){ // Retrieve the provider module name String moduleName; CIMValue nameValue = providerModule.getProperty( providerModule.findProperty("Name")).getValue(); nameValue.get(moduleName); // Retrieve the provider user context configuration Uint16 userContext = 0; Uint32 pos = providerModule.findProperty( PEGASUS_PROPERTYNAME_MODULE_USERCONTEXT); if (pos != PEG_NOT_FOUND) { CIMValue userContextValue = providerModule.getProperty(pos).getValue(); if (!userContextValue.isNull()) { userContextValue.get(userContext); } } if (userContext == 0) { userContext = PEGASUS_DEFAULT_PROV_USERCTXT; } String userName; if (userContext == PG_PROVMODULE_USERCTXT_REQUESTOR) { if (request->operationContext.contains(IdentityContainer::NAME)) { // User Name is in the OperationContext IdentityContainer ic = (IdentityContainer) request->operationContext.get(IdentityContainer::NAME); userName = ic.getUserName(); } //else //{ // If no IdentityContainer is present, default to the CIM // Server's user context //} // If authentication is disabled, use the CIM Server's user context if (!userName.size()) { userName = System::getEffectiveUserName(); } } else if (userContext == PG_PROVMODULE_USERCTXT_DESIGNATED) { // Retrieve the provider module designated user property value providerModule.getProperty(providerModule.findProperty( PEGASUS_PROPERTYNAME_MODULE_DESIGNATEDUSER)).getValue(). get(userName); } else if (userContext == PG_PROVMODULE_USERCTXT_CIMSERVER) { userName = System::getEffectiveUserName(); } else // Privileged User { PEGASUS_ASSERT(userContext == PG_PROVMODULE_USERCTXT_PRIVILEGED); userName = System::getPrivilegedUserName(); } PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, "Module name = " + moduleName); Tracer::trace(TRC_PROVIDERMANAGER, Tracer::LEVEL4, "User context = %hd.", userContext); PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, "User name = " + userName); ProviderAgentContainer* pa = 0; String key = moduleName + ":" + userName; AutoMutex lock(_providerAgentTableMutex); if (!_providerAgentTable.lookup(key, pa)) { pa = new ProviderAgentContainer( moduleName, userName, userContext, _indicationCallback, _responseChunkCallback, _providerModuleFailCallback, _subscriptionInitComplete); _providerAgentTable.insert(key, pa); } return pa;}Array<ProviderAgentContainer*> OOPProviderManagerRouter::_lookupProviderAgents( const String& moduleName){ Array<ProviderAgentContainer*> paArray; AutoMutex lock(_providerAgentTableMutex); for (ProviderAgentTable::Iterator i = _providerAgentTable.start(); i; i++) { if (i.value()->getModuleName() == moduleName) { paArray.append(i.value()); } } return paArray;}CIMResponseMessage* OOPProviderManagerRouter::_forwardRequestToAllAgents( CIMRequestMessage* request){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "OOPProviderManagerRouter::_forwardRequestToAllAgents"); // Get a list of the ProviderAgentContainers. We need our own array copy // because we cannot hold the _providerAgentTableMutex while calling // _ProviderAgentContainer::processMessage(). Array<ProviderAgentContainer*> paContainerArray; { AutoMutex tableLock(_providerAgentTableMutex); for (ProviderAgentTable::Iterator i = _providerAgentTable.start(); i != 0; i++) { paContainerArray.append(i.value()); } } CIMException responseException; // Forward the request to each of the initialized provider agents for (Uint32 j = 0; j < paContainerArray.size(); j++) { ProviderAgentContainer* pa = paContainerArray[j]; if (pa->isInitialized()) { // Note: The ProviderAgentContainer could become uninitialized // before _ProviderAgentContainer::processMessage() processes // this request. In this case, the Provider Agent process will // (unfortunately) be started to process this message. AutoPtr<CIMResponseMessage> response; response.reset(pa->processMessage(request)); if (response.get() != 0) { // If the operation failed, save the exception data if ((response->cimException.getCode() != CIM_ERR_SUCCESS) && (responseException.getCode() == CIM_ERR_SUCCESS)) { responseException = response->cimException; } } } } CIMResponseMessage* response = request->buildResponse(); response->cimException = responseException; PEG_METHOD_EXIT(); return response;}Boolean OOPProviderManagerRouter::hasActiveProviders(){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "OOPProviderManagerRouter::hasActiveProviders"); // Iterate through the _providerAgentTable looking for initialized agents AutoMutex lock(_providerAgentTableMutex); ProviderAgentTable::Iterator i = _providerAgentTable.start(); for (; i != 0; i++) { if (i.value()->isInitialized()) { PEG_METHOD_EXIT(); return true; } } // No initialized Provider Agents were found PEG_METHOD_EXIT(); return false;}void OOPProviderManagerRouter::unloadIdleProviders(){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "OOPProviderManagerRouter::unloadIdleProviders"); // Iterate through the _providerAgentTable unloading idle providers AutoMutex lock(_providerAgentTableMutex); ProviderAgentTable::Iterator i = _providerAgentTable.start(); for (; i != 0; i++) { i.value()->unloadIdleProviders(); } PEG_METHOD_EXIT();}PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -