Пример #1
0
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;
}
Пример #2
0
static v7_val_t Wifi_status(struct v7 *v7) {
  v7_val_t res;
  char *status = sj_wifi_get_status();
  if (status == NULL) return v7_create_undefined();
  res = v7_create_string(v7, status, strlen(status), 1);
  free(status);
  return res;
}