author | Florian Pose <fp@igh-essen.com> |
Wed, 18 Feb 2009 13:47:08 +0000 | |
changeset 1355 | df9be2b80b9a |
parent 1337 | 0253c74d0940 |
child 1363 | 11c0b2caa253 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
****************************************************************************/ |
|
6 |
||
7 |
#include <iostream> |
|
1222
7348d6abb6cb
Applied patch by Karsten Schwinne, adding a few header files necessary
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 |
|
1337
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
31 |
<< " STATE can be 'INIT', 'PREOP', 'BOOT', '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; |
|
1337
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
66 |
} else if (stateStr == "BOOT") { |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
67 |
state = 0x03; |
1142 | 68 |
} else if (stateStr == "SAFEOP") { |
69 |
state = 0x04; |
|
70 |
} else if (stateStr == "OP") { |
|
71 |
state = 0x08; |
|
72 |
} else { |
|
73 |
err << "Invalid state '" << args[0] << "'!"; |
|
74 |
throwInvalidUsageException(err); |
|
75 |
} |
|
76 |
||
77 |
m.open(MasterDevice::ReadWrite); |
|
1151 | 78 |
slaves = selectedSlaves(m); |
1142 | 79 |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
80 |
if (!slaves.size() && getVerbosity() != Quiet) { |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
81 |
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
|
82 |
} |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
83 |
|
1151 | 84 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
85 |
m.requestState(si->position, state); |
|
1142 | 86 |
} |
87 |
} |
|
88 |
||
89 |
/*****************************************************************************/ |