tool/CommandDebug.cpp
author Florian Pose <fp@igh-essen.com>
Wed, 27 Aug 2008 16:00:48 +0000
changeset 1207 8f4dbee1e567
parent 1142 59be91dfcbe1
child 1363 11c0b2caa253
permissions -rw-r--r--
merge -c1434 branches/stable-1.4: Fixed nodist.
/*****************************************************************************
 *
 * $Id$
 *
 ****************************************************************************/

#include <sstream>
#include <iomanip>
using namespace std;

#include "CommandDebug.h"

/*****************************************************************************/

CommandDebug::CommandDebug():
    Command("debug", "Set the master's debug level.")
{
}

/*****************************************************************************/

string CommandDebug::helpString() const
{
    stringstream str;

	str << getName() << " <LEVEL>" << endl
		<< endl
    	<< getBriefDescription() << endl
    	<< endl
    	<< "Debug messages are printed to syslog." << endl
    	<< endl
    	<< "Arguments:" << endl
    	<< "  LEVEL can have one of the following values:" << endl
    	<< "        0 for no debugging output," << endl
    	<< "        1 for some debug messages, or" << endl
    	<< "        2 for printing all frame contents (use with caution!)."
		<< endl << endl
    	<< numericInfo();

	return str.str();
}

/****************************************************************************/

void CommandDebug::execute(MasterDevice &m, const StringVector &args)
{
    stringstream str;
    int debugLevel;
    
    if (args.size() != 1) {
        stringstream err;
        err << "'" << getName() << "' takes exactly one argument!";
        throwInvalidUsageException(err);
    }

    str << args[0];
    str >> resetiosflags(ios::basefield) // guess base from prefix
        >> debugLevel;

    if (str.fail()) {
        stringstream err;
        err << "Invalid debug level '" << args[0] << "'!";
        throwInvalidUsageException(err);
    }

    m.open(MasterDevice::ReadWrite);
    m.setDebug(debugLevel);
}

/*****************************************************************************/