示例#1
0
/* Call the callback with a list of ssids found in the air. */
SJ_PRIVATE enum v7_err Wifi_scan(struct v7 *v7, v7_val_t *res) {
  v7_val_t cb;

  if (s_wifi_scan_cb.v7 != NULL) {
    return v7_throwf(v7, "Error", "scan in progress");
  }

  cb = v7_arg(v7, 0);
  if (!v7_is_callable(v7, cb)) {
    return v7_throwf(v7, "Error", "Invalid argument");
  }

  s_wifi_scan_cb.v7 = v7;
  s_wifi_scan_cb.v = cb;
  v7_own(v7, &s_wifi_scan_cb.v);

  sj_wifi_scan(sj_wifi_scan_done, &s_wifi_scan_cb);

  (void) res;
  return V7_OK;
}
示例#2
0
/* Call the callback with a list of ssids found in the air. */
static v7_val_t Wifi_scan(struct v7 *v7) {
  int r;
  v7_val_t cb = v7_get(v7, s_wifi, "_scb", ~0);
  if (v7_is_function(cb)) {
    fprintf(stderr, "scan in progress");
    return v7_create_boolean(0);
  }

  cb = v7_arg(v7, 0);
  if (!v7_is_function(cb)) {
    fprintf(stderr, "invalid argument");
    return v7_create_boolean(0);
  }
  v7_set(v7, s_wifi, "_scb", ~0, V7_PROPERTY_DONT_ENUM | V7_PROPERTY_HIDDEN,
         cb);

  r = sj_wifi_scan(sj_wifi_scan_done);
  if (r == 0) {
    v7_set(v7, s_wifi, "_scb", ~0, V7_PROPERTY_DONT_ENUM | V7_PROPERTY_HIDDEN,
           v7_create_undefined());
  }
  return v7_create_boolean(r);
}