BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
GWSConnector.h
1 #pragma once
2 
3 #include <Poco/SharedPtr.h>
4 #include <Poco/Timespan.h>
5 
6 #include "gwmessage/GWMessage.h"
7 #include "server/GWSListener.h"
8 #include "util/EventSource.h"
9 
10 namespace BeeeOn {
11 
21 class GWSConnector {
22 public:
23  typedef Poco::SharedPtr<GWSConnector> Ptr;
24 
25  virtual ~GWSConnector();
26 
33  virtual void send(const GWMessage::Ptr message) = 0;
34 
39  void addListener(GWSListener::Ptr listener);
40 
44  void clearListeners();
45 
50  void setEventsExecutor(AsyncExecutor::Ptr executor);
51 
52 protected:
53  template <typename Event, typename Method>
54  void fireEvent(const Event &e, const Method &m)
55  {
56  m_eventSource.fireEvent(e, m);
57  }
58 
59  void fireReceived(const GWMessage::Ptr message);
60 
61 private:
62  EventSource<GWSListener> m_eventSource;
63 };
64 
65 }
void addListener(GWSListener::Ptr listener)
Register a GWSListener instance that would receive events related to the communication.
Definition: GWSConnector.cpp:36
EventSource implements common logic for firing events to listeners.
Definition: EventSource.h:24
virtual void send(const GWMessage::Ptr message)=0
Send the given message to the remote server. The actual sending operation might be delayed and thus t...
void setEventsExecutor(AsyncExecutor::Ptr executor)
Configure an AsyncExecutor instance that would be used for GWSListener events delivery.
Definition: GWSConnector.cpp:46
GWSConnector is an abstract class that defines an API for communication with a remote server...
Definition: GWSConnector.h:21
void clearListeners()
Remove all registered listeners.
Definition: GWSConnector.cpp:41