CARMA C++
TerminalServer.h
Go to the documentation of this file.
1 #ifndef SZA_UTIL_TERMINALSERVER_H
2 #define SZA_UTIL_TERMINALSERVER_H
3 
11 #include <list>
12 #include <string>
13 #include <stdio.h>
14 
15 #include "carma/szautil/FdSet.h"
16 #include "carma/szautil/LogFile.h"
18 #include "carma/szautil/Runnable.h"
20 #include "carma/szautil/Vector.h"
21 
22 namespace sza {
23  namespace util {
24 
25  class Port;
26  class SignalTask;
27  class SerialClient;
28  class TcpClient;
29  class TcpListener;
30 
31  class TerminalServer : public Runnable {
32 
33  public:
34 
35  enum {
36  CR = '\r',
37  LF = '\n',
38  };
39 
43  TerminalServer(unsigned baudRate, std::string serialPort, bool spawnThread=false);
44 
48  TerminalServer(std::string ipAddress, unsigned port, bool spawnThread=false);
49 
53  virtual ~TerminalServer();
54 
59  void listen(unsigned port, unsigned nClients = 5);
60 
64  void listenToStdin(bool listen);
65 
69  void log(bool log);
70 
74  void strip(std::string strip);
75 
80  void dontStrip(std::string dontStrip);
81 
85  void stripUnprintable(bool strip);
86 
90  void append(std::string append);
91 
92  void setLogFilePrefix(const std::string& prefix);
93 
94  void setLogFileDirectory(const std::string& dir);
95 
96  static RUN_FN(runFn);
97 
101  void run();
102 
103  private:
104 
105  bool hammering_;
106  bool waitingToHammer_;
107 
108  std::list<std::string> hammers_;
109 
110  std::list<std::string>::iterator hammerStep_;
111 
112  TimeVal timeVal_;
113 
114  struct timeval* timeOut_;
115 
116  bool pending_;
117 
121  SignalTask* signalTask_;
122 
126  bool stop_;
127 
132  std::string strip_;
133 
137  std::string append_;
138 
142  TcpListener* listener_;
143 
147  TcpClient* tcpipPort_;
148  SerialClient* serialPort_;
149  Port* port_;
150 
151  FILE* file_;
152 
156  LogFile logFile_;
157 
161  FdSet fdSet_;
162 
166  bool listeningToStdin_;
167 
171  std::list<NetTermHandler*> clients_;
172 
176  void initMembers();
177 
181  void setTcpIp(std::string host, unsigned port);
182 
186  void setSerial(unsigned baudRate, std::string portName);
187 
191  void sendShutdownMsg();
192 
196  void acceptConnection();
197 
201  void readFromPort();
202 
206  void readFromStdin();
207 
211  void writeToStdout(std::string& line);
212 
213  public:
217  void writeToPort(std::string& line);
218  void writeToPort(Vector<unsigned char>& bytes);
219 
220  private:
224  void checkClients();
225 
229  void readFromClient(NetTermHandler* client);
230 
234  static SIGNALTASK_HANDLER_FN(shutDown);
235 
239  void initPort();
240 
244  void openFile(std::string fileName);
245 
249  void readFromFile();
250 
251  bool parseCommand(std::string line);
252 
256  void initHammer();
257 
261  void stepHammer();
262 
263  }; // End class TerminalServer
264 
265  } // End namespace util
266 } // End namespace sza
267 
268 
269 #endif // End #ifndef SZA_UTIL_TERMINALSERVER_H
Tagged: Fri Nov 14 12:39:36 UTC 2003.
Tagged: Tue May 11 14:38:31 PDT 2004.
Tagged: Mon May 10 17:23:41 PDT 2004.
Started: Thu Feb 26 22:08:23 UTC 2004.