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

📄 cmpi_broker.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.////==============================================================================//// Author:      Adrian Schuur, schuur@de.ibm.com//// Modified By: Robert Kieninger, kieningr@de.ibm.com, for bug#2642////%/////////////////////////////////////////////////////////////////////////////#include "CMPI_Version.h"#include "CMPI_Broker.h"#include "CMPI_Object.h"#include "CMPI_ContextArgs.h"#include "CMPI_Enumeration.h"#include "CMPI_Value.h"#include "CMPIProviderManager.h"#include "CMPI_String.h"#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/CIMPropertyList.h>#include <Pegasus/Provider/CIMOMHandle.h>#include <Pegasus/Common/CIMValue.h>#include <Pegasus/Common/CIMType.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN#define DDD(X)   if (_cmpi_trace) X;extern int _cmpi_trace;static CIMPropertyList getList(const char** l) {  CIMPropertyList pl;  if (l) {    Array<CIMName> n;    while (*l) {      n.append(*l++);    }    pl.set(n);  }  return pl;}CIMClass* mbGetClass(const CMPIBroker *mb, const CIMObjectPath &cop) {   DDD(cout<<"--- mbGetClass()"<<endl);   mb=CM_BROKER;   CMPI_Broker *xBroker=(CMPI_Broker*)mb;   String clsId=cop.getNameSpace().getString()+":"+cop.getClassName().getString();   CIMClass *ccp;   {      ReadLock readLock (xBroker->rwsemClassCache);      if (xBroker->clsCache->lookup(clsId,ccp)) return ccp;   }   try {      WriteLock writeLock (xBroker->rwsemClassCache);      if (xBroker->clsCache->lookup(clsId,ccp)) return ccp;      CIMClass cc=CM_CIMOM(mb)->getClass(                  OperationContext(),		  cop.getNameSpace(),		  cop.getClassName(),		  (bool)0,		  (bool)1,		  (bool)0,		  CIMPropertyList());      ccp=new CIMClass(cc);      xBroker->clsCache->insert(clsId,ccp);      return ccp;   }   catch (const CIMException &e) {      DDD(cout<<"### exception: mbGetClass - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);   }   return NULL;}extern "C" {   static CMPIInstance* mbGetInstance(const CMPIBroker *mb, const CMPIContext *ctx,                  const CMPIObjectPath *cop, const char **properties, CMPIStatus *rc) {      DDD(cout<<"--- mbGetInstance()"<<endl);      mb=CM_BROKER;      CMPIFlags flgs=ctx->ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32;      const CIMPropertyList props=getList(properties);      CIMObjectPath qop(String::EMPTY,CIMNamespaceName(),                        CM_ObjectPath(cop)->getClassName(),            CM_ObjectPath(cop)->getKeyBindings());      AutoMutex mtx(((CMPI_Broker*)mb)->mtx);      try {         CIMInstance ci=CM_CIMOM(mb)->getInstance(                     OperationContext(*CM_Context(ctx)),         CM_ObjectPath(cop)->getNameSpace(),         qop, //*CM_ObjectPath(cop),         CM_LocalOnly(flgs),         CM_IncludeQualifiers(flgs),         CM_ClassOrigin(flgs),         props);         ci.setPath(*CM_ObjectPath(cop));         if (rc) CMSetStatus(rc,CMPI_RC_OK);         return reinterpret_cast<CMPIInstance*>(new CMPI_Object(new CIMInstance(ci)));      }      catch (const CIMException &e) {         DDD(cout<<"### exception: mbGetInstance - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);         if (rc) CMSetStatusWithString(rc,(CMPIrc)e.getCode(),            (CMPIString*)string2CMPIString(e.getMessage()));         return NULL;      }      // Code flow should never get here.   }   static CMPIObjectPath* mbCreateInstance(const CMPIBroker *mb, const CMPIContext *ctx,                  const CMPIObjectPath *cop, const CMPIInstance *ci, CMPIStatus *rc) {      DDD(cout<<"--- mbCreateInstance()"<<endl);      mb=CM_BROKER;      AutoMutex mtx(((CMPI_Broker*)mb)->mtx);      try {         CIMObjectPath ncop=CM_CIMOM(mb)->createInstance(                     OperationContext(*CM_Context(ctx)),         CM_ObjectPath(cop)->getNameSpace(),                     *CM_Instance(ci));         if (rc) CMSetStatus(rc,CMPI_RC_OK);         return reinterpret_cast<CMPIObjectPath*>(new CMPI_Object(new CIMObjectPath(ncop)));      }      catch (const CIMException &e) {         DDD(cout<<"### exception: mbCreateInstance - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);         if (rc) CMSetStatusWithString(rc,(CMPIrc)e.getCode(),            (CMPIString*)string2CMPIString(e.getMessage()));         return NULL;      }      // Code flow should never get here.   }   static CMPIStatus mbModifyInstance(const CMPIBroker *mb, const CMPIContext *ctx,         const CMPIObjectPath *cop, const CMPIInstance *ci,const  char ** properties) {      DDD(cout<<"--- mbSetInstance()"<<endl);      mb=CM_BROKER;      CMPIFlags flgs=ctx->ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32;      const CIMPropertyList props=getList(properties);      AutoMutex mtx(((CMPI_Broker*)mb)->mtx);      try {   	 CIMInstance cmi(*CM_Instance(ci));	 cmi.setPath(*CM_ObjectPath(cop));         CM_CIMOM(mb)->modifyInstance(                     OperationContext(*CM_Context(ctx)),		     CM_ObjectPath(cop)->getNameSpace(),                     cmi,         CM_IncludeQualifiers(flgs),         props);      }      catch (const CIMException &e) {         DDD(cout<<"### exception: mbSetInstance - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);         CMReturnWithString((CMPIrc)e.getCode(),            (CMPIString*)string2CMPIString(e.getMessage()));      }      CMReturn(CMPI_RC_OK);   }   static CMPIStatus mbDeleteInstance (const CMPIBroker *mb, const CMPIContext *ctx,                  const CMPIObjectPath *cop) {      DDD(cout<<"--- mbDeleteInstance()"<<endl);      mb=CM_BROKER;      CIMObjectPath qop(String::EMPTY,CIMNamespaceName(),                        CM_ObjectPath(cop)->getClassName(),            CM_ObjectPath(cop)->getKeyBindings());      AutoMutex mtx(((CMPI_Broker*)mb)->mtx);      try {         CM_CIMOM(mb)->deleteInstance(                     OperationContext(*CM_Context(ctx)),         CM_ObjectPath(cop)->getNameSpace(),         qop); //*CM_ObjectPath(cop));      }      catch (const CIMException &e) {         DDD(cout<<"### exception: mbDeleteInstance - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);         CMReturnWithString((CMPIrc)e.getCode(),            (CMPIString*)string2CMPIString(e.getMessage()));      }      CMReturn(CMPI_RC_OK);   }   static CMPIEnumeration* mbExecQuery(const CMPIBroker *mb,				       const CMPIContext *ctx,				       const CMPIObjectPath *cop,				       const char *query, const char *lang, CMPIStatus *rc) {      DDD(cout<<"--- mbExecQuery()"<<endl);      mb=CM_BROKER;      AutoMutex mtx(((CMPI_Broker*)mb)->mtx);      try {         Array<CIMObject> const &en=CM_CIMOM(mb)->execQuery(                     OperationContext(*CM_Context(ctx)),         CM_ObjectPath(cop)->getNameSpace(),         String(query),         String(lang));         if (rc) CMSetStatus(rc,CMPI_RC_OK);         CMPI_Object *obj =             new CMPI_Object(new CMPI_ObjEnumeration(new Array<CIMObject>(en)));         return (CMPI_ObjEnumeration *)obj->getHdl();      }      catch (const CIMException &e) {         DDD(cout<<"### exception: mbExecQuery - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);         if (rc) CMSetStatusWithString(rc,(CMPIrc)e.getCode(),            (CMPIString*)string2CMPIString(e.getMessage()));         return NULL;      }      // Code flow should never get here.   }   static CMPIEnumeration* mbEnumInstances(const CMPIBroker *mb, const CMPIContext *ctx,                  const CMPIObjectPath *cop, const char **properties, CMPIStatus *rc) {      DDD(cout<<"--- mbEnumInstances()"<<endl);      mb=CM_BROKER;      CMPIFlags flgs=ctx->ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32;      const CIMPropertyList props=getList(properties);      AutoMutex mtx(((CMPI_Broker*)mb)->mtx);      try {         Array<CIMInstance> const &en=CM_CIMOM(mb)->enumerateInstances(                     OperationContext(*CM_Context(ctx)),         CM_ObjectPath(cop)->getNameSpace(),         CM_ObjectPath(cop)->getClassName(),         CM_DeepInheritance(flgs),         CM_LocalOnly(flgs),         CM_IncludeQualifiers(flgs),         CM_ClassOrigin(flgs),         props);         if (rc) CMSetStatus(rc,CMPI_RC_OK);         // Workaround for bugzilla 4677         // When running out of process the returned instances don't contain         // a name space. Create a writable copy of the array and add the         // namespace from the input parameters.         Array<CIMInstance> * aInst = new Array<CIMInstance>(en);         for (unsigned int index=0;index < aInst->size(); index++)         {             CIMInstance& myInst = (*aInst)[index];             CIMObjectPath orgCop = myInst.getPath();             orgCop.setNameSpace(CM_ObjectPath(cop)->getNameSpace());             (*aInst)[index].setPath(orgCop);         }         CMPI_Object *obj = new CMPI_Object(new CMPI_InstEnumeration(aInst));         /*CMPI_Object *obj =             new CMPI_Object(new CMPI_InstEnumeration(new Array<CIMInstance>(en)));*/         // End of workaround for bugzilla 4677         return (CMPI_InstEnumeration*)obj->getHdl();      }      catch (const CIMException &e) {         DDD(cout<<"### exception: mbEnumInstances - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);         if (rc) CMSetStatusWithString(rc,(CMPIrc)e.getCode(),            (CMPIString*)string2CMPIString(e.getMessage()));         return NULL;      }      // Code flow should never get here.   }   static CMPIEnumeration* mbEnumInstanceNames(const CMPIBroker *mb, const CMPIContext *ctx,                  const CMPIObjectPath *cop, CMPIStatus *rc) {      DDD(cout<<"--- mbEnumInstanceNames()"<<endl);      mb=CM_BROKER;      AutoMutex mtx(((CMPI_Broker*)mb)->mtx);   try {         Array<CIMObjectPath> const &en=CM_CIMOM(mb)->enumerateInstanceNames(                     OperationContext(*CM_Context(ctx)),         CM_ObjectPath(cop)->getNameSpace(),         CM_ObjectPath(cop)->getClassName());         if (rc) CMSetStatus(rc,CMPI_RC_OK);          // When running out of process the returned instances don't contain          // a name space. Create a writable copy of the array and add the          // namespace from the input parameters.          Array<CIMObjectPath> * aObj = new Array<CIMObjectPath>(en);          for (unsigned int index=0;index < aObj->size(); index++)          {            (*aObj)[index].setNameSpace(CM_ObjectPath(cop)->getNameSpace());          }          CMPI_Object *obj = new CMPI_Object(new CMPI_OpEnumeration(aObj));         return (CMPI_OpEnumeration *)obj->getHdl();      }      catch (const CIMException &e) {         DDD(cout<<"### exception: mbEnumInstances - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);         if (rc) CMSetStatusWithString(rc,(CMPIrc)e.getCode(),            (CMPIString*)string2CMPIString(e.getMessage()));         return NULL;      }      // Code flow should never get here.   }   static CMPIEnumeration* mbAssociators(const CMPIBroker *mb, const CMPIContext *ctx,                  const CMPIObjectPath *cop, const char *assocClass, const char *resultClass,                  const char *role, const char *resultRole, const char **properties, CMPIStatus *rc) {      DDD(cout<<"--- mbAssociators()"<<endl);      mb=CM_BROKER;      CMPIFlags flgs=ctx->ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32;      const CIMPropertyList props=getList(properties);      CIMObjectPath qop(String::EMPTY,CIMNamespaceName(),                        CM_ObjectPath(cop)->getClassName(),            CM_ObjectPath(cop)->getKeyBindings());      AutoMutex mtx(((CMPI_Broker*)mb)->mtx);      try {         Array<CIMObject> const &en=CM_CIMOM(mb)->associators(                     OperationContext(*CM_Context(ctx)),         CM_ObjectPath(cop)->getNameSpace(),         qop,         assocClass ? CIMName(assocClass) : CIMName(),         resultClass ? CIMName(resultClass) : CIMName(),         role ? String(role) : String::EMPTY,         resultRole ? String(resultRole) : String::EMPTY,         CM_IncludeQualifiers(flgs),         CM_ClassOrigin(flgs),         props);         if (rc) CMSetStatus(rc,CMPI_RC_OK);         // Workaround for bugzilla 4677         // When running out of process the returned instances don't contain         // a name space. Create a writable copy of the array and add the         // namespace from the input parameters.         Array<CIMObject> * aInst = new Array<CIMObject>(en);         for (unsigned int index=0;index < aInst->size(); index++)         {             CIMObject& myInst = (*aInst)[index];             CIMObjectPath orgCop = myInst.getPath();

⌨️ 快捷键说明

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