BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
AbstractGWSConnector.h
1 #pragma once
2 
3 #include <queue>
4 
5 #include <Poco/Event.h>
6 #include <Poco/Mutex.h>
7 
8 #include "gwmessage/GWMessage.h"
9 #include "server/GWSConnector.h"
10 #include "server/GWSPriorityAssigner.h"
11 #include "util/Loggable.h"
12 
13 namespace BeeeOn {
14 
39  public GWSConnector,
40  protected Loggable {
41 public:
43 
44  void setOutputsCount(int count);
45  void setPriorityAssigner(GWSPriorityAssigner::Ptr assigner);
46 
51  void setupQueues();
52 
57  void send(const GWMessage::Ptr message) override;
58 
59 protected:
63  size_t selectOutput() const;
64 
69  void updateOutputs(size_t i);
70 
75  bool outputValid(size_t i) const;
76 
80  GWMessage::Ptr peekOutput(size_t i) const;
81 
86  void popOutput(size_t i);
87 
88 protected:
89  Poco::Event m_outputsUpdated;
90  mutable Poco::Mutex m_outputLock;
91 
92 private:
93  unsigned int m_outputsCount;
94  std::vector<std::queue<GWMessage::Ptr>> m_outputs;
95  std::vector<size_t> m_outputsStatus;
96  GWSPriorityAssigner::Ptr m_priorityAssigner;
97 };
98 
99 }
void popOutput(size_t i)
Pop the first (oldest) message in the queue of the given index.
Definition: AbstractGWSConnector.cpp:143
Most GWSConnector implementations would solve the issue of sending prioritization and asynchronous qu...
Definition: AbstractGWSConnector.h:38
bool outputValid(size_t i) const
Definition: AbstractGWSConnector.cpp:128
void setupQueues()
Setup queues based on configuration. This must be called before the connector is started.
Definition: AbstractGWSConnector.cpp:29
GWSConnector is an abstract class that defines an API for communication with a remote server...
Definition: GWSConnector.h:21
Definition: Loggable.h:19
void updateOutputs(size_t i)
Definition: AbstractGWSConnector.cpp:110
void send(const GWMessage::Ptr message) override
Put the message into a queue and notify sender to check queues for updates.
Definition: AbstractGWSConnector.cpp:151
GWMessage::Ptr peekOutput(size_t i) const
Definition: AbstractGWSConnector.cpp:135
size_t selectOutput() const
Definition: AbstractGWSConnector.cpp:48