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

📄 cmpi_result.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.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include "CMPI_Version.h"#include "CMPI_Result.h"#include "CMPI_Ftabs.h"#include "CMPI_Value.h"#include "CMPI_String.h"#include <typeinfo>#include <Pegasus/ProviderManager2/SimpleResponseHandler.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/CIMType.h>#include <Pegasus/Common/Mutex.h>#include <string.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINMutex errorChainMutex;#define DDD(X)	if (_cmpi_trace) X;extern int _cmpi_trace;CMPIStatus resolveEmbeddedInstanceTypes(    OperationResponseHandler * opRes,    CIMInstance & inst){    CIMOperationRequestMessage * request =        dynamic_cast<CIMOperationRequestMessage *>(opRes->getRequest());    if(request->operationContext.contains(NormalizerContextContainer::NAME) &&        request->operationContext.contains(CachedClassDefinitionContainer::NAME))    {        const NormalizerContextContainer * contextContainer =            dynamic_cast<const NormalizerContextContainer *>(                &(request->operationContext.get(                    NormalizerContextContainer::NAME)));        PEGASUS_ASSERT(contextContainer);        const CachedClassDefinitionContainer * classContainer =            dynamic_cast<const CachedClassDefinitionContainer *>(                &(request->operationContext.get(                    CachedClassDefinitionContainer::NAME)));        CIMClass classDef(classContainer->getClass());        for(unsigned int i = 0, n = inst.getPropertyCount(); i < n; ++i)        {            CIMConstProperty currentProp(inst.getProperty(i));            if(currentProp.getType() == CIMTYPE_OBJECT)            {                Uint32 propIndex = classDef.findProperty(                    currentProp.getName());                if(propIndex == PEG_NOT_FOUND)                {                    String message =                         String("Could not find property ")                        + currentProp.getName().getString()                        + " in class definition";                    CMReturnWithString(CMPI_RC_ERR_FAILED,                        (CMPIString*)string2CMPIString(message));                }                CIMConstProperty propertyDef(                    classDef.getProperty(propIndex));                // Normalize the property: this will ensure that the property                // and any embedded instance/object properties are consistent                // with the relevant class definitions.                CIMProperty normalizedProperty(                    ObjectNormalizer::_processProperty(                        propertyDef,                        currentProp,                        false,                        false,                        contextContainer->getContext(),                        request->nameSpace));                // Remove the old property, add the new, and adjust the                // loop counters appropriately.                inst.removeProperty(propIndex);                inst.addProperty(normalizedProperty);                --i;                --n;            }        }    }    //else    //{        // If the NormalizerContextContainer is not present, then the        // ObjectNormalizer must be enabled for this operation and the        // ObjectNormalizer will do the work in the above try block.    //}    CMReturn(CMPI_RC_OK);}extern "C" {   PEGASUS_STATIC CMPIStatus resultReturnData(       const CMPIResult* eRes, const CMPIValue* data,  const CMPIType type)    {      CMPIrc rc;      if ((eRes->hdl == NULL) || (data == NULL))	     CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);    try {      CIMValue v=value2CIMValue((CMPIValue*)data,type,&rc);      if (eRes->ft==CMPI_ResultMethOnStack_Ftab)      {         MethodResultResponseHandler* res=(MethodResultResponseHandler*)eRes->hdl;         if ((((CMPI_Result*)eRes)->flags & RESULT_set)==0)         {            res->processing();            ((CMPI_Result*)eRes)->flags|=RESULT_set;         }#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT          // If the CMPI type is CMPI_instance, then the CIM return type could          // be either an EmbeddedObject or EmbeddedInstance. We must find the          // method signature in the class definition to find out what the          // return type is.          if(type & CMPI_instance)          {              try               {                  InvokeMethodResponseHandler * opRes =                    dynamic_cast<InvokeMethodResponseHandler *>(res);                  CIMInvokeMethodRequestMessage * request =                      dynamic_cast<CIMInvokeMethodRequestMessage *>(                          opRes->getRequest());                  PEGASUS_ASSERT(request != 0);                  const CachedClassDefinitionContainer * classContainer =                      dynamic_cast<const CachedClassDefinitionContainer *>(                          &(request->operationContext.get(                              CachedClassDefinitionContainer::NAME)));                  PEGASUS_ASSERT(classContainer != 0);                  CIMClass classDef(classContainer->getClass());                  Uint32 methodIndex = classDef.findMethod(                      request->methodName);                  if(methodIndex == PEG_NOT_FOUND)                  {                      String message(                          "Method not found in class definition");                      CMReturnWithString(CMPI_RC_ERR_FAILED,                          (CMPIString*)string2CMPIString(message));                  }                  CIMMethod methodDef(classDef.getMethod(methodIndex));                  if(methodDef.findQualifier(CIMName("EmbeddedInstance")) !=                      PEG_NOT_FOUND)                  {                      PEGASUS_ASSERT(v.getType() == CIMTYPE_OBJECT);                      CIMObject tmpObject;                      v.get(tmpObject);                      v = CIMValue(CIMInstance(tmpObject));                  }              }              catch(Exception & e)              {                  CMReturnWithString(CMPI_RC_ERR_FAILED,                      (CMPIString*)string2CMPIString(e.getMessage()));              }          }#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT         res->deliver(v);      }      else {         ValueResponseHandler* res=(ValueResponseHandler*)eRes->hdl;         if ((((CMPI_Result*)eRes)->flags & RESULT_set)==0) {            res->processing();            ((CMPI_Result*)eRes)->flags|=RESULT_set;         }         res->deliver(v);      }    }    catch (const CIMException &e)    {        DDD(cout<<"### exception: resultReturnData - msg: "<<e.getMessage()<<endl);        CMReturnWithString(CMPI_RC_ERR_FAILED, (CMPIString*)string2CMPIString(e.getMessage()));    }    CMReturn(CMPI_RC_OK);   }   PEGASUS_STATIC CMPIStatus resultReturnInstance(const CMPIResult* eRes, const CMPIInstance* eInst) {      InstanceResponseHandler* res=(InstanceResponseHandler*)eRes->hdl;      if ((res == NULL) || (eInst == NULL))		CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);	  if (!eInst->hdl)		CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);	try {	      if ((((CMPI_Result*)eRes)->flags & RESULT_set)==0) {         res->processing();         ((CMPI_Result*)eRes)->flags|=RESULT_set;      }      CIMInstance& inst=*(CIMInstance*)(eInst->hdl);      CMPI_Result *xRes=(CMPI_Result*)eRes;      const CIMObjectPath& op=inst.getPath();      CIMClass *cc=mbGetClass(xRes->xBroker,op);      CIMObjectPath iop=inst.buildPath(*cc);      iop.setNameSpace(op.getNameSpace());      inst.setPath(iop);      // Check if a property filter has been set. If yes throw out      // all properties which are not found in the filter list.      char **listroot=(char**)(reinterpret_cast<const CMPI_Object*>(eInst))->priv;      if (listroot && *listroot)      {         int propertyCount = inst.getPropertyCount()-1;         for (int idx=propertyCount; idx >=0 ; idx--)         {            CIMConstProperty prop = inst.getProperty(idx);            String sName = prop.getName().getString();            char * name = strdup(sName.getCString());            char **list = listroot;            int found = false;            while (*list)            {               if (System::strcasecmp(name,*list)==0)               {                  found = true;                  break;               }               list++;            }            free(name);            if (!found)            {               inst.removeProperty(idx);            }         }      }#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT      // CMPI does not differentiate between EmbeddedInstances and      // EmbeddedObjects, so any mismatches between the property type      // in the instance and the property type in the class definition      // must be resolved.      EnumerateInstancesResponseHandler * eiRes =          dynamic_cast<EnumerateInstancesResponseHandler *>(res);      GetInstanceResponseHandler * giRes = 0;      CMPIStatus status;      if(eiRes)      {          status = resolveEmbeddedInstanceTypes(eiRes, inst);      }      else      {          giRes = dynamic_cast<GetInstanceResponseHandler *>(res);          PEGASUS_ASSERT(giRes);          status = resolveEmbeddedInstanceTypes(giRes, inst);      }            if(status.rc != CMPI_RC_OK)      {        return status;      }#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT      res->deliver(inst);	} catch (const CIMException &e)	{    	DDD(cout<<"### exception: resultReturnInstance - msg: "<<e.getMessage()<<endl);	    CMReturnWithString(CMPI_RC_ERR_FAILED, (CMPIString*)string2CMPIString(e.getMessage()));	}      CMReturn(CMPI_RC_OK);   }   PEGASUS_STATIC CMPIStatus resultReturnObject(const CMPIResult* eRes, const CMPIInstance* eInst) {      ObjectResponseHandler* res=(ObjectResponseHandler*)eRes->hdl;      if ((res == NULL) || (eInst == NULL))		CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);	  if (!eInst->hdl)		CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);	try {       if ((((CMPI_Result*)eRes)->flags & RESULT_set)==0) {         res->processing();         ((CMPI_Result*)eRes)->flags|=RESULT_set;      }      CIMInstance& inst=*(CIMInstance*)(eInst->hdl);      CMPI_Result *xRes=(CMPI_Result*)eRes;      const CIMObjectPath& op=inst.getPath();      CIMClass *cc=mbGetClass(xRes->xBroker,op);      CIMObjectPath iop=inst.buildPath(*cc);      iop.setNameSpace(op.getNameSpace());      inst.setPath(iop);#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT      // CMPI does not differentiate between EmbeddedInstances and      // EmbeddedObjects, so any mismatches between the property type      // in the instance and the property type in the class definition      // must be resolved.      CMPIStatus status;      do      {          // Try EnumerateInstancesResponseHandler:          EnumerateInstancesResponseHandler * eiRes =              dynamic_cast<EnumerateInstancesResponseHandler *>(res);          if(eiRes)          {              status = resolveEmbeddedInstanceTypes(eiRes, inst);              break;          }          // Try GetInstanceResponseHandler          GetInstanceResponseHandler * giRes = 0;              giRes = dynamic_cast<GetInstanceResponseHandler *>(res);          if (giRes)          {              status = resolveEmbeddedInstanceTypes(giRes, inst);              break;          }          // Try AssociatorsResponseHandler:          AssociatorsResponseHandler* aRes = 0;              aRes = dynamic_cast<AssociatorsResponseHandler*>(res);          if (aRes)          {              status = resolveEmbeddedInstanceTypes(aRes, inst);              break;          }          // Try AssociatorsResponseHandler:          ReferencesResponseHandler* rRes = 0;              rRes = dynamic_cast<ReferencesResponseHandler*>(res);          if (rRes)          {              status = resolveEmbeddedInstanceTypes(rRes, inst);              break;          }          // None of the above.          PEGASUS_ASSERT(0);      }      while (0);            if(status.rc != CMPI_RC_OK)      {        return status;      }#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT

⌨️ 快捷键说明

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