fp@1142: /***************************************************************************** fp@1142: * fp@1142: * $Id$ fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1222: #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@1337: << " STATE can be 'INIT', 'PREOP', 'BOOT', 'SAFEOP', or 'OP'." << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1157: << " --alias -a " << endl fp@1157: << " --position -p Slave selection. See the help of" << endl fp@1157: << " the 'slaves' command." << 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@1151: SlaveList slaves; fp@1151: SlaveList::const_iterator si; 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@1337: } else if (stateStr == "BOOT") { fp@1337: state = 0x03; 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@1151: slaves = selectedSlaves(m); fp@1142: fp@1157: if (!slaves.size() && getVerbosity() != Quiet) { fp@1157: cerr << "Warning: Selection matches no slaves!" << endl; fp@1157: } fp@1157: fp@1151: for (si = slaves.begin(); si != slaves.end(); si++) { fp@1151: m.requestState(si->position, state); fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/