void posix_timer_callback(int sig, siginfo_t *si, void *uc) { #ifdef __APPLE__ sj_invoke_cb0(v7, *bsd_timer_cb); #else sj_invoke_cb0(v7, *((v7_val_t *) si->si_value.sival_ptr)); #endif }
SJ_PRIVATE enum v7_err Wifi_ready(struct v7 *v7, v7_val_t *res) { int ret = 0; v7_val_t cbv = v7_arg(v7, 0); if (!v7_is_callable(v7, cbv)) { LOG(LL_ERROR, ("Invalid arguments")); goto exit; } if (sj_wifi_get_status() == SJ_WIFI_IP_ACQUIRED) { sj_invoke_cb0(v7, cbv); ret = 1; } else { struct wifi_cb_arg *arg = (struct wifi_cb_arg *) calloc(1, sizeof(*arg)); if (arg != NULL) { arg->v7 = v7; arg->v = cbv; v7_own(v7, &arg->v); sj_wifi_add_on_change_cb(sj_wifi_ready_js, arg); } else { ret = 0; } } exit: *res = v7_mk_boolean(v7, ret); return V7_OK; }
static void sj_timer_callback(TimerHandle_t t) { v7_val_t *cb = (v7_val_t *) pvTimerGetTimerID(t); xTimerDelete(t, 0); sj_invoke_cb0(s_v7, *cb); v7_disown(s_v7, cb); free(cb); }
void esp_timer_callback(void *arg) { struct timer_info *ti = (struct timer_info *) arg; os_timer_disarm(&ti->t); /* just in case */ sj_invoke_cb0(v7, *ti->cb); v7_disown(v7, ti->cb); free(ti->cb); free(ti); }
static void sj_timer_callback(xTimerHandle t) { struct timer_info *ti = (struct timer_info *) t; xTimerDelete(ti->t, 0); sj_invoke_cb0(v7, *ti->cb); v7_disown(v7, ti->cb); free(ti->cb); free(ti); }
void sj_wifi_ready_js(enum sj_wifi_status event, void *arg) { if (event != SJ_WIFI_IP_ACQUIRED) return; struct wifi_cb_arg *cba = (struct wifi_cb_arg *) arg; sj_invoke_cb0(cba->v7, cba->v); v7_disown(cba->v7, &cba->v); sj_wifi_remove_on_change_cb(sj_wifi_ready_js, arg); free(arg); }
void esp_timer_callback(void *arg) { struct timer_info *ti = (struct timer_info *) arg; if (ti->js_cb != NULL) { sj_invoke_cb0(v7, *ti->js_cb); v7_disown(v7, ti->js_cb); free(ti->js_cb); } if (ti->c_cb != NULL) { ti->c_cb(ti->c_cb_param); } free(ti); }
static void sj_timer_callback(xTimerHandle t) { struct timer_info *ti = (struct timer_info *) t; xTimerDelete(ti->t, 0); /* * Invoke the timer callback (depending on the build options, it might not be * actually invoked immediately, but might be scheduled for the invocation * asap instead; see `sj_invoke_cb()`) */ sj_invoke_cb0(v7, *ti->cb); /* * Disown and free the callback value which was allocated and owned in * `global_set_timeout()` */ v7_disown(v7, ti->cb); free(ti->cb); /* Also free `timer_info` which was allocated in `sj_set_timeout()` */ free(ti); }
static void sj_timer_handler(struct mg_connection *c, int ev, void *p) { struct timer_info *ti = (struct timer_info *) c->user_data; (void) p; if (ti == NULL) return; switch (ev) { case MG_EV_TIMER: { if (c->flags & MG_F_CLOSE_IMMEDIATELY) break; if (ti->v7 != NULL) sj_invoke_cb0(ti->v7, ti->js_cb); if (ti->cb != NULL) ti->cb(ti->arg); if (ti->interval_ms > 0) { c->ev_timer_time = mg_time() + ti->interval_ms / 1000.0; } else { c->flags |= MG_F_CLOSE_IMMEDIATELY; } break; } case MG_EV_CLOSE: { if (ti->v7 != NULL) v7_disown(ti->v7, &ti->js_cb); free(ti); c->user_data = NULL; break; } } }
void esp_timer_callback(void* arg) { v7_val_t* cb = (v7_val_t*) arg; sj_invoke_cb0(v7, *cb); }
static void mqtt_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { struct mg_mqtt_message *msg = (struct mg_mqtt_message *) ev_data; struct user_data *ud = (struct user_data *) nc->user_data; struct v7 *v7 = ud->v7; v7_val_t cb; (void) nc; (void) ev_data; switch (ev) { case MG_EV_CONNECT: if (*(int *) ev_data == 0) { mg_send_mqtt_handshake(nc, ud->client_id); } else { cb = v7_get(v7, ud->client, SJ_MQTT_ERROR_CB, ~0); if (!v7_is_undefined(cb)) { sj_invoke_cb0(v7, cb); } } break; case MG_EV_MQTT_CONNACK: { /* * Call connect or error cb if they were registered. */ const char *key; if (msg->connack_ret_code == MG_EV_MQTT_CONNACK_ACCEPTED) { key = SJ_MQTT_CONNECT_CB; } else { key = SJ_MQTT_ERROR_CB; } cb = v7_get(v7, ud->client, key, ~0); if (!v7_is_undefined(cb)) { sj_invoke_cb0(v7, cb); } break; } case MG_EV_MQTT_PUBLISH: cb = v7_get(v7, ud->client, SJ_MQTT_MESSAGE_CB, ~0); if (!v7_is_undefined(cb)) { v7_val_t topic = v7_mk_string(v7, msg->topic, strlen(msg->topic), 1); v7_val_t payload = v7_mk_string(v7, msg->payload.p, msg->payload.len, 1); sj_invoke_cb2(v7, cb, topic, payload); } break; case MG_EV_CLOSE: /* * Invoke close cb and then destroys all mg state. */ cb = v7_get(v7, ud->client, SJ_MQTT_CLOSE_CB, ~0); if (!v7_is_undefined(cb)) { sj_invoke_cb0(v7, cb); } v7_def(v7, ud->client, "_nc", ~0, _V7_DESC_HIDDEN(1), V7_UNDEFINED); v7_disown(v7, &ud->client); free(ud->client_id); free(ud); break; } }