ThingsBoard Client SDK 0.16.0
Client SDK to connect with ThingsBoard IoT Platform from IoT devices (Arduino, Espressif, etc.)
Loading...
Searching...
No Matches
Attribute_Request_Callback.h
Go to the documentation of this file.
1#ifndef Attribute_Request_Callback_h
2#define Attribute_Request_Callback_h
3
4// Local includes.
6#if !THINGSBOARD_ENABLE_DYNAMIC
7#include "Constants.h"
8#endif // !THINGSBOARD_ENABLE_DYNAMIC
9
10
19#if !THINGSBOARD_ENABLE_DYNAMIC
23template <size_t MaxAttributes = DEFAULT_ATTRIBUTES_AMOUNT>
24#endif // !THINGSBOARD_ENABLE_DYNAMIC
25class Attribute_Request_Callback : public Callback<void, JsonObjectConst const &> {
26#if THINGSBOARD_ENABLE_DYNAMIC
28#else
30#endif // THINGSBOARD_ENABLE_DYNAMIC
31
32 public:
35
55 template<typename... Args>
56 Attribute_Request_Callback(function callback, uint64_t const & timeout_microseconds = 0U, Callback_Watchdog::function timeout_callback = nullptr, Args const &... args)
57 : Callback(callback)
58 , m_attributes(args...)
59 , m_request_id(0U)
60 , m_attribute_key(nullptr)
61 , m_request_timeout(timeout_microseconds, timeout_callback)
62 {
63 // Nothing to do
64 }
65
66 ~Attribute_Request_Callback() override = default;
67
71 size_t const & Get_Request_ID() const {
72 return m_request_id;
73 }
74
80 void Set_Request_ID(size_t const & request_id) {
81 m_request_id = request_id;
82 }
83
87 char const * Get_Attribute_Key() const {
88 return m_attribute_key;
89 }
90
98 void Set_Attribute_Key(char const * attribute_key) {
99 m_attribute_key = attribute_key;
100 }
101
107 return m_attributes;
108 }
109
123 template<typename... Args>
124 void Set_Attributes(Args const &... args) {
125 m_attributes.assign(args...);
126 }
127
133 return m_request_timeout;
134 }
135
136 private:
137 CString_Container m_attributes = {}; // Attribute we want to request
138 size_t m_request_id = {}; // Id the request was called with
139 char const *m_attribute_key = {}; // Attribute key that we wil receive the response on ("client" or "shared")
140 Timeoutable_Request m_request_timeout = {}; // Handles callback that will be called if request times out
141};
142
143#endif // Attribute_Request_Callback_h
Client-side or shared attributes request callback wrapper, contains the needed configuration settings...
Definition: Attribute_Request_Callback.h:25
void Set_Request_ID(size_t const &request_id)
Sets the unique request identifier that is connected to the original request.
Definition: Attribute_Request_Callback.h:80
Timeoutable_Request & Get_Request_Timeout()
Gets the request timeout callback.
Definition: Attribute_Request_Callback.h:132
CString_Container const & Get_Attributes() const
Gets all the requested client-side or shared attributes, that will be transformed into the necessary ...
Definition: Attribute_Request_Callback.h:106
Attribute_Request_Callback()=default
Constructs empty callback, will result in never being called. Internals are simply default constructe...
size_t const & Get_Request_ID() const
Gets the unique request identifier that is connected to the original request.
Definition: Attribute_Request_Callback.h:71
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 attr...
Definition: Attribute_Request_Callback.h:98
void Set_Attributes(Args const &... args)
Sets all the requested client-side or shared attributes, that will be transformed into the necessary ...
Definition: Attribute_Request_Callback.h:124
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 gi...
Definition: Attribute_Request_Callback.h:56
~Attribute_Request_Callback() override=default
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 attr...
Definition: Attribute_Request_Callback.h:87
General purpose safe callback wrapper. Expects either c-style or c++ style function pointer,...
Definition: Callback.h:30
std::function< void(argument_types... arguments)> function
Callback signature.
Definition: Callback.h:34
Custom std::array or std::vector implementation that contains a partial vector-like interface impleme...
Definition: Container.h:29
void assign(InputIterator const &first, InputIterator const &last)
Copies all elements from the given start to exclusively the given end iterator into the underlying da...
Definition: Container.h:129
General purpose request callback that can timeout if the response to the request is not received in t...
Definition: Timeoutable_Request.h:10