📄 cgiclient.cpp
字号:
/** EnumerateClassNames gets the parameters for NameSpace and ClassName and calls the enumerate class name CIMOperation. The returned array in sent to printclassnames*/void EnumerateClassNames(const CGIQueryString& qs){ // Get NameSpace: CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs); // Get ClassName: CIMName className; DDD(cout << "EnumerateClassNames" << endl;) const char* tmp; // 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; elapsedTime.start(); // Make the Connection CIMClient client; String host; Uint32 portNumber; getHostAndPort (host, portNumber); client.connect (host, portNumber, String::EMPTY, String::EMPTY); Array<CIMName> classNames = client.enumerateClassNames( nameSpace, className, deepInheritance); elapsedTime.stop(); // Print the results PrintClassNames(nameSpace, classNames, elapsedTime.getElapsed()); } catch(Exception& e) { ErrorExit(e.getMessage()); }} /*************************************************************************** DeleteClass Function***************************************************************************//** DeleteClass - Deletes the class defined on input*/void DeleteClass(const CGIQueryString& qs){ CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs); // Get ClassName: const char* tmp; if (!(tmp = qs.findValue("ClassName"))) ErrorExit("Missing ClassName field"); CIMName className = CIMName (tmp); if (className.isNull()) ErrorExit("ClassName parameter is null"); try { CIMClient client; String host; Uint32 portNumber; getHostAndPort (host, portNumber); client.connect (host, portNumber, String::EMPTY, String::EMPTY); client.deleteClass(nameSpace, className); String message = "Class \""; message.append(className.getString()); message.append("\" was deleted"); PrintHTMLHead("DeleteClass", "Delete Class Result"); cout << " <h1>" << message << "</h1>\n"; cout << " </body>\n"; cout << "</html>\n"; } catch(Exception& e) { ErrorExit(e.getMessage()); }}void PrintQualifierRow(const CIMNamespaceName& nameSpace, const CIMQualifierDecl& qd){ cout << "<tr>\n"; const CIMValue& value = qd.getValue(); String href = BuildOperationHref("GetQualifier", nameSpace); href.append("QualifierName="); href.append(qd.getName().getString()); href.append("&"); cout << "<td>"; PrintAHref(href, qd.getName().getString()); cout << "</td>"; cout << "<td>" << cimTypeToString (value.getType ()) << "</td>\n"; cout << "<td>" << value.toString() << "</td>\n"; cout << "<td>" << qd.getScope ().toString () << "</td>\n"; cout << "<td>" << MofWriter::getQualifierFlavor(qd.getFlavor()) << "</td>\n"; cout << "<td>" << qd.getArraySize() << "</td>\n"; cout << "</tr>\n";}void PrintGetQualifier( const CIMNamespaceName& nameSpace, CIMQualifierDecl qualifierDecl){ PrintHTMLHead("GetQualifier", "GetQualifier Result"); // cout << "<html>\n"; // PrintHead("GetQualifier"); // cout << "<body bgcolor=\"#CCCCCC\">\n"; // PrintHeader("GetQualifier"); // PrintRule(); cout << "<table border=1 width=\"50%\">\n"; cout << " <tr>\n"; cout << " <th>CIMName</th>\n"; cout << " <th>CIMType</th>\n"; cout << " <th>CIMValue</th>\n"; cout << " <th>CIMScope</th>\n"; cout << " <th>CIMFlavor</th>\n"; cout << " <th>ArraySize</th>\n"; cout << " </tr>\n"; cout << "</tr>\n"; cout << "<h1>CIMQualifier:</h1>\n"; PrintQualifierRow(nameSpace, qualifierDecl); cout << "</table>\n"; // Now show the XML and the MOF for this entity cout << "\n<h2>MOF</h2>\n"; cout << "<pre>"; Buffer x; MofWriter::appendQualifierDeclElement(x, qualifierDecl); x.append('\0'); mofFormat(cout, x.getData(), 4); cout << "</pre>\n"; // Now show the XML for this entity cout << "\n<h2>XML</h2>\n"; cout << "<pre>"; XmlWriter::printQualifierDeclElement(qualifierDecl); cout << "</pre>\n"; cout << "</body>\n"; cout << "</html>\n";}void PrintEnumerateQualifiers( const CIMNamespaceName& nameSpace, const Array<CIMQualifierDecl>& qualifierDecls){ // Check this, why no HTML header here.???? PrintHead("EnumerateQualifiers"); cout << "<body bgcolor=\"#CCCCCC\">\n"; PrintHeader("EnumerateQualifiers"); PrintRule(); cout << "<table border=1 width=\"50%\">\n"; cout << " <tr>\n"; cout << " <th>CIMName</th>\n"; cout << " <th>CIMType</th>\n"; cout << " <th>CIMValue</th>\n"; cout << " <th>CIMScope</th>\n"; cout << " <th>CIMFlavor</th>\n"; cout << " <th>ArraySize</th>\n"; cout << " </tr>\n"; cout << "</tr>\n"; cout << "<h1>Qualifiers:</h1>\n"; for (Uint32 i = 0; i < qualifierDecls.size(); i++) { PrintQualifierRow(nameSpace, qualifierDecls[i]); } cout << "</table>\n" << "</body>\n" << "</html>\n";}/*************************************************************************** EnumerateQualifiers Function***************************************************************************//* CIMMethod to execute the EnumerateQualifiers operation*/void EnumerateQualifiers(const CGIQueryString& qs){ CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs); try { CIMClient client; String host; Uint32 portNumber; getHostAndPort (host, portNumber); client.connect (host, portNumber, String::EMPTY, String::EMPTY); Array<CIMQualifierDecl> qualifierDecls = client.enumerateQualifiers(nameSpace); PrintEnumerateQualifiers(nameSpace, qualifierDecls); } catch(Exception& e) { ErrorExit(e.getMessage()); }}/*************************************************************************** GetQualifier Function***************************************************************************//* CIMMethod to execute the getQualifier Operation*/static void GetQualifier(const CGIQueryString& qs){ CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs); // Get CIMQualifier name: const char* tmp; if (!(tmp = qs.findValue("QualifierName"))) ErrorExit("Missing QualifierName field"); CIMName qualifierName = CIMName (tmp); if (qualifierName.isNull()) ErrorExit("QualifierName parameter is null"); try { CIMClient client; String host; Uint32 portNumber; getHostAndPort (host, portNumber); client.connect (host, portNumber, String::EMPTY, String::EMPTY); CIMQualifierDecl qd = client.getQualifier(nameSpace, qualifierName); PrintGetQualifier(nameSpace, qd); } catch(Exception& e) { ErrorExit(e.getMessage()); }} /*************************************************************************** DeleteQualifier Function***************************************************************************//** DeleteQualifier - Deletes the Qualifier defined on input*/void DeleteQualifier(const CGIQueryString& qs){ CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs); // Get CIMQualifier name: const char* tmp; if (!(tmp = qs.findValue("QualifierName"))) ErrorExit("Missing QualifierName field"); CIMName qualifierName = CIMName (tmp); if (qualifierName.isNull()) ErrorExit("QualifierName parameter is null"); try { CIMClient client; String host; Uint32 portNumber; getHostAndPort (host, portNumber); client.connect (host, portNumber, String::EMPTY, String::EMPTY); client.deleteQualifier(nameSpace, qualifierName); String message = "Qualifier \""; message.append(qualifierName.getString()); message.append("\" was deleted"); PrintHTMLHead("DeleteQualifier", "Delete Qualifier Result"); cout << " <h1>" << message << "</h1>\n"; cout << " </body>\n"; cout << "</html>\n"; } catch(Exception& e) { ErrorExit(e.getMessage()); }}/*************************************************************************** PrintObjectNames Function***************************************************************************//** PrintInstanceNames Prints the HTML form for the names provided in the String array of instancenames. Note that the instance names are provided as an array of CIMObjectPath. The table created includes an href for each name so that a click on the href entry will get the instance Note that we assume the defaults for the extra parameters on the getInstance @param nameSpace @param InstanceNames - The array of references to print KSREVIEW: Change so the user can select extra params. ALAGS : Added last parameter isClass to decide on href for Associatior/Reference Names and to avoid a new method*/static void PrintObjectNames( const String& header, const CIMNamespaceName& nameSpace, const Array<CIMObjectPath>& instanceNames, double elapsedTime, bool isClass ){ PrintHTMLHead("GetInstanceNames", header); cout << "<table border=1>\n"; cout << "<tr><th>Object Names</th><tr>\n"; // For each name prepare the table entry with an href for // click access to the getInstance for that name for (Uint32 i = 0, n = instanceNames.size(); i < n; i++) { cout << "<tr><td>\n"; //ALAGS : Decide if href is to call GetClass or GetInstance // This would be needed in Associator/Reference Name calls // Set this parameter to "true" if the ObjectName textbox is // passing a Class String href; if(isClass) { href = BuildOperationHref("GetClass", nameSpace); href.append("ClassName="); href.append(instanceNames[i].getClassName().getString()); } else { href = BuildOperationHref("GetInstance", nameSpace); href.append("InstanceName="); // // KSREVIEWKS: - Need to convert the '"' (double quote) character to '%22' to // make it a valid URL string in the HTML tag. Also, need to // convert the '_' (underscore) character in the instanceName // string to a '.' (dot). // //ALAGS : No need to convert '-' to '.' as a '-' is already a valid // character in a URL string. A underscore '_' must not be converted // as it would affect all CIM_xxx classes. const String instanceName = instanceNames[i].toString(); String nameString; for (Uint32 j = 0, n = instanceName.size(); j < n; j++) { switch (instanceName[j]) { /*ALAGS: Commented to fix Bug #148 case '-': nameString.append("."); break;*/ case '"': nameString.append("%22"); break; default: nameString.append(instanceName[j]); } } href.append(nameString); href.append("&"); href.append("LocalOnly=true"); href.append("includQualifiers=false"); href.append("includeClassOrigin=false"); } PrintAHref(href, instanceNames[i].toString()); cout << "</tr></td>\n"; } // Close the HTML Table cout << "</table>\n"; // Close the Page cout << "<p>Returned " << instanceNames.size() << " Instances "; cout << " in " << elapsedTime << " Seconds</p>\n"; cout << "</body>\n" << "</html>\n";}/*************************************************************************** EnumerateInstanceNames Function***************************************************************************//** EnumerateInstanceNames Function Called for evaluation of the EvaluateInstance Names operation. Gets the parameters from the CGIQuery String and calls the enumerateInstanceNames CIMClient function. The resulting string array of names is printed by the function PrintObjectNames*/static void EnumerateInstanceNames(const CGIQueryString& qs){ // Get NameSpace: CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs); // Get ClassName: CIMName className; const char* tmp; if ((tmp = qs.findValue("ClassName"))) className = CIMName (tmp); // Invoke the method:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -