Update 0719 20/139620/1
authorSumin Lim <sumin.lim@samsung.com>
Wed, 19 Jul 2017 16:02:55 +0000 (01:02 +0900)
committerSumin Lim <sumin.lim@samsung.com>
Wed, 19 Jul 2017 16:03:20 +0000 (01:03 +0900)
Change-Id: Ia91ab0be4a5d140e81a4d84e7b0fdfa68fa04429

13 files changed:
README.md
src/iotjs_binding.c
src/iotjs_binding.h
src/iotjs_magic_strings.h
src/js/fs.js
src/modules/iotjs_module_fs.c
src/platform/linux/iotjs_module_pwm-linux.c
src/platform/linux/iotjs_module_spi-linux.c
src/platform/linux/iotjs_systemio-linux.c
src/platform/nuttx/iotjs_module_adc-nuttx.c
src/platform/nuttx/iotjs_module_i2c-nuttx.c
src/platform/nuttx/iotjs_module_pwm-nuttx.c
src/platform/tizenrt/iotjs_module_pwm-tizenrt.c

index 6ac772710366da97b816c0f58356e0883c710fdc..e1fd2be8776e5fd7c80c42f4e0b1f156e88e5d28 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
 # IoT.js: Platform for Internet of Things with JavaScript
+[![Join the chat at https://gitter.im/Samsung/iotjs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Samsung/iotjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
 [![License](https://img.shields.io/badge/licence-Apache%202.0-brightgreen.svg?style=flat)](LICENSE)
 [![Build Status](https://travis-ci.org/Samsung/iotjs.svg?branch=master)](https://travis-ci.org/Samsung/iotjs)
 [![Coverity Scan Build Status](https://img.shields.io/coverity/scan/12140.svg)](https://scan.coverity.com/projects/samsung-iotjs)
 [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2FSamsung%2Fiotjs.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2FSamsung%2Fiotjs?ref=badge_shield)
-[![IRC Channel](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://kiwiirc.com/client/irc.freenode.net/#iotjs)
 
 You can find project details on our [project page](http://samsung.github.io/iotjs/) and [wiki](https://github.com/Samsung/iotjs/wiki).
 
index 8d256e2343e10c05021975aa6498e3b43ef2c4c8..d3292d256c99c5cabb363577dc1f782c8d92a68c 100644 (file)
@@ -272,16 +272,6 @@ static jerry_value_t iotjs_jval_as_raw(const iotjs_jval_t* jval) {
 }
 
 
-bool iotjs_jval_set_prototype(const iotjs_jval_t* jobj, iotjs_jval_t* jproto) {
-  jerry_value_t ret =
-      jerry_set_prototype(iotjs_jval_as_raw(jobj), iotjs_jval_as_raw(jproto));
-  bool error_found = jerry_value_has_error_flag(ret);
-  jerry_release_value(ret);
-
-  return !error_found;
-}
-
-
 void iotjs_jval_set_method(const iotjs_jval_t* jobj, const char* name,
                            iotjs_native_handler_t handler) {
   IOTJS_VALIDATABLE_STRUCT_METHOD_VALIDATE(iotjs_jval_t, jobj);
index 16af73eba156668db7ce5d1a377c2049dc4e4492..0b9d2f85e67c426af9d623be9ebce47cb62f6ae0 100644 (file)
@@ -110,7 +110,6 @@ const iotjs_jval_t* iotjs_jval_as_array(THIS_JVAL);
 const iotjs_jval_t* iotjs_jval_as_function(THIS_JVAL);
 
 /* Methods for General JavaScript Object */
-bool iotjs_jval_set_prototype(const iotjs_jval_t* jobj, iotjs_jval_t* jproto);
 void iotjs_jval_set_method(THIS_JVAL, const char* name,
                            iotjs_native_handler_t handler);
 void iotjs_jval_set_property_jval(THIS_JVAL, const char* name,
index b5abb49605b0ca79e607eb0b24767dd47b5e408d..22bc61bd45749f32c9d0ca3c4aaff133ec346454 100644 (file)
 #define IOTJS_MAGIC_STRING_IPV6 "IPv6"
 #define IOTJS_MAGIC_STRING_ISALIVEEXCEPTFOR "isAliveExceptFor"
 #define IOTJS_MAGIC_STRING_ISDEVUP "isDevUp"
-#define IOTJS_MAGIC_STRING_ISDIRECTORY "isDirectory"
-#define IOTJS_MAGIC_STRING_ISFILE "isFile"
 #define IOTJS_MAGIC_STRING_KEY "key"
 #define IOTJS_MAGIC_STRING_LENGTH "length"
 #define IOTJS_MAGIC_STRING_LISTEN "listen"
 #define IOTJS_MAGIC_STRING_SPI "Spi"
 #define IOTJS_MAGIC_STRING_START "start"
 #define IOTJS_MAGIC_STRING_STAT "stat"
-#define IOTJS_MAGIC_STRING_STATS "stats"
 #define IOTJS_MAGIC_STRING_STATUS_MSG "status_msg"
 #define IOTJS_MAGIC_STRING_STATUS "status"
 #define IOTJS_MAGIC_STRING_STDERR "stderr"
index 90b6536758eaade896102a5741a5dbe430d28fd6..e568a09a9370d70a208be9ee67c379a0b80282e4 100644 (file)
@@ -19,6 +19,35 @@ var constants = require('constants');
 var util = require('util');
 var fsBuiltin = process.binding(process.binding.fs);
 
+fs.Stats = function(stat) {
+  this.dev = stat.dev;
+  this.mode = stat.mode;
+  this.nlink = stat.nlink;
+  this.uid = stat.uid;
+  this.gid = stat.gid;
+  this.rdev = stat.rdev;
+  this.blksize = stat.blksize;
+  this.ino = stat.ino;
+  this.size = stat.size;
+  this.blocks = stat.blocks;
+};
+
+
+fs.Stats.prototype.isDirectory = function() {
+  return ((this.mode & constants.S_IFMT) === constants.S_IFDIR);
+};
+
+
+fs.Stats.prototype.isFile = function() {
+  return ((this.mode & constants.S_IFMT) === constants.S_IFREG);
+};
+
+
+fsBuiltin._createStat = function(stat) {
+  return new fs.Stats(stat);
+};
+
+
 fs.exists = function(path, callback) {
   if (!path || !path.length) {
     process.nextTick(function () {
index 90c002b908db4e77d9438d05f6b1c17ec8cbc64b..5dde8498ef8df496d02720e7c52a1046897bd6ef 100644 (file)
@@ -312,15 +312,11 @@ JHANDLER_FUNCTION(Write) {
 iotjs_jval_t MakeStatObject(uv_stat_t* statbuf) {
   const iotjs_jval_t* fs = iotjs_module_get(MODULE_FS);
 
-  iotjs_jval_t stat_prototype =
-      iotjs_jval_get_property(fs, IOTJS_MAGIC_STRING_STATS);
-  IOTJS_ASSERT(iotjs_jval_is_object(&stat_prototype));
+  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();
-  iotjs_jval_set_prototype(&jstat, &stat_prototype);
-
-  iotjs_jval_destroy(&stat_prototype);
-
 
 #define X(statobj, name) \
   iotjs_jval_set_property_number(statobj, #name, statbuf->st_##name);
@@ -338,7 +334,17 @@ iotjs_jval_t MakeStatObject(uv_stat_t* statbuf) {
 
 #undef X
 
-  return jstat;
+  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;
 }
 
 
@@ -482,25 +488,6 @@ JHANDLER_FUNCTION(ReadDir) {
   iotjs_string_destroy(&path);
 }
 
-static void StatsIsTypeOf(iotjs_jhandler_t* jhandler, int type) {
-  DJHANDLER_CHECK_THIS(object);
-  const iotjs_jval_t* stats = JHANDLER_GET_THIS(object);
-  iotjs_jval_t mode = iotjs_jval_get_property(stats, IOTJS_MAGIC_STRING_MODE);
-
-  int mode_number = (int)iotjs_jval_as_number(&mode);
-
-  iotjs_jval_destroy(&mode);
-
-  iotjs_jhandler_return_boolean(jhandler, (mode_number & S_IFMT) == type);
-}
-
-JHANDLER_FUNCTION(StatsIsDirectory) {
-  StatsIsTypeOf(jhandler, S_IFDIR);
-}
-
-JHANDLER_FUNCTION(StatsIsFile) {
-  StatsIsTypeOf(jhandler, S_IFREG);
-}
 
 iotjs_jval_t InitFs() {
   iotjs_jval_t fs = iotjs_jval_create_object();
@@ -517,15 +504,5 @@ iotjs_jval_t InitFs() {
   iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_RENAME, Rename);
   iotjs_jval_set_method(&fs, IOTJS_MAGIC_STRING_READDIR, ReadDir);
 
-  iotjs_jval_t stats_prototype = iotjs_jval_create_object();
-
-  iotjs_jval_set_method(&stats_prototype, IOTJS_MAGIC_STRING_ISDIRECTORY,
-                        StatsIsDirectory);
-  iotjs_jval_set_method(&stats_prototype, IOTJS_MAGIC_STRING_ISFILE,
-                        StatsIsFile);
-
-  iotjs_jval_set_property_jval(&fs, IOTJS_MAGIC_STRING_STATS, &stats_prototype);
-  iotjs_jval_destroy(&stats_prototype);
-
   return fs;
 }
index bfca9672733366f0a914866c50890ebb2eca9518..e2d72b93f7eca88ce124d604a69e197d92458fc0 100644 (file)
@@ -135,7 +135,7 @@ bool iotjs_pwm_set_period(iotjs_pwm_t* pwm) {
     if (devicePath) {
       // Linux API uses nanoseconds, thus 1E9
       unsigned int value = (unsigned)(adjust_period(_this->period) * 1.E9);
-      DDDLOG("%s - path: %s, value: %fs", __func__, devicePath, 1.E-9 * value);
+      DDLOG("%s - path: %s, value: %fs", __func__, devicePath, 1.E-9 * value);
       char buf[PWM_VALUE_BUFFER_SIZE];
       if (snprintf(buf, sizeof(buf), "%d", value) > 0) {
         result = iotjs_systemio_open_write_close(devicePath, buf);
@@ -161,8 +161,7 @@ bool iotjs_pwm_set_dutycycle(iotjs_pwm_t* pwm) {
       // Linux API uses nanoseconds, thus 1E9
       unsigned dutyCycleValue = (unsigned)(period * _this->duty_cycle * 1E9);
 
-      DDDLOG("%s - path: %s, value: %d\n", __func__, devicePath,
-             dutyCycleValue);
+      DDLOG("%s - path: %s, value: %d\n", __func__, devicePath, dutyCycleValue);
       char buf[PWM_VALUE_BUFFER_SIZE];
       if (snprintf(buf, sizeof(buf), "%d", dutyCycleValue) < 0) {
         return false;
@@ -188,7 +187,7 @@ bool iotjs_pwm_set_enable(iotjs_pwm_t* pwm) {
       return false;
     }
 
-    DDDLOG("%s - path: %s, set: %d\n", __func__, devicePath, _this->enable);
+    DDLOG("%s - path: %s, set: %d\n", __func__, devicePath, _this->enable);
     char buf[PWM_VALUE_BUFFER_SIZE];
     if (snprintf(buf, sizeof(buf), "%d", _this->enable) < 0) {
       return false;
index ab4e8be2b2601f1c2d01bf40a240b091cc881448..338c01889ed40abbaf16ee2a076ac5b2e4f3cd95 100644 (file)
@@ -84,7 +84,7 @@ static bool iotjs_spi_set_configuration(iotjs_spi_t* spi) {
     return false;
   }
 
-  DDDLOG(
+  DDLOG(
       "SPI Options \n mode: %d\n chipSelect: %d\n bitOrder: %d\n "
       "maxSpeed: %d\n bitPerWord: %d\n loopback: %d",
       _this->mode, _this->chip_select, _this->bit_order, _this->max_speed,
@@ -107,7 +107,7 @@ bool iotjs_spi_transfer(iotjs_spi_t* spi) {
   // Transfer data
   int err = ioctl(_this->device_fd, SPI_IOC_MESSAGE(1), &data);
   if (err < 1) {
-    DLOG("%s - transfer failed: %d", __func__, err);
+    DDLOG("%s - transfer failed: %d", __func__, err);
     return false;
   }
 
@@ -126,7 +126,7 @@ bool iotjs_spi_close(iotjs_spi_t* spi) {
     int err = uv_fs_close(loop, &fs_close_req, _this->device_fd, NULL);
     uv_fs_req_cleanup(&fs_close_req);
     if (err < 0) {
-      DLOG("%s - close failed: %d", __func__, err);
+      DDLOG("%s - close failed: %d", __func__, err);
       return false;
     }
     _this->device_fd = -1;
index e6a05fb4097e779cb048f918d5279631809906fc..452bbbffa6428502a5972aea96f8b1bebcfeb0c6 100644 (file)
@@ -53,7 +53,7 @@ bool iotjs_systemio_open_write_close(const char* path, const char* value) {
   int fd = uv_fs_open(loop, &fs_req, path, O_WRONLY, 0666, NULL);
   uv_fs_req_cleanup(&fs_req);
   if (fd < 0) {
-    DLOG("%s - open %s failed: %d", __func__, path, fd);
+    DDLOG("%s - open %s failed: %d", __func__, path, fd);
     return false;
   }
 
@@ -68,12 +68,12 @@ bool iotjs_systemio_open_write_close(const char* path, const char* value) {
   uv_fs_req_cleanup(&fs_req);
 
   if (write_err < 0) {
-    DLOG("%s - write %s %s failed: %d", __func__, path, value, write_err);
+    DDLOG("%s - write %s %s failed: %d", __func__, path, value, write_err);
     return false;
   }
 
   if (close_err < 0) {
-    DLOG("%s - close failed: %d", __func__, close_err);
+    DDLOG("%s - close failed: %d", __func__, close_err);
     return false;
   }
 
@@ -93,7 +93,7 @@ bool iotjs_systemio_open_read_close(const char* path, char* buffer,
   int fd = uv_fs_open(loop, &fs_open_req, path, O_RDONLY, 0666, NULL);
   uv_fs_req_cleanup(&fs_open_req);
   if (fd < 0) {
-    DLOG("%s - open %s failed: %d", __func__, path, fd);
+    DDLOG("%s - open %s failed: %d", __func__, path, fd);
     return false;
   }
 
@@ -103,7 +103,7 @@ bool iotjs_systemio_open_read_close(const char* path, char* buffer,
   int err = uv_fs_read(loop, &fs_write_req, fd, &uvbuf, 1, 0, NULL);
   uv_fs_req_cleanup(&fs_write_req);
   if (err < 0) {
-    DLOG("%s - read failed: %d", __func__, err);
+    DDLOG("%s - read failed: %d", __func__, err);
     return false;
   }
 
@@ -114,7 +114,7 @@ bool iotjs_systemio_open_read_close(const char* path, char* buffer,
   err = uv_fs_close(loop, &fs_close_req, fd, NULL);
   uv_fs_req_cleanup(&fs_close_req);
   if (err < 0) {
-    DLOG("%s - close failed: %d", __func__, err);
+    DDLOG("%s - close failed: %d", __func__, err);
     return false;
   }
 
@@ -132,7 +132,7 @@ bool iotjs_systemio_device_open(const char* export_path, uint32_t value,
     return true;
   }
 
-  DDDLOG("%s - path: %s", __func__, export_path);
+  DDLOG("%s - path: %s", __func__, export_path);
 
   // Write export pin.
   char buff[DEVICE_IO_PIN_BUFFER_SIZE] = { 0 };
@@ -161,7 +161,7 @@ bool iotjs_systemio_device_open(const char* export_path, uint32_t value,
     snprintf(path, DEVICE_IO_PATH_BUFFER_SIZE - 1, check_format,
              created_files[i]);
 
-    DDDLOG("%s - created file: %s", __func__, path);
+    DDLOG("%s - created file: %s", __func__, path);
 
     while (!iotjs_systemio_open_read_close(path, buffer,
                                            DEVICE_IO_PIN_BUFFER_SIZE) &&
index 4397c0513853d9c334594de221a9fb052bf783fc..a2f9eb09fc49420120dedfb86e4a9758d0134877 100644 (file)
@@ -68,7 +68,7 @@ static bool iotjs_adc_read_data(uint32_t pin, struct adc_msg_s* msg) {
     return false;
   }
 
-  DDDLOG("ADC Read - path: %s, value: %d", path, msg->am_data);
+  DDLOG("ADC Read - path: %s, value: %d", path, msg->am_data);
 
   return true;
 }
@@ -124,8 +124,8 @@ void iotjs_adc_open_worker(uv_work_t* work_req) {
     return;
   }
 
-  DDDLOG("%s - path: %s, number: %d, timer: %d", __func__, path, adc_number,
-         timer);
+  DDLOG("%s - path: %s, number: %d, timer: %d", __func__, path, adc_number,
+        timer);
 
   req_data->result = true;
 }
index 31f73fed74c7cf260752777b4cc958745c438afc..14dcfe990c15453da82ec629281029885747bea0 100644 (file)
@@ -42,7 +42,7 @@ void OpenWorker(uv_work_t* work_req) {
   IOTJS_VALIDATED_STRUCT_METHOD(iotjs_i2c_t, i2c);
   _this->i2c_master = iotjs_i2c_config_nuttx(req_data->device);
   if (!_this->i2c_master) {
-    DLOG("I2C OpenWorker : cannot open");
+    DDLOG("I2C OpenWorker : cannot open");
     req_data->error = kI2cErrOpen;
     return;
   }
@@ -73,7 +73,7 @@ void WriteWorker(uv_work_t* work_req) {
 
   int ret = i2c_write(_this->i2c_master, &_this->config, data, len);
   if (ret < 0) {
-    DLOG("I2C WriteWorker : cannot write - %d", ret);
+    DDLOG("I2C WriteWorker : cannot write - %d", ret);
     req_data->error = kI2cErrWrite;
   } else {
     req_data->error = kI2cErrOk;
@@ -101,7 +101,7 @@ void ReadWorker(uv_work_t* work_req) {
   int ret = i2c_read(_this->i2c_master, &_this->config,
                      (uint8_t*)req_data->buf_data, len);
   if (ret != 0) {
-    DLOG("I2C ReadWorker : cannot read - %d", ret);
+    DDLOG("I2C ReadWorker : cannot read - %d", ret);
     req_data->error = kI2cErrRead;
     return;
   }
index f1b676cc82c12872cb10b2497ce85e03e89147b8..3f3f3415afec749285dc829319c45a044d7bd77d 100644 (file)
@@ -34,7 +34,7 @@ static bool iotjs_pwm_set_options(iotjs_pwm_t* pwm) {
 
   int fd = _this->device_fd;
   if (fd < 0) {
-    DLOG("%s - file open failed", __func__);
+    DDLOG("%s - file open failed", __func__);
     return false;
   }
 
@@ -90,7 +90,7 @@ void iotjs_pwm_open_worker(uv_work_t* work_req) {
   // File open
   _this->device_fd = open(path, O_RDONLY);
   if (_this->device_fd < 0) {
-    DLOG("%s - file open failed", __func__);
+    DDLOG("%s - file open failed", __func__);
     req_data->result = false;
     return;
   }
@@ -119,7 +119,7 @@ bool iotjs_pwm_set_enable(iotjs_pwm_t* pwm) {
 
   int fd = _this->device_fd;
   if (fd < 0) {
-    DLOG("%s - file open failed", __func__);
+    DDLOG("%s - file open failed", __func__);
     return false;
   }
 
@@ -133,7 +133,7 @@ bool iotjs_pwm_set_enable(iotjs_pwm_t* pwm) {
   }
 
   if (ret < 0) {
-    DLOG("%s - setEnable failed", __func__);
+    DDLOG("%s - setEnable failed", __func__);
     return false;
   }
 
@@ -146,7 +146,7 @@ bool iotjs_pwm_close(iotjs_pwm_t* pwm) {
 
   int fd = _this->device_fd;
   if (fd < 0) {
-    DLOG("%s - file not opened", __func__);
+    DDLOG("%s - file not opened", __func__);
     return false;
   }
 
index 156213fa1957dce2d9d0991d7a1d12aaaca79c39..ff6e3c1d489db7da868e5904dcb57a69d37a489d 100644 (file)
@@ -27,7 +27,7 @@ static bool iotjs_pwm_set_options(iotjs_pwm_t* pwm) {
 
   iotbus_pwm_context_h ctx = _this->ctx;
   if (ctx == NULL) {
-    DLOG("%s - file open failed", __func__);
+    DDLOG("%s - file open failed", __func__);
     return false;
   }
 
@@ -43,7 +43,7 @@ void iotjs_pwm_open_worker(uv_work_t* work_req) {
 
   _this->ctx = iotbus_pwm_open(0, (int)_this->pin);
   if (_this->ctx == NULL) {
-    DLOG("%s - file open failed", __func__);
+    DDLOG("%s - file open failed", __func__);
     req_data->result = false;
     return;
   }
@@ -61,7 +61,7 @@ bool iotjs_pwm_set_period(iotjs_pwm_t* pwm) {
 
   iotbus_pwm_context_h ctx = _this->ctx;
   if (ctx == NULL) {
-    DLOG("%s - file open failed", __func__);
+    DDLOG("%s - file open failed", __func__);
     return false;
   }
 
@@ -76,7 +76,7 @@ bool iotjs_pwm_set_dutycycle(iotjs_pwm_t* pwm) {
 
   iotbus_pwm_context_h ctx = _this->ctx;
   if (ctx == NULL) {
-    DLOG("%s - file open failed", __func__);
+    DDLOG("%s - file open failed", __func__);
     return false;
   }
 
@@ -91,7 +91,7 @@ bool iotjs_pwm_set_enable(iotjs_pwm_t* pwm) {
 
   iotbus_pwm_context_h ctx = _this->ctx;
   if (ctx == NULL) {
-    DLOG("%s - file open failed", __func__);
+    DDLOG("%s - file open failed", __func__);
     return false;
   }
 
@@ -105,7 +105,7 @@ bool iotjs_pwm_set_enable(iotjs_pwm_t* pwm) {
   }
 
   if (ret < 0) {
-    DLOG("%s - setEnable failed", __func__);
+    DDLOG("%s - setEnable failed", __func__);
     return false;
   }
 
@@ -117,7 +117,7 @@ bool iotjs_pwm_close(iotjs_pwm_t* pwm) {
 
   iotbus_pwm_context_h ctx = _this->ctx;
   if (ctx == NULL) {
-    DLOG("%s - file not opened", __func__);
+    DDLOG("%s - file not opened", __func__);
     return false;
   }