CARMA C++
Client.h
1 #ifndef SZA_UTIL_CLIENT_H
2 #define SZA_UTIL_CLIENT_H
3 
11 #include "carma/szautil/FdSet.h"
12 #include "carma/szautil/NetDat.h"
14 #include "carma/szautil/Runnable.h"
17 #include "carma/szautil/TimeVal.h"
18 
19 namespace sza {
20  namespace util {
21 
22  class SignalTask;
23 
24  class Client : public Runnable {
25  public:
26 
30  Client(bool spawn, std::string host, unsigned connectPort,
31  unsigned readBufSize=0, unsigned sendBufSize=0, bool spawnSignalHandler=false);
32 
36  virtual ~Client();
37 
41  void run();
42 
43  void setReadBufSize(unsigned size);
44  void setSendBufSize(unsigned size);
45 
46  protected:
47 
48  // Method called when data have been completely read from the server
49 
50  void readServerData(NetHandler& handler);
51 
52  // Send data to the server
53 
54  void sendServerData(NetDat& dat);
55 
56  // Method called when data have been packed in our bytes array
57 
58  virtual void processServerData() {COUT("Inside base-class procesServerData");};
59 
60  TimeVal timeOut_;
61  struct timeval* timeOutPtr_;
62 
63  // A byte array into which serialized data will be returned
64 
65  std::vector<unsigned char> bytes_;
66 
67  // The size in bytes of the last message read. This is to allow
68  // for the case where a message is smaller than the allocated
69  // bytes_ array.
70 
71  unsigned sizeInBytesOfLastMessage_;
72 
76  SignalTask* signalTask_;
77  bool spawnSignalTask_;
78 
79  private:
80 
81  unsigned sendBufSize_;
82  unsigned readBufSize_;
83 
84  bool stop_;
85 
86  // The connection manager
87 
88  TcpClient tcp_;
89 
90  NetHandler handler_;
91 
92  FdSet fdSet_;
93 
94  void initMembers(std::string host, unsigned port,
95  unsigned readBufSize, unsigned sendBufSize);
96 
97  // A run method to be called from pthread_start()
98 
99  static RUN_FN(runFn);
100 
101  // A shutdown method
102 
103  static SIGNALTASK_HANDLER_FN(shutDown);
104 
105  static NET_READ_HANDLER(readHandler);
106  static NET_SEND_HANDLER(sendHandler);
107  static NET_ERROR_HANDLER(errHandler);
108 
109  void connect();
110  void disconnect();
111 
112  }; // End class Client
113 
114  } // End namespace util
115 } // End namespace sza
116 
117 
118 #endif // End #ifndef SZA_UTIL_CLIENT_H
Tagged: Wed Jul 6 13:41:09 PDT 2005.
Tagged: Fri Nov 14 12:39:36 UTC 2003.
Tagged: Sun Apr 4 22:36:40 UTC 2004.
Tagged: Fri Nov 14 12:39:38 UTC 2003.
Started: Sat Mar 6 14:44:17 UTC 2004.
Started: Thu Feb 26 22:08:23 UTC 2004.