NetBurner 3.5.6
PDF Version
MQTT::mqtt_leaf Class Referenceabstract

Base class for all Mqtt Objects (MqttObj). Mqtt Objects provide a seamless bridge/synchronization to communicate information through an MQTT Broker via a Client object. More...

#include <mqtt.h>

Inherits TimeOutElement.

Inherited by MQTT::ConfigExposer, MQTT::SubHandler, MQTT::mqtt_IO, MQTT::mqtt_bool, MQTT::mqtt_float, MQTT::mqtt_int, MQTT::mqtt_obj, MQTT::mqtt_string, and MQTT::mqtt_uint.

Public Types

enum  eObj_State_t
 Mqtt Object Publication/Subscription States.
 

Public Member Functions

 ~mqtt_leaf ()
 ~mqtt_leaf Destructor for base mqtt_leaf
 
void RemoveFromTree ()
 Remove this object from it's parent tree.
 
bool NameMatch (const char *cp)
 Determine whether a given name matches this object.
 
virtual ValueTestResult TestOrSetValue (ParsedJsonDataSet &pjs, bool setVal)=0
 Test whether the current index of a JSON dataset is valid for this object, or assign the value at the current index of the dataset to this object.
 
virtual int GetPubTopicName (NBString &s)
 Get the Topic Name this object Publishes to.
 
virtual int GetSubTopicFilter (NBString &s)
 Get the Subscription Topic Filter this object Subscribes to.
 
virtual int SubscribeEvent (int mqttFd, PacketInfo::Msg *msg)
 Handle a message sent by the Broker triggered by this object's Subscription.
 
virtual int GetRenderLength (eObj_Serialize_t form=eObj_Serialize_CURRENT_FORM)
 Get the number of bytes used to serialize this object in a particular format.
 
int Publish (int waitForCompletion=-1)
 Publishes the current MQTT object, optionally waiting for completion.
 
void SetPublishInterval (uint32_t intervalPeriodTicks)
 Sets or clears an automatic publishing interval for this MQTT object.
 
virtual void SetSerializationForm (eObj_Serialize_t form)
 Set the default serialization format for this object.
 
eObj_Serialize_t GetSerializationForm ()
 Get the default serialization format for this object.
 
virtual void SetFlags (uint16_t newFlags)
 Set additional behavioral flags for this object.
 
virtual void ClearFlags (uint16_t delFlags)
 Clear behavioral flags from this object.
 
uint16_t GetFlags ()
 Get the behavioral flags set for this object.
 
int getPriority ()
 Get the message priority for this object.
 
virtual int RenderToBuffer (eObj_Serialize_t form, uint8_t *buf, int buflen)=0
 Render this object to an output buffer.
 
virtual int RenderToFd (eObj_Serialize_t form, int fd)=0
 Render this object to an output socket.
 

Static Public Member Functions

static int MqttRxPublish (Client *mClient, int mqttFd, PacketInfo::Msg *msg, void *ctx)
 Static message handler for Publish messages received by the registered Client.
 

Protected Member Functions

 mqtt_leaf (const char *topic, Client *mClient, uint16_t flags=(eObj_Flag_PubOnWrite|eObj_Flag_Subscribe|eObj_Flag_Sub_NoLocal))
 Constructor for mqtt_leaf objects.
 
 mqtt_leaf (mqtt_leaf &parent, const char *topic, Client *mClient, uint16_t flags=(eObj_Flag_PubOnWrite|eObj_Flag_Subscribe|eObj_Flag_Sub_NoLocal))
 Constructor for mqtt_leaf objects.
 
virtual mqtt_leafGetChildren ()
 Get the first child of this object.
 
virtual mqtt_leafAddChild (mqtt_leaf *child)
 Add an MqttObj as a child to this object.
 
virtual mqtt_leafRemoveFirstChild ()
 Remove the first child from this object.
 
void ForEachLeaf (LeafCallBack *p, void *pd)
 Call a function on each element of the MqttObj tree with this object as the root.
 
void RootParse (ParsedJsonDataSet &pjs)
 Assign to this object tree from a JSON dataset.
 
bool MatchId (ParsedJsonDataSet &pjs)
 Determine whether the JSON dataset's current index matches this object's name.
 
int QueuePublish ()
 Queue this object to be Published via the registered Client.
 
int QueueSubscribe ()
 Queue this object to be Subscribed via the registered Client.
 
int QueueUnsubscribe ()
 Queue this object to be Unsubscribed via the registered Client.
 
int Assign ()
 Perform post assignemnt operations.
 
uint8_t PubState ()
 Get the Publish state.
 
uint8_t SubState ()
 Get the Subscribe state of this object.
 
virtual void SetPubState (uint8_t newState)
 Set the Publish state.
 
virtual void SetSubState (uint8_t newState)
 Set the Subscribe state.
 
virtual int ParseFd (int mqttFd)=0
 Parse the data from a file descriptor according to this object's current default serialization method and assign the value.
 
int HandleSubAck (int mqttFd, PacketInfo::Msg *msg)
 Handle a Subscribe Acknowledge message from the broker for our Subscribe request.
 
int HandleUnsubAck (int mqttFd, PacketInfo::Msg *msg)
 Handle an Unsubscribe Acknowledge message from the broker for our Unsubscribe request.
 
int HandlePubAck (int mqttFd, PacketInfo::Msg *msg)
 Handle an Publish Acknowledge message from the broker for our Publish request.
 

Protected Attributes

NBInterpolatedString topicName
 Topic name or additional branch.
 
eObj_Serialize_t publishForm
 Default serialization form.
 
uint16_t mFlags
 Behavioral flags.
 

Detailed Description

Base class for all Mqtt Objects (MqttObj). Mqtt Objects provide a seamless bridge/synchronization to communicate information through an MQTT Broker via a Client object.

Constructor & Destructor Documentation

◆ mqtt_leaf() [1/2]

MQTT::mqtt_leaf::mqtt_leaf ( const char * topic,
Client * mClient,
uint16_t flags = (eObj_Flag_PubOnWrite|eObj_Flag_Subscribe|eObj_Flag_Sub_NoLocal) )
protected

Constructor for mqtt_leaf objects.

Parameters
*topicMqtt Topic Name to use for Publish/Subcribe.
*mClientPointer to Client to register with. If NULL, it will be registered with the first created Client.
flagsBehavioral flags to set on the created object

◆ mqtt_leaf() [2/2]

MQTT::mqtt_leaf::mqtt_leaf ( mqtt_leaf & parent,
const char * topic,
Client * mClient,
uint16_t flags = (eObj_Flag_PubOnWrite|eObj_Flag_Subscribe|eObj_Flag_Sub_NoLocal) )
protected

Constructor for mqtt_leaf objects.

Parameters
&parentReference to parent object.
*topicAdditional Topic Name for the leaf, added as another level in the topic path after the parent objects topic (parent='/foo', this='/foo/bar').
*mClientPointer to Client to register with. If NULL, it will be registered with the first created Client.
flagsBehavioral flags to set on the created object

Member Function Documentation

◆ AddChild()

virtual mqtt_leaf * MQTT::mqtt_leaf::AddChild ( mqtt_leaf * child)
protectedvirtual

Add an MqttObj as a child to this object.

Parameters
*childPointer to the child object to add
Returns
Pointer to the first child of this object

Reimplemented in MQTT::mqtt_obj.

◆ Assign()

int MQTT::mqtt_leaf::Assign ( )
protected

Perform post assignemnt operations.

Returns
eResult_t return code

◆ ClearFlags()

virtual void MQTT::mqtt_leaf::ClearFlags ( uint16_t delFlags)
virtual

Clear behavioral flags from this object.

Parameters
delFlagsThe flags to be cleared from this object

Reimplemented in MQTT::mqtt_IO.

◆ ForEachLeaf()

void MQTT::mqtt_leaf::ForEachLeaf ( LeafCallBack * p,
void * pd )
protected

Call a function on each element of the MqttObj tree with this object as the root.

Parameters
*pPointer to the function to be executed on each element of the tree
*pdPointer to extra data to pass to the function being called

◆ GetChildren()

virtual mqtt_leaf * MQTT::mqtt_leaf::GetChildren ( )
protectedvirtual

Get the first child of this object.

Returns
Pointer to the first child of this object

Reimplemented in MQTT::mqtt_obj.

◆ GetFlags()

uint16_t MQTT::mqtt_leaf::GetFlags ( )
inline

Get the behavioral flags set for this object.

Returns
The flags to set for this object

◆ getPriority()

int MQTT::mqtt_leaf::getPriority ( )
inline

Get the message priority for this object.

Returns
The message priority for this object.

◆ GetPubTopicName()

virtual int MQTT::mqtt_leaf::GetPubTopicName ( NBString & s)
virtual

Get the Topic Name this object Publishes to.

Parameters
&sThe NBString to copy the Topic Name into
Returns
eResult_t return code

Reimplemented in MQTT::ConfigExposer.

◆ GetRenderLength()

virtual int MQTT::mqtt_leaf::GetRenderLength ( eObj_Serialize_t form = eObj_Serialize_CURRENT_FORM)
virtual

Get the number of bytes used to serialize this object in a particular format.

Parameters
formSerialization format to use
Returns
Length of serialized data

Reimplemented in MQTT::ConfigExposer, and MQTT::mqtt_obj.

◆ GetSerializationForm()

eObj_Serialize_t MQTT::mqtt_leaf::GetSerializationForm ( )
inline

Get the default serialization format for this object.

Returns
eObj_Serialize_t Serialization format in use

◆ GetSubTopicFilter()

virtual int MQTT::mqtt_leaf::GetSubTopicFilter ( NBString & s)
virtual

Get the Subscription Topic Filter this object Subscribes to.

Parameters
&sThe NBString to copy the Subscription Topic Filter into
Returns
eResult_t return code

Reimplemented in MQTT::ConfigExposer, and MQTT::mqtt_obj.

◆ HandlePubAck()

int MQTT::mqtt_leaf::HandlePubAck ( int mqttFd,
PacketInfo::Msg * msg )
protected

Handle an Publish Acknowledge message from the broker for our Publish request.

Parameters
mqttFdFile descriptor to read additional message data from
*msgPointer to message struct containing the Publish Acknowledgement
Returns
eResult_t return code

◆ HandleSubAck()

int MQTT::mqtt_leaf::HandleSubAck ( int mqttFd,
PacketInfo::Msg * msg )
protected

Handle a Subscribe Acknowledge message from the broker for our Subscribe request.

Parameters
mqttFdFile descriptor to read additional message data from
*msgPointer to message struct containing the Subscribe Acknowledgement
Returns
eResult_t return code

◆ HandleUnsubAck()

int MQTT::mqtt_leaf::HandleUnsubAck ( int mqttFd,
PacketInfo::Msg * msg )
protected

Handle an Unsubscribe Acknowledge message from the broker for our Unsubscribe request.

Parameters
mqttFdFile descriptor to read additional message data from
*msgPointer to message struct containing the Unsubscribe Acknowledgement
Returns
eResult_t return code

◆ MatchId()

bool MQTT::mqtt_leaf::MatchId ( ParsedJsonDataSet & pjs)
protected

Determine whether the JSON dataset's current index matches this object's name.

Parameters
&pjsReference to the JSON dataset to be assigned from
Returns
Whether the JSON dataset's current index matches this object's name.

◆ MqttRxPublish()

static int MQTT::mqtt_leaf::MqttRxPublish ( Client * mClient,
int mqttFd,
PacketInfo::Msg * msg,
void * ctx )
static

Static message handler for Publish messages received by the registered Client.

Parameters
*mClientPointer to the Client that received the message
mqttFdFile Descriptor to read any additional data from
*msgPointer to the structure containing the received message
*ctxPointer to the leaf this message is for
Returns
The message priority for this object.

◆ NameMatch()

bool MQTT::mqtt_leaf::NameMatch ( const char * cp)

Determine whether a given name matches this object.

Parameters
*cpName to check against
Returns
Whether the given name matches this object

◆ ParseFd()

virtual int MQTT::mqtt_leaf::ParseFd ( int mqttFd)
protectedpure virtual

Parse the data from a file descriptor according to this object's current default serialization method and assign the value.

Parameters
mqttFdFile descriptor to read from.
Returns
eResult_t return code

Implemented in MQTT::ConfigExposer, MQTT::mqtt_bool, MQTT::mqtt_float, MQTT::mqtt_int, MQTT::mqtt_IO, MQTT::mqtt_obj, MQTT::mqtt_string, MQTT::mqtt_uint, and MQTT::SubHandler.

◆ Publish()

int MQTT::mqtt_leaf::Publish ( int waitForCompletion = -1)

Publishes the current MQTT object, optionally waiting for completion.

This method queues the object for publication via MQTT. If waitForCompletion is greater than 0, or if the object is configured to wait (eObj_Flag_WaitForPub), the function will block until the publish operation is complete.

Parameters
waitForCompletionSet to 1 to block until the publish is done.
Returns
eResult_Success on successful queuing and (if applicable) completion; error codes may propagate from QueuePublish().
See also
QueuePublish

◆ PubState()

uint8_t MQTT::mqtt_leaf::PubState ( )
inlineprotected

Get the Publish state.

Returns
eObj_State_t state of this object

◆ QueuePublish()

int MQTT::mqtt_leaf::QueuePublish ( )
protected

Queue this object to be Published via the registered Client.

Returns
eResult_t return code
See also
Client::Publish

◆ QueueSubscribe()

int MQTT::mqtt_leaf::QueueSubscribe ( )
protected

Queue this object to be Subscribed via the registered Client.

Returns
eResult_t return code
See also
Client::Subscribe

◆ QueueUnsubscribe()

int MQTT::mqtt_leaf::QueueUnsubscribe ( )
protected

Queue this object to be Unsubscribed via the registered Client.

Returns
eResult_t return code
See also
Client::Unsubscribe

◆ RemoveFirstChild()

virtual mqtt_leaf * MQTT::mqtt_leaf::RemoveFirstChild ( )
protectedvirtual

Remove the first child from this object.

Returns
Pointer to the new first child of this object

Reimplemented in MQTT::mqtt_obj.

◆ RenderToBuffer()

virtual int MQTT::mqtt_leaf::RenderToBuffer ( eObj_Serialize_t form,
uint8_t * buf,
int buflen )
pure virtual

Render this object to an output buffer.

Parameters
formSerialization format to render as
*bufPointer to output buffer
buflenSize of the output buffer
Returns
Length of the rendered data

Implemented in MQTT::ConfigExposer, MQTT::mqtt_bool, MQTT::mqtt_float, MQTT::mqtt_int, MQTT::mqtt_IO, MQTT::mqtt_obj, MQTT::mqtt_string, MQTT::mqtt_uint, and MQTT::SubHandler.

◆ RenderToFd()

virtual int MQTT::mqtt_leaf::RenderToFd ( eObj_Serialize_t form,
int fd )
pure virtual

Render this object to an output socket.

Parameters
formSerialization format to render as
fdFile descriptor to render to
Returns
Length of the rendered data

Implemented in MQTT::ConfigExposer, MQTT::mqtt_bool, MQTT::mqtt_float, MQTT::mqtt_int, MQTT::mqtt_IO, MQTT::mqtt_obj, MQTT::mqtt_string, MQTT::mqtt_uint, and MQTT::SubHandler.

◆ RootParse()

void MQTT::mqtt_leaf::RootParse ( ParsedJsonDataSet & pjs)
protected

Assign to this object tree from a JSON dataset.

Parameters
&pjsReference to the JSON dataset to be assigned from

◆ SetFlags()

virtual void MQTT::mqtt_leaf::SetFlags ( uint16_t newFlags)
virtual

Set additional behavioral flags for this object.

Parameters
newFlagsThe set of new flags to be set

Reimplemented in MQTT::mqtt_IO.

◆ SetPublishInterval()

void MQTT::mqtt_leaf::SetPublishInterval ( uint32_t intervalPeriodTicks)

Sets or clears an automatic publishing interval for this MQTT object.

If a non-zero interval is specified, the object will be automatically published at the given interval (in system ticks). If the interval is zero, the automatic publishing is disabled by deregistering the object from the client's scheduler.

Parameters
intervalPeriodTicksThe interval period in system ticks. A value of zero disables periodic publishing.
Note
This operation has no effect if the MQTT client (mClient) is not initialized.

◆ SetPubState()

virtual void MQTT::mqtt_leaf::SetPubState ( uint8_t newState)
protectedvirtual

Set the Publish state.

Parameters
newStateThe new Publish state for this object

Reimplemented in MQTT::mqtt_obj.

◆ SetSerializationForm()

virtual void MQTT::mqtt_leaf::SetSerializationForm ( eObj_Serialize_t form)
virtual

Set the default serialization format for this object.

Parameters
formSerialization format to use

◆ SetSubState()

virtual void MQTT::mqtt_leaf::SetSubState ( uint8_t newState)
protectedvirtual

Set the Subscribe state.

Parameters
newStateThe new Subscribe state for this object

Reimplemented in MQTT::mqtt_obj.

◆ SubscribeEvent()

virtual int MQTT::mqtt_leaf::SubscribeEvent ( int mqttFd,
PacketInfo::Msg * msg )
virtual

Handle a message sent by the Broker triggered by this object's Subscription.

Parameters
mqttFdFile Descriptor to read any additional message data from
*msgPointer to message received from the Broker
Returns
eResult_t return code

Reimplemented in MQTT::ConfigExposer, MQTT::mqtt_bool, MQTT::mqtt_float, MQTT::mqtt_int, MQTT::mqtt_IO, MQTT::mqtt_obj, MQTT::mqtt_string, MQTT::mqtt_uint, and MQTT::SubHandler.

◆ SubState()

uint8_t MQTT::mqtt_leaf::SubState ( )
inlineprotected

Get the Subscribe state of this object.

Returns
eObj_State_t state

◆ TestOrSetValue()

virtual ValueTestResult MQTT::mqtt_leaf::TestOrSetValue ( ParsedJsonDataSet & pjs,
bool setVal )
pure virtual

Test whether the current index of a JSON dataset is valid for this object, or assign the value at the current index of the dataset to this object.

Parameters
&pjsThe JSON dataset to use
setValtrue: Assign from the value at the current index, false: test if current index is valid for this object
Returns
ValueTestResult indicating the validity of the current index

Implemented in MQTT::ConfigExposer, MQTT::mqtt_bool, MQTT::mqtt_float, MQTT::mqtt_int, MQTT::mqtt_IO, MQTT::mqtt_obj, MQTT::mqtt_string, MQTT::mqtt_uint, and MQTT::SubHandler.


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