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

📄 mttestclient.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}/**    Parses the command line, validates the options, and sets instance    variables based on the option arguments.    @param   argc  the number of command line arguments    @param   argv  the string vector of command line arguments    @exception  CommandFormatException  if an error is encountered in parsing                                        the command line */void MTTestClient::setCommand (Uint32 argc, char* argv []){    Uint32         i              = 0;    Uint32         c              = 0;    String         httpVersion    = String ();    String         httpMethod     = String ();    String         timeoutStr     = String ();    String         GetOptString   = String ();    getoopt        getOpts;    //    //  Construct GetOptString    //    GetOptString.append (_OPTION_HOSTNAME);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_PORTNUMBER);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_SSL);    GetOptString.append (_OPTION_TIMEOUT);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_USERNAME);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_PASSWORD);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    //    //  Initialize and parse getOpts    //    getOpts = getoopt ();    getOpts.addFlagspec (GetOptString);    getOpts.parse (argc, argv);    if (getOpts.hasErrors ())    {        CommandFormatException e (getOpts.getErrorStrings () [0]);        throw e;    }    //    //  Get options and arguments from the command line    //    for (i =  getOpts.first (); i <  getOpts.last (); i++)    {        if (getOpts [i].getType () == Optarg::LONGFLAG)        {            UnexpectedArgumentException e (                         getOpts [i].Value ());            throw e;        }        else if (getOpts [i].getType () == Optarg::REGULAR)        {            UnexpectedArgumentException e (                         getOpts [i].Value ());            throw e;        }        else /* getOpts [i].getType () == FLAG */        {            c = getOpts [i].getopt () [0];            switch (c)            {                case _OPTION_HOSTNAME:                {                    if (getOpts.isSet (_OPTION_HOSTNAME) > 1)                    {                        //                        // More than one hostname option was found                        //                        DuplicateOptionException e (_OPTION_HOSTNAME);                        throw e;                    }                    _hostName = getOpts [i].Value ();                    _hostNameSet = true;                    break;                }                case _OPTION_PORTNUMBER:                {                    if (getOpts.isSet (_OPTION_PORTNUMBER) > 1)                    {                        //                        // More than one portNumber option was found                        //                        DuplicateOptionException e (_OPTION_PORTNUMBER);                        throw e;                    }                    _portNumberStr = getOpts [i].Value ();                    try                    {                        getOpts [i].Value (_portNumber);                    }                    catch (const TypeMismatchException&)                    {                        InvalidOptionArgumentException e (_portNumberStr,                            _OPTION_PORTNUMBER);                        throw e;                    }                    _portNumberSet = true;                    break;                }                case _OPTION_SSL:                {                    //                    // Use port 5989 as the default port for SSL                    //                    _useSSL = true;                    if (!_portNumberSet)                       _portNumber = 5989;                    break;                }                case _OPTION_TIMEOUT:                {                    if (getOpts.isSet (_OPTION_TIMEOUT) > 1)                    {                        //                        // More than one timeout option was found                        //                        DuplicateOptionException e (_OPTION_TIMEOUT);                        throw e;                    }                    timeoutStr = getOpts [i].Value ();                    try                    {                        getOpts [i].Value (_timeout);                    }                    catch (const TypeMismatchException&)                    {                        InvalidOptionArgumentException e (timeoutStr,                            _OPTION_TIMEOUT);                        throw e;                    }                    break;                }                case _OPTION_USERNAME:                {                    if (getOpts.isSet (_OPTION_USERNAME) > 1)                    {                        //                        // More than one username option was found                        //                        DuplicateOptionException e (_OPTION_USERNAME);                        throw e;                    }                    _userName = getOpts [i].Value ();                    _userNameSet = true;                    break;                }                case _OPTION_PASSWORD:                {                    if (getOpts.isSet (_OPTION_PASSWORD) > 1)                    {                        //                        // More than one password option was found                        //                        DuplicateOptionException e (_OPTION_PASSWORD);                        throw e;                    }                    _password = getOpts [i].Value ();                    _passwordSet = true;                    break;                }                default:                    //                    //  This path should not be hit                    //                    break;            }        }    }    if (getOpts.isSet (_OPTION_PORTNUMBER) < 1)    {        //        //  No portNumber specified        //  Default to WBEM_DEFAULT_PORT        //  Already done in constructor        //    }    else    {        if (_portNumber > _MAX_PORTNUMBER)        {            //            //  Portnumber out of valid range            //            InvalidOptionArgumentException e (_portNumberStr,                _OPTION_PORTNUMBER);            throw e;        }    }    if (getOpts.isSet (_OPTION_TIMEOUT) < 1)    {        //        //  No timeout specified        //  Default to DEFAULT_TIMEOUT_MILLISECONDS        //  Already done in constructor        //    }    else    {        if (_timeout <= 0)        {            //            //  Timeout out of valid range            //            InvalidOptionArgumentException e (timeoutStr,                _OPTION_TIMEOUT);            throw e;        }    }}void MTTestClient::getMTTestClient(ostream& outPrintWriter,                              ostream& errPrintWriter){    const Uint32 THREAD_COUNT = 3;    Thread *test_clients[THREAD_COUNT];       for(Uint32 i = 0; i < THREAD_COUNT; i++)       {           test_clients[i] = new Thread(test_client, 0, false);           test_clients[i]->run();       }       for(Uint32 i = 0; i < THREAD_COUNT; i++)       {           test_clients[i]->join();           delete test_clients[i];       }}/**    Executes the command and writes the results to the PrintWriters.    @param   outPrintWriter     the ostream to which output should be                                written    @param   errPrintWriter     the ostream to which error output should be                                written    @return  0                  if the command is successful             1                  if an error occurs in executing the command */Uint32 MTTestClient::execute (ostream& outPrintWriter,                                 ostream& errPrintWriter){    try    {        getMTTestClient( outPrintWriter, errPrintWriter );    }    catch (const Exception& e)    {        errPrintWriter << MTTestClient::COMMAND_NAME << ": " <<            e.getMessage () << endl;        return (RC_ERROR);    }    catch (...)    {        errPrintWriter << MTTestClient::COMMAND_NAME << ": " <<            "Unknown error" << endl;        return (RC_ERROR);    }    return (RC_SUCCESS);}/**    Parses the command line, and executes the command.    @param   argc  the number of command line arguments    @param   argv  the string vector of command line arguments    @return  0                  if the command is successful             1                  if an error occurs in executing the command */PEGASUS_NAMESPACE_END// exclude main from the Pegasus NamespacePEGASUS_USING_PEGASUS;PEGASUS_USING_STD;int main (int argc, char* argv []){    MTTestClient    command = MTTestClient ();    int                rc;    try    {        command.setCommand (argc, argv);    }    catch (const CommandFormatException& cfe)    {        cerr << MTTestClient::COMMAND_NAME << ": " << cfe.getMessage ()             << endl;        cerr << command.getUsage () << endl;        exit (Command::RC_ERROR);    }    catch (const Exception& e)    {        cerr << MTTestClient::COMMAND_NAME << ": " << e.getMessage ()             << endl;    }    rc = command.execute (cout, cerr);    PEGASUS_STD(cout) <<  "+++++ passed all tests" << PEGASUS_STD(endl);    exit (rc);    return 0;}

⌨️ 快捷键说明

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