Skip to content

Commit 9dddc14

Browse files
fix(net): Use network_event_handle_t for internal callbacks (#11179)
* fix(net): Use network_event_handle_t for internal callbacks * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent cd7f421 commit 9dddc14

File tree

8 files changed

+24
-13
lines changed

8 files changed

+24
-13
lines changed

Diff for: libraries/Ethernet/src/ETH.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ETHClass::ETHClass(uint8_t eth_index)
136136
_pin_mcd(-1), _pin_mdio(-1), _pin_power(-1), _pin_rmii_clock(-1)
137137
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
138138
,
139-
_task_stack_size(4096) {
139+
_task_stack_size(4096), _eth_connected_event_handle(0) {
140140
}
141141

142142
ETHClass::~ETHClass() {}
@@ -359,7 +359,7 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
359359
/* attach to receive events */
360360
initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index));
361361

362-
Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED);
362+
_eth_connected_event_handle = Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED);
363363

364364
ret = esp_eth_start(_eth_handle);
365365
if (ret != ESP_OK) {
@@ -849,7 +849,7 @@ bool ETHClass::beginSPI(
849849
perimanSetPinBusExtraType(_pin_rst, "ETH_RST");
850850
}
851851

852-
Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED);
852+
_eth_connected_event_handle = Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED);
853853

854854
return true;
855855

@@ -885,7 +885,8 @@ static bool empty_ethDetachBus(void *bus_pointer) {
885885

886886
void ETHClass::end(void) {
887887

888-
Network.removeEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED);
888+
Network.removeEvent(_eth_connected_event_handle);
889+
_eth_connected_event_handle = 0;
889890

890891
if (_eth_handle != NULL) {
891892
if (esp_eth_stop(_eth_handle) != ESP_OK) {

Diff for: libraries/Ethernet/src/ETH.h

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class ETHClass : public NetworkInterface {
247247
int8_t _pin_rmii_clock;
248248
#endif /* CONFIG_ETH_USE_ESP32_EMAC */
249249
size_t _task_stack_size;
250+
network_event_handle_t _eth_connected_event_handle;
250251

251252
static bool ethDetachBus(void *bus_pointer);
252253
bool beginSPI(

Diff for: libraries/PPP/src/PPP.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ esp_modem_dce_t *PPPClass::handle() const {
152152

153153
PPPClass::PPPClass()
154154
: _dce(NULL), _pin_tx(-1), _pin_rx(-1), _pin_rts(-1), _pin_cts(-1), _flow_ctrl(ESP_MODEM_FLOW_CONTROL_NONE), _pin_rst(-1), _pin_rst_act_low(true),
155-
_pin_rst_delay(200), _pin(NULL), _apn(NULL), _rx_buffer_size(4096), _tx_buffer_size(512), _mode(ESP_MODEM_MODE_COMMAND), _uart_num(UART_NUM_1) {}
155+
_pin_rst_delay(200), _pin(NULL), _apn(NULL), _rx_buffer_size(4096), _tx_buffer_size(512), _mode(ESP_MODEM_MODE_COMMAND), _uart_num(UART_NUM_1),
156+
_ppp_event_handle(0) {}
156157

157158
PPPClass::~PPPClass() {}
158159

@@ -360,7 +361,7 @@ bool PPPClass::begin(ppp_modem_model_t model, uint8_t uart_num, int baud_rate) {
360361
}
361362
}
362363

363-
Network.onSysEvent(onPppArduinoEvent);
364+
_ppp_event_handle = Network.onSysEvent(onPppArduinoEvent);
364365

365366
setStatusBits(ESP_NETIF_STARTED_BIT);
366367
arduino_event_t arduino_event;
@@ -402,7 +403,8 @@ void PPPClass::end(void) {
402403
}
403404
_esp_modem = NULL;
404405

405-
Network.removeEvent(onPppArduinoEvent);
406+
Network.removeEvent(_ppp_event_handle);
407+
_ppp_event_handle = 0;
406408

407409
if (_dce != NULL) {
408410
esp_modem_destroy(_dce);

Diff for: libraries/PPP/src/PPP.h

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class PPPClass : public NetworkInterface {
108108
int _tx_buffer_size;
109109
esp_modem_dce_mode_t _mode;
110110
uint8_t _uart_num;
111+
network_event_handle_t _ppp_event_handle;
111112

112113
static bool pppDetachBus(void *bus_pointer);
113114
};

Diff for: libraries/WiFi/src/AP.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void APClass::_onApEvent(int32_t event_id, void *event_data) {
148148
}
149149
}
150150

151-
APClass::APClass() {
151+
APClass::APClass() : _wifi_ap_event_handle(0) {
152152
_ap_network_if = this;
153153
}
154154

@@ -163,7 +163,7 @@ bool APClass::onEnable() {
163163
return false;
164164
}
165165
if (_esp_netif == NULL) {
166-
Network.onSysEvent(_onApArduinoEvent);
166+
_wifi_ap_event_handle = Network.onSysEvent(_onApArduinoEvent);
167167
_esp_netif = get_esp_interface_netif(ESP_IF_WIFI_AP);
168168
/* attach to receive events */
169169
initNetif(ESP_NETIF_ID_AP);
@@ -172,7 +172,8 @@ bool APClass::onEnable() {
172172
}
173173

174174
bool APClass::onDisable() {
175-
Network.removeEvent(_onApArduinoEvent);
175+
Network.removeEvent(_wifi_ap_event_handle);
176+
_wifi_ap_event_handle = 0;
176177
// we just set _esp_netif to NULL here, so destroyNetif() does not try to destroy it.
177178
// That would be done by WiFi.enableAP(false) if STA is not enabled, or when it gets disabled
178179
_esp_netif = NULL;

Diff for: libraries/WiFi/src/STA.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ void STAClass::_onStaEvent(int32_t event_id, void *event_data) {
228228
}
229229

230230
STAClass::STAClass()
231-
: _minSecurity(WIFI_AUTH_WPA2_PSK), _scanMethod(WIFI_FAST_SCAN), _sortMethod(WIFI_CONNECT_AP_BY_SIGNAL), _autoReconnect(true), _status(WL_STOPPED) {
231+
: _minSecurity(WIFI_AUTH_WPA2_PSK), _scanMethod(WIFI_FAST_SCAN), _sortMethod(WIFI_CONNECT_AP_BY_SIGNAL), _autoReconnect(true), _status(WL_STOPPED),
232+
_wifi_sta_event_handle(0) {
232233
_sta_network_if = this;
233234
}
234235

@@ -276,14 +277,15 @@ bool STAClass::onEnable() {
276277
return false;
277278
}
278279
/* attach to receive events */
279-
Network.onSysEvent(_onStaArduinoEvent);
280+
_wifi_sta_event_handle = Network.onSysEvent(_onStaArduinoEvent);
280281
initNetif(ESP_NETIF_ID_STA);
281282
}
282283
return true;
283284
}
284285

285286
bool STAClass::onDisable() {
286-
Network.removeEvent(_onStaArduinoEvent);
287+
Network.removeEvent(_wifi_sta_event_handle);
288+
_wifi_sta_event_handle = 0;
287289
// we just set _esp_netif to NULL here, so destroyNetif() does not try to destroy it.
288290
// That would be done by WiFi.enableSTA(false) if AP is not enabled, or when it gets disabled
289291
_esp_netif = NULL;

Diff for: libraries/WiFi/src/WiFiAP.h

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class APClass : public NetworkInterface {
6060
void _onApEvent(int32_t event_id, void *event_data);
6161

6262
protected:
63+
network_event_handle_t _wifi_ap_event_handle;
64+
6365
size_t printDriverInfo(Print &out) const;
6466

6567
friend class WiFiGenericClass;

Diff for: libraries/WiFi/src/WiFiSTA.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class STAClass : public NetworkInterface {
9595
wifi_sort_method_t _sortMethod;
9696
bool _autoReconnect;
9797
wl_status_t _status;
98+
network_event_handle_t _wifi_sta_event_handle;
9899

99100
size_t printDriverInfo(Print &out) const;
100101

0 commit comments

Comments
 (0)