Remove useless files 47/133447/1
authorSumin Lim <sumin.lim@samsung.com>
Mon, 12 Jun 2017 08:36:35 +0000 (17:36 +0900)
committerSumin Lim <sumin.lim@samsung.com>
Mon, 12 Jun 2017 08:37:29 +0000 (17:37 +0900)
Change-Id: I13f6f8ad38e0a5075399903dc80c74eeee0f27de

35 files changed:
packaging/iotjs01.spec [deleted file]
src/module/iotjs_module_adc.c [deleted file]
src/module/iotjs_module_adc.h [deleted file]
src/module/iotjs_module_blehcisocket.c [deleted file]
src/module/iotjs_module_blehcisocket.h [deleted file]
src/module/iotjs_module_buffer.c [deleted file]
src/module/iotjs_module_buffer.h [deleted file]
src/module/iotjs_module_console.c [deleted file]
src/module/iotjs_module_constants.c [deleted file]
src/module/iotjs_module_dns.c [deleted file]
src/module/iotjs_module_dns.h [deleted file]
src/module/iotjs_module_fs.c [deleted file]
src/module/iotjs_module_fs.h [deleted file]
src/module/iotjs_module_gpio.c [deleted file]
src/module/iotjs_module_gpio.h [deleted file]
src/module/iotjs_module_httpparser.c [deleted file]
src/module/iotjs_module_httpparser.h [deleted file]
src/module/iotjs_module_i2c.c [deleted file]
src/module/iotjs_module_i2c.h [deleted file]
src/module/iotjs_module_process.c [deleted file]
src/module/iotjs_module_pwm.c [deleted file]
src/module/iotjs_module_pwm.h [deleted file]
src/module/iotjs_module_spi.c [deleted file]
src/module/iotjs_module_spi.h [deleted file]
src/module/iotjs_module_stm32f4dis.c [deleted file]
src/module/iotjs_module_stm32f4dis.h [deleted file]
src/module/iotjs_module_tcp.c [deleted file]
src/module/iotjs_module_tcp.h [deleted file]
src/module/iotjs_module_testdriver.c [deleted file]
src/module/iotjs_module_timer.c [deleted file]
src/module/iotjs_module_timer.h [deleted file]
src/module/iotjs_module_uart.c [deleted file]
src/module/iotjs_module_uart.h [deleted file]
src/module/iotjs_module_udp.c [deleted file]
src/module/iotjs_module_udp.h [deleted file]

diff --git a/packaging/iotjs01.spec b/packaging/iotjs01.spec
deleted file mode 100644 (file)
index 46e3eaf..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-Name: iotjs\r
-Version: 1.0.0\r
-Release: 0\r
-Summary: IoT.js Runtime\r
-Group: Network & Connectivity \r
-License: Apache-2.0\r
-URL: https://www.iotjs.net/\r
-Source0:    %{name}-%{version}.tar.gz\r
-Source1001: %{name}.manifest\r
-\r
-# Use the official macros that are defined in Project Config (build.tizen.org).\r
-# https://build.tizen.org/project/prjconf?project=<project_name>\r
-#  - tizen_version_major 4\r
-#  - tizen_version_minor 0\r
-# For backward compatibility. Not needed (always true) in unified environment.\r
-#  - unified (undefined)\r
-  \r
-%ifarch arm armv7l\r
-#BuildRequires: python-accel-armv7l-cross-arm\r
-#BuildRequires: arm-linux-gnueabi\r
-#BuildRequires: arm-linux-gnueabi-gcc\r
-%define __arm__ "arm"\r
-%define __ARM__ "arm"\r
-%endif\r
-%ifarch x86\r
-%define __X86__ "x86"\r
-%endif\r
-%ifarch i686\r
-%define __I686__ "i686"\r
-%endif\r
-%ifarch x86_64\r
-%define __x86_64 "x86_64"\r
-%define __X86_64 "x86_64"\r
-%endif\r
-%define exe_install_dir %{buildroot}%{_bindir}\r
-\r
-%define sysroot_path "--sysroot=~/tizen-studio/platforms/tizen-3.0/mobile/rootstraps/mobile-3.0-device.core/"\r
-\r
-#%define ex_install_dir %{buildroot}%{_bindir}\r
-\r
-# Default values to be eventually overiden BEFORE or as gbs params:\r
-# iotjs uses smallcase letter\r
-%{!?target-arch: %define target-arch arm}\r
-%{!?target_os: %define target_os tizen}\r
-%{!?target_board: %define target_board artik10}\r
-%{!?compile-flag: %define compile-flag %{sysroot_path}}\r
-#BuildRequires: cross-arm-linux-gnueabi-binutils cross-arm-linux-gnueabi-kernel-headers cross-arm-linux-gnueabi-glibc-headers mpfr-devel gmp-devel mpc-devel\r
-\r
-BuildRequires:  python, libcurl-devel\r
-BuildRequires:  openssl-devel\r
-BuildRequires:  pkgconfig(glib-2.0)\r
-BuildRequires:  pkgconfig(dlog)\r
-#BuildRequires: gcc-arm-linux-gnueabi\r
-#BuildRequires:  cross-arm-linux-gnueabi-binutils cross-arm-linux-gnueabi-kernel-headers cross-arm-linux-gnueabi-glibc-headers \r
-#BuildRequires:  cross-arm-binutils\r
-#BuildRequires:  cross-armv7l-gcc48-icecream-backend\r
-\r
-Requires(postun): /sbin/ldconfig\r
-Requires(post): /sbin/ldconfig\r
-\r
-%description\r
-An open source reference implementation of the Iotjs\r
-Iotjs Runtime is included.\r
-\r
-%package service\r
-Summary: Development files for %{name}\r
-Group: Network & Connectivity/Service\r
-Requires: %{name} = %{version}-%{release}\r
-\r
-%description service\r
-The %{name}-service package contains service libraries files for\r
-developing applications that use %{name}-service.\r
-\r
-#%package test\r
-#Summary: Development files for %{name}\r
-#Group: Network & Connectivity/Testing\r
-#Requires: %{name} = %{version}-%{release}\r
-\r
-#%description test\r
-#The %{name}-test package contains example files to show\r
-#how the iotjs works using %{name}-test\r
-\r
-%package devel\r
-Summary: Development files for %{name}\r
-Group: Network & Connectivity/Development\r
-Requires: %{name} = %{version}-%{release}\r
-Requires: pkgconfig\r
-\r
-%description devel\r
-The %{name}-devel package contains libraries and header files for\r
-developing applications that use %{name}.\r
-\r
-%prep\r
-%setup -q\r
-chmod g-w %_sourcedir/*\r
-cat LICENSE\r
-\r
-cp %{SOURCE1001} .\r
-\r
-%build\r
-tools/build.py \\r
-  --target-arch=arm --target-os=tizen --target-board=artik10 --no-init-submodule \r
-#eol\r
-#--compile-flag="--sysroot=~/tizen-studio/platforms/tizen-3.0/mobile/rootstraps/mobile-3.0-device.core/"\r
-\r
-%install\r
-cp ./build/arm-tizen/debug/iotjs/iotjs %{buildroot}%{_bindir}\r
-rm -rf %{buildroot}\r
-#eol\r
-rm -rfv . %{buildroot}/out %{buildroot}/${HOME} ||:\r
-\r
-install -d %{buildroot}%{_includedir}/iotjs\r
-\r
-\r
-%post -p /sbin/ldconfig\r
-\r
-%postun -p /sbin/ldconfig\r
-\r
-%files\r
-%manifest %{name}.manifest\r
-%defattr(-,root,root,-)\r
-%license LICENSE\r
-\r
-%files service\r
-%manifest %{name}.manifest\r
-%defattr (-,root,root,-)\r
-%license LICENSE\r
-%{_bindir}/*\r
-\r
-%files devel\r
-%manifest %{name}.manifest\r
-%defattr (-,root,root,-)\r
-%license LICENSE\r
-%{_bindir}/*\r
diff --git a/src/module/iotjs_module_adc.c b/src/module/iotjs_module_adc.c
deleted file mode 100644 (file)
index aa3961d..0000000
+++ /dev/null
@@ -1,290 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module_adc.h"
-#include "iotjs_objectwrap.h"
-
-
-static void iotjs_adc_destroy(iotjs_adc_t* adc);
-static iotjs_adc_t* iotjs_adc_instance_from_jval(const iotjs_jval_t* jadc);
-
-
-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,
-                               (JFreeHandlerType)iotjs_adc_destroy);
-
-  return adc;
-}
-
-
-static void iotjs_adc_destroy(iotjs_adc_t* adc) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_adc_t, adc);
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-#if defined(__linux__)
-  iotjs_string_destroy(&_this->device);
-#endif
-  IOTJS_RELEASE(adc);
-}
-
-
-#define THIS iotjs_adc_reqwrap_t* adc_reqwrap
-
-
-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;
-}
-
-
-static void iotjs_adc_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_adc_reqwrap_t, adc_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(adc_reqwrap);
-}
-
-
-static void iotjs_adc_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_adc_reqwrap_t, adc_reqwrap);
-  iotjs_adc_reqwrap_destroy(adc_reqwrap);
-}
-
-
-static uv_work_t* iotjs_adc_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_adc_reqwrap_t, adc_reqwrap);
-  return &_this->req;
-}
-
-
-static const iotjs_jval_t* iotjs_adc_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_adc_reqwrap_t, adc_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-
-static iotjs_adc_t* iotjs_adc_instance_from_jval(const iotjs_jval_t* jadc) {
-  uintptr_t handle = iotjs_jval_get_object_native_handle(jadc);
-  return (iotjs_adc_t*)handle;
-}
-
-
-iotjs_adc_reqwrap_t* iotjs_adc_reqwrap_from_request(uv_work_t* req) {
-  return (iotjs_adc_reqwrap_t*)(iotjs_reqwrap_from_request((uv_req_t*)req));
-}
-
-
-iotjs_adc_reqdata_t* iotjs_adc_reqwrap_data(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_adc_reqwrap_t, adc_reqwrap);
-  return &_this->req_data;
-}
-
-
-iotjs_adc_t* iotjs_adc_instance_from_reqwrap(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_adc_reqwrap_t, adc_reqwrap);
-  return _this->adc_instance;
-}
-
-
-#undef THIS
-
-
-static void iotjs_adc_after_work(uv_work_t* work_req, int status) {
-  iotjs_adc_reqwrap_t* req_wrap = iotjs_adc_reqwrap_from_request(work_req);
-  iotjs_adc_reqdata_t* req_data = iotjs_adc_reqwrap_data(req_wrap);
-  iotjs_jargs_t jargs = iotjs_jargs_create(2);
-  bool result = req_data->result;
-
-  if (status) {
-    iotjs_jval_t error = iotjs_jval_create_error("System error");
-    iotjs_jargs_append_jval(&jargs, &error);
-    iotjs_jval_destroy(&error);
-  } else {
-    switch (req_data->op) {
-      case kAdcOpOpen:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Failed to open ADC device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      case kAdcOpRead:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Cannot read from ADC device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-          iotjs_jargs_append_number(&jargs, req_data->value);
-        }
-        break;
-      case kAdcOpClose:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Cannot close ADC device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      default: {
-        IOTJS_ASSERT(!"Unreachable");
-        break;
-      }
-    }
-  }
-
-  const iotjs_jval_t* jcallback = iotjs_adc_reqwrap_jcallback(req_wrap);
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &jargs);
-
-  iotjs_jargs_destroy(&jargs);
-
-  iotjs_adc_reqwrap_dispatched(req_wrap);
-}
-
-
-static void iotjs_adc_set_configuration(iotjs_adc_t* adc,
-                                        const iotjs_jval_t* jconfiguration) {
-#if defined(__linux__)
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_adc_t, adc);
-  iotjs_jval_t jdevice =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_DEVICE);
-  _this->device = iotjs_jval_as_string(&jdevice);
-  iotjs_jval_destroy(&jdevice);
-#elif defined(__NUTTX__)
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_adc_t, adc);
-  iotjs_jval_t jpin =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_PIN);
-  _this->pin = iotjs_jval_as_number(&jpin);
-  iotjs_jval_destroy(&jpin);
-#endif
-}
-
-
-static void iotjs_adc_read_worker(uv_work_t* work_req) {
-  ADC_WORKER_INIT;
-  int32_t value = iotjs_adc_read(adc);
-
-  if (value < 0) {
-    req_data->result = false;
-    return;
-  }
-
-  req_data->value = value;
-  req_data->result = true;
-}
-
-
-static void iotjs_adc_close_worker(uv_work_t* work_req) {
-  ADC_WORKER_INIT;
-
-  // Release driver
-  if (!iotjs_adc_close(adc)) {
-    req_data->result = false;
-    return;
-  }
-
-  req_data->result = true;
-}
-
-
-#define ADC_ASYNC(call, jthis, jcallback, op)                                  \
-  do {                                                                         \
-    uv_loop_t* loop = iotjs_environment_loop(iotjs_environment_get());         \
-    iotjs_adc_reqwrap_t* req_wrap =                                            \
-        iotjs_adc_reqwrap_create(jcallback, jthis, op);                        \
-    uv_work_t* req = iotjs_adc_reqwrap_req(req_wrap);                          \
-    uv_queue_work(loop, req, iotjs_adc_##call##_worker, iotjs_adc_after_work); \
-  } while (0)
-
-
-JHANDLER_FUNCTION(AdcConstructor) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, object, function);
-
-  // Create ADC object
-  const iotjs_jval_t* jadc = JHANDLER_GET_THIS(object);
-  iotjs_adc_t* adc = iotjs_adc_create(jadc);
-  IOTJS_ASSERT(adc == iotjs_adc_instance_from_jval(jadc));
-
-  iotjs_adc_set_configuration(adc, JHANDLER_GET_ARG(0, object));
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(1, function);
-  ADC_ASYNC(open, jadc, jcallback, kAdcOpOpen);
-}
-
-
-JHANDLER_FUNCTION(Read) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARG_IF_EXIST(0, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(0, function);
-  const iotjs_jval_t* jadc = JHANDLER_GET_THIS(object);
-  iotjs_adc_t* adc = iotjs_adc_instance_from_jval(jadc);
-
-  if (jcallback) {
-    ADC_ASYNC(read, jadc, jcallback, kAdcOpRead);
-  } else {
-    int32_t value = iotjs_adc_read(adc);
-    if (value < 0) {
-      JHANDLER_THROW(COMMON, "ADC Read Error");
-    } else {
-      iotjs_jhandler_return_number(jhandler, value);
-    }
-  }
-}
-
-
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARG_IF_EXIST(0, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(0, function);
-  const iotjs_jval_t* jadc = JHANDLER_GET_THIS(object);
-  iotjs_adc_t* adc = iotjs_adc_instance_from_jval(jadc);
-
-  if (jcallback) {
-    ADC_ASYNC(close, jadc, jcallback, kAdcOpClose);
-  } else {
-    if (!iotjs_adc_close(adc)) {
-      JHANDLER_THROW(COMMON, "ADC Close Error");
-    }
-  }
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-iotjs_jval_t InitAdc() {
-  iotjs_jval_t jadc = iotjs_jval_create_object();
-  iotjs_jval_t jadcConstructor =
-      iotjs_jval_create_function_with_dispatch(AdcConstructor);
-  iotjs_jval_set_property_jval(&jadc, IOTJS_MAGIC_STRING_ADC, &jadcConstructor);
-
-  iotjs_jval_t jprototype = iotjs_jval_create_object();
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_READ, Read);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_CLOSE, Close);
-  iotjs_jval_set_property_jval(&jadcConstructor, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &jprototype);
-
-  iotjs_jval_destroy(&jprototype);
-  iotjs_jval_destroy(&jadcConstructor);
-
-  return jadc;
-}
diff --git a/src/module/iotjs_module_adc.h b/src/module/iotjs_module_adc.h
deleted file mode 100644 (file)
index 4fd04fd..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_ADC_H
-#define IOTJS_MODULE_ADC_H
-
-#include "iotjs_def.h"
-#include "iotjs_objectwrap.h"
-#include "iotjs_reqwrap.h"
-
-
-typedef enum {
-  kAdcOpOpen,
-  kAdcOpRead,
-  kAdcOpClose,
-} AdcOp;
-
-
-typedef struct {
-  iotjs_jobjectwrap_t jobjectwrap;
-
-#if defined(__linux__)
-  iotjs_string_t device;
-#elif defined(__NUTTX__)
-  uint32_t pin;
-#endif
-  int32_t device_fd;
-} IOTJS_VALIDATED_STRUCT(iotjs_adc_t);
-
-
-typedef struct {
-  int32_t value;
-
-  bool result;
-  AdcOp op;
-} iotjs_adc_reqdata_t;
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_work_t req;
-  iotjs_adc_reqdata_t req_data;
-  iotjs_adc_t* adc_instance;
-} IOTJS_VALIDATED_STRUCT(iotjs_adc_reqwrap_t);
-
-
-#define THIS iotjs_adc_reqwrap_t* adc_reqwrap
-
-iotjs_adc_reqwrap_t* iotjs_adc_reqwrap_from_request(uv_work_t* req);
-iotjs_adc_reqdata_t* iotjs_adc_reqwrap_data(THIS);
-
-iotjs_adc_t* iotjs_adc_instance_from_reqwrap(THIS);
-
-#undef THIS
-
-
-#define ADC_WORKER_INIT                                                     \
-  iotjs_adc_reqwrap_t* req_wrap = iotjs_adc_reqwrap_from_request(work_req); \
-  iotjs_adc_reqdata_t* req_data = iotjs_adc_reqwrap_data(req_wrap);         \
-  iotjs_adc_t* adc = iotjs_adc_instance_from_reqwrap(req_wrap);
-
-
-int32_t iotjs_adc_read(iotjs_adc_t* adc);
-bool iotjs_adc_close(iotjs_adc_t* adc);
-void iotjs_adc_open_worker(uv_work_t* work_req);
-
-
-#endif /* IOTJS_MODULE_ADC_H */
diff --git a/src/module/iotjs_module_blehcisocket.c b/src/module/iotjs_module_blehcisocket.c
deleted file mode 100644 (file)
index 1318e37..0000000
+++ /dev/null
@@ -1,251 +0,0 @@
-/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright (C) 2015 Sandeep Mistry sandeep.mistry@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module_blehcisocket.h"
-#include "iotjs_module_buffer.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-#define THIS iotjs_blehcisocket_t* blehcisocket
-
-
-static void iotjs_blehcisocket_destroy(THIS);
-
-
-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,
-                               (JFreeHandlerType)iotjs_blehcisocket_destroy);
-
-  iotjs_blehcisocket_initialize(blehcisocket);
-
-  return blehcisocket;
-}
-
-
-iotjs_blehcisocket_t* iotjs_blehcisocket_instance_from_jval(
-    const iotjs_jval_t* jble) {
-  iotjs_jobjectwrap_t* jobjectwrap = iotjs_jobjectwrap_from_jobject(jble);
-  return (iotjs_blehcisocket_t*)jobjectwrap;
-}
-
-
-static void iotjs_blehcisocket_destroy(THIS) {
-  iotjs_blehcisocket_close(blehcisocket);
-
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_blehcisocket_t, blehcisocket);
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-  IOTJS_RELEASE(blehcisocket);
-}
-
-
-JHANDLER_FUNCTION(Start) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-
-  iotjs_blehcisocket_t* blehcisocket =
-      iotjs_blehcisocket_instance_from_jval(jblehcisocket);
-
-  iotjs_blehcisocket_start(blehcisocket);
-
-  iotjs_jhandler_return_undefined(jhandler);
-}
-
-
-JHANDLER_FUNCTION(BindRaw) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK(ge(iotjs_jhandler_get_arg_length(jhandler), 1));
-
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-
-  iotjs_blehcisocket_t* blehcisocket =
-      iotjs_blehcisocket_instance_from_jval(jblehcisocket);
-
-  int devId = 0;
-  int* pDevId = NULL;
-
-  const iotjs_jval_t* raw = iotjs_jhandler_get_arg(jhandler, 0);
-  if (iotjs_jval_is_number(raw)) {
-    devId = iotjs_jval_as_number(raw);
-    pDevId = &devId;
-  }
-
-  int ret = iotjs_blehcisocket_bindRaw(blehcisocket, pDevId);
-
-  iotjs_jhandler_return_number(jhandler, ret);
-}
-
-
-JHANDLER_FUNCTION(BindUser) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, number);
-
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-
-  iotjs_blehcisocket_t* blehcisocket =
-      iotjs_blehcisocket_instance_from_jval(jblehcisocket);
-
-  int devId = JHANDLER_GET_ARG(0, number);
-  int* pDevId = &devId;
-
-  int ret = iotjs_blehcisocket_bindUser(blehcisocket, pDevId);
-
-  iotjs_jhandler_return_number(jhandler, ret);
-}
-
-
-JHANDLER_FUNCTION(BindControl) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-
-  iotjs_blehcisocket_t* blehcisocket =
-      iotjs_blehcisocket_instance_from_jval(jblehcisocket);
-
-  iotjs_blehcisocket_bindControl(blehcisocket);
-
-  iotjs_jhandler_return_undefined(jhandler);
-}
-
-
-JHANDLER_FUNCTION(IsDevUp) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-
-  iotjs_blehcisocket_t* blehcisocket =
-      iotjs_blehcisocket_instance_from_jval(jblehcisocket);
-
-  bool ret = iotjs_blehcisocket_isDevUp(blehcisocket);
-
-  iotjs_jhandler_return_boolean(jhandler, ret);
-}
-
-
-JHANDLER_FUNCTION(SetFilter) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, object);
-
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-  iotjs_blehcisocket_t* blehcisocket =
-      iotjs_blehcisocket_instance_from_jval(jblehcisocket);
-  iotjs_bufferwrap_t* buffer =
-      iotjs_bufferwrap_from_jbuffer(JHANDLER_GET_ARG(0, object));
-
-  iotjs_blehcisocket_setFilter(blehcisocket, iotjs_bufferwrap_buffer(buffer),
-                               iotjs_bufferwrap_length(buffer));
-
-  iotjs_jhandler_return_undefined(jhandler);
-}
-
-
-JHANDLER_FUNCTION(Stop) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-
-  iotjs_blehcisocket_t* blehcisocket =
-      iotjs_blehcisocket_instance_from_jval(jblehcisocket);
-
-  iotjs_blehcisocket_stop(blehcisocket);
-
-  iotjs_jhandler_return_undefined(jhandler);
-}
-
-
-JHANDLER_FUNCTION(Write) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, object);
-
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-  iotjs_blehcisocket_t* blehcisocket =
-      iotjs_blehcisocket_instance_from_jval(jblehcisocket);
-  iotjs_bufferwrap_t* buffer =
-      iotjs_bufferwrap_from_jbuffer(JHANDLER_GET_ARG(0, object));
-
-  iotjs_blehcisocket_write(blehcisocket, iotjs_bufferwrap_buffer(buffer),
-                           iotjs_bufferwrap_length(buffer));
-
-  iotjs_jhandler_return_undefined(jhandler);
-}
-
-
-JHANDLER_FUNCTION(BleHciSocketCons) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  // Create object
-  const iotjs_jval_t* jblehcisocket = JHANDLER_GET_THIS(object);
-  iotjs_blehcisocket_t* blehcisocket = iotjs_blehcisocket_create(jblehcisocket);
-  IOTJS_ASSERT(blehcisocket ==
-               (iotjs_blehcisocket_t*)(iotjs_jval_get_object_native_handle(
-                   jblehcisocket)));
-}
-
-
-iotjs_jval_t InitBlehcisocket() {
-  iotjs_jval_t jblehcisocketCons =
-      iotjs_jval_create_function_with_dispatch(BleHciSocketCons);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_START, Start);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_BINDRAW, BindRaw);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_BINDUSER, BindUser);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_BINDCONTROL,
-                        BindControl);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_ISDEVUP, IsDevUp);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SETFILTER, SetFilter);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_STOP, Stop);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITE, Write);
-
-  iotjs_jval_set_property_jval(&jblehcisocketCons, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &prototype);
-
-  iotjs_jval_destroy(&prototype);
-
-  return jblehcisocketCons;
-}
diff --git a/src/module/iotjs_module_blehcisocket.h b/src/module/iotjs_module_blehcisocket.h
deleted file mode 100644 (file)
index 93cc6ad..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright (C) 2015 Sandeep Mistry sandeep.mistry@gmail.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#ifndef IOTJS_MODULE_BLE_HCI_SOCKET_H
-#define IOTJS_MODULE_BLE_HCI_SOCKET_H
-
-#include "iotjs_def.h"
-#include "iotjs_objectwrap.h"
-#include "iotjs_reqwrap.h"
-
-typedef struct {
-  iotjs_jobjectwrap_t jobjectwrap;
-
-  int _mode;
-  int _socket;
-  int _devId;
-  uv_poll_t _pollHandle;
-  int _l2sockets[1024];
-  int _l2socketCount;
-  uint8_t _address[6];
-  uint8_t _addressType;
-} IOTJS_VALIDATED_STRUCT(iotjs_blehcisocket_t);
-
-
-#define THIS iotjs_blehcisocket_t* iotjs_blehcisocket
-
-
-iotjs_blehcisocket_t* iotjs_blehcisocket_create(const iotjs_jval_t* jble);
-iotjs_blehcisocket_t* iotjs_blehcisocket_instance_from_jval(
-    const iotjs_jval_t* jble);
-
-
-void iotjs_blehcisocket_initialize(THIS);
-void iotjs_blehcisocket_close(THIS);
-void iotjs_blehcisocket_start(THIS);
-int iotjs_blehcisocket_bindRaw(THIS, int* devId);
-int iotjs_blehcisocket_bindUser(THIS, int* devId);
-void iotjs_blehcisocket_bindControl(THIS);
-bool iotjs_blehcisocket_isDevUp(THIS);
-void iotjs_blehcisocket_setFilter(THIS, char* data, int length);
-void iotjs_blehcisocket_poll(THIS);
-void iotjs_blehcisocket_stop(THIS);
-void iotjs_blehcisocket_write(THIS, char* data, int length);
-void iotjs_blehcisocket_emitErrnoError(THIS);
-int iotjs_blehcisocket_devIdFor(THIS, int* pDevId, bool isUp);
-void iotjs_blehcisocket_kernelDisconnectWorkArounds(THIS, int length,
-                                                    char* data);
-
-#undef THIS
-
-void iotjs_blehcisocket_poll_cb(uv_poll_t* handle, int status, int events);
-
-
-#endif /* IOTJS_MODULE_BLE_HCI_SOCKET_H */
diff --git a/src/module/iotjs_module_buffer.c b/src/module/iotjs_module_buffer.c
deleted file mode 100644 (file)
index 3b838c9..0000000
+++ /dev/null
@@ -1,519 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module_buffer.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-
-static void iotjs_bufferwrap_destroy(iotjs_bufferwrap_t* bufferwrap);
-
-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,
-                               (JFreeHandlerType)iotjs_bufferwrap_destroy);
-  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;
-}
-
-
-static void iotjs_bufferwrap_destroy(iotjs_bufferwrap_t* bufferwrap) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_bufferwrap_t, bufferwrap);
-  if (_this->buffer != NULL) {
-    iotjs_buffer_release(_this->buffer);
-  }
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-  IOTJS_RELEASE(bufferwrap);
-}
-
-
-iotjs_bufferwrap_t* iotjs_bufferwrap_from_jbuiltin(
-    const iotjs_jval_t* jbuiltin) {
-  IOTJS_ASSERT(iotjs_jval_is_object(jbuiltin));
-  iotjs_bufferwrap_t* buffer =
-      (iotjs_bufferwrap_t*)iotjs_jval_get_object_native_handle(jbuiltin);
-  IOTJS_ASSERT(buffer != NULL);
-  return buffer;
-}
-
-
-iotjs_bufferwrap_t* iotjs_bufferwrap_from_jbuffer(const iotjs_jval_t* jbuffer) {
-  IOTJS_ASSERT(iotjs_jval_is_object(jbuffer));
-  iotjs_jval_t jbuiltin =
-      iotjs_jval_get_property(jbuffer, IOTJS_MAGIC_STRING__BUILTIN);
-  iotjs_bufferwrap_t* buffer = iotjs_bufferwrap_from_jbuiltin(&jbuiltin);
-  iotjs_jval_destroy(&jbuiltin);
-  return buffer;
-}
-
-
-iotjs_jval_t* iotjs_bufferwrap_jbuiltin(iotjs_bufferwrap_t* bufferwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_bufferwrap_t, bufferwrap);
-  return iotjs_jobjectwrap_jobject(&_this->jobjectwrap);
-}
-
-
-iotjs_jval_t iotjs_bufferwrap_jbuffer(iotjs_bufferwrap_t* bufferwrap) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_bufferwrap_t, bufferwrap);
-  iotjs_jval_t* jbuiltin = iotjs_bufferwrap_jbuiltin(bufferwrap);
-  return iotjs_jval_get_property(jbuiltin, IOTJS_MAGIC_STRING__BUFFER);
-}
-
-
-char* iotjs_bufferwrap_buffer(iotjs_bufferwrap_t* bufferwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_bufferwrap_t, bufferwrap);
-  return _this->buffer;
-}
-
-
-size_t iotjs_bufferwrap_length(iotjs_bufferwrap_t* bufferwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_bufferwrap_t, bufferwrap);
-#ifndef NDEBUG
-  iotjs_jval_t jbuf = iotjs_bufferwrap_jbuffer(bufferwrap);
-  iotjs_jval_t jlength =
-      iotjs_jval_get_property(&jbuf, IOTJS_MAGIC_STRING_LENGTH);
-  size_t length = iotjs_jval_as_number(&jlength);
-  IOTJS_ASSERT(length == _this->length);
-  iotjs_jval_destroy(&jbuf);
-  iotjs_jval_destroy(&jlength);
-#endif
-  return _this->length;
-}
-
-
-static size_t bound_range(int index, size_t low, size_t upper) {
-  if (index < (int)low) {
-    return low;
-  }
-  if (index > (int)upper) {
-    return upper;
-  }
-  return index;
-}
-
-
-static unsigned hex2bin(char c) {
-  if (c >= '0' && c <= '9')
-    return c - '0';
-  if (c >= 'A' && c <= 'F')
-    return 10 + (c - 'A');
-  if (c >= 'a' && c <= 'f')
-    return 10 + (c - 'a');
-
-  IOTJS_ASSERT(!"Bad argument");
-  return (unsigned)(-1);
-}
-
-
-static size_t hex_decode(char* buf, size_t len, const char* src,
-                         const size_t srcLen) {
-  size_t i;
-
-  for (i = 0; i < len && i * 2 + 1 < srcLen; ++i) {
-    unsigned a = hex2bin(src[i * 2 + 0]);
-    unsigned b = hex2bin(src[i * 2 + 1]);
-    if (!~a || !~b)
-      return i;
-    buf[i] = (a << 4) | b;
-  }
-
-  return i;
-}
-
-
-int iotjs_bufferwrap_compare(const iotjs_bufferwrap_t* bufferwrap,
-                             const iotjs_bufferwrap_t* other) {
-  const IOTJS_VALIDATED_STRUCT_METHOD(iotjs_bufferwrap_t, bufferwrap);
-
-  const char* other_buffer = other->unsafe.buffer;
-  size_t other_length = other->unsafe.length;
-
-  size_t i = 0;
-  size_t j = 0;
-  while (i < _this->length && j < other_length) {
-    if (_this->buffer[i] < other_buffer[j]) {
-      return -1;
-    } else if (_this->buffer[i] > other_buffer[j]) {
-      return 1;
-    }
-    ++i;
-    ++j;
-  }
-  if (j < other_length) {
-    return -1;
-  } else if (i < _this->length) {
-    return 1;
-  }
-  return 0;
-}
-
-size_t iotjs_bufferwrap_copy_internal(iotjs_bufferwrap_t* bufferwrap,
-                                      const char* src, size_t src_from,
-                                      size_t src_to, size_t dst_from) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_bufferwrap_t, bufferwrap);
-  size_t copied = 0;
-  size_t dst_length = _this->length;
-  for (size_t i = src_from, j = dst_from; i < src_to && j < dst_length;
-       ++i, ++j) {
-    *(_this->buffer + j) = *(src + i);
-    ++copied;
-  }
-  return copied;
-}
-
-
-size_t iotjs_bufferwrap_copy(iotjs_bufferwrap_t* bufferwrap, const char* src,
-                             size_t len) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_bufferwrap_t, bufferwrap);
-  return iotjs_bufferwrap_copy_internal(bufferwrap, src, 0, len, 0);
-}
-
-
-iotjs_jval_t iotjs_bufferwrap_create_buffer(size_t len) {
-  iotjs_jval_t* jglobal = iotjs_jval_get_global_object();
-
-  iotjs_jval_t jbuffer =
-      iotjs_jval_get_property(jglobal, IOTJS_MAGIC_STRING_BUFFER);
-  IOTJS_ASSERT(iotjs_jval_is_function(&jbuffer));
-
-  iotjs_jargs_t jargs = iotjs_jargs_create(1);
-  iotjs_jargs_append_number(&jargs, len);
-
-  iotjs_jval_t jres =
-      iotjs_jhelper_call_ok(&jbuffer, iotjs_jval_get_undefined(), &jargs);
-  IOTJS_ASSERT(iotjs_jval_is_object(&jres));
-
-  iotjs_jargs_destroy(&jargs);
-  iotjs_jval_destroy(&jbuffer);
-
-  return jres;
-}
-
-
-JHANDLER_FUNCTION(Buffer) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, object, number);
-
-  const iotjs_jval_t* jbuiltin = JHANDLER_GET_THIS(object);
-  const iotjs_jval_t* jbuffer = JHANDLER_GET_ARG(0, object);
-  int length = JHANDLER_GET_ARG(1, number);
-
-  iotjs_jval_set_property_jval(jbuiltin, IOTJS_MAGIC_STRING__BUFFER, jbuffer);
-
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_create(jbuiltin, length);
-  IOTJS_UNUSED(buffer_wrap);
-}
-
-
-JHANDLER_FUNCTION(Compare) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, object);
-
-  const iotjs_jval_t* jsrc_builtin = JHANDLER_GET_THIS(object);
-  iotjs_bufferwrap_t* src_buffer_wrap =
-      iotjs_bufferwrap_from_jbuiltin(jsrc_builtin);
-
-  const iotjs_jval_t* jdst_buffer = JHANDLER_GET_ARG(0, object);
-  iotjs_bufferwrap_t* dst_buffer_wrap =
-      iotjs_bufferwrap_from_jbuffer(jdst_buffer);
-
-  int compare = iotjs_bufferwrap_compare(src_buffer_wrap, dst_buffer_wrap);
-  iotjs_jhandler_return_number(jhandler, compare);
-}
-
-
-JHANDLER_FUNCTION(Copy) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(4, object, number, number, number);
-
-  const iotjs_jval_t* jsrc_builtin = JHANDLER_GET_THIS(object);
-  iotjs_bufferwrap_t* src_buffer_wrap =
-      iotjs_bufferwrap_from_jbuiltin(jsrc_builtin);
-
-  const iotjs_jval_t* jdst_buffer = JHANDLER_GET_ARG(0, object);
-  iotjs_bufferwrap_t* dst_buffer_wrap =
-      iotjs_bufferwrap_from_jbuffer(jdst_buffer);
-
-  int dst_start = JHANDLER_GET_ARG(1, number);
-  int src_start = JHANDLER_GET_ARG(2, number);
-  int src_end = JHANDLER_GET_ARG(3, number);
-
-  size_t dst_length = iotjs_bufferwrap_length(dst_buffer_wrap);
-  size_t src_length = iotjs_bufferwrap_length(src_buffer_wrap);
-
-  dst_start = bound_range(dst_start, 0, dst_length);
-  src_start = bound_range(src_start, 0, src_length);
-  src_end = bound_range(src_end, 0, src_length);
-
-  if (src_end < src_start) {
-    src_end = src_start;
-  }
-
-  const char* src_data = iotjs_bufferwrap_buffer(src_buffer_wrap);
-  size_t copied = iotjs_bufferwrap_copy_internal(dst_buffer_wrap, src_data,
-                                                 src_start, src_end, dst_start);
-
-  iotjs_jhandler_return_number(jhandler, copied);
-}
-
-
-JHANDLER_FUNCTION(Write) {
-  JHANDLER_CHECK_ARGS(3, string, number, number);
-
-  iotjs_string_t src = JHANDLER_GET_ARG(0, string);
-  int offset = JHANDLER_GET_ARG(1, number);
-  int length = JHANDLER_GET_ARG(2, number);
-
-  const iotjs_jval_t* jbuiltin = JHANDLER_GET_THIS(object);
-
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuiltin(jbuiltin);
-
-  size_t buffer_length = iotjs_bufferwrap_length(buffer_wrap);
-  offset = bound_range(offset, 0, buffer_length);
-  length = bound_range(length, 0, buffer_length - offset);
-  length = bound_range(length, 0, iotjs_string_size(&src));
-
-  const char* src_data = iotjs_string_data(&src);
-  size_t copied =
-      iotjs_bufferwrap_copy_internal(buffer_wrap, src_data, 0, length, offset);
-
-  iotjs_jhandler_return_number(jhandler, copied);
-
-  iotjs_string_destroy(&src);
-}
-
-
-JHANDLER_FUNCTION(WriteUInt8) {
-  JHANDLER_CHECK_ARGS(2, number, number);
-
-  uint8_t src = (uint8_t)JHANDLER_GET_ARG(0, number);
-  int offset = JHANDLER_GET_ARG(1, number);
-  int length = 1;
-
-  const iotjs_jval_t* jbuiltin = JHANDLER_GET_THIS(object);
-
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuiltin(jbuiltin);
-
-  size_t buffer_length = iotjs_bufferwrap_length(buffer_wrap);
-  offset = bound_range(offset, 0, buffer_length);
-  length = bound_range(length, 0, buffer_length - offset);
-  length = bound_range(length, 0, 1);
-
-  size_t copied = iotjs_bufferwrap_copy_internal(buffer_wrap, (const char*)&src,
-                                                 0, length, offset);
-
-  iotjs_jhandler_return_number(jhandler, copied);
-}
-
-
-JHANDLER_FUNCTION(HexWrite) {
-  JHANDLER_CHECK_ARGS(3, string, number, number);
-
-  iotjs_string_t src = JHANDLER_GET_ARG(0, string);
-  int offset = JHANDLER_GET_ARG(1, number);
-  int length = JHANDLER_GET_ARG(2, number);
-
-  const iotjs_jval_t* jbuiltin = JHANDLER_GET_THIS(object);
-
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuiltin(jbuiltin);
-
-  size_t buffer_length = iotjs_bufferwrap_length(buffer_wrap);
-  offset = bound_range(offset, 0, buffer_length);
-  length = bound_range(length, 0, buffer_length - offset);
-
-  const char* src_data = iotjs_string_data(&src);
-  unsigned src_length = iotjs_string_size(&src);
-  char* src_buf = iotjs_buffer_allocate(length);
-
-  size_t nbytes = hex_decode(src_buf, length, src_data, src_length);
-
-  size_t copied =
-      iotjs_bufferwrap_copy_internal(buffer_wrap, src_buf, 0, nbytes, offset);
-
-  iotjs_jhandler_return_number(jhandler, copied);
-
-  iotjs_buffer_release(src_buf);
-  iotjs_string_destroy(&src);
-}
-
-
-JHANDLER_FUNCTION(ReadUInt8) {
-  JHANDLER_CHECK_ARGS(1, number);
-
-  int offset = JHANDLER_GET_ARG(0, number);
-
-  const iotjs_jval_t* jbuiltin = JHANDLER_GET_THIS(object);
-
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuiltin(jbuiltin);
-
-  size_t buffer_length = iotjs_bufferwrap_length(buffer_wrap);
-  offset = bound_range(offset, 0, buffer_length - 1);
-
-  char* buffer = iotjs_bufferwrap_buffer(buffer_wrap);
-
-  iotjs_jhandler_return_number(jhandler, (uint8_t)buffer[offset]);
-}
-
-
-JHANDLER_FUNCTION(Slice) {
-  JHANDLER_CHECK_ARGS(2, number, number);
-
-  const iotjs_jval_t* jbuiltin = JHANDLER_GET_THIS(object);
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuiltin(jbuiltin);
-
-  int start = JHANDLER_GET_ARG(0, number);
-  int end = JHANDLER_GET_ARG(1, number);
-
-  if (start < 0) {
-    start += iotjs_bufferwrap_length(buffer_wrap);
-  }
-  start = bound_range(start, 0, iotjs_bufferwrap_length(buffer_wrap));
-
-  if (end < 0) {
-    end += iotjs_bufferwrap_length(buffer_wrap);
-  }
-  end = bound_range(end, 0, iotjs_bufferwrap_length(buffer_wrap));
-
-  if (end < start) {
-    end = start;
-  }
-
-  int length = end - start;
-  IOTJS_ASSERT(length >= 0);
-
-  iotjs_jval_t jnew_buffer = iotjs_bufferwrap_create_buffer(length);
-  iotjs_bufferwrap_t* new_buffer_wrap =
-      iotjs_bufferwrap_from_jbuffer(&jnew_buffer);
-  iotjs_bufferwrap_copy_internal(new_buffer_wrap,
-                                 iotjs_bufferwrap_buffer(buffer_wrap), start,
-                                 end, 0);
-
-  iotjs_jhandler_return_jval(jhandler, &jnew_buffer);
-  iotjs_jval_destroy(&jnew_buffer);
-}
-
-
-JHANDLER_FUNCTION(ToString) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, number, number);
-
-  const iotjs_jval_t* jbuiltin = JHANDLER_GET_THIS(object);
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuiltin(jbuiltin);
-
-  int start = JHANDLER_GET_ARG(0, number);
-  int end = JHANDLER_GET_ARG(1, number);
-
-  start = bound_range(start, 0, iotjs_bufferwrap_length(buffer_wrap));
-  end = bound_range(end, 0, iotjs_bufferwrap_length(buffer_wrap));
-
-  if (end < start) {
-    end = start;
-  }
-
-  int length = end - start;
-  IOTJS_ASSERT(length >= 0);
-
-  const char* data = iotjs_bufferwrap_buffer(buffer_wrap) + start;
-  length = strnlen(data, length);
-  iotjs_string_t str = iotjs_string_create_with_size(data, length);
-
-  iotjs_jhandler_return_string(jhandler, &str);
-
-  iotjs_string_destroy(&str);
-}
-
-
-JHANDLER_FUNCTION(ToHexString) {
-  JHANDLER_CHECK_THIS(object);
-
-  const iotjs_jval_t* jbuiltin = JHANDLER_GET_THIS(object);
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuiltin(jbuiltin);
-
-  int length = iotjs_bufferwrap_length(buffer_wrap);
-  const char* data = iotjs_bufferwrap_buffer(buffer_wrap);
-
-  char* buffer = iotjs_buffer_allocate(length * 2);
-  iotjs_string_t str = iotjs_string_create_with_buffer(buffer, length * 2);
-
-  for (int i = 0; i < length; i++) {
-    memcpy(buffer, &"0123456789abcdef"[data[i] >> 4 & 0xF], 1);
-    buffer++;
-    memcpy(buffer, &"0123456789abcdef"[data[i] >> 0 & 0xF], 1);
-    buffer++;
-  }
-
-  iotjs_jhandler_return_string(jhandler, &str);
-  iotjs_string_destroy(&str);
-}
-
-
-JHANDLER_FUNCTION(ByteLength) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, string);
-
-  iotjs_string_t str = JHANDLER_GET_ARG(0, string);
-  iotjs_jval_t size = iotjs_jval_get_string_size(&str);
-
-  iotjs_jhandler_return_jval(jhandler, &size);
-  iotjs_string_destroy(&str);
-  iotjs_jval_destroy(&size);
-}
-
-
-iotjs_jval_t InitBuffer() {
-  iotjs_jval_t buffer = iotjs_jval_create_function_with_dispatch(Buffer);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-  iotjs_jval_t byte_length =
-      iotjs_jval_create_function_with_dispatch(ByteLength);
-
-  iotjs_jval_set_property_jval(&buffer, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &prototype);
-  iotjs_jval_set_property_jval(&buffer, IOTJS_MAGIC_STRING_BYTELENGTH,
-                               &byte_length);
-
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_COMPARE, Compare);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_COPY, Copy);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITE, Write);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_HEXWRITE, HexWrite);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITEUINT8, WriteUInt8);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_READUINT8, ReadUInt8);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SLICE, Slice);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_TOSTRING, ToString);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_TOHEXSTRING,
-                        ToHexString);
-
-  iotjs_jval_destroy(&prototype);
-  iotjs_jval_destroy(&byte_length);
-
-  return buffer;
-}
diff --git a/src/module/iotjs_module_buffer.h b/src/module/iotjs_module_buffer.h
deleted file mode 100644 (file)
index 2f1e53f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IOTJS_MODULE_BUFFER_H
-#define IOTJS_MODULE_BUFFER_H
-
-
-#include "iotjs_objectwrap.h"
-
-
-typedef struct {
-  iotjs_jobjectwrap_t jobjectwrap;
-  char* buffer;
-  size_t length;
-} IOTJS_VALIDATED_STRUCT(iotjs_bufferwrap_t);
-
-
-iotjs_bufferwrap_t* iotjs_bufferwrap_create(const iotjs_jval_t* jbuiltin,
-                                            size_t length);
-
-iotjs_bufferwrap_t* iotjs_bufferwrap_from_jbuiltin(
-    const iotjs_jval_t* jbuiltin);
-iotjs_bufferwrap_t* iotjs_bufferwrap_from_jbuffer(const iotjs_jval_t* jbuffer);
-
-iotjs_jval_t* iotjs_bufferwrap_jbuiltin(iotjs_bufferwrap_t* bufferwrap);
-iotjs_jval_t iotjs_bufferwrap_jbuffer(iotjs_bufferwrap_t* bufferwrap);
-
-char* iotjs_bufferwrap_buffer(iotjs_bufferwrap_t* bufferwrap);
-size_t iotjs_bufferwrap_length(iotjs_bufferwrap_t* bufferwrap);
-
-int iotjs_bufferwrap_compare(const iotjs_bufferwrap_t* bufferwrap,
-                             const iotjs_bufferwrap_t* other);
-
-size_t iotjs_bufferwrap_copy(iotjs_bufferwrap_t* bufferwrap, const char* src,
-                             size_t len);
-
-// Create buffer object.
-iotjs_jval_t iotjs_bufferwrap_create_buffer(size_t len);
-
-
-#endif /* IOTJS_MODULE_BUFFER_H */
diff --git a/src/module/iotjs_module_console.c b/src/module/iotjs_module_console.c
deleted file mode 100644 (file)
index c827636..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-
-
-static void Print(iotjs_jhandler_t* jhandler, FILE* out_fd) {
-  JHANDLER_CHECK_ARGS(1, string);
-
-  iotjs_string_t msg = JHANDLER_GET_ARG(0, string);
-  fprintf(out_fd, "%s", iotjs_string_data(&msg));
-  iotjs_string_destroy(&msg);
-}
-
-
-JHANDLER_FUNCTION(Stdout) {
-  Print(jhandler, stdout);
-}
-
-
-JHANDLER_FUNCTION(Stderr) {
-  Print(jhandler, stderr);
-}
-
-
-iotjs_jval_t InitConsole() {
-  iotjs_jval_t console = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&console, IOTJS_MAGIC_STRING_STDOUT, Stdout);
-  iotjs_jval_set_method(&console, IOTJS_MAGIC_STRING_STDERR, Stderr);
-
-  return console;
-}
diff --git a/src/module/iotjs_module_constants.c b/src/module/iotjs_module_constants.c
deleted file mode 100644 (file)
index a02e675..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module.h"
-
-
-#define SET_CONSTANT(object, constant)                           \
-  do {                                                           \
-    iotjs_jval_set_property_number(object, #constant, constant); \
-  } while (0)
-
-iotjs_jval_t InitConstants() {
-  iotjs_jval_t constants = iotjs_jval_create_object();
-
-  SET_CONSTANT(&constants, O_APPEND);
-  SET_CONSTANT(&constants, O_CREAT);
-  SET_CONSTANT(&constants, O_EXCL);
-  SET_CONSTANT(&constants, O_RDONLY);
-  SET_CONSTANT(&constants, O_RDWR);
-  SET_CONSTANT(&constants, O_SYNC);
-  SET_CONSTANT(&constants, O_TRUNC);
-  SET_CONSTANT(&constants, O_WRONLY);
-  SET_CONSTANT(&constants, S_IFMT);
-  SET_CONSTANT(&constants, S_IFDIR);
-  SET_CONSTANT(&constants, S_IFREG);
-
-  return constants;
-}
diff --git a/src/module/iotjs_module_dns.c b/src/module/iotjs_module_dns.c
deleted file mode 100644 (file)
index 82c2f51..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-
-#include "iotjs_module_dns.h"
-
-#include "iotjs_reqwrap.h"
-#include "uv.h"
-
-
-#define THIS iotjs_getaddrinfo_reqwrap_t* getaddrinfo_reqwrap
-
-iotjs_getaddrinfo_reqwrap_t* iotjs_getaddrinfo_reqwrap_create(
-    const iotjs_jval_t* jcallback) {
-  iotjs_getaddrinfo_reqwrap_t* getaddrinfo_reqwrap =
-      IOTJS_ALLOC(iotjs_getaddrinfo_reqwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_getaddrinfo_reqwrap_t,
-                                     getaddrinfo_reqwrap);
-  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
-  return getaddrinfo_reqwrap;
-}
-
-
-static void iotjs_getaddrinfo_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_getaddrinfo_reqwrap_t,
-                                    getaddrinfo_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(getaddrinfo_reqwrap);
-}
-
-
-void iotjs_getaddrinfo_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_getaddrinfo_reqwrap_t,
-                                           getaddrinfo_reqwrap);
-  iotjs_getaddrinfo_reqwrap_destroy(getaddrinfo_reqwrap);
-}
-
-
-uv_getaddrinfo_t* iotjs_getaddrinfo_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_getaddrinfo_reqwrap_t,
-                                getaddrinfo_reqwrap);
-  return &_this->req;
-}
-
-
-const iotjs_jval_t* iotjs_getaddrinfo_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_getaddrinfo_reqwrap_t,
-                                getaddrinfo_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-#undef THIS
-
-
-#if !defined(__NUTTX__) && !defined(__TIZENRT__)
-static void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status,
-                             struct addrinfo* res) {
-  iotjs_getaddrinfo_reqwrap_t* req_wrap =
-      (iotjs_getaddrinfo_reqwrap_t*)(req->data);
-
-  iotjs_jargs_t args = iotjs_jargs_create(3);
-  iotjs_jargs_append_number(&args, status);
-
-  if (status == 0) {
-    char ip[INET6_ADDRSTRLEN];
-    int family;
-    const char* addr;
-
-    // Only first address is used
-    if (res->ai_family == AF_INET) {
-      struct sockaddr_in* sockaddr = (struct sockaddr_in*)(res->ai_addr);
-      addr = (char*)(&(sockaddr->sin_addr));
-      family = 4;
-    } else {
-      struct sockaddr_in6* sockaddr = (struct sockaddr_in6*)(res->ai_addr);
-      addr = (char*)(&(sockaddr->sin6_addr));
-      family = 6;
-    }
-
-    int err = uv_inet_ntop(res->ai_family, addr, ip, INET6_ADDRSTRLEN);
-    if (err) {
-      ip[0] = 0;
-    }
-
-    iotjs_jargs_append_string_raw(&args, ip);
-    iotjs_jargs_append_number(&args, family);
-  }
-
-  uv_freeaddrinfo(res);
-
-  // Make the callback into JavaScript
-  iotjs_make_callback(iotjs_getaddrinfo_reqwrap_jcallback(req_wrap),
-                      iotjs_jval_get_undefined(), &args);
-
-  iotjs_jargs_destroy(&args);
-
-  iotjs_getaddrinfo_reqwrap_dispatched(req_wrap);
-}
-#endif
-
-
-JHANDLER_FUNCTION(GetAddrInfo) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(4, string, number, number, function);
-
-  iotjs_string_t hostname = JHANDLER_GET_ARG(0, string);
-  int option = JHANDLER_GET_ARG(1, number);
-  int flags = JHANDLER_GET_ARG(2, number);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(3, function);
-
-  int family;
-  if (option == 0) {
-    family = AF_UNSPEC;
-  } else if (option == 4) {
-    family = AF_INET;
-  } else if (option == 6) {
-    family = AF_INET6;
-  } else {
-    JHANDLER_THROW(TYPE, "bad address family");
-    return;
-  }
-
-#if defined(__NUTTX__) || defined(__TIZENRT__)
-  iotjs_jargs_t args = iotjs_jargs_create(3);
-  int err = 0;
-  char ip[INET6_ADDRSTRLEN];
-  const char* hostname_data = iotjs_string_data(&hostname);
-
-  if (strcmp(hostname_data, "localhost") == 0) {
-    strcpy(ip, "127.0.0.1");
-  } else {
-    struct sockaddr_in addr;
-    int result = inet_pton(AF_INET, hostname_data, &(addr.sin_addr));
-
-    if (result != 1) {
-      err = errno;
-    } else {
-      inet_ntop(AF_INET, &(addr.sin_addr), ip, INET6_ADDRSTRLEN);
-    }
-  }
-
-  iotjs_jargs_append_number(&args, err);
-  iotjs_jargs_append_string_raw(&args, ip);
-  iotjs_jargs_append_number(&args, family);
-
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &args);
-  iotjs_jargs_destroy(&args);
-  IOTJS_UNUSED(flags);
-#else
-  iotjs_getaddrinfo_reqwrap_t* req_wrap =
-      iotjs_getaddrinfo_reqwrap_create(jcallback);
-
-  static const struct addrinfo empty_hints;
-  struct addrinfo hints = empty_hints;
-  hints.ai_family = family;
-  hints.ai_socktype = SOCK_STREAM;
-  hints.ai_flags = flags;
-
-  int err =
-      uv_getaddrinfo(iotjs_environment_loop(iotjs_environment_get()),
-                     iotjs_getaddrinfo_reqwrap_req(req_wrap), AfterGetAddrInfo,
-                     iotjs_string_data(&hostname), NULL, &hints);
-
-  if (err) {
-    iotjs_getaddrinfo_reqwrap_dispatched(req_wrap);
-  }
-#endif
-
-  iotjs_jhandler_return_number(jhandler, err);
-
-  iotjs_string_destroy(&hostname);
-}
-
-
-#define SET_CONSTANT(object, constant)                           \
-  do {                                                           \
-    iotjs_jval_set_property_number(object, #constant, constant); \
-  } while (0)
-
-
-iotjs_jval_t InitDns() {
-  iotjs_jval_t dns = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&dns, IOTJS_MAGIC_STRING_GETADDRINFO, GetAddrInfo);
-  SET_CONSTANT(&dns, AI_ADDRCONFIG);
-  SET_CONSTANT(&dns, AI_V4MAPPED);
-
-  return dns;
-}
diff --git a/src/module/iotjs_module_dns.h b/src/module/iotjs_module_dns.h
deleted file mode 100644 (file)
index 51cc508..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_DNS_H
-#define IOTJS_MODULE_DNS_H
-
-
-#include "iotjs_def.h"
-#include "iotjs_reqwrap.h"
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_getaddrinfo_t req;
-} IOTJS_VALIDATED_STRUCT(iotjs_getaddrinfo_reqwrap_t);
-
-#define THIS iotjs_getaddrinfo_reqwrap_t* getaddrinfo_reqwrap
-
-iotjs_getaddrinfo_reqwrap_t* iotjs_getaddrinfo_reqwrap_create(
-    const iotjs_jval_t* jcallback);
-
-void iotjs_getaddrinfo_reqwrap_dispatched(THIS);
-
-uv_getaddrinfo_t* iotjs_getaddrinfo_reqwrap_req(THIS);
-const iotjs_jval_t* iotjs_getaddrinfo_reqwrap_jcallback(THIS);
-
-#undef THIS
-
-
-#endif /* IOTJS_MODULE_DNS_H */
diff --git a/src/module/iotjs_module_fs.c b/src/module/iotjs_module_fs.c
deleted file mode 100644 (file)
index 82b1933..0000000
+++ /dev/null
@@ -1,502 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-
-#include "iotjs_module_fs.h"
-
-#include "iotjs_module_buffer.h"
-
-#include "iotjs_exception.h"
-#include "iotjs_reqwrap.h"
-
-#undef JHANDLER_FUNCTION
-#define JHANDLER_FUNCTION(name) static void name(iotjs_jhandler_t* jhandler)
-
-iotjs_fs_reqwrap_t* iotjs_fs_reqwrap_create(const iotjs_jval_t* jcallback) {
-  iotjs_fs_reqwrap_t* fs_reqwrap = IOTJS_ALLOC(iotjs_fs_reqwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_fs_reqwrap_t, fs_reqwrap);
-  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
-  return fs_reqwrap;
-}
-
-
-static void iotjs_fs_reqwrap_destroy(iotjs_fs_reqwrap_t* fs_reqwrap) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_fs_reqwrap_t, fs_reqwrap);
-  uv_fs_req_cleanup(&_this->req);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(fs_reqwrap);
-}
-
-
-void iotjs_fs_reqwrap_dispatched(iotjs_fs_reqwrap_t* fs_reqwrap) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_fs_reqwrap_t, fs_reqwrap);
-  iotjs_fs_reqwrap_destroy(fs_reqwrap);
-}
-
-
-uv_fs_t* iotjs_fs_reqwrap_req(iotjs_fs_reqwrap_t* fs_reqwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_fs_reqwrap_t, fs_reqwrap);
-  return &_this->req;
-}
-
-const iotjs_jval_t* iotjs_fs_reqwrap_jcallback(iotjs_fs_reqwrap_t* fs_reqwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_fs_reqwrap_t, fs_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-
-iotjs_jval_t MakeStatObject(uv_stat_t* statbuf);
-
-
-static void AfterAsync(uv_fs_t* req) {
-  iotjs_fs_reqwrap_t* req_wrap = (iotjs_fs_reqwrap_t*)(req->data);
-  IOTJS_ASSERT(req_wrap != NULL);
-  IOTJS_ASSERT(iotjs_fs_reqwrap_req(req_wrap) == req);
-
-  const iotjs_jval_t* cb = iotjs_fs_reqwrap_jcallback(req_wrap);
-  IOTJS_ASSERT(iotjs_jval_is_function(cb));
-
-  iotjs_jargs_t jarg = iotjs_jargs_create(2);
-  if (req->result < 0) {
-    iotjs_jval_t jerror = iotjs_create_uv_exception(req->result, "open");
-    iotjs_jargs_append_jval(&jarg, &jerror);
-    iotjs_jval_destroy(&jerror);
-  } else {
-    iotjs_jargs_append_null(&jarg);
-    switch (req->fs_type) {
-      case UV_FS_CLOSE: {
-        break;
-      }
-      case UV_FS_OPEN:
-      case UV_FS_READ:
-      case UV_FS_WRITE: {
-        iotjs_jargs_append_number(&jarg, req->result);
-        break;
-      }
-      case UV_FS_SCANDIR: {
-        int r;
-        uv_dirent_t ent;
-        uint32_t idx = 0;
-        iotjs_jval_t ret = iotjs_jval_create_array(0);
-        while ((r = uv_fs_scandir_next(req, &ent)) != UV_EOF) {
-          iotjs_jval_t name = iotjs_jval_create_string_raw(ent.name);
-          iotjs_jval_set_property_by_index(&ret, idx, &name);
-          iotjs_jval_destroy(&name);
-          idx++;
-        }
-        iotjs_jargs_append_jval(&jarg, &ret);
-        iotjs_jval_destroy(&ret);
-        break;
-      }
-      case UV_FS_STAT: {
-        uv_stat_t s = (req->statbuf);
-        iotjs_jval_t ret = MakeStatObject(&s);
-        iotjs_jargs_append_jval(&jarg, &ret);
-        iotjs_jval_destroy(&ret);
-        break;
-      }
-      default: {
-        iotjs_jargs_append_null(&jarg);
-        break;
-      }
-    }
-  }
-
-  iotjs_make_callback(cb, iotjs_jval_get_undefined(), &jarg);
-
-  iotjs_jargs_destroy(&jarg);
-  iotjs_fs_reqwrap_dispatched(req_wrap);
-}
-
-
-static void AfterSync(uv_fs_t* req, int err, const char* syscall_name,
-                      iotjs_jhandler_t* jhandler) {
-  if (err < 0) {
-    iotjs_jval_t jerror = iotjs_create_uv_exception(err, syscall_name);
-    iotjs_jhandler_throw(jhandler, &jerror);
-    iotjs_jval_destroy(&jerror);
-  } else {
-    switch (req->fs_type) {
-      case UV_FS_CLOSE:
-        break;
-      case UV_FS_OPEN:
-      case UV_FS_READ:
-      case UV_FS_WRITE:
-        iotjs_jhandler_return_number(jhandler, err);
-        break;
-      case UV_FS_STAT: {
-        uv_stat_t* s = &(req->statbuf);
-        iotjs_jval_t stat = MakeStatObject(s);
-        iotjs_jhandler_return_jval(jhandler, &stat);
-        iotjs_jval_destroy(&stat);
-        break;
-      }
-      case UV_FS_MKDIR:
-      case UV_FS_RMDIR:
-      case UV_FS_UNLINK:
-      case UV_FS_RENAME:
-        iotjs_jhandler_return_undefined(jhandler);
-        break;
-      case UV_FS_SCANDIR: {
-        int r;
-        uv_dirent_t ent;
-        uint32_t idx = 0;
-        iotjs_jval_t ret = iotjs_jval_create_array(0);
-        while ((r = uv_fs_scandir_next(req, &ent)) != UV_EOF) {
-          iotjs_jval_t name = iotjs_jval_create_string_raw(ent.name);
-          iotjs_jval_set_property_by_index(&ret, idx, &name);
-          iotjs_jval_destroy(&name);
-          idx++;
-        }
-        iotjs_jhandler_return_jval(jhandler, &ret);
-        iotjs_jval_destroy(&ret);
-        break;
-      }
-      default: {
-        IOTJS_ASSERT(false);
-        break;
-      }
-    }
-  }
-}
-
-
-static inline bool IsWithinBounds(size_t off, size_t len, size_t max) {
-  if (off > max)
-    return false;
-
-  if (max - off < len)
-    return false;
-
-  return true;
-}
-
-#define FS_ASYNC(env, syscall, pcallback, ...)                                \
-  iotjs_fs_reqwrap_t* req_wrap = iotjs_fs_reqwrap_create(pcallback);          \
-  uv_fs_t* fs_req = iotjs_fs_reqwrap_req(req_wrap);                           \
-  int err = uv_fs_##syscall(iotjs_environment_loop(env), fs_req, __VA_ARGS__, \
-                            AfterAsync);                                      \
-  if (err < 0) {                                                              \
-    fs_req->result = err;                                                     \
-    AfterAsync(fs_req);                                                       \
-  }                                                                           \
-  iotjs_jhandler_return_null(jhandler);
-
-
-#define FS_SYNC(env, syscall, ...)                                             \
-  uv_fs_t fs_req;                                                              \
-  int err = uv_fs_##syscall(iotjs_environment_loop(env), &fs_req, __VA_ARGS__, \
-                            NULL);                                             \
-  AfterSync(&fs_req, err, #syscall, jhandler);                                 \
-  uv_fs_req_cleanup(&fs_req);
-
-
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, number);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  int fd = JHANDLER_GET_ARG(0, number);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-
-  if (jcallback) {
-    FS_ASYNC(env, close, jcallback, fd);
-  } else {
-    FS_SYNC(env, close, fd);
-  }
-}
-
-
-JHANDLER_FUNCTION(Open) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(3, string, number, number);
-  JHANDLER_CHECK_ARG_IF_EXIST(3, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  iotjs_string_t path = JHANDLER_GET_ARG(0, string);
-  int flags = JHANDLER_GET_ARG(1, number);
-  int mode = JHANDLER_GET_ARG(2, number);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(3, function);
-
-  if (jcallback) {
-    FS_ASYNC(env, open, jcallback, iotjs_string_data(&path), flags, mode);
-  } else {
-    FS_SYNC(env, open, iotjs_string_data(&path), flags, mode);
-  }
-
-  iotjs_string_destroy(&path);
-}
-
-
-JHANDLER_FUNCTION(Read) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(5, number, object, number, number, number);
-  JHANDLER_CHECK_ARG_IF_EXIST(5, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  int fd = JHANDLER_GET_ARG(0, number);
-  const iotjs_jval_t* jbuffer = JHANDLER_GET_ARG(1, object);
-  size_t offset = JHANDLER_GET_ARG(2, number);
-  size_t length = JHANDLER_GET_ARG(3, number);
-  int position = JHANDLER_GET_ARG(4, number);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(5, function);
-
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(jbuffer);
-  char* data = iotjs_bufferwrap_buffer(buffer_wrap);
-  size_t data_length = iotjs_bufferwrap_length(buffer_wrap);
-  JHANDLER_CHECK(data != NULL);
-  JHANDLER_CHECK(data_length > 0);
-
-  if (offset >= data_length) {
-    JHANDLER_THROW(RANGE, "offset out of bound");
-    return;
-  }
-  if (!IsWithinBounds(offset, length, data_length)) {
-    JHANDLER_THROW(RANGE, "length out of bound");
-    return;
-  }
-
-  uv_buf_t uvbuf = uv_buf_init(data + offset, length);
-
-  if (jcallback) {
-    FS_ASYNC(env, read, jcallback, fd, &uvbuf, 1, position);
-  } else {
-    FS_SYNC(env, read, fd, &uvbuf, 1, position);
-  }
-}
-
-
-JHANDLER_FUNCTION(Write) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(5, number, object, number, number, number);
-  JHANDLER_CHECK_ARG_IF_EXIST(5, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  int fd = JHANDLER_GET_ARG(0, number);
-  const iotjs_jval_t* jbuffer = JHANDLER_GET_ARG(1, object);
-  size_t offset = JHANDLER_GET_ARG(2, number);
-  size_t length = JHANDLER_GET_ARG(3, number);
-  int position = JHANDLER_GET_ARG(4, number);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(5, function);
-
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(jbuffer);
-  char* data = iotjs_bufferwrap_buffer(buffer_wrap);
-  size_t data_length = iotjs_bufferwrap_length(buffer_wrap);
-  JHANDLER_CHECK(data != NULL);
-  JHANDLER_CHECK(data_length > 0);
-
-  if (offset >= data_length) {
-    JHANDLER_THROW(RANGE, "offset out of bound");
-    return;
-  }
-  if (!IsWithinBounds(offset, length, data_length)) {
-    JHANDLER_THROW(RANGE, "length out of bound");
-    return;
-  }
-
-  uv_buf_t uvbuf = uv_buf_init(data + offset, length);
-
-  if (jcallback) {
-    FS_ASYNC(env, write, jcallback, fd, &uvbuf, 1, position);
-  } else {
-    FS_SYNC(env, write, fd, &uvbuf, 1, position);
-  }
-}
-
-
-iotjs_jval_t MakeStatObject(uv_stat_t* statbuf) {
-  const iotjs_jval_t* fs = iotjs_module_get(MODULE_FS);
-
-  iotjs_jval_t create_stat =
-      iotjs_jval_get_property(fs, IOTJS_MAGIC_STRING__CREATESTAT);
-  IOTJS_ASSERT(iotjs_jval_is_function(&create_stat));
-
-  iotjs_jval_t jstat = iotjs_jval_create_object();
-
-#define X(statobj, name) \
-  iotjs_jval_set_property_number(statobj, #name, statbuf->st_##name);
-
-  X(&jstat, dev)
-  X(&jstat, mode)
-  X(&jstat, nlink)
-  X(&jstat, uid)
-  X(&jstat, gid)
-  X(&jstat, rdev)
-  X(&jstat, blksize)
-  X(&jstat, ino)
-  X(&jstat, size)
-  X(&jstat, blocks)
-
-#undef X
-
-  iotjs_jargs_t jargs = iotjs_jargs_create(1);
-  iotjs_jargs_append_jval(&jargs, &jstat);
-  iotjs_jval_destroy(&jstat);
-
-  iotjs_jval_t res =
-      iotjs_jhelper_call_ok(&create_stat, iotjs_jval_get_undefined(), &jargs);
-
-  iotjs_jargs_destroy(&jargs);
-  iotjs_jval_destroy(&create_stat);
-
-  return res;
-}
-
-
-JHANDLER_FUNCTION(Stat) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, string);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  iotjs_string_t path = JHANDLER_GET_ARG(0, string);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-
-  if (jcallback) {
-    FS_ASYNC(env, stat, jcallback, iotjs_string_data(&path));
-  } else {
-    FS_SYNC(env, stat, iotjs_string_data(&path));
-  }
-
-  iotjs_string_destroy(&path);
-}
-
-
-JHANDLER_FUNCTION(MkDir) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, string, number);
-  JHANDLER_CHECK_ARG_IF_EXIST(2, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  iotjs_string_t path = JHANDLER_GET_ARG(0, string);
-  int mode = JHANDLER_GET_ARG(1, number);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(2, function);
-
-  if (jcallback) {
-    FS_ASYNC(env, mkdir, jcallback, iotjs_string_data(&path), mode);
-  } else {
-    FS_SYNC(env, mkdir, iotjs_string_data(&path), mode);
-  }
-
-  iotjs_string_destroy(&path);
-}
-
-
-JHANDLER_FUNCTION(RmDir) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, string);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  iotjs_string_t path = JHANDLER_GET_ARG(0, string);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-
-  if (jcallback) {
-    FS_ASYNC(env, rmdir, jcallback, iotjs_string_data(&path));
-  } else {
-    FS_SYNC(env, rmdir, iotjs_string_data(&path));
-  }
-
-  iotjs_string_destroy(&path);
-}
-
-
-JHANDLER_FUNCTION(Unlink) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, string);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  iotjs_string_t path = JHANDLER_GET_ARG(0, string);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-
-  if (jcallback) {
-    FS_ASYNC(env, unlink, jcallback, iotjs_string_data(&path));
-  } else {
-    FS_SYNC(env, unlink, iotjs_string_data(&path));
-  }
-
-  iotjs_string_destroy(&path);
-}
-
-
-JHANDLER_FUNCTION(Rename) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, string, string);
-  JHANDLER_CHECK_ARG_IF_EXIST(2, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  iotjs_string_t oldPath = JHANDLER_GET_ARG(0, string);
-  iotjs_string_t newPath = JHANDLER_GET_ARG(1, string);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(2, function);
-
-  if (jcallback) {
-    FS_ASYNC(env, rename, jcallback, iotjs_string_data(&oldPath),
-             iotjs_string_data(&newPath));
-  } else {
-    FS_SYNC(env, rename, iotjs_string_data(&oldPath),
-            iotjs_string_data(&newPath));
-  }
-
-  iotjs_string_destroy(&oldPath);
-  iotjs_string_destroy(&newPath);
-}
-
-
-JHANDLER_FUNCTION(ReadDir) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, string);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-  iotjs_string_t path = JHANDLER_GET_ARG(0, string);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-
-  if (jcallback) {
-    FS_ASYNC(env, scandir, jcallback, iotjs_string_data(&path), 0);
-  } else {
-    FS_SYNC(env, scandir, iotjs_string_data(&path), 0);
-  }
-  iotjs_string_destroy(&path);
-}
-
-
-iotjs_jval_t InitFs() {
-  iotjs_jval_t fs = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_CLOSE, Close);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_OPEN, Open);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_READ, Read);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_WRITE, Write);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_STAT, Stat);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_MKDIR, MkDir);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_RMDIR, RmDir);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_UNLINK, Unlink);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_RENAME, Rename);
-  iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_READDIR, ReadDir);
-
-  return fs;
-}
diff --git a/src/module/iotjs_module_fs.h b/src/module/iotjs_module_fs.h
deleted file mode 100644 (file)
index aaab379..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_FS_H
-#define IOTJS_MODULE_FS_H
-
-
-#include "iotjs_def.h"
-#include "iotjs_reqwrap.h"
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_fs_t req;
-} IOTJS_VALIDATED_STRUCT(iotjs_fs_reqwrap_t);
-
-
-iotjs_fs_reqwrap_t* iotjs_fs_reqwrap_create(const iotjs_jval_t* jcallback);
-
-void iotjs_fs_reqwrap_dispatched(iotjs_fs_reqwrap_t* fs_reqwrap);
-
-uv_fs_t* iotjs_fs_reqwrap_req(iotjs_fs_reqwrap_t* fs_reqwrap);
-const iotjs_jval_t* iotjs_fs_reqwrap_jcallback(iotjs_fs_reqwrap_t* fs_reqwrap);
-
-
-#endif /* IOTJS_MODULE_FS_H */
diff --git a/src/module/iotjs_module_gpio.c b/src/module/iotjs_module_gpio.c
deleted file mode 100644 (file)
index d9b86f5..0000000
+++ /dev/null
@@ -1,373 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#include "iotjs_def.h"
-#include "iotjs_module_gpio.h"
-#include "iotjs_objectwrap.h"
-#include <stdio.h>
-
-
-static void iotjs_gpio_destroy(iotjs_gpio_t* gpio);
-static iotjs_gpio_t* iotjs_gpio_instance_from_jval(const iotjs_jval_t* jgpio);
-
-
-static iotjs_gpio_t* iotjs_gpio_create(const iotjs_jval_t* jgpio) {
-  iotjs_gpio_t* gpio = IOTJS_ALLOC(iotjs_gpio_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_gpio_t, gpio);
-  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, jgpio,
-                               (JFreeHandlerType)iotjs_gpio_destroy);
-  return gpio;
-}
-
-
-static void iotjs_gpio_destroy(iotjs_gpio_t* gpio) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_gpio_t, gpio);
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-  IOTJS_RELEASE(gpio);
-}
-
-
-#define THIS iotjs_gpio_reqwrap_t* gpio_reqwrap
-
-
-static iotjs_gpio_reqwrap_t* iotjs_gpio_reqwrap_create(
-    const iotjs_jval_t* jcallback, const iotjs_jval_t* jgpio, GpioOp op) {
-  iotjs_gpio_reqwrap_t* gpio_reqwrap = IOTJS_ALLOC(iotjs_gpio_reqwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_gpio_reqwrap_t, gpio_reqwrap);
-
-  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
-
-  _this->req_data.op = op;
-  _this->gpio_instance = iotjs_gpio_instance_from_jval(jgpio);
-  return gpio_reqwrap;
-}
-
-
-static void iotjs_gpio_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_gpio_reqwrap_t, gpio_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(gpio_reqwrap);
-}
-
-
-static void iotjs_gpio_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_gpio_reqwrap_t, gpio_reqwrap);
-  iotjs_gpio_reqwrap_destroy(gpio_reqwrap);
-}
-
-
-static uv_work_t* iotjs_gpio_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_reqwrap_t, gpio_reqwrap);
-  return &_this->req;
-}
-
-
-static const iotjs_jval_t* iotjs_gpio_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_reqwrap_t, gpio_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-
-static iotjs_gpio_t* iotjs_gpio_instance_from_jval(const iotjs_jval_t* jgpio) {
-  uintptr_t handle = iotjs_jval_get_object_native_handle(jgpio);
-  return (iotjs_gpio_t*)handle;
-}
-
-
-iotjs_gpio_reqwrap_t* iotjs_gpio_reqwrap_from_request(uv_work_t* req) {
-  return (iotjs_gpio_reqwrap_t*)(iotjs_reqwrap_from_request((uv_req_t*)req));
-}
-
-
-iotjs_gpio_reqdata_t* iotjs_gpio_reqwrap_data(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_reqwrap_t, gpio_reqwrap);
-  return &_this->req_data;
-}
-
-
-iotjs_gpio_t* iotjs_gpio_instance_from_reqwrap(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_reqwrap_t, gpio_reqwrap);
-  return _this->gpio_instance;
-}
-
-
-#undef THIS
-
-
-void iotjs_gpio_after_worker(uv_work_t* work_req, int status) {
-  iotjs_gpio_reqwrap_t* req_wrap = iotjs_gpio_reqwrap_from_request(work_req);
-  iotjs_gpio_reqdata_t* req_data = iotjs_gpio_reqwrap_data(req_wrap);
-  iotjs_jargs_t jargs = iotjs_jargs_create(2);
-
-  if (status) {
-    iotjs_jargs_append_error(&jargs, "GPIO System Error");
-  } else {
-    switch (req_data->op) {
-      case kGpioOpOpen:
-        if (req_data->result < 0) {
-          iotjs_jargs_append_error(&jargs, "GPIO Open Error");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      case kGpioOpWrite:
-        if (req_data->result < 0) {
-          iotjs_jargs_append_error(&jargs, "GPIO Write Error");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      case kGpioOpRead:
-        if (req_data->result < 0) {
-          iotjs_jargs_append_error(&jargs, "GPIO Read Error");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-          iotjs_jargs_append_bool(&jargs, req_data->value);
-        }
-        break;
-      case kGpioOpClose:
-        if (req_data->result < 0) {
-          iotjs_jargs_append_error(&jargs, "GPIO Close Error");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      default:
-        IOTJS_ASSERT(!"Unreachable");
-        break;
-    }
-  }
-
-  const iotjs_jval_t* jcallback = iotjs_gpio_reqwrap_jcallback(req_wrap);
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &jargs);
-
-  iotjs_jargs_destroy(&jargs);
-
-  iotjs_gpio_reqwrap_dispatched(req_wrap);
-}
-
-
-static void gpio_set_configurable(iotjs_gpio_t* gpio,
-                                  const iotjs_jval_t* jconfigurable) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_t, gpio);
-
-  iotjs_jval_t jpin =
-      iotjs_jval_get_property(jconfigurable, IOTJS_MAGIC_STRING_PIN);
-  _this->pin = iotjs_jval_as_number(&jpin);
-  iotjs_jval_destroy(&jpin);
-
-  iotjs_jval_t jdirection =
-      iotjs_jval_get_property(jconfigurable, IOTJS_MAGIC_STRING_DIRECTION);
-  _this->direction = (GpioDirection)iotjs_jval_as_number(&jdirection);
-  iotjs_jval_destroy(&jdirection);
-
-  iotjs_jval_t jmode =
-      iotjs_jval_get_property(jconfigurable, IOTJS_MAGIC_STRING_MODE);
-  _this->mode = (GpioMode)iotjs_jval_as_number(&jmode);
-  iotjs_jval_destroy(&jmode);
-}
-
-
-#define GPIO_ASYNC(op)                                                 \
-  do {                                                                 \
-    uv_loop_t* loop = iotjs_environment_loop(iotjs_environment_get()); \
-    uv_work_t* req = iotjs_gpio_reqwrap_req(req_wrap);                 \
-    uv_queue_work(loop, req, iotjs_gpio_##op##_worker,                 \
-                  iotjs_gpio_after_worker);                            \
-  } while (0)
-
-
-// write(value, callback)
-JHANDLER_FUNCTION(Write) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, boolean, function);
-
-  bool value = JHANDLER_GET_ARG(0, boolean);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(1, function);
-
-  iotjs_gpio_reqwrap_t* req_wrap =
-      iotjs_gpio_reqwrap_create(jcallback, JHANDLER_GET_THIS(object),
-                                kGpioOpWrite);
-
-  iotjs_gpio_reqdata_t* req_data = iotjs_gpio_reqwrap_data(req_wrap);
-  req_data->value = value;
-
-  GPIO_ASYNC(write);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-// writeSync(value)
-JHANDLER_FUNCTION(WriteSync) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, boolean);
-
-  const iotjs_jval_t* jgpio = JHANDLER_GET_THIS(object);
-  iotjs_gpio_t* gpio = iotjs_gpio_instance_from_jval(jgpio);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_t, gpio);
-
-  bool value = JHANDLER_GET_ARG(0, boolean);
-
-  if (iotjs_gpio_write(_this->pin, value)) {
-    iotjs_jhandler_return_null(jhandler);
-  } else {
-    iotjs_jval_t jerror = iotjs_jval_create_error("GPIO WriteSync Error");
-    iotjs_jhandler_throw(jhandler, &jerror);
-    iotjs_jval_destroy(&jerror);
-  }
-}
-
-
-// read(callback)
-JHANDLER_FUNCTION(Read) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(0, function);
-  iotjs_gpio_reqwrap_t* req_wrap =
-      iotjs_gpio_reqwrap_create(jcallback, JHANDLER_GET_THIS(object),
-                                kGpioOpRead);
-
-  GPIO_ASYNC(read);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-// readSync()
-JHANDLER_FUNCTION(ReadSync) {
-  JHANDLER_CHECK_THIS(object);
-
-  const iotjs_jval_t* jgpio = JHANDLER_GET_THIS(object);
-  iotjs_gpio_t* gpio = iotjs_gpio_instance_from_jval(jgpio);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_t, gpio);
-
-  int value = iotjs_gpio_read(_this->pin);
-
-  if (value >= 0) {
-    iotjs_jhandler_return_boolean(jhandler, value);
-  } else {
-    iotjs_jval_t jerror = iotjs_jval_create_error("GPIO ReadSync Error");
-    iotjs_jhandler_throw(jhandler, &jerror);
-    iotjs_jval_destroy(&jerror);
-  }
-}
-
-
-// close(callback)
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_ARGS(1, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(0, function);
-  iotjs_gpio_reqwrap_t* req_wrap =
-      iotjs_gpio_reqwrap_create(jcallback, JHANDLER_GET_THIS(object),
-                                kGpioOpClose);
-
-  GPIO_ASYNC(close);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-// closeSync()
-JHANDLER_FUNCTION(CloseSync) {
-  JHANDLER_CHECK_THIS(object);
-
-  const iotjs_jval_t* jgpio = JHANDLER_GET_THIS(object);
-  iotjs_gpio_t* gpio = iotjs_gpio_instance_from_jval(jgpio);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_t, gpio);
-
-  if (iotjs_gpio_close(_this->pin)) {
-    iotjs_jhandler_return_null(jhandler);
-  } else {
-    iotjs_jval_t jerror = iotjs_jval_create_error("GPIO CloseSync Error");
-    iotjs_jhandler_throw(jhandler, &jerror);
-    iotjs_jval_destroy(&jerror);
-  }
-}
-
-
-// Constructor(configurable, callback)
-JHANDLER_FUNCTION(GpioConstructor) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, object, function);
-
-  // Create GPIO object
-  const iotjs_jval_t* jgpio = JHANDLER_GET_THIS(object);
-  iotjs_gpio_t* gpio = iotjs_gpio_create(jgpio);
-  IOTJS_ASSERT(gpio == iotjs_gpio_instance_from_jval(jgpio));
-
-  gpio_set_configurable(gpio, JHANDLER_GET_ARG(0, object));
-
-  // Create reqwrap
-  iotjs_gpio_reqwrap_t* req_wrap =
-      iotjs_gpio_reqwrap_create(JHANDLER_GET_ARG(1, function), jgpio,
-                                kGpioOpOpen);
-
-  GPIO_ASYNC(open);
-}
-
-
-iotjs_jval_t InitGpio() {
-  iotjs_jval_t jgpio = iotjs_jval_create_object();
-  iotjs_jval_t jgpioConstructor =
-      iotjs_jval_create_function_with_dispatch(GpioConstructor);
-  iotjs_jval_set_property_jval(&jgpio, IOTJS_MAGIC_STRING_GPIO,
-                               &jgpioConstructor);
-
-  iotjs_jval_t jprototype = iotjs_jval_create_object();
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_WRITE, Write);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_WRITESYNC, WriteSync);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_READ, Read);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_READSYNC, ReadSync);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_CLOSE, Close);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_CLOSESYNC, CloseSync);
-  iotjs_jval_set_property_jval(&jgpioConstructor, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &jprototype);
-  iotjs_jval_destroy(&jprototype);
-  iotjs_jval_destroy(&jgpioConstructor);
-
-  // GPIO direction properties
-  iotjs_jval_t jdirection = iotjs_jval_create_object();
-  iotjs_jval_set_property_number(&jdirection, IOTJS_MAGIC_STRING_IN,
-                                 kGpioDirectionIn);
-  iotjs_jval_set_property_number(&jdirection, IOTJS_MAGIC_STRING_OUT,
-                                 kGpioDirectionOut);
-  iotjs_jval_set_property_jval(&jgpio, IOTJS_MAGIC_STRING_DIRECTION_U,
-                               &jdirection);
-  iotjs_jval_destroy(&jdirection);
-
-  // GPIO mode properties
-  iotjs_jval_t jmode = iotjs_jval_create_object();
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_NONE,
-                                 kGpioModeNone);
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_PULLUP,
-                                 kGpioModePullup);
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_PULLDOWN,
-                                 kGpioModePulldown);
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_FLOAT,
-                                 kGpioModeFloat);
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_PUSHPULL,
-                                 kGpioModePushpull);
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_OPENDRAIN,
-                                 kGpioModeOpendrain);
-  iotjs_jval_set_property_jval(&jgpio, IOTJS_MAGIC_STRING_MODE_U, &jmode);
-  iotjs_jval_destroy(&jmode);
-
-  return jgpio;
-}
diff --git a/src/module/iotjs_module_gpio.h b/src/module/iotjs_module_gpio.h
deleted file mode 100644 (file)
index 1bb0353..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_GPIO_H
-#define IOTJS_MODULE_GPIO_H
-
-
-#include "iotjs_def.h"
-#include "iotjs_objectwrap.h"
-#include "iotjs_reqwrap.h"
-
-
-typedef enum {
-  kGpioDirectionIn = 0,
-  kGpioDirectionOut,
-} GpioDirection;
-
-
-typedef enum {
-  kGpioModeNone = 0,
-  kGpioModePullup,
-  kGpioModePulldown,
-  kGpioModeFloat,
-  kGpioModePushpull,
-  kGpioModeOpendrain,
-} GpioMode;
-
-
-typedef enum {
-  kGpioOpOpen,
-  kGpioOpWrite,
-  kGpioOpRead,
-  kGpioOpClose,
-} GpioOp;
-
-
-typedef struct {
-  bool value;
-  ssize_t result;
-  GpioOp op;
-} iotjs_gpio_reqdata_t;
-
-
-// This Gpio class provides interfaces for GPIO operation.
-typedef struct {
-  iotjs_jobjectwrap_t jobjectwrap;
-  uint32_t pin;
-  GpioDirection direction;
-  GpioMode mode;
-} IOTJS_VALIDATED_STRUCT(iotjs_gpio_t);
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_work_t req;
-  iotjs_gpio_reqdata_t req_data;
-  iotjs_gpio_t* gpio_instance;
-} IOTJS_VALIDATED_STRUCT(iotjs_gpio_reqwrap_t);
-
-
-#define THIS iotjs_gpio_reqwrap_t* gpio_reqwrap
-
-iotjs_gpio_reqwrap_t* iotjs_gpio_reqwrap_from_request(uv_work_t* req);
-iotjs_gpio_reqdata_t* iotjs_gpio_reqwrap_data(THIS);
-
-iotjs_gpio_t* iotjs_gpio_instance_from_reqwrap(THIS);
-
-#undef THIS
-
-
-#define GPIO_WORKER_INIT()                                                    \
-  iotjs_gpio_reqwrap_t* req_wrap = iotjs_gpio_reqwrap_from_request(work_req); \
-  iotjs_gpio_reqdata_t* req_data = iotjs_gpio_reqwrap_data(req_wrap);         \
-  iotjs_gpio_t* gpio = iotjs_gpio_instance_from_reqwrap(req_wrap);            \
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_t, gpio);
-
-
-void iotjs_gpio_open_worker(uv_work_t* work_req);
-void iotjs_gpio_write_worker(uv_work_t* work_req);
-void iotjs_gpio_read_worker(uv_work_t* work_req);
-void iotjs_gpio_close_worker(uv_work_t* work_req);
-bool iotjs_gpio_write(int32_t pin, bool value);
-int iotjs_gpio_read(int32_t pin);
-bool iotjs_gpio_close(int32_t pin);
-
-#endif /* IOTJS_MODULE_GPIO_H */
diff --git a/src/module/iotjs_module_httpparser.c b/src/module/iotjs_module_httpparser.c
deleted file mode 100644 (file)
index 8e12b04..0000000
+++ /dev/null
@@ -1,511 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "iotjs_def.h"
-#include "iotjs_module_httpparser.h"
-#include "iotjs_module_buffer.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-#define THIS iotjs_httpparserwrap_t* httpparserwrap
-
-
-static void iotjs_httpparserwrap_destroy(THIS);
-
-
-iotjs_httpparserwrap_t* iotjs_httpparserwrap_create(const iotjs_jval_t* jparser,
-                                                    http_parser_type type) {
-  iotjs_httpparserwrap_t* httpparserwrap = IOTJS_ALLOC(iotjs_httpparserwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_httpparserwrap_t, httpparserwrap);
-
-  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, jparser,
-                               (JFreeHandlerType)iotjs_httpparserwrap_destroy);
-
-  _this->url = iotjs_string_create();
-  _this->status_msg = iotjs_string_create();
-  for (size_t i = 0; i < HEADER_MAX; i++) {
-    _this->fields[i] = iotjs_string_create();
-    _this->values[i] = iotjs_string_create();
-  }
-
-  iotjs_httpparserwrap_initialize(httpparserwrap, type);
-  _this->parser.data = httpparserwrap;
-
-  return httpparserwrap;
-}
-
-
-static void iotjs_httpparserwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_httpparserwrap_t, httpparserwrap);
-
-  iotjs_string_destroy(&_this->url);
-  iotjs_string_destroy(&_this->status_msg);
-  for (size_t i = 0; i < HEADER_MAX; i++) {
-    iotjs_string_destroy(&_this->fields[i]);
-    iotjs_string_destroy(&_this->values[i]);
-  }
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-
-  IOTJS_RELEASE(httpparserwrap);
-}
-
-
-void iotjs_httpparserwrap_initialize(THIS, http_parser_type type) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-
-  http_parser_init(&_this->parser, type);
-  iotjs_string_make_empty(&_this->url);
-  iotjs_string_make_empty(&_this->status_msg);
-  _this->n_fields = 0;
-  _this->n_values = 0;
-  _this->flushed = false;
-  _this->cur_jbuf = NULL;
-  _this->cur_buf = NULL;
-  _this->cur_buf_len = 0;
-}
-
-
-// http-parser callbacks
-static int iotjs_httpparserwrap_on_message_begin(http_parser* parser) {
-  iotjs_httpparserwrap_t* httpparserwrap =
-      (iotjs_httpparserwrap_t*)(parser->data);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-  iotjs_string_make_empty(&_this->url);
-  iotjs_string_make_empty(&_this->status_msg);
-  return 0;
-}
-
-
-static int iotjs_httpparserwrap_on_url(http_parser* parser, const char* at,
-                                       size_t length) {
-  iotjs_httpparserwrap_t* httpparserwrap =
-      (iotjs_httpparserwrap_t*)(parser->data);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-  iotjs_string_append(&_this->url, at, length);
-  return 0;
-}
-
-
-static int iotjs_httpparserwrap_on_status(http_parser* parser, const char* at,
-                                          size_t length) {
-  iotjs_httpparserwrap_t* httpparserwrap =
-      (iotjs_httpparserwrap_t*)(parser->data);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-  iotjs_string_append(&_this->status_msg, at, length);
-  return 0;
-}
-
-
-static int iotjs_httpparserwrap_on_header_field(http_parser* parser,
-                                                const char* at, size_t length) {
-  iotjs_httpparserwrap_t* httpparserwrap =
-      (iotjs_httpparserwrap_t*)(parser->data);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-  if (_this->n_fields == _this->n_values) {
-    _this->n_fields++;
-    // values and fields are flushed to JS
-    // before corresponding OnHeaderValue is called.
-    if (_this->n_fields == HEADER_MAX) {
-      iotjs_httpparserwrap_flush(httpparserwrap); // to JS world
-      _this->n_fields = 1;
-      _this->n_values = 0;
-    }
-    iotjs_string_make_empty(&_this->fields[_this->n_fields - 1]);
-  }
-  IOTJS_ASSERT(_this->n_fields == _this->n_values + 1);
-  iotjs_string_append(&_this->fields[_this->n_fields - 1], at, length);
-
-  return 0;
-}
-
-
-static int iotjs_httpparserwrap_on_header_value(http_parser* parser,
-                                                const char* at, size_t length) {
-  iotjs_httpparserwrap_t* httpparserwrap =
-      (iotjs_httpparserwrap_t*)(parser->data);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-  if (_this->n_fields != _this->n_values) {
-    _this->n_values++;
-    iotjs_string_make_empty(&_this->values[_this->n_values - 1]);
-  }
-
-  IOTJS_ASSERT(_this->n_fields == _this->n_values);
-
-  iotjs_string_append(&_this->values[_this->n_values - 1], at, length);
-
-  return 0;
-}
-
-
-static int iotjs_httpparserwrap_on_headers_complete(http_parser* parser) {
-  iotjs_httpparserwrap_t* httpparserwrap =
-      (iotjs_httpparserwrap_t*)(parser->data);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-
-  const iotjs_jval_t* jobj = iotjs_httpparserwrap_jobject(httpparserwrap);
-  iotjs_jval_t func =
-      iotjs_jval_get_property(jobj, IOTJS_MAGIC_STRING_ONHEADERSCOMPLETE);
-  IOTJS_ASSERT(iotjs_jval_is_function(&func));
-
-  // URL
-  iotjs_jargs_t argv = iotjs_jargs_create(1);
-  iotjs_jval_t info = iotjs_jval_create_object();
-
-  if (_this->flushed) {
-    // If some headers already are flushed,
-    // flush the remaining headers.
-    // In Flush function, url is already flushed to JS.
-    iotjs_httpparserwrap_flush(httpparserwrap);
-  } else {
-    // Here, there was no flushed header.
-    // We need to make a new header object with all header fields
-    iotjs_jval_t jheader = iotjs_httpparserwrap_make_header(httpparserwrap);
-    iotjs_jval_set_property_jval(&info, IOTJS_MAGIC_STRING_HEADERS, &jheader);
-    iotjs_jval_destroy(&jheader);
-    if (_this->parser.type == HTTP_REQUEST) {
-      IOTJS_ASSERT(!iotjs_string_is_empty(&_this->url));
-      iotjs_jval_set_property_string(&info, IOTJS_MAGIC_STRING_URL,
-                                     &_this->url);
-    }
-  }
-  _this->n_fields = _this->n_values = 0;
-
-  // Method
-  if (_this->parser.type == HTTP_REQUEST) {
-    iotjs_jval_set_property_number(&info, IOTJS_MAGIC_STRING_METHOD,
-                                   _this->parser.method);
-  }
-
-  // Status
-  if (_this->parser.type == HTTP_RESPONSE) {
-    iotjs_jval_set_property_number(&info, IOTJS_MAGIC_STRING_STATUS,
-                                   _this->parser.status_code);
-    iotjs_jval_set_property_string(&info, IOTJS_MAGIC_STRING_STATUS_MSG,
-                                   &_this->status_msg);
-  }
-
-
-  // For future support, current http_server module does not support
-  // upgrade and keepalive.
-  // upgrade
-  iotjs_jval_set_property_boolean(&info, IOTJS_MAGIC_STRING_UPGRADE,
-                                  _this->parser.upgrade);
-  // shouldkeepalive
-  iotjs_jval_set_property_boolean(&info, IOTJS_MAGIC_STRING_SHOULDKEEPALIVE,
-                                  http_should_keep_alive(&_this->parser));
-
-
-  iotjs_jargs_append_jval(&argv, &info);
-
-  iotjs_jval_t res = iotjs_make_callback_with_result(&func, jobj, &argv);
-  bool ret = iotjs_jval_as_boolean(&res);
-
-  iotjs_jargs_destroy(&argv);
-  iotjs_jval_destroy(&func);
-  iotjs_jval_destroy(&res);
-  iotjs_jval_destroy(&info);
-
-  return ret;
-}
-
-
-static int iotjs_httpparserwrap_on_body(http_parser* parser, const char* at,
-                                        size_t length) {
-  iotjs_httpparserwrap_t* httpparserwrap =
-      (iotjs_httpparserwrap_t*)(parser->data);
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-
-  const iotjs_jval_t* jobj = iotjs_httpparserwrap_jobject(httpparserwrap);
-  iotjs_jval_t func = iotjs_jval_get_property(jobj, IOTJS_MAGIC_STRING_ONBODY);
-  IOTJS_ASSERT(iotjs_jval_is_function(&func));
-
-  iotjs_jargs_t argv = iotjs_jargs_create(3);
-  iotjs_jargs_append_jval(&argv, _this->cur_jbuf);
-  iotjs_jargs_append_number(&argv, at - _this->cur_buf);
-  iotjs_jargs_append_number(&argv, length);
-
-
-  iotjs_make_callback(&func, jobj, &argv);
-
-  iotjs_jargs_destroy(&argv);
-  iotjs_jval_destroy(&func);
-
-  return 0;
-}
-
-
-static int iotjs_httpparserwrap_on_message_complete(http_parser* parser) {
-  iotjs_httpparserwrap_t* httpparserwrap =
-      (iotjs_httpparserwrap_t*)(parser->data);
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_httpparserwrap_t,
-                                           httpparserwrap);
-
-  const iotjs_jval_t* jobj = iotjs_httpparserwrap_jobject(httpparserwrap);
-  iotjs_jval_t func =
-      iotjs_jval_get_property(jobj, IOTJS_MAGIC_STRING_ONMESSAGECOMPLETE);
-  IOTJS_ASSERT(iotjs_jval_is_function(&func));
-
-  iotjs_make_callback(&func, jobj, iotjs_jargs_get_empty());
-
-  iotjs_jval_destroy(&func);
-
-  return 0;
-}
-
-
-iotjs_jval_t iotjs_httpparserwrap_make_header(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-
-  iotjs_jval_t jheader = iotjs_jval_create_array(_this->n_values * 2);
-  for (size_t i = 0; i < _this->n_values; i++) {
-    iotjs_jval_t f = iotjs_jval_create_string(&_this->fields[i]);
-    iotjs_jval_t v = iotjs_jval_create_string(&_this->values[i]);
-    iotjs_jval_set_property_by_index(&jheader, i * 2, &f);
-    iotjs_jval_set_property_by_index(&jheader, i * 2 + 1, &v);
-    iotjs_jval_destroy(&f);
-    iotjs_jval_destroy(&v);
-  }
-  return jheader;
-}
-
-
-void iotjs_httpparserwrap_flush(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-
-  const iotjs_jval_t* jobj = iotjs_httpparserwrap_jobject(httpparserwrap);
-  iotjs_jval_t func =
-      iotjs_jval_get_property(jobj, IOTJS_MAGIC_STRING_ONHEADERS);
-  IOTJS_ASSERT(iotjs_jval_is_function(&func));
-
-  iotjs_jargs_t argv = iotjs_jargs_create(2);
-  iotjs_jval_t jheader = iotjs_httpparserwrap_make_header(httpparserwrap);
-  iotjs_jargs_append_jval(&argv, &jheader);
-  iotjs_jval_destroy(&jheader);
-  if (_this->parser.type == HTTP_REQUEST &&
-      !iotjs_string_is_empty(&_this->url)) {
-    iotjs_jargs_append_string(&argv, &_this->url);
-  }
-
-  iotjs_make_callback(&func, jobj, &argv);
-
-  iotjs_string_make_empty(&_this->url);
-  iotjs_jargs_destroy(&argv);
-  iotjs_jval_destroy(&func);
-  _this->flushed = true;
-}
-
-
-void iotjs_httpparserwrap_set_buf(THIS, iotjs_jval_t* jbuf, char* buf, int sz) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-  _this->cur_jbuf = jbuf;
-  _this->cur_buf = buf;
-  _this->cur_buf_len = sz;
-}
-
-
-iotjs_jval_t* iotjs_httpparserwrap_jobject(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-
-  return iotjs_jobjectwrap_jobject(&_this->jobjectwrap);
-}
-
-
-http_parser* iotjs_httpparserwrap_parser(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_httpparserwrap_t, httpparserwrap);
-  return &_this->parser;
-}
-
-
-#undef THIS
-
-
-const struct http_parser_settings settings = {
-  iotjs_httpparserwrap_on_message_begin,
-  iotjs_httpparserwrap_on_url,
-  iotjs_httpparserwrap_on_status,
-  iotjs_httpparserwrap_on_header_field,
-  iotjs_httpparserwrap_on_header_value,
-  iotjs_httpparserwrap_on_headers_complete,
-  iotjs_httpparserwrap_on_body,
-  iotjs_httpparserwrap_on_message_complete,
-  NULL, /* on_chunk_header */
-  NULL, /* on_chunk_complete */
-};
-
-
-static iotjs_httpparserwrap_t* get_parser_wrap(const iotjs_jval_t* jparser) {
-  uintptr_t handle = iotjs_jval_get_object_native_handle(jparser);
-  return (iotjs_httpparserwrap_t*)(handle);
-}
-
-
-JHANDLER_FUNCTION(Reinitialize) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, number);
-
-  const iotjs_jval_t* jparser = JHANDLER_GET_THIS(object);
-
-  http_parser_type httpparser_type =
-      (http_parser_type)(JHANDLER_GET_ARG(0, number));
-  IOTJS_ASSERT(httpparser_type == HTTP_REQUEST ||
-               httpparser_type == HTTP_RESPONSE);
-
-  iotjs_httpparserwrap_t* parser = get_parser_wrap(jparser);
-  iotjs_httpparserwrap_initialize(parser, httpparser_type);
-}
-
-
-JHANDLER_FUNCTION(Finish) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* jparser = JHANDLER_GET_THIS(object);
-  iotjs_httpparserwrap_t* parser = get_parser_wrap(jparser);
-
-  http_parser* nativeparser = iotjs_httpparserwrap_parser(parser);
-  int rv = http_parser_execute(nativeparser, &settings, NULL, 0);
-
-  if (rv != 0) {
-    enum http_errno err = HTTP_PARSER_ERRNO(nativeparser);
-
-    iotjs_jval_t eobj = iotjs_jval_create_error("Parse Error");
-    iotjs_jval_set_property_number(&eobj, IOTJS_MAGIC_STRING_BYTEPARSED, 0);
-    iotjs_jval_set_property_string_raw(&eobj, IOTJS_MAGIC_STRING_CODE,
-                                       http_errno_name(err));
-    iotjs_jhandler_return_jval(jhandler, &eobj);
-    iotjs_jval_destroy(&eobj);
-  }
-}
-
-
-JHANDLER_FUNCTION(Execute) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, object);
-
-  const iotjs_jval_t* jparser = JHANDLER_GET_THIS(object);
-  iotjs_httpparserwrap_t* parser = get_parser_wrap(jparser);
-
-
-  const iotjs_jval_t* jbuffer = JHANDLER_GET_ARG(0, object);
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(jbuffer);
-  char* buf_data = iotjs_bufferwrap_buffer(buffer_wrap);
-  int buf_len = iotjs_bufferwrap_length(buffer_wrap);
-  JHANDLER_CHECK(buf_data != NULL);
-  JHANDLER_CHECK(buf_len > 0);
-
-  iotjs_httpparserwrap_set_buf(parser, (iotjs_jval_t*)jbuffer, buf_data,
-                               buf_len);
-
-  http_parser* nativeparser = iotjs_httpparserwrap_parser(parser);
-  int nparsed = http_parser_execute(nativeparser, &settings, buf_data, buf_len);
-
-  iotjs_httpparserwrap_set_buf(parser, NULL, NULL, 0);
-
-
-  if (!nativeparser->upgrade && nparsed != buf_len) {
-    // nparsed should equal to buf_len except UPGRADE protocol
-    enum http_errno err = HTTP_PARSER_ERRNO(nativeparser);
-    iotjs_jval_t eobj = iotjs_jval_create_error("Parse Error");
-    iotjs_jval_set_property_number(&eobj, IOTJS_MAGIC_STRING_BYTEPARSED, 0);
-    iotjs_jval_set_property_string_raw(&eobj, IOTJS_MAGIC_STRING_CODE,
-                                       http_errno_name(err));
-    iotjs_jhandler_return_jval(jhandler, &eobj);
-    iotjs_jval_destroy(&eobj);
-  } else {
-    iotjs_jhandler_return_number(jhandler, nparsed);
-  }
-}
-
-
-JHANDLER_FUNCTION(Pause) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-  const iotjs_jval_t* jparser = JHANDLER_GET_THIS(object);
-  iotjs_httpparserwrap_t* parser = get_parser_wrap(jparser);
-  http_parser* nativeparser = iotjs_httpparserwrap_parser(parser);
-  http_parser_pause(nativeparser, 1);
-}
-
-
-JHANDLER_FUNCTION(Resume) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-  const iotjs_jval_t* jparser = JHANDLER_GET_THIS(object);
-  iotjs_httpparserwrap_t* parser = get_parser_wrap(jparser);
-  http_parser* nativeparser = iotjs_httpparserwrap_parser(parser);
-  http_parser_pause(nativeparser, 0);
-}
-
-
-JHANDLER_FUNCTION(HTTPParserCons) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, number);
-
-  const iotjs_jval_t* jparser = JHANDLER_GET_THIS(object);
-
-  http_parser_type httpparser_type =
-      (http_parser_type)(JHANDLER_GET_ARG(0, number));
-  IOTJS_ASSERT(httpparser_type == HTTP_REQUEST ||
-               httpparser_type == HTTP_RESPONSE);
-  iotjs_httpparserwrap_t* parser =
-      iotjs_httpparserwrap_create(jparser, httpparser_type);
-  IOTJS_ASSERT(iotjs_jval_is_object(iotjs_httpparserwrap_jobject(parser)));
-  IOTJS_ASSERT(get_parser_wrap(jparser) == parser);
-}
-
-
-iotjs_jval_t InitHttpparser() {
-  iotjs_jval_t httpparser = iotjs_jval_create_object();
-
-  iotjs_jval_t jParserCons =
-      iotjs_jval_create_function_with_dispatch(HTTPParserCons);
-  iotjs_jval_set_property_jval(&httpparser, IOTJS_MAGIC_STRING_HTTPPARSER,
-                               &jParserCons);
-
-  iotjs_jval_set_property_number(&jParserCons, IOTJS_MAGIC_STRING_REQUEST,
-                                 HTTP_REQUEST);
-  iotjs_jval_set_property_number(&jParserCons, IOTJS_MAGIC_STRING_RESPONSE,
-                                 HTTP_RESPONSE);
-
-  iotjs_jval_t methods = iotjs_jval_create_object();
-#define V(num, name, string) \
-  iotjs_jval_set_property_string_raw(&methods, #num, #string);
-  HTTP_METHOD_MAP(V)
-#undef V
-
-  iotjs_jval_set_property_jval(&jParserCons, IOTJS_MAGIC_STRING_METHODS,
-                               &methods);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_EXECUTE, Execute);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_REINITIALIZE,
-                        Reinitialize);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_FINISH, Finish);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_PAUSE, Pause);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_RESUME, Resume);
-
-  iotjs_jval_set_property_jval(&jParserCons, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &prototype);
-
-  iotjs_jval_destroy(&jParserCons);
-  iotjs_jval_destroy(&methods);
-  iotjs_jval_destroy(&prototype);
-
-  return httpparser;
-}
diff --git a/src/module/iotjs_module_httpparser.h b/src/module/iotjs_module_httpparser.h
deleted file mode 100644 (file)
index dd25b3f..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_HTTPPARSER_H
-#define IOTJS_MODULE_HTTPPARSER_H
-
-
-#include "iotjs_objectwrap.h"
-
-#include "http_parser.h"
-
-
-// If # of header fields == HEADER_MAX, flush header to JS side.
-// This is weired : # of maximum headers in C equals to HEADER_MAX-1.
-// This is because , OnHeaders cb, we increase n_fields first,
-// and check whether field == HEADER_MAX.
-// ex) HEADER_MAX 2 means that we can keep at most 1 header field/value
-// during http parsing.
-// Increase this to minimize inter JS-C call
-#define HEADER_MAX 10
-
-
-typedef struct {
-  iotjs_jobjectwrap_t jobjectwrap;
-
-  http_parser parser;
-
-  iotjs_string_t url;
-  iotjs_string_t status_msg;
-
-  iotjs_string_t fields[HEADER_MAX];
-  iotjs_string_t values[HEADER_MAX];
-  size_t n_fields;
-  size_t n_values;
-
-  iotjs_jval_t* cur_jbuf;
-  char* cur_buf;
-  size_t cur_buf_len;
-
-  bool flushed;
-} IOTJS_VALIDATED_STRUCT(iotjs_httpparserwrap_t);
-
-
-typedef enum http_parser_type http_parser_type;
-
-
-#define THIS iotjs_httpparserwrap_t* httpparserwrap
-
-
-iotjs_httpparserwrap_t* iotjs_httpparserwrap_create(const iotjs_jval_t* jparser,
-                                                    http_parser_type type);
-
-void iotjs_httpparserwrap_initialize(THIS, http_parser_type type);
-iotjs_jval_t iotjs_httpparserwrap_make_header(THIS);
-
-void iotjs_httpparserwrap_flush(THIS);
-
-void iotjs_httpparserwrap_set_buf(THIS, iotjs_jval_t* jbuf, char* buf, int sz);
-
-iotjs_jval_t* iotjs_httpparserwrap_jobject(THIS);
-http_parser* iotjs_httpparserwrap_parser(THIS);
-
-
-#undef THIS
-
-
-#endif /* IOTJS_MODULE_HTTPPARSER_H */
diff --git a/src/module/iotjs_module_i2c.c b/src/module/iotjs_module_i2c.c
deleted file mode 100644 (file)
index 3a49a9a..0000000
+++ /dev/null
@@ -1,435 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "iotjs_def.h"
-#include "iotjs_module_i2c.h"
-#include "iotjs_objectwrap.h"
-
-
-#define THIS iotjs_i2c_reqwrap_t* i2c_reqwrap
-
-
-iotjs_i2c_reqwrap_t* iotjs_i2c_reqwrap_create(const iotjs_jval_t* jcallback,
-                                              const iotjs_jval_t* ji2c,
-                                              I2cOp op) {
-  iotjs_i2c_reqwrap_t* i2c_reqwrap = IOTJS_ALLOC(iotjs_i2c_reqwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_i2c_reqwrap_t, i2c_reqwrap);
-
-  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
-
-  _this->req_data.op = op;
-#if defined(__linux__) || defined(__APPLE__)
-  _this->req_data.device = iotjs_string_create("");
-#endif
-  _this->i2c_data = iotjs_i2c_instance_from_jval(ji2c);
-  return i2c_reqwrap;
-}
-
-
-static void iotjs_i2c_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_i2c_reqwrap_t, i2c_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-#if defined(__linux__) || defined(__APPLE__)
-  iotjs_string_destroy(&_this->req_data.device);
-#endif
-  IOTJS_RELEASE(i2c_reqwrap);
-}
-
-
-void iotjs_i2c_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_i2c_reqwrap_t, i2c_reqwrap);
-  iotjs_i2c_reqwrap_destroy(i2c_reqwrap);
-}
-
-
-uv_work_t* iotjs_i2c_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_i2c_reqwrap_t, i2c_reqwrap);
-  return &_this->req;
-}
-
-
-const iotjs_jval_t* iotjs_i2c_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_i2c_reqwrap_t, i2c_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-
-iotjs_i2c_reqwrap_t* iotjs_i2c_reqwrap_from_request(uv_work_t* req) {
-  return (iotjs_i2c_reqwrap_t*)(iotjs_reqwrap_from_request((uv_req_t*)req));
-}
-
-
-iotjs_i2c_reqdata_t* iotjs_i2c_reqwrap_data(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_i2c_reqwrap_t, i2c_reqwrap);
-  return &_this->req_data;
-}
-
-
-iotjs_i2c_t* iotjs_i2c_instance_from_reqwrap(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_i2c_reqwrap_t, i2c_reqwrap);
-  return _this->i2c_data;
-}
-
-#undef THIS
-
-
-static void iotjs_i2c_destroy(iotjs_i2c_t* i2c);
-
-
-iotjs_i2c_t* iotjs_i2c_create(const iotjs_jval_t* ji2c) {
-  iotjs_i2c_t* i2c = IOTJS_ALLOC(iotjs_i2c_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_i2c_t, i2c);
-
-#if defined(__NUTTX__)
-  _this->i2c_master = NULL;
-#endif
-
-  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, ji2c,
-                               (JFreeHandlerType)iotjs_i2c_destroy);
-  return i2c;
-}
-
-
-static void iotjs_i2c_destroy(iotjs_i2c_t* i2c) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_i2c_t, i2c);
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-  IOTJS_RELEASE(i2c);
-}
-
-
-iotjs_i2c_t* iotjs_i2c_instance_from_jval(const iotjs_jval_t* ji2c) {
-  iotjs_jobjectwrap_t* jobjectwrap = iotjs_jobjectwrap_from_jobject(ji2c);
-  return (iotjs_i2c_t*)jobjectwrap;
-}
-
-
-void AfterI2CWork(uv_work_t* work_req, int status) {
-  iotjs_i2c_reqwrap_t* req_wrap = iotjs_i2c_reqwrap_from_request(work_req);
-  iotjs_i2c_reqdata_t* req_data = iotjs_i2c_reqwrap_data(req_wrap);
-
-  iotjs_jargs_t jargs = iotjs_jargs_create(2);
-
-  if (status) {
-    iotjs_jval_t error = iotjs_jval_create_error("System error");
-    iotjs_jargs_append_jval(&jargs, &error);
-    iotjs_jval_destroy(&error);
-  } else {
-    switch (req_data->op) {
-      case kI2cOpOpen: {
-        if (req_data->error == kI2cErrOpen) {
-          iotjs_jval_t error =
-              iotjs_jval_create_error("Failed to open I2C device");
-          iotjs_jargs_append_jval(&jargs, &error);
-          iotjs_jval_destroy(&error);
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      }
-      case kI2cOpWrite:
-      case kI2cOpWriteByte:
-      case kI2cOpWriteBlock: {
-        if (req_data->error == kI2cErrWrite) {
-          iotjs_jval_t error =
-              iotjs_jval_create_error("Cannot write to device");
-          iotjs_jargs_append_jval(&jargs, &error);
-          iotjs_jval_destroy(&error);
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      }
-      case kI2cOpRead:
-      case kI2cOpReadBlock: {
-        if (req_data->error == kI2cErrRead) {
-          iotjs_jval_t error =
-              iotjs_jval_create_error("Cannot read from device");
-          iotjs_jargs_append_jval(&jargs, &error);
-          iotjs_jargs_append_null(&jargs);
-          iotjs_jval_destroy(&error);
-        } else if (req_data->error == kI2cErrReadBlock) {
-          iotjs_jval_t error =
-              iotjs_jval_create_error("Error reading length of bytes");
-          iotjs_jargs_append_jval(&jargs, &error);
-          iotjs_jargs_append_null(&jargs);
-          iotjs_jval_destroy(&error);
-        } else {
-          iotjs_jargs_append_null(&jargs);
-          iotjs_jval_t result =
-              iotjs_jval_create_byte_array(req_data->buf_len,
-                                           req_data->buf_data);
-          iotjs_jargs_append_jval(&jargs, &result);
-          iotjs_jval_destroy(&result);
-
-          if (req_data->delay > 0) {
-            uv_sleep(req_data->delay);
-          }
-
-          if (req_data->buf_data != NULL) {
-            iotjs_buffer_release(req_data->buf_data);
-          }
-        }
-        break;
-      }
-      case kI2cOpReadByte: {
-        if (req_data->error == kI2cErrRead) {
-          iotjs_jval_t error =
-              iotjs_jval_create_error("Cannot read from device");
-          iotjs_jargs_append_jval(&jargs, &error);
-          iotjs_jargs_append_null(&jargs);
-          iotjs_jval_destroy(&error);
-        } else {
-          iotjs_jargs_append_null(&jargs);
-          iotjs_jargs_append_number(&jargs, req_data->byte);
-        }
-        break;
-      }
-      default: {
-        IOTJS_ASSERT(!"Unreachable");
-        break;
-      }
-    }
-  }
-
-  const iotjs_jval_t* jcallback = iotjs_i2c_reqwrap_jcallback(req_wrap);
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &jargs);
-
-  iotjs_jargs_destroy(&jargs);
-  iotjs_i2c_reqwrap_dispatched(req_wrap);
-}
-
-
-static void GetI2cArray(const iotjs_jval_t* jarray,
-                        iotjs_i2c_reqdata_t* req_data) {
-  // FIXME
-  // Need to implement a function to get array info from iotjs_jval_t Array.
-  iotjs_jval_t jlength =
-      iotjs_jval_get_property(jarray, IOTJS_MAGIC_STRING_LENGTH);
-  IOTJS_ASSERT(!iotjs_jval_is_undefined(&jlength));
-
-  req_data->buf_len = iotjs_jval_as_number(&jlength);
-  req_data->buf_data = iotjs_buffer_allocate(req_data->buf_len);
-
-  for (int i = 0; i < req_data->buf_len; i++) {
-    iotjs_jval_t jdata = iotjs_jval_get_property_by_index(jarray, i);
-    req_data->buf_data[i] = iotjs_jval_as_number(&jdata);
-    iotjs_jval_destroy(&jdata);
-  }
-
-  iotjs_jval_destroy(&jlength);
-}
-
-
-#define I2C_ASYNC(op)                                                  \
-  do {                                                                 \
-    uv_loop_t* loop = iotjs_environment_loop(iotjs_environment_get()); \
-    uv_work_t* req = iotjs_i2c_reqwrap_req(req_wrap);                  \
-    uv_queue_work(loop, req, op##Worker, AfterI2CWork);                \
-  } while (0)
-
-
-JHANDLER_FUNCTION(I2cCons) {
-  JHANDLER_CHECK_THIS(object);
-#if defined(__linux__) || defined(__APPLE__)
-  JHANDLER_CHECK_ARGS(2, string, function);
-  iotjs_string_t device = JHANDLER_GET_ARG(0, string);
-#elif defined(__NUTTX__)
-  JHANDLER_CHECK_ARGS(2, number, function);
-  uint32_t device = JHANDLER_GET_ARG(0, number);
-#endif
-
-  // Create I2C object
-  const iotjs_jval_t* ji2c = JHANDLER_GET_THIS(object);
-  iotjs_i2c_t* i2c = iotjs_i2c_create(ji2c);
-  IOTJS_ASSERT(i2c ==
-               (iotjs_i2c_t*)(iotjs_jval_get_object_native_handle(ji2c)));
-
-  // Create I2C request wrap
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(1, function);
-  iotjs_i2c_reqwrap_t* req_wrap =
-      iotjs_i2c_reqwrap_create(jcallback, ji2c, kI2cOpOpen);
-
-  iotjs_i2c_reqdata_t* req_data = iotjs_i2c_reqwrap_data(req_wrap);
-#if defined(__linux__) || defined(__APPLE__)
-  iotjs_string_append(&req_data->device, iotjs_string_data(&device),
-                      iotjs_string_size(&device));
-#elif defined(__NUTTX__)
-  req_data->device = device;
-#endif
-
-  I2C_ASYNC(Open);
-}
-
-
-JHANDLER_FUNCTION(SetAddress) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, number);
-  iotjs_i2c_t* i2c = iotjs_i2c_instance_from_jval(JHANDLER_GET_THIS(object));
-
-  I2cSetAddress(i2c, JHANDLER_GET_ARG(0, number));
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  iotjs_i2c_t* i2c = iotjs_i2c_instance_from_jval(JHANDLER_GET_THIS(object));
-  I2cClose(i2c);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(Write) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, array, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(1, function);
-  const iotjs_jval_t* ji2c = JHANDLER_GET_THIS(object);
-
-  iotjs_i2c_reqwrap_t* req_wrap =
-      iotjs_i2c_reqwrap_create(jcallback, ji2c, kI2cOpWrite);
-  iotjs_i2c_reqdata_t* req_data = iotjs_i2c_reqwrap_data(req_wrap);
-
-  GetI2cArray(JHANDLER_GET_ARG(0, array), req_data);
-
-  I2C_ASYNC(Write);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(WriteByte) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, number, function);
-
-  uint8_t byte = JHANDLER_GET_ARG(0, number);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(1, function);
-  const iotjs_jval_t* ji2c = JHANDLER_GET_THIS(object);
-
-  iotjs_i2c_reqwrap_t* req_wrap =
-      iotjs_i2c_reqwrap_create(jcallback, ji2c, kI2cOpWriteByte);
-
-  iotjs_i2c_reqdata_t* req_data = iotjs_i2c_reqwrap_data(req_wrap);
-  req_data->byte = byte;
-
-  I2C_ASYNC(WriteByte);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(WriteBlock) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(3, number, array, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(2, function);
-  const iotjs_jval_t* ji2c = JHANDLER_GET_THIS(object);
-
-  iotjs_i2c_reqwrap_t* req_wrap =
-      iotjs_i2c_reqwrap_create(jcallback, ji2c, kI2cOpWriteBlock);
-
-  iotjs_i2c_reqdata_t* req_data = iotjs_i2c_reqwrap_data(req_wrap);
-  req_data->cmd = JHANDLER_GET_ARG(0, number);
-  GetI2cArray(JHANDLER_GET_ARG(1, array), req_data);
-
-  I2C_ASYNC(WriteBlock);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(Read) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, number, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(1, function);
-  const iotjs_jval_t* ji2c = JHANDLER_GET_THIS(object);
-
-  iotjs_i2c_reqwrap_t* req_wrap =
-      iotjs_i2c_reqwrap_create(jcallback, ji2c, kI2cOpRead);
-
-  iotjs_i2c_reqdata_t* req_data = iotjs_i2c_reqwrap_data(req_wrap);
-  req_data->buf_len = JHANDLER_GET_ARG(0, number);
-  req_data->delay = 0;
-
-  I2C_ASYNC(Read);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(ReadByte) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(0, function);
-  const iotjs_jval_t* ji2c = JHANDLER_GET_THIS(object);
-
-  iotjs_i2c_reqwrap_t* req_wrap =
-      iotjs_i2c_reqwrap_create(jcallback, ji2c, kI2cOpReadByte);
-
-  I2C_ASYNC(ReadByte);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(ReadBlock) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(4, number, number, number, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(3, function);
-  const iotjs_jval_t* ji2c = JHANDLER_GET_THIS(object);
-
-  iotjs_i2c_reqwrap_t* req_wrap =
-      iotjs_i2c_reqwrap_create(jcallback, ji2c, kI2cOpReadBlock);
-
-  iotjs_i2c_reqdata_t* req_data = iotjs_i2c_reqwrap_data(req_wrap);
-  req_data->cmd = JHANDLER_GET_ARG(0, number);
-  req_data->buf_len = JHANDLER_GET_ARG(1, number);
-  req_data->delay = JHANDLER_GET_ARG(2, number);
-
-  I2C_ASYNC(ReadBlock);
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-iotjs_jval_t InitI2c() {
-  iotjs_jval_t jI2cCons = iotjs_jval_create_function_with_dispatch(I2cCons);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SETADDRESS, SetAddress);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_CLOSE, Close);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITE, Write);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITEBYTE, WriteByte);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITEBLOCK, WriteBlock);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_READ, Read);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_READBYTE, ReadByte);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_READBLOCK, ReadBlock);
-
-  iotjs_jval_set_property_jval(&jI2cCons, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &prototype);
-
-  iotjs_jval_destroy(&prototype);
-
-  return jI2cCons;
-}
diff --git a/src/module/iotjs_module_i2c.h b/src/module/iotjs_module_i2c.h
deleted file mode 100644 (file)
index 75e48f9..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_I2C_H
-#define IOTJS_MODULE_I2C_H
-
-#include "iotjs_def.h"
-#include "iotjs_objectwrap.h"
-#include "iotjs_reqwrap.h"
-
-#if defined(__NUTTX__)
-#include <nuttx/i2c/i2c_master.h>
-#endif
-
-typedef enum {
-  kI2cOpSetAddress,
-  kI2cOpOpen,
-  kI2cOpClose,
-  kI2cOpWrite,
-  kI2cOpWriteByte,
-  kI2cOpWriteBlock,
-  kI2cOpRead,
-  kI2cOpReadByte,
-  kI2cOpReadBlock,
-} I2cOp;
-
-typedef enum {
-  kI2cErrOk = 0,
-  kI2cErrOpen = -1,
-  kI2cErrRead = -2,
-  kI2cErrReadBlock = -3,
-  kI2cErrWrite = -4,
-} I2cError;
-
-
-typedef struct {
-#if defined(__linux__) || defined(__APPLE__)
-  iotjs_string_t device;
-#elif defined(__NUTTX__)
-  uint32_t device;
-#endif
-  char* buf_data;
-  uint8_t buf_len;
-  uint8_t byte;
-  uint8_t cmd;
-  int32_t delay;
-
-  I2cOp op;
-  I2cError error;
-} iotjs_i2c_reqdata_t;
-
-
-// This I2c class provides interfaces for I2C operation.
-typedef struct {
-#if defined(__NUTTX__)
-  struct i2c_master_s* i2c_master;
-  struct i2c_config_s config;
-#endif
-  iotjs_jobjectwrap_t jobjectwrap;
-} IOTJS_VALIDATED_STRUCT(iotjs_i2c_t);
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_work_t req;
-  iotjs_i2c_reqdata_t req_data;
-  iotjs_i2c_t* i2c_data;
-} IOTJS_VALIDATED_STRUCT(iotjs_i2c_reqwrap_t);
-
-
-iotjs_i2c_t* iotjs_i2c_create(const iotjs_jval_t* ji2c);
-iotjs_i2c_t* iotjs_i2c_instance_from_jval(const iotjs_jval_t* ji2c);
-
-#define THIS iotjs_i2c_reqwrap_t* i2c_reqwrap
-iotjs_i2c_reqwrap_t* iotjs_i2c_reqwrap_create(const iotjs_jval_t* jcallback,
-                                              const iotjs_jval_t* ji2c,
-                                              I2cOp op);
-void iotjs_i2c_reqwrap_dispatched(THIS);
-uv_work_t* iotjs_i2c_reqwrap_req(THIS);
-const iotjs_jval_t* iotjs_i2c_reqwrap_jcallback(THIS);
-iotjs_i2c_reqwrap_t* iotjs_i2c_reqwrap_from_request(uv_work_t* req);
-iotjs_i2c_reqdata_t* iotjs_i2c_reqwrap_data(THIS);
-iotjs_i2c_t* iotjs_i2c_instance_from_reqwrap(THIS);
-#undef THIS
-
-
-void I2cSetAddress(iotjs_i2c_t* i2c, uint8_t address);
-void OpenWorker(uv_work_t* work_req);
-void I2cClose(iotjs_i2c_t* i2c);
-void WriteWorker(uv_work_t* work_req);
-void WriteByteWorker(uv_work_t* work_req);
-void WriteBlockWorker(uv_work_t* work_req);
-void ReadWorker(uv_work_t* work_req);
-void ReadByteWorker(uv_work_t* work_req);
-void ReadBlockWorker(uv_work_t* work_req);
-
-
-#endif /* IOTJS_MODULE_I2C_H */
diff --git a/src/module/iotjs_module_process.c b/src/module/iotjs_module_process.c
deleted file mode 100644 (file)
index 6f30679..0000000
+++ /dev/null
@@ -1,293 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_js.h"
-
-#include <stdlib.h>
-
-
-JHANDLER_FUNCTION(Binding) {
-  JHANDLER_CHECK_ARGS(1, number);
-
-  ModuleKind module_kind = (ModuleKind)JHANDLER_GET_ARG(0, number);
-
-  const iotjs_jval_t* jmodule =
-      iotjs_module_initialize_if_necessary(module_kind);
-
-  iotjs_jhandler_return_jval(jhandler, jmodule);
-}
-
-
-static iotjs_jval_t WrapEval(const char* source, size_t length, bool* throws) {
-  static const char* wrapper[2] = { "(function(exports, require, module) {\n",
-                                    "\n});\n" };
-
-  int len0 = strlen(wrapper[0]);
-  int len1 = strlen(wrapper[1]);
-
-  uint32_t buffer_length = len0 + len1 + length;
-  char* buffer = iotjs_buffer_allocate(buffer_length);
-  memcpy(buffer, wrapper[0], len0);
-  memcpy(buffer + len0, source, length);
-  memcpy(buffer + len0 + length, wrapper[1], len1);
-
-  iotjs_jval_t res = iotjs_jhelper_eval(buffer, buffer_length, false, throws);
-
-  iotjs_buffer_release(buffer);
-
-  return res;
-}
-
-
-JHANDLER_FUNCTION(Compile) {
-  JHANDLER_CHECK_ARGS(1, string);
-
-  iotjs_string_t source = JHANDLER_GET_ARG(0, string);
-
-  bool throws;
-  iotjs_jval_t jres =
-      WrapEval(iotjs_string_data(&source), iotjs_string_size(&source), &throws);
-
-  if (!throws) {
-    iotjs_jhandler_return_jval(jhandler, &jres);
-  } else {
-    iotjs_jhandler_throw(jhandler, &jres);
-  }
-
-  iotjs_string_destroy(&source);
-  iotjs_jval_destroy(&jres);
-}
-
-
-JHANDLER_FUNCTION(CompileNativePtr) {
-  JHANDLER_CHECK_ARGS(1, string);
-
-  iotjs_string_t id = JHANDLER_GET_ARG(0, string);
-
-  int i = 0;
-  while (natives[i].name != NULL) {
-    if (!strcmp(natives[i].name, iotjs_string_data(&id))) {
-      break;
-    }
-
-    i++;
-  }
-
-  iotjs_string_destroy(&id);
-
-  if (natives[i].name != NULL) {
-    bool throws;
-#ifdef ENABLE_SNAPSHOT
-    iotjs_jval_t jres = iotjs_jhelper_exec_snapshot(natives[i].code,
-                                                    natives[i].length, &throws);
-#else
-    iotjs_jval_t jres =
-        WrapEval((const char*)natives[i].code, natives[i].length, &throws);
-#endif
-
-    if (!throws) {
-      iotjs_jhandler_return_jval(jhandler, &jres);
-    } else {
-      iotjs_jhandler_throw(jhandler, &jres);
-    }
-    iotjs_jval_destroy(&jres);
-  } else {
-    iotjs_jval_t jerror = iotjs_jval_create_error("Unknown native module");
-    iotjs_jhandler_throw(jhandler, &jerror);
-    iotjs_jval_destroy(&jerror);
-  }
-}
-
-
-JHANDLER_FUNCTION(ReadSource) {
-  JHANDLER_CHECK_ARGS(1, string);
-
-  iotjs_string_t path = JHANDLER_GET_ARG(0, string);
-  iotjs_string_t code = iotjs_file_read(iotjs_string_data(&path));
-
-  iotjs_jhandler_return_string(jhandler, &code);
-
-  iotjs_string_destroy(&path);
-  iotjs_string_destroy(&code);
-}
-
-
-JHANDLER_FUNCTION(Cwd) {
-  JHANDLER_CHECK_ARGS(0);
-
-  char path[IOTJS_MAX_PATH_SIZE];
-  size_t size_path = sizeof(path);
-  int err = uv_cwd(path, &size_path);
-  if (err) {
-    JHANDLER_THROW(COMMON, "cwd error");
-    return;
-  }
-  iotjs_jhandler_return_string_raw(jhandler, path);
-}
-
-JHANDLER_FUNCTION(Chdir) {
-  JHANDLER_CHECK_ARGS(1, string);
-
-  iotjs_string_t path = JHANDLER_GET_ARG(0, string);
-  int err = uv_chdir(iotjs_string_data(&path));
-
-  if (err) {
-    iotjs_string_destroy(&path);
-    JHANDLER_THROW(COMMON, "chdir error");
-    return;
-  }
-
-  iotjs_string_destroy(&path);
-}
-
-
-JHANDLER_FUNCTION(DoExit) {
-  JHANDLER_CHECK_ARGS(1, number);
-
-  int exit_code = JHANDLER_GET_ARG(0, number);
-
-  exit(exit_code);
-}
-
-
-// Initialize `process.argv`
-JHANDLER_FUNCTION(InitArgv) {
-  JHANDLER_CHECK_THIS(object);
-
-  // environment
-  const iotjs_environment_t* env = iotjs_environment_get();
-
-  // process.argv
-  const iotjs_jval_t* thisObj = JHANDLER_GET_THIS(object);
-  iotjs_jval_t jargv =
-      iotjs_jval_get_property(thisObj, IOTJS_MAGIC_STRING_ARGV);
-
-  int argc = iotjs_environment_argc(env);
-
-  for (int i = 0; i < argc; ++i) {
-    const char* argvi = iotjs_environment_argv(env, i);
-    iotjs_jval_t arg = iotjs_jval_create_string_raw(argvi);
-    iotjs_jval_set_property_by_index(&jargv, i, &arg);
-    iotjs_jval_destroy(&arg);
-  }
-  iotjs_jval_destroy(&jargv);
-}
-
-
-void SetNativeSources(iotjs_jval_t* native_sources) {
-  for (int i = 0; natives[i].name; i++) {
-    iotjs_jval_t native_src = iotjs_jval_create_object();
-    uintptr_t handle = (uintptr_t)(&natives[i]);
-    iotjs_jval_set_object_native_handle(&native_src, handle, NULL);
-    iotjs_jval_set_property_jval(native_sources, natives[i].name, &native_src);
-    iotjs_jval_destroy(&native_src);
-  }
-}
-
-
-static void SetProcessEnv(iotjs_jval_t* process) {
-  const char *homedir, *nodepath, *iotjsenv;
-
-  homedir = getenv("HOME");
-  if (homedir == NULL) {
-    homedir = "";
-  }
-
-  nodepath = getenv("NODE_PATH");
-  if (nodepath == NULL) {
-#if defined(__NUTTX__) || defined(__TIZENRT__)
-    nodepath = "/mnt/sdcard";
-#else
-    nodepath = "";
-#endif
-  }
-
-#if defined(EXPERIMENTAL)
-  iotjsenv = "experimental";
-#else
-  iotjsenv = "";
-#endif
-
-  iotjs_jval_t env = iotjs_jval_create_object();
-  iotjs_jval_set_property_string_raw(&env, IOTJS_MAGIC_STRING_HOME, homedir);
-  iotjs_jval_set_property_string_raw(&env, IOTJS_MAGIC_STRING_NODE_PATH,
-                                     nodepath);
-  iotjs_jval_set_property_string_raw(&env, IOTJS_MAGIC_STRING_ENV, iotjsenv);
-
-  iotjs_jval_set_property_jval(process, IOTJS_MAGIC_STRING_ENV, &env);
-
-  iotjs_jval_destroy(&env);
-}
-
-
-static void SetProcessIotjs(iotjs_jval_t* process) {
-  // IoT.js specific
-  iotjs_jval_t iotjs = iotjs_jval_create_object();
-  iotjs_jval_set_property_jval(process, IOTJS_MAGIC_STRING_IOTJS, &iotjs);
-
-  iotjs_jval_set_property_string_raw(&iotjs, IOTJS_MAGIC_STRING_BOARD,
-                                     TOSTRING(TARGET_BOARD));
-  iotjs_jval_destroy(&iotjs);
-}
-
-
-iotjs_jval_t InitProcess() {
-  iotjs_jval_t process = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&process, IOTJS_MAGIC_STRING_BINDING, Binding);
-  iotjs_jval_set_method(&process, IOTJS_MAGIC_STRING_COMPILE, Compile);
-  iotjs_jval_set_method(&process, IOTJS_MAGIC_STRING_COMPILENATIVEPTR,
-                        CompileNativePtr);
-  iotjs_jval_set_method(&process, IOTJS_MAGIC_STRING_READSOURCE, ReadSource);
-  iotjs_jval_set_method(&process, IOTJS_MAGIC_STRING_CWD, Cwd);
-  iotjs_jval_set_method(&process, IOTJS_MAGIC_STRING_CHDIR, Chdir);
-  iotjs_jval_set_method(&process, IOTJS_MAGIC_STRING_DOEXIT, DoExit);
-  iotjs_jval_set_method(&process, IOTJS_MAGIC_STRING__INITARGV, InitArgv);
-  SetProcessEnv(&process);
-
-  // process.native_sources
-  iotjs_jval_t native_sources = iotjs_jval_create_object();
-  SetNativeSources(&native_sources);
-  iotjs_jval_set_property_jval(&process, IOTJS_MAGIC_STRING_NATIVE_SOURCES,
-                               &native_sources);
-  iotjs_jval_destroy(&native_sources);
-
-  // process.platform
-  iotjs_jval_set_property_string_raw(&process, IOTJS_MAGIC_STRING_PLATFORM,
-                                     TARGET_OS);
-
-  // process.arch
-  iotjs_jval_set_property_string_raw(&process, IOTJS_MAGIC_STRING_ARCH,
-                                     TARGET_ARCH);
-
-  // Set iotjs
-  SetProcessIotjs(&process);
-
-  // Binding module id.
-  iotjs_jval_t jbinding =
-      iotjs_jval_get_property(&process, IOTJS_MAGIC_STRING_BINDING);
-
-#define ENUMDEF_MODULE_LIST(upper, Camel, lower) \
-  iotjs_jval_set_property_number(&jbinding, #lower, MODULE_##upper);
-
-  MAP_MODULE_LIST(ENUMDEF_MODULE_LIST)
-
-#undef ENUMDEF_MODULE_LIST
-
-  iotjs_jval_destroy(&jbinding);
-
-  return process;
-}
diff --git a/src/module/iotjs_module_pwm.c b/src/module/iotjs_module_pwm.c
deleted file mode 100644 (file)
index 67ece49..0000000
+++ /dev/null
@@ -1,378 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module_pwm.h"
-#include "iotjs_objectwrap.h"
-
-
-static void iotjs_pwm_destroy(iotjs_pwm_t* pwm);
-static iotjs_pwm_t* iotjs_pwm_instance_from_jval(const iotjs_jval_t* jpwm);
-
-
-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,
-                               (JFreeHandlerType)iotjs_pwm_destroy);
-
-  _this->period = -1;
-  _this->duty_cycle = 0;
-#if defined(__NUTTX__)
-  _this->device_fd = -1;
-#endif
-  return pwm;
-}
-
-
-static void iotjs_pwm_destroy(iotjs_pwm_t* pwm) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_pwm_t, pwm);
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-#if defined(__linux__)
-  iotjs_string_destroy(&_this->device);
-#endif
-  IOTJS_RELEASE(pwm);
-}
-
-
-#define THIS iotjs_pwm_reqwrap_t* pwm_reqwrap
-
-
-static iotjs_pwm_reqwrap_t* iotjs_pwm_reqwrap_create(
-    const iotjs_jval_t* jcallback, const iotjs_jval_t* jpwm, 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 = iotjs_pwm_instance_from_jval(jpwm);
-  _this->req_data.caller = NULL;
-
-  return pwm_reqwrap;
-}
-
-
-static void iotjs_pwm_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_pwm_reqwrap_t, pwm_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(pwm_reqwrap);
-}
-
-
-static void iotjs_pwm_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_pwm_reqwrap_t, pwm_reqwrap);
-  iotjs_pwm_reqwrap_destroy(pwm_reqwrap);
-}
-
-
-static uv_work_t* iotjs_pwm_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_reqwrap_t, pwm_reqwrap);
-  return &_this->req;
-}
-
-
-static const iotjs_jval_t* iotjs_pwm_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_reqwrap_t, pwm_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-
-static iotjs_pwm_t* iotjs_pwm_instance_from_jval(const iotjs_jval_t* jpwm) {
-  uintptr_t handle = iotjs_jval_get_object_native_handle(jpwm);
-  return (iotjs_pwm_t*)handle;
-}
-
-
-iotjs_pwm_reqwrap_t* iotjs_pwm_reqwrap_from_request(uv_work_t* req) {
-  return (iotjs_pwm_reqwrap_t*)(iotjs_reqwrap_from_request((uv_req_t*)req));
-}
-
-
-iotjs_pwm_reqdata_t* iotjs_pwm_reqwrap_data(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_reqwrap_t, pwm_reqwrap);
-  return &_this->req_data;
-}
-
-
-iotjs_pwm_t* iotjs_pwm_instance_from_reqwrap(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_reqwrap_t, pwm_reqwrap);
-  return _this->pwm_instance;
-}
-
-
-static void iotjs_pwm_set_configuration(const iotjs_jval_t* jconfiguration,
-                                        iotjs_pwm_t* pwm) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_t, pwm);
-
-  iotjs_jval_t jpin =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_PIN);
-  _this->pin = iotjs_jval_as_number(&jpin);
-
-#if defined(__linux__)
-  iotjs_jval_t jchip =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_CHIP);
-  _this->chip = iotjs_jval_as_number(&jchip);
-  iotjs_jval_destroy(&jchip);
-#endif
-
-  iotjs_jval_t jperiod =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_PERIOD);
-  if (iotjs_jval_is_number(&jperiod))
-    _this->period = iotjs_jval_as_number(&jperiod);
-
-  iotjs_jval_t jduty_cycle =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_DUTYCYCLE);
-  if (iotjs_jval_is_number(&jduty_cycle))
-    _this->duty_cycle = iotjs_jval_as_number(&jduty_cycle);
-
-  iotjs_jval_destroy(&jpin);
-  iotjs_jval_destroy(&jperiod);
-  iotjs_jval_destroy(&jduty_cycle);
-}
-
-#undef THIS
-
-
-static void iotjs_pwm_common_worker(uv_work_t* work_req) {
-  PWM_WORKER_INIT;
-
-  IOTJS_ASSERT(req_data->caller != NULL);
-
-  if (!req_data->caller(pwm)) {
-    req_data->result = false;
-    return;
-  }
-
-  req_data->result = true;
-}
-
-
-static void iotjs_pwm_after_worker(uv_work_t* work_req, int status) {
-  iotjs_pwm_reqwrap_t* req_wrap = iotjs_pwm_reqwrap_from_request(work_req);
-  iotjs_pwm_reqdata_t* req_data = iotjs_pwm_reqwrap_data(req_wrap);
-  iotjs_jargs_t jargs = iotjs_jargs_create(1);
-  bool result = req_data->result;
-
-  if (status) {
-    iotjs_jval_t error = iotjs_jval_create_error("System error");
-    iotjs_jargs_append_jval(&jargs, &error);
-    iotjs_jval_destroy(&error);
-  } else {
-    switch (req_data->op) {
-      case kPwmOpOpen:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Failed to open PWM device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      case kPwmOpSetDutyCycle:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Failed to set duty-cycle");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      case kPwmOpSetPeriod:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Failed to set period");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      case kPwmOpSetEnable:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Failed to set enable");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      case kPwmOpClose:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Cannot close PWM device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      default: {
-        IOTJS_ASSERT(!"Unreachable");
-        break;
-      }
-    }
-  }
-
-  const iotjs_jval_t* jcallback = iotjs_pwm_reqwrap_jcallback(req_wrap);
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &jargs);
-
-  iotjs_jargs_destroy(&jargs);
-
-  iotjs_pwm_reqwrap_dispatched(req_wrap);
-}
-
-
-#define PWM_ASYNC(call, jthis, jcallback, op)                          \
-  do {                                                                 \
-    uv_loop_t* loop = iotjs_environment_loop(iotjs_environment_get()); \
-    iotjs_pwm_reqwrap_t* req_wrap =                                    \
-        iotjs_pwm_reqwrap_create(jcallback, jthis, op);                \
-    uv_work_t* req = iotjs_pwm_reqwrap_req(req_wrap);                  \
-    uv_queue_work(loop, req, iotjs_pwm_##call##_worker,                \
-                  iotjs_pwm_after_worker);                             \
-  } while (0)
-
-
-#define PWM_ASYNC_COMMON_WORKER(call, jthis, jcallback, op)                    \
-  do {                                                                         \
-    uv_loop_t* loop = iotjs_environment_loop(iotjs_environment_get());         \
-    iotjs_pwm_reqwrap_t* req_wrap =                                            \
-        iotjs_pwm_reqwrap_create(jcallback, jthis, op);                        \
-    uv_work_t* req = iotjs_pwm_reqwrap_req(req_wrap);                          \
-    iotjs_pwm_reqdata_t* req_data = iotjs_pwm_reqwrap_data(req_wrap);          \
-    req_data->caller = call;                                                   \
-    uv_queue_work(loop, req, iotjs_pwm_common_worker, iotjs_pwm_after_worker); \
-  } while (0)
-
-
-JHANDLER_FUNCTION(PWMConstructor) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, object, function);
-
-  // Create PWM object
-  const iotjs_jval_t* jpwm = JHANDLER_GET_THIS(object);
-  iotjs_pwm_t* pwm = iotjs_pwm_create(jpwm);
-  IOTJS_ASSERT(pwm == iotjs_pwm_instance_from_jval(jpwm));
-
-  const iotjs_jval_t* jconfiguration = JHANDLER_GET_ARG(0, object);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(1, function);
-
-  // Set configuration
-  iotjs_pwm_set_configuration(jconfiguration, pwm);
-
-  PWM_ASYNC(open, jpwm, jcallback, kPwmOpOpen);
-}
-
-
-JHANDLER_FUNCTION(SetPeriod) {
-  JHANDLER_CHECK_ARGS(1, number);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-  const iotjs_jval_t* jpwm = JHANDLER_GET_THIS(object);
-  iotjs_pwm_t* pwm = iotjs_pwm_instance_from_jval(jpwm);
-
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_t, pwm);
-  _this->period = JHANDLER_GET_ARG(0, number);
-
-  if (jcallback) {
-    PWM_ASYNC_COMMON_WORKER(iotjs_pwm_set_period, jpwm, jcallback,
-                            kPwmOpSetPeriod);
-  } else {
-    if (!iotjs_pwm_set_period(pwm)) {
-      JHANDLER_THROW(COMMON, "PWM SetPeriod Error");
-    }
-  }
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(SetDutyCycle) {
-  JHANDLER_CHECK_ARGS(1, number);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-  const iotjs_jval_t* jpwm = JHANDLER_GET_THIS(object);
-  iotjs_pwm_t* pwm = iotjs_pwm_instance_from_jval(jpwm);
-
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_t, pwm);
-  _this->duty_cycle = JHANDLER_GET_ARG(0, number);
-
-  if (jcallback) {
-    PWM_ASYNC_COMMON_WORKER(iotjs_pwm_set_dutycycle, jpwm, jcallback,
-                            kPwmOpSetDutyCycle);
-  } else {
-    if (!iotjs_pwm_set_dutycycle(pwm)) {
-      JHANDLER_THROW(COMMON, "PWM SetDutyCycle Error");
-    }
-  }
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(SetEnable) {
-  JHANDLER_CHECK_ARGS(1, boolean);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-  const iotjs_jval_t* jpwm = JHANDLER_GET_THIS(object);
-  iotjs_pwm_t* pwm = iotjs_pwm_instance_from_jval(jpwm);
-
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_t, pwm);
-  _this->enable = JHANDLER_GET_ARG(0, boolean);
-
-  if (jcallback) {
-    PWM_ASYNC_COMMON_WORKER(iotjs_pwm_set_enable, jpwm, jcallback,
-                            kPwmOpSetEnable);
-  } else {
-    if (!iotjs_pwm_set_enable(pwm)) {
-      JHANDLER_THROW(COMMON, "PWM SetEnabe Error");
-    }
-  }
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARG_IF_EXIST(0, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(0, function);
-  const iotjs_jval_t* jpwm = JHANDLER_GET_THIS(object);
-  iotjs_pwm_t* pwm = iotjs_pwm_instance_from_jval(jpwm);
-
-  if (jcallback) {
-    PWM_ASYNC_COMMON_WORKER(iotjs_pwm_close, jpwm, jcallback, kPwmOpClose);
-  } else {
-    if (!iotjs_pwm_close(pwm)) {
-      JHANDLER_THROW(COMMON, "PWM Close Error");
-    }
-  }
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-iotjs_jval_t InitPwm() {
-  iotjs_jval_t jpwm_constructor =
-      iotjs_jval_create_function_with_dispatch(PWMConstructor);
-
-  iotjs_jval_t jprototype = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_SETPERIOD, SetPeriod);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_SETDUTYCYCLE,
-                        SetDutyCycle);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_SETENABLE, SetEnable);
-  iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_CLOSE, Close);
-
-  iotjs_jval_set_property_jval(&jpwm_constructor, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &jprototype);
-
-  iotjs_jval_destroy(&jprototype);
-
-  return jpwm_constructor;
-}
diff --git a/src/module/iotjs_module_pwm.h b/src/module/iotjs_module_pwm.h
deleted file mode 100644 (file)
index 0f9a9bf..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_PWM_H
-#define IOTJS_MODULE_PWM_H
-
-#include "iotjs_def.h"
-#include "iotjs_objectwrap.h"
-#include "iotjs_reqwrap.h"
-
-
-typedef enum {
-  kPwmOpOpen,
-  kPwmOpSetDutyCycle,
-  kPwmOpSetPeriod,
-  kPwmOpSetFrequency,
-  kPwmOpSetEnable,
-  kPwmOpClose,
-} PwmOp;
-
-
-typedef struct {
-  iotjs_jobjectwrap_t jobjectwrap;
-
-#if defined(__linux__)
-  int chip;
-  iotjs_string_t device;
-#elif defined(__NUTTX__)
-  int device_fd;
-#endif
-  int pin;
-  double duty_cycle;
-  double period;
-  bool enable;
-} IOTJS_VALIDATED_STRUCT(iotjs_pwm_t);
-
-
-typedef bool (*pwm_func_ptr)(iotjs_pwm_t*);
-
-
-typedef struct {
-  pwm_func_ptr caller;
-  bool result;
-  PwmOp op;
-} iotjs_pwm_reqdata_t;
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_work_t req;
-  iotjs_pwm_reqdata_t req_data;
-  iotjs_pwm_t* pwm_instance;
-} IOTJS_VALIDATED_STRUCT(iotjs_pwm_reqwrap_t);
-
-
-#define THIS iotjs_pwm_reqwrap_t* pwm_reqwrap
-
-iotjs_pwm_reqwrap_t* iotjs_pwm_reqwrap_from_request(uv_work_t* req);
-iotjs_pwm_reqdata_t* iotjs_pwm_reqwrap_data(THIS);
-
-iotjs_pwm_t* iotjs_pwm_instance_from_reqwrap(THIS);
-
-#undef THIS
-
-
-#define PWM_WORKER_INIT                                                     \
-  iotjs_pwm_reqwrap_t* req_wrap = iotjs_pwm_reqwrap_from_request(work_req); \
-  iotjs_pwm_reqdata_t* req_data = iotjs_pwm_reqwrap_data(req_wrap);         \
-  iotjs_pwm_t* pwm = iotjs_pwm_instance_from_reqwrap(req_wrap);
-
-
-void iotjs_pwm_open_worker(uv_work_t* work_req);
-
-bool iotjs_pwm_set_period(iotjs_pwm_t* pwm);
-bool iotjs_pwm_set_dutycycle(iotjs_pwm_t* pwm);
-bool iotjs_pwm_set_enable(iotjs_pwm_t* pwm);
-bool iotjs_pwm_close(iotjs_pwm_t* pwm);
-
-
-#endif /* IOTJS_MODULE_PWM_H */
diff --git a/src/module/iotjs_module_spi.c b/src/module/iotjs_module_spi.c
deleted file mode 100644 (file)
index ef829d4..0000000
+++ /dev/null
@@ -1,465 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module_spi.h"
-#include "iotjs_module_buffer.h"
-#include "iotjs_objectwrap.h"
-#include <unistd.h>
-
-
-/*
- * SPI instance function
- */
-static void iotjs_spi_destroy(iotjs_spi_t* spi);
-static iotjs_spi_t* iotjs_spi_instance_from_jval(const iotjs_jval_t* jspi);
-
-
-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,
-                               (JFreeHandlerType)iotjs_spi_destroy);
-
-  _this->device = iotjs_string_create("");
-
-  return spi;
-}
-
-
-static void iotjs_spi_destroy(iotjs_spi_t* spi) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_spi_t, spi);
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-  iotjs_string_destroy(&_this->device);
-  IOTJS_RELEASE(spi);
-}
-
-
-#define THIS iotjs_spi_reqwrap_t* spi_reqwrap
-
-
-static iotjs_spi_reqwrap_t* iotjs_spi_reqwrap_create(
-    const iotjs_jval_t* jcallback, const iotjs_jval_t* jspi, 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 = iotjs_spi_instance_from_jval(jspi);
-
-  return spi_reqwrap;
-}
-
-
-static void iotjs_spi_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_spi_reqwrap_t, spi_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(spi_reqwrap);
-}
-
-
-static void iotjs_spi_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_spi_reqwrap_t, spi_reqwrap);
-  iotjs_spi_reqwrap_destroy(spi_reqwrap);
-}
-
-
-static uv_work_t* iotjs_spi_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_reqwrap_t, spi_reqwrap);
-  return &_this->req;
-}
-
-
-static const iotjs_jval_t* iotjs_spi_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_reqwrap_t, spi_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-
-static iotjs_spi_t* iotjs_spi_instance_from_jval(const iotjs_jval_t* jspi) {
-  uintptr_t handle = iotjs_jval_get_object_native_handle(jspi);
-  return (iotjs_spi_t*)handle;
-}
-
-
-iotjs_spi_reqwrap_t* iotjs_spi_reqwrap_from_request(uv_work_t* req) {
-  return (iotjs_spi_reqwrap_t*)(iotjs_reqwrap_from_request((uv_req_t*)req));
-}
-
-
-iotjs_spi_reqdata_t* iotjs_spi_reqwrap_data(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_reqwrap_t, spi_reqwrap);
-  return &_this->req_data;
-}
-
-
-iotjs_spi_t* iotjs_spi_instance_from_reqwrap(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_reqwrap_t, spi_reqwrap);
-  return _this->spi_instance;
-}
-
-
-#undef THIS
-
-
-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));
-
-  int length = iotjs_jval_as_number(&jlength);
-  *buf = iotjs_buffer_allocate(length);
-
-  for (int 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 length;
-}
-
-
-static void iotjs_spi_set_array_buffer(iotjs_spi_t* spi,
-                                       const iotjs_jval_t* jtx_buf,
-                                       const iotjs_jval_t* jrx_buf) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_t, spi);
-
-  int tx_buf_len = iotjs_spi_get_array_data(&_this->tx_buf_data, jtx_buf);
-  int rx_buf_len = iotjs_spi_get_array_data(&_this->rx_buf_data, jrx_buf);
-
-  IOTJS_ASSERT(_this->tx_buf_data != NULL && _this->rx_buf_data != NULL);
-  IOTJS_ASSERT(tx_buf_len > 0 && rx_buf_len > 0 && tx_buf_len == rx_buf_len);
-
-  _this->buf_len = tx_buf_len;
-}
-
-
-static void iotjs_spi_set_buffer(iotjs_spi_t* spi, const iotjs_jval_t* jtx_buf,
-                                 const iotjs_jval_t* jrx_buf) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_t, spi);
-
-  iotjs_bufferwrap_t* tx_buf = iotjs_bufferwrap_from_jbuffer(jtx_buf);
-  iotjs_bufferwrap_t* rx_buf = iotjs_bufferwrap_from_jbuffer(jrx_buf);
-
-  _this->tx_buf_data = iotjs_bufferwrap_buffer(tx_buf);
-  uint8_t tx_buf_len = iotjs_bufferwrap_length(tx_buf);
-  _this->rx_buf_data = iotjs_bufferwrap_buffer(rx_buf);
-  uint8_t rx_buf_len = iotjs_bufferwrap_length(rx_buf);
-
-  IOTJS_ASSERT(_this->tx_buf_data != NULL && _this->rx_buf_data != NULL);
-  IOTJS_ASSERT(tx_buf_len > 0 && rx_buf_len > 0 && tx_buf_len == rx_buf_len);
-
-  _this->buf_len = tx_buf_len;
-}
-
-
-static void iotjs_spi_release_buffer(iotjs_spi_t* spi) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_t, spi);
-
-  iotjs_buffer_release(_this->tx_buf_data);
-  iotjs_buffer_release(_this->rx_buf_data);
-}
-
-
-static void iotjs_spi_set_configuration(iotjs_spi_t* spi,
-                                        const iotjs_jval_t* joptions) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_t, spi);
-
-  iotjs_jval_t jdevice =
-      iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_DEVICE);
-  _this->device = iotjs_jval_as_string(&jdevice);
-  iotjs_jval_destroy(&jdevice);
-
-  iotjs_jval_t jmode =
-      iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_MODE);
-  _this->mode = (SpiMode)iotjs_jval_as_number(&jmode);
-  iotjs_jval_destroy(&jmode);
-
-  iotjs_jval_t jchip_select =
-      iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_CHIPSELECT);
-  _this->chip_select = (SpiChipSelect)iotjs_jval_as_number(&jchip_select);
-  iotjs_jval_destroy(&jchip_select);
-
-  iotjs_jval_t jmax_speed =
-      iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_MAXSPEED);
-  _this->max_speed = iotjs_jval_as_number(&jmax_speed);
-  iotjs_jval_destroy(&jmax_speed);
-
-  iotjs_jval_t jbits_per_word =
-      iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_BITSPERWORD);
-  _this->bits_per_word = (SpiOrder)iotjs_jval_as_number(&jbits_per_word);
-  iotjs_jval_destroy(&jbits_per_word);
-
-  iotjs_jval_t jbit_order =
-      iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_BITORDER);
-  _this->bit_order = (SpiOrder)iotjs_jval_as_number(&jbit_order);
-  iotjs_jval_destroy(&jbit_order);
-
-  iotjs_jval_t jloopback =
-      iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_LOOPBACK);
-  _this->loopback = iotjs_jval_as_boolean(&jloopback);
-  iotjs_jval_destroy(&jloopback);
-}
-
-
-/*
- * SPI worker function
- */
-static void iotjs_spi_transfer_worker(uv_work_t* work_req) {
-  SPI_WORKER_INIT;
-
-  if (!iotjs_spi_transfer(spi)) {
-    req_data->result = false;
-    return;
-  }
-
-  req_data->result = true;
-}
-
-
-static void iotjs_spi_close_worker(uv_work_t* work_req) {
-  SPI_WORKER_INIT;
-
-  if (!iotjs_spi_close(spi)) {
-    req_data->result = false;
-    return;
-  }
-
-  req_data->result = true;
-}
-
-
-static void iotjs_spi_after_work(uv_work_t* work_req, int status) {
-  iotjs_spi_reqwrap_t* req_wrap = iotjs_spi_reqwrap_from_request(work_req);
-  iotjs_spi_reqdata_t* req_data = iotjs_spi_reqwrap_data(req_wrap);
-  iotjs_spi_t* spi = iotjs_spi_instance_from_reqwrap(req_wrap);
-
-  iotjs_jargs_t jargs = iotjs_jargs_create(2);
-
-  bool result = req_data->result;
-
-  if (status) {
-    iotjs_jargs_append_error(&jargs, "System error");
-  } else {
-    switch (req_data->op) {
-      case kSpiOpOpen:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Failed to export SPI device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      case kSpiOpTransfer:
-
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Cannot transfer from SPI device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-
-          IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_t, spi);
-
-          // Append read data
-          iotjs_jval_t result_data =
-              iotjs_jval_create_byte_array(_this->buf_len, _this->rx_buf_data);
-          iotjs_jargs_append_jval(&jargs, &result_data);
-          iotjs_jval_destroy(&result_data);
-        }
-        iotjs_spi_release_buffer(spi);
-        break;
-      case kSpiOpClose:
-        if (!result) {
-          iotjs_jargs_append_error(&jargs, "Failed to unexport SPI device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      default: {
-        IOTJS_ASSERT(!"Unreachable");
-        break;
-      }
-    }
-  }
-
-  const iotjs_jval_t* jcallback = iotjs_spi_reqwrap_jcallback(req_wrap);
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &jargs);
-
-  iotjs_jargs_destroy(&jargs);
-
-  iotjs_spi_reqwrap_dispatched(req_wrap);
-}
-
-
-iotjs_spi_t* iotjs_spi_get_instance(const iotjs_jval_t* jspi) {
-  uintptr_t handle = iotjs_jval_get_object_native_handle(jspi);
-  return (iotjs_spi_t*)(handle);
-}
-
-
-#define SPI_ASYNC(call, jthis, jcallback, op)                                  \
-  do {                                                                         \
-    uv_loop_t* loop = iotjs_environment_loop(iotjs_environment_get());         \
-    iotjs_spi_reqwrap_t* req_wrap =                                            \
-        iotjs_spi_reqwrap_create(jcallback, jthis, op);                        \
-    uv_work_t* req = iotjs_spi_reqwrap_req(req_wrap);                          \
-    uv_queue_work(loop, req, iotjs_spi_##call##_worker, iotjs_spi_after_work); \
-  } while (0)
-
-
-JHANDLER_FUNCTION(SpiConstructor) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, object, function);
-
-  // Create SPI object
-  const iotjs_jval_t* jspi = JHANDLER_GET_THIS(object);
-  iotjs_spi_t* spi = iotjs_spi_create(jspi);
-  IOTJS_ASSERT(spi == iotjs_spi_get_instance(jspi));
-
-  // Set configuration
-  const iotjs_jval_t* jconfiguration = JHANDLER_GET_ARG(0, object);
-  iotjs_spi_set_configuration(spi, jconfiguration);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(1, function);
-  SPI_ASYNC(open, jspi, jcallback, kSpiOpOpen);
-}
-
-
-// FIXME: do not need transferArray if array buffer is implemented.
-JHANDLER_FUNCTION(TransferArray) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, array, array);
-  JHANDLER_CHECK_ARG_IF_EXIST(2, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(2, function);
-  const iotjs_jval_t* jspi = JHANDLER_GET_THIS(object);
-  iotjs_spi_t* spi = iotjs_spi_get_instance(jspi);
-
-  iotjs_spi_set_array_buffer(spi, JHANDLER_GET_ARG(0, array),
-                             JHANDLER_GET_ARG(1, array));
-
-  if (jcallback) {
-    SPI_ASYNC(transfer, jspi, jcallback, kSpiOpTransfer);
-  } else {
-    if (!iotjs_spi_transfer(spi)) {
-      JHANDLER_THROW(COMMON, "SPI Transfer Error");
-    } else {
-      IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_t, spi);
-
-      iotjs_jval_t result =
-          iotjs_jval_create_byte_array(_this->buf_len, _this->rx_buf_data);
-      iotjs_jhandler_return_jval(jhandler, &result);
-      iotjs_jval_destroy(&result);
-    }
-  }
-}
-
-
-JHANDLER_FUNCTION(TransferBuffer) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, object, object);
-  JHANDLER_CHECK_ARG_IF_EXIST(2, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(2, function);
-  const iotjs_jval_t* jspi = JHANDLER_GET_THIS(object);
-  iotjs_spi_t* spi = iotjs_spi_get_instance(jspi);
-
-  iotjs_spi_set_buffer(spi, JHANDLER_GET_ARG(0, object),
-                       JHANDLER_GET_ARG(1, object));
-
-  if (jcallback) {
-    SPI_ASYNC(transfer, jspi, jcallback, kSpiOpTransfer);
-  } else {
-    if (!iotjs_spi_transfer(spi)) {
-      JHANDLER_THROW(COMMON, "SPI Transfer Error");
-    } else {
-      IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_t, spi);
-
-      iotjs_jval_t result =
-          iotjs_jval_create_byte_array(_this->buf_len, _this->rx_buf_data);
-      iotjs_jhandler_return_jval(jhandler, &result);
-      iotjs_jval_destroy(&result);
-    }
-  }
-}
-
-
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARG_IF_EXIST(0, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(0, function);
-  const iotjs_jval_t* jspi = JHANDLER_GET_THIS(object);
-  iotjs_spi_t* spi = iotjs_spi_get_instance(jspi);
-
-  if (jcallback) {
-    SPI_ASYNC(close, jspi, jcallback, kSpiOpClose);
-  } else {
-    if (!iotjs_spi_close(spi)) {
-      JHANDLER_THROW(COMMON, "SPI Close Error");
-    }
-  }
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-iotjs_jval_t InitSpi() {
-  iotjs_jval_t jspi = iotjs_jval_create_object();
-  iotjs_jval_t jspiConstructor =
-      iotjs_jval_create_function_with_dispatch(SpiConstructor);
-  iotjs_jval_set_property_jval(&jspi, IOTJS_MAGIC_STRING_SPI, &jspiConstructor);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_TRANSFERARRAY,
-                        TransferArray);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_TRANSFERBUFFER,
-                        TransferBuffer);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_CLOSE, Close);
-  iotjs_jval_set_property_jval(&jspiConstructor, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &prototype);
-  iotjs_jval_destroy(&prototype);
-  iotjs_jval_destroy(&jspiConstructor);
-
-  // SPI mode properties
-  iotjs_jval_t jmode = iotjs_jval_create_object();
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_0, kSpiMode_0);
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_1, kSpiMode_1);
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_2, kSpiMode_2);
-  iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_3, kSpiMode_3);
-  iotjs_jval_set_property_jval(&jspi, IOTJS_MAGIC_STRING_MODE_U, &jmode);
-  iotjs_jval_destroy(&jmode);
-
-  // SPI mode properties
-  iotjs_jval_t jcs = iotjs_jval_create_object();
-  iotjs_jval_set_property_number(&jcs, IOTJS_MAGIC_STRING_NONE, kSpiCsNone);
-  iotjs_jval_set_property_number(&jcs, IOTJS_MAGIC_STRING_HIGH, kSpiCsHigh);
-  iotjs_jval_set_property_jval(&jspi, IOTJS_MAGIC_STRING_CHIPSELECT_U, &jcs);
-  iotjs_jval_destroy(&jcs);
-
-  // SPI order properties
-  iotjs_jval_t jbit_order = iotjs_jval_create_object();
-  iotjs_jval_set_property_number(&jbit_order, IOTJS_MAGIC_STRING_MSB,
-                                 kSpiOrderMsb);
-  iotjs_jval_set_property_number(&jbit_order, IOTJS_MAGIC_STRING_LSB,
-                                 kSpiOrderLsb);
-  iotjs_jval_set_property_jval(&jspi, IOTJS_MAGIC_STRING_BITORDER_U,
-                               &jbit_order);
-  iotjs_jval_destroy(&jbit_order);
-
-  return jspi;
-}
diff --git a/src/module/iotjs_module_spi.h b/src/module/iotjs_module_spi.h
deleted file mode 100644 (file)
index b4349f3..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_SPI_H
-#define IOTJS_MODULE_SPI_H
-
-#include "iotjs_def.h"
-#include "iotjs_module_buffer.h"
-#include "iotjs_objectwrap.h"
-#include "iotjs_reqwrap.h"
-
-
-typedef enum {
-  kSpiOpOpen,
-  kSpiOpTransfer,
-  kSpiOpClose,
-} SpiOp;
-
-typedef enum {
-  kSpiMode_0,
-  kSpiMode_1,
-  kSpiMode_2,
-  kSpiMode_3,
-} SpiMode;
-
-typedef enum {
-  kSpiCsNone,
-  kSpiCsHigh,
-} SpiChipSelect;
-
-typedef enum { kSpiOrderMsb, kSpiOrderLsb } SpiOrder;
-
-
-typedef struct {
-  iotjs_jobjectwrap_t jobjectwrap;
-  iotjs_string_t device;
-  int32_t device_fd;
-
-  SpiMode mode;
-  SpiChipSelect chip_select;
-  SpiOrder bit_order;
-  uint8_t bits_per_word;
-  uint16_t delay;
-  uint32_t max_speed;
-  bool loopback;
-
-  // SPI buffer
-  char* tx_buf_data;
-  char* rx_buf_data;
-  uint8_t buf_len;
-
-} IOTJS_VALIDATED_STRUCT(iotjs_spi_t);
-
-
-typedef struct {
-  bool result;
-  SpiOp op;
-} iotjs_spi_reqdata_t;
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_work_t req;
-  iotjs_spi_reqdata_t req_data;
-  iotjs_spi_t* spi_instance;
-} IOTJS_VALIDATED_STRUCT(iotjs_spi_reqwrap_t);
-
-
-#define THIS iotjs_spi_reqwrap_t* spi_reqwrap
-
-iotjs_spi_reqwrap_t* iotjs_spi_reqwrap_from_request(uv_work_t* req);
-iotjs_spi_reqdata_t* iotjs_spi_reqwrap_data(THIS);
-
-iotjs_spi_t* iotjs_spi_instance_from_reqwrap(THIS);
-
-#undef THIS
-
-
-#define SPI_WORKER_INIT                                                     \
-  iotjs_spi_reqwrap_t* req_wrap = iotjs_spi_reqwrap_from_request(work_req); \
-  iotjs_spi_reqdata_t* req_data = iotjs_spi_reqwrap_data(req_wrap);         \
-  iotjs_spi_t* spi = iotjs_spi_instance_from_reqwrap(req_wrap);
-
-
-bool iotjs_spi_transfer(iotjs_spi_t* spi);
-bool iotjs_spi_close(iotjs_spi_t* spi);
-
-void iotjs_spi_open_worker(uv_work_t* work_req);
-
-
-#endif /* IOTJS_MODULE_SPI_H */
diff --git a/src/module/iotjs_module_stm32f4dis.c b/src/module/iotjs_module_stm32f4dis.c
deleted file mode 100644 (file)
index 672a504..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module_stm32f4dis.h"
-
-
-iotjs_jval_t InitStm32f4dis() {
-  iotjs_jval_t stm32f4dis = iotjs_jval_create_object();
-
-#if defined(__NUTTX__)
-
-  iotjs_stm32f4dis_pin_initialize(&stm32f4dis);
-
-#endif
-
-  return stm32f4dis;
-}
diff --git a/src/module/iotjs_module_stm32f4dis.h b/src/module/iotjs_module_stm32f4dis.h
deleted file mode 100644 (file)
index f14d608..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IOTJS_MODULE_STM32F4DIS_H
-#define IOTJS_MODULE_STM32F4DIS_H
-
-
-void iotjs_stm32f4dis_pin_initialize(const iotjs_jval_t* jobj);
-
-
-#endif /* IOTJS_MODULE_STM32F4DIS_H */
diff --git a/src/module/iotjs_module_tcp.c b/src/module/iotjs_module_tcp.c
deleted file mode 100644 (file)
index 02b37dc..0000000
+++ /dev/null
@@ -1,674 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "iotjs_def.h"
-#include "iotjs_module_tcp.h"
-
-#include "iotjs_handlewrap.h"
-#include "iotjs_module_buffer.h"
-#include "iotjs_reqwrap.h"
-
-
-static void iotjs_tcpwrap_destroy(iotjs_tcpwrap_t* tcpwrap);
-
-
-iotjs_tcpwrap_t* iotjs_tcpwrap_create(const iotjs_jval_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),
-                              (JFreeHandlerType)iotjs_tcpwrap_destroy);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-  uv_tcp_init(iotjs_environment_loop(env), &_this->handle);
-
-  return tcpwrap;
-}
-
-
-static void iotjs_tcpwrap_destroy(iotjs_tcpwrap_t* tcpwrap) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_tcpwrap_t, tcpwrap);
-  iotjs_handlewrap_destroy(&_this->handlewrap);
-  IOTJS_RELEASE(tcpwrap);
-}
-
-
-iotjs_tcpwrap_t* iotjs_tcpwrap_from_handle(uv_tcp_t* tcp_handle) {
-  uv_handle_t* handle = (uv_handle_t*)(tcp_handle);
-  iotjs_handlewrap_t* handlewrap = iotjs_handlewrap_from_handle(handle);
-  iotjs_tcpwrap_t* tcpwrap = (iotjs_tcpwrap_t*)handlewrap;
-  IOTJS_ASSERT(iotjs_tcpwrap_tcp_handle(tcpwrap) == tcp_handle);
-  return tcpwrap;
-}
-
-
-iotjs_tcpwrap_t* iotjs_tcpwrap_from_jobject(const iotjs_jval_t* jtcp) {
-  iotjs_handlewrap_t* handlewrap = iotjs_handlewrap_from_jobject(jtcp);
-  return (iotjs_tcpwrap_t*)handlewrap;
-}
-
-
-uv_tcp_t* iotjs_tcpwrap_tcp_handle(iotjs_tcpwrap_t* tcpwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_tcpwrap_t, tcpwrap);
-  uv_handle_t* handle = iotjs_handlewrap_get_uv_handle(&_this->handlewrap);
-  return (uv_tcp_t*)handle;
-}
-
-
-iotjs_jval_t* iotjs_tcpwrap_jobject(iotjs_tcpwrap_t* tcpwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_tcpwrap_t, tcpwrap);
-  return iotjs_handlewrap_jobject(&_this->handlewrap);
-}
-
-
-#define THIS iotjs_connect_reqwrap_t* connect_reqwrap
-
-
-static void iotjs_connect_reqwrap_destroy(THIS);
-
-
-iotjs_connect_reqwrap_t* iotjs_connect_reqwrap_create(
-    const iotjs_jval_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;
-}
-
-
-static void iotjs_connect_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_connect_reqwrap_t, connect_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(connect_reqwrap);
-}
-
-
-void iotjs_connect_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_connect_reqwrap_t,
-                                           connect_reqwrap);
-  iotjs_connect_reqwrap_destroy(connect_reqwrap);
-}
-
-
-uv_connect_t* iotjs_connect_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_connect_reqwrap_t, connect_reqwrap);
-  return &_this->req;
-}
-
-
-const iotjs_jval_t* iotjs_connect_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_connect_reqwrap_t, connect_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-#undef THIS
-
-
-#define THIS iotjs_write_reqwrap_t* write_reqwrap
-
-
-static void iotjs_write_reqwrap_destroy(THIS);
-
-
-iotjs_write_reqwrap_t* iotjs_write_reqwrap_create(
-    const iotjs_jval_t* jcallback) {
-  iotjs_write_reqwrap_t* write_reqwrap = IOTJS_ALLOC(iotjs_write_reqwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_write_reqwrap_t, write_reqwrap);
-  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
-  return write_reqwrap;
-}
-
-
-static void iotjs_write_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_write_reqwrap_t, write_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(write_reqwrap);
-}
-
-
-void iotjs_write_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_write_reqwrap_t,
-                                           write_reqwrap);
-  iotjs_write_reqwrap_destroy(write_reqwrap);
-}
-
-
-uv_write_t* iotjs_write_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_write_reqwrap_t, write_reqwrap);
-  return &_this->req;
-}
-
-
-const iotjs_jval_t* iotjs_write_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_write_reqwrap_t, write_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-#undef THIS
-
-
-#define THIS iotjs_shutdown_reqwrap_t* shutdown_reqwrap
-
-
-static void iotjs_shutdown_reqwrap_destroy(THIS);
-
-
-iotjs_shutdown_reqwrap_t* iotjs_shutdown_reqwrap_create(
-    const iotjs_jval_t* jcallback) {
-  iotjs_shutdown_reqwrap_t* shutdown_reqwrap =
-      IOTJS_ALLOC(iotjs_shutdown_reqwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_shutdown_reqwrap_t,
-                                     shutdown_reqwrap);
-  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
-  return shutdown_reqwrap;
-}
-
-
-static void iotjs_shutdown_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_shutdown_reqwrap_t, shutdown_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(shutdown_reqwrap);
-}
-
-
-void iotjs_shutdown_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_shutdown_reqwrap_t,
-                                           shutdown_reqwrap);
-  iotjs_shutdown_reqwrap_destroy(shutdown_reqwrap);
-}
-
-
-uv_shutdown_t* iotjs_shutdown_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_shutdown_reqwrap_t, shutdown_reqwrap);
-  return &_this->req;
-}
-
-
-const iotjs_jval_t* iotjs_shutdown_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_shutdown_reqwrap_t, shutdown_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-#undef THIS
-
-
-JHANDLER_FUNCTION(TCP) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_create(jtcp);
-  IOTJS_UNUSED(tcp_wrap);
-}
-
-
-JHANDLER_FUNCTION(Open) {
-}
-
-
-// Socket close result handler.
-void AfterClose(uv_handle_t* handle) {
-  iotjs_handlewrap_t* wrap = iotjs_handlewrap_from_handle(handle);
-
-  // tcp object.
-  const iotjs_jval_t* jtcp = iotjs_handlewrap_jobject(wrap);
-
-  // callback function.
-  iotjs_jval_t jcallback =
-      iotjs_jval_get_property(jtcp, IOTJS_MAGIC_STRING_ONCLOSE);
-  if (iotjs_jval_is_function(&jcallback)) {
-    iotjs_make_callback(&jcallback, iotjs_jval_get_undefined(),
-                        iotjs_jargs_get_empty());
-  }
-  iotjs_jval_destroy(&jcallback);
-}
-
-
-// Close socket
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  iotjs_handlewrap_t* wrap = iotjs_handlewrap_from_jobject(jtcp);
-
-  // close uv handle, `AfterClose` will be called after socket closed.
-  iotjs_handlewrap_close(wrap, AfterClose);
-}
-
-
-// Socket binding, this function would be called from server socket before
-// start listening.
-// [0] address
-// [1] port
-JHANDLER_FUNCTION(Bind) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, string, number);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  iotjs_string_t address = JHANDLER_GET_ARG(0, string);
-  int port = JHANDLER_GET_ARG(1, number);
-
-  sockaddr_in addr;
-  int err = uv_ip4_addr(iotjs_string_data(&address), port, &addr);
-
-  if (err == 0) {
-    iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_jobject(jtcp);
-    err = uv_tcp_bind(iotjs_tcpwrap_tcp_handle(tcp_wrap),
-                      (const sockaddr*)(&addr), 0);
-  }
-
-  iotjs_jhandler_return_number(jhandler, err);
-
-  iotjs_string_destroy(&address);
-}
-
-
-// Connection request result handler.
-static void AfterConnect(uv_connect_t* req, int status) {
-  iotjs_connect_reqwrap_t* req_wrap = (iotjs_connect_reqwrap_t*)(req->data);
-  IOTJS_ASSERT(req_wrap != NULL);
-
-  // Take callback function object.
-  // function afterConnect(status)
-  const iotjs_jval_t* jcallback = iotjs_connect_reqwrap_jcallback(req_wrap);
-  IOTJS_ASSERT(iotjs_jval_is_function(jcallback));
-
-  // Only parameter is status code.
-  iotjs_jargs_t args = iotjs_jargs_create(1);
-  iotjs_jargs_append_number(&args, status);
-
-  // Make callback.
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &args);
-
-  // Destroy args
-  iotjs_jargs_destroy(&args);
-
-  // Release request wrapper.
-  iotjs_connect_reqwrap_dispatched(req_wrap);
-}
-
-
-// Create a connection using the socket.
-// [0] address
-// [1] port
-// [2] callback
-JHANDLER_FUNCTION(Connect) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(3, string, number, function);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  iotjs_string_t address = JHANDLER_GET_ARG(0, string);
-  int port = JHANDLER_GET_ARG(1, number);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(2, function);
-
-  sockaddr_in addr;
-  int err = uv_ip4_addr(iotjs_string_data(&address), port, &addr);
-
-  if (err == 0) {
-    // Get tcp wrapper from javascript socket object.
-    iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_jobject(jtcp);
-
-    // Create connection request wrapper.
-    iotjs_connect_reqwrap_t* req_wrap = iotjs_connect_reqwrap_create(jcallback);
-
-    // Create connection request.
-    err = uv_tcp_connect(iotjs_connect_reqwrap_req(req_wrap),
-                         iotjs_tcpwrap_tcp_handle(tcp_wrap),
-                         (const sockaddr*)(&addr), AfterConnect);
-
-    if (err) {
-      iotjs_connect_reqwrap_dispatched(req_wrap);
-    }
-  }
-
-  iotjs_jhandler_return_number(jhandler, err);
-
-  iotjs_string_destroy(&address);
-}
-
-
-// A client socket wants to connect to this server.
-// Parameters:
-//   * uv_stream_t* handle - server handle
-//   * int status - status code
-static void OnConnection(uv_stream_t* handle, int status) {
-  // Server tcp wrapper.
-  iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_handle((uv_tcp_t*)handle);
-
-  // Tcp object
-  const iotjs_jval_t* jtcp = iotjs_tcpwrap_jobject(tcp_wrap);
-
-  // `onconnection` callback.
-  iotjs_jval_t jonconnection =
-      iotjs_jval_get_property(jtcp, IOTJS_MAGIC_STRING_ONCONNECTION);
-  IOTJS_ASSERT(iotjs_jval_is_function(&jonconnection));
-
-  // The callback takes two parameter
-  // [0] status
-  // [1] client tcp object
-  iotjs_jargs_t args = iotjs_jargs_create(2);
-  iotjs_jargs_append_number(&args, status);
-
-  if (status == 0) {
-    // Create client socket handle wrapper.
-    iotjs_jval_t jcreate_tcp =
-        iotjs_jval_get_property(jtcp, IOTJS_MAGIC_STRING_CREATETCP);
-    IOTJS_ASSERT(iotjs_jval_is_function(&jcreate_tcp));
-
-    iotjs_jval_t jclient_tcp =
-        iotjs_jhelper_call_ok(&jcreate_tcp, iotjs_jval_get_undefined(),
-                              iotjs_jargs_get_empty());
-    IOTJS_ASSERT(iotjs_jval_is_object(&jclient_tcp));
-
-    iotjs_tcpwrap_t* tcp_wrap_client =
-        (iotjs_tcpwrap_t*)(iotjs_jval_get_object_native_handle(&jclient_tcp));
-
-    uv_stream_t* client_handle =
-        (uv_stream_t*)(iotjs_tcpwrap_tcp_handle(tcp_wrap_client));
-
-    int err = uv_accept(handle, client_handle);
-    if (err) {
-      return;
-    }
-
-    iotjs_jargs_append_jval(&args, &jclient_tcp);
-    iotjs_jval_destroy(&jcreate_tcp);
-    iotjs_jval_destroy(&jclient_tcp);
-  }
-
-  iotjs_make_callback(&jonconnection, jtcp, &args);
-
-  iotjs_jval_destroy(&jonconnection);
-  iotjs_jargs_destroy(&args);
-}
-
-
-JHANDLER_FUNCTION(Listen) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, number);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_jobject(jtcp);
-
-  int backlog = JHANDLER_GET_ARG(0, number);
-
-  int err = uv_listen((uv_stream_t*)(iotjs_tcpwrap_tcp_handle(tcp_wrap)),
-                      backlog, OnConnection);
-
-  iotjs_jhandler_return_number(jhandler, err);
-}
-
-
-void AfterWrite(uv_write_t* req, int status) {
-  iotjs_write_reqwrap_t* req_wrap = (iotjs_write_reqwrap_t*)(req->data);
-  iotjs_tcpwrap_t* tcp_wrap = (iotjs_tcpwrap_t*)(req->handle->data);
-  IOTJS_ASSERT(req_wrap != NULL);
-  IOTJS_ASSERT(tcp_wrap != NULL);
-
-  // Take callback function object.
-  const iotjs_jval_t* jcallback = iotjs_write_reqwrap_jcallback(req_wrap);
-
-  // Only parameter is status code.
-  iotjs_jargs_t args = iotjs_jargs_create(1);
-  iotjs_jargs_append_number(&args, status);
-
-  // Make callback.
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &args);
-
-  // Destroy args
-  iotjs_jargs_destroy(&args);
-
-  // Release request wrapper.
-  iotjs_write_reqwrap_dispatched(req_wrap);
-}
-
-
-JHANDLER_FUNCTION(Write) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, object, function);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_jobject(jtcp);
-
-  const iotjs_jval_t* jbuffer = JHANDLER_GET_ARG(0, object);
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(jbuffer);
-  char* buffer = iotjs_bufferwrap_buffer(buffer_wrap);
-  int len = iotjs_bufferwrap_length(buffer_wrap);
-
-  uv_buf_t buf;
-  buf.base = buffer;
-  buf.len = len;
-
-  const iotjs_jval_t* arg1 = JHANDLER_GET_ARG(1, object);
-  iotjs_write_reqwrap_t* req_wrap = iotjs_write_reqwrap_create(arg1);
-
-  int err = uv_write(iotjs_write_reqwrap_req(req_wrap),
-                     (uv_stream_t*)(iotjs_tcpwrap_tcp_handle(tcp_wrap)), &buf,
-                     1, AfterWrite);
-
-  if (err) {
-    iotjs_write_reqwrap_dispatched(req_wrap);
-  }
-
-  iotjs_jhandler_return_number(jhandler, err);
-}
-
-
-void OnAlloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
-  if (suggested_size > IOTJS_MAX_READ_BUFFER_SIZE) {
-    suggested_size = IOTJS_MAX_READ_BUFFER_SIZE;
-  }
-
-  buf->base = iotjs_buffer_allocate(suggested_size);
-  buf->len = suggested_size;
-}
-
-
-void OnRead(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
-  iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_handle((uv_tcp_t*)handle);
-
-  // tcp handle
-  const iotjs_jval_t* jtcp = iotjs_tcpwrap_jobject(tcp_wrap);
-
-  // socket object
-  iotjs_jval_t jsocket =
-      iotjs_jval_get_property(jtcp, IOTJS_MAGIC_STRING_OWNER);
-  IOTJS_ASSERT(iotjs_jval_is_object(&jsocket));
-
-  // onread callback
-  iotjs_jval_t jonread =
-      iotjs_jval_get_property(jtcp, IOTJS_MAGIC_STRING_ONREAD);
-  IOTJS_ASSERT(iotjs_jval_is_function(&jonread));
-
-  iotjs_jargs_t jargs = iotjs_jargs_create(4);
-  iotjs_jargs_append_jval(&jargs, &jsocket);
-  iotjs_jargs_append_number(&jargs, nread);
-  iotjs_jargs_append_bool(&jargs, false);
-
-  if (nread <= 0) {
-    if (buf->base != NULL) {
-      iotjs_buffer_release(buf->base);
-    }
-    if (nread < 0) {
-      if (nread == UV__EOF) {
-        iotjs_jargs_replace(&jargs, 2, iotjs_jval_get_boolean(true));
-      }
-
-      iotjs_make_callback(&jonread, iotjs_jval_get_undefined(), &jargs);
-    }
-  } else {
-    iotjs_jval_t jbuffer = iotjs_bufferwrap_create_buffer(nread);
-    iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(&jbuffer);
-
-    iotjs_bufferwrap_copy(buffer_wrap, buf->base, nread);
-
-    iotjs_jargs_append_jval(&jargs, &jbuffer);
-    iotjs_make_callback(&jonread, iotjs_jval_get_undefined(), &jargs);
-
-    iotjs_jval_destroy(&jbuffer);
-    iotjs_buffer_release(buf->base);
-  }
-
-  iotjs_jargs_destroy(&jargs);
-  iotjs_jval_destroy(&jonread);
-  iotjs_jval_destroy(&jsocket);
-}
-
-
-JHANDLER_FUNCTION(ReadStart) {
-  JHANDLER_CHECK_THIS(object);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_jobject(jtcp);
-
-  int err = uv_read_start((uv_stream_t*)(iotjs_tcpwrap_tcp_handle(tcp_wrap)),
-                          OnAlloc, OnRead);
-
-  iotjs_jhandler_return_number(jhandler, err);
-}
-
-
-static void AfterShutdown(uv_shutdown_t* req, int status) {
-  iotjs_shutdown_reqwrap_t* req_wrap = (iotjs_shutdown_reqwrap_t*)(req->data);
-  iotjs_tcpwrap_t* tcp_wrap = (iotjs_tcpwrap_t*)(req->handle->data);
-  IOTJS_ASSERT(req_wrap != NULL);
-  IOTJS_ASSERT(tcp_wrap != NULL);
-
-  // function onShutdown(status)
-  const iotjs_jval_t* jonshutdown = iotjs_shutdown_reqwrap_jcallback(req_wrap);
-  IOTJS_ASSERT(iotjs_jval_is_function(jonshutdown));
-
-  iotjs_jargs_t args = iotjs_jargs_create(1);
-  iotjs_jargs_append_number(&args, status);
-
-  iotjs_make_callback(jonshutdown, iotjs_jval_get_undefined(), &args);
-
-  iotjs_jargs_destroy(&args);
-
-  iotjs_shutdown_reqwrap_dispatched(req_wrap);
-}
-
-
-JHANDLER_FUNCTION(Shutdown) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, function);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_jobject(jtcp);
-
-  const iotjs_jval_t* arg0 = JHANDLER_GET_ARG(0, object);
-  iotjs_shutdown_reqwrap_t* req_wrap = iotjs_shutdown_reqwrap_create(arg0);
-
-  int err = uv_shutdown(iotjs_shutdown_reqwrap_req(req_wrap),
-                        (uv_stream_t*)(iotjs_tcpwrap_tcp_handle(tcp_wrap)),
-                        AfterShutdown);
-
-  if (err) {
-    iotjs_shutdown_reqwrap_dispatched(req_wrap);
-  }
-
-  iotjs_jhandler_return_number(jhandler, err);
-}
-
-
-// Enable/Disable keepalive option.
-// [0] enable
-// [1] delay
-JHANDLER_FUNCTION(SetKeepAlive) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, number, number);
-
-  const iotjs_jval_t* jtcp = JHANDLER_GET_THIS(object);
-  int enable = JHANDLER_GET_ARG(0, number);
-  unsigned delay = JHANDLER_GET_ARG(1, number);
-
-  iotjs_tcpwrap_t* tcp_wrap = iotjs_tcpwrap_from_jobject(jtcp);
-  int err = uv_tcp_keepalive(iotjs_tcpwrap_tcp_handle(tcp_wrap), enable, delay);
-
-  iotjs_jhandler_return_number(jhandler, err);
-}
-
-
-// used in iotjs_module_udp.cpp
-void AddressToJS(const iotjs_jval_t* obj, const sockaddr* addr) {
-  char ip[INET6_ADDRSTRLEN];
-  const sockaddr_in* a4;
-  const sockaddr_in6* a6;
-  int port;
-
-  switch (addr->sa_family) {
-    case AF_INET6: {
-      a6 = (const sockaddr_in6*)(addr);
-      uv_inet_ntop(AF_INET6, &a6->sin6_addr, ip, sizeof ip);
-      port = ntohs(a6->sin6_port);
-      iotjs_jval_set_property_string_raw(obj, IOTJS_MAGIC_STRING_ADDRESS, ip);
-      iotjs_jval_set_property_string_raw(obj, IOTJS_MAGIC_STRING_FAMILY,
-                                         IOTJS_MAGIC_STRING_IPV6);
-      iotjs_jval_set_property_number(obj, IOTJS_MAGIC_STRING_PORT, port);
-      break;
-    }
-
-    case AF_INET: {
-      a4 = (const sockaddr_in*)(addr);
-      uv_inet_ntop(AF_INET, &a4->sin_addr, ip, sizeof ip);
-      port = ntohs(a4->sin_port);
-      iotjs_jval_set_property_string_raw(obj, IOTJS_MAGIC_STRING_ADDRESS, ip);
-      iotjs_jval_set_property_string_raw(obj, IOTJS_MAGIC_STRING_FAMILY,
-                                         IOTJS_MAGIC_STRING_IPV4);
-      iotjs_jval_set_property_number(obj, IOTJS_MAGIC_STRING_PORT, port);
-      break;
-    }
-
-    default: {
-      iotjs_jval_set_property_string_raw(obj, IOTJS_MAGIC_STRING_ADDRESS, "");
-      break;
-    }
-  }
-}
-
-GetSockNameFunction(tcpwrap, tcp_handle, uv_tcp_getsockname);
-
-
-JHANDLER_FUNCTION(GetSockeName) {
-  DoGetSockName(jhandler);
-}
-
-iotjs_jval_t InitTcp() {
-  iotjs_jval_t tcp = iotjs_jval_create_function_with_dispatch(TCP);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-  iotjs_jval_set_property_jval(&tcp, IOTJS_MAGIC_STRING_PROTOTYPE, &prototype);
-
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_OPEN, Open);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_CLOSE, Close);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_CONNECT, Connect);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_BIND, Bind);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_LISTEN, Listen);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITE, Write);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_READSTART, ReadStart);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SHUTDOWN, Shutdown);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SETKEEPALIVE,
-                        SetKeepAlive);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_GETSOCKNAME,
-                        GetSockeName);
-
-  iotjs_jval_destroy(&prototype);
-
-  return tcp;
-}
diff --git a/src/module/iotjs_module_tcp.h b/src/module/iotjs_module_tcp.h
deleted file mode 100644 (file)
index 5fbe909..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_TCP_H
-#define IOTJS_MODULE_TCP_H
-
-
-#include "iotjs_binding.h"
-#include "iotjs_handlewrap.h"
-#include "iotjs_reqwrap.h"
-
-
-typedef struct sockaddr sockaddr;
-typedef struct sockaddr_in sockaddr_in;
-typedef struct sockaddr_in6 sockaddr_in6;
-typedef struct sockaddr_storage sockaddr_storage;
-
-
-typedef struct {
-  iotjs_handlewrap_t handlewrap;
-  uv_tcp_t handle;
-} IOTJS_VALIDATED_STRUCT(iotjs_tcpwrap_t);
-
-
-iotjs_tcpwrap_t* iotjs_tcpwrap_create(const iotjs_jval_t* jtcp);
-
-iotjs_tcpwrap_t* iotjs_tcpwrap_from_handle(uv_tcp_t* handle);
-iotjs_tcpwrap_t* iotjs_tcpwrap_from_jobject(const iotjs_jval_t* jtcp);
-
-uv_tcp_t* iotjs_tcpwrap_tcp_handle(iotjs_tcpwrap_t* tcpwrap);
-iotjs_jval_t* iotjs_tcpwrap_jobject(iotjs_tcpwrap_t* tcpwrap);
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_connect_t req;
-} IOTJS_VALIDATED_STRUCT(iotjs_connect_reqwrap_t);
-
-#define THIS iotjs_connect_reqwrap_t* connect_reqwrap
-iotjs_connect_reqwrap_t* iotjs_connect_reqwrap_create(
-    const iotjs_jval_t* jcallback);
-void iotjs_connect_reqwrap_dispatched(THIS);
-uv_connect_t* iotjs_connect_reqwrap_req(THIS);
-const iotjs_jval_t* iotjs_connect_reqwrap_jcallback(THIS);
-#undef THIS
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_write_t req;
-} IOTJS_VALIDATED_STRUCT(iotjs_write_reqwrap_t);
-
-#define THIS iotjs_write_reqwrap_t* write_reqwrap
-iotjs_write_reqwrap_t* iotjs_write_reqwrap_create(
-    const iotjs_jval_t* jcallback);
-void iotjs_write_reqwrap_dispatched(THIS);
-uv_write_t* iotjs_write_reqwrap_req(THIS);
-const iotjs_jval_t* iotjs_write_reqwrap_jcallback(THIS);
-#undef THIS
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_shutdown_t req;
-} IOTJS_VALIDATED_STRUCT(iotjs_shutdown_reqwrap_t);
-
-#define THIS iotjs_shutdown_reqwrap_t* shutdown_reqwrap
-iotjs_shutdown_reqwrap_t* iotjs_shutdown_reqwrap_create(
-    const iotjs_jval_t* jcallback);
-void iotjs_shutdown_reqwrap_dispatched(THIS);
-uv_shutdown_t* iotjs_shutdown_reqwrap_req(THIS);
-const iotjs_jval_t* iotjs_shutdown_reqwrap_jcallback(THIS);
-#undef THIS
-
-
-void AddressToJS(const iotjs_jval_t* obj, const sockaddr* addr);
-
-
-#define GetSockNameFunction(wraptype, handletype, function)                    \
-  static void DoGetSockName(iotjs_jhandler_t* jhandler) {                      \
-    JHANDLER_CHECK_ARGS(1, object);                                            \
-                                                                               \
-    iotjs_##wraptype##_t* wrap =                                               \
-        iotjs_##wraptype##_from_jobject(JHANDLER_GET_THIS(object));            \
-    IOTJS_ASSERT(wrap != NULL);                                                \
-                                                                               \
-    sockaddr_storage storage;                                                  \
-    int addrlen = sizeof(storage);                                             \
-    sockaddr* const addr = (sockaddr*)(&storage);                              \
-    int err = function(iotjs_##wraptype##_##handletype(wrap), addr, &addrlen); \
-    if (err == 0)                                                              \
-      AddressToJS(JHANDLER_GET_ARG(0, object), addr);                          \
-    iotjs_jhandler_return_number(jhandler, err);                               \
-  }
-
-
-#endif /* IOTJS_MODULE_TCP_H */
diff --git a/src/module/iotjs_module_testdriver.c b/src/module/iotjs_module_testdriver.c
deleted file mode 100644 (file)
index 1c6d087..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module_timer.h"
-
-
-// Only for test driver
-JHANDLER_FUNCTION(IsAliveExceptFor) {
-  JHANDLER_CHECK(iotjs_jhandler_get_arg_length(jhandler) == 1);
-  const iotjs_environment_t* env = iotjs_environment_get();
-  uv_loop_t* loop = iotjs_environment_loop(env);
-
-  const iotjs_jval_t* arg0 = iotjs_jhandler_get_arg(jhandler, 0);
-
-  if (iotjs_jval_is_null(arg0)) {
-    int alive = uv_loop_alive(loop);
-
-    iotjs_jhandler_return_boolean(jhandler, alive);
-  } else {
-    JHANDLER_CHECK(iotjs_jval_is_object(arg0));
-
-    iotjs_jval_t jtimer =
-        iotjs_jval_get_property(arg0, IOTJS_MAGIC_STRING_HANDLER);
-
-    iotjs_timerwrap_t* timer_wrap = iotjs_timerwrap_from_jobject(&jtimer);
-    iotjs_jval_destroy(&jtimer);
-
-    bool has_active_reqs = uv_loop_has_active_reqs(loop);
-    bool has_closing_handler = loop->closing_handles != NULL;
-
-    bool ret = true;
-    bool alive = !has_active_reqs && !has_closing_handler;
-    if (alive) {
-      int active_handlers = loop->active_handles;
-      if (active_handlers == 1) {
-        const uv_timer_t* timer_handle = iotjs_timerwrap_handle(timer_wrap);
-        int timer_alive = uv_is_active((uv_handle_t*)timer_handle);
-
-        if (timer_alive) {
-          // If the timer handler we set for test driver is alive,
-          // then it can be safely terminated.
-          ret = false;
-        }
-      }
-    }
-
-    iotjs_jhandler_return_boolean(jhandler, ret);
-  }
-}
-
-
-iotjs_jval_t InitTestdriver() {
-  iotjs_jval_t testdriver = iotjs_jval_create_object();
-  iotjs_jval_set_method(&testdriver, IOTJS_MAGIC_STRING_ISALIVEEXCEPTFOR,
-                        IsAliveExceptFor);
-
-  return testdriver;
-}
diff --git a/src/module/iotjs_module_timer.c b/src/module/iotjs_module_timer.c
deleted file mode 100644 (file)
index 5dda485..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-#include "iotjs_module_timer.h"
-
-
-static void iotjs_timerwrap_destroy(iotjs_timerwrap_t* timerwrap);
-static void iotjs_timerwrap_on_timeout(iotjs_timerwrap_t* timerwrap);
-
-
-iotjs_timerwrap_t* iotjs_timerwrap_create(const iotjs_jval_t* jtimer) {
-  iotjs_timerwrap_t* timerwrap = IOTJS_ALLOC(iotjs_timerwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_timerwrap_t, timerwrap);
-
-  iotjs_handlewrap_initialize(&_this->handlewrap, jtimer,
-                              (uv_handle_t*)(&_this->handle),
-                              (JFreeHandlerType)iotjs_timerwrap_destroy);
-
-  // Initialize timer handler.
-  const iotjs_environment_t* env = iotjs_environment_get();
-  uv_timer_init(iotjs_environment_loop(env), &_this->handle);
-
-  return timerwrap;
-}
-
-
-static void iotjs_timerwrap_destroy(iotjs_timerwrap_t* timerwrap) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_timerwrap_t, timerwrap);
-  iotjs_handlewrap_destroy(&_this->handlewrap);
-
-  IOTJS_RELEASE(timerwrap);
-}
-
-
-// This function is called from uv when timeout expires.
-static void TimeoutHandler(uv_timer_t* handle) {
-  // Find timer wrap from handle.
-  iotjs_timerwrap_t* timer_wrap = iotjs_timerwrap_from_handle(handle);
-
-  // Call the timeout handler.
-  iotjs_timerwrap_on_timeout(timer_wrap);
-}
-
-
-int iotjs_timerwrap_start(iotjs_timerwrap_t* timerwrap, int64_t timeout,
-                          int64_t repeat) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_timerwrap_t, timerwrap);
-
-  // Start uv timer.
-  return uv_timer_start(&_this->handle, TimeoutHandler, timeout, repeat);
-}
-
-
-int iotjs_timerwrap_stop(iotjs_timerwrap_t* timerwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_timerwrap_t, timerwrap);
-
-  if (!uv_is_closing(iotjs_handlewrap_get_uv_handle(&_this->handlewrap))) {
-    iotjs_handlewrap_close(&_this->handlewrap, NULL);
-  }
-
-  return 0;
-}
-
-
-static void iotjs_timerwrap_on_timeout(iotjs_timerwrap_t* timerwrap) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_timerwrap_t, timerwrap);
-
-  // Call javascript timeout handler function.
-  const iotjs_jval_t* jobject = iotjs_timerwrap_jobject(timerwrap);
-  iotjs_jval_t jcallback =
-      iotjs_jval_get_property(jobject, IOTJS_MAGIC_STRING_HANDLETIMEOUT);
-  iotjs_make_callback(&jcallback, jobject, iotjs_jargs_get_empty());
-  iotjs_jval_destroy(&jcallback);
-}
-
-
-uv_timer_t* iotjs_timerwrap_handle(iotjs_timerwrap_t* timerwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_timerwrap_t, timerwrap);
-  return &_this->handle;
-}
-
-
-iotjs_jval_t* iotjs_timerwrap_jobject(iotjs_timerwrap_t* timerwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_timerwrap_t, timerwrap);
-  iotjs_jval_t* jobject = iotjs_handlewrap_jobject(&_this->handlewrap);
-  IOTJS_ASSERT(iotjs_jval_is_object(jobject));
-  return jobject;
-}
-
-
-iotjs_timerwrap_t* iotjs_timerwrap_from_handle(uv_timer_t* timer_handle) {
-  uv_handle_t* handle = (uv_handle_t*)(timer_handle);
-  iotjs_handlewrap_t* handlewrap = iotjs_handlewrap_from_handle(handle);
-  iotjs_timerwrap_t* timerwrap = (iotjs_timerwrap_t*)handlewrap;
-  IOTJS_ASSERT(iotjs_timerwrap_handle(timerwrap) == timer_handle);
-  return timerwrap;
-}
-
-
-iotjs_timerwrap_t* iotjs_timerwrap_from_jobject(const iotjs_jval_t* jtimer) {
-  iotjs_handlewrap_t* handlewrap = iotjs_handlewrap_from_jobject(jtimer);
-  return (iotjs_timerwrap_t*)handlewrap;
-}
-
-
-JHANDLER_FUNCTION(Start) {
-  // Check parameters.
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(2, number, number);
-
-  const iotjs_jval_t* jtimer = JHANDLER_GET_THIS(object);
-
-  // Take timer wrap.
-  iotjs_timerwrap_t* timer_wrap = iotjs_timerwrap_from_jobject(jtimer);
-
-  // parameters.
-  int64_t timeout = JHANDLER_GET_ARG(0, number);
-  int64_t repeat = JHANDLER_GET_ARG(1, number);
-
-  // Start timer.
-  int res = iotjs_timerwrap_start(timer_wrap, timeout, repeat);
-
-  iotjs_jhandler_return_number(jhandler, res);
-}
-
-
-JHANDLER_FUNCTION(Stop) {
-  JHANDLER_CHECK_THIS(object);
-
-  const iotjs_jval_t* jtimer = JHANDLER_GET_THIS(object);
-
-  iotjs_timerwrap_t* timer_wrap = iotjs_timerwrap_from_jobject(jtimer);
-
-  // Stop timer.
-  int res = iotjs_timerwrap_stop(timer_wrap);
-
-  iotjs_jhandler_return_number(jhandler, res);
-}
-
-
-JHANDLER_FUNCTION(Timer) {
-  JHANDLER_CHECK_THIS(object);
-
-  const iotjs_jval_t* jtimer = JHANDLER_GET_THIS(object);
-
-  iotjs_timerwrap_t* timer_wrap = iotjs_timerwrap_create(jtimer);
-  IOTJS_ASSERT(iotjs_jval_is_object(iotjs_timerwrap_jobject(timer_wrap)));
-  IOTJS_ASSERT(iotjs_jval_get_object_native_handle(jtimer) != 0);
-}
-
-
-iotjs_jval_t InitTimer() {
-  iotjs_jval_t timer = iotjs_jval_create_function_with_dispatch(Timer);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-  iotjs_jval_set_property_jval(&timer, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &prototype);
-
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_START, Start);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_STOP, Stop);
-
-  iotjs_jval_destroy(&prototype);
-
-  return timer;
-}
diff --git a/src/module/iotjs_module_timer.h b/src/module/iotjs_module_timer.h
deleted file mode 100644 (file)
index f419592..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IOTJS_MODULE_TIMER_H
-#define IOTJS_MODULE_TIMER_H
-
-
-#include "iotjs_binding.h"
-#include "iotjs_handlewrap.h"
-
-
-typedef struct {
-  iotjs_handlewrap_t handlewrap;
-  uv_timer_t handle;
-} IOTJS_VALIDATED_STRUCT(iotjs_timerwrap_t);
-
-
-iotjs_timerwrap_t* iotjs_timerwrap_create(const iotjs_jval_t* jtimer);
-
-iotjs_timerwrap_t* iotjs_timerwrap_from_jobject(const iotjs_jval_t* jtimer);
-iotjs_timerwrap_t* iotjs_timerwrap_from_handle(uv_timer_t* timer_handle);
-
-uv_timer_t* iotjs_timerwrap_handle(iotjs_timerwrap_t* timerwrap);
-iotjs_jval_t* iotjs_timerwrap_jobject(iotjs_timerwrap_t* timerwrap);
-
-// Start timer.
-int iotjs_timerwrap_start(iotjs_timerwrap_t* timerwrap, int64_t timeout,
-                          int64_t repeat);
-// Stop & close timer.
-int iotjs_timerwrap_stop(iotjs_timerwrap_t* timerwrap);
-
-
-#endif /* IOTJS_MODULE_TIMER_H */
diff --git a/src/module/iotjs_module_uart.c b/src/module/iotjs_module_uart.c
deleted file mode 100644 (file)
index c082374..0000000
+++ /dev/null
@@ -1,360 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <unistd.h>
-
-#include "iotjs_def.h"
-#include "iotjs_module_uart.h"
-#include "iotjs_objectwrap.h"
-
-
-static void iotjs_uart_destroy(iotjs_uart_t* uart);
-static iotjs_uart_t* iotjs_uart_instance_from_jval(const iotjs_jval_t* juart);
-
-
-static iotjs_uart_t* iotjs_uart_create(const iotjs_jval_t* juart) {
-  iotjs_uart_t* uart = IOTJS_ALLOC(iotjs_uart_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_uart_t, uart);
-  iotjs_jobjectwrap_initialize(&_this->jobjectwrap, juart,
-                               (JFreeHandlerType)iotjs_uart_destroy);
-
-  _this->device_fd = -1;
-
-  return uart;
-}
-
-
-static void iotjs_uart_destroy(iotjs_uart_t* uart) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_uart_t, uart);
-  iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
-  iotjs_string_destroy(&_this->device_path);
-  IOTJS_RELEASE(uart);
-}
-
-
-#define THIS iotjs_uart_reqwrap_t* uart_reqwrap
-
-
-static iotjs_uart_reqwrap_t* iotjs_uart_reqwrap_create(
-    const iotjs_jval_t* jcallback, const iotjs_jval_t* juart, UartOp op) {
-  iotjs_uart_reqwrap_t* uart_reqwrap = IOTJS_ALLOC(iotjs_uart_reqwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_uart_reqwrap_t, uart_reqwrap);
-
-  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
-
-  _this->req_data.op = op;
-  _this->uart_instance = iotjs_uart_instance_from_jval(juart);
-
-  return uart_reqwrap;
-}
-
-
-static void iotjs_uart_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_uart_reqwrap_t, uart_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(uart_reqwrap);
-}
-
-
-static void iotjs_uart_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_uart_reqwrap_t, uart_reqwrap);
-  iotjs_uart_reqwrap_destroy(uart_reqwrap);
-}
-
-
-static uv_work_t* iotjs_uart_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_reqwrap_t, uart_reqwrap);
-  return &_this->req;
-}
-
-
-static const iotjs_jval_t* iotjs_uart_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_reqwrap_t, uart_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-
-static iotjs_uart_t* iotjs_uart_instance_from_jval(const iotjs_jval_t* juart) {
-  iotjs_jobjectwrap_t* jobjectwrap = iotjs_jobjectwrap_from_jobject(juart);
-  return (iotjs_uart_t*)jobjectwrap;
-}
-
-
-iotjs_uart_reqwrap_t* iotjs_uart_reqwrap_from_request(uv_work_t* req) {
-  return (iotjs_uart_reqwrap_t*)(iotjs_reqwrap_from_request((uv_req_t*)req));
-}
-
-
-iotjs_uart_reqdata_t* iotjs_uart_reqwrap_data(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_reqwrap_t, uart_reqwrap);
-  return &_this->req_data;
-}
-
-
-iotjs_uart_t* iotjs_uart_instance_from_reqwrap(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_reqwrap_t, uart_reqwrap);
-  return _this->uart_instance;
-}
-
-
-#undef THIS
-
-
-static bool iotjs_uart_close(iotjs_uart_t* uart) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_t, uart);
-  uv_poll_t* poll_handle = &_this->poll_handle;
-
-  if (_this->device_fd > 0) {
-    if (!uv_is_closing((uv_handle_t*)poll_handle)) {
-      uv_close((uv_handle_t*)poll_handle, NULL);
-    }
-    if (close(_this->device_fd) < 0) {
-      return false;
-    }
-  }
-
-  return true;
-}
-
-
-static void iotjs_uart_write_worker(uv_work_t* work_req) {
-  UART_WORKER_INIT;
-
-  if (!iotjs_uart_write(uart)) {
-    req_data->result = false;
-    return;
-  }
-
-  req_data->result = true;
-}
-
-
-static void iotjs_uart_close_worker(uv_work_t* work_req) {
-  UART_WORKER_INIT;
-
-  if (!iotjs_uart_close(uart)) {
-    req_data->result = false;
-    return;
-  }
-
-  req_data->result = true;
-}
-
-
-static void iotjs_uart_after_worker(uv_work_t* work_req, int status) {
-  iotjs_uart_reqwrap_t* req_wrap = iotjs_uart_reqwrap_from_request(work_req);
-  iotjs_uart_reqdata_t* req_data = iotjs_uart_reqwrap_data(req_wrap);
-
-  iotjs_jargs_t jargs = iotjs_jargs_create(1);
-
-  if (status) {
-    iotjs_jval_t error = iotjs_jval_create_error("System error");
-    iotjs_jargs_append_jval(&jargs, &error);
-    iotjs_jval_destroy(&error);
-  } else {
-    switch (req_data->op) {
-      case kUartOpOpen: {
-        if (!req_data->result) {
-          iotjs_jargs_append_error(&jargs, "Failed to open UART device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      }
-      case kUartOpWrite: {
-        iotjs_uart_t* uart = iotjs_uart_instance_from_reqwrap(req_wrap);
-        IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_t, uart);
-
-        iotjs_string_destroy(&_this->buf_data);
-
-        if (!req_data->result) {
-          iotjs_jargs_append_error(&jargs, "Cannot write to device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      }
-      case kUartOpClose: {
-        if (!req_data->result) {
-          iotjs_jargs_append_error(&jargs, "Failed to close UART device");
-        } else {
-          iotjs_jargs_append_null(&jargs);
-        }
-        break;
-      }
-      default: {
-        IOTJS_ASSERT(!"Unreachable");
-        break;
-      }
-    }
-  }
-
-  const iotjs_jval_t* jcallback = iotjs_uart_reqwrap_jcallback(req_wrap);
-  iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &jargs);
-
-  iotjs_jargs_destroy(&jargs);
-  iotjs_uart_reqwrap_dispatched(req_wrap);
-}
-
-
-static void iotjs_uart_onread(iotjs_jval_t* jthis, char* buf) {
-  iotjs_jval_t jemit = iotjs_jval_get_property(jthis, "emit");
-  IOTJS_ASSERT(iotjs_jval_is_function(&jemit));
-
-  iotjs_jargs_t jargs = iotjs_jargs_create(2);
-  iotjs_jval_t str = iotjs_jval_create_string_raw("data");
-  iotjs_jval_t data = iotjs_jval_create_string_raw(buf);
-  iotjs_jargs_append_jval(&jargs, &str);
-  iotjs_jargs_append_jval(&jargs, &data);
-  iotjs_jhelper_call_ok(&jemit, jthis, &jargs);
-
-  iotjs_jval_destroy(&str);
-  iotjs_jval_destroy(&data);
-  iotjs_jargs_destroy(&jargs);
-  iotjs_jval_destroy(&jemit);
-}
-
-
-void iotjs_uart_read_cb(uv_poll_t* req, int status, int events) {
-  iotjs_uart_t* uart = (iotjs_uart_t*)req->data;
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_t, uart);
-
-  char buf[UART_WRITE_BUFFER_SIZE];
-  int i = read(_this->device_fd, buf, UART_WRITE_BUFFER_SIZE - 1);
-  if (i > 0) {
-    buf[i] = '\0';
-    DDDLOG("%s - read data: %s", __func__, buf);
-    iotjs_uart_onread(&_this->jemitter_this, buf);
-  }
-}
-
-
-#define UART_ASYNC(call, jthis, jcallback, op)                         \
-  do {                                                                 \
-    uv_loop_t* loop = iotjs_environment_loop(iotjs_environment_get()); \
-    iotjs_uart_reqwrap_t* req_wrap =                                   \
-        iotjs_uart_reqwrap_create(jcallback, jthis, op);               \
-    uv_work_t* req = iotjs_uart_reqwrap_req(req_wrap);                 \
-    uv_queue_work(loop, req, iotjs_uart_##call##_worker,               \
-                  iotjs_uart_after_worker);                            \
-  } while (0)
-
-
-JHANDLER_FUNCTION(UartConstructor) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(3, object, object, function);
-
-  // Create UART object
-  const iotjs_jval_t* juart = JHANDLER_GET_THIS(object);
-  iotjs_uart_t* uart = iotjs_uart_create(juart);
-  IOTJS_ASSERT(uart == iotjs_uart_instance_from_jval(juart));
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_t, uart);
-
-  const iotjs_jval_t* jconfiguration = JHANDLER_GET_ARG(0, object);
-  const iotjs_jval_t* jemitter_this = JHANDLER_GET_ARG(1, object);
-  _this->jemitter_this = iotjs_jval_create_copied(jemitter_this);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(2, function);
-
-  // set configuration
-  iotjs_jval_t jdevice =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_DEVICE);
-  iotjs_jval_t jbaud_rate =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_BAUDRATE);
-  iotjs_jval_t jdata_bits =
-      iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_DATABITS);
-
-  _this->device_path = iotjs_jval_as_string(&jdevice);
-  _this->baud_rate = iotjs_jval_as_number(&jbaud_rate);
-  _this->data_bits = iotjs_jval_as_number(&jdata_bits);
-
-  DDDLOG("%s - path: %s, baudRate: %d, dataBits: %d", __func__,
-         iotjs_string_data(&_this->device_path), _this->baud_rate,
-         _this->data_bits);
-
-  iotjs_jval_destroy(&jdevice);
-  iotjs_jval_destroy(&jbaud_rate);
-  iotjs_jval_destroy(&jdata_bits);
-
-  UART_ASYNC(open, juart, jcallback, kUartOpOpen);
-}
-
-
-JHANDLER_FUNCTION(Write) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(1, string);
-  JHANDLER_CHECK_ARG_IF_EXIST(1, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
-  const iotjs_jval_t* juart = JHANDLER_GET_THIS(object);
-  iotjs_uart_t* uart = iotjs_uart_instance_from_jval(juart);
-
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_t, uart);
-
-  _this->buf_data = JHANDLER_GET_ARG(0, string);
-  _this->buf_len = iotjs_string_size(&_this->buf_data);
-
-  if (jcallback) {
-    UART_ASYNC(write, juart, jcallback, kUartOpWrite);
-  } else {
-    bool result = iotjs_uart_write(uart);
-    iotjs_string_destroy(&_this->buf_data);
-
-    if (!result) {
-      JHANDLER_THROW(COMMON, "UART Write Error");
-      return;
-    }
-  }
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARG_IF_EXIST(0, function);
-
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(0, function);
-  const iotjs_jval_t* juart = JHANDLER_GET_THIS(object);
-  iotjs_uart_t* uart = iotjs_uart_instance_from_jval(juart);
-
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_t, uart);
-  iotjs_jval_destroy(&_this->jemitter_this);
-
-  if (jcallback) {
-    UART_ASYNC(close, juart, jcallback, kUartOpClose);
-  } else {
-    if (!iotjs_uart_close(uart)) {
-      JHANDLER_THROW(COMMON, "UART Close Error");
-    }
-  }
-}
-
-
-iotjs_jval_t InitUart() {
-  iotjs_jval_t juart_constructor =
-      iotjs_jval_create_function_with_dispatch(UartConstructor);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITE, Write);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_CLOSE, Close);
-
-  iotjs_jval_set_property_jval(&juart_constructor, IOTJS_MAGIC_STRING_PROTOTYPE,
-                               &prototype);
-
-  iotjs_jval_destroy(&prototype);
-
-  return juart_constructor;
-}
diff --git a/src/module/iotjs_module_uart.h b/src/module/iotjs_module_uart.h
deleted file mode 100644 (file)
index 3b1c72f..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_UART_H
-#define IOTJS_MODULE_UART_H
-
-#include "iotjs_def.h"
-#include "iotjs_objectwrap.h"
-#include "iotjs_reqwrap.h"
-
-
-#define UART_WRITE_BUFFER_SIZE 512
-
-
-typedef enum {
-  kUartOpOpen,
-  kUartOpClose,
-  kUartOpWrite,
-} UartOp;
-
-
-typedef struct {
-  iotjs_jobjectwrap_t jobjectwrap;
-  iotjs_jval_t jemitter_this;
-  int device_fd;
-  int baud_rate;
-  uint8_t data_bits;
-  iotjs_string_t device_path;
-  iotjs_string_t buf_data;
-  unsigned buf_len;
-  uv_poll_t poll_handle;
-} IOTJS_VALIDATED_STRUCT(iotjs_uart_t);
-
-
-typedef struct {
-  UartOp op;
-  bool result;
-} iotjs_uart_reqdata_t;
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_work_t req;
-  iotjs_uart_reqdata_t req_data;
-  iotjs_uart_t* uart_instance;
-} IOTJS_VALIDATED_STRUCT(iotjs_uart_reqwrap_t);
-
-#define THIS iotjs_uart_reqwrap_t* uart_reqwrap
-
-iotjs_uart_reqwrap_t* iotjs_uart_reqwrap_from_request(uv_work_t* req);
-iotjs_uart_reqdata_t* iotjs_uart_reqwrap_data(THIS);
-
-iotjs_uart_t* iotjs_uart_instance_from_reqwrap(THIS);
-
-#undef THIS
-
-
-#define UART_WORKER_INIT                                                      \
-  iotjs_uart_reqwrap_t* req_wrap = iotjs_uart_reqwrap_from_request(work_req); \
-  iotjs_uart_reqdata_t* req_data = iotjs_uart_reqwrap_data(req_wrap);         \
-  iotjs_uart_t* uart = iotjs_uart_instance_from_reqwrap(req_wrap);
-
-
-void iotjs_uart_read_cb(uv_poll_t* req, int status, int events);
-
-void iotjs_uart_open_worker(uv_work_t* work_req);
-bool iotjs_uart_write(iotjs_uart_t* uart);
-
-#endif /* IOTJS_MODULE_UART_H */
diff --git a/src/module/iotjs_module_udp.c b/src/module/iotjs_module_udp.c
deleted file mode 100644 (file)
index 119c79e..0000000
+++ /dev/null
@@ -1,509 +0,0 @@
-/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "iotjs_def.h"
-
-#include "iotjs_module_udp.h"
-
-#include "iotjs_handlewrap.h"
-#include "iotjs_module_buffer.h"
-#include "iotjs_module_tcp.h"
-#include "iotjs_reqwrap.h"
-
-
-static void iotjs_udpwrap_destroy(iotjs_udpwrap_t* udpwrap);
-
-
-iotjs_udpwrap_t* iotjs_udpwrap_create(const iotjs_jval_t* judp) {
-  iotjs_udpwrap_t* udpwrap = IOTJS_ALLOC(iotjs_udpwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_udpwrap_t, udpwrap);
-
-  iotjs_handlewrap_initialize(&_this->handlewrap, judp,
-                              (uv_handle_t*)(&_this->handle),
-                              (JFreeHandlerType)iotjs_udpwrap_destroy);
-
-  const iotjs_environment_t* env = iotjs_environment_get();
-  uv_udp_init(iotjs_environment_loop(env), &_this->handle);
-
-  return udpwrap;
-}
-
-
-static void iotjs_udpwrap_destroy(iotjs_udpwrap_t* udpwrap) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_udpwrap_t, udpwrap);
-  iotjs_handlewrap_destroy(&_this->handlewrap);
-  IOTJS_RELEASE(udpwrap);
-}
-
-
-iotjs_udpwrap_t* iotjs_udpwrap_from_handle(uv_udp_t* udp_handle) {
-  uv_handle_t* handle = (uv_handle_t*)(udp_handle);
-  iotjs_handlewrap_t* handlewrap = iotjs_handlewrap_from_handle(handle);
-  iotjs_udpwrap_t* udpwrap = (iotjs_udpwrap_t*)handlewrap;
-  IOTJS_ASSERT(iotjs_udpwrap_udp_handle(udpwrap) == udp_handle);
-  return udpwrap;
-}
-
-
-iotjs_udpwrap_t* iotjs_udpwrap_from_jobject(const iotjs_jval_t* judp) {
-  iotjs_handlewrap_t* handlewrap = iotjs_handlewrap_from_jobject(judp);
-  return (iotjs_udpwrap_t*)handlewrap;
-}
-
-
-uv_udp_t* iotjs_udpwrap_udp_handle(iotjs_udpwrap_t* udpwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_udpwrap_t, udpwrap);
-  uv_handle_t* handle = iotjs_handlewrap_get_uv_handle(&_this->handlewrap);
-  return (uv_udp_t*)handle;
-}
-
-
-iotjs_jval_t* iotjs_udpwrap_jobject(iotjs_udpwrap_t* udpwrap) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_udpwrap_t, udpwrap);
-  return iotjs_handlewrap_jobject(&_this->handlewrap);
-}
-
-
-#define THIS iotjs_send_reqwrap_t* send_reqwrap
-
-iotjs_send_reqwrap_t* iotjs_send_reqwrap_create(const iotjs_jval_t* jcallback,
-                                                const size_t msg_size) {
-  iotjs_send_reqwrap_t* send_reqwrap = IOTJS_ALLOC(iotjs_send_reqwrap_t);
-  IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_send_reqwrap_t, send_reqwrap);
-
-  iotjs_reqwrap_initialize(&_this->reqwrap, jcallback, (uv_req_t*)&_this->req);
-  _this->msg_size = msg_size;
-
-  return send_reqwrap;
-}
-
-
-static void iotjs_send_reqwrap_destroy(THIS) {
-  IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_send_reqwrap_t, send_reqwrap);
-  iotjs_reqwrap_destroy(&_this->reqwrap);
-  IOTJS_RELEASE(send_reqwrap);
-}
-
-
-void iotjs_send_reqwrap_dispatched(THIS) {
-  IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_send_reqwrap_t, send_reqwrap);
-  iotjs_send_reqwrap_destroy(send_reqwrap);
-}
-
-
-uv_udp_send_t* iotjs_send_reqwrap_req(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_send_reqwrap_t, send_reqwrap);
-  return &_this->req;
-}
-
-
-const iotjs_jval_t* iotjs_send_reqwrap_jcallback(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_send_reqwrap_t, send_reqwrap);
-  return iotjs_reqwrap_jcallback(&_this->reqwrap);
-}
-
-
-size_t iotjs_send_reqwrap_msg_size(THIS) {
-  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_send_reqwrap_t, send_reqwrap);
-  return _this->msg_size;
-}
-
-#undef THIS
-
-
-JHANDLER_FUNCTION(UDP) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* judp = JHANDLER_GET_THIS(object);
-  iotjs_udpwrap_t* udp_wrap = iotjs_udpwrap_create(judp);
-  IOTJS_UNUSED(udp_wrap);
-}
-
-
-JHANDLER_FUNCTION(Bind) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS_2(string, number);
-
-  const iotjs_jval_t* judp = JHANDLER_GET_THIS(object);
-  iotjs_udpwrap_t* udp_wrap = iotjs_udpwrap_from_jobject(judp);
-
-  iotjs_string_t address = JHANDLER_GET_ARG(0, string);
-  const int port = JHANDLER_GET_ARG(1, number);
-  const iotjs_jval_t* this_obj = JHANDLER_GET_THIS(object);
-  iotjs_jval_t reuse_addr =
-      iotjs_jval_get_property(this_obj, IOTJS_MAGIC_STRING__REUSEADDR);
-  IOTJS_ASSERT(iotjs_jval_is_boolean(&reuse_addr) ||
-               iotjs_jval_is_undefined(&reuse_addr));
-
-  int flags = false;
-  if (!iotjs_jval_is_undefined(&reuse_addr)) {
-    flags = iotjs_jval_as_boolean(&reuse_addr) ? UV_UDP_REUSEADDR : 0;
-  }
-
-  char addr[sizeof(sockaddr_in6)];
-  int err =
-      uv_ip4_addr(iotjs_string_data(&address), port, (sockaddr_in*)(&addr));
-
-  if (err == 0) {
-    err = uv_udp_bind(iotjs_udpwrap_udp_handle(udp_wrap),
-                      (const sockaddr*)(&addr), flags);
-  }
-
-  iotjs_jhandler_return_number(jhandler, err);
-
-  iotjs_jval_destroy(&reuse_addr);
-  iotjs_string_destroy(&address);
-}
-
-
-static void OnAlloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
-  if (suggested_size > IOTJS_MAX_READ_BUFFER_SIZE) {
-    suggested_size = IOTJS_MAX_READ_BUFFER_SIZE;
-  }
-
-  buf->base = iotjs_buffer_allocate(suggested_size);
-  buf->len = suggested_size;
-}
-
-
-static void OnRecv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* buf,
-                   const struct sockaddr* addr, unsigned int flags) {
-  if (nread == 0 && addr == NULL) {
-    if (buf->base != NULL)
-      iotjs_buffer_release(buf->base);
-    return;
-  }
-
-  iotjs_udpwrap_t* udp_wrap = iotjs_udpwrap_from_handle(handle);
-
-  // udp handle
-  const iotjs_jval_t* judp = iotjs_udpwrap_jobject(udp_wrap);
-  IOTJS_ASSERT(iotjs_jval_is_object(judp));
-
-  // onmessage callback
-  iotjs_jval_t jonmessage =
-      iotjs_jval_get_property(judp, IOTJS_MAGIC_STRING_ONMESSAGE);
-  IOTJS_ASSERT(iotjs_jval_is_function(&jonmessage));
-
-  iotjs_jargs_t jargs = iotjs_jargs_create(4);
-  iotjs_jargs_append_number(&jargs, nread);
-  iotjs_jargs_append_jval(&jargs, judp);
-
-  if (nread < 0) {
-    if (buf->base != NULL)
-      iotjs_buffer_release(buf->base);
-    iotjs_make_callback(&jonmessage, iotjs_jval_get_undefined(), &jargs);
-    iotjs_jval_destroy(&jonmessage);
-    iotjs_jargs_destroy(&jargs);
-    return;
-  }
-
-  iotjs_jval_t jbuffer = iotjs_bufferwrap_create_buffer(nread);
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(&jbuffer);
-
-  iotjs_bufferwrap_copy(buffer_wrap, buf->base, nread);
-
-  iotjs_jargs_append_jval(&jargs, &jbuffer);
-
-  iotjs_jval_t rinfo = iotjs_jval_create_object();
-  AddressToJS(&rinfo, addr);
-  iotjs_jargs_append_jval(&jargs, &rinfo);
-
-  iotjs_make_callback(&jonmessage, iotjs_jval_get_undefined(), &jargs);
-
-  iotjs_jval_destroy(&rinfo);
-  iotjs_jval_destroy(&jbuffer);
-  iotjs_jval_destroy(&jonmessage);
-  iotjs_buffer_release(buf->base);
-  iotjs_jargs_destroy(&jargs);
-}
-
-
-JHANDLER_FUNCTION(RecvStart) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* judp = JHANDLER_GET_THIS(object);
-  iotjs_udpwrap_t* udp_wrap = iotjs_udpwrap_from_jobject(judp);
-
-  int err =
-      uv_udp_recv_start(iotjs_udpwrap_udp_handle(udp_wrap), OnAlloc, OnRecv);
-
-  // UV_EALREADY means that the socket is already bound but that's okay
-  if (err == UV_EALREADY)
-    err = 0;
-
-  iotjs_jhandler_return_number(jhandler, err);
-}
-
-
-JHANDLER_FUNCTION(RecvStop) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* judp = JHANDLER_GET_THIS(object);
-  iotjs_udpwrap_t* udp_wrap = iotjs_udpwrap_from_jobject(judp);
-
-  int r = uv_udp_recv_stop(iotjs_udpwrap_udp_handle(udp_wrap));
-
-  iotjs_jhandler_return_number(jhandler, r);
-}
-
-
-static void OnSend(uv_udp_send_t* req, int status) {
-  iotjs_send_reqwrap_t* req_wrap = (iotjs_send_reqwrap_t*)(req->data);
-  IOTJS_ASSERT(req_wrap != NULL);
-
-  // Take callback function object.
-  const iotjs_jval_t* jcallback = iotjs_send_reqwrap_jcallback(req_wrap);
-
-  if (iotjs_jval_is_function(jcallback)) {
-    // Take callback function object.
-
-    iotjs_jargs_t jargs = iotjs_jargs_create(2);
-    iotjs_jargs_append_number(&jargs, status);
-    iotjs_jargs_append_number(&jargs, iotjs_send_reqwrap_msg_size(req_wrap));
-
-    iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &jargs);
-    iotjs_jargs_destroy(&jargs);
-  }
-
-  iotjs_send_reqwrap_dispatched(req_wrap);
-}
-
-
-// Send messages using the socket.
-// [0] buffer
-// [1] port
-// [2] ip
-// [3] callback function
-JHANDLER_FUNCTION(Send) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS_3(object, number, string);
-  IOTJS_ASSERT(iotjs_jval_is_function(iotjs_jhandler_get_arg(jhandler, 3)) ||
-               iotjs_jval_is_undefined(iotjs_jhandler_get_arg(jhandler, 3)));
-
-  const iotjs_jval_t* judp = JHANDLER_GET_THIS(object);
-  iotjs_udpwrap_t* udp_wrap = iotjs_udpwrap_from_jobject(judp);
-
-  const iotjs_jval_t* jbuffer = JHANDLER_GET_ARG(0, object);
-  const unsigned short port = JHANDLER_GET_ARG(1, number);
-  iotjs_string_t address = JHANDLER_GET_ARG(2, string);
-  const iotjs_jval_t* jcallback = JHANDLER_GET_ARG(3, object);
-
-  iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(jbuffer);
-  char* buffer = iotjs_bufferwrap_buffer(buffer_wrap);
-  int len = iotjs_bufferwrap_length(buffer_wrap);
-
-  iotjs_send_reqwrap_t* req_wrap = iotjs_send_reqwrap_create(jcallback, len);
-
-  uv_buf_t buf;
-  buf.base = buffer;
-  buf.len = len;
-
-  char addr[sizeof(sockaddr_in6)];
-  int err =
-      uv_ip4_addr(iotjs_string_data(&address), port, (sockaddr_in*)(&addr));
-
-  if (err == 0) {
-    err = uv_udp_send(iotjs_send_reqwrap_req(req_wrap),
-                      iotjs_udpwrap_udp_handle(udp_wrap), &buf, 1,
-                      (const sockaddr*)(&addr), OnSend);
-  }
-
-  if (err) {
-    iotjs_send_reqwrap_dispatched(req_wrap);
-  }
-
-  iotjs_jhandler_return_number(jhandler, err);
-
-  iotjs_string_destroy(&address);
-}
-
-
-// Close socket
-JHANDLER_FUNCTION(Close) {
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS(0);
-
-  const iotjs_jval_t* judp = JHANDLER_GET_THIS(object);
-  iotjs_handlewrap_t* wrap = iotjs_handlewrap_from_jobject(judp);
-
-  iotjs_handlewrap_close(wrap, NULL);
-}
-
-
-GetSockNameFunction(udpwrap, udp_handle, uv_udp_getsockname);
-
-
-JHANDLER_FUNCTION(GetSockeName) {
-  DoGetSockName(jhandler);
-}
-
-
-#define IOTJS_UV_SET_SOCKOPT(fn)                                \
-  JHANDLER_CHECK_THIS(object);                                  \
-  JHANDLER_CHECK_ARGS_1(number);                                \
-                                                                \
-  const iotjs_jval_t* judp = JHANDLER_GET_THIS(object);         \
-  iotjs_udpwrap_t* udp_wrap = iotjs_udpwrap_from_jobject(judp); \
-                                                                \
-  int flag = JHANDLER_GET_ARG(0, number);                       \
-  int err = fn(iotjs_udpwrap_udp_handle(udp_wrap), flag);       \
-                                                                \
-  iotjs_jhandler_return_number(jhandler, err);
-
-
-JHANDLER_FUNCTION(SetBroadcast) {
-#if !defined(__NUTTX__) && !defined(__TIZENRT__)
-  IOTJS_UV_SET_SOCKOPT(uv_udp_set_broadcast);
-#else
-  IOTJS_ASSERT(!"Not implemented");
-
-  iotjs_jhandler_return_null(jhandler);
-#endif
-}
-
-
-JHANDLER_FUNCTION(SetTTL) {
-#if !defined(__NUTTX__) && !defined(__TIZENRT__)
-  IOTJS_UV_SET_SOCKOPT(uv_udp_set_ttl);
-#else
-  IOTJS_ASSERT(!"Not implemented");
-
-  iotjs_jhandler_return_null(jhandler);
-#endif
-}
-
-
-JHANDLER_FUNCTION(SetMulticastTTL) {
-#if !defined(__NUTTX__) && !defined(__TIZENRT__)
-  IOTJS_UV_SET_SOCKOPT(uv_udp_set_multicast_ttl);
-#else
-  IOTJS_ASSERT(!"Not implemented");
-
-  iotjs_jhandler_return_null(jhandler);
-#endif
-}
-
-
-JHANDLER_FUNCTION(SetMulticastLoopback) {
-#if !defined(__NUTTX__) && !defined(__TIZENRT__)
-  IOTJS_UV_SET_SOCKOPT(uv_udp_set_multicast_loop);
-#else
-  IOTJS_ASSERT(!"Not implemented");
-
-  iotjs_jhandler_return_null(jhandler);
-#endif
-}
-
-#undef IOTJS_UV_SET_SOCKOPT
-
-
-void SetMembership(iotjs_jhandler_t* jhandler, uv_membership membership) {
-#if !defined(__NUTTX__) && !defined(__TIZENRT__)
-  JHANDLER_CHECK_THIS(object);
-  JHANDLER_CHECK_ARGS_1(string);
-
-  const iotjs_jval_t* judp = JHANDLER_GET_THIS(object);
-  iotjs_udpwrap_t* udp_wrap = iotjs_udpwrap_from_jobject(judp);
-
-  iotjs_string_t address = JHANDLER_GET_ARG(0, string);
-  const iotjs_jval_t* arg1 = iotjs_jhandler_get_arg(jhandler, 1);
-  bool isUndefinedOrNull =
-      iotjs_jval_is_undefined(arg1) || iotjs_jval_is_null(arg1);
-  iotjs_string_t iface;
-
-  const char* iface_cstr;
-  if (isUndefinedOrNull) {
-    iface_cstr = NULL;
-  } else {
-    iface = iotjs_jval_as_string(arg1);
-    iface_cstr = iotjs_string_data(&iface);
-  }
-
-  int err = uv_udp_set_membership(iotjs_udpwrap_udp_handle(udp_wrap),
-                                  iotjs_string_data(&address), iface_cstr,
-                                  membership);
-
-  iotjs_jhandler_return_number(jhandler, err);
-
-  iotjs_string_destroy(&address);
-  if (!isUndefinedOrNull)
-    iotjs_string_destroy(&iface);
-#else
-  IOTJS_ASSERT(!"Not implemented");
-
-  iotjs_jhandler_return_null(jhandler);
-#endif
-}
-
-
-JHANDLER_FUNCTION(AddMembership) {
-  SetMembership(jhandler, UV_JOIN_GROUP);
-}
-
-
-JHANDLER_FUNCTION(DropMembership) {
-  SetMembership(jhandler, UV_LEAVE_GROUP);
-}
-
-
-JHANDLER_FUNCTION(Ref) {
-  IOTJS_ASSERT(!"Not implemented");
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-JHANDLER_FUNCTION(Unref) {
-  IOTJS_ASSERT(!"Not implemented");
-
-  iotjs_jhandler_return_null(jhandler);
-}
-
-
-iotjs_jval_t InitUdp() {
-  iotjs_jval_t udp = iotjs_jval_create_function_with_dispatch(UDP);
-
-  iotjs_jval_t prototype = iotjs_jval_create_object();
-  iotjs_jval_set_property_jval(&udp, IOTJS_MAGIC_STRING_PROTOTYPE, &prototype);
-
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_BIND, Bind);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_RECVSTART, RecvStart);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_RECVSTOP, RecvStop);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SEND, Send);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_CLOSE, Close);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_GETSOCKNAME,
-                        GetSockeName);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SETBROADCAST,
-                        SetBroadcast);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SETTTL, SetTTL);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SETMULTICASTTTL,
-                        SetMulticastTTL);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SETMULTICASTLOOPBACK,
-                        SetMulticastLoopback);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_ADDMEMBERSHIP,
-                        AddMembership);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_DROPMEMBERSHIP,
-                        DropMembership);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_REF, Ref);
-  iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_UNREF, Unref);
-
-  iotjs_jval_destroy(&prototype);
-
-  return udp;
-}
diff --git a/src/module/iotjs_module_udp.h b/src/module/iotjs_module_udp.h
deleted file mode 100644 (file)
index 2d9e669..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef IOTJS_MODULE_UDP_H
-#define IOTJS_MODULE_UDP_H
-
-
-#include "iotjs_def.h"
-#include "iotjs_handlewrap.h"
-#include "iotjs_reqwrap.h"
-
-
-typedef struct {
-  iotjs_handlewrap_t handlewrap;
-  uv_udp_t handle;
-} IOTJS_VALIDATED_STRUCT(iotjs_udpwrap_t);
-
-
-iotjs_udpwrap_t* iotjs_udpwrap_create(const iotjs_jval_t* judp);
-
-iotjs_udpwrap_t* iotjs_udpwrap_from_handle(uv_udp_t* handle);
-iotjs_udpwrap_t* iotjs_udpwrap_from_jobject(const iotjs_jval_t* judp);
-
-uv_udp_t* iotjs_udpwrap_udp_handle(iotjs_udpwrap_t* udpwrap);
-iotjs_jval_t* iotjs_udpwrap_jobject(iotjs_udpwrap_t* udpwrap);
-
-
-typedef struct {
-  iotjs_reqwrap_t reqwrap;
-  uv_udp_send_t req;
-  size_t msg_size;
-} IOTJS_VALIDATED_STRUCT(iotjs_send_reqwrap_t);
-
-#define THIS iotjs_send_reqwrap_t* send_reqwrap
-
-iotjs_send_reqwrap_t* iotjs_send_reqwrap_create(const iotjs_jval_t* jcallback,
-                                                const size_t msg_size);
-
-void iotjs_send_reqwrap_dispatched(THIS);
-
-uv_udp_send_t* iotjs_send_reqwrap_req(THIS);
-const iotjs_jval_t* iotjs_send_reqwrap_jcallback(THIS);
-
-#undef THIS
-
-
-#endif /* IOTJS_MODULE_UDP_H */