예제 #1
0
void iotjs_jhandler_initialize(iotjs_jhandler_t* jhandler,
                               const jerry_value_t jfunc,
                               const jerry_value_t jthis,
                               const jerry_value_t jargv[],
                               const uint16_t jargc) {
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jhandler_t, jhandler);

  _this->jfunc = iotjs_jval_create_raw(jfunc);
  _this->jthis = iotjs_jval_create_raw(jthis);
  _this->jret = iotjs_jval_create_copied(iotjs_jval_get_undefined());
#ifdef NDEBUG
  _this->jargv = (iotjs_jval_t*)jargv;
#else
  if (jargc > 0) {
    unsigned buffer_size = sizeof(iotjs_jval_t) * jargc;
    _this->jargv = (iotjs_jval_t*)iotjs_buffer_allocate(buffer_size);
    for (int i = 0; i < jargc; ++i) {
      _this->jargv[i] = iotjs_jval_create_raw(jargv[i]);
    }
  } else {
    _this->jargv = NULL;
  }
  _this->finished = false;
#endif

  _this->jargc = jargc;
}
예제 #2
0
static iotjs_adc_t* iotjs_adc_create(const iotjs_jval_t* jadc) {
  iotjs_adc_t* adc = IOTJS_ALLOC(iotjs_adc_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_adc_t, adc);
  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, jadc, &adc_native_info);

  return adc;
}
예제 #3
0
iotjs_jval_t iotjs_jval_create_copied(const iotjs_jval_t* other) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  _this->value = jerry_acquire_value(iotjs_jval_as_raw(other));
  return jval;
}
예제 #4
0
iotjs_jval_t iotjs_jval_create_number(double v) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  _this->value = jerry_create_number(v);
  return jval;
}
예제 #5
0
iotjs_connect_reqwrap_t* iotjs_connect_reqwrap_create(jerry_value_t jcallback) {
  iotjs_connect_reqwrap_t* connect_reqwrap =
      IOTJS_ALLOC(iotjs_connect_reqwrap_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_connect_reqwrap_t, connect_reqwrap);
  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
  return connect_reqwrap;
}
예제 #6
0
iotjs_jval_t iotjs_jval_create_object() {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  _this->value = jerry_create_object();

  return jval;
}
예제 #7
0
iotjs_jval_t iotjs_jval_create_string_raw(const char* data) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  _this->value = jerry_create_string((const jerry_char_t*)data);

  return jval;
}
예제 #8
0
static iotjs_jval_t iotjs_jval_create_raw(jerry_value_t val) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  _this->value = val;

  return jval;
}
예제 #9
0
iotjs_jval_t iotjs_jval_create_array(uint32_t len) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  _this->value = jerry_create_array(len);

  return jval;
}
예제 #10
0
iotjs_jval_t iotjs_jval_create_function(JHandlerType handler) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  _this->value = jerry_create_external_function(handler);
  IOTJS_ASSERT(jerry_value_is_constructor(_this->value));

  return jval;
}
예제 #11
0
/**
 * Initialize an instance of iotjs_environment_t.
 */
static void iotjs_environment_initialize(iotjs_environment_t* env) {
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_environment_t, env);

  _this->argc = 0;
  _this->argv = NULL;
  _this->loop = NULL;
  _this->state = kInitializing;
  _this->config.memstat = false;
  _this->config.show_opcode = false;
}
예제 #12
0
iotjs_jval_t iotjs_jval_create_error_type(iotjs_error_t type, const char* msg) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  const jerry_char_t* jmsg = (const jerry_char_t*)(msg);
  _this->value = jerry_create_error((jerry_error_t)type, jmsg);
  jerry_value_clear_error_flag(&_this->value);

  return jval;
}
예제 #13
0
static iotjs_adc_reqwrap_t* iotjs_adc_reqwrap_create(
    const iotjs_jval_t* jcallback, const iotjs_jval_t* jadc, AdcOp op) {
  iotjs_adc_reqwrap_t* adc_reqwrap = IOTJS_ALLOC(iotjs_adc_reqwrap_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_adc_reqwrap_t, adc_reqwrap);

  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);

  _this->req_data.op = op;
  _this->adc_instance = iotjs_adc_instance_from_jval(jadc);
  return adc_reqwrap;
}
예제 #14
0
iotjs_blehcisocket_t* iotjs_blehcisocket_create(const iotjs_jval_t* jble) {
  THIS = IOTJS_ALLOC(iotjs_blehcisocket_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_blehcisocket_t, blehcisocket);

  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, jble,
                               &blehcisocket_native_info);

  iotjs_blehcisocket_initialize(blehcisocket);

  return blehcisocket;
}
예제 #15
0
iotjs_jval_t iotjs_jval_create_string(const iotjs_string_t* v) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  const jerry_char_t* data = (const jerry_char_t*)(iotjs_string_data(v));
  jerry_size_t size = iotjs_string_size(v);

  _this->value = jerry_create_string_sz(data, size);

  return jval;
}
예제 #16
0
static iotjs_spi_reqwrap_t* iotjs_spi_reqwrap_create(
    const iotjs_jval_t* jcallback, iotjs_spi_t* spi, SpiOp op) {
  iotjs_spi_reqwrap_t* spi_reqwrap = IOTJS_ALLOC(iotjs_spi_reqwrap_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_spi_reqwrap_t, spi_reqwrap);

  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);

  _this->req_data.op = op;
  _this->spi_instance = spi;

  return spi_reqwrap;
}
예제 #17
0
static iotjs_spi_t* iotjs_spi_create(const iotjs_jval_t* jspi) {
  iotjs_spi_t* spi = IOTJS_ALLOC(iotjs_spi_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_spi_t, spi);
  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, jspi,
                               &this_module_native_info);

#if defined(__linux__)
  _this->device = iotjs_string_create("");
#endif

  return spi;
}
예제 #18
0
static iotjs_pwm_reqwrap_t* iotjs_pwm_reqwrap_create(
    const iotjs_jval_t* jcallback, iotjs_pwm_t* pwm, PwmOp op) {
  iotjs_pwm_reqwrap_t* pwm_reqwrap = IOTJS_ALLOC(iotjs_pwm_reqwrap_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_pwm_reqwrap_t, pwm_reqwrap);

  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);

  _this->req_data.op = op;
  _this->pwm_instance = pwm;
  _this->req_data.caller = NULL;

  return pwm_reqwrap;
}
예제 #19
0
static iotjs_pwm_t* iotjs_pwm_create(const iotjs_jval_t* jpwm) {
  iotjs_pwm_t* pwm = IOTJS_ALLOC(iotjs_pwm_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_pwm_t, pwm);
  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, jpwm,
                               &this_module_native_info);

  _this->period = -1;
  _this->duty_cycle = 0;
#if defined(__NUTTX__)
  _this->device_fd = -1;
#endif
  return pwm;
}
예제 #20
0
//--------------https_poll Functions------------------
iotjs_https_poll_t* iotjs_https_poll_create(uv_loop_t* loop,
                                            curl_socket_t sockfd,
                                            iotjs_https_t* https_data) {
  iotjs_https_poll_t* poll_data = IOTJS_ALLOC(iotjs_https_poll_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_https_poll_t, poll_data);
  _this->sockfd = sockfd;
  _this->poll_handle.data = poll_data;
  _this->https_data = https_data;
  _this->closing = false;
  _this->next = NULL;
  uv_poll_init_socket(loop, &_this->poll_handle, sockfd);
  return poll_data;
}
예제 #21
0
iotjs_tcpwrap_t* iotjs_tcpwrap_create(jerry_value_t jtcp) {
  iotjs_tcpwrap_t* tcpwrap = IOTJS_ALLOC(iotjs_tcpwrap_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_tcpwrap_t, tcpwrap);

  iotjs_handlewrap_initialize(&_this->handlewrap, jtcp,
                              (uv_handle_t*)(&_this->handle),
                              &this_module_native_info);

  const iotjs_environment_t* env = iotjs_environment_get();
  uv_tcp_init(iotjs_environment_loop(env), &_this->handle);

  return tcpwrap;
}
예제 #22
0
iotjs_jargs_t iotjs_jargs_create(uint16_t capacity) {
  iotjs_jargs_t jargs;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jargs_t, &jargs);

  _this->capacity = capacity;
  _this->argc = 0;
  if (capacity > 0) {
    unsigned buffer_size = sizeof(iotjs_jval_t) * capacity;
    _this->argv = (iotjs_jval_t*)iotjs_buffer_allocate(buffer_size);
  } else {
    return jargs_empty;
  }

  return jargs;
}
예제 #23
0
iotjs_jval_t iotjs_jval_create_byte_array(uint32_t len, const char* data) {
  iotjs_jval_t jval;
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jval_t, &jval);

  IOTJS_ASSERT(data != NULL);

  _this->value = jerry_create_array(len);
  for (uint32_t i = 0; i < len; i++) {
    jerry_value_t val = jerry_create_number((double)data[i]);
    jerry_set_property_by_index(_this->value, i, val);
    jerry_release_value(val);
  }

  return jval;
}
예제 #24
0
iotjs_bufferwrap_t* iotjs_bufferwrap_create(const iotjs_jval_t* jbuiltin,
                                            size_t length) {
  iotjs_bufferwrap_t* bufferwrap = IOTJS_ALLOC(iotjs_bufferwrap_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_bufferwrap_t, bufferwrap);

  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, jbuiltin,
                               &this_module_native_info);
  if (length > 0) {
    _this->length = length;
    _this->buffer = iotjs_buffer_allocate(length);
    IOTJS_ASSERT(_this->buffer != NULL);
  } else {
    _this->length = 0;
    _this->buffer = NULL;
  }

  IOTJS_ASSERT(
      bufferwrap ==
      (iotjs_bufferwrap_t*)(iotjs_jval_get_object_native_handle(jbuiltin)));

  return bufferwrap;
}
예제 #25
0
//-------------Constructor------------
iotjs_https_t* iotjs_https_create(const char* URL, const char* method,
                                  const char* ca, const char* cert,
                                  const char* key,
                                  const bool reject_unauthorized,
                                  const iotjs_jval_t* jthis) {
  iotjs_https_t* https_data = IOTJS_ALLOC(iotjs_https_t);
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_https_t, https_data);

  // Original Request Details
  _this->URL = URL;
  _this->header_list = NULL;
  if (strcmp(method, STRING_GET) == 0)
    _this->method = HTTPS_GET;
  else if (strcmp(method, STRING_POST) == 0)
    _this->method = HTTPS_POST;
  else if (strcmp(method, STRING_PUT) == 0)
    _this->method = HTTPS_PUT;
  else if (strcmp(method, STRING_DELETE) == 0)
    _this->method = HTTPS_DELETE;
  else if (strcmp(method, STRING_HEAD) == 0)
    _this->method = HTTPS_HEAD;
  else if (strcmp(method, STRING_CONNECT) == 0)
    _this->method = HTTPS_CONNECT;
  else if (strcmp(method, STRING_OPTIONS) == 0)
    _this->method = HTTPS_OPTIONS;
  else if (strcmp(method, STRING_TRACE) == 0)
    _this->method = HTTPS_TRACE;
  else {
    IOTJS_ASSERT(0);
  }

  // TLS certs stuff
  _this->ca = ca;
  _this->cert = cert;
  _this->key = key;
  _this->reject_unauthorized = reject_unauthorized;
  // Content Length stuff
  _this->content_length = -1;

  // Handles
  _this->loop = iotjs_environment_loop(iotjs_environment_get());
  _this->jthis_native = iotjs_jval_create_copied(jthis);
  iotjs_jval_set_object_native_handle(&(_this->jthis_native),
                                      (uintptr_t)https_data,
                                      &https_native_info);
  _this->curl_multi_handle = curl_multi_init();
  _this->curl_easy_handle = curl_easy_init();
  _this->timeout.data = (void*)https_data;
  uv_timer_init(_this->loop, &(_this->timeout));
  _this->request_done = false;
  _this->closing_handles = 3;
  _this->poll_data = NULL;

  // Timeout stuff
  _this->timeout_ms = -1;
  _this->last_bytes_num = -1;
  _this->last_bytes_time = 0;
  _this->socket_timeout.data = (void*)https_data;
  uv_timer_init(_this->loop, &(_this->socket_timeout));

  // ReadData stuff
  _this->cur_read_index = 0;
  _this->is_stream_writable = false;
  _this->stream_ended = false;
  _this->data_to_read = false;
  _this->to_destroy_read_onwrite = false;
  _this->async_read_onwrite.data = (void*)https_data;
  uv_timer_init(_this->loop, &(_this->async_read_onwrite));
  // No Need to read data for following types of requests
  if (_this->method == HTTPS_GET || _this->method == HTTPS_DELETE ||
      _this->method == HTTPS_HEAD || _this->method == HTTPS_OPTIONS ||
      _this->method == HTTPS_TRACE)
    _this->stream_ended = true;

  return https_data;
}
예제 #26
0
static void iotjs_jargs_initialize_empty(iotjs_jargs_t* jargs) {
  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_jargs_t, jargs);
  _this->capacity = 0;
  _this->argc = 0;
  _this->argv = NULL;
}