@@ -27,33 +27,25 @@ FSTR(RANGE, rangeValueDelta); // "rangeValueDelta"
27
27
* @snippet callbacks.cpp onRangeValue
28
28
**/
29
29
30
- using GenericRangeValueCallback_int = std::function< bool ( const String &, const String &, int &)> ;
31
- using GenericRangeValueCallback_float = std::function< bool ( const String &, const String &, float &)> ;
30
+ using GenericRangeValueCallback_int = bool (*)( const String &, const String &, int &);
31
+ using GenericRangeValueCallback_float = bool (*)( const String &, const String &, float &);
32
32
33
33
struct GenericRangeValueCallback {
34
34
GenericRangeValueCallback () : type(type_unknown) {}
35
- GenericRangeValueCallback (GenericRangeValueCallback_int cb) : type(type_int), callback(cb) {}
36
- GenericRangeValueCallback (GenericRangeValueCallback_float cb) : type(type_float), callback(cb) {}
37
- ~GenericRangeValueCallback () {};
38
- GenericRangeValueCallback& operator =(const GenericRangeValueCallback& other) { this ->callback = other.callback ; this ->type = other.type ; return *this ; };
35
+ GenericRangeValueCallback (GenericRangeValueCallback_int cb) : type(type_int), cb_int(cb) {}
36
+ GenericRangeValueCallback (GenericRangeValueCallback_float cb) : type(type_float), cb_float(cb) {}
39
37
enum {
40
38
type_unknown,
41
39
type_int,
42
40
type_float
43
41
} type;
44
- union Callback {
45
- Callback () {};
46
- Callback (const GenericRangeValueCallback_int& cb) : cb_int (cb) {};
47
- Callback (const GenericRangeValueCallback_float& cb) : cb_float (cb) {};
48
- Callback& operator =(const Callback& other) { cb_int = other.cb_int ; return *this ; }
49
- ~Callback (){};
50
-
42
+ union {
51
43
GenericRangeValueCallback_int cb_int;
52
44
GenericRangeValueCallback_float cb_float;
53
- } callback ;
45
+ };
54
46
};
55
47
56
- using SetRangeValueCallback = std::function< bool ( const String &, int &)> ;
48
+ using SetRangeValueCallback = bool (*)( const String &, int &);
57
49
58
50
/* *
59
51
* @brief Callback definition for onRangeValue function on a specific instance
@@ -87,7 +79,7 @@ using SetRangeValueCallback = std::function<bool(const String &, int &)>;
87
79
* @section AdjustRangeValueCallback Example-Code
88
80
* @snippet callbacks.cpp onAdjustRangeValue
89
81
**/
90
- using AdjustRangeValueCallback = std::function< bool ( const String&, int &)> ;
82
+ using AdjustRangeValueCallback = bool (*)( const String &, int &) ;
91
83
92
84
/* *
93
85
* @brief Callback definition for onAdjustRangeValue function on a specific instance for custom devices
@@ -280,14 +272,14 @@ bool RangeController<T>::handleRangeController(SinricProRequest &request) {
280
272
281
273
if (cb.type == GenericRangeValueCallback::type_float) {
282
274
float value = request.request_value [FSTR_RANGE_rangeValue];
283
- success = cb.callback . cb_float (device->deviceId , request.instance , value);
275
+ success = cb.cb_float (device->deviceId , request.instance , value);
284
276
request.response_value [FSTR_RANGE_rangeValue] = value;
285
277
return success;
286
278
}
287
279
288
280
if (cb.type == GenericRangeValueCallback::type_int) {
289
281
int value = request.request_value [FSTR_RANGE_rangeValue];
290
- success = cb.callback . cb_int (device->deviceId , request.instance , value);
282
+ success = cb.cb_int (device->deviceId , request.instance , value);
291
283
request.response_value [FSTR_RANGE_rangeValue] = value;
292
284
return success;
293
285
}
@@ -311,14 +303,14 @@ bool RangeController<T>::handleRangeController(SinricProRequest &request) {
311
303
312
304
if (cb.type == GenericRangeValueCallback::type_float) {
313
305
float value = request.request_value [FSTR_RANGE_rangeValueDelta];
314
- success = cb.callback . cb_float (device->deviceId , request.instance , value);
306
+ success = cb.cb_float (device->deviceId , request.instance , value);
315
307
request.response_value [FSTR_RANGE_rangeValue] = value;
316
308
return success;
317
309
}
318
310
319
311
if (cb.type == GenericRangeValueCallback::type_int) {
320
312
int value = request.request_value [FSTR_RANGE_rangeValueDelta];
321
- success = cb.callback . cb_int (device->deviceId , request.instance , value);
313
+ success = cb.cb_int (device->deviceId , request.instance , value);
322
314
request.response_value [FSTR_RANGE_rangeValue] = value;
323
315
return success;
324
316
}
0 commit comments