My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
Instruction.h
Go to the documentation of this file.
1 // $Id: Instruction.h,v 1.1.1.1 2009/07/06 23:57:25 eml Exp $
2 
3 #ifndef GCP_UTIL_INSTRUCTION_H
4 #define GCP_UTIL_INSTRUCTION_H
5 
15 #include "gcp/util/common/TimeVal.h"
16 
17 #define INSTRUCTION(fn) gcp::util::Instruction::State (fn)(void* args)
18 
19 namespace gcp {
20  namespace util {
21 
22  // A class for managing a single instruction of a command
23 
24  class Instruction {
25  public:
26 
27  enum State {
28  DONE,
29  AGAIN,
30  FAILED
31  };
32 
36  Instruction(INSTRUCTION(*fn), void* args, TimeVal timeToNext, TimeVal timeToRetry);
37  Instruction(INSTRUCTION(*fn), void* args, TimeVal timeToNext);
38  Instruction(INSTRUCTION(*fn), void* args=0);
39  Instruction();
40 
44  virtual ~Instruction();
45 
46  // Execute this instruction. Method should return true if the
47  // instruction has successfully executed.
48 
49  virtual State execute(TimeVal& timeOut);
50 
51  void initialize();
52 
53  void setTimeToNext(TimeVal& tVal);
54  void setTimeToRetry(TimeVal& tVal);
55 
56  private:
57 
58  // A function to call
59 
60  INSTRUCTION(*fn_);
61 
62  // The arguments to call it with
63 
64  void* args_;
65 
66  // The time we should wait before executing another instruction
67  // after this one
68 
69  TimeVal timeToNext_;
70  TimeVal timeToRetry_;
71 
72  }; // End class Instruction
73 
74  } // End namespace util
75 } // End namespace gcp
76 
77 
78 
79 #endif // End #ifndef GCP_UTIL_INSTRUCTION_H
virtual State execute(TimeVal &timeOut)
Definition: Instruction.cc:80
Definition: Instruction.h:24
Instruction()
Definition: Instruction.cc:59
Definition: TimeVal.h:55
virtual ~Instruction()
Definition: Instruction.cc:75