author | Florian Pose <fp@igh-essen.com> |
Tue, 24 Feb 2009 08:53:13 +0000 | |
changeset 1356 | ce338c278809 |
parent 1335 | 09c6fce1ae45 |
child 1363 | 11c0b2caa253 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
****************************************************************************/ |
|
6 |
||
7 |
#ifndef __COMMAND_H__ |
|
8 |
#define __COMMAND_H__ |
|
9 |
||
10 |
#include <stdexcept> |
|
11 |
#include <vector> |
|
1151 | 12 |
#include <list> |
1142 | 13 |
using namespace std; |
14 |
||
15 |
#include "MasterDevice.h" |
|
16 |
||
17 |
/****************************************************************************/ |
|
18 |
||
19 |
class InvalidUsageException: |
|
20 |
public runtime_error |
|
21 |
{ |
|
22 |
friend class Command; |
|
23 |
||
24 |
protected: |
|
25 |
/** Constructor with stringstream parameter. */ |
|
26 |
InvalidUsageException( |
|
27 |
const stringstream &s /**< Message. */ |
|
28 |
): runtime_error(s.str()) {} |
|
29 |
}; |
|
30 |
||
31 |
/****************************************************************************/ |
|
32 |
||
33 |
class CommandException: |
|
34 |
public runtime_error |
|
35 |
{ |
|
36 |
friend class Command; |
|
37 |
||
38 |
protected: |
|
39 |
/** Constructor with stringstream parameter. */ |
|
40 |
CommandException( |
|
41 |
const stringstream &s /**< Message. */ |
|
42 |
): runtime_error(s.str()) {} |
|
43 |
}; |
|
44 |
||
45 |
/****************************************************************************/ |
|
46 |
||
47 |
class Command |
|
48 |
{ |
|
49 |
public: |
|
50 |
Command(const string &, const string &); |
|
51 |
virtual ~Command(); |
|
52 |
||
1151 | 53 |
const string &getName() const; |
54 |
const string &getBriefDescription() const; |
|
55 |
||
1142 | 56 |
enum Verbosity { |
57 |
Quiet, |
|
58 |
Normal, |
|
59 |
Verbose |
|
60 |
}; |
|
61 |
void setVerbosity(Verbosity); |
|
62 |
Verbosity getVerbosity() const; |
|
1151 | 63 |
void setAlias(int); |
64 |
int getAlias() const; |
|
65 |
void setPosition(int); |
|
66 |
int getPosition() const; |
|
1166 | 67 |
void setDomain(int); |
68 |
int getDomain() const; |
|
69 |
void setDataType(const string &); |
|
70 |
const string &getDataType() const; |
|
71 |
void setForce(bool); |
|
72 |
bool getForce() const; |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
73 |
void setOutputFile(const string &); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
74 |
const string &getOutputFile() const; |
1142 | 75 |
|
76 |
bool matchesSubstr(const string &) const; |
|
77 |
bool matchesAbbrev(const string &) const; |
|
78 |
||
79 |
virtual string helpString() const = 0; |
|
80 |
||
81 |
typedef vector<string> StringVector; |
|
82 |
virtual void execute(MasterDevice &, const StringVector &) = 0; |
|
83 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
84 |
static string numericInfo(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
85 |
|
1142 | 86 |
protected: |
1151 | 87 |
enum {BreakAfterBytes = 16}; |
88 |
||
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
89 |
void throwInvalidUsageException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
90 |
void throwCommandException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
91 |
void throwSingleSlaveRequired(unsigned int) const; |
1142 | 92 |
|
1151 | 93 |
typedef list<ec_ioctl_slave_t> SlaveList; |
94 |
SlaveList selectedSlaves(MasterDevice &); |
|
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
95 |
typedef list<ec_ioctl_config_t> ConfigList; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
96 |
ConfigList selectedConfigs(MasterDevice &); |
1166 | 97 |
typedef list<ec_ioctl_domain_t> DomainList; |
98 |
DomainList selectedDomains(MasterDevice &); |
|
1151 | 99 |
|
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
100 |
static string alStateString(uint8_t); |
1142 | 101 |
|
102 |
private: |
|
103 |
string name; |
|
104 |
string briefDesc; |
|
105 |
Verbosity verbosity; |
|
1151 | 106 |
int alias; |
107 |
int position; |
|
1166 | 108 |
int domain; |
109 |
string dataType; |
|
110 |
bool force; |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
111 |
string outputFile; |
1142 | 112 |
|
113 |
Command(); |
|
114 |
}; |
|
115 |
||
116 |
/****************************************************************************/ |
|
117 |
||
118 |
inline const string &Command::getName() const |
|
119 |
{ |
|
120 |
return name; |
|
121 |
} |
|
122 |
||
123 |
/****************************************************************************/ |
|
124 |
||
125 |
inline const string &Command::getBriefDescription() const |
|
126 |
{ |
|
127 |
return briefDesc; |
|
128 |
} |
|
129 |
||
130 |
/****************************************************************************/ |
|
131 |
||
132 |
inline Command::Verbosity Command::getVerbosity() const |
|
133 |
{ |
|
134 |
return verbosity; |
|
135 |
} |
|
136 |
||
137 |
/****************************************************************************/ |
|
138 |
||
1151 | 139 |
inline int Command::getAlias() const |
140 |
{ |
|
141 |
return alias; |
|
142 |
} |
|
143 |
||
144 |
/****************************************************************************/ |
|
145 |
||
146 |
inline int Command::getPosition() const |
|
147 |
{ |
|
148 |
return position; |
|
149 |
} |
|
150 |
||
151 |
/****************************************************************************/ |
|
152 |
||
1166 | 153 |
inline int Command::getDomain() const |
154 |
{ |
|
155 |
return domain; |
|
156 |
} |
|
157 |
||
158 |
/****************************************************************************/ |
|
159 |
||
160 |
inline const string &Command::getDataType() const |
|
161 |
{ |
|
162 |
return dataType; |
|
163 |
} |
|
164 |
||
165 |
/****************************************************************************/ |
|
166 |
||
167 |
inline bool Command::getForce() const |
|
168 |
{ |
|
169 |
return force; |
|
170 |
} |
|
171 |
||
172 |
/****************************************************************************/ |
|
173 |
||
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
174 |
inline const string &Command::getOutputFile() const |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
175 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
176 |
return outputFile; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
177 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
178 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
179 |
/****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
180 |
|
1142 | 181 |
#endif |