📄 cqlfunctionrep.cpp
字号:
// printf("ClassPath --> %s\n", (const char *)newPath.toString().getCString()); PEG_METHOD_EXIT(); return CQLValue(newPath);}CQLValue CQLFunctionRep::objectPath(const CIMInstance& CI, const QueryContext& queryCtx) const{ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::objectPath()"); // This method returns an object path. The object path will only have a namespace, a class name, and key bindings if it is a path to an instance. All other path information will be stripped off. int parmSize = _parms.size(); if(parmSize != 0 && parmSize != 1) { char buf[10]; sprintf(buf, "%d", _parms.size()); MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"), String("Function $0 has $1 parameters. It must have between $2 and $3."), functionTypeToString(), String(buf), String("0"), String("1")); throw CQLRuntimeException(mload); } // The default behavior for this function will be to retrieve the object path from the instance being examined (CI) and build the object path from it. If the path does not have a namespace, then the default namespace is used. if (parmSize == 0) { CIMObjectPath objPath(CI.getPath()); CIMNamespaceName ns = objPath.getNameSpace(); if (ns.isNull() || String::equal(ns.getString(), String::EMPTY)) ns = queryCtx.getNamespace(); PEG_METHOD_EXIT(); return buildObjectPath(objPath, ns); } // We have a parameter, so resolve it first before we use it. CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx); // If we have a String parameter, then we'll use it to create a CIMObjectPath in order to verify the format is correct. We will then build the object path from the object path and return it. If the namespace is NOT set in the object path, it will remain unset in the returned reference. if (cqlVal.getValueType() == CQLValue::String_type) { CIMObjectPath objPath(cqlVal.getString()); PEG_METHOD_EXIT(); return buildObjectPath(objPath, objPath.getNameSpace()); } // If we have a CIMReference parameter, then we will build the object path from the reference and return it. If the namespace is NOT set in the object path, it will remain unset in the returned reference. if (cqlVal.getValueType() == CQLValue::CIMReference_type) { CIMObjectPath objPath = cqlVal.getReference(); PEG_METHOD_EXIT(); return buildObjectPath(objPath, objPath.getNameSpace()); } // If we have a CIMObject, then we retrieve the object path of the obejct and build the object path from it. If the path does not have a namespace, then the default namespace is used. if (cqlVal.getValueType() == CQLValue::CIMObject_type) { CIMObjectPath objPath = cqlVal.getObject().getPath(); CIMNamespaceName ns = objPath.getNameSpace(); if (ns.isNull() || String::equal(ns.getString(), String::EMPTY)) ns = queryCtx.getNamespace(); PEG_METHOD_EXIT(); return buildObjectPath(objPath, ns); } // If it makes it to this block of code, then no valid type was found, and hence no return was made. Throw invalid parameter type exception. { MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"), String("Parameter $0 for function $1 has type $2. It must be type $3."), String("1"), functionTypeToString(), CQLValueRep::valueTypeToString(cqlVal.getValueType()), String("Reference, String, or Object")); throw CQLRuntimeException(mload); }}CQLValue CQLFunctionRep::buildObjectPath(const CIMObjectPath& objPath, const CIMNamespaceName& ns) const{ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::buildObjectPath()"); // This method will take the object path passed in and pick out the host, the class name, the namespace, and the key bindings. The parts are then combined together into a new object path which will be used as the object path and returned. CIMObjectPath newPath; newPath.setHost(objPath.getHost()); newPath.setClassName(objPath.getClassName()); newPath.setNameSpace(ns); newPath.setKeyBindings(objPath.getKeyBindings()); // printf("ObjectPath --> %s\n", (const char *)newPath.toString().getCString()); PEG_METHOD_EXIT(); return CQLValue(newPath);}CQLValue CQLFunctionRep::instanceToReference(const CIMInstance& CI, const QueryContext& queryCtx) const{ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::instanceToReference()"); // The parameter to this function MUST be an instance object. We will use buildPath on the instance to make the path. If there is no namespace on the instance, then the default namespace will be inserted. The completed path is then returned. Note, this could, and should be a more complete reference than the other path functions. int parmSize = _parms.size(); if(parmSize != 0 && parmSize != 1) { char buf[10]; sprintf(buf, "%d", _parms.size()); MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"), String("Function $0 has $1 parameters. It must have between $2 and $3."), functionTypeToString(), String(buf), String("0"), String("1")); throw CQLRuntimeException(mload); } CIMInstance *inst = NULL; Boolean cleanup = false; // whether or not to delete the memory CIMObject obj; // The default behavior is to use the instance being examined as the source instance (CI). if (parmSize == 0) inst = (CIMInstance *)&CI; else { // We have a parameter, so resolve it first before we use it. CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx); // Parameter MUST be an instance object if (cqlVal.getValueType() != CQLValue::CIMObject_type) { MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"), String("Parameter $0 for function $1 has type $2. It must be type $3."), String("1"), functionTypeToString(), CQLValueRep::valueTypeToString(cqlVal.getValueType()), CQLValueRep::valueTypeToString(CQLValue::CIMObject_type)); throw CQLRuntimeException(mload); } // REVIEW question. Inefficient since the CIMobject is copied via the return by value, then it is copied again via the assignment. Is there a better way to handle this? obj = cqlVal.getObject(); if (!obj.isInstance()) { MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_OBJECT_TYPE"), String("Parameter $0 for function $1 must be a CIM instance."), String("1"), functionTypeToString()); throw CQLRuntimeException(mload); } // Make a CIM Instance inst = new CIMInstance(obj); cleanup = true; } // Get the class and build the path CIMConstClass cls = queryCtx.getClass(inst->getClassName()); CIMObjectPath objPath = inst->buildPath(cls); CIMNamespaceName ns = objPath.getNameSpace(); if (ns.isNull() || String::equal(ns.getString(), String::EMPTY)) objPath.setNameSpace(queryCtx.getNamespace()); if (cleanup) { delete inst; inst = NULL; } PEG_METHOD_EXIT(); return CQLValue(objPath);}CQLValue CQLFunctionRep::currentDateTime() const{ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::currentDateTime()"); if(_parms.size() != 0) { char buf[10]; sprintf(buf, "%d", _parms.size()); MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"), String("Function $0 has $1 parameters. It must have between $2 and $3."), functionTypeToString(), String(buf), String("0"), String("0")); throw CQLRuntimeException(mload); } PEG_METHOD_EXIT(); return(CQLValue(CIMDateTime::getCurrentDateTime()));}CQLValue CQLFunctionRep::dateTime(const CIMInstance& CI, const QueryContext& queryCtx) const{ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::dateTime()"); if(_parms.size() != 1) { char buf[10]; sprintf(buf, "%d", _parms.size()); MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"), String("Function $0 has $1 parameters. It must have between $2 and $3."), functionTypeToString(), String(buf), String("1"), String("1")); throw CQLRuntimeException(mload); } CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx); if(cqlVal.getValueType() != CQLValue::String_type) { MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"), String("Parameter $0 for function $1 has type $2. It must be type $3."), String("1"), functionTypeToString(), CQLValueRep::valueTypeToString(cqlVal.getValueType()), CQLValueRep::valueTypeToString(CQLValue::String_type)); throw CQLRuntimeException(mload); } CIMDateTime dt(cqlVal.getString()); PEG_METHOD_EXIT(); return(CQLValue(dt));}CQLValue CQLFunctionRep::microsecondToTimestamp(const CIMInstance& CI, const QueryContext& queryCtx) const{ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::microsecondToTimestamp()"); if(_parms.size() != 1) { char buf[10]; sprintf(buf, "%d", _parms.size()); MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"), String("Function $0 has $1 parameters. It must have between $2 and $3."), functionTypeToString(), String(buf), String("1"), String("1")); throw CQLRuntimeException(mload); } CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx); CQLValue::CQLValueType valType = cqlVal.getValueType(); if(valType != CQLValue::Uint64_type && valType != CQLValue::Sint64_type) { MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"), String("Parameter $0 for function $1 has type $2. It must be type $3."), String("1"), functionTypeToString(), CQLValueRep::valueTypeToString(cqlVal.getValueType()), String("Integer")); throw CQLRuntimeException(mload); } Uint64 uIntVal = 0; if (valType == CQLValue::Sint64_type) { Sint64 intVal = cqlVal.getSint(); if (intVal < 0) { char negVal[100]; sprintf(negVal, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", intVal); MessageLoaderParms mload(String("CQL.CQLFunctionRep.NEGATIVE_INT_ERROR"), String("Parameter $0 for function $1 has a value of $2. It must be non-negative."), String("1"), functionTypeToString(), String(negVal)); throw CQLRuntimeException(mload); } uIntVal = intVal; } else uIntVal = cqlVal.getUint(); PEG_METHOD_EXIT(); return CQLValue(CIMDateTime(uIntVal, false));}CQLValue CQLFunctionRep::microsecondToInterval(const CIMInstance& CI, const QueryContext& queryCtx) const{ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::microsecondToInterval()"); if(_parms.size() != 1) { char buf[10]; sprintf(buf, "%d", _parms.size()); MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"), String("Function $0 has $1 parameters. It must have between $2 and $3."), functionTypeToString(), String(buf), String("1"), String("1")); throw CQLRuntimeException(mload); } CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx); CQLValue::CQLValueType valType = cqlVal.getValueType(); if(valType != CQLValue::Uint64_type && valType != CQLValue::Sint64_type) { MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"), String("Parameter $0 for function $1 has type $2. It must be type $3."), String("1"), functionTypeToString(), CQLValueRep::valueTypeToString(cqlVal.getValueType()), String("Integer")); throw CQLRuntimeException(mload); } Uint64 uIntVal = 0; if (valType == CQLValue::Sint64_type) { Sint64 intVal = cqlVal.getSint(); if (intVal < 0) { char negVal[100]; sprintf(negVal, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", intVal); MessageLoaderParms mload(String("CQL.CQLFunctionRep.NEGATIVE_INT_ERROR"), String("Parameter $0 for function $1 has a value of $2. It must be non-negative."), String("1"), functionTypeToString(), String(negVal)); throw CQLRuntimeException(mload); } uIntVal = intVal; } else uIntVal = cqlVal.getUint(); PEG_METHOD_EXIT(); return CQLValue(CIMDateTime(uIntVal, true)); }PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -