BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
GWSQueuingExporter.h
1 #pragma once
2 
3 #include <set>
4 
5 #include <Poco/Event.h>
6 #include <Poco/Mutex.h>
7 #include <Poco/Timespan.h>
8 
9 #include "core/QueuingExporter.h"
10 #include "loop/StoppableRunnable.h"
11 #include "loop/StopControl.h"
12 #include "server/GWSConnector.h"
13 #include "server/GWSListener.h"
14 
15 namespace BeeeOn {
16 
31  public QueuingExporter,
32  public StoppableRunnable,
33  public GWSListener {
34 public:
35  typedef Poco::SharedPtr<GWSQueuingExporter> Ptr;
36 
38 
44  void setActiveCount(int count);
45 
51  void setAcquireTimeout(const Poco::Timespan &timeout);
52 
57  void setSendFailedDelay(const Poco::Timespan &delay);
58 
62  void setConnector(GWSConnector::Ptr connector);
63 
68  void onConnected(const Address &address) override;
69 
73  void onOther(const GWMessage::Ptr message) override;
74 
75  void run() override;
76  void stop() override;
77 
78 private:
79  size_t m_activeCount;
80  Poco::Timespan m_acquireTimeout;
81  Poco::Timespan m_sendFailedDelay;
82  GWSConnector::Ptr m_connector;
83  StopControl m_stopControl;
84  Poco::Event m_event;
85  std::set<GlobalID> m_acked;
86  Poco::FastMutex m_ackedLock;
87 };
88 
89 }
GWSQueuingExporter implements stop-and-go exporting logic based on the QueuingExporter. The GWSQueuingExporter is to be explicitly registered as a GWSListener to a selected GWSConnector instance. The same GWSConnector instance should then be used for sending of messages.
Definition: GWSQueuingExporter.h:30
void onOther(const GWMessage::Ptr message) override
Receive GWSensorDataConfirm messages via this method.
Definition: GWSQueuingExporter.cpp:139
void setConnector(GWSConnector::Ptr connector)
Configure GWSConnector instance to send data through.
Definition: GWSQueuingExporter.cpp:57
void setAcquireTimeout(const Poco::Timespan &timeout)
Configure how long to wait until the QueuingExporter::acquire() operation returns a result...
Definition: GWSQueuingExporter.cpp:41
Implements Exporter interface and provides SensorData prevents SensorData loss.
Definition: QueuingExporter.h:45
void setActiveCount(int count)
Configure how many SensorData instances to acquire while exporting data, i.e. it denotes a batch size...
Definition: GWSQueuingExporter.cpp:33
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
Definition: GWSListener.h:23
void setSendFailedDelay(const Poco::Timespan &delay)
Configure delay for the next send attempt, if the current send() fails.
Definition: GWSQueuingExporter.cpp:49
void onConnected(const Address &address) override
Wake-up failed sending when it seems that the connection is up again.
Definition: GWSQueuingExporter.cpp:134
void stop() override
Definition: GWSQueuingExporter.cpp:128
Definition: StoppableRunnable.h:8
GWSListener provides an interface for delivering of events and messages related to communication with...
Definition: GWSListener.h:19