File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,20 @@ CClientWrapper CAtHandler::getClient(int sock) {
69
69
void CAtHandler::run () {
70
70
/* -------------------------------------------------------------------------- */
71
71
at_srv.run ();
72
+
73
+ // execute all the pending tasks
74
+
75
+ // it is intended for the tasks to add other tasks in queue after being executed,
76
+ // saving the current size of the queue
77
+ auto size = tasks.size ();
78
+ for (int i=0 ; i<size; i++) {
79
+ auto task = tasks.front ();
80
+ tasks.pop ();
81
+ if (task) {
82
+ task ();
83
+ }
84
+ }
85
+
72
86
vTaskDelay (1 );
73
87
}
74
88
Original file line number Diff line number Diff line change 4
4
#include " chAT.hpp"
5
5
#include " WiFi.h"
6
6
#include " Server.h"
7
+ #include < queue>
7
8
8
9
#include " WiFiClient.h"
9
10
#include < WiFiClientSecure.h>
@@ -66,6 +67,10 @@ class CAtHandler {
66
67
std::vector<std::uint8_t > clients_ca[MAX_CLIENT_AVAILABLE];
67
68
std::vector<std::uint8_t > clients_cert_pem[MAX_CLIENT_AVAILABLE];
68
69
std::vector<std::uint8_t > clients_key_pem[MAX_CLIENT_AVAILABLE];
70
+
71
+ // this vector is a list of function to be called in the run function
72
+ std::queue<std::function<void ()>> tasks;
73
+
69
74
int udps_num = 0 ;
70
75
int servers_num = 0 ;
71
76
int clientsToServer_num = 0 ;
@@ -90,6 +95,10 @@ class CAtHandler {
90
95
void add_cmds_preferences ();
91
96
void add_cmds_se ();
92
97
public:
98
+ inline void addTask (std::function<void ()> task) {
99
+ tasks.push (task);
100
+ }
101
+
93
102
/* Used by cmds_se */
94
103
std::vector<std::uint8_t > se_buf;
95
104
You can’t perform that action at this time.
0 commit comments