浏览代码

Apply clang-format for more source files (#795)

Apply clang-format for C source files in folder core/app-mgr,
core/app-framework, and test-tools.
And rename folder component_test to component-test, update
zephyr build document.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
Wenyong Huang 4 年之前
父节点
当前提交
32242988ed
共有 100 个文件被更改,包括 3639 次插入3126 次删除
  1. 1 1
      .github/workflows/codeing_guildelines.yml
  2. 288 252
      core/app-framework/app-native-shared/attr_container.c
  3. 19 20
      core/app-framework/app-native-shared/bi-inc/attr_container.h
  4. 21 22
      core/app-framework/app-native-shared/bi-inc/shared_utils.h
  5. 0 2
      core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h
  6. 0 2
      core/app-framework/app-native-shared/native_interface.h
  7. 37 34
      core/app-framework/app-native-shared/restful_utils.c
  8. 7 8
      core/app-framework/app_ext_lib_export.c
  9. 18 10
      core/app-framework/base/app/bh_platform.c
  10. 20 17
      core/app-framework/base/app/bh_platform.h
  11. 0 1
      core/app-framework/base/app/req_resp_api.h
  12. 56 40
      core/app-framework/base/app/request.c
  13. 19 14
      core/app-framework/base/app/timer.c
  14. 0 1
      core/app-framework/base/app/timer_api.h
  15. 34 33
      core/app-framework/base/app/wa-inc/request.h
  16. 8 5
      core/app-framework/base/app/wa-inc/timer_wasm_app.h
  17. 0 1
      core/app-framework/base/app/wasm_app.h
  18. 5 6
      core/app-framework/base/native/base_lib_export.c
  19. 0 1
      core/app-framework/base/native/req_resp_native_api.h
  20. 8 8
      core/app-framework/base/native/request_response.c
  21. 10 6
      core/app-framework/base/native/runtime_lib.h
  22. 3 6
      core/app-framework/base/native/timer_native_api.h
  23. 20 23
      core/app-framework/base/native/timer_wrapper.c
  24. 19 20
      core/app-framework/connection/app/connection.c
  25. 0 1
      core/app-framework/connection/app/connection_api.h
  26. 11 12
      core/app-framework/connection/app/wa-inc/connection.h
  27. 3 5
      core/app-framework/connection/native/connection_lib.h
  28. 7 12
      core/app-framework/connection/native/connection_native_api.h
  29. 8 8
      core/app-framework/connection/native/connection_wrapper.c
  30. 7 4
      core/app-framework/connection/native/linux/conn_tcp.c
  31. 6 4
      core/app-framework/connection/native/linux/conn_tcp.h
  32. 8 4
      core/app-framework/connection/native/linux/conn_uart.c
  33. 6 4
      core/app-framework/connection/native/linux/conn_uart.h
  34. 8 9
      core/app-framework/connection/native/linux/conn_udp.c
  35. 6 4
      core/app-framework/connection/native/linux/conn_udp.h
  36. 108 84
      core/app-framework/connection/native/linux/connection_mgr.c
  37. 6 4
      core/app-framework/connection/native/zephyr/connection_lib_impl.c
  38. 21 14
      core/app-framework/sensor/app/sensor.c
  39. 1 2
      core/app-framework/sensor/app/sensor_api.h
  40. 11 9
      core/app-framework/sensor/app/wa-inc/sensor.h
  41. 59 51
      core/app-framework/sensor/native/runtime_sensor.c
  42. 31 22
      core/app-framework/sensor/native/runtime_sensor.h
  43. 35 35
      core/app-framework/sensor/native/sensor_mgr_ref.c
  44. 4 7
      core/app-framework/sensor/native/sensor_native_api.h
  45. 0 2
      core/app-framework/wgl/app/gui_api.h
  46. 41 27
      core/app-framework/wgl/app/src/wgl_btn.c
  47. 22 18
      core/app-framework/wgl/app/src/wgl_cb.c
  48. 79 80
      core/app-framework/wgl/app/src/wgl_label.c
  49. 27 27
      core/app-framework/wgl/app/src/wgl_list.c
  50. 24 16
      core/app-framework/wgl/app/src/wgl_obj.c
  51. 287 163
      core/app-framework/wgl/app/wa-inc/lvgl/lv_obj.h
  52. 0 4
      core/app-framework/wgl/app/wa-inc/lvgl/lvgl.h
  53. 3 5
      core/app-framework/wgl/app/wa-inc/lvgl/test.c
  54. 10 12
      core/app-framework/wgl/native/gui_native_api.h
  55. 4 2
      core/app-framework/wgl/native/wgl.h
  56. 19 21
      core/app-framework/wgl/native/wgl_btn_wrapper.c
  57. 11 14
      core/app-framework/wgl/native/wgl_cb_wrapper.c
  58. 11 12
      core/app-framework/wgl/native/wgl_label_wrapper.c
  59. 9 11
      core/app-framework/wgl/native/wgl_list_wrapper.c
  60. 12 17
      core/app-framework/wgl/native/wgl_native_utils.c
  61. 21 22
      core/app-framework/wgl/native/wgl_native_utils.h
  62. 55 52
      core/app-framework/wgl/native/wgl_obj_wrapper.c
  63. 56 46
      core/app-mgr/app-manager/app_manager.c
  64. 14 12
      core/app-mgr/app-manager/app_manager.h
  65. 26 20
      core/app-mgr/app-manager/app_manager_host.c
  66. 1 2
      core/app-mgr/app-manager/app_manager_host.h
  67. 1 1
      core/app-mgr/app-manager/ble_msg.c
  68. 40 28
      core/app-mgr/app-manager/event.c
  69. 1 1
      core/app-mgr/app-manager/event.h
  70. 10 8
      core/app-mgr/app-manager/message.c
  71. 1351 1201
      core/app-mgr/app-manager/module_jeff.c
  72. 34 23
      core/app-mgr/app-manager/module_utils.c
  73. 300 277
      core/app-mgr/app-manager/module_wasm_app.c
  74. 8 6
      core/app-mgr/app-manager/module_wasm_app.h
  75. 27 18
      core/app-mgr/app-manager/module_wasm_lib.c
  76. 12 9
      core/app-mgr/app-manager/platform/linux/app_mgr_linux.c
  77. 14 10
      core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c
  78. 31 24
      core/app-mgr/app-manager/resource_reg.c
  79. 27 19
      core/app-mgr/app-manager/watchdog.c
  80. 1 2
      core/app-mgr/app-manager/watchdog.h
  81. 27 18
      core/app-mgr/app-mgr-shared/app_manager_export.h
  82. 3 3
      core/iwasm/aot/arch/aot_reloc_x86_32.c
  83. 1 1
      doc/build_wamr.md
  84. 30 30
      test-tools/binarydump-tool/binarydump.c
  85. 0 0
      test-tools/component-test/README.md
  86. 0 0
      test-tools/component-test/__init__.py
  87. 0 0
      test-tools/component-test/framework/__init__.py
  88. 0 0
      test-tools/component-test/framework/case_base.py
  89. 0 0
      test-tools/component-test/framework/engine.py
  90. 0 0
      test-tools/component-test/framework/framework.py
  91. 0 0
      test-tools/component-test/framework/suite.py
  92. 0 0
      test-tools/component-test/framework/test_api.py
  93. 0 0
      test-tools/component-test/framework/test_utils.py
  94. 0 0
      test-tools/component-test/harness/__init__.py
  95. 0 0
      test-tools/component-test/harness/harness_api.py
  96. 50 34
      test-tools/component-test/host-clients/src/host_app_sample.c
  97. 0 0
      test-tools/component-test/host-clients/src/makefile
  98. 0 0
      test-tools/component-test/set_dev_env.sh
  99. 0 0
      test-tools/component-test/start.py
  100. 0 0
      test-tools/component-test/suites/01-life-cycle/__init__.py

+ 1 - 1
.github/workflows/codeing_guildelines.yml

@@ -33,7 +33,7 @@ jobs:
         uses: actions/checkout@v2
         with:
           fetch-depth: 0
-      
+
       # github.event.pull_request.base.label = ${{github.repository}}/${{github.base_ref}}
       - name: Run Coding Guidelines Checks
         run: /usr/bin/env python3 ./ci/coding_guidelines_check.py --commits ${{ github.event.pull_request.base.sha }}..HEAD

+ 288 - 252
core/app-framework/app-native-shared/attr_container.c

@@ -16,79 +16,89 @@ typedef union jvalue {
     double d;
 } jvalue;
 
-
-
-static inline int16_t get_int16(const char *buf)
+static inline int16_t
+get_int16(const char *buf)
 {
     int16_t ret;
     bh_memcpy_s(&ret, sizeof(int16_t), buf, sizeof(int16_t));
     return ret;
 }
 
-static inline uint16_t get_uint16(const char *buf)
+static inline uint16_t
+get_uint16(const char *buf)
 {
     return get_int16(buf);
 }
 
-static inline int32_t get_int32(const char *buf)
+static inline int32_t
+get_int32(const char *buf)
 {
     int32_t ret;
     bh_memcpy_s(&ret, sizeof(int32_t), buf, sizeof(int32_t));
     return ret;
 }
 
-static inline uint32_t get_uint32(const char *buf)
+static inline uint32_t
+get_uint32(const char *buf)
 {
     return get_int32(buf);
 }
 
-static inline int64_t get_int64(const char *buf)
+static inline int64_t
+get_int64(const char *buf)
 {
     int64_t ret;
     bh_memcpy_s(&ret, sizeof(int64_t), buf, sizeof(int64_t));
     return ret;
 }
 
-static inline uint64_t get_uint64(const char *buf)
+static inline uint64_t
+get_uint64(const char *buf)
 {
     return get_int64(buf);
 }
 
-static inline void set_int16(char *buf, int16_t v)
+static inline void
+set_int16(char *buf, int16_t v)
 {
     bh_memcpy_s(buf, sizeof(int16_t), &v, sizeof(int16_t));
 }
 
-static inline void set_uint16(char *buf, uint16_t v)
+static inline void
+set_uint16(char *buf, uint16_t v)
 {
     bh_memcpy_s(buf, sizeof(uint16_t), &v, sizeof(uint16_t));
 }
 
-static inline void set_int32(char *buf, int32_t v)
+static inline void
+set_int32(char *buf, int32_t v)
 {
     bh_memcpy_s(buf, sizeof(int32_t), &v, sizeof(int32_t));
 }
 
-static inline void set_uint32(char *buf, uint32_t v)
+static inline void
+set_uint32(char *buf, uint32_t v)
 {
     bh_memcpy_s(buf, sizeof(uint32_t), &v, sizeof(uint32_t));
 }
 
-static inline void set_int64(char *buf, int64_t v)
+static inline void
+set_int64(char *buf, int64_t v)
 {
     bh_memcpy_s(buf, sizeof(int64_t), &v, sizeof(int64_t));
 }
 
-static inline void set_uint64(char *buf, uint64_t v)
+static inline void
+set_uint64(char *buf, uint64_t v)
 {
     bh_memcpy_s(buf, sizeof(uint64_t), &v, sizeof(uint64_t));
 }
 
-char*
+char *
 attr_container_get_attr_begin(const attr_container_t *attr_cont,
-        uint32_t *p_total_length, uint16_t *p_attr_num)
+                              uint32_t *p_total_length, uint16_t *p_attr_num)
 {
-    char *p = (char*) attr_cont->buf;
+    char *p = (char *)attr_cont->buf;
     uint16_t str_len, attr_num;
     uint32_t total_length;
 
@@ -125,10 +135,10 @@ attr_container_get_attr_begin(const attr_container_t *attr_cont,
     return p;
 }
 
-static char*
+static char *
 attr_container_get_attr_next(const char *curr_attr)
 {
-    char *p = (char*) curr_attr;
+    char *p = (char *)curr_attr;
     uint8_t type;
 
     /* key length and key */
@@ -154,7 +164,7 @@ attr_container_get_attr_next(const char *curr_attr)
     return NULL;
 }
 
-static const char*
+static const char *
 attr_container_find_attr(const attr_container_t *attr_cont, const char *key)
 {
     uint32_t total_length;
@@ -164,7 +174,8 @@ attr_container_find_attr(const attr_container_t *attr_cont, const char *key)
     if (!key)
         return NULL;
 
-    if (!(p = attr_container_get_attr_begin(attr_cont, &total_length, &attr_num)))
+    if (!(p = attr_container_get_attr_begin(attr_cont, &total_length,
+                                            &attr_num)))
         return NULL;
 
     for (i = 0; i < attr_num; i++) {
@@ -173,9 +184,9 @@ attr_container_find_attr(const attr_container_t *attr_cont, const char *key)
             return NULL;
 
         if (str_len == strlen(key) + 1
-                && memcmp(p + sizeof(uint16_t), key, str_len) == 0) {
-            if ((uint32_t)(p + sizeof(uint16_t) + str_len
-                           - attr_cont->buf) >= total_length)
+            && memcmp(p + sizeof(uint16_t), key, str_len) == 0) {
+            if ((uint32_t)(p + sizeof(uint16_t) + str_len - attr_cont->buf)
+                >= total_length)
                 return NULL;
             return p;
         }
@@ -187,14 +198,15 @@ attr_container_find_attr(const attr_container_t *attr_cont, const char *key)
     return NULL;
 }
 
-char*
+char *
 attr_container_get_attr_end(const attr_container_t *attr_cont)
 {
     uint32_t total_length;
     uint16_t attr_num, i;
     char *p;
 
-    if (!(p = attr_container_get_attr_begin(attr_cont, &total_length, &attr_num)))
+    if (!(p = attr_container_get_attr_begin(attr_cont, &total_length,
+                                            &attr_num)))
         return NULL;
 
     for (i = 0; i < attr_num; i++)
@@ -204,14 +216,15 @@ attr_container_get_attr_end(const attr_container_t *attr_cont)
     return p;
 }
 
-static char*
+static char *
 attr_container_get_msg_end(attr_container_t *attr_cont)
 {
     char *p = attr_cont->buf;
     return p + get_uint32(p);
 }
 
-uint16_t attr_container_get_attr_num(const attr_container_t *attr_cont)
+uint16_t
+attr_container_get_attr_num(const attr_container_t *attr_cont)
 {
     uint16_t str_len;
     /* skip total length */
@@ -225,7 +238,8 @@ uint16_t attr_container_get_attr_num(const attr_container_t *attr_cont)
     return get_uint16(p);
 }
 
-static void attr_container_inc_attr_num(attr_container_t *attr_cont)
+static void
+attr_container_inc_attr_num(attr_container_t *attr_cont)
 {
     uint16_t str_len, attr_num;
     /* skip total length */
@@ -249,12 +263,12 @@ attr_container_create(const char *tag)
 
     tag_length = tag ? strlen(tag) + 1 : 1;
     length = offsetof(attr_container_t, buf) +
-    /* total length + tag length + tag + reserved 100 bytes */
-    sizeof(uint32_t) + sizeof(uint16_t) + tag_length + 100;
+             /* total length + tag length + tag + reserved 100 bytes */
+             sizeof(uint32_t) + sizeof(uint16_t) + tag_length + 100;
 
     if (!(attr_cont = attr_container_malloc(length))) {
         attr_container_printf(
-                "Create attr_container failed: allocate memory failed.\r\n");
+            "Create attr_container failed: allocate memory failed.\r\n");
         return NULL;
     }
 
@@ -274,34 +288,37 @@ attr_container_create(const char *tag)
     return attr_cont;
 }
 
-void attr_container_destroy(const attr_container_t *attr_cont)
+void
+attr_container_destroy(const attr_container_t *attr_cont)
 {
     if (attr_cont)
-        attr_container_free((char*) attr_cont);
+        attr_container_free((char *)attr_cont);
 }
 
-static bool check_set_attr(attr_container_t **p_attr_cont, const char *key)
+static bool
+check_set_attr(attr_container_t **p_attr_cont, const char *key)
 {
     uint32_t flags;
 
     if (!p_attr_cont || !*p_attr_cont || !key || strlen(key) == 0) {
         attr_container_printf(
-                "Set attribute failed: invalid input arguments.\r\n");
+            "Set attribute failed: invalid input arguments.\r\n");
         return false;
     }
 
-    flags = get_uint32((char*) *p_attr_cont);
+    flags = get_uint32((char *)*p_attr_cont);
     if (flags & ATTR_CONT_READONLY_SHIFT) {
         attr_container_printf(
-                "Set attribute failed: attribute container is readonly.\r\n");
+            "Set attribute failed: attribute container is readonly.\r\n");
         return false;
     }
 
     return true;
 }
 
-bool attr_container_set_attr(attr_container_t **p_attr_cont, const char *key,
-        int type, const void *value, int value_length)
+bool
+attr_container_set_attr(attr_container_t **p_attr_cont, const char *key,
+                        int type, const void *value, int value_length)
 {
     attr_container_t *attr_cont, *attr_cont1;
     uint16_t str_len;
@@ -351,13 +368,14 @@ bool attr_container_set_attr(attr_container_t **p_attr_cont, const char *key,
         set_uint16(p, value_length);
         p += sizeof(uint16_t);
         bh_memcpy_s(p, value_length, value, value_length);
-    } else if (type == ATTR_TYPE_BYTEARRAY) {
+    }
+    else if (type == ATTR_TYPE_BYTEARRAY) {
         set_uint32(p, value_length);
         p += sizeof(uint32_t);
         bh_memcpy_s(p, value_length, value, value_length);
     }
 
-    if ((p = (char*) attr_container_find_attr(attr_cont, key))) {
+    if ((p = (char *)attr_container_find_attr(attr_cont, key))) {
         /* key found */
         p1 = attr_container_get_attr_next(p);
 
@@ -375,22 +393,21 @@ bool attr_container_set_attr(attr_container_t **p_attr_cont, const char *key,
         }
 
         total_length += attr_len + 100;
-        if (!(attr_cont1 = attr_container_malloc(
-                offsetof(attr_container_t, buf) + total_length))) {
+        if (!(attr_cont1 = attr_container_malloc(offsetof(attr_container_t, buf)
+                                                 + total_length))) {
             attr_container_printf(
-                    "Set attr failed: allocate memory failed.\r\n");
+                "Set attr failed: allocate memory failed.\r\n");
             attr_container_free(attr_buf);
             return false;
         }
 
-        bh_memcpy_s(attr_cont1, p - (char* )attr_cont, attr_cont,
-                p - (char* )attr_cont);
-        bh_memcpy_s((char* )attr_cont1 + (unsigned )(p - (char* )attr_cont),
-                attr_end - p1, p1, attr_end - p1);
-        bh_memcpy_s(
-                (char* )attr_cont1 + (unsigned )(p - (char* )attr_cont)
-                        + (unsigned )(attr_end - p1), attr_len, attr_buf,
-                attr_len);
+        bh_memcpy_s(attr_cont1, p - (char *)attr_cont, attr_cont,
+                    p - (char *)attr_cont);
+        bh_memcpy_s((char *)attr_cont1 + (unsigned)(p - (char *)attr_cont),
+                    attr_end - p1, p1, attr_end - p1);
+        bh_memcpy_s((char *)attr_cont1 + (unsigned)(p - (char *)attr_cont)
+                        + (unsigned)(attr_end - p1),
+                    attr_len, attr_buf, attr_len);
         p = attr_cont1->buf;
         set_uint32(p, total_length);
         *p_attr_cont = attr_cont1;
@@ -398,7 +415,8 @@ bool attr_container_set_attr(attr_container_t **p_attr_cont, const char *key,
         attr_container_free(attr_cont);
         attr_container_free(attr_buf);
         return true;
-    } else {
+    }
+    else {
         /* key not found */
         if ((uint32_t)(msg_end - attr_end) >= attr_len) {
             bh_memcpy_s(attr_end, msg_end - attr_end, attr_buf, attr_len);
@@ -408,19 +426,19 @@ bool attr_container_set_attr(attr_container_t **p_attr_cont, const char *key,
         }
 
         total_length += attr_len + 100;
-        if (!(attr_cont1 = attr_container_malloc(
-                offsetof(attr_container_t, buf) + total_length))) {
+        if (!(attr_cont1 = attr_container_malloc(offsetof(attr_container_t, buf)
+                                                 + total_length))) {
             attr_container_printf(
-                    "Set attr failed: allocate memory failed.\r\n");
+                "Set attr failed: allocate memory failed.\r\n");
             attr_container_free(attr_buf);
             return false;
         }
 
-        bh_memcpy_s(attr_cont1, attr_end - (char* )attr_cont, attr_cont,
-                attr_end - (char* )attr_cont);
-        bh_memcpy_s(
-                (char* )attr_cont1 + (unsigned )(attr_end - (char* )attr_cont),
-                attr_len, attr_buf, attr_len);
+        bh_memcpy_s(attr_cont1, attr_end - (char *)attr_cont, attr_cont,
+                    attr_end - (char *)attr_cont);
+        bh_memcpy_s((char *)attr_cont1
+                        + (unsigned)(attr_end - (char *)attr_cont),
+                    attr_len, attr_buf, attr_len);
         attr_container_inc_attr_num(attr_cont1);
         p = attr_cont1->buf;
         set_uint32(p, total_length);
@@ -434,88 +452,101 @@ bool attr_container_set_attr(attr_container_t **p_attr_cont, const char *key,
     return false;
 }
 
-bool attr_container_set_short(attr_container_t **p_attr_cont, const char *key,
-        short value)
+bool
+attr_container_set_short(attr_container_t **p_attr_cont, const char *key,
+                         short value)
 {
-    return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_SHORT, &value, 2);
+    return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_SHORT, &value,
+                                   2);
 }
 
-bool attr_container_set_int(attr_container_t **p_attr_cont, const char *key,
-        int value)
+bool
+attr_container_set_int(attr_container_t **p_attr_cont, const char *key,
+                       int value)
 {
     return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT, &value, 4);
 }
 
-bool attr_container_set_int64(attr_container_t **p_attr_cont, const char *key,
-        int64_t value)
+bool
+attr_container_set_int64(attr_container_t **p_attr_cont, const char *key,
+                         int64_t value)
 {
-    return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT64, &value, 8);
+    return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT64, &value,
+                                   8);
 }
 
-bool attr_container_set_byte(attr_container_t **p_attr_cont, const char *key,
-        int8_t value)
+bool
+attr_container_set_byte(attr_container_t **p_attr_cont, const char *key,
+                        int8_t value)
 {
     return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_BYTE, &value, 1);
 }
 
-bool attr_container_set_uint16(attr_container_t **p_attr_cont, const char *key,
-        uint16_t value)
+bool
+attr_container_set_uint16(attr_container_t **p_attr_cont, const char *key,
+                          uint16_t value)
 {
     return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT16, &value,
-            2);
+                                   2);
 }
 
-bool attr_container_set_float(attr_container_t **p_attr_cont, const char *key,
-        float value)
+bool
+attr_container_set_float(attr_container_t **p_attr_cont, const char *key,
+                         float value)
 {
-    return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_FLOAT, &value, 4);
+    return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_FLOAT, &value,
+                                   4);
 }
 
-bool attr_container_set_double(attr_container_t **p_attr_cont, const char *key,
-        double value)
+bool
+attr_container_set_double(attr_container_t **p_attr_cont, const char *key,
+                          double value)
 {
     return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_DOUBLE, &value,
-            8);
+                                   8);
 }
 
-bool attr_container_set_bool(attr_container_t **p_attr_cont, const char *key,
-        bool value)
+bool
+attr_container_set_bool(attr_container_t **p_attr_cont, const char *key,
+                        bool value)
 {
     int8_t value1 = value ? 1 : 0;
     return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_BOOLEAN, &value1,
-            1);
+                                   1);
 }
 
-bool attr_container_set_string(attr_container_t **p_attr_cont, const char *key,
-        const char *value)
+bool
+attr_container_set_string(attr_container_t **p_attr_cont, const char *key,
+                          const char *value)
 {
     if (!value) {
         attr_container_printf("Set attr failed: invald input arguments.\r\n");
         return false;
     }
     return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_STRING, value,
-            strlen(value) + 1);;
+                                   strlen(value) + 1);
 }
 
-bool attr_container_set_bytearray(attr_container_t **p_attr_cont,
-        const char *key, const int8_t *value, unsigned length)
+bool
+attr_container_set_bytearray(attr_container_t **p_attr_cont, const char *key,
+                             const int8_t *value, unsigned length)
 {
     if (!value) {
         attr_container_printf("Set attr failed: invald input arguments.\r\n");
         return false;
     }
     return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_BYTEARRAY, value,
-            length);;
+                                   length);
 }
 
-static const char*
+static const char *
 attr_container_get_attr(const attr_container_t *attr_cont, const char *key)
 {
     const char *attr_addr;
 
     if (!attr_cont || !key) {
         attr_container_printf(
-                "Get attribute failed: invalid input arguments.\r\n");
+            "Get attribute failed: invalid input arguments.\r\n");
         return NULL;
     }
 
@@ -528,101 +559,103 @@ attr_container_get_attr(const attr_container_t *attr_cont, const char *key)
     return attr_addr + 2 + strlen(key) + 1;
 }
 
-#define TEMPLATE_ATTR_BUF_TO_VALUE(attr, key, var_name) do {\
-    jvalue val;                                             \
-    const char *addr = attr_container_get_attr(attr, key);  \
-    uint8_t type;                                           \
-    if (!addr)                                              \
-      return 0;                                             \
-    val.j = 0;                                              \
-    type = *(uint8_t*)addr++;                               \
-    switch (type) {                                         \
-      case ATTR_TYPE_SHORT:                                 \
-      case ATTR_TYPE_INT:                                   \
-      case ATTR_TYPE_INT64:                                 \
-      case ATTR_TYPE_BYTE:                                  \
-      case ATTR_TYPE_UINT16:                                \
-      case ATTR_TYPE_FLOAT:                                 \
-      case ATTR_TYPE_DOUBLE:                                \
-      case ATTR_TYPE_BOOLEAN:                               \
-        bh_memcpy_s(&val, sizeof(val.var_name), addr, 1 << (type & 3)); \
-        break;                                              \
-      case ATTR_TYPE_STRING:                                \
-      {                                                     \
-        unsigned len= get_uint16(addr);                     \
-        addr += 2;                                          \
-        if (len > sizeof(val.var_name))                     \
-          len = sizeof(val.var_name);                       \
-        bh_memcpy_s(&val.var_name, sizeof(val.var_name), addr, len); \
-        break;                                              \
-      }                                                     \
-      case ATTR_TYPE_BYTEARRAY:                             \
-      {                                                     \
-        unsigned len= get_uint32(addr);                     \
-        addr += 4;                                          \
-        if (len > sizeof(val.var_name))                     \
-          len = sizeof(val.var_name);                       \
-        bh_memcpy_s(&val.var_name, sizeof(val.var_name), addr, len); \
-        break;                                              \
-      }                                                     \
-      default:                                              \
-        bh_assert(0);                                       \
-        break;                                              \
-    }                                                       \
-    return val.var_name;                                    \
-  } while (0)
-
-short attr_container_get_as_short(const attr_container_t *attr_cont,
-        const char *key)
+#define TEMPLATE_ATTR_BUF_TO_VALUE(attr, key, var_name)                      \
+    do {                                                                     \
+        jvalue val;                                                          \
+        const char *addr = attr_container_get_attr(attr, key);               \
+        uint8_t type;                                                        \
+        if (!addr)                                                           \
+            return 0;                                                        \
+        val.j = 0;                                                           \
+        type = *(uint8_t *)addr++;                                           \
+        switch (type) {                                                      \
+            case ATTR_TYPE_SHORT:                                            \
+            case ATTR_TYPE_INT:                                              \
+            case ATTR_TYPE_INT64:                                            \
+            case ATTR_TYPE_BYTE:                                             \
+            case ATTR_TYPE_UINT16:                                           \
+            case ATTR_TYPE_FLOAT:                                            \
+            case ATTR_TYPE_DOUBLE:                                           \
+            case ATTR_TYPE_BOOLEAN:                                          \
+                bh_memcpy_s(&val, sizeof(val.var_name), addr,                \
+                            1 << (type & 3));                                \
+                break;                                                       \
+            case ATTR_TYPE_STRING:                                           \
+            {                                                                \
+                unsigned len = get_uint16(addr);                             \
+                addr += 2;                                                   \
+                if (len > sizeof(val.var_name))                              \
+                    len = sizeof(val.var_name);                              \
+                bh_memcpy_s(&val.var_name, sizeof(val.var_name), addr, len); \
+                break;                                                       \
+            }                                                                \
+            case ATTR_TYPE_BYTEARRAY:                                        \
+            {                                                                \
+                unsigned len = get_uint32(addr);                             \
+                addr += 4;                                                   \
+                if (len > sizeof(val.var_name))                              \
+                    len = sizeof(val.var_name);                              \
+                bh_memcpy_s(&val.var_name, sizeof(val.var_name), addr, len); \
+                break;                                                       \
+            }                                                                \
+            default:                                                         \
+                bh_assert(0);                                                \
+                break;                                                       \
+        }                                                                    \
+        return val.var_name;                                                 \
+    } while (0)
+
+short
+attr_container_get_as_short(const attr_container_t *attr_cont, const char *key)
 {
     TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, s);
 }
 
-int attr_container_get_as_int(const attr_container_t *attr_cont,
-        const char *key)
+int
+attr_container_get_as_int(const attr_container_t *attr_cont, const char *key)
 {
     TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i);
 }
 
-int64_t attr_container_get_as_int64(const attr_container_t *attr_cont,
-        const char *key)
+int64_t
+attr_container_get_as_int64(const attr_container_t *attr_cont, const char *key)
 {
     TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, j);
 }
 
-int8_t attr_container_get_as_byte(const attr_container_t *attr_cont,
-        const char *key)
+int8_t
+attr_container_get_as_byte(const attr_container_t *attr_cont, const char *key)
 {
     TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, b);
 }
 
-uint16_t attr_container_get_as_uint16(const attr_container_t *attr_cont,
-        const char *key)
+uint16_t
+attr_container_get_as_uint16(const attr_container_t *attr_cont, const char *key)
 {
     TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, s);
 }
 
-float attr_container_get_as_float(const attr_container_t *attr_cont,
-        const char *key)
+float
+attr_container_get_as_float(const attr_container_t *attr_cont, const char *key)
 {
     TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, f);
 }
 
-double attr_container_get_as_double(const attr_container_t *attr_cont,
-        const char *key)
+double
+attr_container_get_as_double(const attr_container_t *attr_cont, const char *key)
 {
     TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, d);
 }
 
-bool attr_container_get_as_bool(const attr_container_t *attr_cont,
-        const char *key)
+bool
+attr_container_get_as_bool(const attr_container_t *attr_cont, const char *key)
 {
     TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, z);
 }
 
-const int8_t*
+const int8_t *
 attr_container_get_as_bytearray(const attr_container_t *attr_cont,
-        const char *key, unsigned *array_length)
+                                const char *key, unsigned *array_length)
 {
     const char *addr = attr_container_get_attr(attr_cont, key);
     uint8_t type;
@@ -636,68 +669,68 @@ attr_container_get_as_bytearray(const attr_container_t *attr_cont,
         return NULL;
     }
 
-    type = *(uint8_t*) addr++;
+    type = *(uint8_t *)addr++;
     switch (type) {
-    case ATTR_TYPE_SHORT:
-    case ATTR_TYPE_INT:
-    case ATTR_TYPE_INT64:
-    case ATTR_TYPE_BYTE:
-    case ATTR_TYPE_UINT16:
-    case ATTR_TYPE_FLOAT:
-    case ATTR_TYPE_DOUBLE:
-    case ATTR_TYPE_BOOLEAN:
-        length = 1 << (type & 3);
-        break;
-    case ATTR_TYPE_STRING:
-        length = get_uint16(addr);
-        addr += 2;
-        break;
-    case ATTR_TYPE_BYTEARRAY:
-        length = get_uint32(addr);
-        addr += 4;
-        break;
-    default:
-        return NULL;
+        case ATTR_TYPE_SHORT:
+        case ATTR_TYPE_INT:
+        case ATTR_TYPE_INT64:
+        case ATTR_TYPE_BYTE:
+        case ATTR_TYPE_UINT16:
+        case ATTR_TYPE_FLOAT:
+        case ATTR_TYPE_DOUBLE:
+        case ATTR_TYPE_BOOLEAN:
+            length = 1 << (type & 3);
+            break;
+        case ATTR_TYPE_STRING:
+            length = get_uint16(addr);
+            addr += 2;
+            break;
+        case ATTR_TYPE_BYTEARRAY:
+            length = get_uint32(addr);
+            addr += 4;
+            break;
+        default:
+            return NULL;
     }
 
     *array_length = length;
-    return (const int8_t*) addr;
+    return (const int8_t *)addr;
 }
 
-char*
+char *
 attr_container_get_as_string(const attr_container_t *attr_cont, const char *key)
 {
     unsigned array_length;
-    return (char*) attr_container_get_as_bytearray(attr_cont, key,
-            &array_length);
+    return (char *)attr_container_get_as_bytearray(attr_cont, key,
+                                                   &array_length);
 }
 
-const char*
+const char *
 attr_container_get_tag(const attr_container_t *attr_cont)
 {
-    return attr_cont ?
-            attr_cont->buf + sizeof(uint32_t) + sizeof(uint16_t) : NULL;
+    return attr_cont ? attr_cont->buf + sizeof(uint32_t) + sizeof(uint16_t)
+                     : NULL;
 }
 
-bool attr_container_contain_key(const attr_container_t *attr_cont,
-        const char *key)
+bool
+attr_container_contain_key(const attr_container_t *attr_cont, const char *key)
 {
     if (!attr_cont || !key || !strlen(key)) {
         attr_container_printf(
-                "Check contain key failed: invalid input arguments.\r\n");
+            "Check contain key failed: invalid input arguments.\r\n");
         return false;
     }
     return attr_container_find_attr(attr_cont, key) ? true : false;
 }
 
-unsigned int attr_container_get_serialize_length(
-        const attr_container_t *attr_cont)
+unsigned int
+attr_container_get_serialize_length(const attr_container_t *attr_cont)
 {
     const char *p;
 
     if (!attr_cont) {
-        attr_container_printf(
-                "Get container serialize length failed: invalid input arguments.\r\n");
+        attr_container_printf("Get container serialize length failed: invalid "
+                              "input arguments.\r\n");
         return 0;
     }
 
@@ -705,7 +738,8 @@ unsigned int attr_container_get_serialize_length(
     return sizeof(uint16_t) + get_uint32(p);
 }
 
-bool attr_container_serialize(char *buf, const attr_container_t *attr_cont)
+bool
+attr_container_serialize(char *buf, const attr_container_t *attr_cont)
 {
     const char *p;
     uint16_t flags;
@@ -713,7 +747,7 @@ bool attr_container_serialize(char *buf, const attr_container_t *attr_cont)
 
     if (!buf || !attr_cont) {
         attr_container_printf(
-                "Container serialize failed: invalid input arguments.\r\n");
+            "Container serialize failed: invalid input arguments.\r\n");
         return false;
     }
 
@@ -721,27 +755,29 @@ bool attr_container_serialize(char *buf, const attr_container_t *attr_cont)
     length = sizeof(uint16_t) + get_uint32(p);
     bh_memcpy_s(buf, length, attr_cont, length);
     /* Set readonly */
-    flags = get_uint16((const char*) attr_cont);
+    flags = get_uint16((const char *)attr_cont);
     set_uint16(buf, flags | (1 << ATTR_CONT_READONLY_SHIFT));
 
     return true;
 }
 
-bool attr_container_is_constant(const attr_container_t* attr_cont)
+bool
+attr_container_is_constant(const attr_container_t *attr_cont)
 {
     uint16_t flags;
 
     if (!attr_cont) {
         attr_container_printf(
-                "Container check const: invalid input arguments.\r\n");
+            "Container check const: invalid input arguments.\r\n");
         return false;
     }
 
-    flags = get_uint16((const char*) attr_cont);
+    flags = get_uint16((const char *)attr_cont);
     return (flags & (1 << ATTR_CONT_READONLY_SHIFT)) ? true : false;
 }
 
-void attr_container_dump(const attr_container_t *attr_cont)
+void
+attr_container_dump(const attr_container_t *attr_cont)
 {
     uint32_t total_length;
     uint16_t attr_num, i, type;
@@ -771,64 +807,64 @@ void attr_container_dump(const attr_container_t *attr_cont)
         attr_container_printf("  key: %s", key);
 
         switch (type) {
-        case ATTR_TYPE_SHORT:
-            bh_memcpy_s(&value.s, sizeof(int16_t), p, sizeof(int16_t));
-            attr_container_printf(", type: short, value: 0x%x\n",
-                    value.s & 0xFFFF);
-            p += 2;
-            break;
-        case ATTR_TYPE_INT:
-            bh_memcpy_s(&value.i, sizeof(int32_t), p, sizeof(int32_t));
-            attr_container_printf(", type: int, value: 0x%x\n", value.i);
-            p += 4;
-            break;
-        case ATTR_TYPE_INT64:
-            bh_memcpy_s(&value.j, sizeof(uint64_t), p, sizeof(uint64_t));
-            attr_container_printf(", type: int64, value: 0x%llx\n", (long long unsigned int)(value.j));
-            p += 8;
-            break;
-        case ATTR_TYPE_BYTE:
-            bh_memcpy_s(&value.b, 1, p, 1);
-            attr_container_printf(", type: byte, value: 0x%x\n",
-                    value.b & 0xFF);
-            p++;
-            break;
-        case ATTR_TYPE_UINT16:
-            bh_memcpy_s(&value.c, sizeof(uint16_t), p, sizeof(uint16_t));
-            attr_container_printf(", type: uint16, value: 0x%x\n", value.c);
-            p += 2;
-            break;
-        case ATTR_TYPE_FLOAT:
-            bh_memcpy_s(&value.f, sizeof(float), p, sizeof(float));
-            attr_container_printf(", type: float, value: %f\n", value.f);
-            p += 4;
-            break;
-        case ATTR_TYPE_DOUBLE:
-            bh_memcpy_s(&value.d, sizeof(double), p, sizeof(double));
-            attr_container_printf(", type: double, value: %f\n", value.d);
-            p += 8;
-            break;
-        case ATTR_TYPE_BOOLEAN:
-            bh_memcpy_s(&value.z, 1, p, 1);
-            attr_container_printf(", type: bool, value: 0x%x\n", value.z);
-            p++;
-            break;
-        case ATTR_TYPE_STRING:
-            attr_container_printf(", type: string, value: %s\n",
-                    p + sizeof(uint16_t));
-            p += sizeof(uint16_t) + get_uint16(p);
-            break;
-        case ATTR_TYPE_BYTEARRAY:
-            attr_container_printf(", type: byte array, length: %d\n",
-                    get_uint32(p));
-            p += sizeof(uint32_t) + get_uint32(p);
-            break;
-        default:
-            bh_assert(0);
-            break;
+            case ATTR_TYPE_SHORT:
+                bh_memcpy_s(&value.s, sizeof(int16_t), p, sizeof(int16_t));
+                attr_container_printf(", type: short, value: 0x%x\n",
+                                      value.s & 0xFFFF);
+                p += 2;
+                break;
+            case ATTR_TYPE_INT:
+                bh_memcpy_s(&value.i, sizeof(int32_t), p, sizeof(int32_t));
+                attr_container_printf(", type: int, value: 0x%x\n", value.i);
+                p += 4;
+                break;
+            case ATTR_TYPE_INT64:
+                bh_memcpy_s(&value.j, sizeof(uint64_t), p, sizeof(uint64_t));
+                attr_container_printf(", type: int64, value: 0x%llx\n",
+                                      (long long unsigned int)(value.j));
+                p += 8;
+                break;
+            case ATTR_TYPE_BYTE:
+                bh_memcpy_s(&value.b, 1, p, 1);
+                attr_container_printf(", type: byte, value: 0x%x\n",
+                                      value.b & 0xFF);
+                p++;
+                break;
+            case ATTR_TYPE_UINT16:
+                bh_memcpy_s(&value.c, sizeof(uint16_t), p, sizeof(uint16_t));
+                attr_container_printf(", type: uint16, value: 0x%x\n", value.c);
+                p += 2;
+                break;
+            case ATTR_TYPE_FLOAT:
+                bh_memcpy_s(&value.f, sizeof(float), p, sizeof(float));
+                attr_container_printf(", type: float, value: %f\n", value.f);
+                p += 4;
+                break;
+            case ATTR_TYPE_DOUBLE:
+                bh_memcpy_s(&value.d, sizeof(double), p, sizeof(double));
+                attr_container_printf(", type: double, value: %f\n", value.d);
+                p += 8;
+                break;
+            case ATTR_TYPE_BOOLEAN:
+                bh_memcpy_s(&value.z, 1, p, 1);
+                attr_container_printf(", type: bool, value: 0x%x\n", value.z);
+                p++;
+                break;
+            case ATTR_TYPE_STRING:
+                attr_container_printf(", type: string, value: %s\n",
+                                      p + sizeof(uint16_t));
+                p += sizeof(uint16_t) + get_uint16(p);
+                break;
+            case ATTR_TYPE_BYTEARRAY:
+                attr_container_printf(", type: byte array, length: %d\n",
+                                      get_uint32(p));
+                p += sizeof(uint32_t) + get_uint32(p);
+                break;
+            default:
+                bh_assert(0);
+                break;
         }
     }
 
     attr_container_printf("\n");
 }
-

+ 19 - 20
core/app-framework/app-native-shared/bi-inc/attr_container.h

@@ -34,7 +34,7 @@ enum {
     ATTR_TYPE_END = ATTR_TYPE_BYTEARRAY
 };
 
-#define ATTR_CONT_READONLY_SHIFT    2
+#define ATTR_CONT_READONLY_SHIFT 2
 
 typedef struct attr_container {
     /* container flag:
@@ -87,7 +87,7 @@ attr_container_destroy(const attr_container_t *attr_cont);
  */
 bool
 attr_container_set_short(attr_container_t **p_attr_cont, const char *key,
-        short value);
+                         short value);
 
 /**
  * Set int attribute in attribute container
@@ -101,7 +101,7 @@ attr_container_set_short(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_int(attr_container_t **p_attr_cont, const char *key,
-        int value);
+                       int value);
 
 /**
  * Set int64 attribute in attribute container
@@ -115,7 +115,7 @@ attr_container_set_int(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_int64(attr_container_t **p_attr_cont, const char *key,
-        int64_t value);
+                         int64_t value);
 
 /**
  * Set byte attribute in attribute container
@@ -129,7 +129,7 @@ attr_container_set_int64(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_byte(attr_container_t **p_attr_cont, const char *key,
-        int8_t value);
+                        int8_t value);
 
 /**
  * Set uint16 attribute in attribute container
@@ -143,7 +143,7 @@ attr_container_set_byte(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_uint16(attr_container_t **p_attr_cont, const char *key,
-        uint16_t value);
+                          uint16_t value);
 
 /**
  * Set float attribute in attribute container
@@ -157,7 +157,7 @@ attr_container_set_uint16(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_float(attr_container_t **p_attr_cont, const char *key,
-        float value);
+                         float value);
 
 /**
  * Set double attribute in attribute container
@@ -171,7 +171,7 @@ attr_container_set_float(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_double(attr_container_t **p_attr_cont, const char *key,
-        double value);
+                          double value);
 
 /**
  * Set bool attribute in attribute container
@@ -185,7 +185,7 @@ attr_container_set_double(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_bool(attr_container_t **p_attr_cont, const char *key,
-        bool value);
+                        bool value);
 
 /**
  * Set string attribute in attribute container
@@ -199,7 +199,7 @@ attr_container_set_bool(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_string(attr_container_t **p_attr_cont, const char *key,
-        const char *value);
+                          const char *value);
 
 /**
  * Set bytearray attribute in attribute container
@@ -214,7 +214,7 @@ attr_container_set_string(attr_container_t **p_attr_cont, const char *key,
  */
 bool
 attr_container_set_bytearray(attr_container_t **p_attr_cont, const char *key,
-        const int8_t *value, unsigned length);
+                             const int8_t *value, unsigned length);
 
 /**
  * Get tag of current attribute container
@@ -223,7 +223,7 @@ attr_container_set_bytearray(attr_container_t **p_attr_cont, const char *key,
  *
  * @return tag of current attribute container
  */
-const char*
+const char *
 attr_container_get_tag(const attr_container_t *attr_cont);
 
 /**
@@ -306,7 +306,7 @@ attr_container_get_as_byte(const attr_container_t *attr_cont, const char *key);
  */
 uint16_t
 attr_container_get_as_uint16(const attr_container_t *attr_cont,
-        const char *key);
+                             const char *key);
 
 /**
  * Get attribute from attribute container and return it as float value,
@@ -331,7 +331,7 @@ attr_container_get_as_float(const attr_container_t *attr_cont, const char *key);
  */
 double
 attr_container_get_as_double(const attr_container_t *attr_cont,
-        const char *key);
+                             const char *key);
 
 /**
  * Get attribute from attribute container and return it as bool value,
@@ -354,9 +354,9 @@ attr_container_get_as_bool(const attr_container_t *attr_cont, const char *key);
  *
  * @return the string value of the attribute, NULL if key isn't found
  */
-char*
+char *
 attr_container_get_as_string(const attr_container_t *attr_cont,
-        const char *key);
+                             const char *key);
 
 /**
  * Get attribute from attribute container and return it as bytearray value,
@@ -367,9 +367,9 @@ attr_container_get_as_string(const attr_container_t *attr_cont,
  *
  * @return the bytearray value of the attribute, NULL if key isn't found
  */
-const int8_t*
+const int8_t *
 attr_container_get_as_bytearray(const attr_container_t *attr_cont,
-        const char *key, unsigned *array_length);
+                                const char *key, unsigned *array_length);
 
 /**
  * Get the buffer size of attribute container
@@ -400,7 +400,7 @@ attr_container_serialize(char *buf, const attr_container_t *attr_cont);
  * @return true if const, false otherwise
  */
 bool
-attr_container_is_constant(const attr_container_t* attr_cont);
+attr_container_is_constant(const attr_container_t *attr_cont);
 
 void
 attr_container_dump(const attr_container_t *attr_cont);
@@ -422,4 +422,3 @@ attr_container_dump(const attr_container_t *attr_cont);
 #endif
 
 #endif /* end of _ATTR_CONTAINER_H_ */
-

+ 21 - 22
core/app-framework/app-native-shared/bi-inc/shared_utils.h

@@ -12,8 +12,8 @@
 extern "C" {
 #endif
 
-#define FMT_ATTR_CONTAINER  99
-#define FMT_APP_RAW_BINARY  98
+#define FMT_ATTR_CONTAINER 99
+#define FMT_APP_RAW_BINARY 98
 
 /* the request structure */
 typedef struct request {
@@ -32,10 +32,10 @@ typedef struct request {
     // payload of the request, currently only support attr_container_t type
     void *payload;
 
-    //length in bytes of the payload
+    // length in bytes of the payload
     int payload_len;
 
-    //sender of the request
+    // sender of the request
     unsigned long sender;
 } request_t;
 
@@ -53,21 +53,21 @@ typedef struct response {
     // payload of the response,
     void *payload;
 
-    //length in bytes of the payload
+    // length in bytes of the payload
     int payload_len;
 
-    //receiver of the response
+    // receiver of the response
     unsigned long reciever;
 } response_t;
 
 int
-check_url_start(const char* url, int url_len, const char * leading_str);
+check_url_start(const char *url, int url_len, const char *leading_str);
 
 bool
-match_url(char * pattern, char * matched);
+match_url(char *pattern, char *matched);
 
 char *
-find_key_value(char * buffer, int buffer_len, char * key, char * value,
+find_key_value(char *buffer, int buffer_len, char *key, char *value,
                int value_len, char delimiter);
 
 request_t *
@@ -77,10 +77,10 @@ void
 request_cleaner(request_t *request);
 
 response_t *
-clone_response(response_t * response);
+clone_response(response_t *response);
 
 void
-response_cleaner(response_t * response);
+response_cleaner(response_t *response);
 
 /**
  * @brief Set fields of response.
@@ -96,8 +96,8 @@ response_cleaner(response_t * response);
  * @warning the response pointer MUST NOT be NULL
  */
 response_t *
-set_response(response_t * response, int status, int fmt,
-             const char *payload, int payload_len);
+set_response(response_t *response, int status, int fmt, const char *payload,
+             int payload_len);
 
 /**
  * @brief Make a response for a request.
@@ -110,7 +110,7 @@ set_response(response_t * response, int status, int fmt,
  * @warning the request and response pointers MUST NOT be NULL
  */
 response_t *
-make_response_for_request(request_t * request, response_t * response);
+make_response_for_request(request_t *request, response_t *response);
 
 /**
  * @brief Initialize a request.
@@ -127,28 +127,27 @@ make_response_for_request(request_t * request, response_t * response);
  * @warning the request pointer MUST NOT be NULL
  */
 request_t *
-init_request(request_t * request, char *url, int action, int fmt,
-             void *payload, int payload_len);
+init_request(request_t *request, char *url, int action, int fmt, void *payload,
+             int payload_len);
 
 char *
-pack_request(request_t *request, int * size);
+pack_request(request_t *request, int *size);
 
 request_t *
-unpack_request(char * packet, int size, request_t * request);
+unpack_request(char *packet, int size, request_t *request);
 
 char *
-pack_response(response_t *response, int * size);
+pack_response(response_t *response, int *size);
 
 response_t *
-unpack_response(char * packet, int size, response_t * response);
+unpack_response(char *packet, int size, response_t *response);
 
 void
-free_req_resp_packet(char * packet);
+free_req_resp_packet(char *packet);
 
 char *
 wa_strdup(const char *str);
 
-
 #ifdef __cplusplus
 }
 #endif

+ 0 - 2
core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h

@@ -8,14 +8,12 @@
 
 #include "bh_platform.h"
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #include <stdbool.h>
 
-
 /* Object native function IDs */
 enum {
     OBJ_FUNC_ID_DEL,

+ 0 - 2
core/app-framework/app-native-shared/native_interface.h

@@ -10,6 +10,4 @@
          implemented by both [app] and [native] worlds */
 #include "bh_platform.h"
 
-
 #endif /* end of _NATIVE_INTERFACE_H */
-

+ 37 - 34
core/app-framework/app-native-shared/restful_utils.c

@@ -20,22 +20,27 @@
  * 4. attr-containers of our own
  * 5. customized serialization for request/response
  *
- * Now we choose the #5 mainly because we need to quickly get the URL for dispatching
- * and sometimes we want to change the URL in the original packet. the request format:
- * fixed part: version: (1 byte), code (1 byte), fmt(2 byte), mid (4 bytes), sender_id(4 bytes),  url_len(2 bytes), payload_len(4bytes)
- * dynamic part: url (bytes in url_len), payload
+ * Now we choose the #5 mainly because we need to quickly get the URL for
+ * dispatching and sometimes we want to change the URL in the original packet.
+ * the request format: fixed part: version: (1 byte), code (1 byte), fmt(2
+ * byte), mid (4 bytes), sender_id(4 bytes),  url_len(2 bytes),
+ * payload_len(4bytes) dynamic part: url (bytes in url_len), payload
  *
  * response format:
- * fixed part: (1 byte), code (1 byte), fmt(2 byte), mid (4 bytes), sender_id(4 bytes),   payload_len(4bytes)
- * dynamic part: payload
+ * fixed part: (1 byte), code (1 byte), fmt(2 byte), mid (4 bytes), sender_id(4
+ * bytes),   payload_len(4bytes) dynamic part: payload
  */
 #define REQUES_PACKET_VER 1
 #define REQUEST_PACKET_FIX_PART_LEN 18
 #define REQUEST_PACKET_URL_OFFSET REQUEST_PACKET_FIX_PART_LEN
-#define REQUEST_PACKET_URL_LEN  *((uint16*)((char*) buffer + 12))   /* to ensure little endian */
-#define REQUEST_PACKET_PAYLOAD_LEN *((uint32*)((char*) buffer + 14))   /* to ensure little endian */
-#define REQUEST_PACKET_URL(buffer) ((char*) buffer + REQUEST_PACKET_URL_OFFSET)
-#define REQUEST_PACKET_PAYLOAD(buffer)  ((char*) buffer + REQUEST_PACKET_URL_OFFSET + REQUEST_PACKET_URL_LEN(buffer))
+#define REQUEST_PACKET_URL_LEN \
+    *((uint16 *)((char *)buffer + 12)) /* to ensure little endian */
+#define REQUEST_PACKET_PAYLOAD_LEN \
+    *((uint32 *)((char *)buffer + 14)) /* to ensure little endian */
+#define REQUEST_PACKET_URL(buffer) ((char *)buffer + REQUEST_PACKET_URL_OFFSET)
+#define REQUEST_PACKET_PAYLOAD(buffer)          \
+    ((char *)buffer + REQUEST_PACKET_URL_OFFSET \
+     + REQUEST_PACKET_URL_LEN(buffer))
 
 #define RESPONSE_PACKET_FIX_PART_LEN 16
 
@@ -48,17 +53,17 @@ pack_request(request_t *request, int *size)
     uint32 u32;
     char *packet;
 
-    if ((packet = (char*) WA_MALLOC(len)) == NULL)
+    if ((packet = (char *)WA_MALLOC(len)) == NULL)
         return NULL;
 
     /* TODO: ensure little endian for words and dwords */
     *packet = REQUES_PACKET_VER;
-    *((uint8*) (packet + 1)) = request->action;
+    *((uint8 *)(packet + 1)) = request->action;
 
     u16 = htons(request->fmt);
     memcpy(packet + 2, &u16, 2);
 
-    u32  = htonl(request->mid);
+    u32 = htonl(request->mid);
     memcpy(packet + 4, &u32, 4);
 
     u32 = htonl(request->sender);
@@ -72,7 +77,7 @@ pack_request(request_t *request, int *size)
 
     strcpy(packet + REQUEST_PACKET_URL_OFFSET, request->url);
     memcpy(packet + REQUEST_PACKET_URL_OFFSET + url_len, request->payload,
-            request->payload_len);
+           request->payload_len);
 
     *size = len;
     return packet;
@@ -111,7 +116,7 @@ unpack_request(char *packet, int size, request_t *request)
         return NULL;
     }
 
-    request->action = *((uint8*) (packet + 1));
+    request->action = *((uint8 *)(packet + 1));
 
     memcpy(&u16, packet + 2, 2);
     request->fmt = ntohs(u16);
@@ -141,12 +146,12 @@ pack_response(response_t *response, int *size)
     uint32 u32;
     char *packet;
 
-    if ((packet = (char*) WA_MALLOC(len)) == NULL)
+    if ((packet = (char *)WA_MALLOC(len)) == NULL)
         return NULL;
 
     /* TODO: ensure little endian for words and dwords */
     *packet = REQUES_PACKET_VER;
-    *((uint8*) (packet + 1)) = response->status;
+    *((uint8 *)(packet + 1)) = response->status;
 
     u16 = htons(response->fmt);
     memcpy(packet + 2, &u16, 2);
@@ -161,7 +166,7 @@ pack_response(response_t *response, int *size)
     memcpy(packet + 12, &u32, 4);
 
     memcpy(packet + RESPONSE_PACKET_FIX_PART_LEN, response->payload,
-            response->payload_len);
+           response->payload_len);
 
     *size = len;
     return packet;
@@ -184,7 +189,7 @@ unpack_response(char *packet, int size, response_t *response)
     if (size != (RESPONSE_PACKET_FIX_PART_LEN + payload_len))
         return NULL;
 
-    response->status = *((uint8*) (packet + 1));
+    response->status = *((uint8 *)(packet + 1));
 
     memcpy(&u16, packet + 2, 2);
     response->fmt = ntohs(u16);
@@ -208,7 +213,7 @@ request_t *
 clone_request(request_t *request)
 {
     /* deep clone */
-    request_t *req = (request_t *) WA_MALLOC(sizeof(request_t));
+    request_t *req = (request_t *)WA_MALLOC(sizeof(request_t));
     if (req == NULL)
         return NULL;
 
@@ -278,7 +283,7 @@ clone_response(response_t *response)
     clone->reciever = response->reciever;
     clone->payload_len = response->payload_len;
     if (clone->payload_len) {
-        clone->payload = (char *) WA_MALLOC(response->payload_len);
+        clone->payload = (char *)WA_MALLOC(response->payload_len);
         if (!clone->payload)
             goto fail;
         memcpy(clone->payload, response->payload, response->payload_len);
@@ -296,8 +301,8 @@ fail:
 }
 
 response_t *
-set_response(response_t *response, int status, int fmt,
-             const char *payload, int payload_len)
+set_response(response_t *response, int status, int fmt, const char *payload,
+             int payload_len)
 {
     response->payload = (void *)payload;
     response->payload_len = payload_len;
@@ -307,8 +312,7 @@ set_response(response_t *response, int status, int fmt,
 }
 
 response_t *
-make_response_for_request(request_t *request,
-                          response_t *response)
+make_response_for_request(request_t *request, response_t *response)
 {
     response->mid = request->mid;
     response->reciever = request->sender;
@@ -319,8 +323,8 @@ make_response_for_request(request_t *request,
 static unsigned int mid = 0;
 
 request_t *
-init_request(request_t *request, char *url, int action, int fmt,
-             void *payload, int payload_len)
+init_request(request_t *request, char *url, int action, int fmt, void *payload,
+             int payload_len)
 {
     request->url = url;
     request->action = action;
@@ -334,10 +338,10 @@ init_request(request_t *request, char *url, int action, int fmt,
 
 /*
  check if the "url" is starting with "leading_str"
- return: 0 - not match; >0 - the offset of matched url, include any "/" at the end
- notes:
- 1. it ensures the leading_str "/abc" can pass "/abc/cde" and "/abc/, but fail "/ab" and "/abcd".
- leading_str "/abc/" can pass "/abc"
+ return: 0 - not match; >0 - the offset of matched url, include any "/" at the
+ end notes:
+ 1. it ensures the leading_str "/abc" can pass "/abc/cde" and "/abc/, but fail
+ "/ab" and "/abcd". leading_str "/abc/" can pass "/abc"
  2. it omit the '/' at the first char
  3. it ensure the leading_str "/abc" can pass "/abc?cde
  */
@@ -425,7 +429,6 @@ match_url(char *pattern, char *matched)
             return true;
 
         return false;
-
     }
     else if (pattern[len - 1] == '*') {
         if (pattern[len - 2] == '/') {
@@ -468,9 +471,9 @@ find_key_value(char *buffer, int buffer_len, char *key, char *value,
         if (0 == strncmp(p, key, key_len) && p[key_len] == '=') {
             p += (key_len + 1);
             remaining -= (key_len + 1);
-            char * v = value;
+            char *v = value;
             memset(value, 0, value_len);
-            value_len--;  /* ensure last char is 0 */
+            value_len--; /* ensure last char is 0 */
             while (*p != delimiter && remaining > 0 && value_len > 0) {
                 *v++ = *p++;
                 remaining--;

+ 7 - 8
core/app-framework/app_ext_lib_export.c

@@ -1,33 +1,33 @@
 #include "lib_export.h"
 
 #ifdef APP_FRAMEWORK_SENSOR
-    #include "sensor_native_api.h"
+#include "sensor_native_api.h"
 #endif
 
 #ifdef APP_FRAMEWORK_CONNECTION
-    #include "connection_native_api.h"
+#include "connection_native_api.h"
 #endif
 
 #ifdef APP_FRAMEWORK_WGL
-    #include "gui_native_api.h"
+#include "gui_native_api.h"
 #endif
 
 /* More header file here */
 
 static NativeSymbol extended_native_symbol_defs[] = {
 #ifdef APP_FRAMEWORK_SENSOR
-    #include "runtime_sensor.inl"
+#include "runtime_sensor.inl"
 #endif
 
 #ifdef APP_FRAMEWORK_CONNECTION
-    #include "connection.inl"
+#include "connection.inl"
 #endif
 
 #ifdef APP_FRAMEWORK_WGL
-    #include "wamr_gui.inl"
+#include "wamr_gui.inl"
 #endif
 
-/* More inl file here */
+    /* More inl file here */
 };
 
 int
@@ -36,4 +36,3 @@ get_ext_lib_export_apis(NativeSymbol **p_ext_lib_apis)
     *p_ext_lib_apis = extended_native_symbol_defs;
     return sizeof(extended_native_symbol_defs) / sizeof(NativeSymbol);
 }
-

+ 18 - 10
core/app-framework/base/app/bh_platform.c

@@ -13,14 +13,16 @@
  *
  */
 
-static bool is_little_endian()
+static bool
+is_little_endian()
 {
     long i = 0x01020304;
-    unsigned char* c = (unsigned char*) &i;
+    unsigned char *c = (unsigned char *)&i;
     return (*c == 0x04) ? true : false;
 }
 
-static void swap32(uint8* pData)
+static void
+swap32(uint8 *pData)
 {
     uint8 value = *pData;
     *pData = *(pData + 3);
@@ -31,31 +33,35 @@ static void swap32(uint8* pData)
     *(pData + 2) = value;
 }
 
-static void swap16(uint8* pData)
+static void
+swap16(uint8 *pData)
 {
     uint8 value = *pData;
     *(pData) = *(pData + 1);
     *(pData + 1) = value;
 }
 
-uint32 htonl(uint32 value)
+uint32
+htonl(uint32 value)
 {
     uint32 ret;
     if (is_little_endian()) {
         ret = value;
-        swap32((uint8*) &ret);
+        swap32((uint8 *)&ret);
         return ret;
     }
 
     return value;
 }
 
-uint32 ntohl(uint32 value)
+uint32
+ntohl(uint32 value)
 {
     return htonl(value);
 }
 
-uint16 htons(uint16 value)
+uint16
+htons(uint16 value)
 {
     uint16 ret;
     if (is_little_endian()) {
@@ -67,12 +73,14 @@ uint16 htons(uint16 value)
     return value;
 }
 
-uint16 ntohs(uint16 value)
+uint16
+ntohs(uint16 value)
 {
     return htons(value);
 }
 
-char *wa_strdup(const char *s)
+char *
+wa_strdup(const char *s)
 {
     char *s1 = NULL;
     if (s && (s1 = WA_MALLOC(strlen(s) + 1)))

+ 20 - 17
core/app-framework/base/app/bh_platform.h

@@ -16,7 +16,7 @@ typedef unsigned int uint32;
 typedef int int32;
 
 #ifndef NULL
-#  define NULL ((void*) 0)
+#define NULL ((void *)0)
 #endif
 
 #ifndef __cplusplus
@@ -35,28 +35,31 @@ typedef int int32;
 #define WA_FREE free
 #endif
 
-
-uint32 htonl(uint32 value);
-uint32 ntohl(uint32 value);
-uint16 htons(uint16 value);
-uint16 ntohs(uint16 value);
-
+uint32
+htonl(uint32 value);
+uint32
+ntohl(uint32 value);
+uint16
+htons(uint16 value);
+uint16
+ntohs(uint16 value);
 
 // We are not worried for the WASM world since the sandbox will catch it.
-#define bh_memcpy_s(dst, dst_len, src, src_len)  memcpy(dst, src, src_len)
+#define bh_memcpy_s(dst, dst_len, src, src_len) memcpy(dst, src, src_len)
 
 #ifdef NDEBUG
 #define bh_assert(v) (void)0
 #else
-#define bh_assert(v) do {                             \
-    if (!(v)) {                                       \
-        int _count;                                   \
-        printf("ASSERTION FAILED: %s, at %s, line %d",\
-               #v, __FILE__, __LINE__);               \
-        _count = printf("\n");                        \
-        printf("%d\n", _count / (_count - 1));        \
-    }                                                 \
-  } while (0)
+#define bh_assert(v)                                                     \
+    do {                                                                 \
+        if (!(v)) {                                                      \
+            int _count;                                                  \
+            printf("ASSERTION FAILED: %s, at %s, line %d", #v, __FILE__, \
+                   __LINE__);                                            \
+            _count = printf("\n");                                       \
+            printf("%d\n", _count / (_count - 1));                       \
+        }                                                                \
+    } while (0)
 #endif
 
 #endif /* DEPS_IWASM_APP_LIBS_BASE_BH_PLATFORM_H_ */

+ 0 - 1
core/app-framework/base/app/req_resp_api.h

@@ -29,4 +29,3 @@ wasm_sub_event(const char *url);
 #endif
 
 #endif /* end of _REQ_RESP_API_H_ */
-

+ 56 - 40
core/app-framework/base/app/request.c

@@ -13,13 +13,11 @@
 
 #define TRANSACTION_TIMEOUT_MS 5000
 
-typedef enum {
-    Reg_Event, Reg_Request
-} reg_type_t;
+typedef enum { Reg_Event, Reg_Request } reg_type_t;
 
 typedef struct _res_register {
     struct _res_register *next;
-    const char * url;
+    const char *url;
     reg_type_t reg_type;
     void (*request_handler)(request_t *);
 } res_register_t;
@@ -32,13 +30,14 @@ typedef struct transaction {
     void *user_data;
 } transaction_t;
 
-static res_register_t * g_resources = NULL;
+static res_register_t *g_resources = NULL;
 
 static transaction_t *g_transactions = NULL;
 
 static user_timer_t g_trans_timer = NULL;
 
-static transaction_t *transaction_find(int mid)
+static transaction_t *
+transaction_find(int mid)
 {
     transaction_t *t = g_transactions;
 
@@ -55,7 +54,8 @@ static transaction_t *transaction_find(int mid)
  * new transaction is added to the tail of the list, so the list
  * is sorted by expiry time naturally.
  */
-static void transaction_add(transaction_t *trans)
+static void
+transaction_add(transaction_t *trans)
 {
     transaction_t *t;
 
@@ -73,7 +73,8 @@ static void transaction_add(transaction_t *trans)
     }
 }
 
-static void transaction_remove(transaction_t *trans)
+static void
+transaction_remove(transaction_t *trans)
 {
     transaction_t *prev = NULL, *current = g_transactions;
 
@@ -93,15 +94,17 @@ static void transaction_remove(transaction_t *trans)
     }
 }
 
-static bool is_event_type(request_t * req)
+static bool
+is_event_type(request_t *req)
 {
     return req->action == COAP_EVENT;
 }
 
-static bool register_url_handler(const char *url,
-        request_handler_f request_handler, reg_type_t reg_type)
+static bool
+register_url_handler(const char *url, request_handler_f request_handler,
+                     reg_type_t reg_type)
 {
-    res_register_t * r = g_resources;
+    res_register_t *r = g_resources;
 
     while (r) {
         if (reg_type == r->reg_type && strcmp(r->url, url) == 0) {
@@ -111,7 +114,7 @@ static bool register_url_handler(const char *url,
         r = r->next;
     }
 
-    r = (res_register_t *) malloc(sizeof(res_register_t));
+    r = (res_register_t *)malloc(sizeof(res_register_t));
     if (r == NULL)
         return false;
 
@@ -137,13 +140,15 @@ static bool register_url_handler(const char *url,
     return true;
 }
 
-bool api_register_resource_handler(const char *url,
-                                   request_handler_f request_handler)
+bool
+api_register_resource_handler(const char *url,
+                              request_handler_f request_handler)
 {
     return register_url_handler(url, request_handler, Reg_Request);
 }
 
-static void transaction_timeout_handler(user_timer_t timer)
+static void
+transaction_timeout_handler(user_timer_t timer)
 {
     transaction_t *cur, *expired = NULL;
     unsigned int elpased_ms, now = wasm_get_sys_tick_ms();
@@ -164,7 +169,8 @@ static void transaction_timeout_handler(user_timer_t timer)
             cur->next = expired;
             expired = cur;
             cur = g_transactions;
-        } else {
+        }
+        else {
             break;
         }
     }
@@ -186,27 +192,30 @@ static void transaction_timeout_handler(user_timer_t timer)
         unsigned int elpased_ms, ms_to_expiry, now = wasm_get_sys_tick_ms();
         if (now < g_transactions->time) {
             elpased_ms = now + (0xFFFFFFFF - g_transactions->time) + 1;
-        } else {
+        }
+        else {
             elpased_ms = now - g_transactions->time;
         }
         ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms;
         api_timer_restart(g_trans_timer, ms_to_expiry);
-    } else {
+    }
+    else {
         api_timer_cancel(g_trans_timer);
         g_trans_timer = NULL;
     }
 }
 
-void api_send_request(request_t * request, response_handler_f response_handler,
-        void * user_data)
+void
+api_send_request(request_t *request, response_handler_f response_handler,
+                 void *user_data)
 {
     int size;
     char *buffer;
     transaction_t *trans;
 
-    if ((trans = (transaction_t *) malloc(sizeof(transaction_t))) == NULL) {
+    if ((trans = (transaction_t *)malloc(sizeof(transaction_t))) == NULL) {
         printf(
-                "send request: allocate memory for request transaction failed!\n");
+            "send request: allocate memory for request transaction failed!\n");
         return;
     }
 
@@ -228,9 +237,8 @@ void api_send_request(request_t * request, response_handler_f response_handler,
     if (trans == g_transactions) {
         /* assert(g_trans_timer == NULL); */
         if (g_trans_timer == NULL) {
-            g_trans_timer = api_timer_create(TRANSACTION_TIMEOUT_MS,
-            false,
-            true, transaction_timeout_handler);
+            g_trans_timer = api_timer_create(TRANSACTION_TIMEOUT_MS, false,
+                                             true, transaction_timeout_handler);
         }
     }
 
@@ -241,11 +249,13 @@ void api_send_request(request_t * request, response_handler_f response_handler,
 
 /*
  *
- *  APIs for the native layers to callback for request/response arrived to this app
+ *  APIs for the native layers to callback for request/response arrived to this
+ * app
  *
  */
 
-void on_response(char * buffer, int size)
+void
+on_response(char *buffer, int size)
 {
     response_t response[1];
     transaction_t *trans;
@@ -262,7 +272,8 @@ void on_response(char * buffer, int size)
 
     /*
      * When the 1st transaction get response:
-     * 1. If the 2nd trans exist, restart the timer according to its expiry time;
+     * 1. If the 2nd trans exist, restart the timer according to its expiry
+     * time;
      * 2. Otherwise, stop the timer since there is no more transactions;
      */
     if (trans == g_transactions) {
@@ -270,12 +281,14 @@ void on_response(char * buffer, int size)
             unsigned int elpased_ms, ms_to_expiry, now = wasm_get_sys_tick_ms();
             if (now < trans->next->time) {
                 elpased_ms = now + (0xFFFFFFFF - trans->next->time) + 1;
-            } else {
+            }
+            else {
                 elpased_ms = now - trans->next->time;
             }
             ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms;
             api_timer_restart(g_trans_timer, ms_to_expiry);
-        } else {
+        }
+        else {
             api_timer_cancel(g_trans_timer);
             g_trans_timer = NULL;
         }
@@ -285,7 +298,8 @@ void on_response(char * buffer, int size)
     transaction_remove(trans);
 }
 
-void on_request(char *buffer, int size)
+void
+on_request(char *buffer, int size)
 {
     request_t request[1];
     bool is_event;
@@ -300,9 +314,9 @@ void on_request(char *buffer, int size)
 
     while (r) {
         if ((is_event && r->reg_type == Reg_Event)
-                || (!is_event && r->reg_type == Reg_Request)) {
+            || (!is_event && r->reg_type == Reg_Request)) {
             if (check_url_start(request->url, strlen(request->url), r->url)
-                    > 0) {
+                > 0) {
                 r->request_handler(request);
                 return;
             }
@@ -314,10 +328,11 @@ void on_request(char *buffer, int size)
     printf("on_request: exit. no service handler\n");
 }
 
-void api_response_send(response_t *response)
+void
+api_response_send(response_t *response)
 {
     int size;
-    char * buffer = pack_response(response, &size);
+    char *buffer = pack_response(response, &size);
     if (buffer == NULL)
         return;
 
@@ -327,12 +342,13 @@ void api_response_send(response_t *response)
 
 /// event api
 
-bool api_publish_event(const char *url, int fmt, void *payload, int payload_len)
+bool
+api_publish_event(const char *url, int fmt, void *payload, int payload_len)
 {
     int size;
     request_t request[1];
     init_request(request, (char *)url, COAP_EVENT, fmt, payload, payload_len);
-    char * buffer = pack_request(request, &size);
+    char *buffer = pack_request(request, &size);
     if (buffer == NULL)
         return false;
     wasm_post_request(buffer, size);
@@ -342,8 +358,8 @@ bool api_publish_event(const char *url, int fmt, void *payload, int payload_len)
     return true;
 }
 
-bool api_subscribe_event(const char * url, request_handler_f handler)
+bool
+api_subscribe_event(const char *url, request_handler_f handler)
 {
     return register_url_handler(url, handler, Reg_Event);
 }
-

+ 19 - 14
core/app-framework/base/app/timer.c

@@ -16,22 +16,23 @@
 #endif
 
 struct user_timer {
-    struct user_timer * next;
+    struct user_timer *next;
     int timer_id;
     void (*user_timer_callback)(user_timer_t);
 };
 
-struct user_timer * g_timers = NULL;
+struct user_timer *g_timers = NULL;
 
-user_timer_t api_timer_create(int interval, bool is_period, bool auto_start,
-        on_user_timer_update_f on_timer_update)
+user_timer_t
+api_timer_create(int interval, bool is_period, bool auto_start,
+                 on_user_timer_update_f on_timer_update)
 {
 
     int timer_id = wasm_create_timer(interval, is_period, auto_start);
 
-    //TODO
-    struct user_timer * timer = (struct user_timer *) malloc(
-            sizeof(struct user_timer));
+    // TODO
+    struct user_timer *timer =
+        (struct user_timer *)malloc(sizeof(struct user_timer));
     if (timer == NULL) {
         // TODO: remove the timer_id
         printf("### api_timer_create malloc faild!!! \n");
@@ -52,7 +53,8 @@ user_timer_t api_timer_create(int interval, bool is_period, bool auto_start,
     return timer;
 }
 
-void api_timer_cancel(user_timer_t timer)
+void
+api_timer_cancel(user_timer_t timer)
 {
     user_timer_t t = g_timers, prev = NULL;
 
@@ -63,26 +65,30 @@ void api_timer_cancel(user_timer_t timer)
             if (prev == NULL) {
                 g_timers = t->next;
                 free(t);
-            } else {
+            }
+            else {
                 prev->next = t->next;
                 free(t);
             }
             return;
-        } else {
+        }
+        else {
             prev = t;
             t = t->next;
         }
     }
 }
 
-void api_timer_restart(user_timer_t timer, int interval)
+void
+api_timer_restart(user_timer_t timer, int interval)
 {
     wasm_timer_restart(timer->timer_id, interval);
 }
 
-void on_timer_callback(int timer_id)
+void
+on_timer_callback(int timer_id)
 {
-    struct user_timer * t = g_timers;
+    struct user_timer *t = g_timers;
 
     while (t) {
         if (t->timer_id == timer_id) {
@@ -92,4 +98,3 @@ void on_timer_callback(int timer_id)
         t = t->next;
     }
 }
-

+ 0 - 1
core/app-framework/base/app/timer_api.h

@@ -34,4 +34,3 @@ wasm_get_sys_tick_ms(void);
 #endif
 
 #endif /* end of _TIMER_API_H_ */
-

+ 34 - 33
core/app-framework/base/app/wa-inc/request.h

@@ -12,7 +12,6 @@
 extern "C" {
 #endif
 
-
 /* CoAP request method codes */
 typedef enum {
     COAP_GET = 1,
@@ -26,39 +25,40 @@ typedef enum {
 typedef enum {
     NO_ERROR = 0,
 
-    CREATED_2_01 = 65, /* CREATED */
-    DELETED_2_02 = 66, /* DELETED */
-    VALID_2_03 = 67, /* NOT_MODIFIED */
-    CHANGED_2_04 = 68, /* CHANGED */
-    CONTENT_2_05 = 69, /* OK */
+    CREATED_2_01 = 65,  /* CREATED */
+    DELETED_2_02 = 66,  /* DELETED */
+    VALID_2_03 = 67,    /* NOT_MODIFIED */
+    CHANGED_2_04 = 68,  /* CHANGED */
+    CONTENT_2_05 = 69,  /* OK */
     CONTINUE_2_31 = 95, /* CONTINUE */
 
-    BAD_REQUEST_4_00 = 128, /* BAD_REQUEST */
-    UNAUTHORIZED_4_01 = 129, /* UNAUTHORIZED */
-    BAD_OPTION_4_02 = 130, /* BAD_OPTION */
-    FORBIDDEN_4_03 = 131, /* FORBIDDEN */
-    NOT_FOUND_4_04 = 132, /* NOT_FOUND */
-    METHOD_NOT_ALLOWED_4_05 = 133, /* METHOD_NOT_ALLOWED */
-    NOT_ACCEPTABLE_4_06 = 134, /* NOT_ACCEPTABLE */
-    PRECONDITION_FAILED_4_12 = 140, /* BAD_REQUEST */
+    BAD_REQUEST_4_00 = 128,              /* BAD_REQUEST */
+    UNAUTHORIZED_4_01 = 129,             /* UNAUTHORIZED */
+    BAD_OPTION_4_02 = 130,               /* BAD_OPTION */
+    FORBIDDEN_4_03 = 131,                /* FORBIDDEN */
+    NOT_FOUND_4_04 = 132,                /* NOT_FOUND */
+    METHOD_NOT_ALLOWED_4_05 = 133,       /* METHOD_NOT_ALLOWED */
+    NOT_ACCEPTABLE_4_06 = 134,           /* NOT_ACCEPTABLE */
+    PRECONDITION_FAILED_4_12 = 140,      /* BAD_REQUEST */
     REQUEST_ENTITY_TOO_LARGE_4_13 = 141, /* REQUEST_ENTITY_TOO_LARGE */
-    UNSUPPORTED_MEDIA_TYPE_4_15 = 143, /* UNSUPPORTED_MEDIA_TYPE */
+    UNSUPPORTED_MEDIA_TYPE_4_15 = 143,   /* UNSUPPORTED_MEDIA_TYPE */
 
-    INTERNAL_SERVER_ERROR_5_00 = 160, /* INTERNAL_SERVER_ERROR */
-    NOT_IMPLEMENTED_5_01 = 161, /* NOT_IMPLEMENTED */
-    BAD_GATEWAY_5_02 = 162, /* BAD_GATEWAY */
-    SERVICE_UNAVAILABLE_5_03 = 163, /* SERVICE_UNAVAILABLE */
-    GATEWAY_TIMEOUT_5_04 = 164, /* GATEWAY_TIMEOUT */
+    INTERNAL_SERVER_ERROR_5_00 = 160,  /* INTERNAL_SERVER_ERROR */
+    NOT_IMPLEMENTED_5_01 = 161,        /* NOT_IMPLEMENTED */
+    BAD_GATEWAY_5_02 = 162,            /* BAD_GATEWAY */
+    SERVICE_UNAVAILABLE_5_03 = 163,    /* SERVICE_UNAVAILABLE */
+    GATEWAY_TIMEOUT_5_04 = 164,        /* GATEWAY_TIMEOUT */
     PROXYING_NOT_SUPPORTED_5_05 = 165, /* PROXYING_NOT_SUPPORTED */
 
     /* Erbium errors */
-    MEMORY_ALLOCATION_ERROR = 192, PACKET_SERIALIZATION_ERROR,
+    MEMORY_ALLOCATION_ERROR = 192,
+    PACKET_SERIALIZATION_ERROR,
 
     /* Erbium hooks */
-    MANUAL_RESPONSE, PING_RESPONSE
+    MANUAL_RESPONSE,
+    PING_RESPONSE
 } coap_status_t;
 
-
 /**
  * @typedef request_handler_f
  *
@@ -87,7 +87,6 @@ typedef void (*request_handler_f)(request_t *request);
  */
 typedef void (*response_handler_f)(response_t *response, void *user_data);
 
-
 /*
  *****************
  * Request APIs
@@ -102,7 +101,8 @@ typedef void (*response_handler_f)(response_t *response, void *user_data);
  *
  * @return true if success, false otherwise
  */
-bool api_register_resource_handler(const char *url, request_handler_f handler);
+bool
+api_register_resource_handler(const char *url, request_handler_f handler);
 
 /**
  * @brief Send request asynchronously.
@@ -111,8 +111,9 @@ bool api_register_resource_handler(const char *url, request_handler_f handler);
  * @param response_handler callback function to handle the response
  * @param user_data user data
  */
-void api_send_request(request_t * request, response_handler_f response_handler,
-        void * user_data);
+void
+api_send_request(request_t *request, response_handler_f response_handler,
+                 void *user_data);
 
 /**
  * @brief Send response.
@@ -130,8 +131,8 @@ void api_send_request(request_t * request, response_handler_f response_handler,
  * }
  * @endcode
  */
-void api_response_send(response_t *response);
-
+void
+api_response_send(response_t *response);
 
 /*
  *****************
@@ -149,9 +150,8 @@ void api_response_send(response_t *response);
  *
  * @return true if success, false otherwise
  */
-bool api_publish_event(const char *url, int fmt, void *payload,
-        int payload_len);
-
+bool
+api_publish_event(const char *url, int fmt, void *payload, int payload_len);
 
 /**
  * @brief Subscribe an event.
@@ -161,7 +161,8 @@ bool api_publish_event(const char *url, int fmt, void *payload,
  *
  * @return true if success, false otherwise
  */
-bool api_subscribe_event(const char * url, request_handler_f handler);
+bool
+api_subscribe_event(const char *url, request_handler_f handler);
 
 #ifdef __cplusplus
 }

+ 8 - 5
core/app-framework/base/app/wa-inc/timer_wasm_app.h

@@ -14,7 +14,7 @@ extern "C" {
 
 /* board producer define user_timer */
 struct user_timer;
-typedef struct user_timer * user_timer_t;
+typedef struct user_timer *user_timer_t;
 
 /**
  * @typedef on_user_timer_update_f
@@ -43,15 +43,17 @@ typedef void (*on_user_timer_update_f)(user_timer_t timer);
  *
  * @return the timer created if success, NULL otherwise
  */
-user_timer_t api_timer_create(int interval, bool is_period, bool auto_start,
-        on_user_timer_update_f on_timer_update);
+user_timer_t
+api_timer_create(int interval, bool is_period, bool auto_start,
+                 on_user_timer_update_f on_timer_update);
 
 /**
  * @brief Cancel timer.
  *
  * @param timer the timer to cancel
  */
-void api_timer_cancel(user_timer_t timer);
+void
+api_timer_cancel(user_timer_t timer);
 
 /**
  * @brief Restart timer.
@@ -59,7 +61,8 @@ void api_timer_cancel(user_timer_t timer);
  * @param timer the timer to cancel
  * @param interval the timer interval
  */
-void api_timer_restart(user_timer_t timer, int interval);
+void
+api_timer_restart(user_timer_t timer, int interval);
 
 #ifdef __cplusplus
 }

+ 0 - 1
core/app-framework/base/app/wasm_app.h

@@ -13,7 +13,6 @@
 extern "C" {
 #endif
 
-
 #ifdef __cplusplus
 }
 #endif

+ 5 - 6
core/app-framework/base/native/base_lib_export.c

@@ -10,16 +10,15 @@
 #include "req_resp_native_api.h"
 #include "timer_native_api.h"
 
-
 static NativeSymbol extended_native_symbol_defs[] = {
-    /* TODO: use macro EXPORT_WASM_API() or EXPORT_WASM_API2() to
-       add functions to register. */
-	#include "base_lib.inl"
+/* TODO: use macro EXPORT_WASM_API() or EXPORT_WASM_API2() to
+   add functions to register. */
+#include "base_lib.inl"
 };
 
-uint32 get_base_lib_export_apis(NativeSymbol **p_base_lib_apis)
+uint32
+get_base_lib_export_apis(NativeSymbol **p_base_lib_apis)
 {
     *p_base_lib_apis = extended_native_symbol_defs;
     return sizeof(extended_native_symbol_defs) / sizeof(NativeSymbol);
 }
-

+ 0 - 1
core/app-framework/base/native/req_resp_native_api.h

@@ -27,4 +27,3 @@ wasm_sub_event(wasm_exec_env_t exec_env, char *url);
 #endif
 
 #endif /* end of _REQ_RESP_API_H_ */
-

+ 8 - 8
core/app-framework/base/native/request_response.c

@@ -8,7 +8,8 @@
 #include "wasm_export.h"
 #include "bh_assert.h"
 
-extern void module_request_handler(request_t *request, void *user_data);
+extern void
+module_request_handler(request_t *request, void *user_data);
 
 bool
 wasm_response_send(wasm_exec_env_t exec_env, char *buffer, int size)
@@ -33,8 +34,8 @@ wasm_register_resource(wasm_exec_env_t exec_env, char *url)
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
 
     if (url != NULL) {
-        unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
-                                                        module_inst);
+        unsigned int mod_id =
+            app_manager_get_module_id(Module_WASM_App, module_inst);
         bh_assert(mod_id != ID_NONE);
         am_register_resource(url, module_request_handler, mod_id);
     }
@@ -54,8 +55,8 @@ wasm_post_request(wasm_exec_env_t exec_env, char *buffer, int size)
         // TODO: add permission check, ensure app can't do harm
 
         // set sender to help dispatch the response to the sender ap
-        unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
-                                                        module_inst);
+        unsigned int mod_id =
+            app_manager_get_module_id(Module_WASM_App, module_inst);
         bh_assert(mod_id != ID_NONE);
         req->sender = mod_id;
 
@@ -74,11 +75,10 @@ wasm_sub_event(wasm_exec_env_t exec_env, char *url)
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
 
     if (url != NULL) {
-        unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
-                                                        module_inst);
+        unsigned int mod_id =
+            app_manager_get_module_id(Module_WASM_App, module_inst);
 
         bh_assert(mod_id != ID_NONE);
         am_register_event(url, mod_id);
     }
 }
-

+ 10 - 6
core/app-framework/base/native/runtime_lib.h

@@ -6,13 +6,17 @@
 #ifndef LIB_BASE_RUNTIME_LIB_H_
 #define LIB_BASE_RUNTIME_LIB_H_
 
-
 #include "runtime_timer.h"
 
-void init_wasm_timer();
-void exit_wasm_timer();
-timer_ctx_t get_wasm_timer_ctx();
-timer_ctx_t create_wasm_timer_ctx(unsigned int module_id, int prealloc_num);
-void destroy_module_timer_ctx(unsigned int module_id);
+void
+init_wasm_timer();
+void
+exit_wasm_timer();
+timer_ctx_t
+get_wasm_timer_ctx();
+timer_ctx_t
+create_wasm_timer_ctx(unsigned int module_id, int prealloc_num);
+void
+destroy_module_timer_ctx(unsigned int module_id);
 
 #endif /* LIB_BASE_RUNTIME_LIB_H_ */

+ 3 - 6
core/app-framework/base/native/timer_native_api.h

@@ -9,7 +9,6 @@
 #include "bh_platform.h"
 #include "wasm_export.h"
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -23,15 +22,14 @@ typedef unsigned int timer_id_t;
 typedef unsigned int timer_id_t;
 
 timer_id_t
-wasm_create_timer(wasm_exec_env_t exec_env,
-                  int interval, bool is_period, bool auto_start);
+wasm_create_timer(wasm_exec_env_t exec_env, int interval, bool is_period,
+                  bool auto_start);
 void
 wasm_timer_destroy(wasm_exec_env_t exec_env, timer_id_t timer_id);
 void
 wasm_timer_cancel(wasm_exec_env_t exec_env, timer_id_t timer_id);
 void
-wasm_timer_restart(wasm_exec_env_t exec_env,
-                   timer_id_t timer_id, int interval);
+wasm_timer_restart(wasm_exec_env_t exec_env, timer_id_t timer_id, int interval);
 uint32
 wasm_get_sys_tick_ms(wasm_exec_env_t exec_env);
 
@@ -40,4 +38,3 @@ wasm_get_sys_tick_ms(wasm_exec_env_t exec_env);
 #endif
 
 #endif /* end of _TIMER_API_H_ */
-

+ 20 - 23
core/app-framework/base/native/timer_wrapper.c

@@ -22,7 +22,7 @@ static korp_mutex g_timer_ctx_list_mutex;
 void
 wasm_timer_callback(timer_id_t id, unsigned int mod_id)
 {
-    module_data* module = module_data_list_lookup_id(mod_id);
+    module_data *module = module_data_list_lookup_id(mod_id);
     if (module == NULL)
         return;
 
@@ -40,7 +40,8 @@ wasm_timer_callback(timer_id_t id, unsigned int mod_id)
  * the module from module id. It is for avoiding that situation.
  */
 
-void * thread_modulers_timer_check(void * arg)
+void *
+thread_modulers_timer_check(void *arg)
 {
     uint32 ms_to_expiry;
     uint64 us_to_wait;
@@ -48,8 +49,8 @@ void * thread_modulers_timer_check(void * arg)
     while (timer_thread_run) {
         ms_to_expiry = (uint32)-1;
         os_mutex_lock(&g_timer_ctx_list_mutex);
-        timer_ctx_node_t* elem = (timer_ctx_node_t*)
-                                 bh_list_first_elem(&g_timer_ctx_list);
+        timer_ctx_node_t *elem =
+            (timer_ctx_node_t *)bh_list_first_elem(&g_timer_ctx_list);
         while (elem) {
             uint32 next = check_app_timers(elem->timer_ctx);
             if (next != (uint32)-1) {
@@ -57,7 +58,7 @@ void * thread_modulers_timer_check(void * arg)
                     ms_to_expiry = next;
             }
 
-            elem = (timer_ctx_node_t*) bh_list_elem_next(elem);
+            elem = (timer_ctx_node_t *)bh_list_elem_next(elem);
         }
         os_mutex_unlock(&g_timer_ctx_list_mutex);
 
@@ -93,8 +94,8 @@ init_wasm_timer()
        would recursive lock the mutex */
     os_recursive_mutex_init(&g_timer_ctx_list_mutex);
 
-    os_thread_create(&tm_tid, thread_modulers_timer_check,
-                     NULL, BH_APPLET_PRESERVED_STACK_SIZE);
+    os_thread_create(&tm_tid, thread_modulers_timer_check, NULL,
+                     BH_APPLET_PRESERVED_STACK_SIZE);
 }
 
 void
@@ -106,15 +107,15 @@ exit_wasm_timer()
 timer_ctx_t
 create_wasm_timer_ctx(unsigned int module_id, int prealloc_num)
 {
-    timer_ctx_t ctx = create_timer_ctx(wasm_timer_callback,
-                                       wakeup_modules_timer_thread,
-                                       prealloc_num, module_id);
+    timer_ctx_t ctx =
+        create_timer_ctx(wasm_timer_callback, wakeup_modules_timer_thread,
+                         prealloc_num, module_id);
 
     if (ctx == NULL)
         return NULL;
 
-    timer_ctx_node_t * node = (timer_ctx_node_t*)
-                              wasm_runtime_malloc(sizeof(timer_ctx_node_t));
+    timer_ctx_node_t *node =
+        (timer_ctx_node_t *)wasm_runtime_malloc(sizeof(timer_ctx_node_t));
     if (node == NULL) {
         destroy_timer_ctx(ctx);
         return NULL;
@@ -132,11 +133,10 @@ create_wasm_timer_ctx(unsigned int module_id, int prealloc_num)
 void
 destroy_module_timer_ctx(unsigned int module_id)
 {
-    timer_ctx_node_t* elem;
+    timer_ctx_node_t *elem;
 
     os_mutex_lock(&g_timer_ctx_list_mutex);
-    elem = (timer_ctx_node_t*)
-           bh_list_first_elem(&g_timer_ctx_list);
+    elem = (timer_ctx_node_t *)bh_list_first_elem(&g_timer_ctx_list);
     while (elem) {
         if (timer_ctx_get_owner(elem->timer_ctx) == module_id) {
             bh_list_remove(&g_timer_ctx_list, elem);
@@ -145,7 +145,7 @@ destroy_module_timer_ctx(unsigned int module_id)
             break;
         }
 
-        elem = (timer_ctx_node_t*) bh_list_elem_next(elem);
+        elem = (timer_ctx_node_t *)bh_list_elem_next(elem);
     }
     os_mutex_unlock(&g_timer_ctx_list_mutex);
 }
@@ -153,16 +153,15 @@ destroy_module_timer_ctx(unsigned int module_id)
 timer_ctx_t
 get_wasm_timer_ctx(wasm_module_inst_t module_inst)
 {
-    module_data * m = app_manager_get_module_data(Module_WASM_App,
-                                                  module_inst);
+    module_data *m = app_manager_get_module_data(Module_WASM_App, module_inst);
     if (m == NULL)
         return NULL;
     return m->timer_ctx;
 }
 
 timer_id_t
-wasm_create_timer(wasm_exec_env_t exec_env,
-                  int interval, bool is_period, bool auto_start)
+wasm_create_timer(wasm_exec_env_t exec_env, int interval, bool is_period,
+                  bool auto_start)
 {
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
     timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
@@ -189,8 +188,7 @@ wasm_timer_cancel(wasm_exec_env_t exec_env, timer_id_t timer_id)
 }
 
 void
-wasm_timer_restart(wasm_exec_env_t exec_env,
-                   timer_id_t timer_id, int interval)
+wasm_timer_restart(wasm_exec_env_t exec_env, timer_id_t timer_id, int interval)
 {
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
     timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
@@ -203,4 +201,3 @@ wasm_get_sys_tick_ms(wasm_exec_env_t exec_env)
 {
     return (uint32)bh_get_tick_ms();
 }
-

+ 19 - 20
core/app-framework/connection/app/connection.c

@@ -24,10 +24,9 @@ typedef struct _connection {
 /* Raw connections list */
 static connection_t *g_conns = NULL;
 
-connection_t *api_open_connection(const char *name,
-                                  attr_container_t *args,
-                                  on_connection_event_f on_event,
-                                  void *user_data)
+connection_t *
+api_open_connection(const char *name, attr_container_t *args,
+                    on_connection_event_f on_event, void *user_data)
 {
     connection_t *conn;
     char *args_buffer = (char *)args;
@@ -51,14 +50,16 @@ connection_t *api_open_connection(const char *name,
     if (g_conns != NULL) {
         conn->next = g_conns;
         g_conns = conn;
-    } else {
+    }
+    else {
         g_conns = conn;
     }
 
     return conn;
 }
 
-void api_close_connection(connection_t *c)
+void
+api_close_connection(connection_t *c)
 {
     connection_t *conn = g_conns, *prev = NULL;
 
@@ -71,19 +72,22 @@ void api_close_connection(connection_t *c)
                 g_conns = conn->next;
             free(conn);
             return;
-        } else {
+        }
+        else {
             prev = conn;
             conn = conn->next;
         }
     }
 }
 
-int api_send_on_connection(connection_t *conn, const char *data, uint32 len)
+int
+api_send_on_connection(connection_t *conn, const char *data, uint32 len)
 {
     return wasm_send_on_connection(conn->handle, data, len);
 }
 
-bool api_config_connection(connection_t *conn, attr_container_t *cfg)
+bool
+api_config_connection(connection_t *conn, attr_container_t *cfg)
 {
     char *cfg_buffer = (char *)cfg;
     uint32 cfg_len = attr_container_get_serialize_length(cfg);
@@ -91,23 +95,19 @@ bool api_config_connection(connection_t *conn, attr_container_t *cfg)
     return wasm_config_connection(conn->handle, cfg_buffer, cfg_len);
 }
 
-void on_connection_data(uint32 handle, char *buffer, uint32 len)
+void
+on_connection_data(uint32 handle, char *buffer, uint32 len)
 {
     connection_t *conn = g_conns;
 
     while (conn != NULL) {
         if (conn->handle == handle) {
             if (len == 0) {
-                conn->on_event(conn,
-                               CONN_EVENT_TYPE_DISCONNECT,
-                               NULL,
-                               0,
+                conn->on_event(conn, CONN_EVENT_TYPE_DISCONNECT, NULL, 0,
                                conn->user_data);
-            } else {
-                conn->on_event(conn,
-                               CONN_EVENT_TYPE_DATA,
-                               buffer,
-                               len,
+            }
+            else {
+                conn->on_event(conn, CONN_EVENT_TYPE_DATA, buffer, len,
                                conn->user_data);
             }
 
@@ -116,4 +116,3 @@ void on_connection_data(uint32 handle, char *buffer, uint32 len)
         conn = conn->next;
     }
 }
-

+ 0 - 1
core/app-framework/connection/app/connection_api.h

@@ -28,5 +28,4 @@ wasm_config_connection(uint32 handle, const char *cfg_buf, uint32 cfg_buf_len);
 }
 #endif
 
-
 #endif /* end of CONNECTION_API_H_ */

+ 11 - 12
core/app-framework/connection/app/wa-inc/connection.h

@@ -33,10 +33,8 @@ typedef enum {
  * @param user_data user data
  */
 typedef void (*on_connection_event_f)(connection_t *conn,
-                                      conn_event_type_t type,
-                                      const char *data,
-                                      uint32 len,
-                                      void *user_data);
+                                      conn_event_type_t type, const char *data,
+                                      uint32 len, void *user_data);
 
 /*
  *****************
@@ -54,17 +52,17 @@ typedef void (*on_connection_event_f)(connection_t *conn,
  *
  * @return the connection or NULL means fail
  */
-connection_t *api_open_connection(const char *name,
-                                  attr_container_t *args,
-                                  on_connection_event_f on_event,
-                                  void *user_data);
+connection_t *
+api_open_connection(const char *name, attr_container_t *args,
+                    on_connection_event_f on_event, void *user_data);
 
 /*
  * @brief Close a connection.
  *
  * @param conn connection
  */
-void api_close_connection(connection_t *conn);
+void
+api_close_connection(connection_t *conn);
 
 /*
  * Send data to the connection in non-blocking manner which returns immediately
@@ -75,7 +73,8 @@ void api_close_connection(connection_t *conn);
  *
  * @return actual length sent, or -1 if fail(maybe underlying buffer is full)
  */
-int api_send_on_connection(connection_t *conn, const char *data, uint32 len);
+int
+api_send_on_connection(connection_t *conn, const char *data, uint32 len);
 
 /*
  * @brief Configure connection.
@@ -85,8 +84,8 @@ int api_send_on_connection(connection_t *conn, const char *data, uint32 len);
  *
  * @return true if success, false otherwise
  */
-bool api_config_connection(connection_t *conn, attr_container_t *cfg);
-
+bool
+api_config_connection(connection_t *conn, attr_container_t *cfg);
 
 #ifdef __cplusplus
 }

+ 3 - 5
core/app-framework/connection/native/connection_lib.h

@@ -13,10 +13,9 @@
 extern "C" {
 #endif
 
-/*
- *****************
- * This file defines connection library which should be implemented by different platforms
- *****************
+/**
+ * This file defines connection library which should be implemented by
+ * different platforms
  */
 
 /*
@@ -73,5 +72,4 @@ extern connection_interface_t connection_impl;
 }
 #endif
 
-
 #endif /* CONNECTION_LIB_H_ */

+ 7 - 12
core/app-framework/connection/native/connection_native_api.h

@@ -13,29 +13,24 @@
 extern "C" {
 #endif
 
-
 /*
  * connection interfaces
  */
 
 uint32
-wasm_open_connection(wasm_exec_env_t exec_env,
-                     char *name, char *args_buf, uint32 len);
+wasm_open_connection(wasm_exec_env_t exec_env, char *name, char *args_buf,
+                     uint32 len);
 void
-wasm_close_connection(wasm_exec_env_t exec_env,
-                      uint32 handle);
+wasm_close_connection(wasm_exec_env_t exec_env, uint32 handle);
 int
-wasm_send_on_connection(wasm_exec_env_t exec_env,
-                        uint32 handle, char *data, uint32 len);
+wasm_send_on_connection(wasm_exec_env_t exec_env, uint32 handle, char *data,
+                        uint32 len);
 bool
-wasm_config_connection(wasm_exec_env_t exec_env,
-                       uint32 handle, char *cfg_buf, uint32 len);
-
-
+wasm_config_connection(wasm_exec_env_t exec_env, uint32 handle, char *cfg_buf,
+                       uint32 len);
 
 #ifdef __cplusplus
 }
 #endif
 
-
 #endif /* end of CONNECTION_API_H_ */

+ 8 - 8
core/app-framework/connection/native/connection_wrapper.c

@@ -8,15 +8,15 @@
 #include "native_interface.h"
 #include "connection_native_api.h"
 
-
 /* Note:
  *
- * This file is the consumer of connection lib which is implemented by different platforms
+ * This file is the consumer of connection lib which is implemented by different
+ * platforms
  */
 
 uint32
-wasm_open_connection(wasm_exec_env_t exec_env,
-                     char *name, char *args_buf, uint32 len)
+wasm_open_connection(wasm_exec_env_t exec_env, char *name, char *args_buf,
+                     uint32 len)
 {
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
     attr_container_t *args;
@@ -37,8 +37,8 @@ wasm_close_connection(wasm_exec_env_t exec_env, uint32 handle)
 }
 
 int
-wasm_send_on_connection(wasm_exec_env_t exec_env,
-                        uint32 handle, char *data, uint32 len)
+wasm_send_on_connection(wasm_exec_env_t exec_env, uint32 handle, char *data,
+                        uint32 len)
 {
     if (connection_impl._send != NULL)
         return connection_impl._send(handle, data, len);
@@ -47,8 +47,8 @@ wasm_send_on_connection(wasm_exec_env_t exec_env,
 }
 
 bool
-wasm_config_connection(wasm_exec_env_t exec_env,
-                       uint32 handle, char *cfg_buf, uint32 len)
+wasm_config_connection(wasm_exec_env_t exec_env, uint32 handle, char *cfg_buf,
+                       uint32 len)
 {
     attr_container_t *cfg;
 

+ 7 - 4
core/app-framework/connection/native/linux/conn_tcp.c

@@ -11,7 +11,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-int tcp_open(char *address, uint16 port)
+int
+tcp_open(char *address, uint16 port)
 {
     int sock, ret;
     struct sockaddr_in servaddr;
@@ -25,7 +26,7 @@ int tcp_open(char *address, uint16 port)
     if (sock == -1)
         return -1;
 
-    ret = connect(sock, (struct sockaddr*)&servaddr, sizeof(servaddr));
+    ret = connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr));
     if (ret == -1) {
         close(sock);
         return -1;
@@ -40,12 +41,14 @@ int tcp_open(char *address, uint16 port)
     return sock;
 }
 
-int tcp_send(int sock, const char *data, int size)
+int
+tcp_send(int sock, const char *data, int size)
 {
     return send(sock, data, size, 0);
 }
 
-int tcp_recv(int sock, char *buffer, int buf_size)
+int
+tcp_recv(int sock, char *buffer, int buf_size)
 {
     return recv(sock, buffer, buf_size, 0);
 }

+ 6 - 4
core/app-framework/connection/native/linux/conn_tcp.h

@@ -12,15 +12,17 @@
 extern "C" {
 #endif
 
-int tcp_open(char *address, uint16 port);
+int
+tcp_open(char *address, uint16 port);
 
-int tcp_send(int sock, const char *data, int size);
+int
+tcp_send(int sock, const char *data, int size);
 
-int tcp_recv(int sock, char *buffer, int buf_size);
+int
+tcp_recv(int sock, char *buffer, int buf_size);
 
 #ifdef __cplusplus
 }
 #endif
 
-
 #endif

+ 8 - 4
core/app-framework/connection/native/linux/conn_uart.c

@@ -9,7 +9,8 @@
 #include <termios.h>
 #include <unistd.h>
 
-static int parse_baudrate(int baud)
+static int
+parse_baudrate(int baud)
 {
     switch (baud) {
         case 9600:
@@ -53,7 +54,8 @@ static int parse_baudrate(int baud)
     }
 }
 
-int uart_open(char* device, int baudrate)
+int
+uart_open(char *device, int baudrate)
 {
     int uart_fd;
     struct termios uart_term;
@@ -88,12 +90,14 @@ int uart_open(char* device, int baudrate)
     return uart_fd;
 }
 
-int uart_send(int fd, const char *data, int size)
+int
+uart_send(int fd, const char *data, int size)
 {
     return write(fd, data, size);
 }
 
-int uart_recv(int fd, char *buffer, int buf_size)
+int
+uart_recv(int fd, char *buffer, int buf_size)
 {
     return read(fd, buffer, buf_size);
 }

+ 6 - 4
core/app-framework/connection/native/linux/conn_uart.h

@@ -12,15 +12,17 @@
 extern "C" {
 #endif
 
-int uart_open(char* device, int baudrate);
+int
+uart_open(char *device, int baudrate);
 
-int uart_send(int fd, const char *data, int size);
+int
+uart_send(int fd, const char *data, int size);
 
-int uart_recv(int fd, char *buffer, int buf_size);
+int
+uart_recv(int fd, char *buffer, int buf_size);
 
 #ifdef __cplusplus
 }
 #endif
 
-
 #endif

+ 8 - 9
core/app-framework/connection/native/linux/conn_udp.c

@@ -11,7 +11,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-int udp_open(uint16 port)
+int
+udp_open(uint16 port)
 {
     int sock, ret;
     struct sockaddr_in addr;
@@ -25,7 +26,7 @@ int udp_open(uint16 port)
     addr.sin_addr.s_addr = htonl(INADDR_ANY);
     addr.sin_port = htons(port);
 
-    ret = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
+    ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
     if (ret == -1) {
         close(sock);
         return -1;
@@ -40,20 +41,18 @@ int udp_open(uint16 port)
     return sock;
 }
 
-int udp_send(int sock, struct sockaddr *dest, const char *data, int size)
+int
+udp_send(int sock, struct sockaddr *dest, const char *data, int size)
 {
     return sendto(sock, data, size, MSG_CONFIRM, dest, sizeof(*dest));
 }
 
-int udp_recv(int sock, char *buffer, int buf_size)
+int
+udp_recv(int sock, char *buffer, int buf_size)
 {
     struct sockaddr_in remaddr;
     socklen_t addrlen = sizeof(remaddr);
 
-    return recvfrom(sock,
-                    buffer,
-                    buf_size,
-                    0,
-                    (struct sockaddr *)&remaddr,
+    return recvfrom(sock, buffer, buf_size, 0, (struct sockaddr *)&remaddr,
                     &addrlen);
 }

+ 6 - 4
core/app-framework/connection/native/linux/conn_udp.h

@@ -12,15 +12,17 @@
 extern "C" {
 #endif
 
-int udp_open(uint16 port);
+int
+udp_open(uint16 port);
 
-int udp_send(int sock, struct sockaddr *dest, const char *data, int size);
+int
+udp_send(int sock, struct sockaddr *dest, const char *data, int size);
 
-int udp_recv(int sock, char *buffer, int buf_size);
+int
+udp_recv(int sock, char *buffer, int buf_size);
 
 #ifdef __cplusplus
 }
 #endif
 
-
 #endif

+ 108 - 84
core/app-framework/connection/native/linux/connection_mgr.c

@@ -76,23 +76,30 @@ static struct epoll_event epoll_events[MAX_EVENTS];
 /* Buffer to receive data */
 static char io_buf[IO_BUF_SIZE];
 
-static uint32 _conn_open(wasm_module_inst_t module_inst,
-                         const char *name, attr_container_t *args);
-static void _conn_close(uint32 handle);
-static int _conn_send(uint32 handle, const char *data, int len);
-static bool _conn_config(uint32 handle, attr_container_t *cfg);
-
+static uint32
+_conn_open(wasm_module_inst_t module_inst, const char *name,
+           attr_container_t *args);
+static void
+_conn_close(uint32 handle);
+static int
+_conn_send(uint32 handle, const char *data, int len);
+static bool
+_conn_config(uint32 handle, attr_container_t *cfg);
+
+/* clang-format off */
 /*
  * Platform implementation of connection library
  */
 connection_interface_t connection_impl = {
-        ._open = _conn_open,
-        ._close = _conn_close,
-        ._send = _conn_send,
-        ._config = _conn_config
+    ._open = _conn_open,
+    ._close = _conn_close,
+    ._send = _conn_send,
+    ._config = _conn_config
 };
+/* clang-format on */
 
-static void add_connection(sys_connection_t *conn)
+static void
+add_connection(sys_connection_t *conn)
 {
     os_mutex_lock(&g_lock);
 
@@ -104,20 +111,23 @@ static void add_connection(sys_connection_t *conn)
     if (g_connections) {
         conn->next = g_connections;
         g_connections = conn;
-    } else {
+    }
+    else {
         g_connections = conn;
     }
 
     os_mutex_unlock(&g_lock);
 }
 
-#define FREE_CONNECTION(conn) do {      \
-    if (conn->arg)                      \
-        wasm_runtime_free(conn->arg);   \
-    wasm_runtime_free(conn);            \
-} while (0)
+#define FREE_CONNECTION(conn)             \
+    do {                                  \
+        if (conn->arg)                    \
+            wasm_runtime_free(conn->arg); \
+        wasm_runtime_free(conn);          \
+    } while (0)
 
-static int get_app_conns_num(uint32 module_id)
+static int
+get_app_conns_num(uint32 module_id)
 {
     sys_connection_t *conn;
     int num = 0;
@@ -136,7 +146,8 @@ static int get_app_conns_num(uint32 module_id)
     return num;
 }
 
-static sys_connection_t *find_connection(uint32 handle, bool remove_found)
+static sys_connection_t *
+find_connection(uint32 handle, bool remove_found)
 {
     sys_connection_t *conn, *prev = NULL;
 
@@ -148,13 +159,15 @@ static sys_connection_t *find_connection(uint32 handle, bool remove_found)
             if (remove_found) {
                 if (prev != NULL) {
                     prev->next = conn->next;
-                } else {
+                }
+                else {
                     g_connections = conn->next;
                 }
             }
             os_mutex_unlock(&g_lock);
             return conn;
-        } else {
+        }
+        else {
             prev = conn;
             conn = conn->next;
         }
@@ -165,7 +178,8 @@ static sys_connection_t *find_connection(uint32 handle, bool remove_found)
     return NULL;
 }
 
-static void cleanup_connections(uint32 module_id)
+static void
+cleanup_connections(uint32 module_id)
 {
     sys_connection_t *conn, *prev = NULL;
 
@@ -181,12 +195,14 @@ static void cleanup_connections(uint32 module_id)
                 prev->next = conn->next;
                 FREE_CONNECTION(conn);
                 conn = prev->next;
-            } else {
+            }
+            else {
                 g_connections = conn->next;
                 FREE_CONNECTION(conn);
                 conn = g_connections;
             }
-        } else {
+        }
+        else {
             prev = conn;
             conn = conn->next;
         }
@@ -195,7 +211,8 @@ static void cleanup_connections(uint32 module_id)
     os_mutex_unlock(&g_lock);
 }
 
-static conn_type_t get_conn_type(const char *name)
+static conn_type_t
+get_conn_type(const char *name)
 {
     if (strcmp(name, "TCP") == 0)
         return CONN_TYPE_TCP;
@@ -208,14 +225,14 @@ static conn_type_t get_conn_type(const char *name)
 }
 
 /* --- connection lib function --- */
-static uint32 _conn_open(wasm_module_inst_t module_inst,
-                         const char *name, attr_container_t *args)
+static uint32
+_conn_open(wasm_module_inst_t module_inst, const char *name,
+           attr_container_t *args)
 {
     int fd;
     sys_connection_t *conn;
     struct epoll_event ev;
-    uint32 module_id = app_manager_get_module_id(Module_WASM_App,
-                                                 module_inst);
+    uint32 module_id = app_manager_get_module_id(Module_WASM_App, module_inst);
     bh_assert(module_id != ID_NONE);
 
     if (get_app_conns_num(module_id) >= MAX_CONNECTION_PER_APP)
@@ -237,8 +254,8 @@ static uint32 _conn_open(wasm_module_inst_t module_inst,
         uint16 port;
 
         /* Check and parse connection parameters */
-        if (!attr_container_contain_key(args, "address") ||
-            !attr_container_contain_key(args, "port"))
+        if (!attr_container_contain_key(args, "address")
+            || !attr_container_contain_key(args, "port"))
             goto fail;
 
         address = attr_container_get_as_string(args, "address");
@@ -247,8 +264,8 @@ static uint32 _conn_open(wasm_module_inst_t module_inst,
         /* Connect to TCP server */
         if (!address || (fd = tcp_open(address, port)) == -1)
             goto fail;
-
-    } else if (conn->type == CONN_TYPE_UDP) {
+    }
+    else if (conn->type == CONN_TYPE_UDP) {
         uint16 port;
 
         /* Check and parse connection parameters */
@@ -259,14 +276,14 @@ static uint32 _conn_open(wasm_module_inst_t module_inst,
         /* Bind port */
         if ((fd = udp_open(port)) == -1)
             goto fail;
-
-    } else if (conn->type == CONN_TYPE_UART) {
+    }
+    else if (conn->type == CONN_TYPE_UART) {
         char *device;
         int baud;
 
         /* Check and parse connection parameters */
-        if (!attr_container_contain_key(args, "device") ||
-            !attr_container_contain_key(args, "baudrate"))
+        if (!attr_container_contain_key(args, "device")
+            || !attr_container_contain_key(args, "baudrate"))
             goto fail;
         device = attr_container_get_as_string(args, "device");
         baud = attr_container_get_as_int(args, "baudrate");
@@ -274,7 +291,8 @@ static uint32 _conn_open(wasm_module_inst_t module_inst,
         /* Open device */
         if (!device || (fd = uart_open(device, baud)) == -1)
             goto fail;
-    } else {
+    }
+    else {
         goto fail;
     }
 
@@ -299,7 +317,8 @@ fail:
 }
 
 /* --- connection lib function --- */
-static void _conn_close(uint32 handle)
+static void
+_conn_close(uint32 handle)
 {
     sys_connection_t *conn = find_connection(handle, true);
 
@@ -311,7 +330,8 @@ static void _conn_close(uint32 handle)
 }
 
 /* --- connection lib function --- */
-static int _conn_send(uint32 handle, const char *data, int len)
+static int
+_conn_send(uint32 handle, const char *data, int len)
 {
     sys_connection_t *conn = find_connection(handle, false);
 
@@ -333,7 +353,8 @@ static int _conn_send(uint32 handle, const char *data, int len)
 }
 
 /* --- connection lib function --- */
-static bool _conn_config(uint32 handle, attr_container_t *cfg)
+static bool
+_conn_config(uint32 handle, attr_container_t *cfg)
 {
     sys_connection_t *conn = find_connection(handle, false);
 
@@ -346,8 +367,8 @@ static bool _conn_config(uint32 handle, attr_container_t *cfg)
         struct sockaddr_in *addr;
 
         /* Parse remote address/port */
-        if (!attr_container_contain_key(cfg, "address") ||
-            !attr_container_contain_key(cfg, "port"))
+        if (!attr_container_contain_key(cfg, "address")
+            || !attr_container_contain_key(cfg, "port"))
             return false;
         if (!(address = attr_container_get_as_string(cfg, "address")))
             return false;
@@ -365,7 +386,8 @@ static bool _conn_config(uint32 handle, attr_container_t *cfg)
 
             /* Set remote address as connection arg */
             conn->arg = addr;
-        } else {
+        }
+        else {
             addr = (struct sockaddr_in *)conn->arg;
             addr->sin_addr.s_addr = inet_addr(address);
             addr->sin_port = htons(port);
@@ -385,16 +407,16 @@ typedef struct connection_event {
     uint32 len;
 } connection_event_t;
 
-static void connection_event_cleaner(connection_event_t *conn_event)
+static void
+connection_event_cleaner(connection_event_t *conn_event)
 {
     if (conn_event->data != NULL)
         wasm_runtime_free(conn_event->data);
     wasm_runtime_free(conn_event);
 }
 
-static void post_msg_to_module(sys_connection_t *conn,
-                               char *data,
-                               uint32 len)
+static void
+post_msg_to_module(sys_connection_t *conn, char *data, uint32 len)
 {
     module_data *module = module_data_list_lookup_id(conn->module_id);
     char *data_copy = NULL;
@@ -404,7 +426,8 @@ static void post_msg_to_module(sys_connection_t *conn,
     if (module == NULL)
         return;
 
-    conn_data_event = (connection_event_t *)wasm_runtime_malloc(sizeof(*conn_data_event));
+    conn_data_event =
+        (connection_event_t *)wasm_runtime_malloc(sizeof(*conn_data_event));
     if (conn_data_event == NULL)
         return;
 
@@ -422,10 +445,8 @@ static void post_msg_to_module(sys_connection_t *conn,
     conn_data_event->data = data_copy;
     conn_data_event->len = len;
 
-    msg = bh_new_msg(CONNECTION_EVENT_WASM,
-                     conn_data_event,
-                     sizeof(*conn_data_event),
-                     connection_event_cleaner);
+    msg = bh_new_msg(CONNECTION_EVENT_WASM, conn_data_event,
+                     sizeof(*conn_data_event), connection_event_cleaner);
     if (!msg) {
         connection_event_cleaner(conn_data_event);
         return;
@@ -434,7 +455,8 @@ static void post_msg_to_module(sys_connection_t *conn,
     bh_post_msg2(module->queue, msg);
 }
 
-static void* polling_thread_routine (void *arg)
+static void *
+polling_thread_routine(void *arg)
 {
     while (polling_thread_run) {
         int i, n;
@@ -445,8 +467,8 @@ static void* polling_thread_routine (void *arg)
             continue;
 
         for (i = 0; i < n; i++) {
-            sys_connection_t *conn
-                             = (sys_connection_t *)epoll_events[i].data.ptr;
+            sys_connection_t *conn =
+                (sys_connection_t *)epoll_events[i].data.ptr;
 
             if (conn->type == CONN_TYPE_TCP) {
                 int count = tcp_recv(conn->fd, io_buf, IO_BUF_SIZE);
@@ -454,15 +476,18 @@ static void* polling_thread_routine (void *arg)
                     /* Connection is closed by peer */
                     post_msg_to_module(conn, NULL, 0);
                     _conn_close(conn->handle);
-                } else {
+                }
+                else {
                     /* Data is received */
                     post_msg_to_module(conn, io_buf, count);
                 }
-            } else if (conn->type == CONN_TYPE_UDP) {
+            }
+            else if (conn->type == CONN_TYPE_UDP) {
                 int count = udp_recv(conn->fd, io_buf, IO_BUF_SIZE);
                 if (count > 0)
                     post_msg_to_module(conn, io_buf, count);
-            } else if (conn->type == CONN_TYPE_UART) {
+            }
+            else if (conn->type == CONN_TYPE_UART) {
                 int count = uart_recv(conn->fd, io_buf, IO_BUF_SIZE);
                 if (count > 0)
                     post_msg_to_module(conn, io_buf, count);
@@ -473,25 +498,26 @@ static void* polling_thread_routine (void *arg)
     return NULL;
 }
 
-void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
+void
+app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
 {
     uint32 argv[3];
     wasm_function_inst_t func_on_conn_data;
     bh_assert(CONNECTION_EVENT_WASM == bh_message_type(msg));
-    wasm_data *wasm_app_data = (wasm_data*)m_data->internal_data;
+    wasm_data *wasm_app_data = (wasm_data *)m_data->internal_data;
     wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
-    connection_event_t *conn_event
-                       = (connection_event_t *)bh_message_payload(msg);
+    connection_event_t *conn_event =
+        (connection_event_t *)bh_message_payload(msg);
     int32 data_offset;
 
     if (conn_event == NULL)
         return;
 
-    func_on_conn_data = wasm_runtime_lookup_function(inst, "_on_connection_data",
-                                                     "(i32i32i32)");
+    func_on_conn_data = wasm_runtime_lookup_function(
+        inst, "_on_connection_data", "(i32i32i32)");
     if (!func_on_conn_data)
-        func_on_conn_data = wasm_runtime_lookup_function(inst, "on_connection_data",
-                                                         "(i32i32i32)");
+        func_on_conn_data = wasm_runtime_lookup_function(
+            inst, "on_connection_data", "(i32i32i32)");
     if (!func_on_conn_data) {
         printf("Cannot find function on_connection_data\n");
         return;
@@ -506,34 +532,31 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
                                     3, argv)) {
             const char *exception = wasm_runtime_get_exception(inst);
             bh_assert(exception);
-            printf(":Got exception running wasm code: %s\n",
-                   exception);
+            printf(":Got exception running wasm code: %s\n", exception);
             wasm_runtime_clear_exception(inst);
             return;
         }
-    } else {
-        data_offset = wasm_runtime_module_dup_data(inst,
-                                                   conn_event->data,
+    }
+    else {
+        data_offset = wasm_runtime_module_dup_data(inst, conn_event->data,
                                                    conn_event->len);
         if (data_offset == 0) {
             const char *exception = wasm_runtime_get_exception(inst);
             if (exception) {
-                printf("Got exception running wasm code: %s\n",
-                       exception);
+                printf("Got exception running wasm code: %s\n", exception);
                 wasm_runtime_clear_exception(inst);
             }
             return;
         }
 
         argv[0] = conn_event->handle;
-        argv[1] = (uint32) data_offset;
+        argv[1] = (uint32)data_offset;
         argv[2] = conn_event->len;
         if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_on_conn_data,
                                     3, argv)) {
             const char *exception = wasm_runtime_get_exception(inst);
             bh_assert(exception);
-            printf(":Got exception running wasm code: %s\n",
-                   exception);
+            printf(":Got exception running wasm code: %s\n", exception);
             wasm_runtime_clear_exception(inst);
             wasm_runtime_module_free(inst, data_offset);
             return;
@@ -542,7 +565,8 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
     }
 }
 
-bool init_connection_framework()
+bool
+init_connection_framework()
 {
     korp_tid tid;
 
@@ -560,14 +584,13 @@ bool init_connection_framework()
     }
 
     if (!wasm_register_msg_callback(CONNECTION_EVENT_WASM,
-                               app_mgr_connection_event_callback)) {
+                                    app_mgr_connection_event_callback)) {
         goto fail;
     }
 
-    if (os_thread_create(&tid,
-                         polling_thread_routine,
-                         NULL,
-                         BH_APPLET_PRESERVED_STACK_SIZE) != 0) {
+    if (os_thread_create(&tid, polling_thread_routine, NULL,
+                         BH_APPLET_PRESERVED_STACK_SIZE)
+        != 0) {
         goto fail;
     }
 
@@ -579,7 +602,8 @@ fail:
     return false;
 }
 
-void exit_connection_framework()
+void
+exit_connection_framework()
 {
     polling_thread_run = false;
 }

+ 6 - 4
core/app-framework/connection/native/zephyr/connection_lib_impl.c

@@ -12,12 +12,14 @@
 
 #include "connection_lib.h"
 
+/* clang-format off */
 /*
  * Platform implementation of connection library
  */
 connection_interface_t connection_impl = {
-        ._open = NULL,
-        ._close = NULL,
-        ._send = NULL,
-        ._config = NULL
+    ._open = NULL,
+    ._close = NULL,
+    ._send = NULL,
+    ._config = NULL
 };
+/* clang-format on */

+ 21 - 14
core/app-framework/sensor/app/sensor.c

@@ -8,7 +8,7 @@
 #include "sensor_api.h"
 
 typedef struct _sensor {
-    struct _sensor * next;
+    struct _sensor *next;
     char *name;
     uint32 handle;
     void (*sensor_callback)(sensor_t, attr_container_t *, void *);
@@ -17,16 +17,16 @@ typedef struct _sensor {
 
 static sensor_t g_sensors = NULL;
 
-sensor_t sensor_open(const char* name, int index,
-        sensor_event_handler_f sensor_event_handler,
-        void *user_data)
+sensor_t
+sensor_open(const char *name, int index,
+            sensor_event_handler_f sensor_event_handler, void *user_data)
 {
     uint32 id = wasm_sensor_open(name, index);
     if (id == -1)
         return NULL;
 
-    //create local node for holding the user callback
-    sensor_t sensor = (sensor_t) malloc(sizeof(struct _sensor));
+    // create local node for holding the user callback
+    sensor_t sensor = (sensor_t)malloc(sizeof(struct _sensor));
     if (sensor == NULL)
         return NULL;
 
@@ -43,7 +43,8 @@ sensor_t sensor_open(const char* name, int index,
 
     if (g_sensors == NULL) {
         g_sensors = sensor;
-    } else {
+    }
+    else {
         sensor->next = g_sensors;
         g_sensors = sensor;
     }
@@ -51,7 +52,8 @@ sensor_t sensor_open(const char* name, int index,
     return sensor;
 }
 
-bool sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg)
+bool
+sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg)
 {
     char *buffer = (char *)cfg;
     int len = attr_container_get_serialize_length(cfg);
@@ -59,13 +61,15 @@ bool sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg)
     return wasm_sensor_config_with_attr_container(sensor->handle, buffer, len);
 }
 
-bool sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay)
+bool
+sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay)
 {
     bool ret = wasm_sensor_config(sensor->handle, interval, bit_cfg, delay);
     return ret;
 }
 
-bool sensor_close(sensor_t sensor)
+bool
+sensor_close(sensor_t sensor)
 {
     wasm_sensor_close(sensor->handle);
 
@@ -76,13 +80,15 @@ bool sensor_close(sensor_t sensor)
         if (s == sensor) {
             if (prev == NULL) {
                 g_sensors = s->next;
-            } else {
+            }
+            else {
                 prev->next = s->next;
             }
             free(s->name);
             free(s);
             return true;
-        } else {
+        }
+        else {
             prev = s;
             s = s->next;
         }
@@ -97,9 +103,10 @@ bool sensor_close(sensor_t sensor)
  *
  */
 
-void on_sensor_event(uint32 sensor_id, char * buffer, int len)
+void
+on_sensor_event(uint32 sensor_id, char *buffer, int len)
 {
-    attr_container_t * sensor_data = (attr_container_t *) buffer;
+    attr_container_t *sensor_data = (attr_container_t *)buffer;
 
     // lookup the sensor and call the handlers
     sensor_t s = g_sensors;

+ 1 - 2
core/app-framework/sensor/app/sensor_api.h

@@ -13,7 +13,7 @@ extern "C" {
 #endif
 
 uint32
-wasm_sensor_open(const char* name, int instance);
+wasm_sensor_open(const char *name, int instance);
 
 bool
 wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay);
@@ -29,4 +29,3 @@ wasm_sensor_close(uint32 sensor);
 #endif
 
 #endif /* end of _SENSOR_API_H_ */
-

+ 11 - 9
core/app-framework/sensor/app/wa-inc/sensor.h

@@ -30,8 +30,8 @@ typedef struct _sensor *sensor_t;
  * @see sensor_open
  */
 typedef void (*sensor_event_handler_f)(sensor_t sensor,
-                                     attr_container_t *sensor_event,
-                                     void *user_data);
+                                       attr_container_t *sensor_event,
+                                       void *user_data);
 
 /*
  *****************
@@ -49,10 +49,9 @@ typedef void (*sensor_event_handler_f)(sensor_t sensor,
  *
  * @return the sensor opened if success, NULL otherwise
  */
-sensor_t sensor_open(const char* name,
-                     int index,
-                     sensor_event_handler_f handler,
-                     void *user_data);
+sensor_t
+sensor_open(const char *name, int index, sensor_event_handler_f handler,
+            void *user_data);
 
 /**
  * @brief Configure sensor with interval/bit_cfg/delay values.
@@ -64,7 +63,8 @@ sensor_t sensor_open(const char* name,
  *
  * @return true if success, false otherwise
  */
-bool sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay);
+bool
+sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay);
 
 /**
  * @brief Configure sensor with attr_container_t object.
@@ -74,7 +74,8 @@ bool sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay);
  *
  * @return true if success, false otherwise
  */
-bool sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg);
+bool
+sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg);
 
 /**
  * @brief Close sensor.
@@ -83,7 +84,8 @@ bool sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg);
  *
  * @return true if success, false otherwise
  */
-bool sensor_close(sensor_t sensor);
+bool
+sensor_close(sensor_t sensor);
 
 #ifdef __cplusplus
 }

+ 59 - 51
core/app-framework/sensor/native/runtime_sensor.c

@@ -8,12 +8,12 @@
 #include "module_wasm_app.h"
 #include "bh_platform.h"
 
-static sys_sensor_t * g_sys_sensors = NULL;
+static sys_sensor_t *g_sys_sensors = NULL;
 static int g_sensor_id_max = 0;
 
 static sensor_client_t *
-find_sensor_client(sys_sensor_t * sensor,
-                   unsigned int client_id, bool remove_if_found);
+find_sensor_client(sys_sensor_t *sensor, unsigned int client_id,
+                   bool remove_if_found);
 
 void (*rechedule_sensor_callback)() = NULL;
 
@@ -38,30 +38,32 @@ sensor_event_cleaner(sensor_event_data_t *sensor_event)
 static void
 wasm_sensor_callback(void *client, uint32 sensor_id, void *user_data)
 {
-    attr_container_t *sensor_data = (attr_container_t *) user_data;
+    attr_container_t *sensor_data = (attr_container_t *)user_data;
     attr_container_t *sensor_data_clone;
     int sensor_data_len;
     sensor_event_data_t *sensor_event;
     bh_message_t msg;
-    sensor_client_t *c = (sensor_client_t *) client;
+    sensor_client_t *c = (sensor_client_t *)client;
 
     module_data *module = module_data_list_lookup_id(c->client_id);
     if (module == NULL)
         return;
 
     if (sensor_data == NULL)
-      return;
+        return;
 
     sensor_data_len = attr_container_get_serialize_length(sensor_data);
-    sensor_data_clone = (attr_container_t *)wasm_runtime_malloc(sensor_data_len);
+    sensor_data_clone =
+        (attr_container_t *)wasm_runtime_malloc(sensor_data_len);
     if (sensor_data_clone == NULL)
         return;
 
     /* multiple sensor clients may use/free the sensor data, so make a copy */
-    bh_memcpy_s(sensor_data_clone, sensor_data_len,
-                sensor_data, sensor_data_len);
+    bh_memcpy_s(sensor_data_clone, sensor_data_len, sensor_data,
+                sensor_data_len);
 
-    sensor_event = (sensor_event_data_t *)wasm_runtime_malloc(sizeof(*sensor_event));
+    sensor_event =
+        (sensor_event_data_t *)wasm_runtime_malloc(sizeof(*sensor_event));
     if (sensor_event == NULL) {
         wasm_runtime_free(sensor_data_clone);
         return;
@@ -72,9 +74,7 @@ wasm_sensor_callback(void *client, uint32 sensor_id, void *user_data)
     sensor_event->data = sensor_data_clone;
     sensor_event->data_fmt = FMT_ATTR_CONTAINER;
 
-    msg = bh_new_msg(SENSOR_EVENT_WASM,
-                     sensor_event,
-                     sizeof(*sensor_event),
+    msg = bh_new_msg(SENSOR_EVENT_WASM, sensor_event, sizeof(*sensor_event),
                      sensor_event_cleaner);
     if (!msg) {
         sensor_event_cleaner(sensor_event);
@@ -85,19 +85,18 @@ wasm_sensor_callback(void *client, uint32 sensor_id, void *user_data)
 }
 
 bool
-wasm_sensor_config(wasm_exec_env_t exec_env,
-                   uint32 sensor, int interval,
+wasm_sensor_config(wasm_exec_env_t exec_env, uint32 sensor, int interval,
                    int bit_cfg, int delay)
 {
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
-    attr_container_t * attr_cont;
-    sensor_client_t * c;
+    attr_container_t *attr_cont;
+    sensor_client_t *c;
     sensor_obj_t s = find_sys_sensor_id(sensor);
     if (s == NULL)
         return false;
 
-    unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
-                                                    module_inst);
+    unsigned int mod_id =
+        app_manager_get_module_id(Module_WASM_App, module_inst);
     bh_assert(mod_id != ID_NONE);
 
     os_mutex_lock(&s->lock);
@@ -131,8 +130,7 @@ wasm_sensor_config(wasm_exec_env_t exec_env,
 }
 
 uint32
-wasm_sensor_open(wasm_exec_env_t exec_env,
-                 char *name, int instance)
+wasm_sensor_open(wasm_exec_env_t exec_env, char *name, int instance)
 {
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
 
@@ -142,8 +140,8 @@ wasm_sensor_open(wasm_exec_env_t exec_env,
         if (s == NULL)
             return -1;
 
-        unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
-                                                        module_inst);
+        unsigned int mod_id =
+            app_manager_get_module_id(Module_WASM_App, module_inst);
         bh_assert(mod_id != ID_NONE);
 
         os_mutex_lock(&s->lock);
@@ -155,8 +153,8 @@ wasm_sensor_open(wasm_exec_env_t exec_env,
             return -1;
         }
 
-        sensor_client_t * client = (sensor_client_t*) wasm_runtime_malloc(
-                sizeof(sensor_client_t));
+        sensor_client_t *client =
+            (sensor_client_t *)wasm_runtime_malloc(sizeof(sensor_client_t));
         if (client == NULL) {
             os_mutex_unlock(&s->lock);
             return -1;
@@ -182,8 +180,8 @@ wasm_sensor_open(wasm_exec_env_t exec_env,
 }
 
 bool
-wasm_sensor_config_with_attr_container(wasm_exec_env_t exec_env,
-                                       uint32 sensor, char *buffer, int len)
+wasm_sensor_config_with_attr_container(wasm_exec_env_t exec_env, uint32 sensor,
+                                       char *buffer, int len)
 {
     if (buffer != NULL) {
         attr_container_t *cfg = (attr_container_t *)buffer;
@@ -204,8 +202,8 @@ bool
 wasm_sensor_close(wasm_exec_env_t exec_env, uint32 sensor)
 {
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
-    unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
-                                                    module_inst);
+    unsigned int mod_id =
+        app_manager_get_module_id(Module_WASM_App, module_inst);
     unsigned int client_id = mod_id;
     sensor_obj_t s = find_sys_sensor_id(sensor);
     sensor_client_t *c;
@@ -232,19 +230,22 @@ wasm_sensor_close(wasm_exec_env_t exec_env, uint32 sensor)
  * sensor framework API - don't expose to the applications
  *
  */
-void set_sensor_reshceduler(void (*callback)())
+void
+set_sensor_reshceduler(void (*callback)())
 {
     rechedule_sensor_callback = callback;
 }
 
 // used for other threads to wakeup the sensor read thread
-void reschedule_sensor_read()
+void
+reschedule_sensor_read()
 {
     if (rechedule_sensor_callback)
         rechedule_sensor_callback();
 }
 
-void refresh_read_interval(sensor_obj_t sensor)
+void
+refresh_read_interval(sensor_obj_t sensor)
 {
     sensor_client_t *c;
     uint32 interval = sensor->default_interval;
@@ -266,10 +267,10 @@ void refresh_read_interval(sensor_obj_t sensor)
 }
 
 sensor_obj_t
-add_sys_sensor(char * name, char * description, int instance,
-               uint32 default_interval, void * read_func, void * config_func)
+add_sys_sensor(char *name, char *description, int instance,
+               uint32 default_interval, void *read_func, void *config_func)
 {
-    sys_sensor_t * s = (sys_sensor_t *) wasm_runtime_malloc(sizeof(sys_sensor_t));
+    sys_sensor_t *s = (sys_sensor_t *)wasm_runtime_malloc(sizeof(sys_sensor_t));
     if (s == NULL)
         return NULL;
 
@@ -302,7 +303,8 @@ add_sys_sensor(char * name, char * description, int instance,
 
     if (g_sys_sensors == NULL) {
         g_sys_sensors = s;
-    } else {
+    }
+    else {
         s->next = g_sys_sensors;
         g_sys_sensors = s;
     }
@@ -312,9 +314,10 @@ add_sys_sensor(char * name, char * description, int instance,
     return s;
 }
 
-sensor_obj_t find_sys_sensor(const char* name, int instance)
+sensor_obj_t
+find_sys_sensor(const char *name, int instance)
 {
-    sys_sensor_t * s = g_sys_sensors;
+    sys_sensor_t *s = g_sys_sensors;
     while (s) {
         if (strcmp(s->name, name) == 0 && s->sensor_instance == instance)
             return s;
@@ -324,9 +327,10 @@ sensor_obj_t find_sys_sensor(const char* name, int instance)
     return NULL;
 }
 
-sensor_obj_t find_sys_sensor_id(uint32 sensor_id)
+sensor_obj_t
+find_sys_sensor_id(uint32 sensor_id)
 {
-    sys_sensor_t * s = g_sys_sensors;
+    sys_sensor_t *s = g_sys_sensors;
     while (s) {
         if (s->sensor_id == sensor_id)
             return s;
@@ -336,8 +340,9 @@ sensor_obj_t find_sys_sensor_id(uint32 sensor_id)
     return NULL;
 }
 
-sensor_client_t *find_sensor_client(sys_sensor_t * sensor,
-        unsigned int client_id, bool remove_if_found)
+sensor_client_t *
+find_sensor_client(sys_sensor_t *sensor, unsigned int client_id,
+                   bool remove_if_found)
 {
     sensor_client_t *prev = NULL, *c = sensor->clients;
 
@@ -351,7 +356,8 @@ sensor_client_t *find_sensor_client(sys_sensor_t * sensor,
                     sensor->clients = next;
             }
             return c;
-        } else {
+        }
+        else {
             c = c->next;
         }
     }
@@ -360,12 +366,13 @@ sensor_client_t *find_sensor_client(sys_sensor_t * sensor,
 }
 
 // return the milliseconds to next check
-int check_sensor_timers()
+int
+check_sensor_timers()
 {
     int ms_to_next_check = -1;
     uint32 now = (uint32)bh_get_tick_ms();
 
-    sys_sensor_t * s = g_sys_sensors;
+    sys_sensor_t *s = g_sys_sensors;
     while (s) {
         uint32 last_read = s->last_read;
         uint32 elpased_ms = bh_get_elpased_ms(&last_read);
@@ -376,9 +383,9 @@ int check_sensor_timers()
         }
 
         if (elpased_ms >= s->read_interval) {
-            attr_container_t * data = s->read(s);
+            attr_container_t *data = s->read(s);
             if (data) {
-                sensor_client_t * client = s->clients;
+                sensor_client_t *client = s->clients;
                 while (client) {
                     client->client_callback(client, s->sensor_id, data);
                     client = client->next;
@@ -390,11 +397,11 @@ int check_sensor_timers()
 
             if (ms_to_next_check == -1 || (ms_to_next_check < s->read_interval))
                 ms_to_next_check = s->read_interval;
-        } else {
+        }
+        else {
             int remaining = s->read_interval - elpased_ms;
             if (ms_to_next_check == -1 || (ms_to_next_check < remaining))
                 ms_to_next_check = remaining;
-
         }
 
         s = s->next;
@@ -403,9 +410,10 @@ int check_sensor_timers()
     return ms_to_next_check;
 }
 
-void sensor_cleanup_callback(uint32 module_id)
+void
+sensor_cleanup_callback(uint32 module_id)
 {
-    sys_sensor_t * s = g_sys_sensors;
+    sys_sensor_t *s = g_sys_sensors;
 
     while (s) {
         sensor_client_t *c;

+ 31 - 22
core/app-framework/sensor/native/runtime_sensor.h

@@ -12,49 +12,58 @@
 #include "sensor_native_api.h"
 
 struct _sys_sensor;
-typedef struct _sys_sensor* sensor_obj_t;
+typedef struct _sys_sensor *sensor_obj_t;
 
 typedef struct _sensor_client {
-    struct _sensor_client * next;
+    struct _sensor_client *next;
     unsigned int client_id; // the app id
     int interval;
     int bit_cfg;
     int delay;
-    void (*client_callback)(void * client, uint32, attr_container_t *);
+    void (*client_callback)(void *client, uint32, attr_container_t *);
 } sensor_client_t;
 
 typedef struct _sys_sensor {
-    struct _sys_sensor * next;
-    char * name;
+    struct _sys_sensor *next;
+    char *name;
     int sensor_instance;
-    char * description;
+    char *description;
     uint32 sensor_id;
-    sensor_client_t * clients;
+    sensor_client_t *clients;
     /* app, sensor mgr and app mgr may access the clients at the same time,
-     * so need a lock to protect the clients */
+       so need a lock to protect the clients */
     korp_mutex lock;
     uint32 last_read;
     uint32 read_interval;
     uint32 default_interval;
 
-    attr_container_t * (*read)(void *); /* TODO: may support other type return value, such as 'cbor' */
+    /* TODO: may support other type return value, such as 'cbor' */
+    attr_container_t *(*read)(void *);
     bool (*config)(void *, void *);
 
 } sys_sensor_t;
 
-sensor_obj_t add_sys_sensor(char * name, char * description, int instance,
-        uint32 default_interval, void * read_func, void * config_func);
-sensor_obj_t find_sys_sensor(const char* name, int instance);
-sensor_obj_t find_sys_sensor_id(uint32 sensor_id);
-void refresh_read_interval(sensor_obj_t sensor);
-void sensor_cleanup_callback(uint32 module_id);
-int check_sensor_timers();
-void reschedule_sensor_read();
-
-void init_sensor_framework();
-void start_sensor_framework();
-void exit_sensor_framework();
-
+sensor_obj_t
+add_sys_sensor(char *name, char *description, int instance,
+               uint32 default_interval, void *read_func, void *config_func);
+sensor_obj_t
+find_sys_sensor(const char *name, int instance);
+sensor_obj_t
+find_sys_sensor_id(uint32 sensor_id);
+void
+refresh_read_interval(sensor_obj_t sensor);
+void
+sensor_cleanup_callback(uint32 module_id);
+int
+check_sensor_timers();
+void
+reschedule_sensor_read();
 
+void
+init_sensor_framework();
+void
+start_sensor_framework();
+void
+exit_sensor_framework();
 
 #endif /* LIB_EXTENSION_RUNTIME_SENSOR_H_ */

+ 35 - 35
core/app-framework/sensor/native/sensor_mgr_ref.c

@@ -19,60 +19,62 @@ static korp_cond cond;
 static korp_mutex mutex;
 static bool sensor_check_thread_run = true;
 
-void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
+void
+app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
 {
     uint32 argv[3];
     wasm_function_inst_t func_onSensorEvent;
 
     bh_assert(SENSOR_EVENT_WASM == bh_message_type(msg));
-    wasm_data *wasm_app_data = (wasm_data*)m_data->internal_data;
+    wasm_data *wasm_app_data = (wasm_data *)m_data->internal_data;
     wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
 
-    sensor_event_data_t *payload = (sensor_event_data_t*)
-                                   bh_message_payload(msg);
+    sensor_event_data_t *payload =
+        (sensor_event_data_t *)bh_message_payload(msg);
     if (payload == NULL)
         return;
 
-    func_onSensorEvent = wasm_runtime_lookup_function(inst, "_on_sensor_event",
-                                                      "(i32i32i32)");
+    func_onSensorEvent =
+        wasm_runtime_lookup_function(inst, "_on_sensor_event", "(i32i32i32)");
     if (!func_onSensorEvent)
-        func_onSensorEvent = wasm_runtime_lookup_function(inst, "on_sensor_event",
-                                                          "(i32i32i32)");
+        func_onSensorEvent = wasm_runtime_lookup_function(
+            inst, "on_sensor_event", "(i32i32i32)");
     if (!func_onSensorEvent) {
         printf("Cannot find function on_sensor_event\n");
-    } else {
+    }
+    else {
         int32 sensor_data_offset;
         uint32 sensor_data_len;
 
         if (payload->data_fmt == FMT_ATTR_CONTAINER) {
-            sensor_data_len = attr_container_get_serialize_length(payload->data);
-        } else {
+            sensor_data_len =
+                attr_container_get_serialize_length(payload->data);
+        }
+        else {
             printf("Unsupported sensor data format: %d\n", payload->data_fmt);
             return;
         }
 
-        sensor_data_offset = wasm_runtime_module_dup_data(inst, payload->data,
-                                                          sensor_data_len);
+        sensor_data_offset =
+            wasm_runtime_module_dup_data(inst, payload->data, sensor_data_len);
         if (sensor_data_offset == 0) {
             const char *exception = wasm_runtime_get_exception(inst);
             if (exception) {
-                printf("Got exception running wasm code: %s\n",
-                       exception);
+                printf("Got exception running wasm code: %s\n", exception);
                 wasm_runtime_clear_exception(inst);
             }
             return;
         }
 
         argv[0] = payload->sensor_id;
-        argv[1] = (uint32) sensor_data_offset;
+        argv[1] = (uint32)sensor_data_offset;
         argv[2] = sensor_data_len;
 
         if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_onSensorEvent,
                                     3, argv)) {
             const char *exception = wasm_runtime_get_exception(inst);
             bh_assert(exception);
-            printf(":Got exception running wasm code: %s\n",
-                   exception);
+            printf(":Got exception running wasm code: %s\n", exception);
             wasm_runtime_clear_exception(inst);
             wasm_runtime_module_free(inst, sensor_data_offset);
             return;
@@ -82,8 +84,8 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
     }
 }
 
-
-static void thread_sensor_check(void * arg)
+static void
+thread_sensor_check(void *arg)
 {
     while (sensor_check_thread_run) {
         int ms_to_expiry = check_sensor_timers();
@@ -95,46 +97,44 @@ static void thread_sensor_check(void * arg)
     }
 }
 
-static void cb_wakeup_thread()
+static void
+cb_wakeup_thread()
 {
     os_cond_signal(&cond);
 }
 
-void set_sensor_reshceduler(void (*callback)());
+void
+set_sensor_reshceduler(void (*callback)());
 
-void init_sensor_framework()
+void
+init_sensor_framework()
 {
     // init the mutext and conditions
     os_cond_init(&cond);
     os_mutex_init(&mutex);
 
-
     set_sensor_reshceduler(cb_wakeup_thread);
 
     wasm_register_msg_callback(SENSOR_EVENT_WASM,
                                app_mgr_sensor_event_callback);
 
     wasm_register_cleanup_callback(sensor_cleanup_callback);
-
-
 }
 
-void start_sensor_framework()
+void
+start_sensor_framework()
 {
     korp_tid tid;
 
-    os_thread_create(&tid,
-            (void *)thread_sensor_check,
-            NULL,
-            BH_APPLET_PRESERVED_STACK_SIZE);
+    os_thread_create(&tid, (void *)thread_sensor_check, NULL,
+                     BH_APPLET_PRESERVED_STACK_SIZE);
 }
 
-
-void exit_sensor_framework()
+void
+exit_sensor_framework()
 {
     sensor_check_thread_run = false;
     reschedule_sensor_read();
 
-    //todo: wait the sensor thread termination
+    // todo: wait the sensor thread termination
 }
-

+ 4 - 7
core/app-framework/sensor/native/sensor_native_api.h

@@ -14,16 +14,14 @@ extern "C" {
 #endif
 
 bool
-wasm_sensor_config(wasm_exec_env_t exec_env,
-                   uint32 sensor, int interval,
+wasm_sensor_config(wasm_exec_env_t exec_env, uint32 sensor, int interval,
                    int bit_cfg, int delay);
 uint32
-wasm_sensor_open(wasm_exec_env_t exec_env,
-                 char *name, int instance);
+wasm_sensor_open(wasm_exec_env_t exec_env, char *name, int instance);
 
 bool
-wasm_sensor_config_with_attr_container(wasm_exec_env_t exec_env,
-                                       uint32 sensor, char *buffer, int len);
+wasm_sensor_config_with_attr_container(wasm_exec_env_t exec_env, uint32 sensor,
+                                       char *buffer, int len);
 
 bool
 wasm_sensor_close(wasm_exec_env_t exec_env, uint32 sensor);
@@ -33,4 +31,3 @@ wasm_sensor_close(wasm_exec_env_t exec_env, uint32 sensor);
 #endif
 
 #endif /* end of _SENSOR_NATIVE_API_H_ */
-

+ 0 - 2
core/app-framework/wgl/app/gui_api.h

@@ -28,10 +28,8 @@ wasm_cb_native_call(int32 func_id, uint32 *argv, uint32 argc);
 void
 wasm_list_native_call(int32 func_id, uint32 *argv, uint32 argc);
 
-
 #ifdef __cplusplus
 }
 #endif
 
-
 #endif /* end of _GUI_API_H_ */

+ 41 - 27
core/app-framework/wgl/app/src/wgl_btn.c

@@ -7,12 +7,13 @@
 #include "bh_platform.h"
 #include "gui_api.h"
 
-#define ARGC sizeof(argv)/sizeof(uint32)
+#define ARGC sizeof(argv) / sizeof(uint32)
 #define CALL_BTN_NATIVE_FUNC(id) wasm_btn_native_call(id, argv, ARGC)
 
-lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy)
+lv_obj_t *
+lv_btn_create(lv_obj_t *par, const lv_obj_t *copy)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
 
     argv[0] = (uint32)par;
     argv[1] = (uint32)copy;
@@ -20,100 +21,113 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy)
     return (lv_obj_t *)argv[0];
 }
 
-void lv_btn_set_toggle(lv_obj_t * btn, bool tgl)
+void
+lv_btn_set_toggle(lv_obj_t *btn, bool tgl)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)btn;
     argv[1] = tgl;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_TOGGLE);
 }
 
-void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state)
+void
+lv_btn_set_state(lv_obj_t *btn, lv_btn_state_t state)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)btn;
     argv[1] = state;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_STATE);
 }
 
-void lv_btn_toggle(lv_obj_t * btn)
+void
+lv_btn_toggle(lv_obj_t *btn)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)btn;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_TOGGLE);
 }
 
-void lv_btn_set_ink_in_time(lv_obj_t * btn, uint16_t time)
+void
+lv_btn_set_ink_in_time(lv_obj_t *btn, uint16_t time)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)btn;
     argv[1] = time;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_INK_IN_TIME);
 }
 
-void lv_btn_set_ink_wait_time(lv_obj_t * btn, uint16_t time)
+void
+lv_btn_set_ink_wait_time(lv_obj_t *btn, uint16_t time)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)btn;
     argv[1] = time;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_INK_WAIT_TIME);
 }
 
-void lv_btn_set_ink_out_time(lv_obj_t * btn, uint16_t time)
+void
+lv_btn_set_ink_out_time(lv_obj_t *btn, uint16_t time)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)btn;
     argv[1] = time;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_SET_INK_OUT_TIME);
 }
 
-//void wgl_btn_set_style(wgl_obj_t btn, wgl_btn_style_t type, const wgl_style_t * style)
+// void wgl_btn_set_style(wgl_obj_t btn, wgl_btn_style_t type,
+//                        const wgl_style_t *style)
 //{
 //    //TODO: pack style
 //    //wasm_btn_set_style(btn, type, style);
 //}
 //
-lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn)
+lv_btn_state_t
+lv_btn_get_state(const lv_obj_t *btn)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)btn;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_STATE);
     return (lv_btn_state_t)argv[0];
 }
 
-bool lv_btn_get_toggle(const lv_obj_t * btn)
+bool
+lv_btn_get_toggle(const lv_obj_t *btn)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)btn;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_TOGGLE);
     return (bool)argv[0];
 }
 
-uint16_t lv_btn_get_ink_in_time(const lv_obj_t * btn)
+uint16_t
+lv_btn_get_ink_in_time(const lv_obj_t *btn)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)btn;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_INK_IN_TIME);
     return (uint16_t)argv[0];
 }
 
-uint16_t lv_btn_get_ink_wait_time(const lv_obj_t * btn)
+uint16_t
+lv_btn_get_ink_wait_time(const lv_obj_t *btn)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)btn;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_INK_WAIT_TIME);
     return (uint16_t)argv[0];
 }
 
-uint16_t lv_btn_get_ink_out_time(const lv_obj_t * btn)
+uint16_t
+lv_btn_get_ink_out_time(const lv_obj_t *btn)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)btn;
     CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_GET_INK_OUT_TIME);
     return (uint16_t)argv[0];
 }
 //
-//const wgl_style_t * wgl_btn_get_style(const wgl_obj_t btn, wgl_btn_style_t type)
+// const wgl_style_t * wgl_btn_get_style(const wgl_obj_t btn,
+//                                       wgl_btn_style_t type)
 //{
 //    //TODO: pack style
 //    //wasm_btn_get_style(btn, type);

+ 22 - 18
core/app-framework/wgl/app/src/wgl_cb.c

@@ -3,18 +3,18 @@
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  */
 
-
 #include "wa-inc/lvgl/lvgl.h"
 #include "gui_api.h"
 
 #include <string.h>
 
-#define ARGC sizeof(argv)/sizeof(uint32)
+#define ARGC sizeof(argv) / sizeof(uint32)
 #define CALL_CB_NATIVE_FUNC(id) wasm_cb_native_call(id, argv, ARGC)
 
-lv_obj_t * lv_cb_create(lv_obj_t * par, const lv_obj_t * copy)
+lv_obj_t *
+lv_cb_create(lv_obj_t *par, const lv_obj_t *copy)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
 
     argv[0] = (uint32)par;
     argv[1] = (uint32)copy;
@@ -22,41 +22,46 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, const lv_obj_t * copy)
     return (lv_obj_t *)argv[0];
 }
 
-void lv_cb_set_text(lv_obj_t * cb, const char * txt)
+void
+lv_cb_set_text(lv_obj_t *cb, const char *txt)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)cb;
     argv[1] = (uint32)txt;
     argv[2] = strlen(txt) + 1;
     CALL_CB_NATIVE_FUNC(CB_FUNC_ID_SET_TEXT);
 }
 
-void lv_cb_set_static_text(lv_obj_t * cb, const char * txt)
+void
+lv_cb_set_static_text(lv_obj_t *cb, const char *txt)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)cb;
     argv[1] = (uint32)txt;
     argv[2] = strlen(txt) + 1;
     CALL_CB_NATIVE_FUNC(CB_FUNC_ID_SET_STATIC_TEXT);
 }
 
-//void wgl_cb_set_style(wgl_obj_t cb, wgl_cb_style_t type, const wgl_style_t * style)
+// void wgl_cb_set_style(wgl_obj_t cb, wgl_cb_style_t type,
+//                       const wgl_style_t *style)
 //{
 //    //TODO:
 //}
 //
 
-static unsigned int wgl_cb_get_text_length(lv_obj_t * cb)
+static unsigned int
+wgl_cb_get_text_length(lv_obj_t *cb)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)cb;
     CALL_CB_NATIVE_FUNC(CB_FUNC_ID_GET_TEXT_LENGTH);
     return argv[0];
 }
 
-static char *wgl_cb_get_text(lv_obj_t * cb, char *buffer, int buffer_len)
+static char *
+wgl_cb_get_text(lv_obj_t *cb, char *buffer, int buffer_len)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)cb;
     argv[1] = (uint32)buffer;
     argv[2] = buffer_len;
@@ -65,18 +70,17 @@ static char *wgl_cb_get_text(lv_obj_t * cb, char *buffer, int buffer_len)
 }
 
 // TODO: need to use a global data buffer for the returned text
-const char * lv_cb_get_text(const lv_obj_t * cb)
+const char *
+lv_cb_get_text(const lv_obj_t *cb)
 {
 
     return NULL;
 }
 
-
-//const wgl_style_t * wgl_cb_get_style(const wgl_obj_t cb, wgl_cb_style_t type)
+// const wgl_style_t * wgl_cb_get_style(const wgl_obj_t cb,
+//                                      wgl_cb_style_t type)
 //{
 //    //TODO
 //    return NULL;
 //}
 //
-
-

+ 79 - 80
core/app-framework/wgl/app/src/wgl_label.c

@@ -3,19 +3,17 @@
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  */
 
-
-
 #include "wa-inc/lvgl/lvgl.h"
 #include "gui_api.h"
 #include <string.h>
 
-
-#define ARGC sizeof(argv)/sizeof(uint32)
+#define ARGC sizeof(argv) / sizeof(uint32)
 #define CALL_LABEL_NATIVE_FUNC(id) wasm_label_native_call(id, argv, ARGC)
 
-lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy)
+lv_obj_t *
+lv_label_create(lv_obj_t *par, const lv_obj_t *copy)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
 
     argv[0] = (uint32)par;
     argv[1] = (uint32)copy;
@@ -23,109 +21,112 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy)
     return (lv_obj_t *)argv[0];
 }
 
-void lv_label_set_text(lv_obj_t * label, const char * text)
+void
+lv_label_set_text(lv_obj_t *label, const char *text)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = (uint32)text;
     argv[2] = strlen(text) + 1;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_TEXT);
 }
 
-
-void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size)
+void
+lv_label_set_array_text(lv_obj_t *label, const char *array, uint16_t size)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = (uint32)array;
     argv[2] = size;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_ARRAY_TEXT);
 }
 
-
-void lv_label_set_static_text(lv_obj_t * label, const char * text)
+void
+lv_label_set_static_text(lv_obj_t *label, const char *text)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = (uint32)text;
     argv[2] = strlen(text) + 1;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_STATIC_TEXT);
 }
 
-
-void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode)
+void
+lv_label_set_long_mode(lv_obj_t *label, lv_label_long_mode_t long_mode)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = long_mode;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_LONG_MODE);
 }
 
-
-void lv_label_set_align(lv_obj_t * label, lv_label_align_t align)
+void
+lv_label_set_align(lv_obj_t *label, lv_label_align_t align)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = align;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_ALIGN);
 }
 
-
-void lv_label_set_recolor(lv_obj_t * label, bool en)
+void
+lv_label_set_recolor(lv_obj_t *label, bool en)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = en;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_RECOLOR);
 }
 
-
-void lv_label_set_body_draw(lv_obj_t * label, bool en)
+void
+lv_label_set_body_draw(lv_obj_t *label, bool en)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = en;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_BODY_DRAW);
 }
 
-
-void lv_label_set_anim_speed(lv_obj_t * label, uint16_t anim_speed)
+void
+lv_label_set_anim_speed(lv_obj_t *label, uint16_t anim_speed)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = anim_speed;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_ANIM_SPEED);
 }
 
-
-void lv_label_set_text_sel_start(lv_obj_t * label, uint16_t index)
+void
+lv_label_set_text_sel_start(lv_obj_t *label, uint16_t index)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = index;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_TEXT_SEL_START);
 }
 
-
-void lv_label_set_text_sel_end(lv_obj_t * label, uint16_t index)
+void
+lv_label_set_text_sel_end(lv_obj_t *label, uint16_t index)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = index;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_SET_TEXT_SEL_END);
 }
 
-unsigned int wgl_label_get_text_length(lv_obj_t * label)
+unsigned int
+wgl_label_get_text_length(lv_obj_t *label)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)label;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_TEXT_LENGTH);
     return argv[0];
 }
 
-char * wgl_label_get_text(lv_obj_t * label, char *buffer, int buffer_len)
+char *
+wgl_label_get_text(lv_obj_t *label, char *buffer, int buffer_len)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = (uint32)buffer;
     argv[2] = buffer_len;
@@ -133,63 +134,63 @@ char * wgl_label_get_text(lv_obj_t * label, char *buffer, int buffer_len)
     return (char *)argv[0];
 }
 
-// TODO: 
-char * lv_label_get_text(const lv_obj_t * label)
+// TODO:
+char *
+lv_label_get_text(const lv_obj_t *label)
 {
 
     return NULL;
-
 }
 
-
-lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * label)
+lv_label_long_mode_t
+lv_label_get_long_mode(const lv_obj_t *label)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)label;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LONG_MODE);
     return (lv_label_long_mode_t)argv[0];
 }
 
-
-lv_label_align_t lv_label_get_align(const lv_obj_t * label)
+lv_label_align_t
+lv_label_get_align(const lv_obj_t *label)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)label;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_ALIGN);
     return (lv_label_align_t)argv[0];
 }
 
-
-bool lv_label_get_recolor(const lv_obj_t * label)
+bool
+lv_label_get_recolor(const lv_obj_t *label)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)label;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_RECOLOR);
     return (bool)argv[0];
 }
 
-
-bool lv_label_get_body_draw(const lv_obj_t * label)
+bool
+lv_label_get_body_draw(const lv_obj_t *label)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)label;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_BODY_DRAW);
     return (bool)argv[0];
 }
 
-
-uint16_t lv_label_get_anim_speed(const lv_obj_t * label)
+uint16_t
+lv_label_get_anim_speed(const lv_obj_t *label)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)label;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_ANIM_SPEED);
     return (uint16_t)argv[0];
 }
 
-
-void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t * pos)
+void
+lv_label_get_letter_pos(const lv_obj_t *label, uint16_t index, lv_point_t *pos)
 {
-    uint32 argv[4] = {0};
+    uint32 argv[4] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = index;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LETTER_POS);
@@ -197,10 +198,10 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t
     pos->y = argv[3];
 }
 
-
-uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
+uint16_t
+lv_label_get_letter_on(const lv_obj_t *label, lv_point_t *pos)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = pos->x;
     argv[2] = pos->y;
@@ -208,10 +209,10 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
     return (uint16_t)argv[0];
 }
 
-
-bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
+bool
+lv_label_is_char_under_pos(const lv_obj_t *label, lv_point_t *pos)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = pos->x;
     argv[2] = pos->y;
@@ -219,28 +220,28 @@ bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos)
     return (bool)argv[0];
 }
 
-
-uint16_t lv_label_get_text_sel_start(const lv_obj_t * label)
+uint16_t
+lv_label_get_text_sel_start(const lv_obj_t *label)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)label;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_TEXT_SEL_START);
     return (uint16_t)argv[0];
 }
 
-
-uint16_t lv_label_get_text_sel_end(const lv_obj_t * label)
+uint16_t
+lv_label_get_text_sel_end(const lv_obj_t *label)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)label;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_TEXT_SEL_END);
     return (uint16_t)argv[0];
 }
 
-
-void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt)
+void
+lv_label_ins_text(lv_obj_t *label, uint32_t pos, const char *txt)
 {
-    uint32 argv[4] = {0};
+    uint32 argv[4] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = pos;
     argv[2] = (uint32)txt;
@@ -248,14 +249,12 @@ void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt)
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_INS_TEXT);
 }
 
-
-void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt)
+void
+lv_label_cut_text(lv_obj_t *label, uint32_t pos, uint32_t cnt)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
     argv[0] = (uint32)label;
     argv[1] = pos;
     argv[2] = cnt;
     CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_CUT_TEXT);
 }
-
-

+ 27 - 27
core/app-framework/wgl/app/src/wgl_list.c

@@ -3,19 +3,18 @@
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  */
 
-
 #include "wa-inc/lvgl/lvgl.h"
 #include "gui_api.h"
 
 #include <string.h>
 
-#define ARGC sizeof(argv)/sizeof(uint32)
+#define ARGC sizeof(argv) / sizeof(uint32)
 #define CALL_LIST_NATIVE_FUNC(id) wasm_list_native_call(id, argv, ARGC)
 
-
-lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy)
+lv_obj_t *
+lv_list_create(lv_obj_t *par, const lv_obj_t *copy)
 {
-    uint32 argv[2] = {0};
+    uint32 argv[2] = { 0 };
 
     argv[0] = (uint32)par;
     argv[1] = (uint32)copy;
@@ -25,15 +24,16 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy)
 }
 //
 //
-//void wgl_list_clean(wgl_obj_t obj)
+// void wgl_list_clean(wgl_obj_t obj)
 //{
 //    wasm_list_clean(obj);
 //}
 //
 
-lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * txt)
+lv_obj_t *
+lv_list_add_btn(lv_obj_t *list, const void *img_src, const char *txt)
 {
-    uint32 argv[3] = {0};
+    uint32 argv[3] = { 0 };
 
     (void)img_src; /* doesn't support img src currently */
 
@@ -45,13 +45,13 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t
 }
 //
 //
-//bool wgl_list_remove(const wgl_obj_t list, uint16_t index)
+// bool wgl_list_remove(const wgl_obj_t list, uint16_t index)
 //{
 //    return wasm_list_remove(list, index);
 //}
 //
 //
-//void wgl_list_set_single_mode(wgl_obj_t list, bool mode)
+// void wgl_list_set_single_mode(wgl_obj_t list, bool mode)
 //{
 //    wasm_list_set_single_mode(list, mode);
 //}
@@ -59,68 +59,69 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t
 //#if LV_USE_GROUP
 //
 //
-//void wgl_list_set_btn_selected(wgl_obj_t list, wgl_obj_t btn)
+// void wgl_list_set_btn_selected(wgl_obj_t list, wgl_obj_t btn)
 //{
 //    wasm_list_set_btn_selected(list, btn);
 //}
 //#endif
 //
 //
-//void wgl_list_set_style(wgl_obj_t list, wgl_list_style_t type, const wgl_style_t * style)
+// void wgl_list_set_style(wgl_obj_t list, wgl_list_style_t type,
+//                         const wgl_style_t * style)
 //{
 //    //TODO
 //}
 //
 //
-//bool wgl_list_get_single_mode(wgl_obj_t list)
+// bool wgl_list_get_single_mode(wgl_obj_t list)
 //{
 //    return wasm_list_get_single_mode(list);
 //}
 //
 //
-//const char * wgl_list_get_btn_text(const wgl_obj_t btn)
+// const char * wgl_list_get_btn_text(const wgl_obj_t btn)
 //{
 //    return wasm_list_get_btn_text(btn);
 //}
 //
-//wgl_obj_t wgl_list_get_btn_label(const wgl_obj_t btn)
+// wgl_obj_t wgl_list_get_btn_label(const wgl_obj_t btn)
 //{
 //    return wasm_list_get_btn_label(btn);
 //}
 //
 //
-//wgl_obj_t wgl_list_get_btn_img(const wgl_obj_t btn)
+// wgl_obj_t wgl_list_get_btn_img(const wgl_obj_t btn)
 //{
 //    return wasm_list_get_btn_img(btn);
 //}
 //
 //
-//wgl_obj_t wgl_list_get_prev_btn(const wgl_obj_t list, wgl_obj_t prev_btn)
+// wgl_obj_t wgl_list_get_prev_btn(const wgl_obj_t list, wgl_obj_t prev_btn)
 //{
 //    return wasm_list_get_prev_btn(list, prev_btn);
 //}
 //
 //
-//wgl_obj_t wgl_list_get_next_btn(const wgl_obj_t list, wgl_obj_t prev_btn)
+// wgl_obj_t wgl_list_get_next_btn(const wgl_obj_t list, wgl_obj_t prev_btn)
 //{
 //    return wasm_list_get_next_btn(list, prev_btn);
 //}
 //
 //
-//int32_t wgl_list_get_btn_index(const wgl_obj_t list, const wgl_obj_t btn)
+// int32_t wgl_list_get_btn_index(const wgl_obj_t list, const wgl_obj_t btn)
 //{
 //    return wasm_list_get_btn_index(list, btn);
 //}
 //
 //
-//uint16_t wgl_list_get_size(const wgl_obj_t list)
+// uint16_t wgl_list_get_size(const wgl_obj_t list)
 //{
 //    return wasm_list_get_size(list);
 //}
 //
 //#if LV_USE_GROUP
 //
-//wgl_obj_t wgl_list_get_btn_selected(const wgl_obj_t list)
+// wgl_obj_t wgl_list_get_btn_selected(const wgl_obj_t list)
 //{
 //    return wasm_list_get_btn_selected(list);
 //}
@@ -128,28 +129,27 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t
 //
 //
 //
-//const wgl_style_t * wgl_list_get_style(const wgl_obj_t list, wgl_list_style_t type)
+// const wgl_style_t * wgl_list_get_style(const wgl_obj_t list,
+//                                        wgl_list_style_t type)
 //{
 //    //TODO
 //    return NULL;
 //}
 //
 //
-//void wgl_list_up(const wgl_obj_t list)
+// void wgl_list_up(const wgl_obj_t list)
 //{
 //    wasm_list_up(list);
 //}
 //
-//void wgl_list_down(const wgl_obj_t list)
+// void wgl_list_down(const wgl_obj_t list)
 //{
 //    wasm_list_down(list);
 //}
 //
 //
-//void wgl_list_focus(const wgl_obj_t btn, wgl_anim_enable_t anim)
+// void wgl_list_focus(const wgl_obj_t btn, wgl_anim_enable_t anim)
 //{
 //    wasm_list_focus(btn, anim);
 //}
 //
-
-

+ 24 - 16
core/app-framework/wgl/app/src/wgl_obj.c

@@ -3,19 +3,18 @@
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  */
 
-
 #include "wa-inc/lvgl/lvgl.h"
 #include "gui_api.h"
 #include <stdlib.h>
 #include <string.h>
 
-#define ARGC sizeof(argv)/sizeof(uint32)
+#define ARGC sizeof(argv) / sizeof(uint32)
 #define CALL_OBJ_NATIVE_FUNC(id) wasm_obj_native_call(id, argv, ARGC)
 
 typedef struct _obj_evt_cb {
     struct _obj_evt_cb *next;
 
-    lv_obj_t * obj;
+    lv_obj_t *obj;
     lv_event_cb_t event_cb;
 } obj_evt_cb_t;
 
@@ -24,31 +23,36 @@ static obj_evt_cb_t *g_obj_evt_cb_list = NULL;
 /* For lvgl compatible */
 char g_widget_text[100];
 
-lv_res_t lv_obj_del(lv_obj_t * obj)
+lv_res_t
+lv_obj_del(lv_obj_t *obj)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)obj;
     CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_DEL);
     return (lv_res_t)argv[0];
 }
 
-void lv_obj_del_async(struct _lv_obj_t *obj)
+void
+lv_obj_del_async(struct _lv_obj_t *obj)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)obj;
     CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_DEL_ASYNC);
 }
 
-void lv_obj_clean(lv_obj_t * obj)
+void
+lv_obj_clean(lv_obj_t *obj)
 {
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
     argv[0] = (uint32)obj;
     CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_CLEAN);
 }
 
-void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod)
+void
+lv_obj_align(lv_obj_t *obj, const lv_obj_t *base, lv_align_t align,
+             lv_coord_t x_mod, lv_coord_t y_mod)
 {
-    uint32 argv[5] = {0};
+    uint32 argv[5] = { 0 };
     argv[0] = (uint32)obj;
     argv[1] = (uint32)base;
     argv[2] = align;
@@ -57,7 +61,8 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co
     CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_ALIGN);
 }
 
-lv_event_cb_t lv_obj_get_event_cb(const lv_obj_t * obj)
+lv_event_cb_t
+lv_obj_get_event_cb(const lv_obj_t *obj)
 {
     obj_evt_cb_t *obj_evt_cb = g_obj_evt_cb_list;
     while (obj_evt_cb != NULL) {
@@ -70,10 +75,11 @@ lv_event_cb_t lv_obj_get_event_cb(const lv_obj_t * obj)
     return NULL;
 }
 
-void lv_obj_set_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb)
+void
+lv_obj_set_event_cb(lv_obj_t *obj, lv_event_cb_t event_cb)
 {
     obj_evt_cb_t *obj_evt_cb;
-    uint32 argv[1] = {0};
+    uint32 argv[1] = { 0 };
 
     obj_evt_cb = g_obj_evt_cb_list;
     while (obj_evt_cb) {
@@ -94,7 +100,8 @@ void lv_obj_set_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb)
     if (g_obj_evt_cb_list != NULL) {
         obj_evt_cb->next = g_obj_evt_cb_list;
         g_obj_evt_cb_list = obj_evt_cb;
-    } else {
+    }
+    else {
         g_obj_evt_cb_list = obj_evt_cb;
     }
 
@@ -102,7 +109,8 @@ void lv_obj_set_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb)
     CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_SET_EVT_CB);
 }
 
-void on_widget_event(lv_obj_t * obj, lv_event_t event)
+void
+on_widget_event(lv_obj_t *obj, lv_event_t event)
 {
     obj_evt_cb_t *obj_evt_cb = g_obj_evt_cb_list;
 

文件差异内容过多而无法显示
+ 287 - 163
core/app-framework/wgl/app/wa-inc/lvgl/lv_obj.h


+ 0 - 4
core/app-framework/wgl/app/wa-inc/lvgl/lvgl.h

@@ -10,7 +10,6 @@
 extern "C" {
 #endif
 
-
 //#include "bi-inc/wgl_shared_utils.h" /* shared types between app and native */
 /*
 #include "lvgl-compatible/lv_types.h"
@@ -21,9 +20,6 @@ extern "C" {
 #include "lvgl-compatible/lv_list.h"
 */
 
-
-
-
 #include "src/lv_version.h"
 
 #include "src/lv_misc/lv_log.h"

+ 3 - 5
core/app-framework/wgl/app/wa-inc/lvgl/test.c

@@ -1,11 +1,9 @@
 #include "lvgl.h"
 
-
-int main()
+int
+main()
 
 {
 
-
-	return  0;
-
+    return 0;
 }

+ 10 - 12
core/app-framework/wgl/native/gui_native_api.h

@@ -13,34 +13,32 @@
 extern "C" {
 #endif
 
-
 /**
  * gui interfaces
  */
 
 void
-wasm_obj_native_call(wasm_exec_env_t exec_env,
-                     int32 func_id, uint32 *argv, uint32 argc);
+wasm_obj_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                     uint32 argc);
 
 void
-wasm_btn_native_call(wasm_exec_env_t exec_env,
-                     int32 func_id, uint32 *argv, uint32 argc);
+wasm_btn_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                     uint32 argc);
 
 void
-wasm_label_native_call(wasm_exec_env_t exec_env,
-                       int32 func_id, uint32 *argv, uint32 argc);
+wasm_label_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                       uint32 argc);
 
 void
-wasm_cb_native_call(wasm_exec_env_t exec_env,
-                    int32 func_id, uint32 *argv, uint32 argc);
+wasm_cb_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                    uint32 argc);
 
 void
-wasm_list_native_call(wasm_exec_env_t exec_env,
-                      int32 func_id, uint32 *argv, uint32 argc);
+wasm_list_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                      uint32 argc);
 
 #ifdef __cplusplus
 }
 #endif
 
-
 #endif /* end of _GUI_API_H_ */

+ 4 - 2
core/app-framework/wgl/native/wgl.h

@@ -10,8 +10,10 @@
 extern "C" {
 #endif
 
-void wgl_init(void);
-void wgl_exit(void);
+void
+wgl_init(void);
+void
+wgl_exit(void);
 
 #ifdef __cplusplus
 }

+ 19 - 21
core/app-framework/wgl/native/wgl_btn_wrapper.c

@@ -19,7 +19,8 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_btn_create_wrapper)
     wgl_native_get_arg(uint32, copy_obj_id);
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
 
-    res = wgl_native_wigdet_create(WIDGET_TYPE_BTN, par_obj_id, copy_obj_id, module_inst);
+    res = wgl_native_wigdet_create(WIDGET_TYPE_BTN, par_obj_id, copy_obj_id,
+                                   module_inst);
     wgl_native_set_return(res);
 }
 
@@ -131,33 +132,30 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_btn_toggle_wrapper)
     lv_btn_toggle(btn);
 }
 
+/* clang-format off */
 static WGLNativeFuncDef btn_native_func_defs[] = {
-    { BTN_FUNC_ID_CREATE,              lv_btn_create_wrapper,             2,  false },
-    { BTN_FUNC_ID_SET_TOGGLE,          lv_btn_set_toggle_wrapper,         2,  true },
-    { BTN_FUNC_ID_SET_STATE,           lv_btn_set_state_wrapper,          2,  true },
-    { BTN_FUNC_ID_SET_INK_IN_TIME,     lv_btn_set_ink_in_time_wrapper,    2,  true },
-    { BTN_FUNC_ID_SET_INK_OUT_TIME,    lv_btn_set_ink_out_time_wrapper,   2,  true },
-    { BTN_FUNC_ID_SET_INK_WAIT_TIME,   lv_btn_set_ink_wait_time_wrapper,  2,  true },
-    { BTN_FUNC_ID_GET_INK_IN_TIME,     lv_btn_get_ink_in_time_wrapper,    1,  true },
-    { BTN_FUNC_ID_GET_INK_OUT_TIME,    lv_btn_get_ink_out_time_wrapper,   1,  true },
-    { BTN_FUNC_ID_GET_INK_WAIT_TIME,   lv_btn_get_ink_wait_time_wrapper,  1,  true },
-    { BTN_FUNC_ID_GET_STATE,           lv_btn_get_state_wrapper,          1,  true },
-    { BTN_FUNC_ID_GET_TOGGLE,          lv_btn_get_toggle_wrapper,         1,  true },
-    { BTN_FUNC_ID_TOGGLE,              lv_btn_toggle_wrapper,             1,  true },
-
+    { BTN_FUNC_ID_CREATE, lv_btn_create_wrapper, 2, false },
+    { BTN_FUNC_ID_SET_TOGGLE, lv_btn_set_toggle_wrapper, 2, true },
+    { BTN_FUNC_ID_SET_STATE, lv_btn_set_state_wrapper, 2, true },
+    { BTN_FUNC_ID_SET_INK_IN_TIME, lv_btn_set_ink_in_time_wrapper, 2, true },
+    { BTN_FUNC_ID_SET_INK_OUT_TIME, lv_btn_set_ink_out_time_wrapper, 2, true },
+    { BTN_FUNC_ID_SET_INK_WAIT_TIME, lv_btn_set_ink_wait_time_wrapper, 2, true },
+    { BTN_FUNC_ID_GET_INK_IN_TIME, lv_btn_get_ink_in_time_wrapper, 1, true },
+    { BTN_FUNC_ID_GET_INK_OUT_TIME, lv_btn_get_ink_out_time_wrapper, 1, true },
+    { BTN_FUNC_ID_GET_INK_WAIT_TIME, lv_btn_get_ink_wait_time_wrapper, 1, true },
+    { BTN_FUNC_ID_GET_STATE, lv_btn_get_state_wrapper, 1, true },
+    { BTN_FUNC_ID_GET_TOGGLE, lv_btn_get_toggle_wrapper, 1, true },
+    { BTN_FUNC_ID_TOGGLE, lv_btn_toggle_wrapper, 1, true },
 };
+/* clang-format on */
 
 /*************** Native Interface to Wasm App ***********/
 void
-wasm_btn_native_call(wasm_exec_env_t exec_env,
-                     int32 func_id, uint32 *argv, uint32 argc)
+wasm_btn_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                     uint32 argc)
 {
     uint32 size = sizeof(btn_native_func_defs) / sizeof(WGLNativeFuncDef);
 
-    wgl_native_func_call(exec_env,
-                         btn_native_func_defs,
-                         size,
-                         func_id,
-                         argv,
+    wgl_native_func_call(exec_env, btn_native_func_defs, size, func_id, argv,
                          argc);
 }

+ 11 - 14
core/app-framework/wgl/native/wgl_cb_wrapper.c

@@ -20,7 +20,8 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_cb_create_wrapper)
     wgl_native_get_arg(uint32, copy_obj_id);
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
 
-    res = wgl_native_wigdet_create(WIDGET_TYPE_CB, par_obj_id, copy_obj_id, module_inst);
+    res = wgl_native_wigdet_create(WIDGET_TYPE_CB, par_obj_id, copy_obj_id,
+                                   module_inst);
     wgl_native_set_return(res);
 }
 
@@ -63,7 +64,7 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_length_wrapper)
     (void)exec_env;
 
     text = lv_cb_get_text(cb);
-    wgl_native_set_return(text ? strlen(text): 0);
+    wgl_native_set_return(text ? strlen(text) : 0);
 }
 
 DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_wrapper)
@@ -89,24 +90,20 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_wrapper)
 }
 
 static WGLNativeFuncDef cb_native_func_defs[] = {
-    { CB_FUNC_ID_CREATE,            lv_cb_create_wrapper,            2,  false },
-    { CB_FUNC_ID_SET_TEXT,          lv_cb_set_text_wrapper,          3,  true },
-    { CB_FUNC_ID_SET_STATIC_TEXT,   lv_cb_set_static_text_wrapper,   3,  true },
-    { CB_FUNC_ID_GET_TEXT_LENGTH,   lv_cb_get_text_length_wrapper,   1,  true },
-    { CB_FUNC_ID_GET_TEXT,          lv_cb_get_text_wrapper,          3,  true },
+    { CB_FUNC_ID_CREATE, lv_cb_create_wrapper, 2, false },
+    { CB_FUNC_ID_SET_TEXT, lv_cb_set_text_wrapper, 3, true },
+    { CB_FUNC_ID_SET_STATIC_TEXT, lv_cb_set_static_text_wrapper, 3, true },
+    { CB_FUNC_ID_GET_TEXT_LENGTH, lv_cb_get_text_length_wrapper, 1, true },
+    { CB_FUNC_ID_GET_TEXT, lv_cb_get_text_wrapper, 3, true },
 };
 
 /*************** Native Interface to Wasm App ***********/
 void
-wasm_cb_native_call(wasm_exec_env_t exec_env,
-                    int32 func_id, uint32 *argv, uint32 argc)
+wasm_cb_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                    uint32 argc)
 {
     uint32 size = sizeof(cb_native_func_defs) / sizeof(WGLNativeFuncDef);
 
-    wgl_native_func_call(exec_env,
-                         cb_native_func_defs,
-                         size,
-                         func_id,
-                         argv,
+    wgl_native_func_call(exec_env, cb_native_func_defs, size, func_id, argv,
                          argc);
 }

+ 11 - 12
core/app-framework/wgl/native/wgl_label_wrapper.c

@@ -20,7 +20,8 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_label_create_wrapper)
     wgl_native_get_arg(uint32, copy_obj_id);
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
 
-    res = wgl_native_wigdet_create(WIDGET_TYPE_LABEL, par_obj_id, copy_obj_id, module_inst);
+    res = wgl_native_wigdet_create(WIDGET_TYPE_LABEL, par_obj_id, copy_obj_id,
+                                   module_inst);
     wgl_native_set_return(res);
 }
 
@@ -73,24 +74,22 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_label_get_text_wrapper)
     wgl_native_set_return(buffer_offset);
 }
 
+/* clang-format off */
 static WGLNativeFuncDef label_native_func_defs[] = {
-    { LABEL_FUNC_ID_CREATE,           lv_label_create_wrapper,          2,  false },
-    { LABEL_FUNC_ID_SET_TEXT,         lv_label_set_text_wrapper,        3,  true },
-    { LABEL_FUNC_ID_GET_TEXT_LENGTH,  lv_label_get_text_length_wrapper, 1,  true },
-    { LABEL_FUNC_ID_GET_TEXT,         lv_label_get_text_wrapper,        3,  true },
+    { LABEL_FUNC_ID_CREATE, lv_label_create_wrapper, 2, false },
+    { LABEL_FUNC_ID_SET_TEXT, lv_label_set_text_wrapper, 3, true },
+    { LABEL_FUNC_ID_GET_TEXT_LENGTH, lv_label_get_text_length_wrapper, 1, true },
+    { LABEL_FUNC_ID_GET_TEXT, lv_label_get_text_wrapper, 3, true },
 };
+/* clang-format on */
 
 /*************** Native Interface to Wasm App ***********/
 void
-wasm_label_native_call(wasm_exec_env_t exec_env,
-                       int32 func_id, uint32 *argv, uint32 argc)
+wasm_label_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                       uint32 argc)
 {
     uint32 size = sizeof(label_native_func_defs) / sizeof(WGLNativeFuncDef);
 
-    wgl_native_func_call(exec_env,
-                         label_native_func_defs,
-                         size,
-                         func_id,
-                         argv,
+    wgl_native_func_call(exec_env, label_native_func_defs, size, func_id, argv,
                          argc);
 }

+ 9 - 11
core/app-framework/wgl/native/wgl_list_wrapper.c

@@ -20,7 +20,8 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_list_create_wrapper)
     wgl_native_get_arg(uint32, copy_obj_id);
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
 
-    res = wgl_native_wigdet_create(WIDGET_TYPE_LIST, par_obj_id, copy_obj_id, module_inst);
+    res = wgl_native_wigdet_create(WIDGET_TYPE_LIST, par_obj_id, copy_obj_id,
+                                   module_inst);
     wgl_native_set_return(res);
 }
 
@@ -49,7 +50,8 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_list_add_btn_wrapper)
     bh_assert(mod_id != ID_NONE);
 
     if (!wgl_native_add_object(btn, mod_id, &btn_obj_id)) {
-        wasm_runtime_set_exception(module_inst, "add button to object list fail.");
+        wasm_runtime_set_exception(module_inst,
+                                   "add button to object list fail.");
         return;
     }
 
@@ -57,21 +59,17 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_list_add_btn_wrapper)
 }
 
 static WGLNativeFuncDef list_native_func_defs[] = {
-    { LIST_FUNC_ID_CREATE,       lv_list_create_wrapper,       2,  false },
-    { LIST_FUNC_ID_ADD_BTN,      lv_list_add_btn_wrapper,      3,  true },
+    { LIST_FUNC_ID_CREATE, lv_list_create_wrapper, 2, false },
+    { LIST_FUNC_ID_ADD_BTN, lv_list_add_btn_wrapper, 3, true },
 };
 
 /*************** Native Interface to Wasm App ***********/
 void
-wasm_list_native_call(wasm_exec_env_t exec_env,
-                      int32 func_id, uint32 *argv, uint32 argc)
+wasm_list_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                      uint32 argc)
 {
     uint32 size = sizeof(list_native_func_defs) / sizeof(WGLNativeFuncDef);
 
-    wgl_native_func_call(exec_env,
-                         list_native_func_defs,
-                         size,
-                         func_id,
-                         argv,
+    wgl_native_func_call(exec_env, list_native_func_defs, size, func_id, argv,
                          argc);
 }

+ 12 - 17
core/app-framework/wgl/native/wgl_native_utils.c

@@ -10,16 +10,15 @@
 
 #define THROW_EXC(msg) wasm_runtime_set_exception(module_inst, msg);
 
-uint32 wgl_native_wigdet_create(int8 widget_type,
-                                uint32 par_obj_id,
-                                uint32 copy_obj_id,
-                                wasm_module_inst_t module_inst)
+uint32
+wgl_native_wigdet_create(int8 widget_type, uint32 par_obj_id,
+                         uint32 copy_obj_id, wasm_module_inst_t module_inst)
 {
     uint32 obj_id;
     lv_obj_t *wigdet = NULL, *par = NULL, *copy = NULL;
     uint32 mod_id;
 
-    //TODO: limit total widget number
+    // TODO: limit total widget number
 
     /* validate the parent object id if not equal to 0 */
     if (par_obj_id != 0 && !wgl_native_validate_object(par_obj_id, &par)) {
@@ -58,14 +57,11 @@ uint32 wgl_native_wigdet_create(int8 widget_type,
     return 0;
 }
 
-void wgl_native_func_call(wasm_exec_env_t exec_env,
-                          WGLNativeFuncDef *funcs,
-                          uint32 size,
-                          int32 func_id,
-                          uint32 *argv,
-                          uint32 argc)
+void
+wgl_native_func_call(wasm_exec_env_t exec_env, WGLNativeFuncDef *funcs,
+                     uint32 size, int32 func_id, uint32 *argv, uint32 argc)
 {
-    typedef void (*WGLNativeFuncPtr)(wasm_exec_env_t, uint64*, uint32*);
+    typedef void (*WGLNativeFuncPtr)(wasm_exec_env_t, uint64 *, uint32 *);
     WGLNativeFuncPtr wglNativeFuncPtr;
     wasm_module_inst_t module_inst = get_module_inst(exec_env);
     WGLNativeFuncDef *func_def = funcs;
@@ -74,12 +70,12 @@ void wgl_native_func_call(wasm_exec_env_t exec_env,
     /* Note: argv is validated in wasm_runtime_invoke_native()
      * with pointer length equals to 1. Here validate the argv
      * buffer again but with its total length in bytes */
-    if (!wasm_runtime_validate_native_addr(module_inst, argv, argc * sizeof(uint32)))
+    if (!wasm_runtime_validate_native_addr(module_inst, argv,
+                                           argc * sizeof(uint32)))
         return;
 
     while (func_def < func_def_end) {
-        if (func_def->func_id == func_id
-            && (uint32)func_def->arg_num == argc) {
+        if (func_def->func_id == func_id && (uint32)func_def->arg_num == argc) {
             uint64 argv_copy_buf[16], size;
             uint64 *argv_copy = argv_copy_buf;
             int i;
@@ -96,7 +92,7 @@ void wgl_native_func_call(wasm_exec_env_t exec_env,
 
             /* Init argv_copy */
             for (i = 0; i < func_def->arg_num; i++)
-                *(uint32*)&argv_copy[i] = argv[i];
+                *(uint32 *)&argv_copy[i] = argv[i];
 
             /* Validate the first argument which is a lvgl object if needed */
             if (func_def->check_obj) {
@@ -128,4 +124,3 @@ void wgl_native_func_call(wasm_exec_env_t exec_env,
 
     THROW_EXC("the native widget function is not found!");
 }
-

+ 21 - 22
core/app-framework/wgl/native/wgl_native_utils.h

@@ -15,21 +15,22 @@ extern "C" {
 #include "wasm_export.h"
 #include "bi-inc/wgl_shared_utils.h"
 
-#define wgl_native_return_type(type) type *wgl_ret = (type*)(args_ret)
-#define wgl_native_get_arg(type, name) type name = *((type*)(args++))
+#define wgl_native_return_type(type) type *wgl_ret = (type *)(args_ret)
+#define wgl_native_get_arg(type, name) type name = *((type *)(args++))
 #define wgl_native_set_return(val) *wgl_ret = (val)
 
-#define DEFINE_WGL_NATIVE_WRAPPER(func_name) \
-static void func_name(wasm_exec_env_t exec_env, uint64 *args, uint32 *args_ret)
+#define DEFINE_WGL_NATIVE_WRAPPER(func_name)                      \
+    static void func_name(wasm_exec_env_t exec_env, uint64 *args, \
+                          uint32 *args_ret)
 
 enum {
-  WIDGET_TYPE_BTN,
-  WIDGET_TYPE_LABEL,
-  WIDGET_TYPE_CB,
-  WIDGET_TYPE_LIST,
-  WIDGET_TYPE_DDLIST,
+    WIDGET_TYPE_BTN,
+    WIDGET_TYPE_LABEL,
+    WIDGET_TYPE_CB,
+    WIDGET_TYPE_LIST,
+    WIDGET_TYPE_DDLIST,
 
-  _WIDGET_TYPE_NUM,
+    _WIDGET_TYPE_NUM,
 };
 
 typedef struct WGLNativeFuncDef {
@@ -46,21 +47,19 @@ typedef struct WGLNativeFuncDef {
     bool check_obj;
 } WGLNativeFuncDef;
 
-bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj);
+bool
+wgl_native_validate_object(int32 obj_id, lv_obj_t **obj);
 
-bool wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id);
+bool
+wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id);
 
-uint32 wgl_native_wigdet_create(int8 widget_type,
-                                uint32 par_obj_id,
-                                uint32 copy_obj_id,
-                                wasm_module_inst_t module_inst);
+uint32
+wgl_native_wigdet_create(int8 widget_type, uint32 par_obj_id,
+                         uint32 copy_obj_id, wasm_module_inst_t module_inst);
 
-void wgl_native_func_call(wasm_exec_env_t exec_env,
-                          WGLNativeFuncDef *funcs,
-                          uint32 size,
-                          int32 func_id,
-                          uint32 *argv,
-                          uint32 argc);
+void
+wgl_native_func_call(wasm_exec_env_t exec_env, WGLNativeFuncDef *funcs,
+                     uint32 size, int32 func_id, uint32 *argv, uint32 argc);
 
 #ifdef __cplusplus
 }

+ 55 - 52
core/app-framework/wgl/native/wgl_obj_wrapper.c

@@ -10,7 +10,6 @@
 #include "wgl_native_utils.h"
 #include "wgl.h"
 
-
 typedef struct {
     bh_list_link l;
 
@@ -42,24 +41,24 @@ static korp_mutex task_handler_lock;
 
 static korp_cond task_handler_cond;
 
-static void app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
+static void
+app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
 {
     uint32 argv[2];
     wasm_function_inst_t func_on_object_event;
     bh_assert(WIDGET_EVENT_WASM == bh_message_type(msg));
-    wasm_data *wasm_app_data = (wasm_data*)m_data->internal_data;
+    wasm_data *wasm_app_data = (wasm_data *)m_data->internal_data;
     wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
-    object_event_t *object_event
-                       = (object_event_t *)bh_message_payload(msg);
+    object_event_t *object_event = (object_event_t *)bh_message_payload(msg);
 
     if (object_event == NULL)
         return;
 
-    func_on_object_event = wasm_runtime_lookup_function(inst, "_on_widget_event",
-                                                        "(i32i32)");
+    func_on_object_event =
+        wasm_runtime_lookup_function(inst, "_on_widget_event", "(i32i32)");
     if (!func_on_object_event)
-        func_on_object_event = wasm_runtime_lookup_function(inst, "on_widget_event",
-                                                            "(i32i32)");
+        func_on_object_event =
+            wasm_runtime_lookup_function(inst, "on_widget_event", "(i32i32)");
     if (!func_on_object_event) {
         printf("Cannot find function on_widget_event\n");
         return;
@@ -71,14 +70,14 @@ static void app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
                                 2, argv)) {
         const char *exception = wasm_runtime_get_exception(inst);
         bh_assert(exception);
-        printf(":Got exception running wasm code: %s\n",
-                exception);
+        printf(":Got exception running wasm code: %s\n", exception);
         wasm_runtime_clear_exception(inst);
         return;
     }
 }
 
-static void cleanup_object_list(uint32 module_id)
+static void
+cleanup_object_list(uint32 module_id)
 {
     object_node_t *elem;
 
@@ -89,8 +88,8 @@ static void cleanup_object_list(uint32 module_id)
         elem = (object_node_t *)bh_list_first_elem(&g_object_list);
         while (elem) {
             /* delete the leaf node belongs to the module firstly */
-            if (module_id == elem->module_id &&
-                lv_obj_count_children(elem->obj) == 0) {
+            if (module_id == elem->module_id
+                && lv_obj_count_children(elem->obj) == 0) {
                 object_node_t *next = (object_node_t *)bh_list_elem_next(elem);
 
                 found = true;
@@ -98,7 +97,8 @@ static void cleanup_object_list(uint32 module_id)
                 bh_list_remove(&g_object_list, elem);
                 wasm_runtime_free(elem);
                 elem = next;
-            } else {
+            }
+            else {
                 elem = (object_node_t *)bh_list_elem_next(elem);
             }
         }
@@ -110,7 +110,8 @@ static void cleanup_object_list(uint32 module_id)
     os_mutex_unlock(&g_object_list_mutex);
 }
 
-static bool init_object_event_callback_framework()
+static bool
+init_object_event_callback_framework()
 {
     if (!wasm_register_cleanup_callback(cleanup_object_list)) {
         goto fail;
@@ -127,7 +128,8 @@ fail:
     return false;
 }
 
-bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj)
+bool
+wgl_native_validate_object(int32 obj_id, lv_obj_t **obj)
 {
     object_node_t *elem;
 
@@ -141,7 +143,7 @@ bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj)
             os_mutex_unlock(&g_object_list_mutex);
             return true;
         }
-        elem = (object_node_t *) bh_list_elem_next(elem);
+        elem = (object_node_t *)bh_list_elem_next(elem);
     }
 
     os_mutex_unlock(&g_object_list_mutex);
@@ -149,11 +151,12 @@ bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj)
     return false;
 }
 
-bool wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id)
+bool
+wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id)
 {
     object_node_t *node;
 
-    node = (object_node_t *) wasm_runtime_malloc(sizeof(object_node_t));
+    node = (object_node_t *)wasm_runtime_malloc(sizeof(object_node_t));
 
     if (node == NULL)
         return false;
@@ -178,11 +181,12 @@ bool wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id)
     return true;
 }
 
-static void _obj_del_recursive(lv_obj_t *obj)
+static void
+_obj_del_recursive(lv_obj_t *obj)
 {
     object_node_t *elem;
-    lv_obj_t * i;
-    lv_obj_t * i_next;
+    lv_obj_t *i;
+    lv_obj_t *i_next;
 
     i = lv_ll_get_head(&(obj->child_ll));
 
@@ -207,16 +211,17 @@ static void _obj_del_recursive(lv_obj_t *obj)
             os_mutex_unlock(&g_object_list_mutex);
             return;
         }
-        elem = (object_node_t *) bh_list_elem_next(elem);
+        elem = (object_node_t *)bh_list_elem_next(elem);
     }
 
     os_mutex_unlock(&g_object_list_mutex);
 }
 
-static void _obj_clean_recursive(lv_obj_t *obj)
+static void
+_obj_clean_recursive(lv_obj_t *obj)
 {
-    lv_obj_t * i;
-    lv_obj_t * i_next;
+    lv_obj_t *i;
+    lv_obj_t *i_next;
 
     i = lv_ll_get_head(&(obj->child_ll));
 
@@ -232,7 +237,8 @@ static void _obj_clean_recursive(lv_obj_t *obj)
     }
 }
 
-static void post_widget_msg_to_module(object_node_t *object_node, lv_event_t event)
+static void
+post_widget_msg_to_module(object_node_t *object_node, lv_event_t event)
 {
     module_data *module = module_data_list_lookup_id(object_node->module_id);
     object_event_t *object_event;
@@ -248,13 +254,12 @@ static void post_widget_msg_to_module(object_node_t *object_node, lv_event_t eve
     object_event->obj_id = object_node->obj_id;
     object_event->event = event;
 
-    bh_post_msg(module->queue,
-                WIDGET_EVENT_WASM,
-                object_event,
+    bh_post_msg(module->queue, WIDGET_EVENT_WASM, object_event,
                 sizeof(*object_event));
 }
 
-static void internal_lv_obj_event_cb(lv_obj_t *obj, lv_event_t event)
+static void
+internal_lv_obj_event_cb(lv_obj_t *obj, lv_event_t event)
 {
     object_node_t *elem;
 
@@ -267,13 +272,14 @@ static void internal_lv_obj_event_cb(lv_obj_t *obj, lv_event_t event)
             os_mutex_unlock(&g_object_list_mutex);
             return;
         }
-        elem = (object_node_t *) bh_list_elem_next(elem);
+        elem = (object_node_t *)bh_list_elem_next(elem);
     }
 
     os_mutex_unlock(&g_object_list_mutex);
 }
 
-static void* lv_task_handler_thread_routine (void *arg)
+static void *
+lv_task_handler_thread_routine(void *arg)
 {
     os_mutex_lock(&task_handler_lock);
 
@@ -287,7 +293,8 @@ static void* lv_task_handler_thread_routine (void *arg)
     return NULL;
 }
 
-void wgl_init(void)
+void
+wgl_init(void)
 {
     korp_tid tid;
 
@@ -306,13 +313,12 @@ void wgl_init(void)
     init_object_event_callback_framework();
 
     /* new a thread, call lv_task_handler periodically */
-    os_thread_create(&tid,
-                     lv_task_handler_thread_routine,
-                     NULL,
+    os_thread_create(&tid, lv_task_handler_thread_routine, NULL,
                      BH_APPLET_PRESERVED_STACK_SIZE);
 }
 
-void wgl_exit(void)
+void
+wgl_exit(void)
 {
     lv_task_handler_thread_run = false;
     os_cond_destroy(&task_handler_cond);
@@ -371,7 +377,8 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_obj_align_wrapper)
 
     /* validate the base object id if not equal to 0 */
     if (base_obj_id != 0 && !wgl_native_validate_object(base_obj_id, &base)) {
-        wasm_runtime_set_exception(module_inst, "align with invalid base object.");
+        wasm_runtime_set_exception(module_inst,
+                                   "align with invalid base object.");
         return;
     }
 
@@ -388,24 +395,20 @@ DEFINE_WGL_NATIVE_WRAPPER(lv_obj_set_event_cb_wrapper)
 /* ------------------------------------------------------------------------- */
 
 static WGLNativeFuncDef obj_native_func_defs[] = {
-    { OBJ_FUNC_ID_DEL,         lv_obj_del_wrapper,            1,  true },
-    { OBJ_FUNC_ID_DEL_ASYNC,   lv_obj_del_async_wrapper,      1,  true },
-    { OBJ_FUNC_ID_CLEAN,       lv_obj_clean_wrapper,          1,  true },
-    { OBJ_FUNC_ID_ALIGN,       lv_obj_align_wrapper,          5,  true },
-    { OBJ_FUNC_ID_SET_EVT_CB,  lv_obj_set_event_cb_wrapper,   1,  true },
+    { OBJ_FUNC_ID_DEL, lv_obj_del_wrapper, 1, true },
+    { OBJ_FUNC_ID_DEL_ASYNC, lv_obj_del_async_wrapper, 1, true },
+    { OBJ_FUNC_ID_CLEAN, lv_obj_clean_wrapper, 1, true },
+    { OBJ_FUNC_ID_ALIGN, lv_obj_align_wrapper, 5, true },
+    { OBJ_FUNC_ID_SET_EVT_CB, lv_obj_set_event_cb_wrapper, 1, true },
 };
 
 /*************** Native Interface to Wasm App ***********/
 void
-wasm_obj_native_call(wasm_exec_env_t exec_env,
-                     int32 func_id, uint32 *argv, uint32 argc)
+wasm_obj_native_call(wasm_exec_env_t exec_env, int32 func_id, uint32 *argv,
+                     uint32 argc)
 {
     uint32 size = sizeof(obj_native_func_defs) / sizeof(WGLNativeFuncDef);
 
-    wgl_native_func_call(exec_env,
-                         obj_native_func_defs,
-                         size,
-                         func_id,
-                         argv,
+    wgl_native_func_call(exec_env, obj_native_func_defs, size, func_id, argv,
                          argc);
 }

+ 56 - 46
core/app-mgr/app-manager/app_manager.c

@@ -14,13 +14,14 @@
 /* Queue of app manager */
 static bh_queue *g_app_mgr_queue;
 
-void*
+void *
 get_app_manager_queue()
 {
     return g_app_mgr_queue;
 }
 
-void app_manager_post_applets_update_event()
+void
+app_manager_post_applets_update_event()
 {
     module_data *m_data;
     attr_container_t *attr_cont;
@@ -56,7 +57,8 @@ void app_manager_post_applets_update_event()
         char buf[32];
         i++;
         snprintf(buf, sizeof(buf), "%s%d", "applet", i);
-        if (!(attr_container_set_string(&attr_cont, buf, m_data->module_name))) {
+        if (!(attr_container_set_string(&attr_cont, buf,
+                                        m_data->module_name))) {
             app_manager_printf("Post applets update event failed: "
                                "set attr applet name key failed.");
             goto fail;
@@ -73,7 +75,7 @@ void app_manager_post_applets_update_event()
     memset(&msg, 0, sizeof(msg));
     msg.url = url;
     msg.action = COAP_EVENT;
-    msg.payload = (char*) attr_cont;
+    msg.payload = (char *)attr_cont;
     send_request_to_host(&msg);
 
     app_manager_printf("Post applets update event success!\n");
@@ -84,7 +86,8 @@ fail:
     attr_container_destroy(attr_cont);
 }
 
-static int get_applets_count()
+static int
+get_applets_count()
 {
     module_data *m_data;
     int num = 0;
@@ -103,7 +106,8 @@ static int get_applets_count()
 }
 
 /* Query fw apps info if name = NULL, otherwise query specify app */
-static bool app_manager_query_applets(request_t *msg, const char *name)
+static bool
+app_manager_query_applets(request_t *msg, const char *name)
 {
     module_data *m_data;
     attr_container_t *attr_cont;
@@ -127,8 +131,8 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
     }
 
     if (name == NULL && !(attr_container_set_int(&attr_cont, "num", num))) {
-        SEND_ERR_RESPONSE(msg->mid,
-                          "Query Applets failed: set attr container key failed.");
+        SEND_ERR_RESPONSE(
+            msg->mid, "Query Applets failed: set attr container key failed.");
         goto fail;
     }
 
@@ -140,10 +144,9 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
             i++;
             snprintf(buf, sizeof(buf), "%s%d", "applet", i);
             if (!(attr_container_set_string(&attr_cont, buf,
-                    m_data->module_name))) {
-                SEND_ERR_RESPONSE(msg->mid,
-                                  "Query Applets failed: "
-                                  "set attr container key failed.");
+                                            m_data->module_name))) {
+                SEND_ERR_RESPONSE(msg->mid, "Query Applets failed: "
+                                            "set attr container key failed.");
                 goto fail;
             }
             snprintf(buf, sizeof(buf), "%s%d", "heap", i);
@@ -157,13 +160,13 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
         else if (!strcmp(name, m_data->module_name)) {
             found = true;
             if (!(attr_container_set_string(&attr_cont, "name",
-                    m_data->module_name))) {
-                SEND_ERR_RESPONSE(msg->mid,
-                                  "Query Applet failed: "
-                                  "set attr container key failed.");
+                                            m_data->module_name))) {
+                SEND_ERR_RESPONSE(msg->mid, "Query Applet failed: "
+                                            "set attr container key failed.");
                 goto fail;
             }
-            if (!(attr_container_set_int(&attr_cont, "heap", m_data->heap_size))) {
+            if (!(attr_container_set_int(&attr_cont, "heap",
+                                         m_data->heap_size))) {
                 SEND_ERR_RESPONSE(msg->mid,
                                   "Query Applet failed: "
                                   "set attr container heap key failed.");
@@ -176,15 +179,15 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
 
     if (name != NULL && !found) {
         SEND_ERR_RESPONSE(msg->mid,
-                "Query Applet failed: the app is not found.");
+                          "Query Applet failed: the app is not found.");
         goto fail;
     }
 
     len = attr_container_get_serialize_length(attr_cont);
 
     make_response_for_request(msg, response);
-    set_response(response, CONTENT_2_05,
-    FMT_ATTR_CONTAINER, (char*) attr_cont, len);
+    set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, (char *)attr_cont,
+                 len);
     send_response_to_host(response);
 
     ret = true;
@@ -197,7 +200,8 @@ fail:
     return ret;
 }
 
-void applet_mgt_reqeust_handler(request_t *request, void *unused)
+void
+applet_mgt_reqeust_handler(request_t *request, void *unused)
 {
     bh_message_t msg;
     /* deep copy, but not use app self heap, but use global heap */
@@ -216,13 +220,14 @@ void applet_mgt_reqeust_handler(request_t *request, void *unused)
 }
 
 /* return -1 for error */
-static int get_module_type(char *kv_str)
+static int
+get_module_type(char *kv_str)
 {
     int module_type = -1;
     char type_str[16] = { 0 };
 
     find_key_value(kv_str, strlen(kv_str), "type", type_str,
-            sizeof(type_str) - 1, '&');
+                   sizeof(type_str) - 1, '&');
 
     if (strlen(type_str) == 0)
         module_type = Module_WASM_App;
@@ -240,34 +245,37 @@ static int get_module_type(char *kv_str)
 
 /* Queue callback of App Manager */
 
-static void app_manager_queue_callback(void *message, void *arg)
+static void
+app_manager_queue_callback(void *message, void *arg)
 {
-    request_t *request = (request_t *) bh_message_payload((bh_message_t)message);
+    request_t *request = (request_t *)bh_message_payload((bh_message_t)message);
     int mid = request->mid, module_type, offset;
 
     (void)arg;
 
-    if ((offset = check_url_start(request->url, strlen(request->url), "/applet"))
-            > 0) {
+    if ((offset =
+             check_url_start(request->url, strlen(request->url), "/applet"))
+        > 0) {
         module_type = get_module_type(request->url + offset);
 
         if (module_type == -1) {
             SEND_ERR_RESPONSE(mid,
-                    "Applet Management failed: invalid module type.");
+                              "Applet Management failed: invalid module type.");
             goto fail;
         }
 
         /* Install Applet */
         if (request->action == COAP_PUT) {
             if (get_applets_count() >= MAX_APP_INSTALLATIONS) {
-                SEND_ERR_RESPONSE(mid,
-                        "Install Applet failed: exceed max app installations.");
+                SEND_ERR_RESPONSE(
+                    mid,
+                    "Install Applet failed: exceed max app installations.");
                 goto fail;
             }
 
             if (!request->payload) {
                 SEND_ERR_RESPONSE(mid,
-                        "Install Applet failed: invalid payload.");
+                                  "Install Applet failed: invalid payload.");
                 goto fail;
             }
             if (g_module_interfaces[module_type]
@@ -280,14 +288,15 @@ static void app_manager_queue_callback(void *message, void *arg)
         else if (request->action == COAP_DELETE) {
             module_type = get_module_type(request->url + offset);
             if (module_type == -1) {
-                SEND_ERR_RESPONSE(mid,
-                                  "Uninstall Applet failed: invalid module type.");
+                SEND_ERR_RESPONSE(
+                    mid, "Uninstall Applet failed: invalid module type.");
                 goto fail;
             }
 
             if (g_module_interfaces[module_type]
-                    && g_module_interfaces[module_type]->module_uninstall) {
-                if (!g_module_interfaces[module_type]->module_uninstall(request))
+                && g_module_interfaces[module_type]->module_uninstall) {
+                if (!g_module_interfaces[module_type]->module_uninstall(
+                        request))
                     goto fail;
             }
         }
@@ -308,7 +317,8 @@ static void app_manager_queue_callback(void *message, void *arg)
     }
     /* Event Register/Unregister */
     else if ((offset = check_url_start(request->url, strlen(request->url),
-                                       "/event/")) > 0) {
+                                       "/event/"))
+             > 0) {
         char url_buf[256] = { 0 };
 
         strncpy(url_buf, request->url + offset, sizeof(url_buf) - 1);
@@ -328,14 +338,14 @@ static void app_manager_queue_callback(void *message, void *arg)
                     break;
             }
         }
-
     }
 
 fail:
     return;
 }
 
-static void module_interfaces_init()
+static void
+module_interfaces_init()
 {
     int i;
     for (i = 0; i < Module_Max; i++) {
@@ -344,7 +354,8 @@ static void module_interfaces_init()
     }
 }
 
-void app_manager_startup(host_interface *interface)
+void
+app_manager_startup(host_interface *interface)
 {
     module_interfaces_init();
 
@@ -390,21 +401,20 @@ fail1:
 
 module_interface *g_module_interfaces[Module_Max] = {
 #if ENABLE_MODULE_JEFF != 0
-        &jeff_module_interface,
+    &jeff_module_interface,
 #else
-        NULL,
+    NULL,
 #endif
 
 #if ENABLE_MODULE_WASM_APP != 0
-        &wasm_app_module_interface,
+    &wasm_app_module_interface,
 #else
-        NULL,
+    NULL,
 #endif
 
 #if ENABLE_MODULE_WASM_LIB != 0
-        &wasm_lib_module_interface
+    &wasm_lib_module_interface
 #else
-        NULL
+    NULL
 #endif
 };
-

+ 14 - 12
core/app-mgr/app-manager/app_manager.h

@@ -21,10 +21,11 @@ extern "C" {
 /* os_printf is defined in each platform */
 #define app_manager_printf os_printf
 
-#define SEND_ERR_RESPONSE(mid, err_msg) do {                            \
-  app_manager_printf("%s\n", err_msg);                                  \
-  send_error_response_to_host(mid, INTERNAL_SERVER_ERROR_5_00, err_msg);  \
-} while (0)
+#define SEND_ERR_RESPONSE(mid, err_msg)                                        \
+    do {                                                                       \
+        app_manager_printf("%s\n", err_msg);                                   \
+        send_error_response_to_host(mid, INTERNAL_SERVER_ERROR_5_00, err_msg); \
+    } while (0)
 
 extern module_interface *g_module_interfaces[Module_Max];
 
@@ -49,14 +50,15 @@ module_data_list_destroy();
 bool
 app_manager_is_interrupting_module(uint32 module_type, void *module_inst);
 
-void release_module(module_data *m_data);
+void
+release_module(module_data *m_data);
 
 void
 module_data_list_remove(module_data *m_data);
 
-void*
-app_manager_timer_create(void (*timer_callback)(void*),
-        watchdog_timer *wd_timer);
+void *
+app_manager_timer_create(void (*timer_callback)(void *),
+                         watchdog_timer *wd_timer);
 
 void
 app_manager_timer_destroy(void *timer);
@@ -67,18 +69,18 @@ app_manager_timer_start(void *timer, int timeout);
 void
 app_manager_timer_stop(void *timer);
 
-watchdog_timer*
+watchdog_timer *
 app_manager_get_wd_timer_from_timer_handle(void *timer);
 
 int
 app_manager_signature_verify(const uint8_t *file, unsigned int file_len,
-        const uint8_t *signature, unsigned int sig_size);
+                             const uint8_t *signature, unsigned int sig_size);
 
-void targeted_app_request_handler(request_t *request, void *unused);
+void
+targeted_app_request_handler(request_t *request, void *unused);
 
 #ifdef __cplusplus
 } /* end of extern "C" */
 #endif
 
 #endif
-

+ 26 - 20
core/app-mgr/app-manager/app_manager_host.c

@@ -13,10 +13,7 @@
 static host_interface host_commu;
 
 /* IMRTLink Two leading bytes */
-static unsigned char leadings[] = {
-    (unsigned char)0x12,
-    (unsigned char)0x34
-};
+static unsigned char leadings[] = { (unsigned char)0x12, (unsigned char)0x34 };
 
 /* IMRTLink Receiving Phase */
 typedef enum recv_phase_t {
@@ -43,14 +40,16 @@ static korp_mutex host_lock;
 
 static bool enable_log = false;
 
-static bool is_little_endian()
+static bool
+is_little_endian()
 {
     long i = 0x01020304;
-    unsigned char* c = (unsigned char*) &i;
+    unsigned char *c = (unsigned char *)&i;
     return (*c == 0x04) ? true : false;
 }
 
-static void exchange32(uint8* pData)
+static void
+exchange32(uint8 *pData)
 {
     uint8 value = *pData;
     *pData = *(pData + 3);
@@ -65,7 +64,8 @@ static void exchange32(uint8* pData)
  *  1: complete message received
  *  0: incomplete message received
  */
-static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
+static int
+on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
 {
     if (ctx->phase == Phase_Non_Start) {
         ctx->message.payload_size = 0;
@@ -88,7 +88,8 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
             if (enable_log)
                 app_manager_printf("##On byte arrive: got leading 1\n");
             ctx->phase = Phase_Type;
-        } else
+        }
+        else
             ctx->phase = Phase_Non_Start;
 
         return 0;
@@ -111,7 +112,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
         return 0;
     }
     else if (ctx->phase == Phase_Size) {
-        unsigned char *p = (unsigned char *) &ctx->message.payload_size;
+        unsigned char *p = (unsigned char *)&ctx->message.payload_size;
 
         if (enable_log)
             app_manager_printf("##On byte arrive: got payload_size, byte %d\n",
@@ -141,7 +142,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
 
             if (ctx->message.message_type != INSTALL_WASM_APP) {
                 ctx->message.payload =
-                    (char *) APP_MGR_MALLOC(ctx->message.payload_size);
+                    (char *)APP_MGR_MALLOC(ctx->message.payload_size);
                 if (!ctx->message.payload) {
                     ctx->phase = Phase_Non_Start;
                     return 0;
@@ -158,7 +159,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
         if (ctx->message.message_type == INSTALL_WASM_APP) {
             int received_size;
             module_on_install_request_byte_arrive_func module_on_install =
-                    g_module_interfaces[Module_WASM_App]->module_on_install;
+                g_module_interfaces[Module_WASM_App]->module_on_install;
 
             ctx->size_in_phase++;
 
@@ -216,7 +217,8 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
     return 0;
 }
 
-int aee_host_msg_callback(void *msg, uint32_t msg_len)
+int
+aee_host_msg_callback(void *msg, uint32_t msg_len)
 {
     unsigned char *p = msg, *p_end = p + msg_len;
 
@@ -234,7 +236,8 @@ int aee_host_msg_callback(void *msg, uint32_t msg_len)
                     memset(&request, 0, sizeof(request));
 
                     if (!unpack_request(recv_ctx.message.payload,
-                                        recv_ctx.message.payload_size, &request))
+                                        recv_ctx.message.payload_size,
+                                        &request))
                         continue;
 
                     request.sender = ID_HOST;
@@ -242,7 +245,8 @@ int aee_host_msg_callback(void *msg, uint32_t msg_len)
                     am_dispatch_request(&request);
                 }
                 else {
-                    app_manager_printf("unexpected host msg type: %d\n", msg_type);
+                    app_manager_printf("unexpected host msg type: %d\n",
+                                       msg_type);
                 }
 
                 APP_MGR_FREE(recv_ctx.message.payload);
@@ -257,7 +261,8 @@ int aee_host_msg_callback(void *msg, uint32_t msg_len)
     return 0;
 }
 
-bool app_manager_host_init(host_interface *interface)
+bool
+app_manager_host_init(host_interface *interface)
 {
     os_mutex_init(&host_lock);
     memset(&recv_ctx, 0, sizeof(recv_ctx));
@@ -267,12 +272,13 @@ bool app_manager_host_init(host_interface *interface)
     host_commu.destroy = interface->destroy;
 
     if (host_commu.init != NULL)
-      return host_commu.init();
+        return host_commu.init();
 
     return true;
 }
 
-int app_manager_host_send_msg(int msg_type, const char *buf, int size)
+int
+app_manager_host_send_msg(int msg_type, const char *buf, int size)
 {
     /* send an IMRT LINK message contains the buf as payload */
     if (host_commu.send != NULL) {
@@ -285,11 +291,11 @@ int app_manager_host_send_msg(int msg_type, const char *buf, int size)
 
         /* message type */
         /* TODO: check if use network byte order!!! */
-        *((uint16*)(header + 2)) = htons(msg_type);
+        *((uint16 *)(header + 2)) = htons(msg_type);
 
         /* payload length */
         if (is_little_endian())
-            exchange32((uint8*) &size_s);
+            exchange32((uint8 *)&size_s);
 
         bh_memcpy_s(header + 4, 4, &size_s, 4);
         n = host_commu.send(NULL, header, 8);

+ 1 - 2
core/app-mgr/app-manager/app_manager_host.h

@@ -12,7 +12,7 @@
 extern "C" {
 #endif
 
-#define HOST_MODE_AON  1
+#define HOST_MODE_AON 1
 #define HOST_MODE_UART 2
 #define HOST_MODE_TEST 3
 
@@ -21,4 +21,3 @@ extern "C" {
 #endif
 
 #endif
-

+ 1 - 1
core/app-mgr/app-manager/ble_msg.c

@@ -5,7 +5,7 @@
 
 #if 0
 
-#define BLUETOOTH_INTERFACE_ADVERTISMENT_DATA_LENGTH   31
+#define BLUETOOTH_INTERFACE_ADVERTISMENT_DATA_LENGTH 31
 /* ble_device_info */
 typedef struct ble_device_info {
 

+ 40 - 28
core/app-mgr/app-manager/event.c

@@ -11,25 +11,26 @@
 #include "coap_ext.h"
 
 typedef struct _subscribe {
-    struct _subscribe * next;
+    struct _subscribe *next;
     uint32 subscriber_id;
 } subscribe_t;
 
 typedef struct _event {
     struct _event *next;
     int subscriber_size;
-    subscribe_t * subscribers;
+    subscribe_t *subscribers;
     char url[1]; /* event url */
 } event_reg_t;
 
 event_reg_t *g_events = NULL;
 
-static bool find_subscriber(event_reg_t * reg, uint32 id, bool remove_found)
+static bool
+find_subscriber(event_reg_t *reg, uint32 id, bool remove_found)
 {
-    subscribe_t* c = reg->subscribers;
-    subscribe_t * prev = NULL;
+    subscribe_t *c = reg->subscribers;
+    subscribe_t *prev = NULL;
     while (c) {
-        subscribe_t * next = c->next;
+        subscribe_t *next = c->next;
         if (c->subscriber_id == id) {
             if (remove_found) {
                 if (prev)
@@ -41,7 +42,8 @@ static bool find_subscriber(event_reg_t * reg, uint32 id, bool remove_found)
             }
 
             return true;
-        } else {
+        }
+        else {
             prev = c;
             c = next;
         }
@@ -50,7 +52,8 @@ static bool find_subscriber(event_reg_t * reg, uint32 id, bool remove_found)
     return false;
 }
 
-static bool check_url(const char *url)
+static bool
+check_url(const char *url)
 {
     if (*url == 0)
         return false;
@@ -58,7 +61,8 @@ static bool check_url(const char *url)
     return true;
 }
 
-bool am_register_event(const char *url, uint32_t reg_client)
+bool
+am_register_event(const char *url, uint32_t reg_client)
 {
     event_reg_t *current = g_events;
 
@@ -76,8 +80,8 @@ bool am_register_event(const char *url, uint32_t reg_client)
 
     if (current == NULL) {
         if (NULL
-                == (current = (event_reg_t *) APP_MGR_MALLOC(
-                        offsetof(event_reg_t, url) + strlen(url) + 1))) {
+            == (current = (event_reg_t *)APP_MGR_MALLOC(
+                    offsetof(event_reg_t, url) + strlen(url) + 1))) {
             app_manager_printf("am_register_event: malloc fail\n");
             return false;
         }
@@ -90,8 +94,9 @@ bool am_register_event(const char *url, uint32_t reg_client)
 
     if (find_subscriber(current, reg_client, false)) {
         return true;
-    } else {
-        subscribe_t * s = (subscribe_t*) APP_MGR_MALLOC(sizeof(subscribe_t));
+    }
+    else {
+        subscribe_t *s = (subscribe_t *)APP_MGR_MALLOC(sizeof(subscribe_t));
         if (s == NULL)
             return false;
 
@@ -100,29 +105,30 @@ bool am_register_event(const char *url, uint32_t reg_client)
         s->next = current->subscribers;
         current->subscribers = s;
         app_manager_printf("client: %d registered event (%s)\n", reg_client,
-                url);
+                           url);
     }
 
     return true;
 }
 
 // @url: NULL means the client wants to unregister all its subscribed items
-bool am_unregister_event(const char *url, uint32_t reg_client)
+bool
+am_unregister_event(const char *url, uint32_t reg_client)
 {
     event_reg_t *current = g_events, *pre = NULL;
 
     while (current != NULL) {
         if (url == NULL || strcmp(current->url, url) == 0) {
-            event_reg_t * next = current->next;
+            event_reg_t *next = current->next;
             if (find_subscriber(current, reg_client, true)) {
                 app_manager_printf("client: %d deregistered event (%s)\n",
-                        reg_client, current->url);
+                                   reg_client, current->url);
             }
 
             // remove the registration if no client subscribe it
             if (current->subscribers == NULL) {
                 app_manager_printf("unregister for event deleted url:(%s)\n",
-                        current->url);
+                                   current->url);
                 if (pre)
                     pre->next = next;
                 else
@@ -139,33 +145,38 @@ bool am_unregister_event(const char *url, uint32_t reg_client)
     return true;
 }
 
-bool event_handle_event_request(uint8_t code, const char *event_url,
-        uint32_t reg_client)
+bool
+event_handle_event_request(uint8_t code, const char *event_url,
+                           uint32_t reg_client)
 {
     if (code == COAP_PUT) { /* register */
         return am_register_event(event_url, reg_client);
-    } else if (code == COAP_DELETE) { /* unregister */
+    }
+    else if (code == COAP_DELETE) { /* unregister */
         return am_unregister_event(event_url, reg_client);
-    } else {
+    }
+    else {
         /* invalid request */
         return false;
     }
 }
 
-void am_publish_event(request_t * event)
+void
+am_publish_event(request_t *event)
 {
     bh_assert(event->action == COAP_EVENT);
 
     event_reg_t *current = g_events;
     while (current) {
         if (0 == strcmp(event->url, current->url)) {
-            subscribe_t* c = current->subscribers;
+            subscribe_t *c = current->subscribers;
             while (c) {
                 if (c->subscriber_id == ID_HOST) {
                     send_request_to_host(event);
-                } else {
-                    module_request_handler
-                        (event, (void *)(uintptr_t)c->subscriber_id);
+                }
+                else {
+                    module_request_handler(event,
+                                           (void *)(uintptr_t)c->subscriber_id);
                 }
                 c = c->next;
             }
@@ -177,7 +188,8 @@ void am_publish_event(request_t * event)
     }
 }
 
-bool event_is_registered(const char *event_url)
+bool
+event_is_registered(const char *event_url)
 {
     event_reg_t *current = g_events;
 

+ 1 - 1
core/app-mgr/app-manager/event.h

@@ -22,7 +22,7 @@ extern "C" {
  */
 bool
 event_handle_event_request(uint8_t code, const char *event_url,
-        uint32_t register);
+                           uint32_t register);
 
 /**
  * Test whether the event is registered

+ 10 - 8
core/app-mgr/app-manager/message.c

@@ -26,7 +26,8 @@ bool send_coap_packet_to_host(coap_packet_t * packet)
 }
 #endif
 
-bool send_request_to_host(request_t *msg)
+bool
+send_request_to_host(request_t *msg)
 {
     if (COAP_EVENT == msg->action && !event_is_registered(msg->url)) {
         app_manager_printf("Event is not registered\n");
@@ -34,7 +35,7 @@ bool send_request_to_host(request_t *msg)
     }
 
     int size;
-    char * packet = pack_request(msg, &size);
+    char *packet = pack_request(msg, &size);
     if (packet == NULL)
         return false;
 
@@ -45,10 +46,11 @@ bool send_request_to_host(request_t *msg)
     return true;
 }
 
-bool send_response_to_host(response_t *response)
+bool
+send_response_to_host(response_t *response)
 {
     int size;
-    char * packet = pack_response(response, &size);
+    char *packet = pack_response(response, &size);
     if (packet == NULL)
         return false;
 
@@ -59,7 +61,8 @@ bool send_response_to_host(response_t *response)
     return true;
 }
 
-bool send_error_response_to_host(int mid, int status, const char *msg)
+bool
+send_error_response_to_host(int mid, int status, const char *msg)
 {
     int payload_len = 0;
     attr_container_t *payload = NULL;
@@ -73,8 +76,8 @@ bool send_error_response_to_host(int mid, int status, const char *msg)
         }
     }
 
-    set_response(response, status, FMT_ATTR_CONTAINER,
-                 (const char *)payload, payload_len);
+    set_response(response, status, FMT_ATTR_CONTAINER, (const char *)payload,
+                 payload_len);
     response->mid = mid;
 
     send_response_to_host(response);
@@ -83,4 +86,3 @@ bool send_error_response_to_host(int mid, int status, const char *msg)
         attr_container_destroy(payload);
     return true;
 }
-

+ 1351 - 1201
core/app-mgr/app-manager/module_jeff.c

@@ -45,7 +45,7 @@ typedef struct jeff_applet_data {
     JeffFileHeaderLinked *main_file;
     /* Permissions of the Java Applet */
     char *perms;
-}jeff_applet_data;
+} jeff_applet_data;
 
 /* Jeff class com.intel.aee.AEEApplet */
 static JeffClassHeaderLinked *class_AEEApplet;
@@ -113,9 +113,8 @@ app_manager_get_tool_agent_queue()
 static bool
 is_tool_agent_running(module_data *m_data)
 {
-    jeff_applet_data *applet_data = (jeff_applet_data*)m_data->internal_data;
-    return (applet_data->debug_mode
-            && applet_data->tool_agent_queue
+    jeff_applet_data *applet_data = (jeff_applet_data *)m_data->internal_data;
+    return (applet_data->debug_mode && applet_data->tool_agent_queue
             && applet_data->vm_instance->tool_agent);
 }
 #endif
@@ -123,12 +122,12 @@ is_tool_agent_running(module_data *m_data)
 static char *
 get_class_qname(const JeffString *pname, const JeffString *cname)
 {
-    unsigned int length = pname->length ? pname->length + 2 + cname->length
-    : cname->length + 1;
+    unsigned int length =
+        pname->length ? pname->length + 2 + cname->length : cname->length + 1;
     char *buf = APP_MGR_MALLOC(length), *p;
 
     if (!buf)
-    return NULL;
+        return NULL;
 
     p = buf;
     if (pname->length) {
@@ -159,8 +158,8 @@ send_exception_event_to_host(const char *applet_name, const char *exc_name)
     }
 
     if (!attr_container_set_string(&payload, "exception name", exc_name)
-            || !attr_container_set_string(&payload, "stack trace", "TODO")
-            || !attr_container_set_string(&payload, "applet name", applet_name)) {
+        || !attr_container_set_string(&payload, "stack trace", "TODO")
+        || !attr_container_set_string(&payload, "applet name", applet_name)) {
         app_manager_printf("Send exception to host fail: set attr");
         goto fail;
     }
@@ -184,7 +183,7 @@ send_exception_event_to_host(const char *applet_name, const char *exc_name)
 
     APP_MGR_FREE(url);
 
-    fail:
+fail:
     attr_container_destroy(payload);
 }
 
@@ -193,1541 +192,1692 @@ check_exception()
 {
     if (jeff_runtime_get_exception()) {
         jeff_printf("V1.Exception thrown when running applet '%s':\n",
-                app_manager_get_module_name(Module_Jeff));
+                    app_manager_get_module_name(Module_Jeff));
         jeff_runtime_print_exception();
         jeff_printf("\n");
         jeff_printf(NULL);
+    }
 
-        if (!app_manager_is_interrupting_module(Module_Jeff)) {
-            attr_container_t *payload;
-            int payload_len;
-            JeffClassHeaderLinked *exc_class = jeff_object_class_pointer(jeff_runtime_get_exception());
-            char *qname_buf = get_class_qname(jeff_get_class_pname(exc_class),
-                    jeff_get_class_cname(exc_class));
-
-            /* Send exception event to host */
-            if (qname_buf) {
-                send_exception_event_to_host(app_manager_get_module_name(Module_Jeff), qname_buf);
-                APP_MGR_FREE(qname_buf);
-            }
-
-            /* Uninstall the applet */
-            if ((payload = attr_container_create("uninstall myself"))) {
-                if (attr_container_set_string(&payload, "name", app_manager_get_module_name(Module_Jeff))
-                        /* Set special flag to prevent app manager making response since this is an internal message */
-                        && attr_container_set_bool(&payload, "do not reply me", true)) {
-                    request_t request = {0};
-                    payload_len = attr_container_get_serialize_length(payload);
+    if (!app_manager_is_interrupting_module(Module_Jeff)) {
+        attr_container_t *payload;
+        int payload_len;
+        JeffClassHeaderLinked *exc_class =
+            jeff_object_class_pointer(jeff_runtime_get_exception());
+        char *qname_buf = get_class_qname(jeff_get_class_pname(exc_class),
+                                          jeff_get_class_cname(exc_class));
+
+        /* Send exception event to host */
+        if (qname_buf) {
+            send_exception_event_to_host(
+                app_manager_get_module_name(Module_Jeff), qname_buf);
+            APP_MGR_FREE(qname_buf);
+        }
+
+        /* Uninstall the applet */
+        if ((payload = attr_container_create("uninstall myself"))) {
+            if (attr_container_set_string(
+                    &payload, "name", app_manager_get_module_name(Module_Jeff))
+                /* Set special flag to prevent app manager making response
+                   since this is an internal message */
+                && attr_container_set_bool(&payload, "do not reply me", true)) {
+                request_t request = { 0 };
+                payload_len = attr_container_get_serialize_length(payload);
 
                     init_request(request, "/applet", COAP_DELETE, (char *)payload, payload_len));
                     app_mgr_lookup_resource(&request);
 
                     // TODO: confirm this is right
                     attr_container_destroy(payload);
-                }
             }
-
-            jeff_runtime_set_exception(NULL);
-            return true;
         }
 
-        return false;
+        jeff_runtime_set_exception(NULL);
+        return true;
     }
 
-    static bool
-    app_manager_initialize_class(JeffClassHeaderLinked *c)
-    {
-        jeff_runtime_initialize_class(c);
-        return !check_exception();
-    }
+    return false;
+}
 
-    static bool
-    app_manager_initialize_object(JeffObjectRef obj)
-    {
-        jeff_runtime_initialize_object(obj);
-        return !check_exception();
-    }
+static bool
+app_manager_initialize_class(JeffClassHeaderLinked *c)
+{
+    jeff_runtime_initialize_class(c);
+    return !check_exception();
+}
+
+static bool
+app_manager_initialize_object(JeffObjectRef obj)
+{
+    jeff_runtime_initialize_object(obj);
+    return !check_exception();
+}
 
-    static bool
-    app_manager_call_java(JeffMethodLinked *method,
-    unsigned int argc, uint32 argv[], uint8 argt[])
-    {
-        module_data *m_data = app_manager_get_module_data(Module_Jeff);
-        watchdog_timer *wd_timer = &m_data->wd_timer;
-        bool is_wd_started = false;
+static bool
+app_manager_call_java(JeffMethodLinked *method, unsigned int argc,
+                      uint32 argv[], uint8 argt[])
+{
+    module_data *m_data = app_manager_get_module_data(Module_Jeff);
+    watchdog_timer *wd_timer = &m_data->wd_timer;
+    bool is_wd_started = false;
 
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
-        /* Only start watchdog when debugger is not running */
-        if (!is_tool_agent_running(m_data)) {
+    /* Only start watchdog when debugger is not running */
+    if (!is_tool_agent_running(m_data)) {
 #endif
-            watchdog_timer_start(wd_timer);
-            is_wd_started = true;
+        watchdog_timer_start(wd_timer);
+        is_wd_started = true;
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
-        }
+    }
 #endif
 
-        jeff_runtime_call_java(method, argc, argv, argt);
+    jeff_runtime_call_java(method, argc, argv, argt);
 
-        if (is_wd_started) {
-            os_mutex_lock(&wd_timer->lock);
-            if (!wd_timer->is_interrupting) {
-                wd_timer->is_stopped = true;
-                watchdog_timer_stop(wd_timer);
-            }
-            os_mutex_unlock(&wd_timer->lock);
+    if (is_wd_started) {
+        os_mutex_lock(&wd_timer->lock);
+        if (!wd_timer->is_interrupting) {
+            wd_timer->is_stopped = true;
+            watchdog_timer_stop(wd_timer);
         }
-
-        return !check_exception();
+        os_mutex_unlock(&wd_timer->lock);
     }
 
-    static AEEBLEDevice
-    create_object_BLEDevice(ble_device_info *dev_info)
-    {
-        JeffLocalObjectRef ref;
-        AEEBLEDevice dev_struct;
-
-        jeff_runtime_push_local_object_ref(&ref);
-
-        ref.val = jeff_runtime_new_object(class_BLEDevice);
+    return !check_exception();
+}
 
-        if (!ref.val) {
-            jeff_runtime_pop_local_object_ref(1);
-            return NULL;
-        }
+static AEEBLEDevice
+create_object_BLEDevice(ble_device_info *dev_info)
+{
+    JeffLocalObjectRef ref;
+    AEEBLEDevice dev_struct;
 
-        dev_struct = (AEEBLEDevice) (ref.val);
-        dev_struct->rssi = dev_info->rssi;
-        dev_struct->mac = (jbyteArray) jeff_runtime_create_byte_array((int8 *)dev_info->mac, 6);
+    jeff_runtime_push_local_object_ref(&ref);
 
-        app_manager_printf("adv_data_len:%d,scan_response_len:%d\n", dev_info->adv_data_len, dev_info->scan_response_len);
+    ref.val = jeff_runtime_new_object(class_BLEDevice);
 
-        dev_struct->advData = (jbyteArray) jeff_runtime_create_byte_array((int8 *)dev_info->adv_data, dev_info->adv_data_len);
-        dev_struct->scanResponse = (jbyteArray) jeff_runtime_create_byte_array((int8 *)dev_info->scan_response, dev_info->scan_response_len);
-        dev_struct->addressType = dev_info->address_type;
-        jeff_runtime_initialize_object(ref.val);
+    if (!ref.val) {
         jeff_runtime_pop_local_object_ref(1);
-        if ((dev_struct->mac == NULL) || (dev_struct->advData == NULL) || (dev_struct->scanResponse == NULL)) {
-            return NULL;
-        }
-        return (AEEBLEDevice) ref.val;
+        return NULL;
     }
 
-    static void
-    app_instance_process_ble_msg(char *msg)
-    {
-        bh_queue_ble_sub_msg_t *ble_msg = (bh_queue_ble_sub_msg_t *)msg;
-        unsigned int argv[5];
-        uint8 argt[5];
-
-        ble_device_info *dev_info;
-
-        dev_info = (ble_device_info *) ble_msg->payload;
-        AEEBLEDevice ble_dev;
+    dev_struct = (AEEBLEDevice)(ref.val);
+    dev_struct->rssi = dev_info->rssi;
+    dev_struct->mac =
+        (jbyteArray)jeff_runtime_create_byte_array((int8 *)dev_info->mac, 6);
+
+    app_manager_printf("adv_data_len:%d,scan_response_len:%d\n",
+                       dev_info->adv_data_len, dev_info->scan_response_len);
+
+    dev_struct->advData = (jbyteArray)jeff_runtime_create_byte_array(
+        (int8 *)dev_info->adv_data, dev_info->adv_data_len);
+    dev_struct->scanResponse = (jbyteArray)jeff_runtime_create_byte_array(
+        (int8 *)dev_info->scan_response, dev_info->scan_response_len);
+    dev_struct->addressType = dev_info->address_type;
+    jeff_runtime_initialize_object(ref.val);
+    jeff_runtime_pop_local_object_ref(1);
+    if ((dev_struct->mac == NULL) || (dev_struct->advData == NULL)
+        || (dev_struct->scanResponse == NULL)) {
+        return NULL;
+    }
+    return (AEEBLEDevice)ref.val;
+}
 
-        argv[0] = (unsigned int) (jbyteArray) jeff_runtime_create_byte_array((int8 *)dev_info->mac, 6);
-        argt[0] = 1;
-        if (!app_manager_call_java(method_callOnBLEManagerGetBLEDevice, 1, argv, argt)) {
-            app_manager_printf("app_manager_call_java BLEManagerGetBLEDevice fail error\n");
+static void
+app_instance_process_ble_msg(char *msg)
+{
+    bh_queue_ble_sub_msg_t *ble_msg = (bh_queue_ble_sub_msg_t *)msg;
+    unsigned int argv[5];
+    uint8 argt[5];
+
+    ble_device_info *dev_info;
+
+    dev_info = (ble_device_info *)ble_msg->payload;
+    AEEBLEDevice ble_dev;
+
+    argv[0] = (unsigned int)(jbyteArray)jeff_runtime_create_byte_array(
+        (int8 *)dev_info->mac, 6);
+    argt[0] = 1;
+    if (!app_manager_call_java(method_callOnBLEManagerGetBLEDevice, 1, argv,
+                               argt)) {
+        app_manager_printf(
+            "app_manager_call_java BLEManagerGetBLEDevice fail error\n");
+        goto fail;
+    }
+    ble_dev = (AEEBLEDevice)argv[0];
+    if (ble_dev == NULL) {
+        ble_dev = create_object_BLEDevice(dev_info);
+        if (ble_dev == NULL) {
             goto fail;
         }
-        ble_dev = (AEEBLEDevice) argv[0];
-        if (ble_dev == NULL) {
-            ble_dev = create_object_BLEDevice(dev_info);
-            if (ble_dev == NULL) {
+    }
+
+    switch (ble_msg->type) {
+        case BLE_SUB_EVENT_DISCOVERY:
+        {
+            argv[0] = (unsigned int)ble_dev;
+            argt[0] = 1;
+            ble_dev->rssi = dev_info->rssi;
+            if (!app_manager_call_java(method_callOnBLEStartDiscovery, 1, argv,
+                                       argt)) {
+                app_manager_printf(
+                    "app_manager_call_java method_callOnBLEStartDiscovery "
+                    "fail error\n");
                 goto fail;
             }
+            break;
         }
 
-        switch (ble_msg->type) {
-            case BLE_SUB_EVENT_DISCOVERY:
-            {
-                argv[0] = (unsigned int) ble_dev;
+        case BLE_SUB_EVENT_CONNECTED:
+        {
+            if (ble_dev) {
+                argv[0] = (unsigned int)ble_dev;
+                argv[1] = 0;
                 argt[0] = 1;
-                ble_dev->rssi = dev_info->rssi;
-                if (!app_manager_call_java(method_callOnBLEStartDiscovery, 1, argv, argt)) {
-                    app_manager_printf("app_manager_call_java method_callOnBLEStartDiscovery fail error\n");
+                argt[1] = 1;
+                if (!app_manager_call_java(method_callOnBLEConnected, 2, argv,
+                                           argt)) {
+                    app_manager_printf(
+                        "app_manager_call_java method_callOnBLEConnected "
+                        "fail error\n");
                     goto fail;
                 }
             }
             break;
+        }
 
-            case BLE_SUB_EVENT_CONNECTED:
-            {
-                if (ble_dev) {
-                    argv[0] = (unsigned int) ble_dev;
-                    argv[1] = 0;
-                    argt[0] = 1;
-                    argt[1] = 1;
-                    if (!app_manager_call_java(method_callOnBLEConnected, 2, argv, argt)) {
-                        app_manager_printf("app_manager_call_java method_callOnBLEConnected fail error\n");
-                        goto fail;
-                    }
-                }
-            }
-            break;
-
-            case BLE_SUB_EVENT_DISCONNECTED:
-            {
-                app_manager_printf("app instance received disconnected\n");
+        case BLE_SUB_EVENT_DISCONNECTED:
+        {
+            app_manager_printf("app instance received disconnected\n");
 
-                if (ble_dev) {
-                    argv[0] = (unsigned int) ble_dev;
-                    argv[1] = 0;
-                    argt[0] = 1;
-                    argt[1] = 1;
-                    ble_dev->rssi = dev_info->rssi;
-                    if (!app_manager_call_java(method_callOnBLEDisconnected, 2, argv, argt)) {
-                        app_manager_printf("app_manager_call_java method_callOnBLEDisconnected fail error\n");
-                        goto fail;
-                    }
+            if (ble_dev) {
+                argv[0] = (unsigned int)ble_dev;
+                argv[1] = 0;
+                argt[0] = 1;
+                argt[1] = 1;
+                ble_dev->rssi = dev_info->rssi;
+                if (!app_manager_call_java(method_callOnBLEDisconnected, 2,
+                                           argv, argt)) {
+                    app_manager_printf(
+                        "app_manager_call_java "
+                        "method_callOnBLEDisconnected fail error\n");
+                    goto fail;
                 }
             }
             break;
+        }
 
-            case BLE_SUB_EVENT_NOTIFICATION:
-            {
-                if (ble_dev) {
-                    argv[0] = (unsigned int) ble_dev;
-                    argv[1] = (unsigned int) (jbyteArray) jeff_runtime_create_byte_array(
-                    (int8 *)dev_info->private_data, dev_info->private_data_length);
-                    argv[2] = dev_info->value_handle;
-                    argv[3] = dev_info->ccc_handle;
-                    argt[1] = 1;
-                    argt[2] = 0;
-                    argt[3] = 0;
-                    ble_dev->rssi = dev_info->rssi;
-                    if (!app_manager_call_java(method_callOnBLENotification, 4, argv, argt)) {
-                        app_manager_printf("app_manager_call_java method_callOnBLENotification fail error\n");
-                        goto fail;
-                    }
+        case BLE_SUB_EVENT_NOTIFICATION:
+        {
+            if (ble_dev) {
+                argv[0] = (unsigned int)ble_dev;
+                argv[1] =
+                    (unsigned int)(jbyteArray)jeff_runtime_create_byte_array(
+                        (int8 *)dev_info->private_data,
+                        dev_info->private_data_length);
+                argv[2] = dev_info->value_handle;
+                argv[3] = dev_info->ccc_handle;
+                argt[1] = 1;
+                argt[2] = 0;
+                argt[3] = 0;
+                ble_dev->rssi = dev_info->rssi;
+                if (!app_manager_call_java(method_callOnBLENotification, 4,
+                                           argv, argt)) {
+                    app_manager_printf(
+                        "app_manager_call_java "
+                        "method_callOnBLENotification fail error\n");
+                    goto fail;
                 }
             }
             break;
+        }
 
-            case BLE_SUB_EVENT_INDICATION:
-            {
-                if (ble_dev) {
-                    argv[0] = (unsigned int) ble_dev;
-                    argv[1] = (unsigned int) (jbyteArray) jeff_runtime_create_byte_array(
-                    (int8 *)dev_info->private_data, dev_info->private_data_length);
-                    argv[2] = dev_info->value_handle;
-                    argv[3] = dev_info->ccc_handle;
-                    argt[0] = 1;
-                    argt[1] = 1;
-                    argt[2] = 0;
-                    argt[3] = 0;
-                    ble_dev->rssi = dev_info->rssi;
-                    if (!app_manager_call_java(method_callOnBLEIndication, 4, argv, argt)) {
-                        app_manager_printf("app_manager_call_java method_callOnBLEIndication fail error\n");
-                        goto fail;
-                    }
+        case BLE_SUB_EVENT_INDICATION:
+        {
+            if (ble_dev) {
+                argv[0] = (unsigned int)ble_dev;
+                argv[1] =
+                    (unsigned int)(jbyteArray)jeff_runtime_create_byte_array(
+                        (int8 *)dev_info->private_data,
+                        dev_info->private_data_length);
+                argv[2] = dev_info->value_handle;
+                argv[3] = dev_info->ccc_handle;
+                argt[0] = 1;
+                argt[1] = 1;
+                argt[2] = 0;
+                argt[3] = 0;
+                ble_dev->rssi = dev_info->rssi;
+                if (!app_manager_call_java(method_callOnBLEIndication, 4, argv,
+                                           argt)) {
+                    app_manager_printf(
+                        "app_manager_call_java method_callOnBLEIndication "
+                        "fail error\n");
+                    goto fail;
                 }
             }
             break;
+        }
 
-            case BLE_SUB_EVENT_PASSKEYENTRY:
-            {
+        case BLE_SUB_EVENT_PASSKEYENTRY:
+        {
 
-                if (ble_dev) {
-                    argv[0] = (unsigned int) ble_dev;
-                    argt[0] = 1;
-                    argt[1] = 1;
-                    ble_dev->rssi = dev_info->rssi;
-                    if (!app_manager_call_java(method_callOnBLEPasskeyEntry, 1, argv, argt)) {
-                        app_manager_printf("app_manager_call_java method_callOnBLEPasskeyEntry fail error\n");
-                        goto fail;
-                    }
+            if (ble_dev) {
+                argv[0] = (unsigned int)ble_dev;
+                argt[0] = 1;
+                argt[1] = 1;
+                ble_dev->rssi = dev_info->rssi;
+                if (!app_manager_call_java(method_callOnBLEPasskeyEntry, 1,
+                                           argv, argt)) {
+                    app_manager_printf(
+                        "app_manager_call_java "
+                        "method_callOnBLEPasskeyEntry fail error\n");
+                    goto fail;
                 }
             }
             break;
+        }
 
-            case BLE_SUB_EVENT_SECURITY_LEVEL_CHANGE:
-            {
-                if (ble_dev) {
-                    ble_dev->securityLevel = dev_info->security_level;
-                }
+        case BLE_SUB_EVENT_SECURITY_LEVEL_CHANGE:
+        {
+            if (ble_dev) {
+                ble_dev->securityLevel = dev_info->security_level;
             }
             break;
-
-            default:
-            break;
         }
 
-        fail:
-        if (dev_info->scan_response != NULL) {
-            APP_MGR_FREE(dev_info->scan_response);
-        }
-        if (dev_info->private_data != NULL) {
-            APP_MGR_FREE(dev_info->private_data);
-        }
+        default:
+            break;
+    }
 
-        if (dev_info->adv_data != NULL) {
-            APP_MGR_FREE(dev_info->adv_data);
-        }
-        if (dev_info != NULL) {
-            APP_MGR_FREE(dev_info);
-        }
+fail:
+    if (dev_info->scan_response != NULL) {
+        APP_MGR_FREE(dev_info->scan_response);
+    }
+    if (dev_info->private_data != NULL) {
+        APP_MGR_FREE(dev_info->private_data);
+    }
 
+    if (dev_info->adv_data != NULL) {
+        APP_MGR_FREE(dev_info->adv_data);
+    }
+    if (dev_info != NULL) {
+        APP_MGR_FREE(dev_info);
     }
+}
 
-    static void
-    app_instance_free_ble_msg(char *msg)
-    {
-        bh_queue_ble_sub_msg_t *ble_msg = (bh_queue_ble_sub_msg_t *)msg;
-        ble_device_info *dev_info;
+static void
+app_instance_free_ble_msg(char *msg)
+{
+    bh_queue_ble_sub_msg_t *ble_msg = (bh_queue_ble_sub_msg_t *)msg;
+    ble_device_info *dev_info;
 
-        dev_info = (ble_device_info *) ble_msg->payload;
+    dev_info = (ble_device_info *)ble_msg->payload;
 
-        if (dev_info->scan_response != NULL)
+    if (dev_info->scan_response != NULL)
         APP_MGR_FREE(dev_info->scan_response);
 
-        if (dev_info->private_data != NULL)
+    if (dev_info->private_data != NULL)
         APP_MGR_FREE(dev_info->private_data);
 
-        if (dev_info->adv_data != NULL)
+    if (dev_info->adv_data != NULL)
         APP_MGR_FREE(dev_info->adv_data);
 
-        if (dev_info != NULL)
+    if (dev_info != NULL)
         APP_MGR_FREE(dev_info);
-    }
-
-    static void
-    app_instance_queue_free_callback(void *queue_msg)
-    {
-        bh_queue_msg_t *msg = (bh_queue_msg_t *)queue_msg;
+}
 
-        switch (msg->message_type) {
-            case APPLET_REQUEST:
-            {
-                bh_request_msg_t *req_msg = (bh_request_msg_t *)msg->payload;
-                APP_MGR_FREE(req_msg);
-                break;
-            }
+static void
+app_instance_queue_free_callback(void *queue_msg)
+{
+    bh_queue_msg_t *msg = (bh_queue_msg_t *)queue_msg;
 
-            case TIMER_EVENT:
-            {
-                break;
-            }
+    switch (msg->message_type) {
+        case APPLET_REQUEST:
+        {
+            bh_request_msg_t *req_msg = (bh_request_msg_t *)msg->payload;
+            APP_MGR_FREE(req_msg);
+            break;
+        }
 
-            case SENSOR_EVENT:
-            {
-                if (msg->payload) {
-                    bh_sensor_event_t *sensor_event = (bh_sensor_event_t *)msg->payload;
-                    attr_container_t *event = sensor_event->event;
+        case TIMER_EVENT:
+        {
+            break;
+        }
 
-                    attr_container_destroy(event);
-                    APP_MGR_FREE(sensor_event);
-                }
-                break;
-            }
+        case SENSOR_EVENT:
+        {
+            if (msg->payload) {
+                bh_sensor_event_t *sensor_event =
+                    (bh_sensor_event_t *)msg->payload;
+                attr_container_t *event = sensor_event->event;
 
-            case BLE_EVENT:
-            {
-                if (msg->payload) {
-                    app_instance_free_ble_msg(msg->payload);
-                    APP_MGR_FREE(msg->payload);
-                }
-                break;
+                attr_container_destroy(event);
+                APP_MGR_FREE(sensor_event);
             }
+            break;
+        }
 
-            case GPIO_INTERRUPT_EVENT:
-            {
-                break;
+        case BLE_EVENT:
+        {
+            if (msg->payload) {
+                app_instance_free_ble_msg(msg->payload);
+                APP_MGR_FREE(msg->payload);
             }
+            break;
+        }
 
-            default:
-            {
-                break;
-            }
+        case GPIO_INTERRUPT_EVENT:
+        {
+            break;
         }
 
-        APP_MGR_FREE(msg);
+        default:
+        {
+            break;
+        }
     }
 
-    static void
-    app_instance_queue_callback(void *queue_msg)
-    {
-        bh_queue_msg_t *msg = (bh_queue_msg_t *)queue_msg;
-        unsigned int argv[5];
-        uint8 argt[5];
+    APP_MGR_FREE(msg);
+}
 
-        if (app_manager_is_interrupting_module(Module_Jeff)) {
-            app_instance_queue_free_callback(queue_msg);
-            return;
-        }
+static void
+app_instance_queue_callback(void *queue_msg)
+{
+    bh_queue_msg_t *msg = (bh_queue_msg_t *)queue_msg;
+    unsigned int argv[5];
+    uint8 argt[5];
 
-        switch (msg->message_type) {
-            case APPLET_REQUEST:
-            {
-                JeffLocalObjectRef ref;
-                AEERequest req_obj;
-                bh_request_msg_t *req_msg = (bh_request_msg_t *)msg->payload;
-                attr_container_t *attr_cont = (attr_container_t *)req_msg->payload;
-                module_data *m_data = app_manager_get_module_data(Module_Jeff);
-                jeff_applet_data *applet_data = (jeff_applet_data*)m_data->internal_data;
-
-                app_manager_printf("Applet %s got request, url %s, action %d\n",
-                m_data->module_name, req_msg->url, req_msg->action);
-
-                /* Create Request object */
-                req_obj = (AEERequest)jeff_object_new(m_data->heap, class_AEERequest);
-                if (!req_obj) {
-                    app_manager_printf("Applet process request failed: create request obj failed.\n");
-                    goto fail1;
-                }
+    if (app_manager_is_interrupting_module(Module_Jeff)) {
+        app_instance_queue_free_callback(queue_msg);
+        return;
+    }
 
-                jeff_runtime_push_local_object_ref(&ref);
-                ref.val = (JeffObjectRef)req_obj;
+    switch (msg->message_type) {
+        case APPLET_REQUEST:
+        {
+            JeffLocalObjectRef ref;
+            AEERequest req_obj;
+            bh_request_msg_t *req_msg = (bh_request_msg_t *)msg->payload;
+            attr_container_t *attr_cont = (attr_container_t *)req_msg->payload;
+            module_data *m_data = app_manager_get_module_data(Module_Jeff);
+            jeff_applet_data *applet_data =
+                (jeff_applet_data *)m_data->internal_data;
+
+            app_manager_printf("Applet %s got request, url %s, action %d\n",
+                               m_data->module_name, req_msg->url,
+                               req_msg->action);
+
+            /* Create Request object */
+            req_obj =
+                (AEERequest)jeff_object_new(m_data->heap, class_AEERequest);
+            if (!req_obj) {
+                app_manager_printf("Applet process request failed: create "
+                                   "request obj failed.\n");
+                goto fail1;
+            }
 
-                req_obj->mid = req_msg->mid;
-                req_obj->action = req_msg->action;
-                req_obj->fmt = req_msg->fmt;
+            jeff_runtime_push_local_object_ref(&ref);
+            ref.val = (JeffObjectRef)req_obj;
 
-                /* Create Java url string */
-                if (req_msg->url) {
-                    req_obj->url = (jstring)jeff_runtime_create_java_string(req_msg->url);
-                    if (!req_obj->url) {
-                        app_manager_printf("Applet process request failed: create url string failed.\n");
-                        goto fail2;
-                    }
-                }
+            req_obj->mid = req_msg->mid;
+            req_obj->action = req_msg->action;
+            req_obj->fmt = req_msg->fmt;
 
-                /* Create Java AttributeObject payload */
-                if (attr_cont
-                && !attr_container_to_attr_obj(attr_cont, &req_obj->payload)) {
-                    app_manager_printf("Applet process request failed: convert payload failed.\n");
+            /* Create Java url string */
+            if (req_msg->url) {
+                req_obj->url =
+                    (jstring)jeff_runtime_create_java_string(req_msg->url);
+                if (!req_obj->url) {
+                    app_manager_printf("Applet process request failed: "
+                                       "create url string failed.\n");
                     goto fail2;
                 }
-
-                /* Call AEEApplet.callOnRequest(Request request) method  */
-                argv[0] = (unsigned int)applet_data->applet_obj;
-                argv[1] = (unsigned int)req_obj;
-                argt[0] = argt[1] = 1;
-                app_manager_call_java(method_AEEApplet_callOnRequest, 2, argv, argt);
-                app_manager_printf("Applet process request success.\n");
-
-                fail2:
-                jeff_runtime_pop_local_object_ref(1);
-                fail1:
-                APP_MGR_FREE(req_msg);
-                break;
             }
 
-            case TIMER_EVENT:
-            {
-                if (msg->payload) {
-                    /* Call Timer.callOnTimer() method */
-                    argv[0] = (unsigned int)msg->payload;
-                    argt[0] = 1;
-                    app_manager_call_java(method_callOnTimer, 1, argv, argt);
-                }
-                break;
+            /* Create Java AttributeObject payload */
+            if (attr_cont
+                && !attr_container_to_attr_obj(attr_cont, &req_obj->payload)) {
+                app_manager_printf("Applet process request failed: convert "
+                                   "payload failed.\n");
+                goto fail2;
             }
 
-            case SENSOR_EVENT:
-            {
-                if (msg->payload) {
-                    bh_sensor_event_t *sensor_event = (bh_sensor_event_t *)msg->payload;
-                    AEESensor sensor = sensor_event->sensor;
-                    attr_container_t *event = sensor_event->event;
-                    bool ret = attr_container_to_attr_obj(event, &sensor->event);
-
-                    attr_container_destroy(event);
-                    APP_MGR_FREE(sensor_event);
-
-                    if (ret) {
-                        /* Call Sensor.callOnSensorEvent() method */
-                        argv[0] = (unsigned int)sensor;
-                        argt[0] = 1;
-                        app_manager_call_java(method_callOnSensorEvent, 1, argv, argt);
-                    }
-                }
-                break;
-            }
+            /* Call AEEApplet.callOnRequest(Request request) method  */
+            argv[0] = (unsigned int)applet_data->applet_obj;
+            argv[1] = (unsigned int)req_obj;
+            argt[0] = argt[1] = 1;
+            app_manager_call_java(method_AEEApplet_callOnRequest, 2, argv,
+                                  argt);
+            app_manager_printf("Applet process request success.\n");
 
-            case BLE_EVENT:
-            {
-                if (msg->payload) {
-                    app_instance_process_ble_msg(msg->payload);
-                    APP_MGR_FREE(msg->payload);
-                }
-                break;
+        fail2:
+            jeff_runtime_pop_local_object_ref(1);
+        fail1:
+            APP_MGR_FREE(req_msg);
+            break;
+        }
+
+        case TIMER_EVENT:
+        {
+            if (msg->payload) {
+                /* Call Timer.callOnTimer() method */
+                argv[0] = (unsigned int)msg->payload;
+                argt[0] = 1;
+                app_manager_call_java(method_callOnTimer, 1, argv, argt);
             }
+            break;
+        }
 
-            case GPIO_INTERRUPT_EVENT:
-            {
-                AEEGPIOChannel gpio_ch = (AEEGPIOChannel)msg->payload;
+        case SENSOR_EVENT:
+        {
+            if (msg->payload) {
+                bh_sensor_event_t *sensor_event =
+                    (bh_sensor_event_t *)msg->payload;
+                AEESensor sensor = sensor_event->sensor;
+                attr_container_t *event = sensor_event->event;
+                bool ret = attr_container_to_attr_obj(event, &sensor->event);
 
-                if ((gpio_ch == NULL) || (gpio_ch->callback == 0) || (gpio_ch->listener == NULL)) {
-                    break;
-                }
-                argv[0] = (unsigned int) gpio_ch;
-                argt[0] = 1;
-                bool ret_value = app_manager_call_java(method_callOnGPIOInterrupt, 1, argv, argt);
+                attr_container_destroy(event);
+                APP_MGR_FREE(sensor_event);
 
-                if (!ret_value) {
-                    app_manager_printf("app_manager_call_java method_method_callOnGPIOInterrupt return false\n");
+                if (ret) {
+                    /* Call Sensor.callOnSensorEvent() method */
+                    argv[0] = (unsigned int)sensor;
+                    argt[0] = 1;
+                    app_manager_call_java(method_callOnSensorEvent, 1, argv,
+                                          argt);
                 }
-                break;
             }
+            break;
+        }
+
+        case BLE_EVENT:
+        {
+            if (msg->payload) {
+                app_instance_process_ble_msg(msg->payload);
+                APP_MGR_FREE(msg->payload);
+            }
+            break;
+        }
 
-            default:
-            {
-                app_manager_printf("Invalid message type of applet queue message.\n");
+        case GPIO_INTERRUPT_EVENT:
+        {
+            AEEGPIOChannel gpio_ch = (AEEGPIOChannel)msg->payload;
+
+            if ((gpio_ch == NULL) || (gpio_ch->callback == 0)
+                || (gpio_ch->listener == NULL)) {
                 break;
             }
+            argv[0] = (unsigned int)gpio_ch;
+            argt[0] = 1;
+            bool ret_value = app_manager_call_java(method_callOnGPIOInterrupt,
+                                                   1, argv, argt);
+
+            if (!ret_value) {
+                app_manager_printf(
+                    "app_manager_call_java "
+                    "method_method_callOnGPIOInterrupt return false\n");
+            }
+            break;
         }
 
-        APP_MGR_FREE(msg);
+        default:
+        {
+            app_manager_printf(
+                "Invalid message type of applet queue message.\n");
+            break;
+        }
     }
 
-    static JeffClassHeaderLinked*
-    find_main_class(JeffFileHeaderLinked *main_file)
-    {
-        JeffClassHeaderLinked *c = NULL, *ci;
-        unsigned int i;
+    APP_MGR_FREE(msg);
+}
 
-        for (i = 0; i < main_file->internal_class_count; i++) {
-            ci = main_file->class_header[i];
+static JeffClassHeaderLinked *
+find_main_class(JeffFileHeaderLinked *main_file)
+{
+    JeffClassHeaderLinked *c = NULL, *ci;
+    unsigned int i;
 
-            if (jeff_is_super_class(class_AEEApplet, ci)
-            && (ci->access_flag & JEFF_ACC_PUBLIC)) {
-                if (c) {
-                    jeff_printe_more_than_one_main_class();
-                    return NULL;
-                }
+    for (i = 0; i < main_file->internal_class_count; i++) {
+        ci = main_file->class_header[i];
 
-                c = ci;
+        if (jeff_is_super_class(class_AEEApplet, ci)
+            && (ci->access_flag & JEFF_ACC_PUBLIC)) {
+            if (c) {
+                jeff_printe_more_than_one_main_class();
+                return NULL;
             }
+
+            c = ci;
         }
+    }
 
-        if (!c)
+    if (!c)
         jeff_printe_no_main_class();
 
-        return c;
-    }
+    return c;
+}
 
-    /* Java applet thread main routine */
-    static void*
-    app_instance_main(void *arg)
-    {
-        module_data *m_data = (module_data *)arg;
-        jeff_applet_data *applet_data = (jeff_applet_data*)m_data->internal_data;
-        JeffClassHeaderLinked *object_class;
-        JeffMethodLinked *m;
-        unsigned int argv[1];
-        uint8 argt[1];
+/* Java applet thread main routine */
+static void *
+app_instance_main(void *arg)
+{
+    module_data *m_data = (module_data *)arg;
+    jeff_applet_data *applet_data = (jeff_applet_data *)m_data->internal_data;
+    JeffClassHeaderLinked *object_class;
+    JeffMethodLinked *m;
+    unsigned int argv[1];
+    uint8 argt[1];
 
-        app_manager_printf("Java Applet '%s' started\n", m_data->module_name);
+    app_manager_printf("Java Applet '%s' started\n", m_data->module_name);
 
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
-        if (applet_data->debug_mode)
+    if (applet_data->debug_mode)
         jeff_tool_suspend_self();
 #endif
 
-        applet_data->vm_instance->applet_object = applet_data->applet_obj;
-        object_class = jeff_object_class_pointer(applet_data->applet_obj);
-        m = jeff_select_method_virtual(object_class, method_AEEApplet_onInit);
-        bh_assert(m != NULL);
-        /* Initialize applet class which call <clinit> */
-        if (!app_manager_initialize_class(object_class)) {
-            app_manager_printf("Call <clinit> fail\n");
-            goto fail;
-        }
+    applet_data->vm_instance->applet_object = applet_data->applet_obj;
+    object_class = jeff_object_class_pointer(applet_data->applet_obj);
+    m = jeff_select_method_virtual(object_class, method_AEEApplet_onInit);
+    bh_assert(m != NULL);
+    /* Initialize applet class which call <clinit> */
+    if (!app_manager_initialize_class(object_class)) {
+        app_manager_printf("Call <clinit> fail\n");
+        goto fail;
+    }
 
-        /* Initialize applet object which call <init> */
-        if (!app_manager_initialize_object(applet_data->applet_obj)) {
-            app_manager_printf("Call <init> fail\n");
-            goto fail;
-        }
+    /* Initialize applet object which call <init> */
+    if (!app_manager_initialize_object(applet_data->applet_obj)) {
+        app_manager_printf("Call <init> fail\n");
+        goto fail;
+    }
 
-        /* Call applet's onInit() method */
-        argv[0] = (unsigned int)applet_data->applet_obj;
-        argt[0] = 1;
-        if (app_manager_call_java(m, 1, argv, argt))
-        /* Enter queue loop run to receive and process applet queue message */
+    /* Call applet's onInit() method */
+    argv[0] = (unsigned int)applet_data->applet_obj;
+    argt[0] = 1;
+    if (app_manager_call_java(m, 1, argv, argt))
+        /* Enter queue loop run to receive and process applet queue message
+         */
         bh_queue_enter_loop_run(m_data->queue, app_instance_queue_callback);
 
-        fail:
-        applet_data->vm_instance->applet_object = applet_data->applet_obj;
-        object_class = jeff_object_class_pointer(applet_data->applet_obj);
-        m = jeff_select_method_virtual(object_class, method_AEEApplet_onDestroy);
-        bh_assert(m != NULL);
-        /* Call User Applet or AEEApplet onDestroy() method */
-        app_manager_call_java(m, 1, argv, argt);
-        if (m != method_AEEApplet_onDestroy) {
-            /*If 'm' is user onDestroy, then Call AEEApplet.onDestroy() method*/
-            app_manager_call_java(method_AEEApplet_onDestroy, 1, argv, argt);
-        }
-        app_manager_printf("Applet instance main thread exit.\n");
-        return NULL;
+fail:
+    applet_data->vm_instance->applet_object = applet_data->applet_obj;
+    object_class = jeff_object_class_pointer(applet_data->applet_obj);
+    m = jeff_select_method_virtual(object_class, method_AEEApplet_onDestroy);
+    bh_assert(m != NULL);
+    /* Call User Applet or AEEApplet onDestroy() method */
+    app_manager_call_java(m, 1, argv, argt);
+    if (m != method_AEEApplet_onDestroy) {
+        /*If 'm' is user onDestroy, then Call AEEApplet.onDestroy() method*/
+        app_manager_call_java(method_AEEApplet_onDestroy, 1, argv, argt);
     }
+    app_manager_printf("Applet instance main thread exit.\n");
+    return NULL;
+}
 
-    static bool
-    verify_signature(JeffFileHeader *file, unsigned size)
-    {
-        uint8 *sig;
-        unsigned sig_size;
+static bool
+verify_signature(JeffFileHeader *file, unsigned size)
+{
+    uint8 *sig;
+    unsigned sig_size;
 
 #if BEIHAI_ENABLE_NO_SIGNATURE != 0
-        /* no signature */
-        if (file->file_signature == 0)
+    /* no signature */
+    if (file->file_signature == 0)
         return true;
 #endif
 
-        if (file->file_length != size
+    if (file->file_length != size
 #if BEIHAI_ENABLE_NO_SIGNATURE == 0
         || file->file_signature == 0
 #endif
         || file->file_signature >= file->file_length)
         return false;
 
-        sig = (uint8 *)file + file->file_signature;
-        sig_size = file->file_length - file->file_signature;
+    sig = (uint8 *)file + file->file_signature;
+    sig_size = file->file_length - file->file_signature;
 
-        if (0 == app_manager_signature_verify((uint8_t *)file, file->file_signature,
-                sig, sig_size))
+    if (0
+        == app_manager_signature_verify((uint8_t *)file, file->file_signature,
+                                        sig, sig_size))
         return false;
 
-        return true;
-    }
-
-    /* Install Java Applet */
-    static bool
-    jeff_module_install(bh_request_msg_t *msg)
-    {
-        unsigned int size, bpk_file_len, main_file_len, heap_size, timeout;
-        uint8 *bpk_file;
-        JeffFileHeaderLinked *main_file;
-        JeffClassHeaderLinked *main_class;
-        module_data *m_data;
-        jeff_applet_data *applet_data;
-        char *applet_name, *applet_perm;
-        attr_container_t *attr_cont;
-        bool debug = false;
-
-        /* Check url */
-        if (!msg->url
-        || strcmp(msg->url, "/applet") != 0) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: invalid url.");
-            return false;
-        }
+    return true;
+}
 
-        /* Check payload */
-        attr_cont = (attr_container_t *)msg->payload;
-        if (!attr_cont
-        || !(bpk_file = (uint8 *)
-                attr_container_get_as_bytearray(attr_cont, "bpk", &bpk_file_len))) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: invalid bpk file.");
-            return false;
-        }
+/* Install Java Applet */
+static bool
+jeff_module_install(bh_request_msg_t *msg)
+{
+    unsigned int size, bpk_file_len, main_file_len, heap_size, timeout;
+    uint8 *bpk_file;
+    JeffFileHeaderLinked *main_file;
+    JeffClassHeaderLinked *main_class;
+    module_data *m_data;
+    jeff_applet_data *applet_data;
+    char *applet_name, *applet_perm;
+    attr_container_t *attr_cont;
+    bool debug = false;
+
+    /* Check url */
+    if (!msg->url || strcmp(msg->url, "/applet") != 0) {
+        SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: invalid url.");
+        return false;
+    }
 
-        /* Check applet name */
-        applet_name = attr_container_get_as_string(attr_cont, "name");
+    /* Check payload */
+    attr_cont = (attr_container_t *)msg->payload;
+    if (!attr_cont
+        || !(bpk_file = (uint8 *)attr_container_get_as_bytearray(
+                 attr_cont, "bpk", &bpk_file_len))) {
+        SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: invalid bpk file.");
+        return false;
+    }
 
-        if (!applet_name || strlen(applet_name) == 0) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: invalid applet name.");
-            return false;
-        }
+    /* Check applet name */
+    applet_name = attr_container_get_as_string(attr_cont, "name");
 
-        if (app_manager_lookup_module_data(applet_name)) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: applet already installed.");
-            return false;
-        }
+    if (!applet_name || strlen(applet_name) == 0) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: invalid applet name.");
+        return false;
+    }
 
-        /* TODO: convert bpk file to Jeff file */
-        main_file_len = bpk_file_len;
-        main_file = APP_MGR_MALLOC(main_file_len);
-        if (!main_file) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: allocate memory failed.");
-            return false;
-        }
-        bh_memcpy_s(main_file, main_file_len, bpk_file, main_file_len);
+    if (app_manager_lookup_module_data(applet_name)) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: applet already installed.");
+        return false;
+    }
 
-        /* Verify signature */
-        if (!verify_signature((JeffFileHeader *)main_file, main_file_len)) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: verify Jeff file signature failed.");
-            goto fail1;
-        }
+    /* TODO: convert bpk file to Jeff file */
+    main_file_len = bpk_file_len;
+    main_file = APP_MGR_MALLOC(main_file_len);
+    if (!main_file) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: allocate memory failed.");
+        return false;
+    }
+    bh_memcpy_s(main_file, main_file_len, bpk_file, main_file_len);
+
+    /* Verify signature */
+    if (!verify_signature((JeffFileHeader *)main_file, main_file_len)) {
+        SEND_ERR_RESPONSE(
+            msg->mid,
+            "Install Applet failed: verify Jeff file signature failed.");
+        goto fail1;
+    }
 
-        /* Load Jeff main file */
-        if (!jeff_runtime_load(main_file, main_file_len, false, NULL, NULL)) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: load Jeff file failed.");
-            goto fail1;
-        }
+    /* Load Jeff main file */
+    if (!jeff_runtime_load(main_file, main_file_len, false, NULL, NULL)) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: load Jeff file failed.");
+        goto fail1;
+    }
 
-        /* Find main class */
-        main_class = find_main_class(main_file);
-        if (!main_class) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: find applet class failed.");
-            goto fail2;
-        }
+    /* Find main class */
+    main_class = find_main_class(main_file);
+    if (!main_class) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: find applet class failed.");
+        goto fail2;
+    }
 
-        /* Create module data */
-        size = offsetof(module_data, module_name) + strlen(applet_name) + 1;
-        size = align_uint(size, 4);
-        m_data = APP_MGR_MALLOC(size + sizeof(jeff_applet_data));
-        if (!m_data) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: allocate memory failed.");
-            goto fail2;
-        }
+    /* Create module data */
+    size = offsetof(module_data, module_name) + strlen(applet_name) + 1;
+    size = align_uint(size, 4);
+    m_data = APP_MGR_MALLOC(size + sizeof(jeff_applet_data));
+    if (!m_data) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: allocate memory failed.");
+        goto fail2;
+    }
 
-        memset(m_data, 0, size + sizeof(jeff_applet_data));
-        m_data->module_type = Module_Jeff;
-        m_data->internal_data = (uint8*)m_data + size;
-        applet_data = (jeff_applet_data*)m_data->internal_data;
-        bh_strcpy_s(m_data->module_name, strlen(applet_name) + 1, applet_name);
-        applet_data->main_file = main_file;
+    memset(m_data, 0, size + sizeof(jeff_applet_data));
+    m_data->module_type = Module_Jeff;
+    m_data->internal_data = (uint8 *)m_data + size;
+    applet_data = (jeff_applet_data *)m_data->internal_data;
+    bh_strcpy_s(m_data->module_name, strlen(applet_name) + 1, applet_name);
+    applet_data->main_file = main_file;
 
-        /* Set applet execution timeout */
-        timeout = DEFAULT_APPLET_TIMEOUT;
-        if (attr_container_contain_key(attr_cont, "execution timeout"))
+    /* Set applet execution timeout */
+    timeout = DEFAULT_APPLET_TIMEOUT;
+    if (attr_container_contain_key(attr_cont, "execution timeout"))
         timeout = attr_container_get_as_int(attr_cont, "execution timeout");
-        m_data->timeout = timeout;
-
-        /* Create applet permissions */
-        applet_perm = attr_container_get_as_string(attr_cont, "perm");
-        if (applet_perm != NULL) {
-            applet_data->perms = APP_MGR_MALLOC(strlen(applet_perm) + 1);
-            if (!applet_data->perms) {
-                SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: allocate memory for applet permissions failed.");
-                goto fail3;
-            }
+    m_data->timeout = timeout;
 
-            bh_strcpy_s(applet_data->perms, strlen(applet_perm) + 1, applet_perm);
+    /* Create applet permissions */
+    applet_perm = attr_container_get_as_string(attr_cont, "perm");
+    if (applet_perm != NULL) {
+        applet_data->perms = APP_MGR_MALLOC(strlen(applet_perm) + 1);
+        if (!applet_data->perms) {
+            SEND_ERR_RESPONSE(msg->mid,
+                              "Install Applet failed: allocate memory for "
+                              "applet permissions failed.");
+            goto fail3;
         }
 
-        /* Create applet queue */
-        m_data->queue = bh_queue_create();
-        if (!m_data->queue) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: create applet queue failed.");
-            goto fail3_1;
-        }
+        bh_strcpy_s(applet_data->perms, strlen(applet_perm) + 1, applet_perm);
+    }
+
+    /* Create applet queue */
+    m_data->queue = bh_queue_create();
+    if (!m_data->queue) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: create applet queue failed.");
+        goto fail3_1;
+    }
 
-        /* Set heap size */
-        heap_size = DEFAULT_APPLET_HEAP_SIZE;
-        if (attr_container_contain_key(attr_cont, "heap size")) {
-            heap_size = attr_container_get_as_int(attr_cont, "heap size");
-            if (heap_size < MIN_APPLET_HEAP_SIZE)
+    /* Set heap size */
+    heap_size = DEFAULT_APPLET_HEAP_SIZE;
+    if (attr_container_contain_key(attr_cont, "heap size")) {
+        heap_size = attr_container_get_as_int(attr_cont, "heap size");
+        if (heap_size < MIN_APPLET_HEAP_SIZE)
             heap_size = MIN_APPLET_HEAP_SIZE;
-            else if (heap_size > MAX_APPLET_HEAP_SIZE)
+        else if (heap_size > MAX_APPLET_HEAP_SIZE)
             heap_size = MAX_APPLET_HEAP_SIZE;
-        }
+    }
 
-        m_data->heap_size = heap_size;
+    m_data->heap_size = heap_size;
 
-        /* Create applet heap */
-        m_data->heap = gc_init_for_instance(heap_size);
-        if (!m_data->heap) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: create heap failed.");
-            goto fail4;
-        }
+    /* Create applet heap */
+    m_data->heap = gc_init_for_instance(heap_size);
+    if (!m_data->heap) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: create heap failed.");
+        goto fail4;
+    }
 
-        /* Create applet object */
-        applet_data->applet_obj = jeff_object_new(m_data->heap, main_class);
-        if (!applet_data->applet_obj) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: create applet object failed.");
-            goto fail5;
-        }
+    /* Create applet object */
+    applet_data->applet_obj = jeff_object_new(m_data->heap, main_class);
+    if (!applet_data->applet_obj) {
+        SEND_ERR_RESPONSE(
+            msg->mid, "Install Applet failed: create applet object failed.");
+        goto fail5;
+    }
 
-        /* Initialize watchdog timer */
-        if (!watchdog_timer_init(m_data)) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: create applet watchdog timer failed.");
-            goto fail5;
-        }
+    /* Initialize watchdog timer */
+    if (!watchdog_timer_init(m_data)) {
+        SEND_ERR_RESPONSE(
+            msg->mid,
+            "Install Applet failed: create applet watchdog timer failed.");
+        goto fail5;
+    }
 
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
-        /* Check whether applet is debuggable */
-        if (attr_container_contain_key(attr_cont, "debug"))
+    /* Check whether applet is debuggable */
+    if (attr_container_contain_key(attr_cont, "debug"))
         debug = attr_container_get_as_bool(attr_cont, "debug");
 
-        applet_data->debug_mode = debug;
+    applet_data->debug_mode = debug;
 
-        /* Create tool agent queue */
-        if (debug && !(applet_data->tool_agent_queue = bh_queue_create())) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: create tool agent queue failed.");
-            goto fail5_1;
-        }
+    /* Create tool agent queue */
+    if (debug && !(applet_data->tool_agent_queue = bh_queue_create())) {
+        SEND_ERR_RESPONSE(
+            msg->mid, "Install Applet failed: create tool agent queue failed.");
+        goto fail5_1;
+    }
 #endif
 
-        /* Create applet instance */
-        applet_data->vm_instance =
-        jeff_runtime_create_instance(main_file, m_data->heap, 16,
-        app_instance_main, m_data,
-        NULL);
-        if (!applet_data->vm_instance) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: create Java VM failed");
-            goto fail6;
-        }
+    /* Create applet instance */
+    applet_data->vm_instance = jeff_runtime_create_instance(
+        main_file, m_data->heap, 16, app_instance_main, m_data, NULL);
+    if (!applet_data->vm_instance) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: create Java VM failed");
+        goto fail6;
+    }
 
-        /* Add applet data to applet data list */
-        applet_data->vm_instance->applet_object = applet_data->applet_obj;
-        app_manager_add_module_data(m_data);
-        app_manager_post_applets_update_event();
+    /* Add applet data to applet data list */
+    applet_data->vm_instance->applet_object = applet_data->applet_obj;
+    app_manager_add_module_data(m_data);
+    app_manager_post_applets_update_event();
 
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
-        /* Start tool agent thread */
-        if (debug && !jeff_tool_start_agent(applet_data->vm_instance, applet_data->tool_agent_queue)) {
-            SEND_ERR_RESPONSE(msg->mid, "Install Applet failed: start tool agent failed");
-            goto fail6;
-        }
+    /* Start tool agent thread */
+    if (debug
+        && !jeff_tool_start_agent(applet_data->vm_instance,
+                                  applet_data->tool_agent_queue)) {
+        SEND_ERR_RESPONSE(msg->mid,
+                          "Install Applet failed: start tool agent failed");
+        goto fail6;
+    }
 #endif
 
-        app_manager_printf("Install Applet success!\n");
-        app_send_response_to_host(msg->mid, CREATED_2_01, NULL); /* CREATED */
-        return true;
+    app_manager_printf("Install Applet success!\n");
+    app_send_response_to_host(msg->mid, CREATED_2_01, NULL); /* CREATED */
+    return true;
 
-        fail6:
+fail6:
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
-        if (debug)
+    if (debug)
         bh_queue_destroy(applet_data->tool_agent_queue);
 #endif
 
-        fail5_1:
-        watchdog_timer_destroy(&m_data->wd_timer);
+fail5_1:
+    watchdog_timer_destroy(&m_data->wd_timer);
 
-        fail5:
-        gc_destroy_for_instance(m_data->heap);
+fail5:
+    gc_destroy_for_instance(m_data->heap);
 
-        fail4:
-        bh_queue_destroy(m_data->queue, NULL);
+fail4:
+    bh_queue_destroy(m_data->queue, NULL);
 
-        fail3_1:
-        APP_MGR_FREE(applet_data->perms);
+fail3_1:
+    APP_MGR_FREE(applet_data->perms);
 
-        fail3:
-        APP_MGR_FREE(applet_data);
+fail3:
+    APP_MGR_FREE(applet_data);
 
-        fail2:
-        jeff_runtime_unload(main_file);
+fail2:
+    jeff_runtime_unload(main_file);
 
-        fail1:
-        APP_MGR_FREE(main_file);
+fail1:
+    APP_MGR_FREE(main_file);
 
-        return false;
-    }
+    return false;
+}
 
-    static void
-    cleanup_applet_resource(module_data *m_data)
-    {
-        jeff_applet_data *applet_data = (jeff_applet_data*)m_data->internal_data;
+static void
+cleanup_applet_resource(module_data *m_data)
+{
+    jeff_applet_data *applet_data = (jeff_applet_data *)m_data->internal_data;
 
-        /* Unload Jeff main file and free it */
-        jeff_runtime_unload(applet_data->main_file);
-        APP_MGR_FREE(applet_data->main_file);
+    /* Unload Jeff main file and free it */
+    jeff_runtime_unload(applet_data->main_file);
+    APP_MGR_FREE(applet_data->main_file);
 
-        /* Destroy queue */
-        bh_queue_destroy(m_data->queue, app_instance_queue_free_callback);
+    /* Destroy queue */
+    bh_queue_destroy(m_data->queue, app_instance_queue_free_callback);
 
-        /* Destroy heap */
-        gc_destroy_for_instance(m_data->heap);
+    /* Destroy heap */
+    gc_destroy_for_instance(m_data->heap);
 
-        /* Destroy watchdog timer */
-        watchdog_timer_destroy(&m_data->wd_timer);
+    /* Destroy watchdog timer */
+    watchdog_timer_destroy(&m_data->wd_timer);
 
-        /* Remove module data from module data list and free it */
-        app_manager_del_module_data(m_data);
-        APP_MGR_FREE(applet_data->perms);
-        APP_MGR_FREE(m_data);
-    }
+    /* Remove module data from module data list and free it */
+    app_manager_del_module_data(m_data);
+    APP_MGR_FREE(applet_data->perms);
+    APP_MGR_FREE(m_data);
+}
 
-    /* Uninstall Java Applet */
-    static bool
-    jeff_module_uninstall(bh_request_msg_t *msg)
-    {
-        module_data *m_data;
-        jeff_applet_data *applet_data;
-        attr_container_t *attr_cont;
-        char *applet_name;
-        bool do_not_reply = false;
+/* Uninstall Java Applet */
+static bool
+jeff_module_uninstall(bh_request_msg_t *msg)
+{
+    module_data *m_data;
+    jeff_applet_data *applet_data;
+    attr_container_t *attr_cont;
+    char *applet_name;
+    bool do_not_reply = false;
 
-        /* Check payload and applet name*/
-        attr_cont = (attr_container_t *)msg->payload;
+    /* Check payload and applet name*/
+    attr_cont = (attr_container_t *)msg->payload;
 
-        /* Check whether need to reply this request */
-        if (attr_container_contain_key(attr_cont, "do not reply me"))
+    /* Check whether need to reply this request */
+    if (attr_container_contain_key(attr_cont, "do not reply me"))
         do_not_reply = attr_container_get_as_bool(attr_cont, "do not reply me");
 
-        /* Check url */
-        if (!msg->url
-        || strcmp(msg->url, "/applet") != 0) {
-            if (!do_not_reply)
-            SEND_ERR_RESPONSE(msg->mid, "Uninstall Applet failed: invalid url.");
-            else
+    /* Check url */
+    if (!msg->url || strcmp(msg->url, "/applet") != 0) {
+        if (!do_not_reply)
+            SEND_ERR_RESPONSE(msg->mid,
+                              "Uninstall Applet failed: invalid url.");
+        else
             app_manager_printf("Uninstall Applet failed: invalid url.");
-            return false;
-        }
+        return false;
+    }
 
-        if (!attr_cont
+    if (!attr_cont
         || !(applet_name = attr_container_get_as_string(attr_cont, "name"))
         || strlen(applet_name) == 0) {
-            if (!do_not_reply)
-            SEND_ERR_RESPONSE(msg->mid, "Uninstall Applet failed: invalid applet name.");
-            else
+        if (!do_not_reply)
+            SEND_ERR_RESPONSE(msg->mid,
+                              "Uninstall Applet failed: invalid applet name.");
+        else
             app_manager_printf("Uninstall Applet failed: invalid applet name.");
-            return false;
-        }
+        return false;
+    }
 
-        m_data = app_manager_lookup_module_data(applet_name);
-        if (!m_data) {
-            if (!do_not_reply)
-            SEND_ERR_RESPONSE(msg->mid, "Uninstall Applet failed: no applet found.");
-            else
+    m_data = app_manager_lookup_module_data(applet_name);
+    if (!m_data) {
+        if (!do_not_reply)
+            SEND_ERR_RESPONSE(msg->mid,
+                              "Uninstall Applet failed: no applet found.");
+        else
             app_manager_printf("Uninstall Applet failed: no applet found.");
-            return false;
-        }
+        return false;
+    }
 
-        if (m_data->module_type != Module_Jeff) {
-            if (!do_not_reply)
-            SEND_ERR_RESPONSE(msg->mid, "Uninstall Applet failed: invlaid module type.");
-            else
+    if (m_data->module_type != Module_Jeff) {
+        if (!do_not_reply)
+            SEND_ERR_RESPONSE(msg->mid,
+                              "Uninstall Applet failed: invlaid module type.");
+        else
             app_manager_printf("Uninstall Applet failed: invalid module type.");
-            return false;
-        }
+        return false;
+    }
 
-        if (m_data->wd_timer.is_interrupting) {
-            if (!do_not_reply)
-            SEND_ERR_RESPONSE(msg->mid, "Uninstall Applet failed: applet is being interrupted by watchdog.");
-            else
-            app_manager_printf("Uninstall Applet failed: applet is being interrupted by watchdog.");
-            return false;
-        }
+    if (m_data->wd_timer.is_interrupting) {
+        if (!do_not_reply)
+            SEND_ERR_RESPONSE(msg->mid,
+                              "Uninstall Applet failed: applet is being "
+                              "interrupted by watchdog.");
+        else
+            app_manager_printf("Uninstall Applet failed: applet is being "
+                               "interrupted by watchdog.");
+        return false;
+    }
 
-        /* Exit applet queue loop run */
-        bh_queue_exit_loop_run(m_data->queue);
+    /* Exit applet queue loop run */
+    bh_queue_exit_loop_run(m_data->queue);
 
-        applet_data = (jeff_applet_data*)m_data->internal_data;
+    applet_data = (jeff_applet_data *)m_data->internal_data;
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
-        /* Exit tool agent queue loop run */
-        if (is_tool_agent_running(m_data)) {
-            bh_queue_exit_loop_run(applet_data->tool_agent_queue);
-        }
+    /* Exit tool agent queue loop run */
+    if (is_tool_agent_running(m_data)) {
+        bh_queue_exit_loop_run(applet_data->tool_agent_queue);
+    }
 #endif
 
-        /* Wait the end of the applet instance and then destroy it */
-        if (applet_data->vm_instance->main_file)
+    /* Wait the end of the applet instance and then destroy it */
+    if (applet_data->vm_instance->main_file)
         jeff_runtime_wait_for_instance(applet_data->vm_instance, -1);
-        jeff_runtime_destroy_instance(applet_data->vm_instance);
+    jeff_runtime_destroy_instance(applet_data->vm_instance);
 
-        cleanup_applet_resource(m_data);
-        app_manager_post_applets_update_event();
+    cleanup_applet_resource(m_data);
+    app_manager_post_applets_update_event();
 
-        app_manager_printf("Uninstall Applet success!\n");
+    app_manager_printf("Uninstall Applet success!\n");
 
-        if (!do_not_reply)
+    if (!do_not_reply)
         app_send_response_to_host(msg->mid, DELETED_2_02, NULL); /* DELETED */
-        return true;
-    }
+    return true;
+}
 
 #define PERM_PREFIX "AEE.permission."
 
-    static bool
-    check_permission_format(const char *perm)
-    {
-        const char *prefix = PERM_PREFIX;
-        const char *p;
+static bool
+check_permission_format(const char *perm)
+{
+    const char *prefix = PERM_PREFIX;
+    const char *p;
 
-        if (perm == NULL || strncmp(perm, prefix, strlen(prefix)) != 0
+    if (perm == NULL || strncmp(perm, prefix, strlen(prefix)) != 0
         || *(p = perm + strlen(prefix)) == '\0')
         return false;
 
-        do {
-            if (!(*p == '.' || ('A' <= *p && *p <= 'Z') || ('a' <= *p && *p <= 'z')))
+    do {
+        if (!(*p == '.' || ('A' <= *p && *p <= 'Z')
+              || ('a' <= *p && *p <= 'z')))
             return false;
-        }while (*++p != '\0');
+    } while (*++p != '\0');
 
-        return true;
-    }
+    return true;
+}
 
-    static bool
-    match(const char *haystack, const char *needle, char delim)
-    {
-        const char *p = needle;
+static bool
+match(const char *haystack, const char *needle, char delim)
+{
+    const char *p = needle;
 
-        if (haystack == NULL || *haystack == '\0'
-        || needle == NULL || *needle == '\0')
+    if (haystack == NULL || *haystack == '\0' || needle == NULL
+        || *needle == '\0')
         return false;
 
+    while (true) {
         while (true) {
-            while (true) {
-                if ((*haystack == '\0' || *haystack == delim) && *p == '\0') {
-                    return true;
-                } else if (*p == *haystack) {
-                    ++p;
-                    ++haystack;
-                } else {
-                    break;
-                }
+            if ((*haystack == '\0' || *haystack == delim) && *p == '\0') {
+                return true;
             }
-            while (*haystack != '\0' && *haystack != delim) {
+            else if (*p == *haystack) {
+                ++p;
                 ++haystack;
             }
-            if (*haystack == '\0') {
-                return false;
-            } else {
-                ++haystack;
-                p = needle;
+            else {
+                break;
             }
         }
+        while (*haystack != '\0' && *haystack != delim) {
+            ++haystack;
+        }
+        if (*haystack == '\0') {
+            return false;
+        }
+        else {
+            ++haystack;
+            p = needle;
+        }
     }
+}
 
-    bool
-    bh_applet_check_permission(const char *perm)
-    {
-        return check_permission_format(perm)
-        && match(app_manager_get_jeff_applet_data()->perms,
-        perm + strlen(PERM_PREFIX), ' ');
-    }
-
-    static bool
-    jeff_module_init()
-    {
-        JeffDescriptorFull d[] = { {JEFF_TYPE_VOID, 0, NULL}};
-        JeffDescriptorFull d1[] = {
-            {   JEFF_TYPE_OBJECT | JEFF_TYPE_REF, 0, NULL},
-            {   JEFF_TYPE_VOID, 0, NULL}
-        };
+bool
+bh_applet_check_permission(const char *perm)
+{
+    return check_permission_format(perm)
+           && match(app_manager_get_jeff_applet_data()->perms,
+                    perm + strlen(PERM_PREFIX), ' ');
+}
 
-        /* Resolve class com.intel.aee.AEEApplet */
-        class_AEEApplet = jeff_runtime_resolve_class_full_name("com.intel.aee.AEEApplet");
-        if (!class_AEEApplet) {
-            app_manager_printf("App Manager start failed: resolve class AEEApplet failed.\n");
-            return false;
-        }
+static bool
+jeff_module_init()
+{
+    JeffDescriptorFull d[] = { { JEFF_TYPE_VOID, 0, NULL } };
+    JeffDescriptorFull d1[] = { { JEFF_TYPE_OBJECT | JEFF_TYPE_REF, 0, NULL },
+                                { JEFF_TYPE_VOID, 0, NULL } };
+
+    /* Resolve class com.intel.aee.AEEApplet */
+    class_AEEApplet =
+        jeff_runtime_resolve_class_full_name("com.intel.aee.AEEApplet");
+    if (!class_AEEApplet) {
+        app_manager_printf(
+            "App Manager start failed: resolve class AEEApplet failed.\n");
+        return false;
+    }
 
-        /* Resolve class com.intel.aee.Request */
-        class_AEERequest = jeff_runtime_resolve_class_full_name("com.intel.aee.Request");
-        if (!class_AEERequest) {
-            app_manager_printf("App Manager start failed: resolve class Request failed.\n");
-            return false;
-        }
+    /* Resolve class com.intel.aee.Request */
+    class_AEERequest =
+        jeff_runtime_resolve_class_full_name("com.intel.aee.Request");
+    if (!class_AEERequest) {
+        app_manager_printf(
+            "App Manager start failed: resolve class Request failed.\n");
+        return false;
+    }
 
-        /* Resolve class com.intel.aee.Timer */
-        class_Timer = jeff_runtime_resolve_class_full_name("com.intel.aee.Timer");
-        if (!class_Timer) {
-            app_manager_printf("App Manager start failed: resolve class Timer failed.\n");
-            return false;
-        }
+    /* Resolve class com.intel.aee.Timer */
+    class_Timer = jeff_runtime_resolve_class_full_name("com.intel.aee.Timer");
+    if (!class_Timer) {
+        app_manager_printf(
+            "App Manager start failed: resolve class Timer failed.\n");
+        return false;
+    }
 
-        /* Resolve class com.intel.aee.Sensor */
-        class_Sensor = jeff_runtime_resolve_class_full_name("com.intel.aee.Sensor");
-        if (!class_Sensor) {
-            app_manager_printf("App Manager start failed: resolve class Sensor failed.\n");
-            return false;
-        }
+    /* Resolve class com.intel.aee.Sensor */
+    class_Sensor = jeff_runtime_resolve_class_full_name("com.intel.aee.Sensor");
+    if (!class_Sensor) {
+        app_manager_printf(
+            "App Manager start failed: resolve class Sensor failed.\n");
+        return false;
+    }
 
-        /* Resolve class com.intel.aee.ble.BLEManager */
-        class_BLEManager = jeff_runtime_resolve_class_full_name(
-        "com.intel.aee.ble.BLEManager");
-        if (!class_BLEManager) {
-            app_manager_printf(
+    /* Resolve class com.intel.aee.ble.BLEManager */
+    class_BLEManager =
+        jeff_runtime_resolve_class_full_name("com.intel.aee.ble.BLEManager");
+    if (!class_BLEManager) {
+        app_manager_printf(
             "App Manager start failed: resolve class BLEManager failed.\n");
-            return false;
-        }
+        return false;
+    }
 
-        /* Resolve class com.intel.aee.ble.BLEDevice */
-        class_BLEDevice = jeff_runtime_resolve_class_full_name(
-        "com.intel.aee.ble.BLEDevice");
-        if (!class_BLEDevice) {
-            app_manager_printf(
+    /* Resolve class com.intel.aee.ble.BLEDevice */
+    class_BLEDevice =
+        jeff_runtime_resolve_class_full_name("com.intel.aee.ble.BLEDevice");
+    if (!class_BLEDevice) {
+        app_manager_printf(
             "App Manager start failed: resolve class BLEDevice failed.\n");
-            return false;
-        }
-        /* Resolve class com.intel.aee.ble.BLEDevice */
-        class_BLEGattService = jeff_runtime_resolve_class_full_name(
+        return false;
+    }
+    /* Resolve class com.intel.aee.ble.BLEDevice */
+    class_BLEGattService = jeff_runtime_resolve_class_full_name(
         "com.intel.aee.ble.BLEGattService");
-        if (!class_BLEGattService) {
-            app_manager_printf(
-            "App Manager start failed: resolve class BLEGattService failed.\n");
-            return false;
-        }
+    if (!class_BLEGattService) {
+        app_manager_printf("App Manager start failed: resolve class "
+                           "BLEGattService failed.\n");
+        return false;
+    }
 
-        /* Resolve class com.intel.aee.ble.BLEDevice */
-        class_BLEGattCharacteristic = jeff_runtime_resolve_class_full_name(
+    /* Resolve class com.intel.aee.ble.BLEDevice */
+    class_BLEGattCharacteristic = jeff_runtime_resolve_class_full_name(
         "com.intel.aee.ble.BLEGattCharacteristic");
-        if (!class_BLEGattCharacteristic) {
-            app_manager_printf(
-            "App Manager start failed: resolve class BLEGattCharacteristic failed.\n");
-            return false;
-        }
+    if (!class_BLEGattCharacteristic) {
+        app_manager_printf("App Manager start failed: resolve class "
+                           "BLEGattCharacteristic failed.\n");
+        return false;
+    }
 
-        /* Resolve class com.intel.aee.ble.BLEDevice */
-        class_BLEGattDescriptor = jeff_runtime_resolve_class_full_name(
+    /* Resolve class com.intel.aee.ble.BLEDevice */
+    class_BLEGattDescriptor = jeff_runtime_resolve_class_full_name(
         "com.intel.aee.ble.BLEGattDescriptor");
-        if (!class_BLEGattDescriptor) {
-            app_manager_printf(
-            "App Manager start failed: resolve class BLEGattDescriptor failed.\n");
-            return false;
-        }
-        /* Resolve class com.intel.aee.gpio.GPIOChannel */
-        class_GPIOChannel = jeff_runtime_resolve_class_full_name(
-        "com.intel.aee.gpio.GPIOChannel");
-        if (!class_GPIOChannel) {
-            app_manager_printf(
-            "App Manager start failed: resolve class GPIOChannel failed.\n");
-            return false;
-        }
-
-        /* Resolve method com.intel.aee.AEEApplet.onInit() */
-        method_AEEApplet_onInit = jeff_lookup_method(class_AEEApplet, "onInit", 0, d);
-        if (!method_AEEApplet_onInit) {
-            app_manager_printf("App Manager start failed: resolve method Applet.onInit() failed.\n");
-            return false;
-        }
+    if (!class_BLEGattDescriptor) {
+        app_manager_printf("App Manager start failed: resolve class "
+                           "BLEGattDescriptor failed.\n");
+        return false;
+    }
+    /* Resolve class com.intel.aee.gpio.GPIOChannel */
+    class_GPIOChannel =
+        jeff_runtime_resolve_class_full_name("com.intel.aee.gpio.GPIOChannel");
+    if (!class_GPIOChannel) {
+        app_manager_printf("App Manager start failed: resolve class "
+                           "GPIOChannel failed.\n");
+        return false;
+    }
 
-        /* Resolve method com.intel.aee.AEEApplet.onDestroy() */
-        method_AEEApplet_onDestroy = jeff_lookup_method(class_AEEApplet, "onDestroy", 0, d);
-        if (!method_AEEApplet_onDestroy) {
-            app_manager_printf("App Manager start failed: resolve method AEEApplet.onDestroy() failed.\n");
-            return false;
-        }
+    /* Resolve method com.intel.aee.AEEApplet.onInit() */
+    method_AEEApplet_onInit =
+        jeff_lookup_method(class_AEEApplet, "onInit", 0, d);
+    if (!method_AEEApplet_onInit) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "Applet.onInit() failed.\n");
+        return false;
+    }
 
-        /* Resolve method com.intel.aee.AEEApplet.callOnRequest(Request) */
-        d1[0].class_header = class_AEERequest;
-        method_AEEApplet_callOnRequest = jeff_lookup_method(class_AEEApplet, "callOnRequest", 1, d1);
-        if (!method_AEEApplet_callOnRequest) {
-            app_manager_printf("App Manager start failed: resolve method AEEApplet.callOnRequest() failed.\n");
-            return false;
-        }
+    /* Resolve method com.intel.aee.AEEApplet.onDestroy() */
+    method_AEEApplet_onDestroy =
+        jeff_lookup_method(class_AEEApplet, "onDestroy", 0, d);
+    if (!method_AEEApplet_onDestroy) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "AEEApplet.onDestroy() failed.\n");
+        return false;
+    }
 
-        /* Resolve method com.intel.aee.Timer.callOnTimer() */
-        method_callOnTimer = jeff_lookup_method(class_Timer, "callOnTimer", 0, d);
-        if (!method_callOnTimer) {
-            app_manager_printf("App Manager start failed: resolve method Timer.callOnTimer() failed.\n");
-            return false;
-        }
+    /* Resolve method com.intel.aee.AEEApplet.callOnRequest(Request) */
+    d1[0].class_header = class_AEERequest;
+    method_AEEApplet_callOnRequest =
+        jeff_lookup_method(class_AEEApplet, "callOnRequest", 1, d1);
+    if (!method_AEEApplet_callOnRequest) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "AEEApplet.callOnRequest() failed.\n");
+        return false;
+    }
 
-        /* Resolve method com.intel.aee.Sensor.callOnSensorEvent() */
-        method_callOnSensorEvent = jeff_lookup_method(class_Sensor, "callOnSensorEvent", 0, d);
-        if (!method_callOnSensorEvent) {
-            app_manager_printf("App Manager start failed: resolve method Sensor.callOnSensorEvent() failed.\n");
-            return false;
-        }
+    /* Resolve method com.intel.aee.Timer.callOnTimer() */
+    method_callOnTimer = jeff_lookup_method(class_Timer, "callOnTimer", 0, d);
+    if (!method_callOnTimer) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "Timer.callOnTimer() failed.\n");
+        return false;
+    }
 
-        /* Resovle method com.intel.aee.ble.BLEManager.callOnBLEStartDiscovery(BLEDevice) */
-        d1[0].class_header = class_BLEDevice;
-        method_callOnBLEStartDiscovery = jeff_lookup_method(class_BLEManager, "callOnBLEStartDiscovery", 1, d1);
-        if (!method_callOnBLEStartDiscovery) {
-            app_manager_printf("App Manager start failed: resolve method BLEManager.callOnBLEStartDiscovery() failed.\n");
-            return false;
-        }
+    /* Resolve method com.intel.aee.Sensor.callOnSensorEvent() */
+    method_callOnSensorEvent =
+        jeff_lookup_method(class_Sensor, "callOnSensorEvent", 0, d);
+    if (!method_callOnSensorEvent) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "Sensor.callOnSensorEvent() failed.\n");
+        return false;
+    }
 
-        /* Resovle method com.intel.aee.ble.BLEManager.callOnBLEConnected(BLEDevice) */
-        JeffDescriptorFull d2_1[] = { {JEFF_TYPE_OBJECT | JEFF_TYPE_REF, 0, class_BLEDevice},
-            {   JEFF_TYPE_INT, 0, NULL},
-            {   JEFF_TYPE_VOID, 0, NULL}};
-        method_callOnBLEConnected = jeff_lookup_method(class_BLEManager, "callOnBLEConnected", 2, d2_1);
-        if (!method_callOnBLEConnected) {
-            app_manager_printf("App Manager start failed: resolve method BLEManager.callOnBLEConnected() failed.\n");
-            return false;
-        }
+    /* Resovle method
+     * com.intel.aee.ble.BLEManager.callOnBLEStartDiscovery(BLEDevice) */
+    d1[0].class_header = class_BLEDevice;
+    method_callOnBLEStartDiscovery =
+        jeff_lookup_method(class_BLEManager, "callOnBLEStartDiscovery", 1, d1);
+    if (!method_callOnBLEStartDiscovery) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "BLEManager.callOnBLEStartDiscovery() failed.\n");
+        return false;
+    }
 
-        /* Resovle method com.intel.aee.ble.BLEManager.method_callOnBLENotification(BLEDevice,byte[]) */
-        JeffDescriptorFull d2_2[] = { {JEFF_TYPE_OBJECT | JEFF_TYPE_REF, 0, class_BLEDevice},
-            {   JEFF_TYPE_BYTE | JEFF_TYPE_REF | JEFF_TYPE_MONO, 1, NULL},
-            {   JEFF_TYPE_INT, 0, NULL},
-            {   JEFF_TYPE_INT, 0, NULL},
-            {   JEFF_TYPE_VOID, 0, NULL}};
-        method_callOnBLENotification = jeff_lookup_method(class_BLEManager, "callOnBLENotification", 4, d2_2);
-        if (!method_callOnBLENotification) {
-            app_manager_printf("App Manager start failed: resolve method BLEManager.callOnBLENotification() failed.\n");
-            return false;
-        }
+    /* Resovle method
+     * com.intel.aee.ble.BLEManager.callOnBLEConnected(BLEDevice) */
+    JeffDescriptorFull d2_1[] = { { JEFF_TYPE_OBJECT | JEFF_TYPE_REF, 0,
+                                    class_BLEDevice },
+                                  { JEFF_TYPE_INT, 0, NULL },
+                                  { JEFF_TYPE_VOID, 0, NULL } };
+    method_callOnBLEConnected =
+        jeff_lookup_method(class_BLEManager, "callOnBLEConnected", 2, d2_1);
+    if (!method_callOnBLEConnected) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "BLEManager.callOnBLEConnected() failed.\n");
+        return false;
+    }
 
-        /* Resovle method com.intel.aee.ble.BLEManager.callOnBLEConnected(BLEDevice,byte[]) */
-        method_callOnBLEIndication = jeff_lookup_method(class_BLEManager, "callOnBLEIndication", 4, d2_2);
-        if (!method_callOnBLEIndication) {
-            app_manager_printf("App Manager start failed: resolve method BLEManager.callOnBLEIndication() failed.\n");
-            return false;
-        }
+    /* Resovle method
+     * com.intel.aee.ble.BLEManager.method_callOnBLENotification(BLEDevice,byte[])
+     */
+    JeffDescriptorFull d2_2[] = {
+        { JEFF_TYPE_OBJECT | JEFF_TYPE_REF, 0, class_BLEDevice },
+        { JEFF_TYPE_BYTE | JEFF_TYPE_REF | JEFF_TYPE_MONO, 1, NULL },
+        { JEFF_TYPE_INT, 0, NULL },
+        { JEFF_TYPE_INT, 0, NULL },
+        { JEFF_TYPE_VOID, 0, NULL }
+    };
+    method_callOnBLENotification =
+        jeff_lookup_method(class_BLEManager, "callOnBLENotification", 4, d2_2);
+    if (!method_callOnBLENotification) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "BLEManager.callOnBLENotification() failed.\n");
+        return false;
+    }
 
-        /* Resovle method com.intel.aee.ble.BLEManager.callOnBLEConnected(BLEDevice) */
-        d1[0].class_header = class_BLEDevice;
-        method_callOnBLEDisconnected = jeff_lookup_method(class_BLEManager, "callOnBLEDisconnected", 1, d1);
-        if (!method_callOnBLEDisconnected) {
-            app_manager_printf("App Manager start failed: resolve method BLEManager.callOnBLEDisconnected() failed.\n");
-            return false;
-        }
+    /* Resovle method
+     * com.intel.aee.ble.BLEManager.callOnBLEConnected(BLEDevice,byte[]) */
+    method_callOnBLEIndication =
+        jeff_lookup_method(class_BLEManager, "callOnBLEIndication", 4, d2_2);
+    if (!method_callOnBLEIndication) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "BLEManager.callOnBLEIndication() failed.\n");
+        return false;
+    }
 
-        /* Resovle method com.intel.aee.ble.BLEManager.callOnBLEConnected(BLEDevice) */
-        method_callOnBLEPasskeyEntry = jeff_lookup_method(class_BLEManager, "callOnBLEPasskeyEntry", 1, d1);
-        if (!method_callOnBLEPasskeyEntry) {
-            app_manager_printf("App Manager start failed: resolve method BLEManager.callOnBLEPasskeyEntry() failed.\n");
-            return false;
-        }
-        /* Resovle  method void com.intel.aee.gpio.GPIOChannel.callOnGPIOInterrupt()  */
-        method_callOnGPIOInterrupt = jeff_lookup_method(class_GPIOChannel, "callOnGPIOInterrupt", 0, d);
-        if (!method_callOnGPIOInterrupt) {
-            app_manager_printf("App Manager start failed: resolve method GPIOChannel.callOnGPIOInterrupt() failed.\n");
-            return false;
-        }
+    /* Resovle method
+     * com.intel.aee.ble.BLEManager.callOnBLEConnected(BLEDevice) */
+    d1[0].class_header = class_BLEDevice;
+    method_callOnBLEDisconnected =
+        jeff_lookup_method(class_BLEManager, "callOnBLEDisconnected", 1, d1);
+    if (!method_callOnBLEDisconnected) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "BLEManager.callOnBLEDisconnected() failed.\n");
+        return false;
+    }
 
-        JeffDescriptorFull d2[] = { {JEFF_TYPE_BYTE | JEFF_TYPE_REF | JEFF_TYPE_MONO, 1, NULL},
-            {   JEFF_TYPE_OBJECT | JEFF_TYPE_REF, 0, class_BLEDevice}};
-        /* Resovle method com.intel.aee.ble.BLEManager.getBLEDevice(byte []) */
-        method_callOnBLEManagerGetBLEDevice = jeff_lookup_method(class_BLEManager,
-        "getBLEDevice", 1, d2);
-        if (!method_callOnBLEManagerGetBLEDevice) {
-            app_manager_printf(
-            "App Manager start failed: resolve method BLEManager.getBLEDevice() failed.\n");
-            return false;
-        }
+    /* Resovle method
+     * com.intel.aee.ble.BLEManager.callOnBLEConnected(BLEDevice) */
+    method_callOnBLEPasskeyEntry =
+        jeff_lookup_method(class_BLEManager, "callOnBLEPasskeyEntry", 1, d1);
+    if (!method_callOnBLEPasskeyEntry) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "BLEManager.callOnBLEPasskeyEntry() failed.\n");
+        return false;
+    }
+    /* Resovle  method void
+     * com.intel.aee.gpio.GPIOChannel.callOnGPIOInterrupt()  */
+    method_callOnGPIOInterrupt =
+        jeff_lookup_method(class_GPIOChannel, "callOnGPIOInterrupt", 0, d);
+    if (!method_callOnGPIOInterrupt) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "GPIOChannel.callOnGPIOInterrupt() failed.\n");
+        return false;
+    }
 
-        return true;
+    JeffDescriptorFull d2[] = {
+        { JEFF_TYPE_BYTE | JEFF_TYPE_REF | JEFF_TYPE_MONO, 1, NULL },
+        { JEFF_TYPE_OBJECT | JEFF_TYPE_REF, 0, class_BLEDevice }
+    };
+    /* Resovle method com.intel.aee.ble.BLEManager.getBLEDevice(byte []) */
+    method_callOnBLEManagerGetBLEDevice =
+        jeff_lookup_method(class_BLEManager, "getBLEDevice", 1, d2);
+    if (!method_callOnBLEManagerGetBLEDevice) {
+        app_manager_printf("App Manager start failed: resolve method "
+                           "BLEManager.getBLEDevice() failed.\n");
+        return false;
     }
 
-    static void
-    jeff_module_watchdog_kill(module_data *m_data)
-    {
-        jeff_applet_data *applet_data = (jeff_applet_data*)m_data->internal_data;
+    return true;
+}
 
-        app_manager_printf("Watchdog interrupt the applet %s\n", m_data->module_name);
+static void
+jeff_module_watchdog_kill(module_data *m_data)
+{
+    jeff_applet_data *applet_data = (jeff_applet_data *)m_data->internal_data;
 
-        jeff_runtime_interrupt_instance(applet_data->vm_instance, true);
+    app_manager_printf("Watchdog interrupt the applet %s\n",
+                       m_data->module_name);
 
-        /* Exit applet queue loop run */
-        bh_queue_exit_loop_run(m_data->queue);
+    jeff_runtime_interrupt_instance(applet_data->vm_instance, true);
 
-        /* Wait the end of the applet instance. If timeout, it means applet
-         * is busy executing native code, then try to cancle the main thread. */
-        if (applet_data->vm_instance->main_file)
-        jeff_runtime_wait_for_instance(applet_data->vm_instance, 3000);
+    /* Exit applet queue loop run */
+    bh_queue_exit_loop_run(m_data->queue);
 
-        if (applet_data->vm_instance->main_file) {
-            app_manager_printf("Watchdog cancel applet main thread.\n");
-            os_thread_cancel(applet_data->vm_instance->main_tlr.handle);
-            /* k_thread_abort(applet_data->vm_instance->main_tlr.handle); */
-        }
+    /* Wait the end of the applet instance. If timeout, it means applet
+     * is busy executing native code, then try to cancle the main thread. */
+    if (applet_data->vm_instance->main_file)
+        jeff_runtime_wait_for_instance(applet_data->vm_instance, 3000);
 
-        send_exception_event_to_host(m_data->module_name, "java.lang.InterruptedException");
-        cleanup_applet_resource(m_data);
-        app_manager_printf("Watchdog interrupt Jeff applet done.\n");
+    if (applet_data->vm_instance->main_file) {
+        app_manager_printf("Watchdog cancel applet main thread.\n");
+        os_thread_cancel(applet_data->vm_instance->main_tlr.handle);
+        /* k_thread_abort(applet_data->vm_instance->main_tlr.handle); */
     }
 
-    static bool
-    jeff_module_handle_host_url(void *queue_msg)
-    {
+    send_exception_event_to_host(m_data->module_name,
+                                 "java.lang.InterruptedException");
+    cleanup_applet_resource(m_data);
+    app_manager_printf("Watchdog interrupt Jeff applet done.\n");
+}
+
+static bool
+jeff_module_handle_host_url(void *queue_msg)
+{
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
-        bh_queue_msg_t *msg = (bh_queue_msg_t *)queue_msg;
-
-        if (msg->message_type == COAP_PARSED) {
-            coap_packet_t *packet = (coap_packet_t *)msg->payload;
-            attr_container_t *attr_cont = (attr_container_t *)packet->payload;
-            const char *url = NULL;
-            int url_len = 0, mid;
-
-            bh_memcpy_s(&mid, sizeof(uint32), packet->token, sizeof(uint32));
-            url_len = coap_get_header_uri_path(packet, &url);
-
-            /* Send request to tool agent */
-            if (url_len >= 12 && memcmp(url, "/tool_agent/", 12) == 0) {
-                module_data *m_data;
-                jeff_applet_data *applet_data;
-                unsigned attr_cont_len = 0, req_msg_len;
-                bh_queue_msg_t *tool_agent_msg;
-                bh_request_msg_t *req_msg;
-                char url_buf[256] = {0}, *p = url_buf;
-                char applet_name[128] = {0};
-
-                /* Resolve applet name */
-                bh_memcpy_s(url_buf, sizeof(url_buf), url + 12, url_len - 12);
-                while (*p != '/' && *p != '\0')
+    bh_queue_msg_t *msg = (bh_queue_msg_t *)queue_msg;
+
+    if (msg->message_type == COAP_PARSED) {
+        coap_packet_t *packet = (coap_packet_t *)msg->payload;
+        attr_container_t *attr_cont = (attr_container_t *)packet->payload;
+        const char *url = NULL;
+        int url_len = 0, mid;
+
+        bh_memcpy_s(&mid, sizeof(uint32), packet->token, sizeof(uint32));
+        url_len = coap_get_header_uri_path(packet, &url);
+
+        /* Send request to tool agent */
+        if (url_len >= 12 && memcmp(url, "/tool_agent/", 12) == 0) {
+            module_data *m_data;
+            jeff_applet_data *applet_data;
+            unsigned attr_cont_len = 0, req_msg_len;
+            bh_queue_msg_t *tool_agent_msg;
+            bh_request_msg_t *req_msg;
+            char url_buf[256] = { 0 }, *p = url_buf;
+            char applet_name[128] = { 0 };
+
+            /* Resolve applet name */
+            bh_memcpy_s(url_buf, sizeof(url_buf), url + 12, url_len - 12);
+            while (*p != '/' && *p != '\0')
                 p++;
 
-                bh_memcpy_s(applet_name, sizeof(applet_name), url_buf, p - url_buf);
-                app_manager_printf("Send request to tool agent of applet: %s\n", applet_name);
+            bh_memcpy_s(applet_name, sizeof(applet_name), url_buf, p - url_buf);
+            app_manager_printf("Send request to tool agent of applet: %s\n",
+                               applet_name);
+
+            /* Check applet name */
+            if (!(m_data = app_manager_lookup_module_data(applet_name))) {
+                SEND_ERR_RESPONSE(mid, "Send request to tool agent failed: "
+                                       "invalid applet name");
+                return false;
+            }
 
-                /* Check applet name */
-                if (!(m_data = app_manager_lookup_module_data(applet_name))) {
-                    SEND_ERR_RESPONSE(mid, "Send request to tool agent failed: invalid applet name");
+            applet_data = (jeff_applet_data *)m_data->internal_data;
+            /* Attach debug: start the tool agent firstly */
+            if (packet->code == COAP_PUT) {
+                if (is_tool_agent_running(m_data)) {
+                    SEND_ERR_RESPONSE(mid, "Attach debug failed: tool "
+                                           "agent is already exist.");
                     return false;
                 }
 
-                applet_data = (jeff_applet_data*)m_data->internal_data;
-                /* Attach debug: start the tool agent firstly */
-                if (packet->code == COAP_PUT) {
-                    if (is_tool_agent_running(m_data)) {
-                        SEND_ERR_RESPONSE(mid, "Attach debug failed: tool agent is already exist.");
-                        return false;
-                    }
-
-                    applet_data->debug_mode = true;
-
-                    /* Create tool agent queue */
-                    if (!(applet_data->tool_agent_queue = bh_queue_create())) {
-                        SEND_ERR_RESPONSE(mid, "Attach debug failed: create tool agent queue failed.");
-                        return false;
-                    }
-
-                    /* Start tool agent thread */
-                    if (!jeff_tool_start_agent(applet_data->vm_instance, applet_data->tool_agent_queue)) {
-                        bh_queue_destroy(applet_data->tool_agent_queue, NULL);
-                        SEND_ERR_RESPONSE(mid, "Attach debug failed: start tool agent failed");
-                        return false;
-                    }
-
-                    app_manager_printf("Attach debug: start tool agent of applet %s success.\n", applet_name);
-                    app_send_response_to_host(mid, CREATED_2_01, NULL); /* OK */
-                } else {
-                    /* Check tool agent running */
-                    if (!is_tool_agent_running(m_data)) {
-                        SEND_ERR_RESPONSE(mid, "Send request to tool agent failed: tool agent is not running");
-                        return false;
-                    }
-
-                    /* Create queue message for tool agent */
-                    if (!(tool_agent_msg = APP_MGR_MALLOC(sizeof(bh_queue_msg_t)))) {
-                        SEND_ERR_RESPONSE(mid, "Send request to tool agent failed: allocate memory failed");
-                        return false;
-                    }
-
-                    if (attr_cont)
-                    attr_cont_len = attr_container_get_serialize_length(attr_cont);
-
-                    req_msg_len = sizeof(bh_request_msg_t) + strlen(p) + 1 + attr_cont_len;
-
-                    /* Create request message */
-                    if (!(req_msg = APP_MGR_MALLOC(req_msg_len))) {
-                        SEND_ERR_RESPONSE(mid, "Send request to applet failed: allocate memory failed");
-                        APP_MGR_FREE(tool_agent_msg);
-                        return false;
-                    }
-
-                    /* Set request message */
-                    memset(req_msg, 0, req_msg_len);
-                    req_msg->mid = mid;
-                    req_msg->url = (char*)req_msg + sizeof(bh_request_msg_t);
-                    bh_strcpy_s(req_msg->url, strlen(p)+1, p); /* Actual url sent to tool agent */
-                    req_msg->action = packet->code;
-                    req_msg->fmt = 0;
-                    if (attr_cont) {
-                        req_msg->payload = (char*)req_msg + sizeof(bh_request_msg_t) +
-                        strlen(p) + 1;
-                        attr_container_serialize(req_msg->payload, attr_cont);
-                    }
-
-                    /* Set queue message and send to tool agent's queue */
-                    tool_agent_msg->message_type = JDWP_REQUEST;
-                    tool_agent_msg->payload_size = req_msg_len;
-                    tool_agent_msg->payload = (char*)req_msg;
-                    if (!bh_queue_send_message(applet_data->tool_agent_queue, tool_agent_msg)) {
-                        APP_MGR_FREE(req_msg);
-                        APP_MGR_FREE(tool_agent_msg);
-                        SEND_ERR_RESPONSE
-                        (mid, "Send request to tool agent failed: send queue msg failed.");
-                        return false;
-                    }
-
-                    /* app_manager_printf("Send request to tool agent of applet %s success.\n", applet_name); */
+                applet_data->debug_mode = true;
+
+                /* Create tool agent queue */
+                if (!(applet_data->tool_agent_queue = bh_queue_create())) {
+                    SEND_ERR_RESPONSE(mid, "Attach debug failed: create "
+                                           "tool agent queue failed.");
+                    return false;
                 }
 
-                return true;
+                /* Start tool agent thread */
+                if (!jeff_tool_start_agent(applet_data->vm_instance,
+                                           applet_data->tool_agent_queue)) {
+                    bh_queue_destroy(applet_data->tool_agent_queue, NULL);
+                    SEND_ERR_RESPONSE(
+                        mid, "Attach debug failed: start tool agent failed");
+                    return false;
+                }
+
+                app_manager_printf("Attach debug: start tool agent of "
+                                   "applet %s success.\n",
+                                   applet_name);
+                app_send_response_to_host(mid, CREATED_2_01, NULL); /* OK */
+            }
+            else {
+                /* Check tool agent running */
+                if (!is_tool_agent_running(m_data)) {
+                    SEND_ERR_RESPONSE(mid, "Send request to tool agent failed: "
+                                           "tool agent is not running");
+                    return false;
+                }
+
+                /* Create queue message for tool agent */
+                if (!(tool_agent_msg =
+                          APP_MGR_MALLOC(sizeof(bh_queue_msg_t)))) {
+                    SEND_ERR_RESPONSE(mid, "Send request to tool agent failed: "
+                                           "allocate memory failed");
+                    return false;
+                }
+
+                if (attr_cont)
+                    attr_cont_len =
+                        attr_container_get_serialize_length(attr_cont);
+
+                req_msg_len =
+                    sizeof(bh_request_msg_t) + strlen(p) + 1 + attr_cont_len;
+
+                /* Create request message */
+                if (!(req_msg = APP_MGR_MALLOC(req_msg_len))) {
+                    SEND_ERR_RESPONSE(mid, "Send request to applet failed: "
+                                           "allocate memory failed");
+                    APP_MGR_FREE(tool_agent_msg);
+                    return false;
+                }
+
+                /* Set request message */
+                memset(req_msg, 0, req_msg_len);
+                req_msg->mid = mid;
+                req_msg->url = (char *)req_msg + sizeof(bh_request_msg_t);
+                bh_strcpy_s(req_msg->url, strlen(p) + 1,
+                            p); /* Actual url sent to tool agent */
+                req_msg->action = packet->code;
+                req_msg->fmt = 0;
+                if (attr_cont) {
+                    req_msg->payload = (char *)req_msg
+                                       + sizeof(bh_request_msg_t) + strlen(p)
+                                       + 1;
+                    attr_container_serialize(req_msg->payload, attr_cont);
+                }
+
+                /* Set queue message and send to tool agent's queue */
+                tool_agent_msg->message_type = JDWP_REQUEST;
+                tool_agent_msg->payload_size = req_msg_len;
+                tool_agent_msg->payload = (char *)req_msg;
+                if (!bh_queue_send_message(applet_data->tool_agent_queue,
+                                           tool_agent_msg)) {
+                    APP_MGR_FREE(req_msg);
+                    APP_MGR_FREE(tool_agent_msg);
+                    SEND_ERR_RESPONSE(mid, "Send request to tool agent failed: "
+                                           "send queue msg failed.");
+                    return false;
+                }
+
+                /* app_manager_printf("Send request to tool agent of applet
+                 * %s success.\n", applet_name); */
             }
+
+            return true;
         }
-#endif /* BEIHAI_ENABLE_TOOL_AGENT != 0 */
-        return false;
     }
+#endif /* BEIHAI_ENABLE_TOOL_AGENT != 0 */
+    return false;
+}
 
-    static module_data*
-    jeff_module_get_module_data(void)
-    {
-        JeffThreadLocalRoot *self = jeff_runtime_get_tlr();
-        return (module_data *)self->il_root->start_routine_arg;
-    }
+static module_data *
+jeff_module_get_module_data(void)
+{
+    JeffThreadLocalRoot *self = jeff_runtime_get_tlr();
+    return (module_data *)self->il_root->start_routine_arg;
+}
 
 #if BEIHAI_ENABLE_TOOL_AGENT != 0
 
-#define JDWP_HANDSHAKE_MAGIC    "JDWP-Handshake"
-#define JDWP_HANDSHAKE_LEN      (sizeof (JDWP_HANDSHAKE_MAGIC) - 1)
+#define JDWP_HANDSHAKE_MAGIC "JDWP-Handshake"
+#define JDWP_HANDSHAKE_LEN (sizeof(JDWP_HANDSHAKE_MAGIC) - 1)
 
-#define JDWP_PAYLOAD_KEY        "jdwp"
+#define JDWP_PAYLOAD_KEY "jdwp"
 
-    static bool debug = true;
+static bool debug = true;
 
-    static bool
-    send_msg_to_host (int mid, const char *url, int code, const uint8 *msg, unsigned size)
-    {
-        bool ret;
-        int payload_len = 0;
-        attr_container_t *payload = NULL;
+static bool
+send_msg_to_host(int mid, const char *url, int code, const uint8 *msg,
+                 unsigned size)
+{
+    bool ret;
+    int payload_len = 0;
+    attr_container_t *payload = NULL;
 
-        if (msg) {
-            if ((payload = attr_container_create(""))) {
-                attr_container_set_bytearray(&payload, JDWP_PAYLOAD_KEY, (const int8_t *)msg, size);
-                payload_len = attr_container_get_serialize_length(payload);
-            }
+    if (msg) {
+        if ((payload = attr_container_create(""))) {
+            attr_container_set_bytearray(&payload, JDWP_PAYLOAD_KEY,
+                                         (const int8_t *)msg, size);
+            payload_len = attr_container_get_serialize_length(payload);
         }
-        ret = app_send_msg_to_host(mid, url, code, (char*)payload, payload_len);
+    }
+    ret = app_send_msg_to_host(mid, url, code, (char *)payload, payload_len);
 
-        if (payload)
+    if (payload)
         attr_container_destroy(payload);
 
-        return ret;
-    }
+    return ret;
+}
 
-    static bool
-    send_response(int mid, int code, const uint8 *msg, unsigned size)
-    {
-        return send_msg_to_host(mid, NULL, code, msg, size);
-    }
+static bool
+send_response(int mid, int code, const uint8 *msg, unsigned size)
+{
+    return send_msg_to_host(mid, NULL, code, msg, size);
+}
 
-    static bool
-    send_packet_response(int mid, int code, JeffBuffer *packet)
-    {
-        int size;
+static bool
+send_packet_response(int mid, int code, JeffBuffer *packet)
+{
+    int size;
 
-        if ((size = jeff_buffer_size(packet)) == 0)
+    if ((size = jeff_buffer_size(packet)) == 0)
         /* No data need to be written, succeed.  */
         return true;
 
-        return send_msg_to_host(mid, NULL, code, jeff_buffer_at(packet, 0), size);
-    }
+    return send_msg_to_host(mid, NULL, code, jeff_buffer_at(packet, 0), size);
+}
 
-    void
-    jeff_tool_event_publish(uint8 *evtbuf, unsigned size)
-    {
-        char *prefix = "/jdwp/", *url = NULL;
-        int url_len;
+void
+jeff_tool_event_publish(uint8 *evtbuf, unsigned size)
+{
+    char *prefix = "/jdwp/", *url = NULL;
+    int url_len;
 
-        url_len = strlen(prefix) + strlen(app_manager_get_module_name(Module_Jeff));
-        if (NULL == (url = jeff_runtime_malloc(url_len + 1)))
+    url_len = strlen(prefix) + strlen(app_manager_get_module_name(Module_Jeff));
+    if (NULL == (url = jeff_runtime_malloc(url_len + 1)))
         return;
 
-        bh_strcpy_s(url,url_len + 1, prefix);
-        bh_strcat_s(url,url_len + 1, app_manager_get_module_name(Module_Jeff));
+    bh_strcpy_s(url, url_len + 1, prefix);
+    bh_strcat_s(url, url_len + 1, app_manager_get_module_name(Module_Jeff));
 
-        /* Event is sent as request so we set code as COAP_PUT */
-        if (event_is_registered(url))
+    /* Event is sent as request so we set code as COAP_PUT */
+    if (event_is_registered(url))
         send_msg_to_host(0, url, COAP_PUT, evtbuf, size);
 
-        jeff_runtime_free(url);
-    }
-
-#define SEND_ERROR_RESPONSE(err_msg) do {                  \
-    app_manager_printf("%s\n", err_msg);                   \
-    send_response(req_msg->mid, INTERNAL_SERVER_ERROR_5_00,\
-                  (uint8 *)err_msg, strlen(err_msg) + 1);  \
-  } while (0)
-
-    /* Queue callback of tool agent */
-    void
-    tool_agent_queue_callback(void *arg)
-    {
-        bh_queue_msg_t *msg = (bh_queue_msg_t*)arg;
-
-        if (msg->message_type == JDWP_REQUEST) {
-            bh_request_msg_t *req_msg = (bh_request_msg_t*)msg->payload;
-            attr_container_t *attr_cont = (attr_container_t*)req_msg->payload;
-            JeffThreadLocalRoot *self = jeff_runtime_get_tlr();
-            JeffInstanceLocalRoot *cur_instance = self->il_root;
-            JeffToolAgent *agent = cur_instance->tool_agent;
-            bh_queue *queue = (bh_queue *)self->start_routine_arg;
-
-            if (debug)
-            app_manager_printf("Tool Agent of applet %s got request, url %s, action %d\n",
-            app_manager_get_module_name(Module_Jeff), req_msg->url, req_msg->action);
-
-            /* Handshake or Process Request */
-            if (req_msg->action == COAP_GET) {
-                uint8 *buf;
-                unsigned buf_len;
-
-                if (!attr_cont
-                || !(buf = (uint8*)
-                        attr_container_get_as_bytearray(attr_cont, JDWP_PAYLOAD_KEY, &buf_len))) {
-                    SEND_ERROR_RESPONSE("Tool Agent fail: invalid JDWP payload.");
+    jeff_runtime_free(url);
+}
+
+#define SEND_ERROR_RESPONSE(err_msg)                            \
+    do {                                                        \
+        app_manager_printf("%s\n", err_msg);                    \
+        send_response(req_msg->mid, INTERNAL_SERVER_ERROR_5_00, \
+                      (uint8 *)err_msg, strlen(err_msg) + 1);   \
+    } while (0)
+
+/* Queue callback of tool agent */
+void
+tool_agent_queue_callback(void *arg)
+{
+    bh_queue_msg_t *msg = (bh_queue_msg_t *)arg;
+
+    if (msg->message_type == JDWP_REQUEST) {
+        bh_request_msg_t *req_msg = (bh_request_msg_t *)msg->payload;
+        attr_container_t *attr_cont = (attr_container_t *)req_msg->payload;
+        JeffThreadLocalRoot *self = jeff_runtime_get_tlr();
+        JeffInstanceLocalRoot *cur_instance = self->il_root;
+        JeffToolAgent *agent = cur_instance->tool_agent;
+        bh_queue *queue = (bh_queue *)self->start_routine_arg;
+
+        if (debug)
+            app_manager_printf(
+                "Tool Agent of applet %s got request, url %s, action %d\n",
+                app_manager_get_module_name(Module_Jeff), req_msg->url,
+                req_msg->action);
+
+        /* Handshake or Process Request */
+        if (req_msg->action == COAP_GET) {
+            uint8 *buf;
+            unsigned buf_len;
+
+            if (!attr_cont
+                || !(buf = (uint8 *)attr_container_get_as_bytearray(
+                         attr_cont, JDWP_PAYLOAD_KEY, &buf_len))) {
+                SEND_ERROR_RESPONSE("Tool Agent fail: invalid JDWP payload.");
+                goto fail;
+            }
+
+            if (!agent->connected) {
+                if (buf_len != JDWP_HANDSHAKE_LEN
+                    || memcmp(buf, JDWP_HANDSHAKE_MAGIC, JDWP_HANDSHAKE_LEN)) {
+                    SEND_ERROR_RESPONSE("Tool Agent fail: handshake fail.");
                     goto fail;
                 }
 
-                if (!agent->connected) {
-                    if (buf_len != JDWP_HANDSHAKE_LEN
-                    || memcmp (buf, JDWP_HANDSHAKE_MAGIC, JDWP_HANDSHAKE_LEN)) {
-                        SEND_ERROR_RESPONSE("Tool Agent fail: handshake fail.");
-                        goto fail;
-                    }
-
-                    /* Handshake success and response */
-                    agent->connected = true;
-                    send_response(req_msg->mid, CONTENT_2_05, buf, buf_len);
-                } else {
-                    /* TODO: tool-agent thread should reuse the request/reply buffer to avoid allocating memory repeatedly */
-                    JeffBuffer request, reply;
-
-                    /* Initialize the package buffers. */
-                    jeff_buffer_init(&request);
-                    jeff_buffer_init(&reply);
-
-                    if (!jeff_buffer_resize(&request, buf_len)) {
-                        SEND_ERROR_RESPONSE("Tool Agent fail: resize buffer fail.");
-                        jeff_buffer_destroy(&request);
-                        jeff_buffer_destroy(&reply);
-                        goto fail;
-                    }
-
-                    /* Copy data from request to jeff buffer */
-                    bh_memcpy_s(jeff_buffer_at(&request, 0), jeff_buffer_size(&request), buf, buf_len);
-
-                    /* Handle JDWP request */
-                    if (!jeff_tool_handle_packet(agent, &request, &reply)) {
-                        SEND_ERROR_RESPONSE("Tool agent fail: handle request fail.");
-                        jeff_buffer_destroy(&request);
-                        jeff_buffer_destroy(&reply);
-                        goto fail;
-                    }
-
-                    /* Response JDWP reply */
-                    send_packet_response(req_msg->mid, CONTENT_2_05, &reply);
-
-                    /* Destroy the package buffers. */
+                /* Handshake success and response */
+                agent->connected = true;
+                send_response(req_msg->mid, CONTENT_2_05, buf, buf_len);
+            }
+            else {
+                /* TODO: tool-agent thread should reuse the request/reply
+                 * buffer to avoid allocating memory repeatedly */
+                JeffBuffer request, reply;
+
+                /* Initialize the package buffers. */
+                jeff_buffer_init(&request);
+                jeff_buffer_init(&reply);
+
+                if (!jeff_buffer_resize(&request, buf_len)) {
+                    SEND_ERROR_RESPONSE("Tool Agent fail: resize buffer fail.");
                     jeff_buffer_destroy(&request);
                     jeff_buffer_destroy(&reply);
+                    goto fail;
                 }
-            }
-            /* Debugger disconnect */
-            else if (req_msg->action == COAP_DELETE) {
-                send_response(req_msg->mid, DELETED_2_02, NULL, 0);
-                bh_queue_exit_loop_run(queue);
-            }
-            else {
-                SEND_ERROR_RESPONSE("Tool agent fail: invalid request.");
-                goto fail;
-            }
 
-            APP_MGR_FREE(req_msg);
-            APP_MGR_FREE(msg);
-            return;
+                /* Copy data from request to jeff buffer */
+                bh_memcpy_s(jeff_buffer_at(&request, 0),
+                            jeff_buffer_size(&request), buf, buf_len);
+
+                /* Handle JDWP request */
+                if (!jeff_tool_handle_packet(agent, &request, &reply)) {
+                    SEND_ERROR_RESPONSE(
+                        "Tool agent fail: handle request fail.");
+                    jeff_buffer_destroy(&request);
+                    jeff_buffer_destroy(&reply);
+                    goto fail;
+                }
+
+                /* Response JDWP reply */
+                send_packet_response(req_msg->mid, CONTENT_2_05, &reply);
 
-            fail:
+                /* Destroy the package buffers. */
+                jeff_buffer_destroy(&request);
+                jeff_buffer_destroy(&reply);
+            }
+        }
+        /* Debugger disconnect */
+        else if (req_msg->action == COAP_DELETE) {
+            send_response(req_msg->mid, DELETED_2_02, NULL, 0);
             bh_queue_exit_loop_run(queue);
-            APP_MGR_FREE(req_msg);
+        }
+        else {
+            SEND_ERROR_RESPONSE("Tool agent fail: invalid request.");
+            goto fail;
         }
 
+        APP_MGR_FREE(req_msg);
         APP_MGR_FREE(msg);
+        return;
+
+    fail:
+        bh_queue_exit_loop_run(queue);
+        APP_MGR_FREE(req_msg);
     }
 
-    void
-    tool_agent_queue_free_callback(void *message)
-    {
-        bh_queue_msg_t *msg = (bh_queue_msg_t*)message;
+    APP_MGR_FREE(msg);
+}
 
-        if (msg->message_type == JDWP_REQUEST) {
-            bh_request_msg_t *req_msg = (bh_request_msg_t*)msg->payload;
-            APP_MGR_FREE(req_msg);
-        }
+void
+tool_agent_queue_free_callback(void *message)
+{
+    bh_queue_msg_t *msg = (bh_queue_msg_t *)message;
 
-        APP_MGR_FREE(msg);
+    if (msg->message_type == JDWP_REQUEST) {
+        bh_request_msg_t *req_msg = (bh_request_msg_t *)msg->payload;
+        APP_MGR_FREE(req_msg);
     }
 
-#endif  /* BEIHAI_ENABLE_TOOL_AGENT != 0 */
+    APP_MGR_FREE(msg);
+}
 
-    module_interface jeff_module_interface = {
-        jeff_module_init,
-        jeff_module_install,
-        jeff_module_uninstall,
-        jeff_module_watchdog_kill,
-        jeff_module_handle_host_url,
-        jeff_module_get_module_data,
-        NULL
-    };
+#endif /* BEIHAI_ENABLE_TOOL_AGENT != 0 */
+
+/* clang-format off */
+module_interface jeff_module_interface = {
+    jeff_module_init,
+    jeff_module_install,
+    jeff_module_uninstall,
+    jeff_module_watchdog_kill,
+    jeff_module_handle_host_url,
+    jeff_module_get_module_data,
+    NULL
+};
+/* clang-format on */
 
 #endif

+ 34 - 23
core/app-mgr/app-manager/module_utils.c

@@ -17,13 +17,15 @@ korp_mutex module_data_list_lock;
 /* Module data list */
 module_data *module_data_list;
 
-bool module_data_list_init()
+bool
+module_data_list_init()
 {
     module_data_list = NULL;
     return !os_mutex_init(&module_data_list_lock) ? true : false;
 }
 
-void module_data_list_destroy()
+void
+module_data_list_destroy()
 {
 
     os_mutex_lock(&module_data_list_lock);
@@ -38,7 +40,8 @@ void module_data_list_destroy()
     os_mutex_destroy(&module_data_list_lock);
 }
 
-static void module_data_list_add(module_data *m_data)
+static void
+module_data_list_add(module_data *m_data)
 {
     static uint32 module_id_max = 1;
     os_mutex_lock(&module_data_list_lock);
@@ -49,7 +52,8 @@ static void module_data_list_add(module_data *m_data)
     m_data->id = module_id_max++;
     if (!module_data_list) {
         module_data_list = m_data;
-    } else {
+    }
+    else {
         /* Set as head */
         m_data->next = module_data_list;
         module_data_list = m_data;
@@ -57,7 +61,8 @@ static void module_data_list_add(module_data *m_data)
     os_mutex_unlock(&module_data_list_lock);
 }
 
-void module_data_list_remove(module_data *m_data)
+void
+module_data_list_remove(module_data *m_data)
 {
     os_mutex_lock(&module_data_list_lock);
     if (module_data_list) {
@@ -76,7 +81,7 @@ void module_data_list_remove(module_data *m_data)
     os_mutex_unlock(&module_data_list_lock);
 }
 
-module_data*
+module_data *
 module_data_list_lookup(const char *module_name)
 {
     os_mutex_lock(&module_data_list_lock);
@@ -96,7 +101,7 @@ module_data_list_lookup(const char *module_name)
     return NULL;
 }
 
-module_data*
+module_data *
 module_data_list_lookup_id(unsigned int module_id)
 {
     os_mutex_lock(&module_data_list_lock);
@@ -119,72 +124,78 @@ module_data_list_lookup_id(unsigned int module_id)
 module_data *
 app_manager_get_module_data(uint32 module_type, void *module_inst)
 {
-    if (module_type < Module_Max
-        && g_module_interfaces[module_type]
+    if (module_type < Module_Max && g_module_interfaces[module_type]
         && g_module_interfaces[module_type]->module_get_module_data)
-        return g_module_interfaces[module_type]->module_get_module_data(module_inst);
+        return g_module_interfaces[module_type]->module_get_module_data(
+            module_inst);
     return NULL;
 }
 
-void*
+void *
 app_manager_get_module_queue(uint32 module_type, void *module_inst)
 {
     module_data *m_data = app_manager_get_module_data(module_type, module_inst);
     return m_data ? m_data->queue : NULL;
 }
 
-const char*
+const char *
 app_manager_get_module_name(uint32 module_type, void *module_inst)
 {
     module_data *m_data = app_manager_get_module_data(module_type, module_inst);
     return m_data ? m_data->module_name : NULL;
 }
 
-unsigned int app_manager_get_module_id(uint32 module_type, void *module_inst)
+unsigned int
+app_manager_get_module_id(uint32 module_type, void *module_inst)
 {
     module_data *m_data = app_manager_get_module_data(module_type, module_inst);
     return m_data ? m_data->id : ID_NONE;
 }
 
-void*
+void *
 app_manager_get_module_heap(uint32 module_type, void *module_inst)
 {
     module_data *m_data = app_manager_get_module_data(module_type, module_inst);
     return m_data ? m_data->heap : NULL;
 }
 
-module_data*
+module_data *
 app_manager_lookup_module_data(const char *name)
 {
     return module_data_list_lookup(name);
 }
 
-void app_manager_add_module_data(module_data *m_data)
+void
+app_manager_add_module_data(module_data *m_data)
 {
     module_data_list_add(m_data);
 }
 
-void app_manager_del_module_data(module_data *m_data)
+void
+app_manager_del_module_data(module_data *m_data)
 {
     module_data_list_remove(m_data);
 
     release_module(m_data);
 }
 
-bool app_manager_is_interrupting_module(uint32 module_type, void *module_inst)
+bool
+app_manager_is_interrupting_module(uint32 module_type, void *module_inst)
 {
     module_data *m_data = app_manager_get_module_data(module_type, module_inst);
     return m_data ? m_data->wd_timer.is_interrupting : false;
 }
 
-extern void destroy_module_timer_ctx(unsigned int module_id);
+extern void
+destroy_module_timer_ctx(unsigned int module_id);
 
-void release_module(module_data *m_data)
+void
+release_module(module_data *m_data)
 {
     watchdog_timer_destroy(&m_data->wd_timer);
 
 #ifdef HEAP_ENABLED /* TODO */
-    if(m_data->heap)
+    if (m_data->heap)
         gc_destroy_for_instance(m_data->heap);
 #endif
 
@@ -198,7 +209,8 @@ void release_module(module_data *m_data)
     APP_MGR_FREE(m_data);
 }
 
-uint32 check_modules_timer_expiry()
+uint32
+check_modules_timer_expiry()
 {
     os_mutex_lock(&module_data_list_lock);
     module_data *p = module_data_list;
@@ -216,4 +228,3 @@ uint32 check_modules_timer_expiry()
     os_mutex_unlock(&module_data_list_lock);
     return ms_to_expiry;
 }
-

文件差异内容过多而无法显示
+ 300 - 277
core/app-mgr/app-manager/module_wasm_app.c


+ 8 - 6
core/app-mgr/app-manager/module_wasm_app.h

@@ -56,7 +56,7 @@ typedef struct wasm_data {
     /* thread list mapped with this WASM module */
     korp_tid thread_id;
     /* for easily access the containing module data */
-    module_data* m_data;
+    module_data *m_data;
     /* is bytecode or aot */
     bool is_bytecode;
     /* sections of wasm bytecode or aot file */
@@ -109,16 +109,18 @@ typedef struct wasm_app_file_t {
 extern module_interface wasm_app_module_interface;
 
 typedef void (*message_type_handler_t)(module_data *m_data, bh_message_t msg);
-extern bool wasm_register_msg_callback(int msg_type,
-        message_type_handler_t message_handler);
+extern bool
+wasm_register_msg_callback(int msg_type,
+                           message_type_handler_t message_handler);
 
 typedef void (*resource_cleanup_handler_t)(uint32 module_id);
-extern bool wasm_register_cleanup_callback(resource_cleanup_handler_t handler);
+extern bool
+wasm_register_cleanup_callback(resource_cleanup_handler_t handler);
 
 /**
  * Set WASI root dir for modules. On each wasm app installation, a sub dir named
- * with the app's name will be created autamically. That wasm app can only access
- * this sub dir.
+ * with the app's name will be created autamically. That wasm app can only
+ * access this sub dir.
  *
  * @param root_dir the root dir to set
  * @return true for success, false otherwise

+ 27 - 18
core/app-mgr/app-manager/module_wasm_lib.c

@@ -3,47 +3,56 @@
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  */
 
-
 #include "module_wasm_lib.h"
 
-static bool wasm_lib_module_init(void)
+static bool
+wasm_lib_module_init(void)
 {
     return false;
 }
 
-static bool wasm_lib_module_install(request_t *msg)
+static bool
+wasm_lib_module_install(request_t *msg)
 {
-    (void) msg;
+    (void)msg;
     return false;
 }
 
-static bool wasm_lib_module_uninstall(request_t *msg)
+static bool
+wasm_lib_module_uninstall(request_t *msg)
 {
-    (void) msg;
+    (void)msg;
     return false;
 }
 
-static void wasm_lib_module_watchdog_kill(module_data *m_data)
+static void
+wasm_lib_module_watchdog_kill(module_data *m_data)
 {
-    (void) m_data;
+    (void)m_data;
 }
 
-static bool wasm_lib_module_handle_host_url(void *queue_msg)
+static bool
+wasm_lib_module_handle_host_url(void *queue_msg)
 {
-    (void) queue_msg;
+    (void)queue_msg;
     return false;
 }
 
-static module_data*
+static module_data *
 wasm_lib_module_get_module_data(void *inst)
 {
-    (void) inst;
+    (void)inst;
     return NULL;
 }
 
-module_interface wasm_lib_module_interface = { wasm_lib_module_init,
-        wasm_lib_module_install, wasm_lib_module_uninstall,
-        wasm_lib_module_watchdog_kill, wasm_lib_module_handle_host_url,
-        wasm_lib_module_get_module_data,
-        NULL };
-
+/* clang-format off */
+module_interface wasm_lib_module_interface = {
+    wasm_lib_module_init,
+    wasm_lib_module_install,
+    wasm_lib_module_uninstall,
+    wasm_lib_module_watchdog_kill,
+    wasm_lib_module_handle_host_url,
+    wasm_lib_module_get_module_data,
+    NULL
+};
+/* clang-format on */

+ 12 - 9
core/app-mgr/app-manager/platform/linux/app_mgr_linux.c

@@ -5,25 +5,28 @@
 
 #include "app_manager.h"
 
-void*
-app_manager_timer_create(void (*timer_callback)(void*),
-        watchdog_timer *wd_timer)
+void *
+app_manager_timer_create(void (*timer_callback)(void *),
+                         watchdog_timer *wd_timer)
 {
     /* TODO */
     return NULL;
 }
 
-void app_manager_timer_destroy(void *timer)
+void
+app_manager_timer_destroy(void *timer)
 {
     /* TODO */
 }
 
-void app_manager_timer_start(void *timer, int timeout)
+void
+app_manager_timer_start(void *timer, int timeout)
 {
     /* TODO */
 }
 
-void app_manager_timer_stop(void *timer)
+void
+app_manager_timer_stop(void *timer)
 {
     /* TODO */
 }
@@ -35,9 +38,9 @@ app_manager_get_wd_timer_from_timer_handle(void *timer)
     return NULL;
 }
 
-int app_manager_signature_verify(const uint8_t *file, unsigned int file_len,
-        const uint8_t *signature, unsigned int sig_size)
+int
+app_manager_signature_verify(const uint8_t *file, unsigned int file_len,
+                             const uint8_t *signature, unsigned int sig_size)
 {
     return 1;
 }
-

+ 14 - 10
core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c

@@ -16,32 +16,36 @@ typedef struct k_timer_watchdog {
     watchdog_timer *wd_timer;
 } k_timer_watchdog;
 
-void*
-app_manager_timer_create(void (*timer_callback)(void*),
-        watchdog_timer *wd_timer)
+void *
+app_manager_timer_create(void (*timer_callback)(void *),
+                         watchdog_timer *wd_timer)
 {
-    struct k_timer_watchdog *timer = APP_MGR_MALLOC(sizeof(struct k_timer_watchdog));
+    struct k_timer_watchdog *timer =
+        APP_MGR_MALLOC(sizeof(struct k_timer_watchdog));
 
     if (timer) {
-        k_timer_init(&timer->timer, (void (*)(struct k_timer*)) timer_callback,
-        NULL);
+        k_timer_init(&timer->timer, (void (*)(struct k_timer *))timer_callback,
+                     NULL);
         timer->wd_timer = wd_timer;
     }
 
     return timer;
 }
 
-void app_manager_timer_destroy(void *timer)
+void
+app_manager_timer_destroy(void *timer)
 {
     APP_MGR_FREE(timer);
 }
 
-void app_manager_timer_start(void *timer, int timeout)
+void
+app_manager_timer_start(void *timer, int timeout)
 {
     k_timer_start(timer, Z_TIMEOUT_MS(timeout), Z_TIMEOUT_MS(0));
 }
 
-void app_manager_timer_stop(void *timer)
+void
+app_manager_timer_stop(void *timer)
 {
     k_timer_stop(timer);
 }
@@ -49,7 +53,7 @@ void app_manager_timer_stop(void *timer)
 watchdog_timer *
 app_manager_get_wd_timer_from_timer_handle(void *timer)
 {
-    return ((k_timer_watchdog*) timer)->wd_timer;
+    return ((k_timer_watchdog *)timer)->wd_timer;
 }
 #if 0
 int app_manager_signature_verify(const uint8_t *file, unsigned int file_len,

+ 31 - 24
core/app-mgr/app-manager/resource_reg.c

@@ -3,7 +3,6 @@
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  */
 
-
 #include "native_interface.h"
 #include "app_manager.h"
 #include "app_manager_export.h"
@@ -13,14 +12,15 @@
 
 typedef struct _app_res_register {
     struct _app_res_register *next;
-    char * url;
+    char *url;
     void (*request_handler)(request_t *, void *);
     uint32 register_id;
 } app_res_register_t;
 
-static app_res_register_t * g_resources = NULL;
+static app_res_register_t *g_resources = NULL;
 
-void module_request_handler(request_t *request, void *user_data)
+void
+module_request_handler(request_t *request, void *user_data)
 {
     unsigned int mod_id = (unsigned int)(uintptr_t)user_data;
     bh_message_t msg;
@@ -54,10 +54,11 @@ void module_request_handler(request_t *request, void *user_data)
     }
 
     app_manager_printf("Send request to app %s success.\n",
-            m_data->module_name);
+                       m_data->module_name);
 }
 
-void targeted_app_request_handler(request_t *request, void *unused)
+void
+targeted_app_request_handler(request_t *request, void *unused)
 {
     char applet_name[128] = { 0 };
     int offset;
@@ -74,7 +75,8 @@ void targeted_app_request_handler(request_t *request, void *unused)
     char *p = strchr(applet_name, '/');
     if (p) {
         *p = 0;
-    } else
+    }
+    else
         return;
     app_manager_printf("Send request to applet: %s\n", applet_name);
 
@@ -84,16 +86,17 @@ void targeted_app_request_handler(request_t *request, void *unused)
     m_data = module_data_list_lookup(applet_name);
     if (!m_data) {
         SEND_ERR_RESPONSE(request->mid,
-                "Send request to applet failed: invalid applet name");
+                          "Send request to applet failed: invalid applet name");
         goto end;
     }
 
     module_request_handler(request, (void *)(uintptr_t)m_data->id);
-    end: request->url = url;
-
+end:
+    request->url = url;
 }
 
-void am_send_response(response_t *response)
+void
+am_send_response(response_t *response)
 {
     module_data *m_data;
 
@@ -101,15 +104,15 @@ void am_send_response(response_t *response)
     m_data = module_data_list_lookup_id(response->reciever);
     if (!m_data) {
         send_response_to_host(response);
-
-    } else {
-        response_t * resp_for_send = clone_response(response);
+    }
+    else {
+        response_t *resp_for_send = clone_response(response);
         if (!resp_for_send) {
             return;
         }
 
         bh_message_t msg = bh_new_msg(RESTFUL_RESPONSE, resp_for_send,
-                sizeof(*resp_for_send), response_cleaner);
+                                      sizeof(*resp_for_send), response_cleaner);
         if (!msg) {
             response_cleaner(resp_for_send);
             return;
@@ -121,7 +124,8 @@ void am_send_response(response_t *response)
     }
 }
 
-void * am_dispatch_request(request_t *request)
+void *
+am_dispatch_request(request_t *request)
 {
     app_res_register_t *r = g_resources;
 
@@ -135,11 +139,12 @@ void * am_dispatch_request(request_t *request)
     return NULL;
 }
 
-bool am_register_resource(const char *url,
-                          void (*request_handler)(request_t *, void *),
-                          uint32 register_id)
+bool
+am_register_resource(const char *url,
+                     void (*request_handler)(request_t *, void *),
+                     uint32 register_id)
 {
-    app_res_register_t * r = g_resources;
+    app_res_register_t *r = g_resources;
     int register_num = 0;
 
     while (r) {
@@ -178,10 +183,11 @@ bool am_register_resource(const char *url,
     return true;
 }
 
-void am_cleanup_registeration(uint32 register_id)
+void
+am_cleanup_registeration(uint32 register_id)
 {
-    app_res_register_t * r = g_resources;
-    app_res_register_t * prev = NULL;
+    app_res_register_t *r = g_resources;
+    app_res_register_t *prev = NULL;
 
     while (r) {
         app_res_register_t *next = r->next;
@@ -194,7 +200,8 @@ void am_cleanup_registeration(uint32 register_id)
 
             APP_MGR_FREE(r->url);
             APP_MGR_FREE(r);
-        } else
+        }
+        else
             /* if r is freed, should not change prev. Only set prev to r
              when r isn't freed. */
             prev = r;

+ 27 - 19
core/app-mgr/app-manager/watchdog.c

@@ -12,10 +12,11 @@
 static bh_queue *watchdog_queue;
 
 #ifdef WATCHDOG_ENABLED /* TODO */
-static void watchdog_timer_callback(void *timer)
+static void
+watchdog_timer_callback(void *timer)
 {
-    watchdog_timer *wd_timer = app_manager_get_wd_timer_from_timer_handle(
-            timer);
+    watchdog_timer *wd_timer =
+        app_manager_get_wd_timer_from_timer_handle(timer);
 
     watchdog_timer_stop(wd_timer);
 
@@ -26,14 +27,15 @@ static void watchdog_timer_callback(void *timer)
         wd_timer->is_interrupting = true;
 
         bh_post_msg(watchdog_queue, WD_TIMEOUT, wd_timer->module_data,
-                sizeof(module_data));
+                    sizeof(module_data));
     }
 
     os_mutex_unlock(&wd_timer->lock);
 }
 #endif
 
-bool watchdog_timer_init(module_data *m_data)
+bool
+watchdog_timer_init(module_data *m_data)
 {
 #ifdef WATCHDOG_ENABLED /* TODO */
     watchdog_timer *wd_timer = &m_data->wd_timer;
@@ -42,7 +44,7 @@ bool watchdog_timer_init(module_data *m_data)
         return false;
 
     if (!(wd_timer->timer_handle =
-                    app_manager_timer_create(watchdog_timer_callback, wd_timer))) {
+              app_manager_timer_create(watchdog_timer_callback, wd_timer))) {
         os_mutex_destroy(&wd_timer->lock);
         return false;
     }
@@ -54,7 +56,8 @@ bool watchdog_timer_init(module_data *m_data)
     return true;
 }
 
-void watchdog_timer_destroy(watchdog_timer *wd_timer)
+void
+watchdog_timer_destroy(watchdog_timer *wd_timer)
 {
 #ifdef WATCHDOG_ENABLED /* TODO */
     app_manager_timer_destroy(wd_timer->timer_handle);
@@ -62,32 +65,35 @@ void watchdog_timer_destroy(watchdog_timer *wd_timer)
 #endif
 }
 
-void watchdog_timer_start(watchdog_timer *wd_timer)
+void
+watchdog_timer_start(watchdog_timer *wd_timer)
 {
     os_mutex_lock(&wd_timer->lock);
 
     wd_timer->is_interrupting = false;
     wd_timer->is_stopped = false;
     app_manager_timer_start(wd_timer->timer_handle,
-            wd_timer->module_data->timeout);
+                            wd_timer->module_data->timeout);
 
     os_mutex_unlock(&wd_timer->lock);
 }
 
-void watchdog_timer_stop(watchdog_timer *wd_timer)
+void
+watchdog_timer_stop(watchdog_timer *wd_timer)
 {
     app_manager_timer_stop(wd_timer->timer_handle);
 }
 
 #ifdef WATCHDOG_ENABLED /* TODO */
-static void watchdog_queue_callback(void *queue_msg)
+static void
+watchdog_queue_callback(void *queue_msg)
 {
     if (bh_message_type(queue_msg) == WD_TIMEOUT) {
-        module_data *m_data = (module_data *) bh_message_payload(queue_msg);
+        module_data *m_data = (module_data *)bh_message_payload(queue_msg);
         if (g_module_interfaces[m_data->module_type]
-                && g_module_interfaces[m_data->module_type]->module_watchdog_kill) {
+            && g_module_interfaces[m_data->module_type]->module_watchdog_kill) {
             g_module_interfaces[m_data->module_type]->module_watchdog_kill(
-                    m_data);
+                m_data);
             app_manager_post_applets_update_event();
         }
     }
@@ -95,22 +101,23 @@ static void watchdog_queue_callback(void *queue_msg)
 #endif
 
 #ifdef WATCHDOG_ENABLED /* TODO */
-static void*
+static void *
 watchdog_thread_routine(void *arg)
 {
     /* Enter loop run */
     bh_queue_enter_loop_run(watchdog_queue, watchdog_queue_callback);
 
-    (void) arg;
+    (void)arg;
     return NULL;
 }
 #endif
 
-bool watchdog_startup()
+bool
+watchdog_startup()
 {
     if (!(watchdog_queue = bh_queue_create())) {
         app_manager_printf(
-                "App Manager start failed: create watchdog queue failed.\n");
+            "App Manager start failed: create watchdog queue failed.\n");
         return false;
     }
 #if 0
@@ -125,7 +132,8 @@ bool watchdog_startup()
     return true;
 }
 
-void watchdog_destroy()
+void
+watchdog_destroy()
 {
     bh_queue_exit_loop_run(watchdog_queue);
     bh_queue_destroy(watchdog_queue);

+ 1 - 2
core/app-mgr/app-manager/watchdog.h

@@ -3,7 +3,6 @@
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  */
 
-
 #ifndef _WATCHDOG_H_
 #define _WATCHDOG_H_
 
@@ -25,7 +24,7 @@ watchdog_timer_start(watchdog_timer *wd_timer);
 void
 watchdog_timer_stop(watchdog_timer *wd_timer);
 
-watchdog_timer*
+watchdog_timer *
 app_manager_get_watchdog_timer(void *timer);
 
 bool

+ 27 - 18
core/app-mgr/app-mgr-shared/app_manager_export.h

@@ -20,7 +20,7 @@ extern "C" {
 #define ID_HOST -3
 #define ID_APP_MGR -2
 /* Invalid module ID */
-#define ID_NONE (uint32)-1
+#define ID_NONE ((uint32)-1)
 
 struct attr_container_t;
 
@@ -40,7 +40,10 @@ typedef enum QUEUE_MSG_TYPE {
 } QUEUE_MSG_TYPE;
 
 typedef enum {
-    Module_Jeff, Module_WASM_App, Module_WASM_Lib, Module_Max
+    Module_Jeff,
+    Module_WASM_App,
+    Module_WASM_Lib,
+    Module_Max
 } Module_Type;
 
 struct module_data;
@@ -111,12 +114,13 @@ typedef module_data *(*module_get_module_data_func)(void *inst);
  *
  * @param ch the byte to be received and handled
  * @param total_size total size of the request
- * @param received_total_size currently received total size when the function return
+ * @param received_total_size currently received total size when
+ *        the function return
  *
  * @return true if success, false otherwise
  */
-typedef bool (*module_on_install_request_byte_arrive_func) (
-        uint8 ch, int total_size, int *received_total_size);
+typedef bool (*module_on_install_request_byte_arrive_func)(
+    uint8 ch, int total_size, int *received_total_size);
 
 /* Interfaces of each module */
 typedef struct module_interface {
@@ -148,7 +152,7 @@ typedef bool (*host_init_func)(void);
  *
  * @return size of the data sent in bytes
  */
-typedef int (*host_send_fun)(void * ctx, const char *buf, int size);
+typedef int (*host_send_fun)(void *ctx, const char *buf, int size);
 
 /**
  * @typedef host_destroy_fun
@@ -191,22 +195,22 @@ app_manager_get_module_name(uint32 module_type, void *module_inst);
 void *
 app_manager_get_module_heap(uint32 module_type, void *module_inst);
 
-void*
+void *
 get_app_manager_queue();
 
-module_data*
+module_data *
 app_manager_get_module_data(uint32 module_type, void *module_inst);
 
 unsigned int
 app_manager_get_module_id(uint32 module_type, void *module_inst);
 
-module_data*
+module_data *
 app_manager_lookup_module_data(const char *name);
 
-module_data*
+module_data *
 module_data_list_lookup(const char *module_name);
 
-module_data*
+module_data *
 module_data_list_lookup_id(unsigned int module_id);
 
 void
@@ -214,9 +218,11 @@ app_manager_post_applets_update_event();
 
 bool
 am_register_resource(const char *url,
-        void (*request_handler)(request_t *, void *), uint32 register_id);
+                     void (*request_handler)(request_t *, void *),
+                     uint32 register_id);
 
-void am_cleanup_registeration(uint32 register_id);
+void
+am_cleanup_registeration(uint32 register_id);
 
 bool
 am_register_event(const char *url, uint32_t reg_client);
@@ -224,13 +230,17 @@ am_register_event(const char *url, uint32_t reg_client);
 bool
 am_unregister_event(const char *url, uint32_t reg_client);
 
-void am_publish_event(request_t * event);
+void
+am_publish_event(request_t *event);
 
-void * am_dispatch_request(request_t *request);
+void *
+am_dispatch_request(request_t *request);
 
-void am_send_response(response_t *response);
+void
+am_send_response(response_t *response);
 
-void module_request_handler(request_t *request, void *user_data);
+void
+module_request_handler(request_t *request, void *user_data);
 
 /**
  * Send request message to host
@@ -291,4 +301,3 @@ app_manager_host_send_msg(int msg_type, const char *buf, int size);
 #endif
 
 #endif
-

+ 3 - 3
core/iwasm/aot/arch/aot_reloc_x86_32.c

@@ -5,9 +5,9 @@
 
 #include "aot_reloc.h"
 
-#define R_386_32 1   /* Direct 32 bit  */
-#define R_386_PC32 2 /* PC relative 32 bit */
-#define R_386_PLT32 4 /* 32bit address ProcedureLinkageTable */
+#define R_386_32 1    /* Direct 32 bit  */
+#define R_386_PC32 2  /* PC relative 32 bit */
+#define R_386_PLT32 4 /* 32-bit address ProcedureLinkageTable */
 
 #if !defined(_WIN32) && !defined(_WIN32_)
 /* clang-format off */

+ 1 - 1
doc/build_wamr.md

@@ -302,7 +302,7 @@ Zephyr
 You need to download the Zephyr source code first and embed WAMR into it.
 ``` Bash
 git clone https://github.com/zephyrproject-rtos/zephyr.git
-source ../zephyr-env.sh
+source zephyr/zephyr-env.sh
 cd <wamr_root_dir>/product-mini/platforms/zephyr/simple
 # Execute the ./build_and_run.sh script with board name as parameter. Here take x86 as example:
 ./build_and_run.sh x86

+ 30 - 30
test-tools/binarydump-tool/binarydump.c

@@ -8,30 +8,30 @@
 #include <stdbool.h>
 #include <string.h>
 
-static unsigned char*
-read_file_to_buffer (const char *filename, int *ret_size)
+static unsigned char *
+read_file_to_buffer(const char *filename, int *ret_size)
 {
     unsigned char *buffer;
     FILE *file;
     int file_size, read_size;
 
-    if (!(file = fopen (filename, "r")))
+    if (!(file = fopen(filename, "r")))
         return NULL;
 
-    fseek (file, 0, SEEK_END);
-    file_size = ftell (file);
-    fseek (file, 0, SEEK_SET);
+    fseek(file, 0, SEEK_END);
+    file_size = ftell(file);
+    fseek(file, 0, SEEK_SET);
 
-    if (!(buffer = malloc (file_size))) {
-        fclose (file);
+    if (!(buffer = malloc(file_size))) {
+        fclose(file);
         return NULL;
     }
 
-    read_size = fread (buffer, 1, file_size, file);
-    fclose (file);
+    read_size = fread(buffer, 1, file_size, file);
+    fclose(file);
 
     if (read_size < file_size) {
-        free (buffer);
+        free(buffer);
         return NULL;
     }
 
@@ -41,20 +41,19 @@ read_file_to_buffer (const char *filename, int *ret_size)
 }
 
 static int
-print_help ()
+print_help()
 {
-    printf ("Usage: binarydump -o <file> -n <name> input_file\n");
-    printf ("Options:\n");
-    printf ("  -o <file>      Place the output into <file>\n");
-    printf ("  -n <name>      The name of array <file>\n");
+    printf("Usage: binarydump -o <file> -n <name> input_file\n");
+    printf("Options:\n");
+    printf("  -o <file>      Place the output into <file>\n");
+    printf("  -n <name>      The name of array <file>\n");
 
     return -1;
 }
 
 static bool
-bin_file_dump (const unsigned char *file, int size,
-                const char *bin_file_output,
-                const char *array_name)
+bin_file_dump(const unsigned char *file, int size, const char *bin_file_output,
+              const char *array_name)
 {
     unsigned i = 0;
     const unsigned char *p = file, *p_end = file + size;
@@ -63,7 +62,8 @@ bin_file_dump (const unsigned char *file, int size,
     if (!file_output)
         return false;
 
-    fprintf(file_output, "\nunsigned char __aligned(4) %s[] = {\n  ", array_name);
+    fprintf(file_output, "\nunsigned char __aligned(4) %s[] = {\n  ",
+            array_name);
 
     while (p < p_end) {
         fprintf(file_output, "0x%02X", *p++);
@@ -86,7 +86,7 @@ bin_file_dump (const unsigned char *file, int size,
 }
 
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
     unsigned char *file;
     int size;
@@ -94,33 +94,33 @@ main (int argc, char *argv[])
     const char *bin_file_input, *array_file_output = NULL, *array_name = NULL;
 
     for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
-        if (!strcmp (argv[0], "-o")) {
+        if (!strcmp(argv[0], "-o")) {
             ++argv;
             if (--argc == 0)
-                return print_help ();
+                return print_help();
             array_file_output = *argv;
         }
-        else if (!strcmp (argv[0], "-n")) {
+        else if (!strcmp(argv[0], "-n")) {
             ++argv;
             if (--argc == 0)
-                return print_help ();
+                return print_help();
             array_name = *argv;
         }
         else
-            return print_help ();
+            return print_help();
     }
 
     if (!array_file_output || !array_name)
-        return print_help ();
+        return print_help();
 
     bin_file_input = *argv;
 
-    if (!(file = read_file_to_buffer (bin_file_input, &size)))
+    if (!(file = read_file_to_buffer(bin_file_input, &size)))
         return -1;
 
-    ret = bin_file_dump (file, size, array_file_output, array_name);
+    ret = bin_file_dump(file, size, array_file_output, array_name);
 
-    free (file);
+    free(file);
 
     return ret ? 0 : -1;
 }

+ 0 - 0
test-tools/component_test/README.md → test-tools/component-test/README.md


+ 0 - 0
test-tools/component_test/__init__.py → test-tools/component-test/__init__.py


+ 0 - 0
test-tools/component_test/framework/__init__.py → test-tools/component-test/framework/__init__.py


+ 0 - 0
test-tools/component_test/framework/case_base.py → test-tools/component-test/framework/case_base.py


+ 0 - 0
test-tools/component_test/framework/engine.py → test-tools/component-test/framework/engine.py


+ 0 - 0
test-tools/component_test/framework/framework.py → test-tools/component-test/framework/framework.py


+ 0 - 0
test-tools/component_test/framework/suite.py → test-tools/component-test/framework/suite.py


+ 0 - 0
test-tools/component_test/framework/test_api.py → test-tools/component-test/framework/test_api.py


+ 0 - 0
test-tools/component_test/framework/test_utils.py → test-tools/component-test/framework/test_utils.py


+ 0 - 0
test-tools/component_test/harness/__init__.py → test-tools/component-test/harness/__init__.py


+ 0 - 0
test-tools/component_test/harness/harness_api.py → test-tools/component-test/harness/harness_api.py


+ 50 - 34
test-tools/component_test/host-clients/src/host_app_sample.c → test-tools/component-test/host-clients/src/host_app_sample.c

@@ -11,32 +11,36 @@
 #include "bi-inc/attr_container.h"
 #include "er-coap-constants.h"
 
-static char *read_file_to_buffer(const char *filename, int *ret_size);
+static char *
+read_file_to_buffer(const char *filename, int *ret_size);
 int send_request_to_applet_success = 0;
 const char *label_for_request = "request1";
 int event_listener_counter = 0;
 char *applet_buf[1024 * 1024];
 const char *host_agent_ip = "127.0.0.1";
-void f_aee_response_handler(void *usr_ctx, aee_response_t *response)
+void
+f_aee_response_handler(void *usr_ctx, aee_response_t *response)
 {
     if (response == NULL) {
         printf("########## request timeout!!! \n");
-    } else {
-        char *str = (char *) usr_ctx;
+    }
+    else {
+        char *str = (char *)usr_ctx;
         printf("#### dump response ####\n");
         printf("#### user data: %s \n", str);
         printf("#### status: %d \n", response->status);
         if (response->payload != NULL)
-            attr_container_dump((attr_container_t *) response->payload);
+            attr_container_dump((attr_container_t *)response->payload);
     }
 }
 
-void f_aee_event_listener(const char *url, void *event, int fmt)
+void
+f_aee_event_listener(const char *url, void *event, int fmt)
 {
     printf("######## event is received. url: %s, fmt:%d ############\n", url,
-            fmt);
+           fmt);
 
-    attr_container_t *attr_obj = (attr_container_t *) event;
+    attr_container_t *attr_obj = (attr_container_t *)event;
 
     attr_container_dump(attr_obj);
     /*
@@ -48,7 +52,8 @@ void f_aee_event_listener(const char *url, void *event, int fmt)
      */
 }
 
-static int print_menu_and_select(void)
+static int
+print_menu_and_select(void)
 {
     char s[256];
     int choice;
@@ -83,7 +88,8 @@ static int print_menu_and_select(void)
     return 0;
 }
 
-static void install_applet(int index)
+static void
+install_applet(int index)
 {
     char applet_name[64];
     char applet_file_name[64];
@@ -94,15 +100,15 @@ static void install_applet(int index)
     printf("Installing TestApplet%d...\n", index);
     snprintf(applet_name, sizeof(applet_name), "TestApplet%d", index);
     snprintf(applet_file_name, sizeof(applet_file_name), "./TestApplet%d.wasm",
-            index);
+             index);
     buf = read_file_to_buffer(applet_file_name, &size);
     if (!buf) {
         printf("Install Applet failed: read file %s error.\n",
-                applet_file_name);
+               applet_file_name);
         return;
     }
 
-    //step2. install applet
+    // step2. install applet
     ret = aee_applet_install(buf, "wasm", size, applet_name, 5000);
     if (ret) {
         printf("%s install success\n", applet_name);
@@ -110,7 +116,8 @@ static void install_applet(int index)
     free(buf);
 }
 
-static void uninstall_applet(int index)
+static void
+uninstall_applet(int index)
 {
     int ret;
     char applet_name[64];
@@ -118,51 +125,56 @@ static void uninstall_applet(int index)
     ret = aee_applet_uninstall(applet_name, "wasm", 5000);
     if (ret) {
         printf("uninstall %s success\n", applet_name);
-    } else {
+    }
+    else {
         printf("uninstall %s failed\n", applet_name);
     }
 }
 
-static void send_request(int index)
+static void
+send_request(int index)
 {
     char url[64];
     int ret;
     aee_request_t req;
     const char *user_context = "label for request";
-    attr_container_t *attr_obj = attr_container_create(
-            "Send Request to Applet");
+    attr_container_t *attr_obj =
+        attr_container_create("Send Request to Applet");
     attr_container_set_string(&attr_obj, "String key", "Hello");
     attr_container_set_int(&attr_obj, "Int key", 1000);
     attr_container_set_int64(&attr_obj, "Int64 key", 0x77BBCCDD11223344LL);
 
-    //specify the target wasm app
+    // specify the target wasm app
     snprintf(url, sizeof(url), "/app/TestApplet%d/url1", index);
 
-    //not specify the target wasm app
-    //snprintf(url, sizeof(url), "url1");
+    // not specify the target wasm app
+    // snprintf(url, sizeof(url), "url1");
     aee_request_init(&req, url, COAP_PUT);
     aee_request_set_payload(&req, attr_obj,
-            attr_container_get_serialize_length(attr_obj),
-            PAYLOAD_FORMAT_ATTRIBUTE_OBJECT);
-    ret = aee_request_send(&req, f_aee_response_handler, (void *) user_context,
-            10000);
+                            attr_container_get_serialize_length(attr_obj),
+                            PAYLOAD_FORMAT_ATTRIBUTE_OBJECT);
+    ret = aee_request_send(&req, f_aee_response_handler, (void *)user_context,
+                           10000);
 
     if (ret) {
         printf("send request to TestApplet1 success\n");
     }
 }
 
-static void register_event(const char *event_path)
+static void
+register_event(const char *event_path)
 {
     hostclient_register_event(event_path, f_aee_event_listener);
 }
 
-static void unregister_event(const char *event_path)
+static void
+unregister_event(const char *event_path)
 {
     hostclient_unregister_event(event_path);
 }
 
-static void query_applets()
+static void
+query_applets()
 {
     aee_applet_list_t applet_lst;
     aee_applet_list_init(&applet_lst);
@@ -189,7 +201,7 @@ read_file_to_buffer(const char *filename, int *ret_size)
         return NULL;
     }
 
-    if (!(buffer = (char *) malloc(file_size))) {
+    if (!(buffer = (char *)malloc(file_size))) {
         fclose(fl);
         return NULL;
     }
@@ -206,7 +218,8 @@ read_file_to_buffer(const char *filename, int *ret_size)
     return buffer;
 }
 
-static void auto_test()
+static void
+auto_test()
 {
     int i;
     int interval = 1000; /* ms */
@@ -228,7 +241,8 @@ static void auto_test()
     }
 }
 
-void exit_program()
+void
+exit_program()
 {
     hostclient_shutdown();
     exit(0);
@@ -240,7 +254,7 @@ main()
 {
     bool ret;
 
-    //step1. host client init
+    // step1. host client init
     ret = hostclient_initialize(host_agent_ip, 3456);
 
     if (!ret) {
@@ -281,5 +295,7 @@ main()
 //   2. Use the Team Explorer window to connect to source control
 //   3. Use the Output window to see build output and other messages
 //   4. Use the Error List window to view errors
-//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
-//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
+//   5. Go to Project > Add New Item to create new code files, or
+//      Project > Add Existing Item to add existing code files to the project
+//   6. In the future, to open this project again, go to File > Open > Project
+//      and select the .sln file

+ 0 - 0
test-tools/component_test/host-clients/src/makefile → test-tools/component-test/host-clients/src/makefile


+ 0 - 0
test-tools/component_test/set_dev_env.sh → test-tools/component-test/set_dev_env.sh


+ 0 - 0
test-tools/component_test/start.py → test-tools/component-test/start.py


+ 0 - 0
test-tools/component_test/suites/01-life-cycle/__init__.py → test-tools/component-test/suites/01-life-cycle/__init__.py


部分文件因为文件数量过多而无法显示