コード例 #1
0
ファイル: iotjs_module.c プロジェクト: esevan/iotjs
const iotjs_jval_t* iotjs_module_initialize_if_necessary(ModuleKind kind) {
  IOTJS_ASSERT(kind < MODULE_COUNT);
  IOTJS_ASSERT(&modules[kind].fn_register != NULL);

  if (iotjs_jval_is_undefined(&modules[kind].jmodule)) {
    modules[kind].jmodule = modules[kind].fn_register();
  }

  return iotjs_module_get(kind);
}
コード例 #2
0
// Call onWrite and callback after ClientRequest._write
void iotjs_https_call_read_onwrite(uv_timer_t* timer) {
  iotjs_https_t* https_data = (iotjs_https_t*)(timer->data);
  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data);

  uv_timer_stop(&(_this->async_read_onwrite));
  if (iotjs_jval_is_null(&_this->jthis_native))
    return;
  const iotjs_jargs_t* jarg = iotjs_jargs_get_empty();
  const iotjs_jval_t* jthis = &(_this->jthis_native);
  IOTJS_ASSERT(iotjs_jval_is_function(&(_this->read_onwrite)));

  if (!iotjs_jval_is_undefined(&(_this->read_callback)))
    iotjs_make_callback(&(_this->read_callback), jthis, jarg);

  iotjs_make_callback(&(_this->read_onwrite), jthis, jarg);
}
コード例 #3
0
ファイル: iotjs_module_spi.c プロジェクト: drashti304/TizenRT
static int iotjs_spi_get_array_data(char** buf, const iotjs_jval_t* jarray) {
  iotjs_jval_t jlength =
      iotjs_jval_get_property(jarray, IOTJS_MAGIC_STRING_LENGTH);
  IOTJS_ASSERT(!iotjs_jval_is_undefined(&jlength));

  size_t length = iotjs_jval_as_number(&jlength);
  IOTJS_ASSERT((int)length >= 0);
  *buf = iotjs_buffer_allocate(length);

  for (size_t i = 0; i < length; i++) {
    iotjs_jval_t jdata = iotjs_jval_get_property_by_index(jarray, i);
    (*buf)[i] = iotjs_jval_as_number(&jdata);
    iotjs_jval_destroy(&jdata);
  }

  iotjs_jval_destroy(&jlength);

  return (int)length;
}
コード例 #4
0
// Cleanup before destructor
void iotjs_https_cleanup(iotjs_https_t* https_data) {
  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data);
  _this->loop = NULL;

  uv_close((uv_handle_t*)&_this->timeout,
           (uv_close_cb)iotjs_https_uv_close_callback);
  uv_close((uv_handle_t*)&_this->socket_timeout,
           (uv_close_cb)iotjs_https_uv_close_callback);
  uv_close((uv_handle_t*)&_this->async_read_onwrite,
           (uv_close_cb)iotjs_https_uv_close_callback);

  iotjs_https_jcallback(https_data, IOTJS_MAGIC_STRING_ONEND,
                        iotjs_jargs_get_empty(), false);
  iotjs_https_jcallback(https_data, IOTJS_MAGIC_STRING_ONCLOSED,
                        iotjs_jargs_get_empty(), false);

  curl_multi_remove_handle(_this->curl_multi_handle, _this->curl_easy_handle);
  curl_easy_cleanup(_this->curl_easy_handle);
  _this->curl_easy_handle = NULL;
  curl_multi_cleanup(_this->curl_multi_handle);
  _this->curl_multi_handle = NULL;
  curl_slist_free_all(_this->header_list);

  if (_this->poll_data != NULL)
    iotjs_https_poll_close_all(_this->poll_data);

  if (_this->to_destroy_read_onwrite) {
    const iotjs_jargs_t* jarg = iotjs_jargs_get_empty();
    const iotjs_jval_t* jthis = &(_this->jthis_native);
    IOTJS_ASSERT(iotjs_jval_is_function(&(_this->read_onwrite)));

    if (!iotjs_jval_is_undefined(&(_this->read_callback)))
      iotjs_make_callback(&(_this->read_callback), jthis, jarg);

    iotjs_make_callback(&(_this->read_onwrite), jthis, jarg);
    _this->to_destroy_read_onwrite = false;
    iotjs_string_destroy(&(_this->read_chunk));
    iotjs_jval_destroy(&(_this->read_onwrite));
    iotjs_jval_destroy(&(_this->read_callback));
  }
  return;
}
コード例 #5
0
ファイル: iotjs_module.c プロジェクト: esevan/iotjs
const iotjs_jval_t* iotjs_module_get(ModuleKind kind) {
  IOTJS_ASSERT(kind < MODULE_COUNT);
  IOTJS_ASSERT(!iotjs_jval_is_undefined(&modules[kind].jmodule));
  return &modules[kind].jmodule;
}