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

📄 cgiclient.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    CIMObjectPath referenceName;    try    {        referenceName = tmp;    }    catch(Exception& e)    {        ErrorExit(e.getMessage());    }    try    {        // Time the connection        Stopwatch elapsedTime;        elapsedTime.start();        CIMClient client;        String host;        Uint32 portNumber;        getHostAndPort (host, portNumber);        client.connect (host, portNumber, String::EMPTY, String::EMPTY);        client.deleteInstance(nameSpace, referenceName);        elapsedTime.stop();        PrintHTMLHead("DeleteInstance", "Delete an Instance Result");        cout << "<h1>Instance " << referenceName.toString() << " Deleted</H1>";        cout << " in " << elapsedTime.getElapsed() << " Seconds</p>\n";        cout << "</body>\n" << "</html>\n";        //PrintInstance(nameSpace, cimInstance, localOnly, includeQualifiers,        //includeClassOrigin);    }    catch(Exception& e)    {        ErrorExit(e.getMessage());    }}/***************************************************************************   CreateNameSpace Function***************************************************************************/static void CreateNameSpace(const CGIQueryString& qs){  // Get NameSpace:    CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs);    // Get nameSpace Name:    CIMNamespaceName nameSpaceName;    CIMName className;    const char* tmp;    if ((tmp = qs.findValue("NewNameSpace")))    nameSpaceName = CIMNamespaceName (tmp);    // Create the instance with full instancename since this is the key.    String instanceName = "__Namespace";    //ALAGS : FIX - No need to append property "name" while creating    // Instance here. CIMInstance constructor failed when this was done earlier    /*instanceName.append( ".name=\"");    instanceName.append(nameSpaceName.getString());    instanceName.append("\"");*/    CIMInstance newInstance(instanceName);    newInstance.addProperty(CIMProperty(CIMName ("name"),        nameSpaceName.getString()));    try    {    // Time the connection    Stopwatch elapsedTime;    elapsedTime.start();    CIMClient client;        String host;        Uint32 portNumber;        getHostAndPort (host, portNumber);        client.connect (host, portNumber, String::EMPTY, String::EMPTY);    // Call create Instances CIM Method for class __Namespace    cout << "Creating " << nameSpaceName;    client.createInstance(nameSpace, newInstance);    elapsedTime.stop();    PrintHTMLHead("CreateNameSpace", "Create a NameSpace Result");    cout << "<h1>Namespace " << nameSpaceName << " Created</H1>";    cout << " in " << elapsedTime.getElapsed() << " Seconds</p>\n";    cout << "</body>\n" << "</html>\n";    }    catch(Exception& e)    {    ErrorExit(e.getMessage());    }}/***************************************************************************   DeleteNameSpace Function***************************************************************************//** DeleteNameSpace - Deletes the Namespace defined.    Namespace deletion is done by deleting the instance of    __Namespace defined by the input parameter*/static void DeleteNameSpace(const CGIQueryString& qs){  // Get NameSpace:    CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs);    // Get NameSpaceName to delete:    CIMNamespaceName nameSpaceToDelete;    const char* tmp;    if ((tmp = qs.findValue("DeletionNameSpace")))    nameSpaceToDelete= CIMNamespaceName (tmp);    // Create Instance Name    String instanceName = "__Namespace.name=\"";    instanceName.append(nameSpaceToDelete.getString());    instanceName.append("\"");    // Create Instance Reference. Name must be in form Reference    CIMObjectPath referenceName;    try    {    referenceName = instanceName;    }    catch(Exception& e)    {    ErrorExit(e.getMessage());    }    // Now make connection and Delete the instance    // Deleting the Instance of __Namespace deletes    // the Namespace.    try    {    // Time the connection    Stopwatch elapsedTime;    elapsedTime.start();    CIMClient client;        String host;        Uint32 portNumber;        getHostAndPort (host, portNumber);        client.connect (host, portNumber, String::EMPTY, String::EMPTY);    // Call delete Instances CIM Method for class __Namespace    client.deleteInstance(nameSpace, referenceName);    elapsedTime.stop();    PrintHTMLHead("DeleteNameSpace", "Delete a NameSpace Result");    cout << "<h1>Namespace " << nameSpaceToDelete << " Deleted</H1>";    cout << " in " << elapsedTime.getElapsed() << " Seconds</p>\n";    cout << "</body>\n" << "</html>\n";    }    catch(Exception& e)    {    ErrorExit(e.getMessage());    } }/***************************************************************************   EnumerateNameSpaces Function***************************************************************************/static void EnumerateNameSpaces(const CGIQueryString& qs){  // Get NameSpace:    CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs);    // Get ClassName:    //CIMNamespaceName nameSpaceName;    CIMName className;    const char* tmp;    if ((tmp = qs.findValue("ClassName")))    className = CIMName (tmp);    // Invoke the method:    try    {    // Time the connection    Stopwatch elapsedTime;    elapsedTime.start();    CIMClient client;        String host;        Uint32 portNumber;        getHostAndPort (host, portNumber);        client.connect (host, portNumber, String::EMPTY, String::EMPTY);    // Call enumerate Instances CIM Method    Array<CIMObjectPath> instanceNames = client.enumerateInstanceNames(        nameSpace, className);    elapsedTime.stop();    // Convert from CIMObjectPath to String form    Array<String> tmpInstanceNames;        for (Uint32 i = 0; i < instanceNames.size(); i++)        tmpInstanceNames.append(instanceNames[i].toString());    // Print the name array    PrintHTMLHead("EnumerateNameSpaces", "Enumerate NameSpaces Result");    cout << "<table border=1>\n";    cout << "<tr><th>Namespaces</th><tr>\n";    for (Uint32 i = 0, n = instanceNames.size(); i < n; i++)    {        cout << "<tr><td>\n";        // Instnance name in form        // __Namespace.name="namespace"        // Strip off all but the namespace itself        String work = tmpInstanceNames[i];        Uint32 pos = work.find('\"');        if (pos != PEG_NOT_FOUND)        work = tmpInstanceNames[i].subString((pos+1), PEG_NOT_FOUND);        // remove trailing quote        work.remove((work.size() - 1), PEG_NOT_FOUND);        // Create href for click to get classnames        //ALAGS : FIX - Prefix "root/" to the Namespace Name for link to work        CIMNamespaceName nameSpaceName("root/"+work);        String href = BuildOperationHref("EnumerateClassNames",nameSpaceName);        href.append("InstanceName=&");        href.append("DeepInheritance=true");        PrintAHref(href, work);        cout << "</tr></td>\n";    }    // Close the HTML Table    cout << "</table>\n";    // Close the Page    cout << "<p>Click on a namespace to enumerate class Names</p>";    cout << "<p>Returned " << instanceNames.size() << " Names";    cout << " in " << elapsedTime.getElapsed() << " Seconds</p>\n";    cout << "</body>\n" << "</html>\n";    }    catch(Exception& e)    {    ErrorExit(e.getMessage());    }}/***************************************************************************   DefineHostParameters Function***************************************************************************//** DefineHostParameters - Function to make the changesto the basic host parameters if the input parameters areset.*/static void DefineHostParameters(const CGIQueryString& qs){    // const char* tmp;    HostInfo hostInfo;    // if ((tmp = qs.findValue("HostURL")))    // hostInfo.setHostName(tmp);    // if ((tmp = qs.findValue("HostPort")))    // hostInfo.setHostPort("8888");    /// Respond with the new parameters    PrintHTMLHead("DefineHostParameters", "HostName/Port");    cout << "<B>Host CIMName</B>  ";    cout << hostInfo.getAddress();    cout << "\n";    cout << "</body>\n" << "</html>\n";}/** PrintClassTreeEntry - Prints a single table entry for the class    with the proper indenation, etc.*/void PrintClassTreeEntry(const CIMNamespaceName& nameSpace,             const CIMName& className,             Uint32 level){    cout << "<LI>";    cout << level;    cout << " ";    //KSREVIEW figure out why clasName in href and printaHref.    String href = createGetClassHref(nameSpace,                          className);    href.append("LocalOnly=true");    PrintAHref(href, className.getString());}/***************************************************************************   TraverseClassTree Function***************************************************************************//** TraverseClassTree - Traverse the Tree of super-to-subclasses    printing each new subclass. This function uses recursieve calls    to traverse the complete Class Tree.    Note that the initial call is expected to be -1 which starts    us at the root.  We don't want to print the root.    @param - nameSpace - target namespace. Used to build href    @param - className at top of hiearchy (should be "" for complete    @param - superClassNames - Array of superclasses to className    array    @param - classNames - Array of all classNames    @param - size - size of className array    @level - Current level of inheritance tree.*/void TraverseClassTree(    const CIMNamespaceName& nameSpace,    const CIMName& className,    const Array<CIMName>& superClassNames,    const Array<CIMName>& classNames,    Uint32 size,    Uint32 level) {    Boolean putUL = false;    level++;    for (Uint32 i = 0; i < size; i++)    {       if (className == superClassNames[i])       {       if (!putUL)       {           putUL = true;           cout << "<ul>";       }       PrintClassTreeEntry(nameSpace,classNames[i], level);           cout << "&nbsp;&nbsp;&nbsp;";           // Build href for enumerate instance names           PrintEnumInstanceNameHref(nameSpace,classNames[i]);       TraverseClassTree(nameSpace,              classNames[i],              superClassNames,              classNames, size, level);       }    }    if (putUL)    cout << "</UL><!-- " << level << " -->\n";}/***************************************************************************   ClassInheritance Function***************************************************************************//**    ClassInheritance    This function operates on the same parameters as the enumerate classes    This version simply prints out one level of the class tree starting at    a defined superclass. Note that it does not print the starting class,    Simply the subclasses.    KSREVIEW: In reality this is the enumerate class itself and should be    merged with that.*/static void ClassInheritance(const CGIQueryString& qs){    // Get NameSpace:    CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs);    // Get ClassName:    CIMName className;    const char* tmp;    // Get the timeout that is an option on this command    Uint32 timeOut = 5 * 1000;    if ((tmp = qs.findValue("timeout")))    timeOut = 60 * 1000;    // KSREVIEW: Need the ascitointeger function.    // Get the ClassName field:    if ((tmp = qs.findValue("ClassName")) && *tmp)    className = CIMName (tmp);    // Get DeepInheritance:    Boolean deepInheritance = false;    if (qs.findValue("DeepInheritance"))    deepInheritance = true;    // Invoke the method:    try    {    // Time the connection    Stopwatch elapsedTime;    // Make the Connection    Boolean localOnly = false;    Boolean includeQualifiers = false;    Boolean includeClassOrigin = true;    elapsedTime.start();    CIMClient client;        String host;        Uint32 portNumber;        getHostAndPort (host, portNumber);        client.connect (host, portNumber, String::EMPTY, String::EMPTY);    client.setTimeout(timeOut);    Array<CIMClass> classArray = client.enumerateClasses(                    nameSpace,                    className,                    deepInheritance,                    localOnly,                    includeQualifiers,                    includeClassOrigin);    // Organize and Print the Class Tree results    elapsedTime.stop();    PrintHTMLHead("EnumerateInheritance", "Class Inheritance Result");    cout << "<table border=1>\n";    cout << "<tr><th>Super Class Names<th>Class Names<tr></th>\n";    String classNameHrefBuilder;    cout << "Count " <<   classArray.size() << endl;    for (Uint32 i = 0, n = classArray.size(); i < n; i++)    {        cout << "<tr><td>\n";        if (classArray[i].getSuperClassName().isNul

⌨️ 快捷键说明

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