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