author | Florian Pose <fp@igh-essen.com> |
Mon, 28 Jul 2008 12:11:50 +0000 | |
changeset 1159 | 25cc77cf3993 |
parent 1156 | ecaf2a896ea3 |
child 1166 | 006244d53f68 |
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 |
extern unsigned int masterIndex; |
|
20 |
extern int domainIndex; |
|
21 |
extern string dataTypeStr; |
|
22 |
extern bool force; |
|
23 |
||
24 |
/****************************************************************************/ |
|
25 |
||
26 |
class InvalidUsageException: |
|
27 |
public runtime_error |
|
28 |
{ |
|
29 |
friend class Command; |
|
30 |
||
31 |
protected: |
|
32 |
/** Constructor with stringstream parameter. */ |
|
33 |
InvalidUsageException( |
|
34 |
const stringstream &s /**< Message. */ |
|
35 |
): runtime_error(s.str()) {} |
|
36 |
}; |
|
37 |
||
38 |
/****************************************************************************/ |
|
39 |
||
40 |
class CommandException: |
|
41 |
public runtime_error |
|
42 |
{ |
|
43 |
friend class Command; |
|
44 |
||
45 |
protected: |
|
46 |
/** Constructor with stringstream parameter. */ |
|
47 |
CommandException( |
|
48 |
const stringstream &s /**< Message. */ |
|
49 |
): runtime_error(s.str()) {} |
|
50 |
}; |
|
51 |
||
52 |
/****************************************************************************/ |
|
53 |
||
54 |
class Command |
|
55 |
{ |
|
56 |
public: |
|
57 |
Command(const string &, const string &); |
|
58 |
virtual ~Command(); |
|
59 |
||
1151 | 60 |
const string &getName() const; |
61 |
const string &getBriefDescription() const; |
|
62 |
||
1142 | 63 |
enum Verbosity { |
64 |
Quiet, |
|
65 |
Normal, |
|
66 |
Verbose |
|
67 |
}; |
|
68 |
void setVerbosity(Verbosity); |
|
69 |
Verbosity getVerbosity() const; |
|
1151 | 70 |
void setAlias(int); |
71 |
int getAlias() const; |
|
72 |
void setPosition(int); |
|
73 |
int getPosition() const; |
|
1142 | 74 |
|
75 |
bool matchesSubstr(const string &) const; |
|
76 |
bool matchesAbbrev(const string &) const; |
|
77 |
||
78 |
virtual string helpString() const = 0; |
|
79 |
||
80 |
typedef vector<string> StringVector; |
|
81 |
virtual void execute(MasterDevice &, const StringVector &) = 0; |
|
82 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
83 |
static string numericInfo(); |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
84 |
|
1142 | 85 |
protected: |
1151 | 86 |
enum {BreakAfterBytes = 16}; |
87 |
||
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
88 |
void throwInvalidUsageException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
89 |
void throwCommandException(const stringstream &) const; |
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
90 |
void throwSingleSlaveRequired(unsigned int) const; |
1142 | 91 |
|
1151 | 92 |
typedef list<ec_ioctl_slave_t> SlaveList; |
93 |
SlaveList selectedSlaves(MasterDevice &); |
|
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
94 |
typedef list<ec_ioctl_config_t> ConfigList; |
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
95 |
ConfigList selectedConfigs(MasterDevice &); |
1151 | 96 |
|
1146
f18d124d7fbc
Moved slaveState() to Command::alStateString().
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
97 |
static string alStateString(uint8_t); |
1142 | 98 |
|
99 |
private: |
|
100 |
string name; |
|
101 |
string briefDesc; |
|
102 |
Verbosity verbosity; |
|
1151 | 103 |
int alias; |
104 |
int position; |
|
1142 | 105 |
|
106 |
Command(); |
|
107 |
}; |
|
108 |
||
109 |
/****************************************************************************/ |
|
110 |
||
111 |
inline const string &Command::getName() const |
|
112 |
{ |
|
113 |
return name; |
|
114 |
} |
|
115 |
||
116 |
/****************************************************************************/ |
|
117 |
||
118 |
inline const string &Command::getBriefDescription() const |
|
119 |
{ |
|
120 |
return briefDesc; |
|
121 |
} |
|
122 |
||
123 |
/****************************************************************************/ |
|
124 |
||
125 |
inline Command::Verbosity Command::getVerbosity() const |
|
126 |
{ |
|
127 |
return verbosity; |
|
128 |
} |
|
129 |
||
130 |
/****************************************************************************/ |
|
131 |
||
1151 | 132 |
inline int Command::getAlias() const |
133 |
{ |
|
134 |
return alias; |
|
135 |
} |
|
136 |
||
137 |
/****************************************************************************/ |
|
138 |
||
139 |
inline int Command::getPosition() const |
|
140 |
{ |
|
141 |
return position; |
|
142 |
} |
|
143 |
||
144 |
/****************************************************************************/ |
|
145 |
||
1142 | 146 |
#endif |