author | Florian Pose <fp@igh-essen.com> |
Wed, 05 Nov 2008 10:55:48 +0000 | |
branch | stable-1.4 |
changeset 1664 | 0fd56b9fbd38 |
parent 1636 | b26170e168d9 |
child 1337 | 0253c74d0940 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
****************************************************************************/ |
|
6 |
||
7 |
#include <iostream> |
|
1636
b26170e168d9
merge -c1452 trunk: Headers.
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
8 |
#include <algorithm> |
1142 | 9 |
using namespace std; |
10 |
||
11 |
#include "CommandStates.h" |
|
12 |
||
13 |
/*****************************************************************************/ |
|
14 |
||
15 |
CommandStates::CommandStates(): |
|
16 |
Command("states", "Request application-layer states.") |
|
17 |
{ |
|
18 |
} |
|
19 |
||
20 |
/*****************************************************************************/ |
|
21 |
||
22 |
string CommandStates::helpString() const |
|
23 |
{ |
|
24 |
stringstream str; |
|
25 |
||
26 |
str << getName() << " [OPTIONS] <STATE>" << endl |
|
27 |
<< endl |
|
28 |
<< getBriefDescription() << endl |
|
29 |
<< endl |
|
30 |
<< "Arguments:" << endl |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
31 |
<< " STATE can be 'INIT', 'PREOP', 'SAFEOP', or 'OP'." << endl |
1142 | 32 |
<< endl |
33 |
<< "Command-specific options:" << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
34 |
<< " --alias -a <alias>" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
35 |
<< " --position -p <pos> Slave selection. See the help of" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
36 |
<< " the 'slaves' command." << endl |
1142 | 37 |
<< endl |
38 |
<< numericInfo(); |
|
39 |
||
40 |
return str.str(); |
|
41 |
} |
|
42 |
||
43 |
/****************************************************************************/ |
|
44 |
||
45 |
void CommandStates::execute(MasterDevice &m, const StringVector &args) |
|
46 |
{ |
|
1151 | 47 |
SlaveList slaves; |
48 |
SlaveList::const_iterator si; |
|
1142 | 49 |
stringstream err; |
50 |
string stateStr; |
|
51 |
uint8_t state = 0x00; |
|
52 |
||
53 |
if (args.size() != 1) { |
|
54 |
err << "'" << getName() << "' takes exactly one argument!"; |
|
55 |
throwInvalidUsageException(err); |
|
56 |
} |
|
57 |
||
58 |
stateStr = args[0]; |
|
59 |
transform(stateStr.begin(), stateStr.end(), |
|
60 |
stateStr.begin(), (int (*) (int)) std::toupper); |
|
61 |
||
62 |
if (stateStr == "INIT") { |
|
63 |
state = 0x01; |
|
64 |
} else if (stateStr == "PREOP") { |
|
65 |
state = 0x02; |
|
66 |
} else if (stateStr == "SAFEOP") { |
|
67 |
state = 0x04; |
|
68 |
} else if (stateStr == "OP") { |
|
69 |
state = 0x08; |
|
70 |
} else { |
|
71 |
err << "Invalid state '" << args[0] << "'!"; |
|
72 |
throwInvalidUsageException(err); |
|
73 |
} |
|
74 |
||
75 |
m.open(MasterDevice::ReadWrite); |
|
1151 | 76 |
slaves = selectedSlaves(m); |
1142 | 77 |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
78 |
if (!slaves.size() && getVerbosity() != Quiet) { |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
79 |
cerr << "Warning: Selection matches no slaves!" << endl; |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
80 |
} |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
81 |
|
1151 | 82 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
83 |
m.requestState(si->position, state); |
|
1142 | 84 |
} |
85 |
} |
|
86 |
||
87 |
/*****************************************************************************/ |