📄 cmpi_brokerenc.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 <Pegasus/Common/CIMNameUnchecked.h>#include "CMPI_Version.h"#include "CMPI_Object.h"#include "CMPI_Broker.h"#include "CMPI_Ftabs.h"#include "CMPI_String.h"#include "CMPI_SelectExp.h"#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/CIMPropertyList.h>#if defined (CMPI_VER_85)#include <Pegasus/Common/MessageLoader.h>#include <Pegasus/Common/LanguageParser.h>#endif#if defined(CMPI_VER_100)#include <Pegasus/Common/Logger.h>#include <Pegasus/Common/TraceComponents.h>#include <Pegasus/Common/Tracer.h>#endif#include <Pegasus/Provider/CIMOMHandle.h>#include <Pegasus/WQL/WQLSelectStatement.h>#include <Pegasus/WQL/WQLParser.h>#ifndef PEGASUS_DISABLE_CQL#include <Pegasus/Provider/CIMOMHandleQueryContext.h>#include <Pegasus/CQL/CQLSelectStatement.h>#include <Pegasus/CQL/CQLParser.h>#include <Pegasus/CQL/CQLChainedIdentifier.h>#include <Pegasus/Provider/CMPI/cmpi_cql.h>#endif#include <stdarg.h>#include <string.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN#define DDD(X) if (_cmpi_trace) X;extern int _cmpi_trace;#ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC #define lloonngg __int64#else #define lloonngg long long int#endif// Factory sectionstatic String typeToString(CIMType t) { switch (t) { case CIMTYPE_BOOLEAN: return "boolean"; case CIMTYPE_UINT8: return "uint8"; case CIMTYPE_SINT8: return "sint8"; case CIMTYPE_UINT16: return "uint16"; case CIMTYPE_SINT16: return "sint16"; case CIMTYPE_UINT32: return "uint32"; case CIMTYPE_SINT32: return "sint32"; case CIMTYPE_UINT64: return "sint64"; case CIMTYPE_SINT64: return "sint64"; case CIMTYPE_REAL32: return "real32"; case CIMTYPE_REAL64: return "real64"; case CIMTYPE_CHAR16: return "char16"; case CIMTYPE_STRING: return "string"; case CIMTYPE_DATETIME: return "datetime"; case CIMTYPE_REFERENCE: return "reference"; case CIMTYPE_OBJECT: return "object";#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT case CIMTYPE_INSTANCE: return "instance";#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT default: return "???"; }}#define CMPIInstance_str "CMPIInstance"#define CMPIInstance_str_l 13#define CMPIObjectPath_str "CMPIObjectPath"#define CMPIObjectPath_str_l 16#define CMPIArgs_str "CMPIArgs"#define CMPIArgs_str_l 8#define CMPIContext_str "CMPIContext"#define CMPIContext_str_l 11#define CMPIResult_str "CMPIResult"#define CMPIResult_str_l 12#define CMPIDateTime_str "CMPIDateTime"#define CMPIDateTime_str_l 12#define CMPIArray_str "CMPIArray"#define CMPIArray_str_l 9#define CMPIString_str "CMPIString"#define CMPIString_str_l 10#define CMPISelectExp_str "CMPISelectExp"#define CMPISelectExp_str_l 13#define CMPISelectCond_str "CMPISelectCond"#define CMPISelectCond_str_l 14#define CMPISubCond_str "CMPISubCond"#define CMPISubCond_str_l 11#define CMPIPredicate_str "CMPIPredicate"#define CMPIPredicate_str_l 13#define CMPIBroker_str "CMPIBroker"#define CMPIBroker_str_l 10#define CMPIEnumeration_str "CMPIEnumeration"#define CMPIEnumeration_str_l 15static Formatter::Arg formatValue(va_list *argptr, CMPIStatus *rc, int *err) { CMPIType type=va_arg(*argptr,int); if (rc) CMSetStatus(rc,CMPI_RC_OK); if (*err) return Formatter::Arg("*failed*"); switch(type) { case CMPI_sint8: case CMPI_sint16: case CMPI_sint32: return Formatter::Arg((int)va_arg(*argptr,int)); case CMPI_uint8: case CMPI_uint16: case CMPI_uint32: return Formatter::Arg((unsigned int)va_arg(*argptr,unsigned int)); case CMPI_boolean: return Formatter::Arg((Boolean)va_arg(*argptr,int)); case CMPI_real32: case CMPI_real64: return Formatter::Arg((double)va_arg(*argptr,double)); case CMPI_sint64: return Formatter::Arg((lloonngg)va_arg(*argptr,lloonngg)); case CMPI_uint64: return Formatter::Arg((unsigned lloonngg)va_arg(*argptr,unsigned lloonngg)); case CMPI_chars: return Formatter::Arg((char*)va_arg(*argptr,char*)); case CMPI_string: { CMPIString *s=va_arg(*argptr,CMPIString*); return Formatter::Arg((char*)CMGetCharsPtr(s,NULL)); } default: *err=1; if (rc) rc->rc=CMPI_RC_ERR_INVALID_PARAMETER; return Formatter::Arg("*bad value type*"); }}static inline CIMNamespaceName NameSpaceName(const char *ns) { CIMNamespaceName n; if (ns==NULL) return n; try { n = CIMNamespaceName(ns); } catch (...) { // n won't be assigned to anything yet, so it is safe // to send it off. } return n;}static inline CIMName Name(const char *n) { CIMName name; if (n==NULL) return name; try { name = CIMNameUnchecked(n); } catch ( ...) { } return name;}extern "C" { static CMPIString* mbEncToString(const CMPIBroker*,const void *o, CMPIStatus *rc); static CMPIInstance* mbEncNewInstance(const CMPIBroker* mb, const CMPIObjectPath* eCop, CMPIStatus *rc) { if (!eCop) { if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER); return NULL; } CIMObjectPath* cop=(CIMObjectPath*)eCop->hdl; if (!cop) { if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER); return NULL; } // cout<<"--- mbEncNewInstance() "<<cop->getClassName()<<"-"<<cop->getNameSpace()<<endl; CIMClass *cls=mbGetClass(mb,*cop); CIMInstance *ci=NULL; if (cls) { const CMPIContext *ctx=CMPI_ThreadContext::getContext(); CMPIFlags flgs=ctx->ft->getEntry(ctx,CMPIInvocationFlags,rc).value.uint32; CIMInstance newInst = cls->buildInstance( Boolean(flgs & CMPI_FLAG_IncludeQualifiers), false, CIMPropertyList()); ci = new CIMInstance(newInst); } else { if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND); return NULL; } ci->setPath(*cop); CMPIInstance* neInst=reinterpret_cast<CMPIInstance*>(new CMPI_Object(ci)); if (rc) CMSetStatus(rc,CMPI_RC_OK); // CMPIString *str=mbEncToString(mb,neInst,NULL); return neInst; } static CMPIObjectPath* mbEncNewObjectPath(const CMPIBroker* mb, const char *ns, const char *cls, CMPIStatus *rc) { // cout<<"--- mbEncNewObjectPath() "<<ns<<"-"<<cls<<endl; Array<CIMKeyBinding> keyBindings; String host; CIMName className; if (cls) className=Name(cls); else className=Name(""); CIMNamespaceName nameSpace; if (ns) nameSpace =NameSpaceName(ns); else nameSpace=NameSpaceName(""); CIMObjectPath *cop=new CIMObjectPath(host,nameSpace,className,keyBindings); CMPIObjectPath *nePath=reinterpret_cast<CMPIObjectPath*>(new CMPI_Object(cop)); if (rc) CMSetStatus(rc,CMPI_RC_OK); return nePath; } static CMPIArgs* mbEncNewArgs(const CMPIBroker* mb, CMPIStatus *rc) { if (rc) CMSetStatus(rc,CMPI_RC_OK); return reinterpret_cast<CMPIArgs*>(new CMPI_Object(new Array<CIMParamValue>())); } static CMPIString* mbEncNewString(const CMPIBroker* mb, const char *cStr, CMPIStatus *rc) { if (rc) CMSetStatus(rc,CMPI_RC_OK); if (cStr == NULL) return reinterpret_cast<CMPIString*>(new CMPI_Object((char*)NULL)); return reinterpret_cast<CMPIString*>(new CMPI_Object(cStr)); } CMPIString* mbIntNewString(const char *s) { return mbEncNewString(NULL,s,NULL); } CMPIArray* mbEncNewArray(const CMPIBroker* mb, CMPICount count, CMPIType type, CMPIStatus *rc) { if (rc) CMSetStatus(rc,CMPI_RC_OK); CMPIData *dta=new CMPIData[count+1]; dta->type=type; dta->value.uint32=count; for (unsigned int i=1; i<=count; i++) { dta[i].type=type; dta[i].state=CMPI_nullValue; dta[i].value.uint64=0; } return reinterpret_cast<CMPIArray*>(new CMPI_Object(dta)); } extern CMPIDateTime *newDateTime(); static CMPIDateTime* mbEncNewDateTime(const CMPIBroker* mb, CMPIStatus *rc) { // cout<<"--- mbEncNewDateTime()"<<endl; if (rc) CMSetStatus(rc,CMPI_RC_OK); return newDateTime(); } extern CMPIDateTime *newDateTimeBin(CMPIUint64,CMPIBoolean); static CMPIDateTime* mbEncNewDateTimeFromBinary(const CMPIBroker* mb, CMPIUint64 time, CMPIBoolean interval ,CMPIStatus *rc) { // cout<<"--- mbEncNewDateTimeFromBinary()"<<endl; if (rc) CMSetStatus(rc,CMPI_RC_OK); return newDateTimeBin(time,interval); } extern CMPIDateTime *newDateTimeChar(const char*); static CMPIDateTime* mbEncNewDateTimeFromString(const CMPIBroker* mb, const char *t ,CMPIStatus *rc) { // cout<<"--- mbEncNewDateTimeFromString()"<<endl; CMPIDateTime *date = NULL; if (rc) CMSetStatus(rc,CMPI_RC_OK); date=newDateTimeChar(t); if (!date) if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER); return date; }#if defined(CMPI_VER_200) extern CMPIError *newCMPIError(const char*, const char*, const char*, const CMPIErrorSeverity, const CMPIErrorProbableCause, const CMPIrc); static CMPIError* mbEncNewCMPIError (const CMPIBroker* mb, const char* owner, const char* msgID, const char* msg, const CMPIErrorSeverity sev, const CMPIErrorProbableCause pc, const CMPIrc cimStatusCode, CMPIStatus* rc) { CMPIError* cmpiError; if (rc) { CMSetStatus(rc,CMPI_RC_OK); } cmpiError = newCMPIError(owner, msgID, msg, sev, pc, cimStatusCode); if (!cmpiError) if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER); return cmpiError; }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -