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

📄 cqlfunctionrep.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    //printf("ClassName --> %s\n", (const char *)cqlVal.getObject().getClassName().getString().getCString());    return CQLValue(cqlVal.getObject().getClassName().getString());  }  // 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::nameSpaceName(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::nameSpaceName()");  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 beavior for this function will first look at the object path of the instance being examined (CI).  If the path contains a namespace, we will return it.  If it does not, then we will return the default namespace from the query context.  // *** NOTE ***  This does not function entirely according to the CQL spec.  The CQL spec says to return the namespace of the instance regardless if it is set or not.  However, with the current implementation (CQL phase 1 PEP 193) we only operate a query engine within a single namespace and so we can assume the default namespace.  if (parmSize == 0)  {    CIMNamespaceName ns = CI.getPath().getNameSpace();    if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))      ns = queryCtx.getNamespace();    PEG_METHOD_EXIT();    //printf("Namespace --> %s\n", (const char *)ns.getString().getCString());    return CQLValue(ns.getString());      }  // 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 get the namespace from the object path and return it.  If there is no namespace in the path given, then an empty string will be returned.  if (cqlVal.getValueType() == CQLValue::String_type)  {    CIMObjectPath objPath(cqlVal.getString());    PEG_METHOD_EXIT();    //printf("Namespace --> %s\n", (const char *)objPath.getNameSpace().getString().getCString());    return CQLValue(objPath.getNameSpace().getString());  }  // If we have a CIMReference parameter, then we will just get the namespace name from the reference and return it.  A refernce is a CIMObjectPath.  If there is no namespace in the path given, then an empty string will be returned.  if (cqlVal.getValueType() == CQLValue::CIMReference_type)  {    PEG_METHOD_EXIT();    //printf("Namespace --> %s\n", (const char *)cqlVal.getReference().getNameSpace().getString().getCString());    return CQLValue(cqlVal.getReference().getNameSpace().getString());  }  // If we have a CIMObject, then we retrieve the path of the obejct and check to see if it has a namespace set in it.  If the path contains a namespace, we will return it.  If it does not, then we will return the default namespace from the query context.  // *** NOTE ***  This does not function entirely according to the CQL spec.  The CQL spec says to return the namespace of the instance regardless if it is set or not.  However, with the current implementation (CQL phase 1 PEP 193) we only operate a query engine within a single namespace and so we can assume the default namespace.   if (cqlVal.getValueType() == CQLValue::CIMObject_type)  {    CIMNamespaceName ns = cqlVal.getObject().getPath().getNameSpace();    if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))      ns = queryCtx.getNamespace();    PEG_METHOD_EXIT();    //printf("Namespace --> %s\n", (const char *)ns.getString().getCString());    return CQLValue(ns.getString());  }    // 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::nameSpaceType(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::nameSpaceType()");  // This is currently (as of CQL Phase 1, PEP 193) not supported in Pegasus since Pegasus does not yet support WEBM URI references.  Nothing in the current object path can be used to represent the name space type (i.e. the protocol).  MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                           String("Function $0 is not supported."),                           functionTypeToString());  throw CQLRuntimeException(mload);  PEGASUS_UNREACHABLE(  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);  }    PEG_METHOD_EXIT();  return CQLValue(Uint64(0));  ) // End PEGASUS_UNREACHABLE}CQLValue CQLFunctionRep::hostPort(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::hostPort()");  // Pegasus currently (as of CQL Phase 1, PEP 193) does not support WEBM URI references, however the current object path dose have a host on it which we will return.  Until Pegasus supportse WEBM URI, it is not guaranteed that this will onform to the format defined in WBEM URI, and therefore this function is not entirely in accordance with the CQL Specification.  // In addition, the CQL specification allows for the parameter to be left off when the query is executed as a result  of an ExecuteQuery operation.  However, right now (as of CQL Phase 1, PEP 193) we are only using this for Indications, and so we are assuming a "Mode" of operation.  For this function to be completely compliant with the CQL specification, it will eventually need to be "mode" aware.    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);  }  // 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 get the host from the object path and return it.  If there is no host in the path given, then an empty string will be returned.  if (cqlVal.getValueType() == CQLValue::String_type)  {    CIMObjectPath objPath(cqlVal.getString());    PEG_METHOD_EXIT();    //printf("HostPort -> %s\n", (const char *)objPath.getHost().getCString());    return CQLValue(objPath.getHost());  }  // If we have a CIMReference parameter, then we will just get the host name from the reference and return it.  A reference is a CIMObjectPath.  If there is no host in the path given, then an empty string will be returned.  if (cqlVal.getValueType() == CQLValue::CIMReference_type)  {    PEG_METHOD_EXIT();    //printf("HostPort -> %s\n", (const char *)cqlVal.getReference().getHost().getCString());    return CQLValue(cqlVal.getReference().getHost());  }  // If we have a CIMObject, then we retrieve the path of the obejct and return the host from the path.  If there is no host in the path given, then an empty string will be returned.  if (cqlVal.getValueType() == CQLValue::CIMObject_type)  {    PEG_METHOD_EXIT();    //printf("HostPort -> %s\n", (const char *)cqlVal.getObject().getPath().getHost().getCString());    return CQLValue(cqlVal.getObject().getPath().getHost());  }  // 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::modelPath(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::modelPath()");  // This method returns the model path portion of an object path.  The model path is the class name and the key bindings (if included)..    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 then return the model path from that.  if (parmSize == 0)  {    PEG_METHOD_EXIT();    return buildModelPath(CI.getPath());  }  // 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 get model path from the object path and return it.  if (cqlVal.getValueType() == CQLValue::String_type)  {    CIMObjectPath objPath(cqlVal.getString());    PEG_METHOD_EXIT();    return buildModelPath(objPath);  }  // If we have a CIMReference parameter, then we will get the model path from the reference and return it.  A reference is a CIMObjectPath.  if (cqlVal.getValueType() == CQLValue::CIMReference_type)  {    PEG_METHOD_EXIT();    return buildModelPath(cqlVal.getReference());  }  // If we have a CIMObject, then we retrieve the path of the obejct and return the model path.  if (cqlVal.getValueType() == CQLValue::CIMObject_type)  {    PEG_METHOD_EXIT();    return buildModelPath(cqlVal.getObject().getPath());  }  // 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::buildModelPath(const CIMObjectPath& objPath) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::buildModelPath()");  // This method will take an existing objet path, pick out the key bindings and the class name, and use those parts to build a new object path with just those parts in it.  This is used to represent the model path.  CIMObjectPath newPath;  newPath.setClassName(objPath.getClassName());  newPath.setKeyBindings(objPath.getKeyBindings());  //printf("ModelPath --> %s\n", (const char *)newPath.toString().getCString());    PEG_METHOD_EXIT();  return CQLValue(newPath.toString());}CQLValue CQLFunctionRep::classPath(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::classPath()");  // This method returns a class path.  The class path will only have a namespace and a class name in it.  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 class 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 buildClassPath(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 class 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 buildClassPath(objPath, objPath.getNameSpace());  }  // If we have a CIMReference parameter, then we will build the class 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 buildClassPath(objPath, objPath.getNameSpace());  }  // If we have a CIMObject, then we retrieve the object path  and build the class 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 buildClassPath(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::buildClassPath(const CIMObjectPath& objPath, const CIMNamespaceName& ns) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::buildClassPath()");  // This method will take the object path pass in and pick out the host, the class name and the namespace.  The 2 parts are then combined together into a new object path which will be used as the class path and returned.  CIMObjectPath newPath;  newPath.setHost(objPath.getHost());  newPath.setClassName(objPath.getClassName());    newPath.setNameSpace(ns);

⌨️ 快捷键说明

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