tool/CommandDebug.cpp
changeset 1142 59be91dfcbe1
child 1363 11c0b2caa253
equal deleted inserted replaced
1141:7ffbca63fc72 1142:59be91dfcbe1
       
     1 /*****************************************************************************
       
     2  *
       
     3  * $Id$
       
     4  *
       
     5  ****************************************************************************/
       
     6 
       
     7 #include <sstream>
       
     8 #include <iomanip>
       
     9 using namespace std;
       
    10 
       
    11 #include "CommandDebug.h"
       
    12 
       
    13 /*****************************************************************************/
       
    14 
       
    15 CommandDebug::CommandDebug():
       
    16     Command("debug", "Set the master's debug level.")
       
    17 {
       
    18 }
       
    19 
       
    20 /*****************************************************************************/
       
    21 
       
    22 string CommandDebug::helpString() const
       
    23 {
       
    24     stringstream str;
       
    25 
       
    26 	str << getName() << " <LEVEL>" << endl
       
    27 		<< endl
       
    28     	<< getBriefDescription() << endl
       
    29     	<< endl
       
    30     	<< "Debug messages are printed to syslog." << endl
       
    31     	<< endl
       
    32     	<< "Arguments:" << endl
       
    33     	<< "  LEVEL can have one of the following values:" << endl
       
    34     	<< "        0 for no debugging output," << endl
       
    35     	<< "        1 for some debug messages, or" << endl
       
    36     	<< "        2 for printing all frame contents (use with caution!)."
       
    37 		<< endl << endl
       
    38     	<< numericInfo();
       
    39 
       
    40 	return str.str();
       
    41 }
       
    42 
       
    43 /****************************************************************************/
       
    44 
       
    45 void CommandDebug::execute(MasterDevice &m, const StringVector &args)
       
    46 {
       
    47     stringstream str;
       
    48     int debugLevel;
       
    49     
       
    50     if (args.size() != 1) {
       
    51         stringstream err;
       
    52         err << "'" << getName() << "' takes exactly one argument!";
       
    53         throwInvalidUsageException(err);
       
    54     }
       
    55 
       
    56     str << args[0];
       
    57     str >> resetiosflags(ios::basefield) // guess base from prefix
       
    58         >> debugLevel;
       
    59 
       
    60     if (str.fail()) {
       
    61         stringstream err;
       
    62         err << "Invalid debug level '" << args[0] << "'!";
       
    63         throwInvalidUsageException(err);
       
    64     }
       
    65 
       
    66     m.open(MasterDevice::ReadWrite);
       
    67     m.setDebug(debugLevel);
       
    68 }
       
    69 
       
    70 /*****************************************************************************/