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

📄 cqlcli.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    CIMPropertyList propList;    for(Uint32 i = 0; i < _statements.size(); i++)    {      cout << "======================================" << i << endl;      cout << _statements[i].toString() << endl;      try      {        cout << endl << "Get Class Path List" << endl;        Array<CIMObjectPath> fromPaths = _statements[i].getClassPathList();        for (Uint32 k = 0; k < fromPaths.size(); k++)        {          cout << "-----" << fromPaths[k].toString() << endl;        }      }      catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}      catch(...){ cout << "Unknown Exception" << endl;}      try      {             cout << "SELECT Chained Identifiers" << endl;        Array<CQLChainedIdentifier> selIds = _statements[i].getSelectChainedIdentifiers();        for (Uint32 k = 0; k < selIds.size(); k++)        {          cout << "-----" << selIds[k].toString() << endl;        }      }      catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}      catch(...){ cout << "Unknown Exception" << endl;}      try      {             cout << "WHERE Chained Identifiers" << endl;        Array<CQLChainedIdentifier> whereIds = _statements[i].getWhereChainedIdentifiers();        if (whereIds.size() == 0)        {          cout << "-----none" << endl;         }        for (Uint32 k = 0; k < whereIds.size(); k++)        {          cout << "-----" << whereIds[k].toString() << endl;        }      }      catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}      catch(...){ cout << "Unknown Exception" << endl;}      try      {        cout << "Property List for the FROM class " << endl;        propList.clear();        propList = _statements[i].getPropertyList();        _printPropertyList(propList);      }      catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}      catch(...){ cout << "Unknown Exception" << endl;}      try      {        cout << "SELECT Property List for the FROM class " << endl;        propList.clear();        propList = _statements[i].getSelectPropertyList();        _printPropertyList(propList);      }      catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}      catch(...){ cout << "Unknown Exception" << endl;}      try      {        cout << "WHERE Property List for the FROM class " << endl;        propList.clear();        propList = _statements[i].getWherePropertyList();        _printPropertyList(propList);      }      catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}      catch(...){ cout << "Unknown Exception" << endl;}      // Build a list of unique class names from the instances      Array<CIMName> classNames;      for(Uint32 j = 0; j < _instances.size(); j++)      {        Boolean found = false;        for(Uint32 k = 0; k < classNames.size(); k++)        {          if (_instances[j].getClassName() == classNames[k])          {            found = true;          }        }        if (!found)        {          classNames.append(_instances[j].getClassName());        }      }      for(Uint32 j = 0; j < classNames.size(); j++)      {        CIMName className = classNames[j];        CIMObjectPath classPath (String::EMPTY,                                 ns,                                 className);        try        {          cout << "Property List for " << className.getString() << endl;          propList.clear();          propList = _statements[i].getPropertyList(classPath);          _printPropertyList(propList);        }        catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}        catch(...){ cout << "Unknown Exception" << endl;}        try        {               cout << "SELECT Property List for " << className.getString() << endl;          propList.clear();          propList = _statements[i].getSelectPropertyList(classPath);          _printPropertyList(propList);        }        catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}        catch(...){ cout << "Unknown Exception" << endl;}        try        {          cout << "WHERE Property List for " << className.getString() << endl;          propList.clear();          propList = _statements[i].getWherePropertyList(classPath);          _printPropertyList(propList);        }        catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}        catch(...){ cout << "Unknown Exception" << endl;}      }    }                           }	  return true;}Boolean _evaluate(Array<CQLSelectStatement>& _statements,                  Array<CIMInstance>& _instances,                  String testOption){  // Not liking how the mof compiler is working with CQL_TestPropertyTypes,   // so I am going to hack the instances so that they have the values  // I need for the function tests.  hackInstances(_instances);    if(testOption == String::EMPTY || testOption == "1")  {             cout << "=========Evaluate Query==============" << endl;                                 for(Uint32 i = 0; i < _statements.size(); i++)    {      cout << "=========     " << i << "     =========" << endl;      cout << "-----Query: " << getStatementString(_statements[i].toString()) << endl << endl;;      for(Uint32 j = 0; j < _instances.size(); j++)      {        try        {          cout << "-----Instance: " << _instances[j].getPath().toString() << endl;          Boolean result = _statements[i].evaluate(_instances[j]);          if(cqlcli_verbose)          {            cout << "Inst # " << j << ": " <<  _statements[i].toString() << " = ";          }          if(result) cout << "TRUE" << endl;          else cout << "FALSE" << endl;        }        catch(Exception e)        {          if (cqlcli_verbose)            cout << "ERROR! -- " << _statements[i].toString() << endl << e.getMessage() << endl << endl;          else            cout << "ERROR!" << endl << e.getMessage() << endl << endl;        }        catch(...){ cout << "Unknown Exception" << endl;}      }    }  }  return true;}Boolean _normalize(Array<CQLSelectStatement>& _statements,                    Array<CIMInstance>& _instances,                   String testOption){  if(testOption == String::EMPTY || testOption == "5")  {    cout << "=========Normalize Results==============" << endl;    for(Uint32 i = 0; i < _statements.size(); i++)    {      cout << "======================================" << i << endl;      try      {        cout << "-----Statement before normalize" << endl;        _statements[i].applyContext();        cout << _statements[i].toString() << endl;        _statements[i].normalizeToDOC();        cout << "-----Statement after normalize" << endl;        cout << _statements[i].toString() << endl;        cout << "-----Traversing the predicates" << endl;        CQLPredicate topPred = _statements[i].getPredicate();        if (topPred.isSimple())        {          cout << "-----Top predicate is simple: " << topPred.toString() << endl;        }        else        {          cout << "-----Top predicate is not simple: " << topPred.toString() << endl;			 if( topPred.getInverted() )			 	cout << "-----ERROR - Top predicate is inverted: " << topPred.toString() << endl;          Array<CQLPredicate> secondLevelPreds = topPred.getPredicates();          for (Uint32 n = 0; n < secondLevelPreds.size(); n++)          {            if (secondLevelPreds[n].isSimple())            {              cout << "-----2nd level predicate is simple: "                   << secondLevelPreds[n].toString() << endl;            }            else            {				  if( secondLevelPreds[n].getInverted() )				  	cout << "-----ERROR - 2nd level predicate is inverted: " << secondLevelPreds[n].toString() << endl;              cout << "-----ERROR - 2nd level predicate is NOT simple!: "                    << secondLevelPreds[n].toString() << endl;            }          }        }      }      catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}      catch(...){ cout << "Unknown Exception" << endl;}    }  }  return true;                                                                                        }void buildEmbeddedObjects(CIMNamespaceName& ns,                          Array<CIMInstance>& instances,                          CIMRepository* rep){  //  // Sort out the instances of CQL_TestElement, CQL_TestPropertyTypes,  // CIM_ComputerSystem that will be added as embedded objects to  // the embedded object test class  //  CIMName nameTE("CQL_TestElement");  CIMName instIdName("InstanceId");  CIMName nameTPT("CQL_TestPropertyTypes");  CIMName nameCS("CIM_ComputerSystem");  CIMInstance testElem;  Array<CIMObject> testElemArray;  Boolean foundTestElem = false;  CIMInstance testCS;  Boolean foundCS = false;  Array<CIMObject> testPropTypesArray;  for (Uint32 i = 0; i < instances.size(); i++)  {    // Find the CQL_TestElement with InstanceId = 0    if (instances[i].getClassName() == nameTE)    {      Uint32 index = instances[i].findProperty(instIdName);      if (index == PEG_NOT_FOUND)      {        throw Exception("Error building embedded objects.  CQL_TestElement with InstanceId prop not found");      }            Uint64 instId;      instances[i].getProperty(index).getValue().get(instId);      if (instId == 0)      {        // Found the CQL_TestElement with InstanceId = 0.        // Change to InstanceId to 10, and save it.        foundTestElem = true;        instances[i].removeProperty(index);        instances[i].addProperty(CIMProperty(instIdName, CIMValue((Uint64)10)));        testElem = instances[i].clone();      }    }    // Save the CQL_TestPropertyType instances as we find them    if (instances[i].getClassName() == nameTPT)    {      testPropTypesArray.append(instances[i].clone());    }    // Save the CIM_ComputerSystem instance    if (instances[i].getClassName() == nameCS)    {      foundCS = true;      testCS = instances[i].clone();      // Remove the PrimaryOwnerName property so that apply projection      // using the wildcard will fail      Uint32 tmpIdx = testCS.findProperty("PrimaryOwnerName");      if (tmpIdx != PEG_NOT_FOUND)      {        testCS.removeProperty(tmpIdx);      }    }  }  if (!foundTestElem)  {    throw Exception("Error building embedded objects.  CQL_TestElement with InstanceId = 0 not found");  }  if (!foundCS)  {    throw Exception("Error building embedded objects.  CIM_ComputerSystem not found");  }  if (testPropTypesArray.size() <= 1)  {    throw Exception("Error building embedded objects. Not enough CQL_TestPropertyTypes found");  }  //  // Now build the array of CQL_TestElement (see below for why we are doing this)  //   testElemArray.append(testElem.clone());  Uint32 index = testElem.findProperty(instIdName);  testElem.removeProperty(index);  testElem.addProperty(CIMProperty(instIdName, CIMValue((Uint64)11)));  testElemArray.append(testElem.clone());  index = testElem.findProperty(instIdName);  testElem.removeProperty(index);  testElem.addProperty(CIMProperty(instIdName, CIMValue((Uint64)12)));  testElemArray.append(testElem.clone());  //  // Get the class that will be added as an embedded object  //  CIMClass someClass = rep->getClass(ns,                                     "CIM_Process",                                     false,  // local only                                     true,   // include quals                                     true);   // include class origin  // Build the embedded object structure.  //  // The structure looks like this:  //  // class CQL_EmbeddedSubClass is subclass of CQL_EmbeddedBase  // class CQL_EmbeddedTestPropertyTypes is subclass of CQL_EmbeddedTestElement  //  // instance of CQL_EmbeddedSubClass   //  //   property InstanceID has value 100  //  //   property EmbObjBase has  //      instance of CQL_EmbeddedTestElement  //         property InstanceID has value 1000  //         property TEArray has array of instance of CQL_TestElement  //             the array elements have InstanceID properties  //             set to 10, 11, 12  //         property TE has instance of CQL_TestElement  //             property InstanceID has value 10  //         property CS has instance of CIM_ComputerSystem  //             note that the PrimaryOwnerName property is removed  //         property SomeClass has class of CIM_Process  //         property SomeString has a string  //     //   property EmbObjSub has

⌨️ 快捷键说明

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