📄 tomof.cpp
字号:
//%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: Karl Schopmeyer (k.schopmeyer@opengroup.org)//// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company// (carolann_graves@hp.com)// Amit K Arora (amita@in.ibm.com) for Bug# 1081 (mofFormat())// David Dillard, VERITAS Software Corp.// (david.dillard@veritas.com)// Aruran, IBM (ashanmug@in.ibm.com) for Bug# 4551////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/OptionManager.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Repository/CIMRepository.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Client/CIMClient.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/MofWriter.h>#include "clientRepositoryInterface.h"PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;CIMNamespaceName nameSpace = CIMNamespaceName ("root/cimv2");/*class classNameList{public: classNameList(CIMNamespaceName& nameSpace, clientRepositoryInterface& cli) { };};*//* class classNameList - Provides creation and management of classNames in a list form.*/class classNameList{public: // constructor - Creates empty list classNameList() { _nameSpace = String::EMPTY; //_cli = 0; _index = 0; } // constructor - with nameSpace and Interface classNameList(const CIMNamespaceName& nameSpace, const clientRepositoryInterface& cli) { _nameSpace = nameSpace, _cli = cli, _index = 0; } ~classNameList() { } // Set Namespace void setNameSpace (const CIMNamespaceName& nameSpac) { _nameSpace = nameSpace; } // enumerate - Executes the enumerate Boolean enumerate(const CIMName& className, Boolean deepInheritance) { try { _classNameList = _cli.enumerateClassNames( _nameSpace, className, deepInheritance); } catch(Exception &e) { cout << "Exception " << e.getMessage() << " on enumerateClassNames open. Terminating." << endl; return false; } return true; } /* filter - Filters the list against a defined pattern using the glob type filter. NOTICE: This method no longer performs glob-style matching. The list is now filtered using exact matching, except that it also recognizes the "*" pattern which matches everything. While the new functionality is quite limited, this change is consistent with the way this method was being used at the time of the change. @param pattern -String defining the pattern used to filter the list. @return Result is the list with all names that do not pass the filter removed. */ void filter(String& pattern) { // Filter the list in accordance with the pattern if (pattern == "*") { return; } Array<CIMName> tmp; for (Uint32 i = 0; i < _classNameList.size(); i++) { if (String::equalNoCase(_classNameList[i].getString(), pattern)) tmp.append(_classNameList[i]); } _classNameList.swap(tmp); } /* getIndex - Get the current index in the list. This is used with next and start functions to get entries in the list one by one. */ Uint32 getIndex() { return _index; } /* size - returns the number of entires in the list @return Uint32 with number of entires in the list. */ Uint32 size() { return _classNameList.size(); } /* next - get the next entry in the list. If there are no more entires returns String:EMPTY @return String containing next entry or String::EMPTY if at end of list */ String next() { if (_index < _classNameList.size()) return _classNameList[_index++].getString(); else return String::EMPTY; } /* start - Set the index to the start of the list */ void start() { _index = 0; }private: Array<CIMName> _classNameList; clientRepositoryInterface _cli; CIMNamespaceName _nameSpace; Uint32 _index;};/** ErrorExit - Print out the error message as an and get out. @param - Text for error message @return - None, Terminates the program @execption - This function terminates the program*/void ErrorExit(const String& message){ cerr << message << endl; exit(1);}//------------------------------------------------------------------------------//// _indent()////------------------------------------------------------------------------------static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentSize){ Uint32 n = level * indentSize; if (n > 50) { cout << "Jumped Ship " << level << " size " << indentSize << endl; exit(1); } for (Uint32 i = 0; i < n; i++) os << ' ';}void mofFormat( PEGASUS_STD(ostream)& os, const char* text, Uint32 indentSize){ char* var = new char[strlen(text)+1]; char* tmp = strcpy(var, text); Uint32 count = 0; Uint32 indent = 0; Boolean quoteState = false; Boolean qualifierState = false; char c; char prevchar = 0; while ((c = *tmp++)) { count++; // This is too simplistic and must move to a token based mini parser // but will do for now. One problem is tokens longer than 12 characters that // overrun the max line length. switch (c) { case '\n': os << Sint8(c); prevchar = c; count = 0 + (indent * indentSize); _indent(os, indent, indentSize); break; case '\"': // quote os << Sint8(c); prevchar = c; quoteState = !quoteState; break; case ' ': os << Sint8(c); prevchar = c; if (count > 66) { if (quoteState) { os << "\"\n"; _indent(os, indent + 1, indentSize); os <<"\""; } else { os <<"\n"; _indent(os, indent + 1, indentSize); } count = 0 + ((indent + 1) * indentSize); } break; case '[': if (prevchar == '\n') { indent++; _indent(os, indent, indentSize); qualifierState = true; } os << Sint8(c); prevchar = c; break; case ']': if (qualifierState) { if (indent > 0) indent--; qualifierState = false; } os << Sint8(c); prevchar = c; break; default: os << Sint8(c); prevchar = c; } } delete [] var;}///////////////////////////////////////////////////////////////// OPTION MANAGEMENT////////////////////////////////////////////////////////////////** GetOptions function - This function defines the Options Table and sets up the options from that table using the option manager. const char* optionName; const char* defaultValue; int required; Option::Type type; char** domain; Uint32 domainSize; const char* commandLineOptionName; const char* optionHelpMessage;*/void GetOptions( OptionManager& om, int& argc, char** argv, const String& pegasusHome){ const char* tmpDir = getenv ("PEGASUS_HOME"); if (tmpDir == NULL) { tmpDir = "."; } static struct OptionRow optionsTable[] = { //optionname defaultvalue rqd type domain domainsize clname hlpmsg {"namespace", "root/cimv2", false, Option::STRING, 0, 0, "n", "Specifies namespace to use for"}, {"version", "false", false, Option::BOOLEAN, 0, 0, "v", "Displays Program Version identification"}, // set to true for testing {"verbose", "true", false, Option::BOOLEAN, 0, 0, "verbose", "Displays Extra information"}, {"help", "false", false, Option::BOOLEAN, 0, 0, "h", "Prints help message with command line options"}, {"qualifiers", "false", false, Option::BOOLEAN, 0, 0, "q", "If set, show the qualifier declarations"}, {"instances", "false", false, Option::BOOLEAN, 0, 0, "i", "If set, show the instances"}, {"noClass", "false", false, Option::BOOLEAN, 0, 0, "nc", "If set, bypass the class display completely"}, {"all", "false", false, Option::BOOLEAN, 0, 0, "a", "If set, show qualifiers, classes, and instances"}, {"summary", "false", false, Option::BOOLEAN, 0, 0, "s", "Print only a summary count at end"}, {"location", tmpDir, false, Option::STRING, 0, 0, "l", "Repository directory (/run if repository directory is /run/repository"}, {"client", "false", false, Option::BOOLEAN, 0, 0, "c", "Runs as Pegasus client using client interface"}, {"onlynames", "false", false, Option::BOOLEAN, 0, 0, "o", "Show Names only, not the MOF"}, {"xml", "false", false, Option::BOOLEAN, 0, 0, "x", "Output result in XML rather than MOF"}, }; const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]); om.registerOptions(optionsTable, NUM_OPTIONS); String configFile = pegasusHome + "/cimserver.conf"; if (FileSystem::exists(configFile)) { om.mergeFile(configFile); cout << "Config file from " << configFile << endl; } om.mergeCommandLine(argc, argv); om.checkRequiredOptions();}void printHelp(char* name, OptionManager om){ String header = "Usage "; header.append(name); header.append(" -parameters [class]"); header.append(" - Generate MOF output from the repository or client\n"); String trailer = "\nAssumes using repository interface and repository at\n"; trailer.append("PEGASUS_HOME for repository unless -r specified"); trailer.append("\nIf [class] exists only that class mof is output.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -