CARMA C++
RemoteSensorCoProc.h
Go to the documentation of this file.
1 #ifndef SZA_UTIL_REMOTESENSORCOPROC_H
2 #define SZA_UTIL_REMOTESENSORCOPROC_H
3 
11 #include <list>
12 #include <string>
13 #include <sstream>
14 
15 #include "carma/szautil/CoProc.h"
17 #include "carma/szautil/FdSet.h"
18 #include "carma/szautil/Port.h"
20 #include "carma/szautil/String.h"
21 
22 namespace sza {
23  namespace util {
24 
25  //-----------------------------------------------------------------------
26  // RemoteSensorCoProc class is defined here
27  //-----------------------------------------------------------------------
28 
29  class RemoteSensorCoProc : public Communicator, public RemoteSensor {
30  public:
31 
32  //------------------------------------------------------------
33  // Methods for use of this object in a stand-alone thread
34  //------------------------------------------------------------
35 
36  // Constructor for internal use of this class (ie, run in its
37  // own thread). If timeOutIntervalInSeconds is non-zero, this
38  // object will automatically retrieve the device status on the
39  // specified interval. Else it will do nothing until told to
40  // retrieve it.
41 
42  RemoteSensorCoProc(std::string host,
43  unsigned timeoutIntervalInSeconds=0);
44 
45  RemoteSensorCoProc(std::string host,
46  SystemStatusSubsystemMutex* ms,
47  carma::monitor::MonitorPointBool& mpIsReachable,
49  unsigned timeoutIntervalInSeconds=0);
50 
51  RemoteSensorCoProc(std::string host,
52  SystemStatusSubsystemMutex* ms,
53  carma::monitor::MonitorPointBool& mpHostIsReachable,
56  carma::monitor::MonitorPointEnum& mcPlaceStatus,
59  sza::util::Temperature& minTemp,
60  sza::util::Temperature& maxTemp,
61  unsigned timeoutIntervalInSeconds=0);
62 
63  // Destructor.
64 
65  virtual ~RemoteSensorCoProc();
66 
67  protected:
68 
69  //------------------------------------------------------------
70  // Methods that should be overloaded by inheritors wanting to
71  // use the CoProc class for processing feedback from generic
72  // types of commands
73  //------------------------------------------------------------
74 
75  void executeReadSensor();
76 
77  // Compile the list of communication/responses needed for
78  // retrieving the device status from the remote server
79 
80  virtual void compileGetDeviceStatusStateMachine() = 0;
81 
82  // Assemble the command string to be issued
83 
84  virtual std::string getCommandString() = 0;
85 
86  // Define what it means to parse the return message
87 
88  virtual void processDeviceStatus() = 0;
89 
90  static COMM_PARSER_FN(parseDeviceStatus);
91 
92  private:
93 
94  //------------------------------------------------------------
95  // Generic methods
96  //------------------------------------------------------------
97 
98  // Initialize pertinent members of this class to sensible
99  // defaults
100 
101  void initialize();
102 
103  // Initiate the comms sequence to retrieve the tipper log from
104  // the remote server
105 
106  void initiateGetDeviceStatusCommSequence();
107 
108  // Process a status message recieved from the server
109 
110  void connect();
111  void disconnect();
112 
113  // Return the read fd associated with the server connection
114 
115  int getFd();
116 
117  // Write a string to the server
118 
119  void writeString(std::string);
120 
121  // Concatenate a string received from the server
122 
123  void concatenateString(std::ostringstream& os);
124 
125  //------------------------------------------------------------
126  // Methods for use of this object in a stand-alone thread
127  //------------------------------------------------------------
128 
129  void serviceMsgQ();
130 
131  //------------------------------------------------------------
132  // Generic methods
133  //------------------------------------------------------------
134 
135  // React to a timeout during communication
136 
137  void registerTimeOut();
138 
139  // Terminate a command sequence to the
140 
141  void terminateCommSequence(bool error);
142 
143  // The process that will communicate with the telnet server
144 
145  CoProc* coProc_;
146 
147  sza::util::Port errPort_;
148  sza::util::Port readPort_;
149  sza::util::Port writePort_;
150 
151  bool connected_;
152 
153  }; // End class RemoteSensorCoProc
154 
155  } // End namespace util
156 } // End namespace sza
157 
158 
159 
160 #endif // End #ifndef SZA_UTIL_REMOTESENSORCOPROC_H
Tagged: Fri Feb 9 09:32:45 NZDT 2007.
Abstract base class for any enumerated constants, like state machines.
Tagged: Mon Jul 19 14:47:35 PDT 2004.
Tagged: Mon May 10 16:41:20 PDT 2004.
Started: Thu Feb 26 22:08:23 UTC 2004.
Tagged: Tue Nov 2 14:28:38 PDT 2010.
Absolute time value monitor point.
Tagged: Wed May 12 09:30:13 PDT 2004.