My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
TipperCommunicator.h
Go to the documentation of this file.
1 #ifndef GCP_UTIL_TIPPERCOMMUNICATOR_H
2 #define GCP_UTIL_TIPPERCOMMUNICATOR_H
3 
11 #include <list>
12 #include <string>
13 #include <sstream>
14 
15 #include "gcp/util/common/Communicator.h"
16 #include "gcp/util/common/FdSet.h"
17 #include "gcp/util/common/GenericTask.h"
18 #include "gcp/util/common/GenericTaskMsg.h"
19 #include "gcp/util/common/SpawnableTask.h"
20 #include "gcp/util/common/String.h"
21 #include "gcp/util/common/TcpClient.h"
22 #include "gcp/util/common/TimeOut.h"
23 
24 namespace gcp {
25  namespace util {
26 
27  // A utility class for sending messages to the ModemPager task
28 
30  public:
31 
32  enum MsgType {
33  GET_FILE,
34  };
35 
36  union {
37  bool enable;
38  } body;
39 
40  // A type for this message
41 
42  MsgType type;
43  };
44 
46  public SpawnableTask<TipperCommunicatorMsg> {
47  public:
48 
49  //-----------------------------------------------------------------------
50  // Methods for use of this object from an external thread
51  //-----------------------------------------------------------------------
52 
53  // Constructor for external use of this class (ie, run from
54  // another thread)
55 
56  TipperCommunicator(gcp::util::FdSet* fdSet, std::string host);
57 
58  // Return the fd corresponding to the communications connection
59  // to the FTP server
60 
61  int getFtpCommFd();
62 
63  // Return the fd corresponding to the data connection to the FTP
64  // server
65 
66  int getFtpDataFd();
67 
68  //-----------------------------------------------------------------------
69  // Methods for use of this object in a stand-alone thread
70  //-----------------------------------------------------------------------
71 
72  // Constructor for internal use of this class (ie, run in its
73  // own thread). If timeOutIntervalInSeconds is non-zero, this
74  // object will automatically retrieve the tipper log on the
75  // specified interval. Else it will do nothing until told to
76  // retrieve it.
77 
78  TipperCommunicator(std::string host, unsigned timeOutIntervalInSeconds=0);
79 
80  // Tell this object to retrieve the tipper log
81 
82  void getTipperLog();
83 
84  //-----------------------------------------------------------------------
85  // Generic methods
86  //-----------------------------------------------------------------------
87 
88  // Initialize pertinent members of this class to sensible
89  // defaults
90 
91  void initialize(std::string host);
92 
93  // Destructor.
94 
95  virtual ~TipperCommunicator();
96 
97  // Initiate the comms sequence to retrieve the tipper log from
98  // the remote server
99 
101 
102  // Read a line from the ftp server and determine what to do
103 
104  void concatenateString(std::ostringstream& os);
105 
106  // Process a tipper log received from the remote FTP server
107 
108  void processTipperLog();
109 
110  private:
111 
112  // A client for communicating wth the remote FTP server
113 
114  gcp::util::TcpClient* ftpClient_;
115 
116  // A pointer to an FdSet object, possibly external
117 
118  gcp::util::FdSet* fdSetPtr_;
119 
120  // A timeout on which we will retrieve the tipper log from the
121  // remote FTP server
122 
123  TimeOut timeOut_;
124 
125  //-----------------------------------------------------------------------
126  // Methods for use of this object in a stand-alone thread
127  //-----------------------------------------------------------------------
128 
129  void serviceMsgQ();
130  void processMsg(TipperCommunicatorMsg* msg);
131 
132  //-----------------------------------------------------------------------
133  // Generic methods
134  //-----------------------------------------------------------------------
135 
136  static COMM_PARSER_FN(parsePortNumber);
137  void parsePortNumber();
138 
139  static COMM_PARSER_FN(quitFromServer);
140  void quitFromServer();
141 
142  // React to a failure to reply
143 
144  void registerTimeOut();
145 
146  // Terminate a command sequence to the
147 
148  void terminateCommSequence(bool error);
149 
150  // Compile the list of communication/responses needed for
151  // retrieving the tipper log from the remote FTP server
152 
153  void compileGetTipperLogStateMachine();
154 
155  }; // End class TipperCommunicator
156 
157  } // End namespace util
158 } // End namespace gcp
159 
160 
161 
162 #endif // End #ifndef GCP_UTIL_TIPPERCOMMUNICATOR_H
Definition: GenericTaskMsg.h:31
int getFtpCommFd()
Definition: TipperCommunicator.cc:304
virtual ~TipperCommunicator()
Definition: TipperCommunicator.cc:69
Definition: FdSet.h:16
Definition: SpawnableTask.h:31
Definition: Communicator.h:26
Definition: TimeOut.h:20
void processTipperLog()
Definition: TipperCommunicator.cc:213
int getFtpDataFd()
Definition: TipperCommunicator.cc:313
Definition: TcpClient.h:18
void initialize(std::string host)
Definition: TipperCommunicator.cc:16
void initiateGetTipperLogCommSequence()
Definition: TipperCommunicator.cc:82
Definition: TipperCommunicator.h:29
void getTipperLog()
Definition: TipperCommunicator.cc:325
TipperCommunicator(gcp::util::FdSet *fdSet, std::string host)
Definition: TipperCommunicator.cc:41
Definition: TipperCommunicator.h:45