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 Member Functions | List of all members
Attribute_Request_Callback< MaxAttributes > Class Template Reference

Client-side or shared attributes request callback wrapper, contains the needed configuration settings to create the request that should be sent to the server. More...

#include <Attribute_Request_Callback.h>

Inheritance diagram for Attribute_Request_Callback< MaxAttributes >:
[legend]
Collaboration diagram for Attribute_Request_Callback< MaxAttributes >:
[legend]

Public Member Functions

 Attribute_Request_Callback ()=default
 Constructs empty callback, will result in never being called. Internals are simply default constructed as nullptr. More...
 
template<typename... Args>
 Attribute_Request_Callback (function callback, uint64_t const &timeout_microseconds=0U, Callback_Watchdog::function timeout_callback=nullptr, Args const &... args)
 Constructs callback, will be called upon client-side or shared attribute request arrival where the given multiple requested client-side or shared attributes were sent by the cloud and received by the client. More...
 
 ~Attribute_Request_Callback () override=default
 
size_t const & Get_Request_ID () const
 Gets the unique request identifier that is connected to the original request. More...
 
void Set_Request_ID (size_t const &request_id)
 Sets the unique request identifier that is connected to the original request. More...
 
char const * Get_Attribute_Key () const
 Gets the response key of the json array key-value pair, that we expect the client-side or shared attribute payload json data to be contained in. More...
 
void Set_Attribute_Key (char const *attribute_key)
 Sets the response key of the json array key-value pair, that we expect the client-side or shared attribute payload json data to be contained in. More...
 
CString_Container const & Get_Attributes () const
 Gets all the requested client-side or shared attributes, that will be transformed into the necessary payload format. More...
 
template<typename... Args>
void Set_Attributes (Args const &... args)
 Sets all the requested client-side or shared attributes, that will be transformed into the necessary payload format. More...
 
Timeoutable_RequestGet_Request_Timeout ()
 Gets the request timeout callback. More...
 
- Public Member Functions inherited from Callback< void, JsonObjectConst const & >
 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...
 
void 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...
 

Additional Inherited Members

- Public Types inherited from Callback< void, JsonObjectConst const & >
using function = std::function< void(argument_types... arguments)>
 Callback signature. More...
 

Detailed Description

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
class Attribute_Request_Callback< MaxAttributes >

Client-side or shared attributes request callback wrapper, contains the needed configuration settings to create the request that should be sent to the server.

Note
Which attribute scope will be requested from either client-side or shared, is decided depending on which method the class instance is passed to as an argument. If that method is the Client_Attributes_Request() then the passed attributes are requested and if they exist are received from the client scope, but if that method is the Shared_Attributes_Request() then the passed attributes are requested and if they exist are received from the shared scope instead. To achieve that some internal member variables get set automatically by those methods, the first one being a string to differentiate which attribute scope was requested and the second being the ID of the MQTT request, where the response by the server will use the same ID, which makes it easy to know which method intially requested the data and should now receive the response. Documentation about the specific use of Requesting client-side or shared scope atrributes in ThingsBoard can be found here https://thingsboard.io/docs/reference/mqtt-api/#request-attribute-values-from-the-server
Template Parameters
MaxAttributesMaximum amount of attributes that will ever be requested with this instance of the class, allows to use an array on the stack in the background. Be aware though the size set in this template and the size passed to the Attribute_Request class MaxAttributes template need to be the same or higher than the value in this class, if not some of the requested keys may be lost and the requests only partially fulfilled, default = DEFAULT_ATTRIBUTES_AMOUNT (1)

Constructor & Destructor Documentation

◆ Attribute_Request_Callback() [1/2]

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
Attribute_Request_Callback< MaxAttributes >::Attribute_Request_Callback ( )
default

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

◆ Attribute_Request_Callback() [2/2]

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
template<typename... Args>
Attribute_Request_Callback< MaxAttributes >::Attribute_Request_Callback ( function  callback,
uint64_t const &  timeout_microseconds = 0U,
Callback_Watchdog::function  timeout_callback = nullptr,
Args const &...  args 
)
inline

Constructs callback, will be called upon client-side or shared attribute request arrival where the given multiple requested client-side or shared attributes were sent by the cloud and received by the client.

Note
Directly forwards the given arguments to the overloaded Container constructor, meaning all combinatons of arguments that would initalize an std::vector can be used to call this constructor. See possible std::vector constructors here https://en.cppreference.com/w/cpp/container/vector/vector, for the possible passable parameters. The possibilites mainly consist out of the fill constructor, where a number n and a value is given and then the value is copied into that many elements, alternatively if no value is given the default constructed value is copied n times instead, or the range constructor where we can pass an interator to the start and to the end of the data container (last element + 1) to copy every element in between thoose iterators, in the same order as in the original data container. The last option is a copy constructor where we pass another container and all the values of that container will be copied into our buffer
Template Parameters
...ArgsHolds the multiple arguments that will simply be forwarded to the container constructor and therefore allow to use every overloaded constructor without having to explicitly implement them
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
timeout_microsecondsOptional amount of microseconds until a response should have been received from the server, counted from the moment the request is sent. If a response is not received in the timeout time, the timeout callback method will be called to inform the user that the request has failed. If the value is 0 the timer will not be started and therefore never call the timeout callback method, default = 0
timeout_callbackOptional callback method that will be called upon request timeout (did not receive a response in the given timeout time). Can happen if the requested method does not exist on the cloud, or if the connection could not be established. A nullptr means even if a timeout occured the callback is simply ignored and the user not informed, default = nullptr
...argsAttributes to requests, that will be forwarded into the overloaded Container constructor see https://en.cppreference.com/w/cpp/container/vector/vector for more information

◆ ~Attribute_Request_Callback()

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
Attribute_Request_Callback< MaxAttributes >::~Attribute_Request_Callback ( )
overridedefault

Member Function Documentation

◆ Get_Attribute_Key()

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
char const * Attribute_Request_Callback< MaxAttributes >::Get_Attribute_Key ( ) const
inline

Gets the response key of the json array key-value pair, that we expect the client-side or shared attribute payload json data to be contained in.

Returns
JSON array key that the data is saved into, "client" for client-side attributes and "shared" for shared scope attributes

◆ Get_Attributes()

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
CString_Container const & Attribute_Request_Callback< MaxAttributes >::Get_Attributes ( ) const
inline

Gets all the requested client-side or shared attributes, that will be transformed into the necessary payload format.

Note
Simply transforms the attributes into one comma-seperated c-string containing all the requested attributes. That c-string is then used to requests thoose attributes from the cloud and receive their values as a response.
Returns
Requested client-side or shared attributes

◆ Get_Request_ID()

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
size_t const & Attribute_Request_Callback< MaxAttributes >::Get_Request_ID ( ) const
inline

Gets the unique request identifier that is connected to the original request.

Note
Will be later used to verifiy which Attribute_Request_Callback is connected to which received client-side or shared attributes
Returns
Unique identifier connected to the requested client-side or shared attribute response

◆ Get_Request_Timeout()

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
Timeoutable_Request & Attribute_Request_Callback< MaxAttributes >::Get_Request_Timeout ( )
inline

Gets the request timeout callback.

Note
Will be called when no response to the request was received in the expected amount of time, causing the internal watchdog to time out. To achieve this behaviour the internal timer can be started and stopped, and simply calls the subscribed callback if the timer is not stopped before it times out
Returns
Request timeout callback

◆ Set_Attribute_Key()

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
void Attribute_Request_Callback< MaxAttributes >::Set_Attribute_Key ( char const *  attribute_key)
inline

Sets the response key of the json array key-value pair, that we expect the client-side or shared attribute payload json data to be contained in.

Note
Not meant for external use, because the value is overwritten by internal method calls anyway once the class instance has been passed as a parameter anyway. This is the case because the json key changes depending on if we request client-side or shared scope attributes and which type we requests depends on which method the class instance is passed too as an argument
Parameters
attribute_keyJson array key that the data is saved into, "client" for client-side attributes and "shared" for shared scope attributes

◆ Set_Attributes()

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
template<typename... Args>
void Attribute_Request_Callback< MaxAttributes >::Set_Attributes ( Args const &...  args)
inline

Sets all the requested client-side or shared attributes, that will be transformed into the necessary payload format.

Note
Simply transforms the attributes into one comma-seperated c-string containing all the requested attributes. That c-string is then used to requests thoose attributes from the cloud and receive their values as a response. Directly forwards the given arguments to the overloaded container assign method which mirrors the std::vector interface, meaning all combinations of arguments that can call the assign method on a std::vector can be used to call this method. See possible overloaded std::vector assign methods https://en.cppreference.com/w/cpp/container/vector/assign, for the possible passable parameters. The possibilites mainly consist out of the fill assign method, where a value and a number n is given and then that many elements of the value will be copied into or be created with their default value, or out of the range assign method where we can pass an interator the start of another data container and to the end of the data container (last element + 1) and then every element between those iteratos will be copied, in the same order as in the original data container. The last option is a copy assign method where we pass a container and all values of that container will be copied into our buffer
Template Parameters
...ArgsHolds the multiple arguments that will simply be forwarded to the Container assign method and therefore allow to use every overloaded Container assign without having to implement them
Parameters
...argsAttributes to requests, that will be forwarded into the overloaded Container assign method see https://en.cppreference.com/w/cpp/container/vector/assign for more information

◆ Set_Request_ID()

template<size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
void Attribute_Request_Callback< MaxAttributes >::Set_Request_ID ( size_t const &  request_id)
inline

Sets the unique request identifier that is connected to the original request.

Note
Will be later used to verifiy which Attribute_Request_Callback is connected to which received client-side or shared attributes. Not meant for external use, because the value is overwritten by internal method calls anyway once the class instance has been passed as a parameter anyway. This is the case because only the internal methods knows the current request id that this callback will be attached too
Parameters
request_idUnqiue identifier of the request for client-side or shared attributes

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