Skip to content

Commit 5a163ac

Browse files
committed
lib Network: add cpp syntax to structs
1 parent 7018cd1 commit 5a163ac

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

Diff for: libraries/Network/src/NetworkEvents.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@
88
#include "esp_task.h"
99
#include "esp32-hal.h"
1010

11-
typedef struct NetworkEventCbList {
11+
/**
12+
* @brief an object holds callback's definitions:
13+
* - callback id
14+
* - callback function pointers
15+
* - binded event id
16+
*
17+
*/
18+
struct NetworkEventCbList_t {
1219
static network_event_handle_t current_id;
1320
network_event_handle_t id;
1421
NetworkEventCb cb;
1522
NetworkEventFuncCb fcb;
1623
NetworkEventSysCb scb;
1724
arduino_event_id_t event;
1825

19-
NetworkEventCbList() : id(current_id++), cb(NULL), fcb(NULL), scb(NULL), event(ARDUINO_EVENT_NONE) {}
20-
} NetworkEventCbList_t;
21-
network_event_handle_t NetworkEventCbList::current_id = 1;
26+
NetworkEventCbList_t() : id(current_id++), cb(NULL), fcb(NULL), scb(NULL), event(ARDUINO_EVENT_NONE) {}
27+
};
28+
// define initial id's value
29+
network_event_handle_t NetworkEventCbList_t::current_id = 1;
2230

2331
// arduino dont like std::vectors move static here
2432
static std::vector<NetworkEventCbList_t> cbEventList;

Diff for: libraries/Network/src/NetworkEvents.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,20 @@ typedef union {
110110
#endif
111111
} arduino_event_info_t;
112112

113-
typedef struct {
113+
/**
114+
* @brief struct combines arduino event id and event's data object
115+
*
116+
*/
117+
struct arduino_event_t {
114118
arduino_event_id_t event_id;
115119
arduino_event_info_t event_info;
116-
} arduino_event_t;
117-
118-
typedef void (*NetworkEventCb)(arduino_event_id_t event);
119-
typedef std::function<void(arduino_event_id_t event, arduino_event_info_t info)> NetworkEventFuncCb;
120-
typedef void (*NetworkEventSysCb)(arduino_event_t *event);
120+
};
121121

122-
typedef size_t network_event_handle_t;
122+
// type aliases
123+
using NetworkEventCb = void(*)(arduino_event_id_t event);
124+
using NetworkEventFuncCb = std::function<void(arduino_event_id_t event, arduino_event_info_t info)>;
125+
using NetworkEventSysCb = void(*)(arduino_event_t *event);
126+
using network_event_handle_t = size_t;
123127

124128
class NetworkEvents {
125129
public:

0 commit comments

Comments
 (0)