Skip to content

Commit

Permalink
BREAKING: Move mgos_net API to mgos_event
Browse files Browse the repository at this point in the history
`mgos_net_add_event_handler()` is removed in favor of `mgos_event`-based
API.

Example:
```c
static void my_net_ev_handler(int ev, void *evd, void *arg) {
  if (ev == MGOS_NET_EV_IP_ACQUIRED) {
    LOG(LL_INFO, ("Just got IP!"));
    // Fetch something very useful from somewhere
  }
  (void) evd;
  (void) arg;
}

// Somewhere else:
mgos_event_add_group_handler(MGOS_EVENT_GRP_NET, my_net_ev_handler, NULL);
```

PUBLISHED_FROM=3e468cd9d0698d49713e57429776c29c624b1325
  • Loading branch information
dimonomid authored and cesantabot committed Dec 22, 2017
1 parent ce27e66 commit 7dcd4ec
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/mgos_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,11 @@ void mgos_mqtt_set_connect_fn(mgos_mqtt_connect_fn_t fn, void *fn_arg) {
s_connect_fn_arg = fn_arg;
}

static void mgos_mqtt_net_ev(enum mgos_net_event ev,
const struct mgos_net_event_data *ev_data,
void *arg) {
static void mgos_mqtt_net_ev(int ev, void *evd, void *arg) {
if (ev != MGOS_NET_EV_IP_ACQUIRED) return;

mgos_mqtt_global_connect();
(void) ev_data;
(void) evd;
(void) arg;
}

Expand Down Expand Up @@ -275,7 +273,7 @@ bool mgos_mqtt_init(void) {
LOG(LL_ERROR, ("MQTT requires server name"));
return false;
}
mgos_net_add_event_handler(mgos_mqtt_net_ev, NULL);
mgos_event_add_group_handler(MGOS_EVENT_GRP_NET, mgos_mqtt_net_ev, NULL);

mgos_mqtt_set_max_qos(mgos_sys_config_get_mqtt_max_qos());

Expand Down

0 comments on commit 7dcd4ec

Please sign in to comment.