|
SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
|
Go to the documentation of this file.
14 #include <unordered_set>
21 namespace SPSP::LocalLayers
32 using SentMsgsSetT = std::unordered_set<LocalMessageT>;
35 SentMsgsSetT m_sentMsgs;
36 size_t m_sentMsgsCount = 0;
50 m_sentMsgs.insert(msg);
66 this->
getNode()->receiveLocal(msg, rssi);
87 return m_sentMsgsCount;
92 namespace SPSP::FarLayers
101 using PubsSetT = std::unordered_set<std::string>;
102 using SubsSetT = std::unordered_set<std::string>;
103 using SubsLogT = std::vector<std::string>;
109 SubsLogT m_unsubsLog;
121 virtual bool publish(
const std::string& src,
const std::string& topic,
122 const std::string& payload)
125 m_pubs.insert(
"PUB " + src +
" " + topic +
" " + payload);
138 m_subs.insert(topic);
139 m_subsLog.push_back(topic);
152 m_unsubsLog.push_back(topic);
153 return m_subs.erase(topic);
163 const std::string& payload)
166 this->
getNode()->receiveFar(topic, payload);
Local layer address container.
virtual void receiveDirect(const std::string &topic, const std::string &payload)
Simulates reception of data from far layer.
const SentMsgsSetT & getSentMsgs()
Returns set of sent messages.
const SubsLogT & getSubsLog()
Returns current subscriptions log.
const SubsLogT & getUnsubsLog()
Returns current unsubscriptions log.
const PubsSetT & getPubs()
Returns current publishes set.
Local and far layers for SPSP.
Dummy far layer for testing.
IFarNode< IFarLayer > * getNode() const
Gets the node object.
Dummy local layer for testing.
void receiveDirect(const LocalMessageT &msg, int rssi=0)
Simulates reception of data from local layer.
ILocalNode< ILocalLayer > * getNode() const
Gets the node object.
Local layer address container.
virtual bool publish(const std::string &src, const std::string &topic, const std::string &payload)
Publishes message coming from node.
bool nodeConnected() const
Checks whether the owner node is connected.
bool nodeConnected() const
Checks whether the owner node is connected.
virtual bool unsubscribe(const std::string &topic)
Unsubscribes from given topic.
Local message representation.
virtual bool send(const LocalMessageT &msg)
Sends the message to given node.
size_t getSentMsgsCount()
Returns count of sent messages.
Interface for local layer.
virtual bool subscribe(const std::string &topic)
Subscribes to given topic.
const SubsSetT & getSubs()
Returns current subscriptions set.