Terminus
networkendpoint.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QObject>
4 
5 class QString;
6 class QTcpSocket;
7 
8 namespace terminus {
9 
10 class AbstractCommand;
11 
19 class NetworkEndpoint : public QObject
20 {
21  Q_OBJECT
22 public:
23  enum class State
24  {
25  Listening,
26  Connected,
28  };
29 
30 public:
31  NetworkEndpoint(QObject * parent = 0);
32  virtual ~NetworkEndpoint();
33 
38  void sendCommand(AbstractCommand * command);
39 
43  void disconnect();
44 
48  State state();
49 
50 signals:
55  void receivedCommand(AbstractCommand * command);
56 
61  void stateChanged(State newState);
62 
63 protected:
64  QTcpSocket * socket();
65  void setSocket(QTcpSocket * socket);
66 
67  void enterState(State state);
68 
69  QString serializeCommand(AbstractCommand * command);
70  AbstractCommand * deserializeCommand(const QString & message);
71 
72  void sendMessage(const QString & message);
73 
74 protected slots:
75  void onDataReceived();
76 
77 protected:
79  QTcpSocket * m_socket;
80 };
81 
82 }
The NetworkEndpoint class provides a common interface that NetworkServer and NetworkClient implement...
Definition: networkendpoint.h:19
void disconnect()
disconnect the underlying socket
Definition: networkendpoint.cpp:42
void setSocket(QTcpSocket *socket)
Definition: networkendpoint.cpp:60
QTcpSocket * socket()
Definition: networkendpoint.cpp:55
void sendCommand(AbstractCommand *command)
serializes command and sends it to the opposite NetworkEndpoint
Definition: networkendpoint.cpp:37
State
Definition: networkendpoint.h:23
void enterState(State state)
Definition: networkendpoint.cpp:65
virtual ~NetworkEndpoint()
Definition: networkendpoint.cpp:32
AbstractCommand * deserializeCommand(const QString &message)
Definition: networkendpoint.cpp:84
State state()
Definition: networkendpoint.cpp:50
NetworkEndpoint(QObject *parent=0)
Definition: networkendpoint.cpp:25
void onDataReceived()
Definition: networkendpoint.cpp:143
void sendMessage(const QString &message)
Definition: networkendpoint.cpp:122
QString serializeCommand(AbstractCommand *command)
Definition: networkendpoint.cpp:71
QTcpSocket * m_socket
Definition: networkendpoint.h:79
Definition: eventhandler.cpp:18
State m_state
Definition: networkendpoint.h:78
void receivedCommand(AbstractCommand *command)
fired for every AbstractCommand received from the opposite NetworkEndpoint
The AbstractCommand class defines the interface that every command has to implement.
Definition: abstractcommand.h:23
void stateChanged(State newState)
fired after state of this NetworkEndpoint is changed