SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
All Classes Files Functions Variables Typedefs Enumerations
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SPSP::Nodes::Client< TLocalLayer > Class Template Reference

Client node. More...

#include <client.hpp>

Inheritance diagram for SPSP::Nodes::Client< TLocalLayer >:
Inheritance graph
[legend]
Collaboration diagram for SPSP::Nodes::Client< TLocalLayer >:
Collaboration graph
[legend]

Classes

struct  SubDBEntry
 Client subscribe database entry. More...
 

Public Types

using LocalAddrT = typename TLocalLayer::LocalAddrT
 
using LocalMessageT = typename TLocalLayer::LocalMessageT
 

Public Member Functions

 Client (TLocalLayer *ll, ClientConfig conf={})
 Constructs a new client node. More...
 
 ~Client ()
 Destroys the client node. More...
 
bool publish (const std::string &topic, const std::string &payload)
 Publishes payload to topic. More...
 
bool subscribe (const std::string &topic, SubscribeCb cb)
 Subscribes to topic. More...
 
bool unsubscribe (const std::string &topic)
 Unsubscribes from topic. More...
 
void resubscribeAll ()
 Resubscribes to all topics. More...
 
bool syncTime ()
 Synchronizes clock with bridge. More...
 
- Public Member Functions inherited from SPSP::ILocalNode< TLocalLayer >
 ILocalNode (TLocalLayer *ll)
 Constructs a new node. More...
 
void receiveLocal (const LocalMessageT &msg, int rssi=NODE_RSSI_UNKNOWN)
 Receives the message from local layer. More...
 
void setLocalRecvSendCb (LocalRecvSendCb cb)
 Sets local receive/send callback function. More...
 

Protected Member Functions

bool processProbeReq (const LocalMessageT &req, int rssi=NODE_RSSI_UNKNOWN)
 Processes PROBE_REQ message. More...
 
bool processProbeRes (const LocalMessageT &req, int rssi=NODE_RSSI_UNKNOWN)
 Processes PROBE_RES message. More...
 
bool processPub (const LocalMessageT &req, int rssi=NODE_RSSI_UNKNOWN)
 Processes PUB message. More...
 
bool processSubReq (const LocalMessageT &req, int rssi=NODE_RSSI_UNKNOWN)
 Processes SUB_REQ message. More...
 
bool processSubData (const LocalMessageT &req, int rssi=NODE_RSSI_UNKNOWN)
 Processes SUB_DATA message. More...
 
bool processUnsub (const LocalMessageT &req, int rssi=NODE_RSSI_UNKNOWN)
 Processes UNSUB message. More...
 
bool processTimeReq (const LocalMessageT &req, int rssi=NODE_RSSI_UNKNOWN)
 Processes TIME_REQ message. More...
 
bool processTimeRes (const LocalMessageT &req, int rssi=NODE_RSSI_UNKNOWN)
 Processes TIME_RES message. More...
 
bool sendSubscribe (const std::string &topic)
 Prepares and sends SUB_REQ message to local layer. More...
 
void subDBTick ()
 Subscribe DB timer tick callback. More...
 
- Protected Member Functions inherited from SPSP::ILocalNode< TLocalLayer >
TLocalLayer * getLocalLayer () const
 Gets the far layer object. More...
 
bool sendLocal (const LocalMessageT &msg)
 Sends the message to local layer. More...
 
void publishRssi (const LocalAddrT &addr, int rssi)
 Publishes RSSI of received message from addr More...
 

Protected Attributes

std::mutex m_mutex
 Mutex to prevent race conditions.
 
ClientConfig m_conf
 Configuration.
 
WildcardTrie< SubDBEntrym_subDB
 Subscribe database.
 
Timer m_subDBTimer
 Sub DB timer.
 
bool m_timeSyncOngoing = false
 Whether time synchronization is ongoing.
 
std::promise< bool > m_timeSyncPromise
 Time synchronization promise.
 

Detailed Description

template<typename TLocalLayer>
class SPSP::Nodes::Client< TLocalLayer >

Client node.

Template Parameters
TLocalLayerType of local layer

Definition at line 77 of file client.hpp.

Constructor & Destructor Documentation

◆ Client()

template<typename TLocalLayer >
SPSP::Nodes::Client< TLocalLayer >::Client ( TLocalLayer *  ll,
ClientConfig  conf = {} 
)
inline

Constructs a new client node.

Parameters
llLocal layer
confConfiguration

Definition at line 108 of file client.hpp.

◆ ~Client()

template<typename TLocalLayer >
SPSP::Nodes::Client< TLocalLayer >::~Client ( )
inline

Destroys the client node.

Definition at line 120 of file client.hpp.

Member Function Documentation

◆ processProbeReq()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::processProbeReq ( const LocalMessageT &  req,
int  rssi = NODE_RSSI_UNKNOWN 
)
inlineprotectedvirtual

Processes PROBE_REQ message.

Doesn't do anything.

Parameters
reqRequest message
rssiReceived signal strength indicator (in dBm)
Returns
true Message delivery successful
false Message delivery failed

Implements SPSP::ILocalNode< TLocalLayer >.

Definition at line 318 of file client.hpp.

◆ processProbeRes()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::processProbeRes ( const LocalMessageT &  req,
int  rssi = NODE_RSSI_UNKNOWN 
)
inlineprotectedvirtual

Processes PROBE_RES message.

Just publishes RSSI. This is handled internally by concrete local layer.

Parameters
reqRequest message
rssiReceived signal strength indicator (in dBm)
Returns
true Message delivery successful
false Message delivery failed

Implements SPSP::ILocalNode< TLocalLayer >.

Definition at line 332 of file client.hpp.

◆ processPub()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::processPub ( const LocalMessageT &  req,
int  rssi = NODE_RSSI_UNKNOWN 
)
inlineprotectedvirtual

Processes PUB message.

Doesn't do anything.

Parameters
reqRequest message
rssiReceived signal strength indicator (in dBm)
Returns
true Message delivery successful
false Message delivery failed

Implements SPSP::ILocalNode< TLocalLayer >.

Definition at line 351 of file client.hpp.

◆ processSubData()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::processSubData ( const LocalMessageT &  req,
int  rssi = NODE_RSSI_UNKNOWN 
)
inlineprotectedvirtual

Processes SUB_DATA message.

Parameters
reqRequest message
rssiReceived signal strength indicator (in dBm)
Returns
true Message delivery successful
false Message delivery failed

Implements SPSP::ILocalNode< TLocalLayer >.

Definition at line 375 of file client.hpp.

◆ processSubReq()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::processSubReq ( const LocalMessageT &  req,
int  rssi = NODE_RSSI_UNKNOWN 
)
inlineprotectedvirtual

Processes SUB_REQ message.

Doesn't do anything.

Parameters
reqRequest message
rssiReceived signal strength indicator (in dBm)
Returns
true Message delivery successful
false Message delivery failed

Implements SPSP::ILocalNode< TLocalLayer >.

Definition at line 364 of file client.hpp.

◆ processTimeReq()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::processTimeReq ( const LocalMessageT &  req,
int  rssi = NODE_RSSI_UNKNOWN 
)
inlineprotectedvirtual

Processes TIME_REQ message.

Doesn't do anything.

Parameters
reqRequest message
rssiReceived signal strength indicator (in dBm)
Returns
true Message delivery successful
false Message delivery failed

Implements SPSP::ILocalNode< TLocalLayer >.

Definition at line 415 of file client.hpp.

◆ processTimeRes()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::processTimeRes ( const LocalMessageT &  req,
int  rssi = NODE_RSSI_UNKNOWN 
)
inlineprotectedvirtual

Processes TIME_RES message.

Synchronizes clock with time in received response.

Parameters
reqRequest message
rssiReceived signal strength indicator (in dBm)
Returns
true Message delivery successful
false Message delivery failed

Implements SPSP::ILocalNode< TLocalLayer >.

Definition at line 428 of file client.hpp.

◆ processUnsub()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::processUnsub ( const LocalMessageT &  req,
int  rssi = NODE_RSSI_UNKNOWN 
)
inlineprotectedvirtual

Processes UNSUB message.

Parameters
reqRequest message
rssiReceived signal strength indicator (in dBm)
Returns
true Message delivery successful
false Message delivery failed

Implements SPSP::ILocalNode< TLocalLayer >.

Definition at line 402 of file client.hpp.

◆ publish()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::publish ( const std::string &  topic,
const std::string &  payload 
)
inline

Publishes payload to topic.

This is primary endpoint for publishing locally data on this node. Sends data to the local layer.

Parameters
topicTopic
payloadPayload
Returns
true Delivery successful
false Delivery failed

Definition at line 136 of file client.hpp.

◆ resubscribeAll()

template<typename TLocalLayer >
void SPSP::Nodes::Client< TLocalLayer >::resubscribeAll ( )
inline

Resubscribes to all topics.

Definition at line 241 of file client.hpp.

◆ sendSubscribe()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::sendSubscribe ( const std::string &  topic)
inlineprotected

Prepares and sends SUB_REQ message to local layer.

Parameters
topicTopic
Returns
true Message delivery successful
false Message delivery failed

Definition at line 473 of file client.hpp.

◆ subDBTick()

template<typename TLocalLayer >
void SPSP::Nodes::Client< TLocalLayer >::subDBTick ( )
inlineprotected

Subscribe DB timer tick callback.

Decrements subscribe database lifetimes. If any item expires, renews it.

Definition at line 490 of file client.hpp.

◆ subscribe()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::subscribe ( const std::string &  topic,
SubscribeCb  cb 
)
inline

Subscribes to topic.

This is primary endpoint for subscribing locally on this node. Directly forwards incoming data from local layer to given callback. Subscribe request is sent to the bridge and extended automatically until unsubscribe() is called.

Parameters
topicTopic
cbCallback function
Returns
true Subscribe successful
false Subscribe failed

Definition at line 168 of file client.hpp.

◆ syncTime()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::syncTime ( )
inline

Synchronizes clock with bridge.

Returns
true Synchronization successful
false Synchronization failed

Definition at line 258 of file client.hpp.

◆ unsubscribe()

template<typename TLocalLayer >
bool SPSP::Nodes::Client< TLocalLayer >::unsubscribe ( const std::string &  topic)
inline

Unsubscribes from topic.

This is primary endpoint for unsubscribing locally on this node.

Parameters
topicTopic
Returns
true Unsubscribe successful
false Unsubscribe failed

Definition at line 203 of file client.hpp.


The documentation for this class was generated from the following file: