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

📄 cimpls.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  Array<CIMObjectPath> iNames;   try  {    iNames = _c.enumerateInstanceNames( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );  }  catch(Exception& e)  {    cerr << /* "enumerateInstanceNames: " << */ e.getMessage() << endl;    return 1;  }  cerr << iNames.size() << " instance(s)" << endl;  for (int i=0; i<iNames.size(); i++)    cout << "  " << iNames[i].toString() << endl;  return 0;}// ===============================================================// getProperty// ===============================================================int _getProperty(const int argc, const char **argv){  // need to get class definition to find keys  // first arg is name of class  CIMClass cldef;  try  {    cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );  }  catch(Exception& e)  {    cerr << /* "getProperty: " << */ e.getMessage() << endl;    return 1;  }  CIMObjectPath ref;  CIMInstance inst;  // If next arg is "ask", prompt user for keys  if (String::equalNoCase("ask",argv[1])) ref = CIMObjectPath(String::EMPTY,                                                   PEGASUS_NAMESPACENAME_INTEROP,                                                   argv[0],                                                   _inputInstanceKeys(cldef) );  // else if the next arg and is "list", enumInstNames and print  // a list from which user will select    else if (String::equalNoCase("list",argv[1]))  {    ref = _selectInstance( argv[0] );    if (ref.identical(CIMObjectPath())) return 0;  }  // else there's another arg but it's invalid  else  {    return 1;  }  CIMProperty pDef;  // if no more args, display property names and ask which  if (argc < 3)  {    int n;    for (n=0; n<cldef.getPropertyCount(); n++)      cerr << n+1 << ": " << cldef.getProperty(n).getName().getString() << endl;    cerr << "Property (1.." << cldef.getPropertyCount() << ")? ";    cin >> n;    pDef = cldef.getProperty(n-1);  }  // else use last arg as property to get  else  {    int pos = cldef.findProperty(argv[2]);    if (pos == PEG_NOT_FOUND)    {      cerr << argv[2] << ": not found." << endl;      return 1;    }    pDef = cldef.getProperty(pos);  }  // Now we can call getProperty() and display result  CIMValue v;  try  {    v = _c.getProperty( PEGASUS_NAMESPACENAME_INTEROP, ref, pDef.getName() );  }  catch (Exception &e)  {    cerr << /* "getProperty: " << */ e.getMessage() << endl;    return 1;  }  cout << "  " << pDef.getName().getString();    if (v.isArray()) cout << "[" << v.getArraySize() << "]";  if (v.isNull()) cout << "=NULL";  else cout << "=" << "\"" << v.toString() << "\"";  cout << endl;  return 0;}// ===============================================================// deleteClass// ===============================================================int _deleteClass(const int argc, const char **argv){  CIMClass cldef;  try  {    _c.deleteClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );  }  catch (Exception& e)  {    cerr << /* "deleteClass: " << */ e.getMessage() << endl;    return 1;  }  return 0;}// ===============================================================// deleteInstance// ===============================================================int _deleteInstance(const int argc, const char **argv){  // need to get class definition to find keys  // first arg is name of class  CIMClass cldef;  try  {    cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );  }  catch(Exception& e)  {    cerr << /* "deleteInstance: " << */ e.getMessage() << endl;    return 1;  }  CIMObjectPath ref;  CIMInstance inst;  // If there are no more args, prompt user for keys  if (argv[1] == 0) ref = CIMObjectPath(String::EMPTY, // hostname left blank                                       PEGASUS_NAMESPACENAME_INTEROP,                                       argv[0],                                       _inputInstanceKeys(cldef));    // else if there's another arg and it's "list", enumInstNames and print  // a list from which user will select (return if none)  else if (String::equalNoCase("list",argv[1]))  {    ref = _selectInstance(argv[0]);    // An empty ObjectPath means nothing was selected    if (ref.identical(CIMObjectPath())) return 0;  }      // else there's another arg but it's invalid  else  {    return 1;  }  // delete the specified instance  try  {    _c.deleteInstance(PEGASUS_NAMESPACENAME_INTEROP,ref);  }  catch(Exception& e)  {    cerr << /* "deleteInstance: " << */ e.getMessage() << endl;    return 1;  }  return 0;}// ===============================================================// Auxiliary function _inputInstanceKeys()//// Prompt user for values of key properties of specified class// ===============================================================Array<CIMKeyBinding> _inputInstanceKeys(const CIMClass &cldef){  Array<CIMKeyBinding> kb;  for (int i=0; i<cldef.getPropertyCount(); i++)  {    CIMProperty prop = cldef.getProperty(i).clone();    if (_isKey(prop))    {      char s[256];      cout << prop.getName().getString() << " (" << cimTypeToString(prop.getType()) << "): ";      cin.getline(s,sizeof(s));      enum CIMKeyBinding::Type t;      switch (prop.getType())      {      case CIMTYPE_BOOLEAN:        t = CIMKeyBinding::BOOLEAN; break;      case CIMTYPE_UINT8:      case CIMTYPE_SINT8:      case CIMTYPE_UINT16:      case CIMTYPE_SINT16:      case CIMTYPE_UINT32:      case CIMTYPE_SINT32:      case CIMTYPE_UINT64:      case CIMTYPE_SINT64:      case CIMTYPE_REAL32:      case CIMTYPE_REAL64:        t = CIMKeyBinding::NUMERIC; break;      case CIMTYPE_STRING:      case CIMTYPE_DATETIME:      default:        t = CIMKeyBinding::STRING; break;      case CIMTYPE_REFERENCE:        t = CIMKeyBinding::REFERENCE; break;      }      kb.append(CIMKeyBinding(prop.getName(), s, t));    }  }  return kb;}// ===============================================================// Auxiliary function _selectInstance()//// Display list of instance names and ask which// ===============================================================CIMObjectPath _selectInstance(const String &clnam){  // Get all the instance handles  Array<CIMObjectPath> iNames;  try  {    iNames = _c.enumerateInstanceNames(PEGASUS_NAMESPACENAME_INTEROP,clnam);  }  catch (Exception& e)  {    cerr << /* "enumerateInstanceNames: " << */ e.getMessage() << endl;    return CIMObjectPath();  }  if (iNames.size() == 0)  {    cerr << "No instances found." << endl;    return CIMObjectPath();  }  // Display them, numbered starting at 1  int i;  for (i=0; i<iNames.size(); i++)    cerr << i+1 << ": " << iNames[i].toString() << endl;  i = 0;  // Ask user to pick one  while (i < 1 || i > iNames.size())  {    cerr << "Instance (1.." << iNames.size() << ")? ";    cin >> i;  }  return iNames[i-1];}// ===============================================================// Auxiliary function _displayInstance()//// Print property names and values// ===============================================================void _displayInstance(CIMInstance &inst){  for (int j=0; j<inst.getPropertyCount(); j++)    _displayProperty(inst.getProperty(j));}// ===============================================================// Auxiliary function _displayProperty()// ===============================================================void _displayProperty(const CIMProperty &p){  cout << "  " << p.getName().getString();    CIMValue v = p.getValue();  if (v.isArray())    cout << "[" << v.getArraySize() << "]";  cout << " = ";  if (v.isNull())    cout << "NULL";  else if (v.getType() == CIMTYPE_STRING ||           v.getType() == CIMTYPE_CHAR16 ||           v.getType() == CIMTYPE_DATETIME)    cout << "\"" << v.toString() << "\"";  else    cout << v.toString();  cout << endl;}// ===============================================================// Auxiliary function _isKey()// ===============================================================const Boolean _isKey(const CIMProperty &p){  int i;  if ( (i=p.findQualifier("key")) == PEG_NOT_FOUND )    return false;  CIMValue v = p.getQualifier(i).getValue();  if (v.isNull())    return false;  Boolean isKey;  v.get(isKey);  if (isKey)    return true;  else    return false;}

⌨️ 快捷键说明

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