OpenDaVINCI  4.16.0
TCPConnection.h
Go to the documentation of this file.
1 
20 #ifndef OPENDAVINCI_CORE_IO_TCP_TCPCONNECTION_H_
21 #define OPENDAVINCI_CORE_IO_TCP_TCPCONNECTION_H_
22 
23 #include <sstream>
24 #include <string>
25 
30 
31 namespace odcore { namespace io { class ConnectionListener; } }
32 namespace odcore { namespace io { class StringListener; } }
33 
34 namespace odcore {
35  namespace io {
36  namespace tcp {
37 
38  using namespace std;
39 
41  private:
48 
54  TCPConnection& operator=(const TCPConnection &);
55 
56  protected:
60  TCPConnection();
61 
62  public:
63  virtual ~TCPConnection();
64 
70  void send(const string &data);
71 
78  void setConnectionListener(ConnectionListener* cl);
79 
86  void setStringListener(StringListener* listener);
87 
91  virtual void start() = 0;
92 
96  virtual void stop() = 0;
97 
103  bool isRaw() const;
104 
109  void setRaw(const bool &raw);
110 
111  protected:
124  void receivedString(const string &partialData);
125 
133  virtual void sendImplementation(const string &data) = 0;
134 
139  void invokeConnectionListener();
140 
141  private:
142  bool hasCompleteData();
143 
148  void invokeStringListener(const string& data);
149 
150  odcore::base::Mutex m_connectionListenerMutex;
151  ConnectionListener* m_connectionListener;
152 
153  odcore::base::Mutex m_stringListenerMutex;
154  StringListener *m_stringListener;
155 
156  odcore::base::Mutex m_partialDataMutex;
157  stringstream m_partialData;
158 
159  bool m_raw;
160  };
161 
162  }
163  }
164 }
165 
166 #endif /* OPENDAVINCI_CORE_IO_TCP_TCPCONNECTION_H_ */
Definition: base/Mutex.h:49
Definition: ConnectionListener.h:31
#define OPENDAVINCI_API
Definition: opendavinci.h:67
Definition: StringListener.h:36
Definition: StringObserver.h:34
Definition: TCPConnection.h:40
Definition: ConnectionObserver.h:34