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

📄 tomof.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    trailer.append("\nIf no parameters set, it outputs nothing");    trailer.append("\nExamples:");    trailer.append("\n  tomof - Returns only help/usage information");    trailer.append("\n  tomof * - Returns information on all classes, etc.");    trailer.append("\n  tomof CIM_DOOR - Shows mof for CIM_Door from default namespace");    //trailer.append("\n  tomof *door* - Shows mof for classes with 'door' in name.");    //trailer.append("\n  tomof -o *software* - Lists Class names with 'door' in name.");    trailer.append("\n  tomof -a - outputs mof for all classes");    trailer.append("\n  tomof -c - outputs mof for all classes using client interface.");    trailer.append("\n  tomof -q - Outputs mof for qualifiers and classes");    trailer.append("\n  tomof -s - Outputs summary count of classes and optionally instances. Does not deliver lists");    om.printOptionsHelpTxt(header, trailer);}/////////////////////////////////////////////////////////////////    MAIN///////////////////////////////////////////////////////////////int main(int argc, char** argv){    String pegasusHome;    pegasusHome = "/";    // GetEnvironmentVariables(argv[0], pegasusHome);    // Get options (from command line and from configuration file); this    // removes corresponding options and their arguments fromt he command    // line.    // Get options (from command line and from configuration file); this    // removes corresponding options and their arguments fromt he command    // line.    OptionManager om;    Boolean argsFound = false;    if (argc > 1)    {        argsFound = true;    }    try    {        GetOptions(om, argc, argv, pegasusHome);    }    catch(Exception& e)    {        cout << "Error Qualifier Enumeration:" << endl;        cerr << argv[0] << ": " << e.getMessage() << endl;        exit(1);    }    // Check to see if user asked for help (-h otpion):    if(om.isTrue("help"))    {        printHelp(argv[0], om);        exit (0);    }    // Check for Version flag and print version message    if(om.isTrue("version"))    {        cout << "Pegasus Version " << PEGASUS_PRODUCT_VERSION                << " " << argv[0] << " version 1.0 " << endl;        return 0;    }    Boolean showOnlyNames = om.isTrue("onlynames");    Boolean doNotShowClasses = om.isTrue("noClass");    // Check for namespace flag and set namespace    String localNameSpace;    if(om.lookupValue("namespace", localNameSpace))    {        cout << "Namespace = " << localNameSpace << endl;    }    // Check for the show qualifiers flag    Boolean showQualifiers = om.isTrue("qualifiers");    // Check for the summary count flag    Boolean summary = om.isTrue("summary");    Uint32 qualifierCount = 0;    Uint32 classCount = 0;    Uint32 classCountDisplayed = 0;    Uint32 instanceCount = 0;    // Check for the instances    Boolean showInstances = om.isTrue("instances");    Boolean showAll = om.isTrue("all");    Boolean verbose = om.isTrue("verbose");    Boolean singleClass = true;    CIMName className;    // Set the flags to determine whether we show all or simply some classes    if(showAll)        singleClass = false;    else    // if no classes in list.        if(argc < 2)        singleClass = false;    // Build the inputClassList from the remaining input parameters    Array<String> inputClassList;    if(argc > 1)    {        // while there are entries in the argv list collect them        for(int i = 1; i < argc; i++)            inputClassList.append(argv[i]);    }    else    {        // Do output if any arguments but only print help if there is no args.        if (argsFound)        {            inputClassList.append("*");        }        else        {            printHelp(argv[0], om);            exit (0);        }    }    if(verbose)    {        if(verbose) cout << "Class list is ";        for(Uint32 i = 0 ; i < inputClassList.size(); i++)        {            if(verbose) cout << inputClassList[i] << " ";        }        cout << endl;    }    // Test to determine if we have a filter pattern to limit classes displayed    //String pattern;    //Boolean doWildCard = false;    // if client request set in options, set isClient variable accordingly    Boolean isClient = om.isTrue("client");    // Determine if output is XML or MOF    Boolean isXMLOutput = om.isTrue("xml");    // Check for repository path flag and set repository directory    String location = "";    if(om.lookupValue("location", location))    {        if(verbose) cout << "location Path = " << location << endl;    }    clientRepositoryInterface clRepository; // the repository interface object    clientRepositoryInterface::_repositoryType rt;    if(isClient)    {        location = "localhost:5988";        rt = clientRepositoryInterface::REPOSITORY_INTERFACE_CLIENT;    }    else    {        rt = clientRepositoryInterface::REPOSITORY_INTERFACE_LOCAL;        const char* tmp = getenv("PEGASUS_HOME");        if (strlen(tmp) == 0 && location == "." )            ErrorExit("Error, PEGASUS_HOME not set and repository option not used");        location.append("/repository");        if (!FileSystem::exists(location) || FileSystem::isDirectoryEmpty(location))        {            cout << "Error. " << location << " does not exist or is empty." << endl;            exit(1);        }    }    // Set a context for either client or repository access.    // Test to determine if we have proper location, etc. for opening    if(verbose)    {        cout << "Get from " << ((isClient) ? "client" : "repository ")        << " at " << location << endl;    }    // Create the repository and client objects    CIMRepository repository(location);    CIMClient client;    // if client mode, do client connection, else do repository connection    try    {        clRepository.init(rt, location);    }    catch(Exception &e)    {        cout << "Exception " << e.getMessage() << " on repository open. Terminating." << endl;        return false;    }    // Get the complete class name list before we start anything else    if(showQualifiers || showAll || summary)    {        try        {            // Enumerate the qualifiers:            Array<CIMQualifierDecl> qualifierDecls                    = clRepository.enumerateQualifiers(nameSpace);            qualifierCount = qualifierDecls.size();            if(showOnlyNames)            {                for(Uint32 i = 0; i < qualifierDecls.size(); i++)                    cout << "Qualifier " << qualifierDecls[i].getName() << endl;            }            if(showQualifiers || showAll)            {                for(Uint32 i = 0; i < qualifierDecls.size(); i++)                {                    CIMQualifierDecl tmp = qualifierDecls[i];                    if(isXMLOutput)                    {                        XmlWriter::printQualifierDeclElement(tmp, cout);                    }                    else                    {                        Buffer x;                        MofWriter::appendQualifierDeclElement(x, tmp);                        x.append('\0');                        mofFormat(cout, x.getData(), 4);                    }                }            }        }        catch(Exception& e)        {            ErrorExit(e.getMessage());        }    }    // Setup clasname list object    classNameList list(nameSpace, clRepository);    // Enumerate all classnames from namespace    if (!list.enumerate(CIMName(), true))        ErrorExit("Class Enumeration failed");    //Filter list for input patterns    for(Uint32 i = 0; i < inputClassList.size(); i++)        list.filter(inputClassList[i]);    // get size for summary    classCount = list.size();    Boolean localOnly = true;    Boolean includeQualifiers = true;    Boolean includeClassOrigin = true;    if (!summary || !doNotShowClasses)    {        if(showOnlyNames)        {            for(Uint32 j = 0; j < list.size(); j++)                cout << "Class " << list.next() << endl;        }        else        {            // Print out the MOF for those found            for(Uint32 j = 0; j < list.size(); j++)            {                CIMName nextClass = list.next();                CIMClass cimClass;                try                {                    cimClass = clRepository.getClass(nameSpace, nextClass,                                                          localOnly, includeQualifiers, includeClassOrigin);                }                catch(Exception& e)                {                    // ErrorExit(e.getMessage());                    cout << "Class get error " << e.getMessage() << " Class " << nextClass << endl;                }                // Note we get and print ourselves rather than use the generic printMof                if(isXMLOutput)                    XmlWriter::printClassElement(cimClass, cout);                else                {                    Buffer x;                    MofWriter::appendClassElement(x, cimClass);                    x.append('\0');                    mofFormat(cout, x.getData(), 4);                }            }        }    // Note that we can do this so we get all instances or just the given class    }    list.start();    if(showInstances | showAll)    {        // try Block around basic instance processing        for(Uint32 j = 0; j < list.size(); j++)        {            CIMName className = list.next();            //cout << "Instances for " << className << endl;            try            {                Boolean deepInheritance = true;                Boolean localOnly = false;                Boolean includeClassOrigin = false;                Boolean includeQualifiers = false;                if(showOnlyNames)                {                    Array<CIMObjectPath> instanceNames;                    instanceNames = clRepository.enumerateInstanceNames(nameSpace,                                                                        className);                    for(Uint32 j = 0; j < instanceNames.size(); j++)                        cout << "Instance " << instanceNames[j].toString();                }                else    // Process complete instances                {                // Process inputClasslist to enumerate and print instances                    Array<CIMInstance> namedInstances;                    namedInstances = clRepository.enumerateInstances(nameSpace,                                                                     className,                                                                     deepInheritance,                                                                     localOnly,                                                                     includeQualifiers,                                                                     includeClassOrigin);                    // Process and output each instance                    for(Uint32 k = 0; k < namedInstances.size(); k++)                    {                        CIMInstance instance = namedInstances[k];                        if(isXMLOutput)                            XmlWriter::printInstanceElement(instance, cout);                        else                        {                            Buffer x;                            MofWriter::appendInstanceElement(x, instance);                            x.append('\0');                            mofFormat(cout, x.getData(), 4);                        }                    }                }            }            catch(Exception& e)            {                cout << "Error Instance Enumeration:" << e.getMessage() << endl;            }        }    }    if(summary)    {        if(qualifierCount != 0)            cout << "Qualifiers - " << qualifierCount << endl;        if(classCount != 0)            cout << "Classes - " << classCount << " found and " << classCountDisplayed                    << " output" << endl;        if(instanceCount != 0)            cout << "Instances - " << instanceCount << endl;    }    exit(0);}//PEGASUS_NAMESPACE_END

⌨️ 快捷键说明

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