All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TcpListener.h
1 // Copyright eeGeo Ltd (2012-2016), All Rights Reserved
2 
3 #pragma once
4 
5 #include "ITcpListener.h"
6 #include "ITcpSocket.h"
7 #include "TcpListenerState.h"
8 #include "TcpClientCallback.h"
9 #include "ITcpClient.h"
10 #include "CallbackCollection.h"
11 
12 #include <vector>
13 
14 namespace Eegeo
15 {
16  namespace Networking
17  {
18  class TcpListener: public ITcpListener, protected Eegeo::NonCopyable
19  {
20  public:
21  TcpListener(ITcpSocket* pListenSocket);
22  ~TcpListener();
23 
24  void StartListening(int port);
25  void Update();
26  void StopListening();
27 
28  const TcpListenerState::Values GetState() const;
29  int GetPort() const;
30 
31  void AddClientConnectedCallback(ITcpClientCallback& callback);
32  void RemoveClientConnectedCallback(ITcpClientCallback& callback);
33  void AddClientDisconnectedCallback(ITcpClientCallback& callback);
34  void RemoveClientDisconnectedCallback(ITcpClientCallback& callback);
35 
36  private:
37  void AcceptNewClient();
38 
39  ITcpSocket* m_pListenSocket;
40  TcpListenerState::Values m_state;
41  int m_port;
42  std::vector<ITcpClient*> m_clients;
43 
44  Helpers::CallbackCollection1<ITcpClient> m_connectedCallbacks;
45  Helpers::CallbackCollection1<ITcpClient> m_disconnectedCallbacks;
46  };
47  }
48 }