ThingsBoard Client SDK 0.16.0
Client SDK to connect with ThingsBoard IoT Platform from IoT devices (Arduino, Espressif, etc.)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Callback< return_type, argument_types > Class Template Reference

General purpose safe callback wrapper. Expects either c-style or c++ style function pointer, depending on if the C++ STL has been implemented on the given device or not. Simply wraps that function pointer and before calling it ensures it is valid. More...

#include <Callback.h>

Inheritance diagram for Callback< return_type, argument_types >:
[legend]

Public Types

using function = std::function< return_type(argument_types... arguments)>
 Callback signature. More...
 

Public Member Functions

 Callback ()=default
 Constructs empty callback, will result in never being called. Internals are simply default constructed as nullptr. More...
 
 Callback (function callback)
 Constructor. More...
 
virtual ~Callback ()=default
 Virtual default destructor, created to ensure that if a pointer to this class is used and deleted, we will also call the derived base class destructor. More...
 
return_type Call_Callback (argument_types const &... arguments) const
 Calls the callback that was subscribed, when this class instance was initally created. More...
 
void Set_Callback (function callback)
 Sets the callback method that will be called upon data arrival with the given data that was received. If nullptr is passed the callback will never be called and instead return with a defaulted instance of the requested return variable. More...
 

Detailed Description

template<typename return_type, typename... argument_types>
class Callback< return_type, argument_types >

General purpose safe callback wrapper. Expects either c-style or c++ style function pointer, depending on if the C++ STL has been implemented on the given device or not. Simply wraps that function pointer and before calling it ensures it is valid.

Template Parameters
return_typeType the given callback method should return
argument_typesTypes the given callback method should receive

Member Typedef Documentation

◆ function

template<typename return_type , typename... argument_types>
using Callback< return_type, argument_types >::function = std::function<return_type(argument_types... arguments)>

Callback signature.

Constructor & Destructor Documentation

◆ Callback() [1/2]

template<typename return_type , typename... argument_types>
Callback< return_type, argument_types >::Callback ( )
default

Constructs empty callback, will result in never being called. Internals are simply default constructed as nullptr.

◆ Callback() [2/2]

template<typename return_type , typename... argument_types>
Callback< return_type, argument_types >::Callback ( function  callback)
inlineexplicit

Constructor.

Parameters
callbackCallback method that will be called upon data arrival with the given data that was received. If nullptr is passed the callback will never be called and instead return with a defaulted instance of the requested return variable

◆ ~Callback()

template<typename return_type , typename... argument_types>
virtual Callback< return_type, argument_types >::~Callback ( )
virtualdefault

Virtual default destructor, created to ensure that if a pointer to this class is used and deleted, we will also call the derived base class destructor.

Note
Deleting a base class destructor that does not have a virtual destructor is undefined behaviour, because the derived class destructor originally instantiated with new is never called. This can cause potential memory leaks, because derived classes can not clean up their internal members as expected and instead simply leak them

Member Function Documentation

◆ Call_Callback()

template<typename return_type , typename... argument_types>
return_type Callback< return_type, argument_types >::Call_Callback ( argument_types const &...  arguments) const
inline

Calls the callback that was subscribed, when this class instance was initally created.

Note
If the default constructor was used or a nullptr was passed instead of a valid function pointer, this method will simply return a defaulted instance of the requested return variable instead
Parameters
...argumentsOptional additional arguments that are simply formwarded to the subscribed callback if it exists
Returns
Argument returned by the previously subscribed callback or if none or nullptr is subscribed we instead return a defaulted instance of the requested return variable

◆ Set_Callback()

template<typename return_type , typename... argument_types>
void Callback< return_type, argument_types >::Set_Callback ( function  callback)
inline

Sets the callback method that will be called upon data arrival with the given data that was received. If nullptr is passed the callback will never be called and instead return with a defaulted instance of the requested return variable.

Parameters
callbackcallback method that will be called upon data arrival with the given data that was received

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