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

📄 cimpls.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%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.////==============================================================================//// Author: Mike Glantz, Hewlett-Packard Company (michael_glantz@hp.com)////%/////////////////////////////////////////////////////////////////////////////#include "Cimpls.h"#include <iostream>#include <unistd.h>#include <stdlib.h>static const int TIMEOUT = 20000;static CIMClient _c;static String _nameSpace("root/PG_InterOp");static String _providerType[] = { "Unknown", "Other", "Instance",  "Association", "Indication", "Method" };static String _providerState[] = {"Unknown", "Other", "OK",  "Degraded", "Stressed", "Predictive Failure", "Error",  "Non-Recoverable Error", "Starting", "Stopping", "Stopped",  "In Service", "No Contact", "Lost Communication"};// ===============================================================// main// ===============================================================int main(const int argc, const char **argv){  // output looks like:  // PG_OperatingSystem  ///  Namespaces: root/cimv2  //   Provider:   PG_OperatingSystemProvider  //   Type:       Instance  //   Module:     OperatingSystemModule  //   File:       libOSProvider.sl  _c.setTimeout(20000);  // everything in big try/catch to display errors  try  {    _c.connectLocal();    // Start by enumerating PG_ProviderCapabilities    Array<CIMObjectPath> capRef =      _c.enumerateInstanceNames(PEGASUS_NAMESPACENAME_INTEROP, "PG_ProviderCapabilities");    for (int i=0; i<capRef.size(); i++)    {      // get the instance      CIMInstance cap = _c.getInstance(PEGASUS_NAMESPACENAME_INTEROP,capRef[i]);      // get referenced instance of PG_ProviderModule for later use      String pMod;      cap.getProperty(cap.findProperty("ProviderModuleName")).getValue().get(pMod);      CIMObjectPath modRef(String("PG_ProviderModule.Name=\"") + pMod + "\"");      CIMInstance mod = _c.getInstance(PEGASUS_NAMESPACENAME_INTEROP,modRef);      // display name of class instrumented      String className;      cap.getProperty(cap.findProperty("ClassName")).getValue().get(className);      cout << endl << className << endl;      // display namespaces      Array<String> nameSpaces;      cap.getProperty(cap.findProperty("Namespaces")).getValue().get(nameSpaces);      cout << "  Namespaces:";      for (int j=0; j<nameSpaces.size(); j++) cout << " " << nameSpaces[j];      cout << endl;            // display name of provider      String pName;      cap.getProperty(cap.findProperty("ProviderName")).getValue().get(pName);      cout << "  Provider:   " << pName << endl;      // display type of provider      Array<Uint16> pType;      cap.getProperty(cap.findProperty("ProviderType")).getValue().get(pType);      cout << "  Type:      ";      for (int j=0; j<pType.size(); j++)        cout << " " << _providerType[ pType[j] ];      cout << endl;            // display state      Array<Uint16> state;      mod.getProperty(mod.findProperty("OperationalStatus")).getValue().get(state);      cout << "  State:     ";      for (int j=0; j<state.size(); j++)        cout << " " << _providerState[ state[j] ];      cout << endl;            // display module      cout << "  Module:     " << pMod << endl;      // display file (PG_ProviderModule.Location)      String loc;      mod.getProperty(mod.findProperty("Location")).getValue().get(loc);      cout << "  File:       lib" << loc << ".sl" << endl;    }  }  catch (Exception &e)  {    cerr << e.getMessage() << endl;    return 1;  }  return 0;}// ===============================================================// getClass// ===============================================================int _getClass(const int argc, const char **argv){  CIMClass cldef;  try  {    cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );  }  catch (Exception& e)  {    cerr << /* "getClass: " << */ e.getMessage() << endl;    return 1;  }  // Display the class definition  // without qualifiers, for the moment  // First the class name and superclass  cout << "class " << cldef.getClassName().getString() << " : "    << cldef.getSuperClassName().getString() << endl;  cout << "{" << endl;    // Now the properties  // No qualifiers except [key], but specify type, array  for (int i=0; i<cldef.getPropertyCount(); i++)  {    CIMProperty p = cldef.getProperty(i);    cout << "  ";    // output key, if required    if (_isKey(p)) cout << "[ Key ] ";    // prepare to output type, but    // first, if type is "reference", find target class    if (p.getType() == CIMTYPE_REFERENCE)      cout << p.getReferenceClassName().getString() << " REF ";    // output type    else cout << cimTypeToString(p.getType()) << " ";    // output name    cout << p.getName().getString();    // output array, if required    if (p.isArray()) cout << "[]";    // final eol    cout << ";" << endl;  }    // need to do methods  for (int i=0; i<cldef.getMethodCount(); i++)  {    CIMMethod m = cldef.getMethod(i);    // output type    cout << "  " << cimTypeToString(m.getType()) << " ";    // output name    cout << m.getName().getString() << "(";    // output parameters    // new line if there are any parameters    for (int j=0; j<m.getParameterCount(); j++)    {      CIMParameter p = m.getParameter(j);      // output IN/OUT qualifiers on a fresh line      cout << endl << "    [ ";      // loop through qualifiers looking for IN, OUT      for (int k=0; k<p.getQualifierCount(); k++)      {        // when one found, output its value        CIMQualifier q = p.getQualifier(k);        if (q.getName().equal("in") ||            q.getName().equal("out"))        {          cout << q.getName().getString() << " ";        }      }      // Now the type      cout << "] " << cimTypeToString(p.getType()) << " ";      // finally the name      cout << p.getName().getString();      // array brackets      if (p.isArray()) cout << "[]";      // closing , on parameter if not last      if (j != m.getParameterCount()-1) cout << ",";    }    // after last param, indent before closing paren    // close paren    cout << ")";    // if (m.isArray()) cout << "[]";    // finish output    cout << ";" << endl;  }    // final brace and done  cout << "};" << endl;  return 0; }// ===============================================================// enumerateClassNames// ===============================================================int _enumerateClassNames(const int argc, const char **argv){  return 0;}// ===============================================================// getInstance// ===============================================================int _getInstance(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 << /* "getInstance: " << */ 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;  }  // get the specified instance  try  {    inst = _c.getInstance(PEGASUS_NAMESPACENAME_INTEROP,ref);  }  catch(Exception& e)  {    cerr << /* "getInstance: " << */ e.getMessage() << endl;    return 1;  }  _displayInstance(inst);  return 0;}// ===============================================================// enumerateInstances// ===============================================================int _enumerateInstances(const int argc, const char **argv){  Array<CIMInstance> ia;  try  {    ia = _c.enumerateInstances( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );  }  catch(Exception& e)  {    cerr << /* "enumerateInstances: " << */ e.getMessage() << endl;    return 1;  }    cerr << ia.size() << " instances" << endl;    for (int i=0; i<ia.size(); i++)  {    cout << endl;    // display property names and values    _displayInstance(ia[i]);  }  return 0;}// ===============================================================// enumerateInstanceNames// ===============================================================int _enumerateInstanceNames(const int argc, const char **argv){

⌨️ 快捷键说明

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