My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
Command.h
Go to the documentation of this file.
1 // $Id: Command.h,v 1.1.1.1 2009/07/06 23:57:25 eml Exp $
2 
3 #ifndef GCP_UTIL_COMMAND_H
4 #define GCP_UTIL_COMMAND_H
5 
15 #include "gcp/util/common/Instruction.h"
16 
17 #include <string>
18 #include <vector>
19 
20 // A function to be called when the command has completed
21 
22 #define COMMAND_DONE_HANDLER(fn) void (fn)(void* args)
23 
24 // A function to be called if the command has failed
25 
26 #define COMMAND_FAILED_HANDLER(fn) void (fn)(void* args)
27 
28 namespace gcp {
29  namespace util {
30 
31  // A class for managing canned commands that can be executed by
32  // tasks via their message queues.
33 
34  class Command {
35  public:
36 
40  Command();
41 
45  virtual ~Command();
46 
50  void installDoneHandler(COMMAND_DONE_HANDLER(*handler),
51  void* args=0);
52 
56  void installFailedHandler(COMMAND_FAILED_HANDLER(*handler),
57  void* args=0);
58 
59  // Insert another instruction into our list
60 
61  Instruction* insert(Instruction instruction);
62 
63  // Insert another command into our list
64 
65  void insert(Command& command);
66 
67  void run();
68 
69  TimeVal& timeOut();
70 
71  bool active();
72 
73  void restart(struct timeval* timeOut);
74 
75  // Execute the next instruction of this command
76 
77  void executeNextInstruction(TimeVal& timeOut, bool setToValue);
78 
79  protected:
80 
81  bool active_;
82 
83  COMMAND_DONE_HANDLER(*doneHandler_);
84  void* doneArgs_;
85 
86  COMMAND_FAILED_HANDLER(*failedHandler_);
87  void* failedArgs_;
88 
89  // A name for this command
90 
91  std::string name_;
92 
93  // A vector of instructions
94 
95  std::vector<Instruction> instructions_;
96 
97  // The current instruction
98 
99  std::vector<Instruction>::iterator nextInstruction_;
100 
101  TimeVal lastTime_;
102  TimeVal currTime_;
103  TimeVal diff_;
104  TimeVal timeOut_;
105 
106  void initialize();
107  void reset();
108  bool isComplete();
109 
110  // Register that this command has completed
111 
112  void registerCompletion();
113 
114  // Register that this command has failed
115 
116  void registerFailure();
117 
118  }; // End class Command
119 
120  } // End namespace util
121 } // End namespace gcp
122 
123 
124 
125 #endif // End #ifndef GCP_UTIL_COMMAND_H
void registerCompletion()
Definition: Command.cc:188
Definition: Command.h:34
Definition: Instruction.h:24
void executeNextInstruction(TimeVal &timeOut, bool setToValue)
Definition: Command.cc:89
void reset()
Definition: Command.cc:47
void installFailedHandler(COMMAND_FAILED_HANDLER(*handler), void *args=0)
Definition: Command.cc:171
void installDoneHandler(COMMAND_DONE_HANDLER(*handler), void *args=0)
Definition: Command.cc:161
void run()
Definition: Command.cc:151
void restart(struct timeval *timeOut)
Definition: Command.cc:56
Instruction * insert(Instruction instruction)
Definition: Command.cc:70
bool isComplete()
Definition: Command.cc:180
Definition: TimeVal.h:55
Command()
Definition: Command.cc:12
virtual ~Command()
Definition: Command.cc:33
void registerFailure()
Definition: Command.cc:201
void initialize()
Definition: Command.cc:38