📄 cmpiprovidermanager.cpp
字号:
//%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 "CMPI_Version.h"#include "CMPIProviderManager.h"#include "CMPI_Object.h"#include "CMPI_ContextArgs.h"#include "CMPI_Instance.h"#include "CMPI_ObjectPath.h"#include "CMPI_Result.h"#include "CMPI_SelectExp.h"#include <Pegasus/Common/CIMMessage.h>#include <Pegasus/Common/OperationContext.h>#include <Pegasus/Common/OperationContextInternal.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/StatisticalData.h>#include <Pegasus/Common/Logger.h>#include <Pegasus/Common/LanguageParser.h>#include <Pegasus/Common/MessageLoader.h> //l10n#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Config/ConfigManager.h>#include <Pegasus/Provider/CIMOMHandleQueryContext.h>#include <Pegasus/ProviderManager2/CIMOMHandleContext.h>#include <Pegasus/ProviderManager2/ProviderName.h>#include <Pegasus/ProviderManager2/AutoPThreadSecurity.h>#include <Pegasus/ProviderManager2/CMPI/CMPIProviderModule.h>#include <Pegasus/ProviderManager2/CMPI/CMPIProvider.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINint _cmpi_trace=0;//Function to throw exception if provider has not been correctly created.void _throw_MINotInitializedException(){ MessageLoaderParms parms("ProviderManager.CMPI.CMPIProviderManager.PROVIDER_LOAD_FAILURE","ProviderLoadFailure: Cannot find _Create<mi-type>MI symbol."); throw CIMException(CIM_ERR_FAILED,MessageLoader::getMessage(parms));}#define DDD(x) if (_cmpi_trace) x;ReadWriteSem CMPIProviderManager::rwSemProvTab;ReadWriteSem CMPIProviderManager::rwSemSelxTab;CMPIProviderManager::IndProvTab CMPIProviderManager::provTab;CMPIProviderManager::IndSelectTab CMPIProviderManager::selxTab;CMPIProviderManager::ProvRegistrar CMPIProviderManager::provReg;class CMPIPropertyList { char **props; int pCount; public: CMPIPropertyList(CIMPropertyList &propertyList) : props(0), pCount(0) { if (!propertyList.isNull()) { Array<CIMName> p=propertyList.getPropertyNameArray(); pCount=p.size(); props = new char*[1+pCount]; for (int i=0; i<pCount; i++) { props[i]=strdup(p[i].getString().getCString()); } props[pCount]=NULL; } else props=NULL; } ~CMPIPropertyList() { if (props) { for (int i=0; i<pCount; i++) free(props[i]); delete [] props; } } char **getList() { return props; }};CMPIProviderManager::CMPIProviderManager(Mode m){ mode=m; #ifdef PEGASUS_DEBUG if (getenv("PEGASUS_CMPI_TRACE")) _cmpi_trace=1; else _cmpi_trace=0; #endif _subscriptionInitComplete = false; DDD(cerr << "-- CMPI Provider Manager activated" << endl);}CMPIProviderManager::~CMPIProviderManager(void){ /* Clean up the hash-tables */ indProvRecord *prec=NULL; { WriteLock writeLock(rwSemProvTab); for (IndProvTab::Iterator i = provTab.start(); i; i++) { provTab.lookup(i.key(),prec); if (prec->handler) delete prec->handler; delete prec; //Remove is not neccessary, since the hashtable destructor takes care //of this already. But instead removing entries while iterating the //hashtable sometimes causes a segmentation fault!!! //provTab.remove(i.key()); prec=NULL; } } indSelectRecord *selx=NULL; { WriteLock writeLock(rwSemSelxTab); for (IndSelectTab::Iterator i = selxTab.start(); i; i++) { selxTab.lookup(i.key(), selx); if (selx->eSelx) delete selx->eSelx; if (selx->qContext) delete selx->qContext; delete selx; //Same as above! //selxTab.remove(i.key()); selx=NULL; } }}Boolean CMPIProviderManager::insertProvider(const ProviderName & name, const String &ns, const String &cn){ String key(ns+String("::")+cn+String("::")+CIMValue(name.getCapabilitiesMask()).toString()); return provReg.insert(key,name);}Message * CMPIProviderManager::processMessage(Message * request){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "CMPIProviderManager::processMessage()"); Message * response = 0; // pass the request message to a handler method based on message type switch(request->getType()) { case CIM_GET_INSTANCE_REQUEST_MESSAGE: response = handleGetInstanceRequest(request); break; case CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE: response = handleEnumerateInstancesRequest(request); break; case CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE: response = handleEnumerateInstanceNamesRequest(request); break; case CIM_CREATE_INSTANCE_REQUEST_MESSAGE: response = handleCreateInstanceRequest(request); break; case CIM_MODIFY_INSTANCE_REQUEST_MESSAGE: response = handleModifyInstanceRequest(request); break; case CIM_DELETE_INSTANCE_REQUEST_MESSAGE: response = handleDeleteInstanceRequest(request); break; case CIM_EXEC_QUERY_REQUEST_MESSAGE: response = handleExecQueryRequest(request); break; case CIM_ASSOCIATORS_REQUEST_MESSAGE: response = handleAssociatorsRequest(request); break; case CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE: response = handleAssociatorNamesRequest(request); break; case CIM_REFERENCES_REQUEST_MESSAGE: response = handleReferencesRequest(request); break; case CIM_REFERENCE_NAMES_REQUEST_MESSAGE: response = handleReferenceNamesRequest(request); break; case CIM_INVOKE_METHOD_REQUEST_MESSAGE: response = handleInvokeMethodRequest(request); break; case CIM_CREATE_SUBSCRIPTION_REQUEST_MESSAGE: response = handleCreateSubscriptionRequest(request); break;/* case CIM_MODIFY_SUBSCRIPTION_REQUEST_MESSAGE: response = handleModifySubscriptionRequest(request); break;*/ case CIM_DELETE_SUBSCRIPTION_REQUEST_MESSAGE: response = handleDeleteSubscriptionRequest(request); break;/* case CIM_EXPORT_INDICATION_REQUEST_MESSAGE: response = handleExportIndicationRequest(request); break;*/ case CIM_DISABLE_MODULE_REQUEST_MESSAGE: response = handleDisableModuleRequest(request); break; case CIM_ENABLE_MODULE_REQUEST_MESSAGE: response = handleEnableModuleRequest(request); break; case CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE: response = handleStopAllProvidersRequest(request); break; case CIM_INITIALIZE_PROVIDER_REQUEST_MESSAGE: response = handleInitializeProviderRequest(request); break; case CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE: response = handleSubscriptionInitCompleteRequest (request); break; case CIM_GET_PROPERTY_REQUEST_MESSAGE: response = handleGetPropertyRequest(request); break; case CIM_SET_PROPERTY_REQUEST_MESSAGE: response = handleSetPropertyRequest(request); break; default: response = handleUnsupportedRequest(request); break; } PEG_METHOD_EXIT(); return(response);}Boolean CMPIProviderManager::hasActiveProviders(){ return providerManager.hasActiveProviders();}void CMPIProviderManager::unloadIdleProviders(){ providerManager.unloadIdleProviders();}#define CHARS(cstring) (char*)(strlen(cstring)?(const char*)cstring:NULL)#define HandlerIntroBase(type,type1,message,request,response,handler) \ CIM##type##RequestMessage * request = \ dynamic_cast<CIM##type##RequestMessage *>(const_cast<Message *>(message)); \ PEGASUS_ASSERT(request != 0); \ CIM##type##ResponseMessage * response = \ dynamic_cast<CIM##type##ResponseMessage*>(request->buildResponse()); \ PEGASUS_ASSERT(response != 0); \ type1##ResponseHandler handler(request, response, _responseChunkCallback);#define HandlerIntroInd(type,message,request,response,handler) \ HandlerIntroBase(type,Operation,message,request,response,handler)#define HandlerIntroInit(type,message,request,response,handler) \ HandlerIntroBase(type,Operation,message,request,response,handler)#define HandlerIntro(type,message,request,response,handler) \ HandlerIntroBase(type,type,message,request,response,handler)#define HandlerCatch(handler) \ catch(const CIMException & e) \ { PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, \ "Exception: " + e.getMessage()); \ handler.setCIMException(e); \ } \ catch(const Exception & e) \ { PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, \ "Exception: " + e.getMessage()); \ handler.setStatus(CIM_ERR_FAILED, e.getContentLanguages(), e.getMessage()); \ } \ catch(...) \ { PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, \ "Exception: Unknown"); \ handler.setStatus(CIM_ERR_FAILED, "Unknown error."); \ }Message * CMPIProviderManager::handleGetInstanceRequest(const Message * message){ PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "CMPIProviderManager::handleGetInstanceRequest"); HandlerIntro(GetInstance,message,request,response,handler); try { Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE, "CmpiProviderManager::handleGetInstanceRequest - Host name: $0 Name space: $1 Class name: $2", System::getHostName(), request->nameSpace.getString(), request->instanceName.getClassName().getString()); // make target object path CIMObjectPath objectPath( System::getHostName(),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -