author | Florian Pose <fp@igh-essen.com> |
Thu, 02 Oct 2008 07:16:17 +0000 | |
branch | stable-1.4 |
changeset 1645 | bbdaddf33131 |
parent 1166 | 006244d53f68 |
child 1335 | 09c6fce1ae45 |
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; |
|
1142 | 73 |
|
74 |
bool matchesSubstr(const string &) const; |
|
75 |
bool matchesAbbrev(const string &) const; |
|
76 |
||
77 |
virtual string helpString() const = 0; |
|
78 |
||
79 |
typedef vector<string> StringVector; |
|
80 |
virtual void execute(MasterDevice &, const StringVector &) = 0; |
|
81 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
82 |
static string numericInfo(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
83 |
|
1142 | 84 |
protected: |
1151 | 85 |
enum {BreakAfterBytes = 16}; |
86 |
||
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
87 |
void throwInvalidUsageException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
88 |
void throwCommandException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
89 |
void throwSingleSlaveRequired(unsigned int) const; |
1142 | 90 |
|
1151 | 91 |
typedef list<ec_ioctl_slave_t> SlaveList; |
92 |
SlaveList selectedSlaves(MasterDevice &); |
|
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
93 |
typedef list<ec_ioctl_config_t> ConfigList; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
94 |
ConfigList selectedConfigs(MasterDevice &); |
1166 | 95 |
typedef list<ec_ioctl_domain_t> DomainList; |
96 |
DomainList selectedDomains(MasterDevice &); |
|
1151 | 97 |
|
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
98 |
static string alStateString(uint8_t); |
1142 | 99 |
|
100 |
private: |
|
101 |
string name; |
|
102 |
string briefDesc; |
|
103 |
Verbosity verbosity; |
|
1151 | 104 |
int alias; |
105 |
int position; |
|
1166 | 106 |
int domain; |
107 |
string dataType; |
|
108 |
bool force; |
|
1142 | 109 |
|
110 |
Command(); |
|
111 |
}; |
|
112 |
||
113 |
/****************************************************************************/ |
|
114 |
||
115 |
inline const string &Command::getName() const |
|
116 |
{ |
|
117 |
return name; |
|
118 |
} |
|
119 |
||
120 |
/****************************************************************************/ |
|
121 |
||
122 |
inline const string &Command::getBriefDescription() const |
|
123 |
{ |
|
124 |
return briefDesc; |
|
125 |
} |
|
126 |
||
127 |
/****************************************************************************/ |
|
128 |
||
129 |
inline Command::Verbosity Command::getVerbosity() const |
|
130 |
{ |
|
131 |
return verbosity; |
|
132 |
} |
|
133 |
||
134 |
/****************************************************************************/ |
|
135 |
||
1151 | 136 |
inline int Command::getAlias() const |
137 |
{ |
|
138 |
return alias; |
|
139 |
} |
|
140 |
||
141 |
/****************************************************************************/ |
|
142 |
||
143 |
inline int Command::getPosition() const |
|
144 |
{ |
|
145 |
return position; |
|
146 |
} |
|
147 |
||
148 |
/****************************************************************************/ |
|
149 |
||
1166 | 150 |
inline int Command::getDomain() const |
151 |
{ |
|
152 |
return domain; |
|
153 |
} |
|
154 |
||
155 |
/****************************************************************************/ |
|
156 |
||
157 |
inline const string &Command::getDataType() const |
|
158 |
{ |
|
159 |
return dataType; |
|
160 |
} |
|
161 |
||
162 |
/****************************************************************************/ |
|
163 |
||
164 |
inline bool Command::getForce() const |
|
165 |
{ |
|
166 |
return force; |
|
167 |
} |
|
168 |
||
169 |
/****************************************************************************/ |
|
170 |
||
1142 | 171 |
#endif |