Skip to content

Commit 3923ff1

Browse files
committed
fix compiling issues on AVR platforms without standard <functional> libraries
1 parent 8402d52 commit 3923ff1

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/ThingerClient.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include <Client.h>
2929
#include "thinger/thinger.h"
3030

31+
// required for the reboot method (wdt_enable)
32+
#if defined(ARDUINO_ARCH_MEGAAVR) || defined(__AVR__)
33+
#include <avr/wdt.h>
34+
#endif
35+
3136
using namespace protoson;
3237

3338
#ifndef THINGER_SERVER
@@ -430,7 +435,12 @@ class ThingerClient : public thinger::thinger {
430435
break;
431436
}
432437
#endif
438+
439+
#ifdef THINGER_USE_FUNCTIONAL
433440
if(state_listener_) state_listener_(state);
441+
#else
442+
if(state_listener_!=nullptr) state_listener_(state);
443+
#endif
434444
}
435445

436446
bool handle_connection()
@@ -542,9 +552,15 @@ class ThingerClient : public thinger::thinger {
542552
return root_ca_;
543553
}
544554

555+
#ifdef THINGER_USE_FUNCTIONAL
545556
void set_state_listener(std::function<void(THINGER_STATE)> state_listener){
546557
state_listener_ = state_listener;
547558
}
559+
#else
560+
void set_state_listener(void (*state_listener)(THINGER_STATE)){
561+
state_listener_ = state_listener;
562+
}
563+
#endif
548564

549565
Client& get_client(){
550566
return client_;
@@ -558,7 +574,12 @@ class ThingerClient : public thinger::thinger {
558574
const char* device_password_;
559575
const char* host_;
560576
const char* root_ca_;
577+
#ifdef THINGER_USE_FUNCTIONAL
561578
std::function<void(THINGER_STATE)> state_listener_;
579+
#else
580+
void (*state_listener_)(THINGER_STATE) = nullptr;
581+
#endif
582+
562583
#ifndef THINGER_DISABLE_OUTPUT_BUFFER
563584
uint8_t * out_buffer_;
564585
size_t out_size_;

src/thinger/thinger_resource.hpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class thinger_resource {
103103
unsigned long last_streaming_;
104104

105105
// used for thenables (code after running a resource)
106+
#ifdef THINGER_USE_FUNCTIONAL
106107
std::function<void()> then_;
108+
#endif
107109

108110
#ifdef THINGER_ENABLE_STREAM_LISTENER
109111
#ifdef THINGER_USE_FUNCTIONAL
@@ -302,6 +304,19 @@ class thinger_resource {
302304
callback_.pson_in_pson_out = pson_in_pson_out_function;
303305
}
304306

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+
}
305320

306321
#ifdef THINGER_ENABLE_STREAM_LISTENER
307322
/**
@@ -319,20 +334,6 @@ class thinger_resource {
319334
}
320335
#endif
321336

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-
336337
#else
337338

338339
/**

0 commit comments

Comments
 (0)