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

📄 cliclientlib.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        exit(1);    }    if (opts.verboseTest)    {        cout << "Name = " << key << ", Value= " << value << endl;    }    // ATTN: KS 20030423 P2 This is incomplete since it only allows us to do string input.    // We don't include the typing information.    //Array<String> valuePair = _tokenize(pair[1], ':');    //if (validType(valuePair[0] >= 0)    //{    //    //}    String tmp = value;    if (value.find('{') == 0)    {        // assume brace at first character position indictates an        // array value        tmp.remove(0,1);  // remove open brace        Array<String> arr;        while (tmp.size() != 0)        {            String token;            _nextParamToken(tmp, token);            arr.append(token);            // Now remove token separators (comma, brace or whitespace)            while ((tmp.size() > 0) &&                    ((tmp.find(",") == 0) || (tmp.find("}") == 0) ||                     (tmp.find(" ") == 0)))                tmp.remove(0,1);        }        CIMValue v(arr);        CIMParamValue pv(key, v);        return pv;    }    // Check for References starting with '[' and ending with ']'    if(tmp.find('[') == 0)    {        if(tmp.find(']') == tmp.size()-1)        {            Array<CIMKeyBinding> keys;            Array<String> arr;            String className;            tmp.remove(0,1);  // remove open bracket            // Iterate over the input param to extract class name,             // key names and values.            while(tmp.size() != 0)            {                String token, identifier, key;                _nextParamToken(tmp, token);                Uint32 dotIndex = 0, equalIndex = 0;                // Get the class name and key1/value1 from class.key = value                if (((dotIndex = token.find('.')) != PEG_NOT_FOUND)  &&                     (((equalIndex = token.find('=')) != PEG_NOT_FOUND) &&                        dotIndex < equalIndex-1))                {                    //extract class name, key1 and value1                    className = token.subString(0, dotIndex);                    identifier = token.subString(dotIndex+1,                                                  equalIndex-1-dotIndex);                    key = token.subString(equalIndex+1, token.size());                    keys.append(CIMKeyBinding(identifier, key,                                              CIMKeyBinding::STRING));                }                // Get the simple keyX = valueX (where X>1)                else if((equalIndex = token.find('=')) != PEG_NOT_FOUND)                {                    identifier = token.subString(0, equalIndex);                    key = token.subString(equalIndex+1, token.size());                    keys.append(CIMKeyBinding(identifier, key,                                              CIMKeyBinding::STRING));                }                else                {                    cout << " Error in the reference param this could be a string param" << endl;                    exit(1);                }                // Now remove token separators (comma, bracket or whitespace)                while((tmp.size() > 0) &&                       ((tmp.find(",") == 0) ||                        (tmp.find("]") == 0) ||                        (tmp.find(" ") == 0)))                {                    tmp.remove(0,1);                }            }            // Reference param specified is valid.             // Make CIM Object Path from the token.            CIMName cimclassName(className);            CIMObjectPath cop(String::EMPTY,CIMNamespaceName(opts.nameSpace),cimclassName,keys);            CIMValue v(cop);            CIMParamValue pv(key, v, false);            return pv;        }        else        {            cout <<"Treat this as String param " << input << endl;        }    }    // Fallthrough...    CIMValue v(value);    CIMParamValue pv(key, v, false);    return pv;}void outputFormatInstance(const OutputType format, CIMInstance& instance){    cout << "path= " << instance.getPath().toString() << endl;    if (format == OUTPUT_XML)        XmlWriter::printInstanceElement(instance, cout);    else if (format == OUTPUT_MOF)    {        // Reset the propagated flag to assure that these entities        // are all shown in the MOF output.        for (Uint32 i = 0 ; i < instance.getPropertyCount() ; i++)        {            CIMProperty p = instance.getProperty(i);            p.setPropagated(false);        }        Buffer x;        MofWriter::appendInstanceElement(x, instance);        x.append('\0');        mofFormat(cout, x.getData(), 4);    }}void outputFormatParamValue(const OutputType format, const CIMParamValue& pv){    if (format == OUTPUT_XML)        XmlWriter::printParamValueElement(pv, cout);    else if (format == OUTPUT_MOF)    {        if (!pv.isUninitialized())        {           CIMValue v =  pv.getValue();           CIMType type = v.getType();           if (pv.isTyped())               cout << cimTypeToString (type) << " ";           else               cout << "UnTyped ";           cout << pv.getParameterName() << "="                << v.toString() << endl;        }        else            cout << "ParamValue not initialized" << endl;    }    else        cout << "Error, Format Definition Error" << endl;}void outputFormatClass(const OutputType format, CIMClass& myClass){    if (format == OUTPUT_XML)        XmlWriter::printClassElement(myClass, cout);    else if (format == OUTPUT_MOF)    {        // Reset the propagated flag to assure that these entities        // are all shown in the MOF output.        for (Uint32 i = 0 ; i < myClass.getPropertyCount() ; i++)        {            CIMProperty p = myClass.getProperty(i);            p.setPropagated(false);        }        for (Uint32 i = 0 ; i < myClass.getMethodCount() ; i++)        {            CIMMethod m = myClass.getMethod(i);            m.setPropagated(false);        }        Buffer x;        MofWriter::appendClassElement(x, myClass);        x.append('\0');        mofFormat(cout, x.getData(), 4);    }    else        cout << "Error, Format Definition Error" << endl;}void outputFormatObject(const OutputType format, const CIMObject& myObject){    if (myObject.isClass())    {        CIMClass c(myObject);        outputFormatClass(format, c);    }    else if (myObject.isInstance())    {        CIMInstance i(myObject);        outputFormatInstance(format, i);    }    else        cout << "Error, Object is neither class or instance" << endl;}void outputFormatQualifierDecl(const OutputType format, const CIMQualifierDecl& myQualifierDecl){    if (format == OUTPUT_XML)        XmlWriter::printQualifierDeclElement(myQualifierDecl, cout);    else if (format == OUTPUT_MOF)    {        Buffer x;        MofWriter::appendQualifierDeclElement(x, myQualifierDecl);        x.append('\0');        mofFormat(cout, x.getData(), 4);    }    else    {        cout << "Format type error" << endl;    }}void outputFormatCIMValue(const OutputType format, const CIMValue& myValue){    if (format == OUTPUT_XML)    {        XmlWriter::printValueElement(myValue, cout);    }    else if (format == OUTPUT_MOF)    {        Buffer x;        MofWriter::appendValueElement(x, myValue);        x.append('\0');        mofFormat(cout, x.getData(), 4);    }    else    {        cout << " Format type error" << endl;    }}/////////////////////////////////////////////////////////////////////                                                               ////     The following section  defines each action function       ////     ex. getInstance. Parameters are defined in the            ////     opts structure.  There are not exception catches.         ////     exception handling is in the main path                    //////////////////////////////////////////////////////////////////////* This command searches the entire namespace and displays names of all instances.    It is in effect enumerate classes followed by enumerate instances.   The user may either provide a starting class or not, in which case   it searches the complete namespace, not simply the defined class.*/int enumerateAllInstanceNames(CIMClient& client, Options& opts){    if (opts.verboseTest)    {        cout << "EnumerateClasseNames "            << "Namespace = " << opts.nameSpace            << ", Class = " << opts.className            << ", deepInheritance = " << _toString(opts.deepInheritance)            << endl;    }    // Added to allow "" string input to represent NULL CIMName.    CIMName myClassName = CIMName();    /****if (opts.className != "")    {        myClassName = opts.className;    }*/    Array<CIMName> classNames;    if (opts.time)    {        opts.elapsedTime.reset();        opts.elapsedTime.start();    }    classNames = client.enumerateClassNames(opts.nameSpace,                                        opts.className,                                        opts.deepInheritance);    for (Uint32 iClass = 0; iClass < classNames.size(); iClass++)    {        if (opts.verboseTest)        {            cout << "EnumerateInstanceNames "                << "Namespace = " << opts.nameSpace                << ", Class = " << classNames[iClass]                << endl;        }        Array<CIMObjectPath> instanceNames =        client.enumerateInstanceNames(opts.nameSpace, classNames[iClass]);        if (opts.summary)        {      String s = "instance names of class";      _displaySummary(instanceNames.size(), s, opts.className.getString(),opts);        }        else        {            //simply output the list one per line for the moment.            for (Uint32 i = 0; i < instanceNames.size(); i++)                        cout << instanceNames[i].toString() << endl;        }    }    if (opts.time)    {        opts.elapsedTime.stop();        opts.saveElapsedTime = opts.elapsedTime.getElapsed();    }    return(0);}int enumerateInstanceNames(CIMClient& client, Options& opts){    if (opts.verboseTest)    {        cout << "EnumerateInstanceNames "            << "Namespace= " << opts.nameSpace            << ", Class= " << opts.className            << endl;    }    if (opts.time)    {        opts.elapsedTime.reset();        opts.elapsedTime.start();    }    Array<CIMObjectPath> instanceNames =        client.enumerateInstanceNames(opts.nameSpace,                                      opts.className);    if (opts.time)    {        opts.elapsedTime.stop();        opts.saveElapsedTime = opts.elapsedTime.getElapsed();    }    if (opts.summary)    {      String s = "instances names of class";      _displaySummary(instanceNames.size(), s, opts.className.getString(),opts);    }    else    {        //Output the list one per line for the moment.        for (Uint32 i = 0; i < instanceNames.size(); i++)                    cout << instanceNames[i].toString() << endl;    }    return(0);}int enumerateInstances(CIMClient& client, Options& opts){    if (opts.verboseTest)    {        cout << "EnumerateInstances "            << "Namespace = " << opts.nameSpace            << ", Class = " << opts.className            << ", deepInheritance = " << _toString(opts.deepInheritance)            << ", localOnly = " << _toString(opts.localOnly)            << ", includeQualifiers = " << _toString(opts.includeQualifiers)            << ", includeClassOrigin = " << _toString(opts.includeClassOrigin)            << ", PropertyList = " << buildPropertyListString(opts.propertyList)            << endl;    }    Array<CIMInstance> instances;    if (opts.time)    {        opts.elapsedTime.reset();        opts.elapsedTime.start();    }    instances = client.enumerateInstances( opts.nameSpace,                                           opts.className,                                           opts.deepInheritance,                                           opts.localOnly,                                           opts.includeQualifiers,                                           opts.includeClassOrigin,                                           opts.propertyList );    if (opts.time)    {        opts.elapsedTime.stop();        opts.saveElapsedTime = opts.elapsedTime.getElapsed();    }    if (opts.summary)    {      String s = "instances of class";        _displaySummary(instances.size(), s, opts.className.getString(),opts);    }    else    {        // Output the returned instances        for (Uint32 i = 0; i < instances.size(); i++)        {            CIMInstance instance = instances[i];            // Check Output Format to print results            outputFormatInstance(opts.outputType, instance);        }    }    return(0);}int executeQuery(CIMClient& client, Options& opts){    if (opts.verboseTest)    {

⌨️ 快捷键说明

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