Ejemplo n.º 1
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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 3
0
int iotjs_tizen_bridge_native(const char* fn_name, unsigned fn_name_size,
                              const char* message, unsigned message_size,
                              user_callback_t cb) {
  iotjs_environment_t* env = iotjs_environment_get();

  if (env->state != kRunningMain && env->state != kRunningLoop) {
    return IOTJS_ERROR_RESULT_FAILED;
  }

  iotjs_call_jfunc_t* handle = IOTJS_ALLOC(iotjs_call_jfunc_t);

  if (handle == NULL) {
    return IOTJS_ERROR_OUT_OF_MEMORY;
  }

  handle->async.data = (void*)handle;
  handle->fn_name = create_string_buffer(fn_name, fn_name_size);
  handle->message = create_string_buffer(message, message_size);
  handle->module = create_string_buffer(IOTJS_MAGIC_STRING_TIZEN,
                                        sizeof(IOTJS_MAGIC_STRING_TIZEN));
  handle->cb = cb;

  uv_loop_t* loop = iotjs_environment_loop(env);
  uv_async_init(loop, &handle->async, bridge_native_async_handler);
  uv_async_send(&handle->async);

  return IOTJS_ERROR_NONE;
}
Ejemplo n.º 4
0
void iotjs_i2c_create_platform_data(iotjs_i2c_t* i2c) {
  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_i2c_t, i2c);

  _this->platform_data = IOTJS_ALLOC(iotjs_i2c_platform_data_t);

  _this->platform_data->i2c_context = NULL;
}
Ejemplo n.º 5
0
void i2c_create_platform_data(iotjs_jhandler_t* jhandler, iotjs_i2c_t* i2c,
                              iotjs_i2c_platform_data_t** ppdata) {
  iotjs_i2c_platform_data_t* pdata = IOTJS_ALLOC(iotjs_i2c_platform_data_t);

  DJHANDLER_CHECK_ARGS(2, number, function);
  pdata->device = JHANDLER_GET_ARG(0, number);
  pdata->i2c_master = NULL;
  *ppdata = pdata;
}
Ejemplo n.º 6
0
iotjs_blehcisocket_t* iotjs_blehcisocket_create(jerry_value_t jble) {
  iotjs_blehcisocket_t* blehcisocket = IOTJS_ALLOC(iotjs_blehcisocket_t);

  blehcisocket->jobject = jble;
  jerry_set_object_native_pointer(jble, blehcisocket, &this_module_native_info);

  iotjs_blehcisocket_initialize(blehcisocket);

  return blehcisocket;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
0
void iotjs_uart_create_platform_data(iotjs_uart_t* uart) {
  uart->platform_data = IOTJS_ALLOC(iotjs_uart_platform_data_t);
}
Ejemplo n.º 17
0
void iotjs_i2c_create_platform_data(iotjs_i2c_t* i2c) {
  i2c->platform_data = IOTJS_ALLOC(iotjs_i2c_platform_data_t);

  i2c->platform_data->i2c_context = NULL;
}
Ejemplo n.º 18
0
void iotjs_gpio_create_platform_data(iotjs_gpio_t* gpio) {
  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_t, gpio);
  _this->platform_data = IOTJS_ALLOC(iotjs_gpio_platform_data_t);
  _this->platform_data->value_fd = -1;
  uv_mutex_init(&_this->platform_data->mutex);
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
void iotjs_adc_create_platform_data(iotjs_adc_t* adc) {
  adc->platform_data = IOTJS_ALLOC(iotjs_adc_platform_data_t);
  adc->platform_data->pin = 0;
}
Ejemplo n.º 21
0
void iotjs_pwm_create_platform_data(iotjs_pwm_t* pwm) {
  pwm->platform_data = IOTJS_ALLOC(iotjs_pwm_platform_data_t);
  pwm->platform_data->device_fd = -1;
}
Ejemplo n.º 22
0
void iotjs_spi_create_platform_data(iotjs_spi_t* spi) {
  spi->platform_data = IOTJS_ALLOC(iotjs_spi_platform_data_t);
  spi->platform_data->bus = -1;
  spi->platform_data->cs_chip = 0;
  spi->platform_data->spi_dev = NULL;
}
Ejemplo n.º 23
0
iotjs_fs_reqwrap_t* iotjs_fs_reqwrap_create(const jerry_value_t jcallback) {
  iotjs_fs_reqwrap_t* fs_reqwrap = IOTJS_ALLOC(iotjs_fs_reqwrap_t);
  iotjs_reqwrap_initialize(&fs_reqwrap->reqwrap, jcallback,
                           (uv_req_t*)&fs_reqwrap->req);
  return fs_reqwrap;
}