File tree Expand file tree Collapse file tree 2 files changed +36
-14
lines changed Expand file tree Collapse file tree 2 files changed +36
-14
lines changed Original file line number Diff line number Diff line change 28
28
#include < Client.h>
29
29
#include " thinger/thinger.h"
30
30
31
+ // required for the reboot method (wdt_enable)
32
+ #if defined(ARDUINO_ARCH_MEGAAVR) || defined(__AVR__)
33
+ #include < avr/wdt.h>
34
+ #endif
35
+
31
36
using namespace protoson ;
32
37
33
38
#ifndef THINGER_SERVER
@@ -430,7 +435,12 @@ class ThingerClient : public thinger::thinger {
430
435
break ;
431
436
}
432
437
#endif
438
+
439
+ #ifdef THINGER_USE_FUNCTIONAL
433
440
if (state_listener_) state_listener_ (state);
441
+ #else
442
+ if (state_listener_!=nullptr ) state_listener_ (state);
443
+ #endif
434
444
}
435
445
436
446
bool handle_connection ()
@@ -542,9 +552,15 @@ class ThingerClient : public thinger::thinger {
542
552
return root_ca_;
543
553
}
544
554
555
+ #ifdef THINGER_USE_FUNCTIONAL
545
556
void set_state_listener (std::function<void (THINGER_STATE)> state_listener){
546
557
state_listener_ = state_listener;
547
558
}
559
+ #else
560
+ void set_state_listener (void (*state_listener)(THINGER_STATE)){
561
+ state_listener_ = state_listener;
562
+ }
563
+ #endif
548
564
549
565
Client& get_client (){
550
566
return client_;
@@ -558,7 +574,12 @@ class ThingerClient : public thinger::thinger {
558
574
const char * device_password_;
559
575
const char * host_;
560
576
const char * root_ca_;
577
+ #ifdef THINGER_USE_FUNCTIONAL
561
578
std::function<void (THINGER_STATE)> state_listener_;
579
+ #else
580
+ void (*state_listener_)(THINGER_STATE) = nullptr;
581
+ #endif
582
+
562
583
#ifndef THINGER_DISABLE_OUTPUT_BUFFER
563
584
uint8_t * out_buffer_;
564
585
size_t out_size_;
Original file line number Diff line number Diff line change @@ -103,7 +103,9 @@ class thinger_resource {
103
103
unsigned long last_streaming_;
104
104
105
105
// used for thenables (code after running a resource)
106
+ #ifdef THINGER_USE_FUNCTIONAL
106
107
std::function<void ()> then_;
108
+ #endif
107
109
108
110
#ifdef THINGER_ENABLE_STREAM_LISTENER
109
111
#ifdef THINGER_USE_FUNCTIONAL
@@ -302,6 +304,19 @@ class thinger_resource {
302
304
callback_.pson_in_pson_out = pson_in_pson_out_function;
303
305
}
304
306
307
+ /* *
308
+ * Establish a function that will be called after executing the resource
309
+ */
310
+ void then (std::function<void ()> then){
311
+ then_ = then;
312
+ }
313
+
314
+ /* *
315
+ * Run the configured 'then' resource function, if any
316
+ */
317
+ void then (){
318
+ if (then_) then_ ();
319
+ }
305
320
306
321
#ifdef THINGER_ENABLE_STREAM_LISTENER
307
322
/* *
@@ -319,20 +334,6 @@ class thinger_resource {
319
334
}
320
335
#endif
321
336
322
- /* *
323
- * Establish a function that will be called after executing the resource
324
- */
325
- void then (std::function<void ()> then){
326
- then_ = then;
327
- }
328
-
329
- /* *
330
- * Run the configured 'then' resource function, if any
331
- */
332
- void then (){
333
- if (then_) then_ ();
334
- }
335
-
336
337
#else
337
338
338
339
/* *
You can’t perform that action at this time.
0 commit comments