fp@1142: /***************************************************************************** fp@1142: * fp@1142: * $Id$ fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandStates.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandStates::CommandStates(): fp@1142: Command("states", "Request application-layer states.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: string CommandStates::helpString() const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1142: str << getName() << " [OPTIONS] " << endl fp@1142: << endl fp@1142: << getBriefDescription() << endl fp@1142: << endl fp@1142: << "Arguments:" << endl fp@1142: << " STATE can be 'INIT', 'PREOP', 'SAFEOP', or 'OP'" << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1142: << " --slave -s Positive numerical ring position," << endl fp@1142: << " or 'all' for all slaves (default)." << endl fp@1142: << endl fp@1142: << numericInfo(); fp@1142: fp@1142: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandStates::execute(MasterDevice &m, const StringVector &args) fp@1142: { fp@1142: stringstream err; fp@1142: string stateStr; fp@1142: uint8_t state = 0x00; fp@1142: fp@1142: if (args.size() != 1) { fp@1142: err << "'" << getName() << "' takes exactly one argument!"; fp@1142: throwInvalidUsageException(err); fp@1142: } fp@1142: fp@1142: stateStr = args[0]; fp@1142: transform(stateStr.begin(), stateStr.end(), fp@1142: stateStr.begin(), (int (*) (int)) std::toupper); fp@1142: fp@1142: if (stateStr == "INIT") { fp@1142: state = 0x01; fp@1142: } else if (stateStr == "PREOP") { fp@1142: state = 0x02; fp@1142: } else if (stateStr == "SAFEOP") { fp@1142: state = 0x04; fp@1142: } else if (stateStr == "OP") { fp@1142: state = 0x08; fp@1142: } else { fp@1142: err << "Invalid state '" << args[0] << "'!"; fp@1142: throwInvalidUsageException(err); fp@1142: } fp@1142: fp@1142: m.open(MasterDevice::ReadWrite); fp@1142: fp@1142: if (slavePosition == -1) { fp@1142: unsigned int i, numSlaves = m.slaveCount(); fp@1142: for (i = 0; i < numSlaves; i++) fp@1142: m.requestState(i, state); fp@1142: } else { fp@1142: m.requestState(slavePosition, state); fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/