My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
ModemPager.h
Go to the documentation of this file.
1 // $Id: ModemPager.h,v 1.1.1.1 2009/07/06 23:57:25 eml Exp $
2 
3 #ifndef GCP_UTIL_MODEMPAGER_H
4 #define GCP_UTIL_MODEMPAGER_H
5 
16 #include <iostream>
17 
18 
19 #include "gcp/util/common/GenericTask.h"
20 #include "gcp/util/common/GenericTaskMsg.h"
21 #include "gcp/util/common/Runnable.h"
22 #include "gcp/util/common/SpawnableTask.h"
23 #include "gcp/util/common/TimeVal.h"
24 
25 #include "gcp/control/code/unix/libunix_src/common/lprintf.h"
26 
27 namespace gcp {
28  namespace util {
29 
30  // A utility class for sending messages to the ModemPager task
31 
32  class ModemPagerMsg : public GenericTaskMsg {
33  public:
34 
35  enum MsgType {
36  ACK,
37  ALIVE,
38  ERROR,
39  ENABLE,
40  RESET,
41  START,
42  STATUS,
43  STOP
44  };
45 
46  union {
47  bool enable;
48  } body;
49 
50  // A type for this message
51 
52  MsgType type;
53  };
54 
58  class ModemPager : public SpawnableTask<ModemPagerMsg> {
59  public:
60 
61  enum State {
62  STATE_NORM,
63  STATE_ESC
64  };
65 
66  enum SpecialChars {
67  ESC = 27,
68  TERM = 109
69  };
70 
74  ModemPager();
75 
79  ModemPager(FILE* stdoutStream, LOG_DISPATCHER(*stdoutDispatcher),
80  void* stdoutContext,
81  FILE* stderrStream, LOG_DISPATCHER(*stderrDispatcher),
82  void* stderrContext);
83 
87  virtual ~ModemPager();
88 
89  // Activate the pager
90 
91  void start();
92  void stop();
93  void acknowledge();
94  void activate(std::string message);
95  void enable(bool enable);
96  void sendAlive();
97  void requestStatus();
98  void reset();
99 
100  private:
101 
102  FILE* stdoutStream_;
103  FILE* stderrStream_;
104  LOG_DISPATCHER(*stdoutDispatcher_);
105  LOG_DISPATCHER(*stderrDispatcher_);
106  void* stdoutContext_;
107  void* stderrContext_;
108 
109  std::string errorMessage_;
110  Mutex msgLock_;
111 
112  TimeVal aliveTimeOut_;
113 
114  void serviceMsgQ(void);
115  void processMsg(ModemPagerMsg* msg);
116 
117  void executeAcknowledge();
118  void executeAlive();
119  void executeError();
120  void executeEnable(bool enable);
121  void executeReset();
122  void executeStart();
123  void executeStatus();
124  void executeStop();
125 
126  void spawnAndCapture(std::string script, bool log=false);
127 
128  }; // End class ModemPager
129 
130  } // End namespace util
131 } // End namespace gcp
132 
133 
134 
135 #endif // End #ifndef GCP_UTIL_MODEMPAGER_H
Definition: GenericTaskMsg.h:31
Definition: SpawnableTask.h:31
Definition: Mutex.h:16
ModemPager()
Definition: ModemPager.cc:15
Definition: TimeVal.h:55
Definition: ModemPager.h:58
virtual ~ModemPager()
Definition: ModemPager.cc:56
Definition: ModemPager.h:32