From 63cd567b3fe0bab8874da89d01f89fccbdf1fe28 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 20 Feb 2024 18:12:36 +0800 Subject: [PATCH] Separate app-manager and app-framework from WAMR (#3129) As planned, the app-manager and app-framework are to be migrated to https://github.com/bytecodealliance/wamr-app-framework. ps. https://github.com/bytecodealliance/wasm-micro-runtime/issues/2329 https://github.com/bytecodealliance/wasm-micro-runtime/wiki/TSC-meeting-notes --- .github/workflows/build_wamr_sdk.yml | 25 +- .../compilation_on_android_ubuntu.yml | 9 - .github/workflows/compilation_on_macos.yml | 2 - .github/workflows/compilation_on_nuttx.yml | 2 - .github/workflows/compilation_on_sgx.yml | 2 - .github/workflows/compilation_on_windows.yml | 2 - .github/workflows/nightly_run.yml | 8 +- .github/workflows/release_process.yml | 3 + .gitignore | 4 - ATTRIBUTIONS.md | 14 +- README.md | 4 +- assembly-script/.gitignore | 1 - assembly-script/README.md | 124 - assembly-script/package-lock.json | 30 - assembly-script/package.json | 20 - assembly-script/samples/event_publisher.ts | 36 - assembly-script/samples/event_subscriber.ts | 36 - assembly-script/samples/request_handler.ts | 40 - assembly-script/samples/request_sender.ts | 43 - assembly-script/samples/timer.ts | 36 - assembly-script/samples/tsconfig.json | 6 - assembly-script/wamr_app_lib/console.ts | 15 - assembly-script/wamr_app_lib/request.ts | 495 --- assembly-script/wamr_app_lib/timer.ts | 80 - assembly-script/wamr_app_lib/tsconfig.json | 6 - build-scripts/SConscript | 8 - build-scripts/runtime_lib.cmake | 16 - ci/coding_guidelines_check.py | 3 - core/app-framework/README.md | 120 - .../app-framework/app-native-shared/README.md | 11 - .../app-native-shared/attr_container.c | 986 ------ .../app-native-shared/bi-inc/attr_container.h | 596 ---- .../app-native-shared/bi-inc/shared_utils.h | 155 - .../bi-inc/wgl_shared_utils.h | 101 - .../app-native-shared/native_interface.cmake | 15 - .../app-native-shared/native_interface.h | 13 - .../app-native-shared/restful_utils.c | 493 --- core/app-framework/app_ext_lib_export.c | 38 - core/app-framework/app_framework.cmake | 93 - core/app-framework/base/app/bh_platform.c | 89 - core/app-framework/base/app/bh_platform.h | 65 - core/app-framework/base/app/req_resp_api.h | 31 - core/app-framework/base/app/request.c | 365 -- core/app-framework/base/app/timer.c | 100 - core/app-framework/base/app/timer_api.h | 36 - core/app-framework/base/app/wa-inc/request.h | 171 - .../base/app/wa-inc/timer_wasm_app.h | 71 - core/app-framework/base/app/wasm_app.cmake | 13 - core/app-framework/base/app/wasm_app.h | 20 - core/app-framework/base/native/base_lib.inl | 14 - .../base/native/base_lib_export.c | 24 - .../base/native/req_resp_native_api.h | 29 - .../base/native/request_response.c | 84 - core/app-framework/base/native/runtime_lib.h | 22 - .../base/native/timer_native_api.h | 40 - .../app-framework/base/native/timer_wrapper.c | 220 -- core/app-framework/base/native/wasm_lib.cmake | 13 - .../app-framework/connection/app/connection.c | 118 - .../connection/app/connection_api.h | 31 - .../connection/app/wa-inc/connection.h | 94 - .../connection/app/wasm_app.cmake | 11 - .../connection/native/connection.inl | 9 - .../connection/native/connection_lib.h | 75 - .../connection/native/connection_native_api.h | 36 - .../connection/native/connection_wrapper.c | 61 - .../connection/native/linux/conn_tcp.c | 54 - .../connection/native/linux/conn_tcp.h | 28 - .../connection/native/linux/conn_uart.c | 103 - .../connection/native/linux/conn_uart.h | 28 - .../connection/native/linux/conn_udp.c | 58 - .../connection/native/linux/conn_udp.h | 28 - .../connection/native/linux/connection_mgr.c | 609 ---- .../native/linux/connection_mgr.cmake | 13 - .../connection/native/wasm_lib.cmake | 18 - .../native/zephyr/connection_lib_impl.c | 25 - .../native/zephyr/connection_mgr.cmake | 13 - core/app-framework/sensor/app/sensor.c | 122 - core/app-framework/sensor/app/sensor_api.h | 31 - core/app-framework/sensor/app/wa-inc/sensor.h | 94 - core/app-framework/sensor/app/wasm_app.cmake | 11 - .../sensor/native/runtime_sensor.c | 434 --- .../sensor/native/runtime_sensor.h | 69 - .../sensor/native/runtime_sensor.inl | 9 - .../sensor/native/sensor_mgr_ref.c | 148 - .../sensor/native/sensor_native_api.h | 33 - .../sensor/native/wasm_lib.cmake | 14 - .../template/app/wa-inc/app_xxx.h | 8 - .../app-framework/template/app/wasm_app.cmake | 16 - .../app-framework/template/native/app_xxx.inl | 6 - .../template/native/wasm_lib.cmake | 17 - core/app-framework/wgl/app/gui_api.h | 35 - core/app-framework/wgl/app/prepare_headers.sh | 46 - core/app-framework/wgl/app/src/wgl_btn.c | 135 - core/app-framework/wgl/app/src/wgl_cb.c | 86 - core/app-framework/wgl/app/src/wgl_label.c | 260 -- core/app-framework/wgl/app/src/wgl_list.c | 155 - core/app-framework/wgl/app/src/wgl_obj.c | 124 - core/app-framework/wgl/app/wa-inc/lv_conf.h | 497 --- .../wgl/app/wa-inc/lvgl/LICENCE.txt | 8 - .../wgl/app/wa-inc/lvgl/lv_obj.h | 1046 ------ core/app-framework/wgl/app/wa-inc/lvgl/lvgl.h | 82 - core/app-framework/wgl/app/wa-inc/lvgl/test.c | 9 - core/app-framework/wgl/app/wasm_app.cmake | 19 - .../app-framework/wgl/native/gui_native_api.h | 44 - core/app-framework/wgl/native/wamr_gui.inl | 28 - core/app-framework/wgl/native/wasm_lib.cmake | 19 - core/app-framework/wgl/native/wgl.h | 22 - .../wgl/native/wgl_btn_wrapper.c | 161 - .../app-framework/wgl/native/wgl_cb_wrapper.c | 109 - .../wgl/native/wgl_cont_wrapper.c | 7 - .../wgl/native/wgl_label_wrapper.c | 95 - .../wgl/native/wgl_list_wrapper.c | 75 - .../wgl/native/wgl_native_utils.c | 126 - .../wgl/native/wgl_native_utils.h | 68 - .../wgl/native/wgl_obj_wrapper.c | 414 --- core/app-framework/wgl/readme.MD | 97 - core/app-mgr/app-manager/app_manager.c | 431 --- core/app-mgr/app-manager/app_manager.h | 86 - core/app-mgr/app-manager/app_manager_host.c | 324 -- core/app-mgr/app-manager/app_manager_host.h | 23 - core/app-mgr/app-manager/app_mgr.cmake | 17 - core/app-mgr/app-manager/ble_msg.c | 115 - core/app-mgr/app-manager/coding_rule.txt | 15 - core/app-mgr/app-manager/event.c | 204 -- core/app-mgr/app-manager/event.h | 41 - core/app-mgr/app-manager/message.c | 88 - core/app-mgr/app-manager/module_config.h | 23 - core/app-mgr/app-manager/module_jeff.c | 1883 ----------- core/app-mgr/app-manager/module_jeff.h | 29 - core/app-mgr/app-manager/module_utils.c | 230 -- core/app-mgr/app-manager/module_wasm_app.h | 143 - core/app-mgr/app-manager/module_wasm_lib.c | 58 - core/app-mgr/app-manager/module_wasm_lib.h | 21 - .../platform/darwin/app_mgr_darwin.c | 1 - .../platform/linux/app_mgr_linux.c | 46 - core/app-mgr/app-manager/resource_reg.c | 211 -- core/app-mgr/app-manager/watchdog.c | 140 - core/app-mgr/app-manager/watchdog.h | 40 - .../app-mgr-shared/app_manager_export.h | 307 -- .../app-mgr-shared/app_mgr_shared.cmake | 16 - core/app-mgr/app-mgr-shared/host_link.h | 31 - core/app-mgr/module.json | 52 - core/deps/download.sh | 20 - doc/export_native_api.md | 10 +- doc/wamr_api.md | 351 -- product-mini/README.md | 3 +- samples/README.md | 3 - samples/gui/README.md | 138 - samples/gui/build.sh | 75 - samples/gui/lv_config/lv_conf.h | 498 --- samples/gui/lv_config/lv_drv_conf.h | 310 -- samples/gui/lv_config/system_header.h | 9 - samples/gui/wamr_config_gui.cmake | 9 - samples/gui/wasm-apps/build_apps.sh | 45 - samples/gui/wasm-apps/decrease/Makefile | 29 - samples/gui/wasm-apps/increase/CMakeLists.txt | 20 - samples/gui/wasm-apps/increase/Makefile | 34 - .../linux-build/CMakeLists.txt | 54 - .../src/platform/linux/iwasm_main.c | 564 ---- .../src/platform/linux/lv_drv_conf.h | 310 -- .../src/platform/linux/main.c | 25 - .../src/platform/zephyr/LICENSE | 202 -- .../src/platform/zephyr/XPT2046.h | 65 - .../src/platform/zephyr/board_config.h | 9 - .../src/platform/zephyr/display.h | 418 --- .../src/platform/zephyr/display_ili9340.c | 283 -- .../zephyr/display_ili9340_adafruit_1480.c | 80 - .../src/platform/zephyr/main.c | 29 - .../src/platform/zephyr/pin_config_jlf.h | 26 - .../src/platform/zephyr/pin_config_stm32.h | 30 - .../zephyr-build/CMakeLists.txt | 78 - .../wasm-runtime-wgl/zephyr-build/prj.conf | 10 - samples/littlevgl/LICENCE.txt | 8 - samples/littlevgl/README.md | 174 - samples/littlevgl/build.sh | 102 - samples/littlevgl/lv_config/lv_conf.h | 389 --- samples/littlevgl/lv_config/lv_drv_conf.h | 310 -- .../vgl-native-ui-app/CMakeLists.txt | 137 - .../vgl-native-ui-app/CMakeLists.txt.in | 18 - .../vgl-native-ui-app/lv-drivers/.gitignore | 1 - .../lv-drivers/display_indev.h | 28 - .../lv-drivers/indev/mouse.c | 96 - .../lv-drivers/indev/mouse.h | 73 - .../lv-drivers/linux_display_indev.c | 319 -- .../lv-drivers/system_header.h | 9 - samples/littlevgl/vgl-native-ui-app/main.c | 170 - .../littlevgl/vgl-wasm-runtime/CMakeLists.txt | 36 - .../vgl-wasm-runtime/src/display_indev.h | 96 - .../src/platform/linux/display_indev.c | 347 -- .../src/platform/linux/iwasm_main.c | 544 --- .../src/platform/linux/main.c | 11 - .../src/platform/linux/mouse.c | 97 - .../src/platform/zephyr/LICENSE | 202 -- .../src/platform/zephyr/XPT2046.h | 87 - .../src/platform/zephyr/board_config.h | 9 - .../src/platform/zephyr/display.h | 418 --- .../src/platform/zephyr/display_ili9340.c | 284 -- .../zephyr/display_ili9340_adafruit_1480.c | 80 - .../src/platform/zephyr/display_indev.c | 105 - .../src/platform/zephyr/main.c | 26 - .../src/platform/zephyr/pin_config_jlf.h | 26 - .../src/platform/zephyr/pin_config_stm32.h | 30 - .../zephyr-build/CMakeLists.txt | 71 - .../vgl-wasm-runtime/zephyr-build/prj.conf | 9 - samples/littlevgl/wamr_config_littlevgl.cmake | 9 - samples/littlevgl/wasm-apps/Makefile_wasm_app | 57 - .../wasm-apps/Makefile_wasm_app_no_wasi | 59 - samples/littlevgl/wasm-apps/build_wasm_app.sh | 22 - .../littlevgl/wasm-apps/src/display_indev.h | 42 - samples/littlevgl/wasm-apps/src/main.c | 189 -- .../littlevgl/wasm-apps/src/system_header.h | 9 - samples/simple/.gitignore | 1 - samples/simple/CMakeLists.txt | 40 - samples/simple/README.md | 342 -- samples/simple/build.sh | 166 - .../profiles/arm-interp/toolchain.cmake | 40 - .../arm-interp/wamr_config_simple.cmake | 11 - .../simple/profiles/arm64-aot/toolchain.cmake | 38 - .../arm64-aot/wamr_config_simple.cmake | 12 - .../profiles/arm64-interp/toolchain.cmake | 38 - .../arm64-interp/wamr_config_simple.cmake | 12 - .../host-aot/wamr_config_simple.cmake | 11 - .../host-interp/wamr_config_simple.cmake | 11 - .../macos-interp/wamr_config_simple.cmake | 11 - samples/simple/sample_test_run.py | 224 -- samples/simple/src/iwasm_main.c | 568 ---- samples/simple/src/main.c | 14 - samples/simple/wasm-apps/connection.c | 89 - samples/simple/wasm-apps/event_publisher.c | 54 - samples/simple/wasm-apps/event_subscriber.c | 29 - samples/simple/wasm-apps/request_handler.c | 59 - samples/simple/wasm-apps/request_sender.c | 52 - samples/simple/wasm-apps/sensor.c | 83 - samples/simple/wasm-apps/timer.c | 34 - test-tools/IoT-APP-Store-Demo/README.md | 50 - .../IoT-APP-Store-Demo/docker-compose.yml | 22 - .../IoT-APP-Store-Demo/wasm_django/Dockerfile | 9 - .../IoT-APP-Store-Demo/wasm_django/db.sqlite3 | Bin 45056 -> 0 bytes .../wasm_django/devices/__init__.py | 0 .../wasm_django/devices/admin.py | 3 - .../wasm_django/devices/apps.py | 5 - .../devices/migrations/__init__.py | 0 .../wasm_django/devices/models.py | 3 - .../devices/templates/application.html | 141 - .../devices/templates/appstore.html | 98 - .../wasm_django/devices/templates/empty.html | 125 - .../wasm_django/devices/templates/help.html | 102 - .../wasm_django/devices/templates/mysite.html | 91 - .../wasm_django/devices/tests.py | 3 - .../wasm_django/devices/views.py | 273 -- .../IoT-APP-Store-Demo/wasm_django/manage.py | 21 - .../wasm_django/mysite/__init__.py | 0 .../wasm_django/mysite/settings.py | 136 - .../wasm_django/mysite/urls.py | 41 - .../wasm_django/mysite/wsgi.py | 16 - .../wasm_django/server/Dockerfile | 6 - .../wasm_django/server/wasm_server.py | 621 ---- .../wasm_django/static/css/application.css | 400 --- .../wasm_django/static/css/appstore.css | 216 -- .../wasm_django/static/css/index.css | 197 -- .../wasm_django/static/js/application.js | 217 -- .../wasm_django/static/js/appstore.js | 125 - .../wasm_django/static/js/index.js | 51 - .../wasm_django/static/photo/app(1).png | Bin 5421 -> 0 bytes .../wasm_django/static/photo/application.png | Bin 7875 -> 0 bytes .../wasm_django/static/photo/delete.png | Bin 4107 -> 0 bytes .../wasm_django/static/photo/download(1).png | Bin 1502 -> 0 bytes .../wasm_django/static/photo/menu.png | Bin 1839 -> 0 bytes .../static/photo/milky-way-2695569_1280.jpg | Bin 535384 -> 0 bytes .../wasm_django/static/photo/net_device.png | Bin 6867 -> 0 bytes .../static/photo/software-icon-32081.png | Bin 39956 -> 0 bytes .../wasm_django/static/photo/totalblack.png | Bin 2301 -> 0 bytes .../wasm_django/static/upload/connection.wasm | Bin 6280 -> 0 bytes .../static/upload/event_publisher.wasm | Bin 4958 -> 0 bytes .../static/upload/event_subscriber.wasm | Bin 4015 -> 0 bytes .../static/upload/request_handler.wasm | Bin 6776 -> 0 bytes .../static/upload/request_sender.wasm | Bin 5311 -> 0 bytes .../wasm_django/static/upload/sensor.wasm | Bin 4455 -> 0 bytes .../wasm_django/static/upload/simple | Bin 387456 -> 0 bytes .../static/upload/sys/connection.wasm | Bin 6280 -> 0 bytes .../static/upload/sys/event_publisher.wasm | Bin 4958 -> 0 bytes .../static/upload/sys/event_subscriber.wasm | Bin 4015 -> 0 bytes .../static/upload/sys/request_handler.wasm | Bin 6776 -> 0 bytes .../static/upload/sys/request_sender.wasm | Bin 5311 -> 0 bytes .../wasm_django/static/upload/sys/timer.wasm | Bin 2388 -> 0 bytes .../wasm_django/static/upload/timer.wasm | Bin 2388 -> 0 bytes .../wasm_django/static/upload/ui_app.wasm | Bin 1912 -> 0 bytes .../static/upload/wasm_runtime_wgl | Bin 615016 -> 0 bytes test-tools/component-test/README.md | 56 - test-tools/component-test/__init__.py | 11 - .../component-test/framework/__init__.py | 11 - .../component-test/framework/case_base.py | 29 - test-tools/component-test/framework/engine.py | 39 - .../component-test/framework/framework.py | 288 -- test-tools/component-test/framework/suite.py | 40 - .../component-test/framework/test_api.py | 99 - .../component-test/framework/test_utils.py | 71 - test-tools/component-test/harness/__init__.py | 0 .../component-test/harness/harness_api.py | 150 - .../host-clients/src/host_app_sample.c | 301 -- .../component-test/host-clients/src/makefile | 44 - test-tools/component-test/set_dev_env.sh | 7 - test-tools/component-test/start.py | 152 - .../suites/01-life-cycle/__init__.py | 0 .../cases/01-install/__init__.py | 0 .../01-life-cycle/cases/01-install/case.py | 94 - .../cases/02-request/__init__.py | 0 .../01-life-cycle/cases/02-request/case.py | 73 - .../01-life-cycle/cases/03-event/__init__.py | 0 .../01-life-cycle/cases/03-event/case.py | 67 - .../cases/04-request-internal/__init__.py | 0 .../cases/04-request-internal/case.py | 80 - .../cases/05-event-internal/__init__.py | 0 .../cases/05-event-internal/case.py | 70 - .../01-life-cycle/cases/06-timer/__init__.py | 0 .../01-life-cycle/cases/06-timer/case.py | 70 - .../01-life-cycle/cases/07-sensor/__init__.py | 0 .../01-life-cycle/cases/07-sensor/case.py | 65 - .../cases/08-on-destroy/__init__.py | 0 .../01-life-cycle/cases/08-on-destroy/case.py | 78 - .../suites/01-life-cycle/cases/__init__.py | 0 .../suites/01-life-cycle/suite_setup.py | 56 - .../01-life-cycle/test-app/01_install.c | 19 - .../01-life-cycle/test-app/02_request.c | 68 - .../suites/01-life-cycle/test-app/03_event.c | 59 - .../test-app/04_request_internal_req.c | 74 - .../test-app/04_request_internal_resp.c | 57 - .../test-app/05_event_internal_provider.c | 59 - .../test-app/05_event_internal_subscriber.c | 56 - .../suites/01-life-cycle/test-app/06_timer.c | 80 - .../suites/01-life-cycle/test-app/07_sensor.c | 74 - .../01-life-cycle/test-app/08_on_destroy.c | 70 - .../suites/01-life-cycle/test-app/build.sh | 39 - .../01-life-cycle/tools/product/start.sh | 10 - .../01-life-cycle/tools/product/stop.sh | 9 - test-tools/component-test/suites/__init__.py | 0 test-tools/component-test/suites/readme.txt | 19 - test-tools/host-tool/CMakeLists.txt | 56 - test-tools/host-tool/external/cJSON/LICENSE | 20 - test-tools/host-tool/external/cJSON/cJSON.c | 2991 ----------------- test-tools/host-tool/external/cJSON/cJSON.h | 392 --- .../host-tool/external/cJSON/cjson.cmake | 10 - test-tools/host-tool/src/host_tool_utils.c | 336 -- test-tools/host-tool/src/host_tool_utils.h | 78 - test-tools/host-tool/src/main.c | 887 ----- test-tools/host-tool/src/transport.c | 263 -- test-tools/host-tool/src/transport.h | 121 - .../spec-test-script/collect_coverage.sh | 3 +- wamr-compiler/CMakeLists.txt | 1 - wamr-sdk/Kconfig | 84 - wamr-sdk/Makefile | 10 - wamr-sdk/README.md | 136 +- wamr-sdk/app/CMakeLists.txt | 98 - wamr-sdk/build_sdk.sh | 254 -- wamr-sdk/menuconfig.sh | 223 -- wamr-sdk/runtime/CMakeLists.txt | 58 - wamr-sdk/wamr_config_default.cmake | 12 - wamr-sdk/wamr_config_macos_release.cmake | 40 - wamr-sdk/wamr_config_ubuntu_release.cmake | 40 - 359 files changed, 45 insertions(+), 37923 deletions(-) delete mode 100644 assembly-script/.gitignore delete mode 100644 assembly-script/README.md delete mode 100644 assembly-script/package-lock.json delete mode 100644 assembly-script/package.json delete mode 100644 assembly-script/samples/event_publisher.ts delete mode 100644 assembly-script/samples/event_subscriber.ts delete mode 100644 assembly-script/samples/request_handler.ts delete mode 100644 assembly-script/samples/request_sender.ts delete mode 100644 assembly-script/samples/timer.ts delete mode 100644 assembly-script/samples/tsconfig.json delete mode 100644 assembly-script/wamr_app_lib/console.ts delete mode 100644 assembly-script/wamr_app_lib/request.ts delete mode 100644 assembly-script/wamr_app_lib/timer.ts delete mode 100644 assembly-script/wamr_app_lib/tsconfig.json delete mode 100644 core/app-framework/README.md delete mode 100644 core/app-framework/app-native-shared/README.md delete mode 100644 core/app-framework/app-native-shared/attr_container.c delete mode 100644 core/app-framework/app-native-shared/bi-inc/attr_container.h delete mode 100644 core/app-framework/app-native-shared/bi-inc/shared_utils.h delete mode 100644 core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h delete mode 100644 core/app-framework/app-native-shared/native_interface.cmake delete mode 100644 core/app-framework/app-native-shared/native_interface.h delete mode 100644 core/app-framework/app-native-shared/restful_utils.c delete mode 100644 core/app-framework/app_ext_lib_export.c delete mode 100644 core/app-framework/app_framework.cmake delete mode 100644 core/app-framework/base/app/bh_platform.c delete mode 100644 core/app-framework/base/app/bh_platform.h delete mode 100644 core/app-framework/base/app/req_resp_api.h delete mode 100644 core/app-framework/base/app/request.c delete mode 100644 core/app-framework/base/app/timer.c delete mode 100644 core/app-framework/base/app/timer_api.h delete mode 100644 core/app-framework/base/app/wa-inc/request.h delete mode 100644 core/app-framework/base/app/wa-inc/timer_wasm_app.h delete mode 100644 core/app-framework/base/app/wasm_app.cmake delete mode 100644 core/app-framework/base/app/wasm_app.h delete mode 100644 core/app-framework/base/native/base_lib.inl delete mode 100644 core/app-framework/base/native/base_lib_export.c delete mode 100644 core/app-framework/base/native/req_resp_native_api.h delete mode 100644 core/app-framework/base/native/request_response.c delete mode 100644 core/app-framework/base/native/runtime_lib.h delete mode 100644 core/app-framework/base/native/timer_native_api.h delete mode 100644 core/app-framework/base/native/timer_wrapper.c delete mode 100644 core/app-framework/base/native/wasm_lib.cmake delete mode 100644 core/app-framework/connection/app/connection.c delete mode 100644 core/app-framework/connection/app/connection_api.h delete mode 100644 core/app-framework/connection/app/wa-inc/connection.h delete mode 100644 core/app-framework/connection/app/wasm_app.cmake delete mode 100644 core/app-framework/connection/native/connection.inl delete mode 100644 core/app-framework/connection/native/connection_lib.h delete mode 100644 core/app-framework/connection/native/connection_native_api.h delete mode 100644 core/app-framework/connection/native/connection_wrapper.c delete mode 100644 core/app-framework/connection/native/linux/conn_tcp.c delete mode 100644 core/app-framework/connection/native/linux/conn_tcp.h delete mode 100644 core/app-framework/connection/native/linux/conn_uart.c delete mode 100644 core/app-framework/connection/native/linux/conn_uart.h delete mode 100644 core/app-framework/connection/native/linux/conn_udp.c delete mode 100644 core/app-framework/connection/native/linux/conn_udp.h delete mode 100644 core/app-framework/connection/native/linux/connection_mgr.c delete mode 100644 core/app-framework/connection/native/linux/connection_mgr.cmake delete mode 100644 core/app-framework/connection/native/wasm_lib.cmake delete mode 100644 core/app-framework/connection/native/zephyr/connection_lib_impl.c delete mode 100644 core/app-framework/connection/native/zephyr/connection_mgr.cmake delete mode 100644 core/app-framework/sensor/app/sensor.c delete mode 100644 core/app-framework/sensor/app/sensor_api.h delete mode 100644 core/app-framework/sensor/app/wa-inc/sensor.h delete mode 100644 core/app-framework/sensor/app/wasm_app.cmake delete mode 100644 core/app-framework/sensor/native/runtime_sensor.c delete mode 100644 core/app-framework/sensor/native/runtime_sensor.h delete mode 100644 core/app-framework/sensor/native/runtime_sensor.inl delete mode 100644 core/app-framework/sensor/native/sensor_mgr_ref.c delete mode 100644 core/app-framework/sensor/native/sensor_native_api.h delete mode 100644 core/app-framework/sensor/native/wasm_lib.cmake delete mode 100644 core/app-framework/template/app/wa-inc/app_xxx.h delete mode 100644 core/app-framework/template/app/wasm_app.cmake delete mode 100644 core/app-framework/template/native/app_xxx.inl delete mode 100644 core/app-framework/template/native/wasm_lib.cmake delete mode 100644 core/app-framework/wgl/app/gui_api.h delete mode 100755 core/app-framework/wgl/app/prepare_headers.sh delete mode 100644 core/app-framework/wgl/app/src/wgl_btn.c delete mode 100644 core/app-framework/wgl/app/src/wgl_cb.c delete mode 100644 core/app-framework/wgl/app/src/wgl_label.c delete mode 100644 core/app-framework/wgl/app/src/wgl_list.c delete mode 100644 core/app-framework/wgl/app/src/wgl_obj.c delete mode 100644 core/app-framework/wgl/app/wa-inc/lv_conf.h delete mode 100644 core/app-framework/wgl/app/wa-inc/lvgl/LICENCE.txt delete mode 100644 core/app-framework/wgl/app/wa-inc/lvgl/lv_obj.h delete mode 100644 core/app-framework/wgl/app/wa-inc/lvgl/lvgl.h delete mode 100644 core/app-framework/wgl/app/wa-inc/lvgl/test.c delete mode 100644 core/app-framework/wgl/app/wasm_app.cmake delete mode 100644 core/app-framework/wgl/native/gui_native_api.h delete mode 100644 core/app-framework/wgl/native/wamr_gui.inl delete mode 100644 core/app-framework/wgl/native/wasm_lib.cmake delete mode 100644 core/app-framework/wgl/native/wgl.h delete mode 100644 core/app-framework/wgl/native/wgl_btn_wrapper.c delete mode 100644 core/app-framework/wgl/native/wgl_cb_wrapper.c delete mode 100644 core/app-framework/wgl/native/wgl_cont_wrapper.c delete mode 100644 core/app-framework/wgl/native/wgl_label_wrapper.c delete mode 100644 core/app-framework/wgl/native/wgl_list_wrapper.c delete mode 100644 core/app-framework/wgl/native/wgl_native_utils.c delete mode 100644 core/app-framework/wgl/native/wgl_native_utils.h delete mode 100644 core/app-framework/wgl/native/wgl_obj_wrapper.c delete mode 100644 core/app-framework/wgl/readme.MD delete mode 100644 core/app-mgr/app-manager/app_manager.c delete mode 100644 core/app-mgr/app-manager/app_manager.h delete mode 100644 core/app-mgr/app-manager/app_manager_host.c delete mode 100644 core/app-mgr/app-manager/app_manager_host.h delete mode 100644 core/app-mgr/app-manager/app_mgr.cmake delete mode 100644 core/app-mgr/app-manager/ble_msg.c delete mode 100644 core/app-mgr/app-manager/coding_rule.txt delete mode 100644 core/app-mgr/app-manager/event.c delete mode 100644 core/app-mgr/app-manager/event.h delete mode 100644 core/app-mgr/app-manager/message.c delete mode 100644 core/app-mgr/app-manager/module_config.h delete mode 100644 core/app-mgr/app-manager/module_jeff.c delete mode 100644 core/app-mgr/app-manager/module_jeff.h delete mode 100644 core/app-mgr/app-manager/module_utils.c delete mode 100644 core/app-mgr/app-manager/module_wasm_app.h delete mode 100644 core/app-mgr/app-manager/module_wasm_lib.c delete mode 100644 core/app-mgr/app-manager/module_wasm_lib.h delete mode 100644 core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c delete mode 100644 core/app-mgr/app-manager/platform/linux/app_mgr_linux.c delete mode 100644 core/app-mgr/app-manager/resource_reg.c delete mode 100644 core/app-mgr/app-manager/watchdog.c delete mode 100644 core/app-mgr/app-manager/watchdog.h delete mode 100644 core/app-mgr/app-mgr-shared/app_manager_export.h delete mode 100644 core/app-mgr/app-mgr-shared/app_mgr_shared.cmake delete mode 100644 core/app-mgr/app-mgr-shared/host_link.h delete mode 100644 core/app-mgr/module.json delete mode 100755 core/deps/download.sh delete mode 100644 doc/wamr_api.md delete mode 100644 samples/gui/README.md delete mode 100755 samples/gui/build.sh delete mode 100644 samples/gui/lv_config/lv_conf.h delete mode 100644 samples/gui/lv_config/lv_drv_conf.h delete mode 100644 samples/gui/lv_config/system_header.h delete mode 100644 samples/gui/wamr_config_gui.cmake delete mode 100755 samples/gui/wasm-apps/build_apps.sh delete mode 100644 samples/gui/wasm-apps/decrease/Makefile delete mode 100644 samples/gui/wasm-apps/increase/CMakeLists.txt delete mode 100644 samples/gui/wasm-apps/increase/Makefile delete mode 100644 samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/linux/main.c delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h delete mode 100644 samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt delete mode 100644 samples/gui/wasm-runtime-wgl/zephyr-build/prj.conf delete mode 100644 samples/littlevgl/LICENCE.txt delete mode 100644 samples/littlevgl/README.md delete mode 100755 samples/littlevgl/build.sh delete mode 100644 samples/littlevgl/lv_config/lv_conf.h delete mode 100644 samples/littlevgl/lv_config/lv_drv_conf.h delete mode 100644 samples/littlevgl/vgl-native-ui-app/CMakeLists.txt delete mode 100644 samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in delete mode 100644 samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore delete mode 100644 samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h delete mode 100644 samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c delete mode 100644 samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h delete mode 100644 samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c delete mode 100644 samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h delete mode 100644 samples/littlevgl/vgl-native-ui-app/main.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/display_indev.h delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h delete mode 100644 samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt delete mode 100644 samples/littlevgl/vgl-wasm-runtime/zephyr-build/prj.conf delete mode 100644 samples/littlevgl/wamr_config_littlevgl.cmake delete mode 100644 samples/littlevgl/wasm-apps/Makefile_wasm_app delete mode 100644 samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi delete mode 100755 samples/littlevgl/wasm-apps/build_wasm_app.sh delete mode 100644 samples/littlevgl/wasm-apps/src/display_indev.h delete mode 100644 samples/littlevgl/wasm-apps/src/main.c delete mode 100644 samples/littlevgl/wasm-apps/src/system_header.h delete mode 100644 samples/simple/.gitignore delete mode 100644 samples/simple/CMakeLists.txt delete mode 100644 samples/simple/README.md delete mode 100755 samples/simple/build.sh delete mode 100644 samples/simple/profiles/arm-interp/toolchain.cmake delete mode 100644 samples/simple/profiles/arm-interp/wamr_config_simple.cmake delete mode 100644 samples/simple/profiles/arm64-aot/toolchain.cmake delete mode 100644 samples/simple/profiles/arm64-aot/wamr_config_simple.cmake delete mode 100644 samples/simple/profiles/arm64-interp/toolchain.cmake delete mode 100644 samples/simple/profiles/arm64-interp/wamr_config_simple.cmake delete mode 100644 samples/simple/profiles/host-aot/wamr_config_simple.cmake delete mode 100644 samples/simple/profiles/host-interp/wamr_config_simple.cmake delete mode 100644 samples/simple/profiles/macos-interp/wamr_config_simple.cmake delete mode 100755 samples/simple/sample_test_run.py delete mode 100644 samples/simple/src/iwasm_main.c delete mode 100644 samples/simple/src/main.c delete mode 100644 samples/simple/wasm-apps/connection.c delete mode 100644 samples/simple/wasm-apps/event_publisher.c delete mode 100644 samples/simple/wasm-apps/event_subscriber.c delete mode 100644 samples/simple/wasm-apps/request_handler.c delete mode 100644 samples/simple/wasm-apps/request_sender.c delete mode 100644 samples/simple/wasm-apps/sensor.c delete mode 100644 samples/simple/wasm-apps/timer.c delete mode 100644 test-tools/IoT-APP-Store-Demo/README.md delete mode 100644 test-tools/IoT-APP-Store-Demo/docker-compose.yml delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/db.sqlite3 delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/devices/__init__.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/devices/admin.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/devices/apps.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/devices/migrations/__init__.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/devices/models.py delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/application.html delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/manage.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/mysite/__init__.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/css/appstore.css delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/static/css/index.css delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/js/index.js delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/app(1).png delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/application.png delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/delete.png delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/download(1).png delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/menu.png delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/milky-way-2695569_1280.jpg delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/net_device.png delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/software-icon-32081.png delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/totalblack.png delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm delete mode 100644 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm delete mode 100755 test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl delete mode 100644 test-tools/component-test/README.md delete mode 100644 test-tools/component-test/__init__.py delete mode 100644 test-tools/component-test/framework/__init__.py delete mode 100644 test-tools/component-test/framework/case_base.py delete mode 100644 test-tools/component-test/framework/engine.py delete mode 100644 test-tools/component-test/framework/framework.py delete mode 100644 test-tools/component-test/framework/suite.py delete mode 100644 test-tools/component-test/framework/test_api.py delete mode 100644 test-tools/component-test/framework/test_utils.py delete mode 100644 test-tools/component-test/harness/__init__.py delete mode 100644 test-tools/component-test/harness/harness_api.py delete mode 100644 test-tools/component-test/host-clients/src/host_app_sample.c delete mode 100644 test-tools/component-test/host-clients/src/makefile delete mode 100755 test-tools/component-test/set_dev_env.sh delete mode 100755 test-tools/component-test/start.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/01-install/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/02-request/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/03-event/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/06-timer/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/07-sensor/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/cases/__init__.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/suite_setup.py delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/01_install.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/02_request.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/03_event.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c delete mode 100644 test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c delete mode 100755 test-tools/component-test/suites/01-life-cycle/test-app/build.sh delete mode 100755 test-tools/component-test/suites/01-life-cycle/tools/product/start.sh delete mode 100755 test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh delete mode 100644 test-tools/component-test/suites/__init__.py delete mode 100644 test-tools/component-test/suites/readme.txt delete mode 100644 test-tools/host-tool/CMakeLists.txt delete mode 100644 test-tools/host-tool/external/cJSON/LICENSE delete mode 100644 test-tools/host-tool/external/cJSON/cJSON.c delete mode 100644 test-tools/host-tool/external/cJSON/cJSON.h delete mode 100644 test-tools/host-tool/external/cJSON/cjson.cmake delete mode 100644 test-tools/host-tool/src/host_tool_utils.c delete mode 100644 test-tools/host-tool/src/host_tool_utils.h delete mode 100644 test-tools/host-tool/src/main.c delete mode 100644 test-tools/host-tool/src/transport.c delete mode 100644 test-tools/host-tool/src/transport.h delete mode 100644 wamr-sdk/Kconfig delete mode 100644 wamr-sdk/Makefile delete mode 100644 wamr-sdk/app/CMakeLists.txt delete mode 100755 wamr-sdk/build_sdk.sh delete mode 100755 wamr-sdk/menuconfig.sh delete mode 100644 wamr-sdk/runtime/CMakeLists.txt delete mode 100644 wamr-sdk/wamr_config_default.cmake delete mode 100644 wamr-sdk/wamr_config_macos_release.cmake delete mode 100644 wamr-sdk/wamr_config_ubuntu_release.cmake diff --git a/.github/workflows/build_wamr_sdk.yml b/.github/workflows/build_wamr_sdk.yml index f4ca9afd4..69dbd7232 100644 --- a/.github/workflows/build_wamr_sdk.yml +++ b/.github/workflows/build_wamr_sdk.yml @@ -30,6 +30,10 @@ on: description: download WASI_SDK from this URL type: string required: true + wamr_app_framework_url: + description: download WAMR app framework to get wamr_sdk + type: string + required: true jobs: build: @@ -37,6 +41,14 @@ jobs: steps: - uses: actions/checkout@v4 + - name: download wamr-app-framework + run: | + git clone ${{ inputs.wamr_app_framework_url }} + cd wamr-app-framework + git submodule init + git submodule update + working-directory: wamr-sdk + - name: download and install wasi-sdk run: | cd /opt @@ -48,14 +60,16 @@ jobs: - name: generate wamr-sdk release run: | + cd ./wamr-app-framework/wamr-sdk ./build_sdk.sh -n wamr-sdk -x $(pwd)/${{ inputs.config_file }} working-directory: wamr-sdk - name: compress the binary run: | + cd wamr-app-framework/wamr-sdk/out tar czf wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamr-sdk zip -r wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamr-sdk - working-directory: wamr-sdk/out + working-directory: wamr-sdk - name: upload release tar.gz uses: actions/upload-release-asset@v1 @@ -63,7 +77,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ inputs.upload_url }} - asset_path: wamr-sdk/out/wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz + asset_path: wamr-sdk/wamr-app-framework/wamr-sdk/out/wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz asset_name: wamr-sdk-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz asset_content_type: application/x-gzip @@ -73,6 +87,11 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ inputs.upload_url }} - asset_path: wamr-sdk/out/wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.zip + asset_path: wamr-sdk/wamr-app-framework/wamr-sdk/out/wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.zip asset_name: wamr-sdk-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip asset_content_type: application/zip + + - name: delete wamr-app-framework + run: | + rm -rf wamr-app-framework + working-directory: wamr-sdk diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index f88c9be67..49f5c7705 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -20,7 +20,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" - "test-tools/wamr-ide/**" # will be triggered on push events push: @@ -38,7 +37,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" - "test-tools/wamr-ide/**" # allow to be triggered manually workflow_dispatch: @@ -430,13 +428,6 @@ jobs: cmake --build . --config Debug --parallel 4 ./hello - - name: Build Sample [simple] - run: | - ./build.sh -p host-interp - python3 ./sample_test_run.py $(pwd)/out - exit $? - working-directory: ./samples/simple - - name: Build Sample [wasi-threads] run: | cd samples/wasi-threads diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index 9d352fbcf..7bea5175e 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -20,7 +20,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" # will be triggered on push events push: branches: @@ -37,7 +36,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" # allow to be triggered manually workflow_dispatch: diff --git a/.github/workflows/compilation_on_nuttx.yml b/.github/workflows/compilation_on_nuttx.yml index 2eff73c2c..98cbb24ff 100644 --- a/.github/workflows/compilation_on_nuttx.yml +++ b/.github/workflows/compilation_on_nuttx.yml @@ -19,7 +19,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" # will be triggered on push events push: branches: @@ -35,7 +34,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" # allow to be triggered manually workflow_dispatch: diff --git a/.github/workflows/compilation_on_sgx.yml b/.github/workflows/compilation_on_sgx.yml index 787b66725..030c76524 100644 --- a/.github/workflows/compilation_on_sgx.yml +++ b/.github/workflows/compilation_on_sgx.yml @@ -20,7 +20,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" # will be triggered on push events push: branches: @@ -37,7 +36,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" # allow to be triggered manually workflow_dispatch: diff --git a/.github/workflows/compilation_on_windows.yml b/.github/workflows/compilation_on_windows.yml index a623ab1a7..8c5db4fdf 100644 --- a/.github/workflows/compilation_on_windows.yml +++ b/.github/workflows/compilation_on_windows.yml @@ -19,7 +19,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" # will be triggered on push events push: branches: @@ -35,7 +34,6 @@ on: - "!samples/workload/**" - "tests/wamr-test-suites/**" - "wamr-compiler/**" - - "wamr-sdk/**" # allow to be triggered manually workflow_dispatch: diff --git a/.github/workflows/nightly_run.yml b/.github/workflows/nightly_run.yml index 8b9a0ed5e..cfc910ea2 100644 --- a/.github/workflows/nightly_run.yml +++ b/.github/workflows/nightly_run.yml @@ -13,7 +13,7 @@ on: paths: - ".github/workflows/nightly_run.yml" - "core/iwasm/libraries/lib-wasi-threads/stress-test/**" - + # midnight UTC schedule: - cron: "0 0 * * *" @@ -489,12 +489,6 @@ jobs: cmake .. cmake --build . --config Release --parallel 4 ./hello - - name: Build Sample [simple] - run: | - ./build.sh -p host-interp - python3 ./sample_test_run.py $(pwd)/out - exit $? - working-directory: ./samples/simple - name: Build Sample [wasi-threads] run: | diff --git a/.github/workflows/release_process.yml b/.github/workflows/release_process.yml index 5808b821c..de62867a8 100644 --- a/.github/workflows/release_process.yml +++ b/.github/workflows/release_process.yml @@ -147,6 +147,7 @@ jobs: upload_url: ${{ needs.create_release.outputs.upload_url }} ver_num: ${{ needs.create_tag.outputs.new_ver}} wasi_sdk_url: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz + wamr_app_framework_url: https://github.com/bytecodealliance/wamr-app-framework.git release_wamr_sdk_on_ubuntu_2204: needs: [create_tag, create_release] @@ -157,6 +158,7 @@ jobs: upload_url: ${{ needs.create_release.outputs.upload_url }} ver_num: ${{ needs.create_tag.outputs.new_ver}} wasi_sdk_url: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz + wamr_app_framework_url: https://github.com/bytecodealliance/wamr-app-framework.git release_wamr_sdk_on_macos: needs: [create_tag, create_release] @@ -167,6 +169,7 @@ jobs: upload_url: ${{ needs.create_release.outputs.upload_url }} ver_num: ${{ needs.create_tag.outputs.new_ver}} wasi_sdk_url: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-macos.tar.gz + wamr_app_framework_url: https://github.com/bytecodealliance/wamr-app-framework.git # # vscode extension cross-platform diff --git a/.gitignore b/.gitignore index 7275e3bef..b85dd392c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,13 +14,9 @@ core/deps/** core/shared/mem-alloc/tlsf -core/app-framework/wgl core/iwasm/libraries/lib-wasi-threads/test/*.wasm core/iwasm/libraries/lib-socket/test/*.wasm -wamr-sdk/out/ -wamr-sdk/runtime/build_runtime_sdk/ -test-tools/host-tool/bin/ product-mini/app-samples/hello-world/test.wasm product-mini/platforms/linux-sgx/enclave-sample/App/ product-mini/platforms/linux-sgx/enclave-sample/Enclave/ diff --git a/ATTRIBUTIONS.md b/ATTRIBUTIONS.md index c772b9691..b249f7b02 100644 --- a/ATTRIBUTIONS.md +++ b/ATTRIBUTIONS.md @@ -2,10 +2,10 @@ WebAssembly Micro Runtime Attributions ====================================== WAMR project reused some components from other open source project: -- **cJson**: used in the host_tool for remotely managing wasm applications +- **cJson**: in the repository [wamr-app-framework](https://github.com/bytecodealliance/wamr-app-framework/), used in the host_tool for remotely managing wasm applications - **contiki-ng**: for the coap protocol implementation - **freebsd libm**: used in core/shared/platform/alios/bh_math.c -- **LVGL**: for the gui samples and wrapped the wasm graphic layer +- **LVGL**: in the repository [wamr-app-framework](https://github.com/bytecodealliance/wamr-app-framework/), for the gui samples and wrapped the wasm graphic layer - **llvm**: for the AOT/JIT compilation - **wasm-c-api**: to implement the C-APIs of wasm. using headers and sameples - **wasmtime**: for the wasi libc implementation @@ -42,7 +42,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the ### cJson -[LICENSE](./test-tools/host-tool/external/cJSON/LICENSE) +[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/test-tools/host-tool/external/cJSON/LICENSE) ### contiki-ng @@ -54,9 +54,9 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the ### LVGL -[LICENSE](./samples/littlevgl/LICENCE.txt) +[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/samples/littlevgl/LICENCE.txt) -[LICENSE](./core/app-framework/wgl/app/wa-inc/lvgl/LICENCE.txt) +[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/wgl/app/wa-inc/lvgl/LICENCE.txt) ### llvm @@ -64,7 +64,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the ### wasm-c-api -[LICENSE](./samples/wasm-c-api/src/LICENSE) +[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/samples/wasm-c-api/src/LICENSE) ### wasmtime @@ -76,7 +76,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the ### zephyr -[LICENSE](./samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE) +[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE) ### wac diff --git a/README.md b/README.md index 31156b9cc..13f777a2f 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ WebAssembly Micro Runtime (WAMR) is a lightweight standalone WebAssembly (Wasm) - [**iwasm**](./product-mini/): The executable binary built with WAMR VMcore supports WASI and command line interface. - [**wamrc**](./wamr-compiler/): The AOT compiler to compile Wasm file into AOT file - Useful components and tools for building real solutions with WAMR vmcore: - - [App-framework](./core/app-framework/README.md): A framework for supporting APIs for the Wasm applications - - [App-manager](./core/app-mgr/README.md): a framework for dynamical loading the Wasm module remotely + - [App-framework](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/README.md): A framework for supporting APIs for the Wasm applications + - [App-manager](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-mgr/README.md): a framework for dynamical loading the Wasm module remotely - [WAMR-IDE](./test-tools/wamr-ide): An experimental VSCode extension for developping WebAssembly applications with C/C++ diff --git a/assembly-script/.gitignore b/assembly-script/.gitignore deleted file mode 100644 index 07e6e472c..000000000 --- a/assembly-script/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/node_modules diff --git a/assembly-script/README.md b/assembly-script/README.md deleted file mode 100644 index a1324e9d7..000000000 --- a/assembly-script/README.md +++ /dev/null @@ -1,124 +0,0 @@ -# AssemblyScript_on_WAMR -This project is based on [Wasm Micro Runtime](https://github.com/bytecodealliance/wasm-micro-runtime) (WAMR) and [AssemblyScript](https://github.com/AssemblyScript/assemblyscript). It implements some of the `wamr app framework` in *assemblyscript*, which allows you to write some applications in *assemblyscript* and dynamically installed on *WAMR Runtime* - -## Building -To build the samples in this repo, you need `npm` on your system -``` bash -sudo apt install npm -``` - -Then install all the dependencies under the repo's root dir -``` bash -cd $repo_root -npm install -``` - -Use the command to build all samples: -``` bash -npm run build:all -``` -or you can build every sample individually: -``` bash -npm run build:timer -npm run build:publisher -npm run build:subscriber -# ... -``` -You will get the compiled wasm file under `build` folder - -Please refer to [package.json](./package.json) for more commands. - -## Run -These applications require WAMR's application framework, you need to build WAMR first. - -``` bash -cd ${WAMR_ROOT}/samples/simple -./build.sh -``` - -You will get two executable files under `out` folder: - -`simple`: The wamr runtime with application framework - -`host_tool`: The tool used to dynamically install/uninstall applications - -1. Start the runtime: - ``` bash - ./simple -s - ``` - -2. Install the compiled wasm file using `host_tool`: - ``` bash - ./host_tool -i app_name -f your_compiled_wasm_file.wasm - ``` -You can also use the WAMR's AoT compiler `wamrc` to compile the wasm bytecode into native code before you run them. Please refer to this [guide](../README.md#build-wamrc-aot-compiler) to build and install `WAMR AoT compiler`. - -After installing `wamrc`, you can compile the wasm file using command: -``` bash -wamrc -o file_name.aot file_name.wasm -``` -and you can install the AoT file to the runtime: -``` bash -./host_tool -i app_name -f your_compiled_aot_file.aot -``` - -## Development -You can develop your own application based on the `wamr_app_lib` APIs. - -### Console APIs -``` typescript -function log(a: string): void; -function log_number(a: number): void; -``` - -### Timer APIs -``` typescript -function setTimeout(cb: () => void, timeout: i32): user_timer; -function setInterval(cb: () => void, timeout: i32): user_timer; -function timer_cancel(timer: user_timer): void; -function timer_restart(timer: user_timer, interval: number): void; -function now(): i32; - -// export to runtime -function on_timer_callback(on_timer_id: i32): void; -``` - -### Request APIs -``` typescript -// register handler -function register_resource_handler(url: string, - request_handle: request_handler_f): void; -// request -function post(url: string, payload: ArrayBuffer, payload_len: number, - tag: string, cb: (resp: wamr_response) => void): void; -function get(url: string, tag: string, - cb: (resp: wamr_response) => void): void; -function put(url: string, payload: ArrayBuffer, payload_len: number, tag: string, - cb: (resp: wamr_response) => void): void; -function del(url: string, tag: string, - cb: (resp: wamr_response) => void): void; - -// response -function make_response_for_request(req: wamr_request): wamr_response; -function api_response_send(resp: wamr_response): void; - -// event -function publish_event(url: string, fmt: number, - payload: ArrayBuffer, payload_len: number): void; -function subscribe_event(url: string, cb: request_handler_f): void; - -// export to runtime -function on_request(buffer_offset: i32, size: i32): void; -function on_response(buffer_offset : i32, size: i32): void; -``` - -You should export the `on_timer_callback`, `on_request` and `on_response` in your application entry file, refer to the samples for example. - -To build your application, you can use `asc`: -``` bash -asc app.ts -b build/app.wasm -t build/app.wat --sourceMap --validate --optimize -``` -or you can add a command into [package.json](./package.json): -``` json -"build:app": "asc app.ts -b build/app.wasm -t build/app.wat --sourceMap --validate --optimize", -``` diff --git a/assembly-script/package-lock.json b/assembly-script/package-lock.json deleted file mode 100644 index 0750cc05e..000000000 --- a/assembly-script/package-lock.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "assembly_script", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "assemblyscript": { - "version": "0.17.4", - "resolved": "https://registry.npm.taobao.org/assemblyscript/download/assemblyscript-0.17.4.tgz", - "integrity": "sha1-1GEduJpClDNa1H7DxmYaJqRCh3E=", - "dev": true, - "requires": { - "binaryen": "98.0.0-nightly.20201109", - "long": "^4.0.0" - } - }, - "binaryen": { - "version": "98.0.0-nightly.20201109", - "resolved": "https://registry.npm.taobao.org/binaryen/download/binaryen-98.0.0-nightly.20201109.tgz", - "integrity": "sha1-USv2yhXGe/dAIURzSkg25jmTqgU=", - "dev": true - }, - "long": { - "version": "4.0.0", - "resolved": "https://registry.npm.taobao.org/long/download/long-4.0.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flong%2Fdownload%2Flong-4.0.0.tgz", - "integrity": "sha1-mntxz7fTYaGU6lVSQckvdGjVvyg=", - "dev": true - } - } -} diff --git a/assembly-script/package.json b/assembly-script/package.json deleted file mode 100644 index b80145fae..000000000 --- a/assembly-script/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "assembly_script", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "build:request_handler": "asc samples/request_handler.ts -b build/request_handler.wasm -t build/request_handler.wat --sourceMap --optimize --exportRuntime --use abort=", - "build:request_sender": "asc samples/request_sender.ts -b build/request_sender.wasm -t build/request_sender.wat --sourceMap --optimize --exportRuntime --use abort=", - "build:timer": "asc samples/timer.ts -b build/timer.wasm -t build/timer.wat --sourceMap --optimize --exportRuntime --use abort=", - "build:publisher": "asc samples/event_publisher.ts -b build/event_publisher.wasm -t build/event_publisher.wat --sourceMap --optimize --exportRuntime --use abort=", - "build:subscriber": "asc samples/event_subscriber.ts -b build/event_subscriber.wasm -t build/event_subscriber.wat --sourceMap --optimize --exportRuntime --use abort=", - "build:all": "npm run build:request_handler; npm run build:request_sender; npm run build:timer; npm run build:subscriber; npm run build:publisher" - }, - "author": "", - "license": "ISC", - "devDependencies": { - "assemblyscript": "^0.18.15" - } -} diff --git a/assembly-script/samples/event_publisher.ts b/assembly-script/samples/event_publisher.ts deleted file mode 100644 index 3ca133fdb..000000000 --- a/assembly-script/samples/event_publisher.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -// The entry file of your WebAssembly module. -import * as console from "../wamr_app_lib/console" -import * as timer from "../wamr_app_lib/timer" -import * as request from "../wamr_app_lib/request" - -function publish_overheat_event(): void { - var payload = String.UTF8.encode("warning: temperature is over high"); - request.publish_event("alert/overheat", 0, payload, payload.byteLength); -} - -export function on_init() : void { - timer.setInterval(publish_overheat_event, 2000); -} - -export function on_destroy() : void { - -} - - -/* Function below are requred by wamr runtime, don't remove or modify them */ -export function _on_timer_callback(on_timer_id: i32): void { - timer.on_timer_callback(on_timer_id); -} - -export function _on_request(buffer_offset: i32, size: i32): void { - request.on_request(buffer_offset, size); -} - -export function _on_response(buffer_offset : i32, size: i32): void { - request.on_response(buffer_offset, size); -} \ No newline at end of file diff --git a/assembly-script/samples/event_subscriber.ts b/assembly-script/samples/event_subscriber.ts deleted file mode 100644 index c9aa52a8e..000000000 --- a/assembly-script/samples/event_subscriber.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -// The entry file of your WebAssembly module. -import * as console from "../wamr_app_lib/console" -import * as timer from "../wamr_app_lib/timer" -import * as request from "../wamr_app_lib/request" - -export function on_init() : void { - request.subscribe_event("alert/overheat", (req) => { - console.log("### user over heat event handler called:"); - - console.log(""); - console.log(" " + String.UTF8.decode(req.payload) + "\n"); - }) -} - -export function on_destroy() : void { - -} - - -/* Function below are requred by wamr runtime, don't remove or modify them */ -export function _on_timer_callback(on_timer_id: i32): void { - timer.on_timer_callback(on_timer_id); -} - -export function _on_request(buffer_offset: i32, size: i32): void { - request.on_request(buffer_offset, size); -} - -export function _on_response(buffer_offset : i32, size: i32): void { - request.on_response(buffer_offset, size); -} \ No newline at end of file diff --git a/assembly-script/samples/request_handler.ts b/assembly-script/samples/request_handler.ts deleted file mode 100644 index ef9f58c58..000000000 --- a/assembly-script/samples/request_handler.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - - // The entry file of your WebAssembly module. -import * as console from "../wamr_app_lib/console" -import * as timer from "../wamr_app_lib/timer" -import * as request from "../wamr_app_lib/request" - -export function on_init() : void { - request.register_resource_handler("/test", (req) => { - console.log("### Req: /test " + String.UTF8.decode(req.payload)); - - console.log(" request payload:"); - console.log(" " + String.UTF8.decode(req.payload) + "\n"); - - var resp = request.make_response_for_request(req); - resp.set_payload(String.UTF8.encode("Ok"), 2); - request.api_response_send(resp); - }); -} - -export function on_destroy() : void { - -} - - -/* Function below are requred by wamr runtime, don't remove or modify them */ -export function _on_timer_callback(on_timer_id: i32): void { - timer.on_timer_callback(on_timer_id); -} - -export function _on_request(buffer_offset: i32, size: i32): void { - request.on_request(buffer_offset, size); -} - -export function _on_response(buffer_offset : i32, size: i32): void { - request.on_response(buffer_offset, size); -} \ No newline at end of file diff --git a/assembly-script/samples/request_sender.ts b/assembly-script/samples/request_sender.ts deleted file mode 100644 index 5648985e7..000000000 --- a/assembly-script/samples/request_sender.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -// The entry file of your WebAssembly module. -import * as console from "../wamr_app_lib/console" -import * as timer from "../wamr_app_lib/timer" -import * as request from "../wamr_app_lib/request" - -export function on_init() : void { - var payload = String.UTF8.encode("test message"); - request.post("/test", payload, payload.byteLength, "", (resp) => { - if (resp != null) { - console.log("Post Success"); - - if (resp.payload != null) { - console.log(" response payload:") - console.log(" " + String.UTF8.decode(resp.payload!) + "\n"); - } - } - else - console.log("Post Timeout"); - }); -} - -export function on_destroy() : void { - -} - - -/* Function below are requred by wamr runtime, don't remove or modify them */ -export function _on_timer_callback(on_timer_id: i32): void { - timer.on_timer_callback(on_timer_id); -} - -export function _on_request(buffer_offset: i32, size: i32): void { - request.on_request(buffer_offset, size); -} - -export function _on_response(buffer_offset : i32, size: i32): void { - request.on_response(buffer_offset, size); -} \ No newline at end of file diff --git a/assembly-script/samples/timer.ts b/assembly-script/samples/timer.ts deleted file mode 100644 index 2e3f69d29..000000000 --- a/assembly-script/samples/timer.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -// The entry file of your WebAssembly module. -import * as console from '../wamr_app_lib/console' -import * as timer from '../wamr_app_lib/timer' - -/* clousure is not implemented yet, we need to declare global variables - so that they can be accessed inside a callback function */ -var cnt = 0; -var my_timer: timer.user_timer; - -export function on_init(): void { - /* The callback function will be called every 2 second, - and will stop after 10 calls */ - my_timer = timer.setInterval(() => { - cnt ++; - console.log((cnt * 2).toString() + " seconds passed"); - - if (cnt >= 10) { - timer.timer_cancel(my_timer); - console.log("Stop Timer"); - } - }, 2000); -} - -export function on_destroy(): void { - -} - -/* Function below are requred by wamr runtime, don't remove or modify them */ -export function _on_timer_callback(on_timer_id: i32): void { - timer.on_timer_callback(on_timer_id); -} \ No newline at end of file diff --git a/assembly-script/samples/tsconfig.json b/assembly-script/samples/tsconfig.json deleted file mode 100644 index c614e5c8e..000000000 --- a/assembly-script/samples/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "../node_modules/assemblyscript/std/assembly.json", - "include": [ - "./**/*.ts" - ] -} \ No newline at end of file diff --git a/assembly-script/wamr_app_lib/console.ts b/assembly-script/wamr_app_lib/console.ts deleted file mode 100644 index f20ede938..000000000 --- a/assembly-script/wamr_app_lib/console.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -@external("env", "puts") -declare function printf(a: ArrayBuffer): i32; - -export function log(a: string): void { - printf(String.UTF8.encode(a, true)); -} - -export function log_number(a: number): void { - printf(String.UTF8.encode(a.toString())); -} \ No newline at end of file diff --git a/assembly-script/wamr_app_lib/request.ts b/assembly-script/wamr_app_lib/request.ts deleted file mode 100644 index 16a229277..000000000 --- a/assembly-script/wamr_app_lib/request.ts +++ /dev/null @@ -1,495 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -import * as console from './console' -import * as timer from './timer' - -@external("env", "wasm_response_send") -declare function wasm_response_send(buffer: ArrayBuffer, size: i32): bool; - -@external("env", "wasm_register_resource") -declare function wasm_register_resource(url: ArrayBuffer): void; - -@external("env", "wasm_post_request") -declare function wasm_post_request(buffer: ArrayBuffer, size: i32): void; - -@external("env", "wasm_sub_event") -declare function wasm_sub_event(url: ArrayBuffer): void; - -var COAP_GET = 1; -var COAP_POST = 2; -var COAP_PUT = 3; -var COAP_DELETE = 4; -var COAP_EVENT = COAP_DELETE + 2; - -/* CoAP response codes */ -export enum CoAP_Status { - 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 */ - 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 */ - REQUEST_ENTITY_TOO_LARGE_4_13 = 141, /* REQUEST_ENTITY_TOO_LARGE */ - 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 */ - PROXYING_NOT_SUPPORTED_5_05 = 165, /* PROXYING_NOT_SUPPORTED */ - - /* Erbium errors */ - MEMORY_ALLOCATION_ERROR = 192, PACKET_SERIALIZATION_ERROR, - - /* Erbium hooks */ - MANUAL_RESPONSE, PING_RESPONSE -}; - -var g_mid: i32 = 0; -class wamr_request { - mid: i32 = 0; - url: string = ""; - action: i32 = 0; - fmt: i32 = 0; - payload: ArrayBuffer; - payload_len: i32 = 0; - - sender: i32 = 0; - - constructor(mid: i32, url: string, action: i32, fmt: i32, - payload: ArrayBuffer, payload_len: number) { - this.mid = mid; - this.url = url; - this.action = action; - this.fmt = fmt; - this.payload = payload; - this.payload_len = i32(payload_len); - } -} - -class wamr_response { - mid: i32 = 0; - status: i32 = 0; - fmt: i32 = 0; - payload: ArrayBuffer | null; - payload_len: i32 = 0; - - receiver: i32 = 0; - - constructor(mid: i32, status: i32, fmt: i32, - payload: ArrayBuffer | null, payload_len: i32) { - this.mid = mid; - this.status = status; - this.fmt = fmt; - this.payload = payload; - this.payload_len = payload_len; - } - - set_status(status: number): void { - this.status = i32(status); - } - - set_payload(payload: ArrayBuffer, payload_len: number): void { - this.payload = payload; - this.payload_len = i32(payload_len); - } -} - -class wamr_resource { - url: string; - type: number; - cb: request_handler_f; - - constructor(url: string, type: number, cb: request_handler_f) { - this.url = url; - this.type = type; - this.cb = cb; - } -} - -function is_expire(trans: wamr_transaction, index: i32, array: Array): bool { - var now = timer.now(); - - var elapsed_ms = (now < trans.time) ? - (now + (0xFFFFFFFF - trans.time) + 1) : (now - trans.time); - - return elapsed_ms >= TRANSACTION_TIMEOUT_MS; -} - -function not_expire(trans: wamr_transaction, index: i32, array: Array): bool { - var now = timer.now(); - - var elapsed_ms = (now < trans.time) ? - (now + (0xFFFFFFFF - trans.time) + 1) : (now - trans.time); - - return elapsed_ms < TRANSACTION_TIMEOUT_MS; -} - -function transaction_timeout_handler(): void { - var now = timer.now(); - - var expired = transaction_list.filter(is_expire); - transaction_list = transaction_list.filter(not_expire); - - expired.forEach(item => { - item.cb(null); - transaction_remove(item); - }) - - if (transaction_list.length > 0) { - var elpased_ms: number, ms_to_expiry: number; - now = timer.now(); - if (now < transaction_list[0].time) { - elpased_ms = now + (0xFFFFFFFF - transaction_list[0].time) + 1; - } else { - elpased_ms = now - transaction_list[0].time; - } - ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms; - timer.timer_restart(g_trans_timer, ms_to_expiry); - } else { - timer.timer_cancel(g_trans_timer); - } -} - -function transaction_find(mid: number): wamr_transaction | null { - for (let i = 0; i < transaction_list.length; i++) { - if (transaction_list[i].mid == mid) - return transaction_list[i]; - } - return null; -} - -function transaction_add(trans: wamr_transaction): void { - transaction_list.push(trans); - - if (transaction_list.length == 1) { - g_trans_timer = timer.setTimeout( - transaction_timeout_handler, - TRANSACTION_TIMEOUT_MS - ); - } -} - -function transaction_remove(trans: wamr_transaction): void { - var index = transaction_list.indexOf(trans); - transaction_list.splice(index, 1); -} - -var transaction_list = new Array(); -class wamr_transaction { - mid: number; - time: number; - cb: (resp: wamr_response | null) => void; - - constructor(mid: number, time: number, cb: (resp: wamr_response) => void) { - this.mid = mid; - this.time = time; - this.cb = cb; - } -} - -var REQUEST_PACKET_FIX_PART_LEN = 18; -var RESPONSE_PACKET_FIX_PART_LEN = 16; -var TRANSACTION_TIMEOUT_MS = 5000; -var g_trans_timer: timer.user_timer; - -var Reg_Event = 0; -var Reg_Request = 1; - -function pack_request(req: wamr_request): DataView { - var url_len = req.url.length + 1; - var len = REQUEST_PACKET_FIX_PART_LEN + url_len + req.payload_len - var buf = new ArrayBuffer(len); - - var dataview = new DataView(buf, 0, len); - - dataview.setUint8(0, 1); - dataview.setUint8(1, u8(req.action)); - dataview.setUint16(2, u16(req.fmt)); - dataview.setUint32(4, req.mid); - dataview.setUint32(8, req.sender); - dataview.setUint16(12, u16(url_len)) - dataview.setUint32(14, req.payload_len); - - var i = 0; - for (i = 0; i < url_len - 1; i++) { - dataview.setUint8(i + 18, u8(req.url.codePointAt(i))); - } - dataview.setUint8(i + 18, 0); - - var payload_view = new DataView(req.payload); - for (i = 0; i < req.payload_len; i++) { - dataview.setUint8(i + 18 + url_len, u8(payload_view.getUint8(i))); - } - - return dataview; -} - -function unpack_request(packet: ArrayBuffer, size: i32): wamr_request { - var dataview = new DataView(packet, 0, size); - - if (dataview.getUint8(0) != 1) - throw new Error("packet version mismatch"); - - if (size < REQUEST_PACKET_FIX_PART_LEN) - throw new Error("packet size error"); - - var url_len = dataview.getUint16(12); - var payload_len = dataview.getUint32(14); - - if (size != (REQUEST_PACKET_FIX_PART_LEN + url_len + payload_len)) - throw new Error("packet size error"); - - var action = dataview.getUint8(1); - var fmt = dataview.getUint16(2); - var mid = dataview.getUint32(4); - var sender = dataview.getUint32(8); - - var url = packet.slice(REQUEST_PACKET_FIX_PART_LEN, REQUEST_PACKET_FIX_PART_LEN + url_len - 1); - var payload = packet.slice(REQUEST_PACKET_FIX_PART_LEN + url_len, REQUEST_PACKET_FIX_PART_LEN + url_len + payload_len); - - var req = new wamr_request(mid, String.UTF8.decode(url), action, fmt, payload, payload_len); - req.sender = sender; - - return req; -} - -function pack_response(resp: wamr_response): DataView { - var len = RESPONSE_PACKET_FIX_PART_LEN + resp.payload_len - var buf = new ArrayBuffer(len); - - var dataview = new DataView(buf, 0, len); - - dataview.setUint8(0, 1); - dataview.setUint8(1, u8(resp.status)); - dataview.setUint16(2, u16(resp.fmt)); - dataview.setUint32(4, resp.mid); - dataview.setUint32(8, resp.receiver); - dataview.setUint32(12, resp.payload_len) - - if (resp.payload != null) { - var payload_view = new DataView(resp.payload!); - for (let i = 0; i < resp.payload_len; i++) { - dataview.setUint8(i + 16, payload_view.getUint8(i)); - } - } - - return dataview; -} - -function unpack_response(packet: ArrayBuffer, size: i32): wamr_response { - var dataview = new DataView(packet, 0, size); - - if (dataview.getUint8(0) != 1) - throw new Error("packet version mismatch"); - - if (size < RESPONSE_PACKET_FIX_PART_LEN) - throw new Error("packet size error"); - - var payload_len = dataview.getUint32(12); - if (size != RESPONSE_PACKET_FIX_PART_LEN + payload_len) - throw new Error("packet size error"); - - var status = dataview.getUint8(1); - var fmt = dataview.getUint16(2); - var mid = dataview.getUint32(4); - var receiver = dataview.getUint32(8); - - var payload = packet.slice(RESPONSE_PACKET_FIX_PART_LEN); - - var resp = new wamr_response(mid, status, fmt, payload, payload_len); - resp.receiver = receiver; - - return resp; -} - -function do_request(req: wamr_request, cb: (resp: wamr_response) => void): void { - var trans = new wamr_transaction(req.mid, timer.now(), cb); - var msg = pack_request(req); - - transaction_add(trans); - - wasm_post_request(msg.buffer, msg.byteLength); -} - -function do_response(resp: wamr_response): void { - var msg = pack_response(resp); - - wasm_response_send(msg.buffer, msg.byteLength); -} - -var resource_list = new Array(); -type request_handler_f = (req: wamr_request) => void; - -function registe_url_handler(url: string, cb: request_handler_f, type: number): void { - for (let i = 0; i < resource_list.length; i++) { - if (resource_list[i].type == type && resource_list[i].url == url) { - resource_list[i].cb = cb; - return; - } - } - - var res = new wamr_resource(url, type, cb); - resource_list.push(res); - - if (type == Reg_Request) - wasm_register_resource(String.UTF8.encode(url)); - else - wasm_sub_event(String.UTF8.encode(url)); -} - -function is_event_type(req: wamr_request): bool { - return req.action == COAP_EVENT; -} - -function check_url_start(url: string, leading_str: string): bool { - return url.split('/')[0] == leading_str.split('/')[0]; -} - -/* User APIs below */ -export function post(url: string, payload: ArrayBuffer, payload_len: number, tag: string, - cb: (resp: wamr_response) => void): void { - var req = new wamr_request(g_mid++, url, COAP_POST, 0, payload, payload_len); - - do_request(req, cb); -} - -export function get(url: string, tag: string, - cb: (resp: wamr_response) => void): void { - var req = new wamr_request(g_mid++, url, COAP_GET, 0, new ArrayBuffer(0), 0); - - do_request(req, cb); -} - -export function put(url: string, payload: ArrayBuffer, payload_len: number, tag: string, - cb: (resp: wamr_response) => void): void { - var req = new wamr_request(g_mid++, url, COAP_PUT, 0, payload, payload_len); - - do_request(req, cb); -} - -export function del(url: string, tag: string, - cb: (resp: wamr_response) => void): void { - var req = new wamr_request(g_mid++, url, COAP_DELETE, 0, new ArrayBuffer(0), 0); - - do_request(req, cb); -} - -export function make_response_for_request(req: wamr_request): wamr_response { - var resp = new wamr_response(req.mid, CoAP_Status.CONTENT_2_05, 0, null, 0); - resp.receiver = req.sender; - - return resp; -} - -export function api_response_send(resp: wamr_response): void { - do_response(resp); -} - -export function register_resource_handler(url: string, - request_handle: request_handler_f): void { - registe_url_handler(url, request_handle, Reg_Request); -} - -export function publish_event(url: string, fmt: number, - payload: ArrayBuffer, payload_len: number): void { - var req = new wamr_request(g_mid++, url, COAP_EVENT, i32(fmt), payload, payload_len); - - var msg = pack_request(req); - - wasm_post_request(msg.buffer, msg.byteLength); -} - -export function subscribe_event(url: string, cb: request_handler_f): void { - registe_url_handler(url, cb, Reg_Event); -} - - -/* These two APIs are required by wamr runtime, - use a wrapper to export them in the entry file - - e.g: - - import * as request from '.wamr_app_lib/request' - - // Your code here ... - - export function _on_request(buffer_offset: i32, size: i32): void { - on_request(buffer_offset, size); - } - - export function _on_response(buffer_offset: i32, size: i32): void { - on_response(buffer_offset, size); - } -*/ -export function on_request(buffer_offset: i32, size: i32): void { - var buffer = new ArrayBuffer(size); - var dataview = new DataView(buffer); - - for (let i = 0; i < size; i++) { - dataview.setUint8(i, load(buffer_offset + i, 0, 1)); - } - - var req = unpack_request(buffer, size); - - var is_event = is_event_type(req); - - for (let i = 0; i < resource_list.length; i++) { - if ((is_event && resource_list[i].type == Reg_Event) - || (!is_event && resource_list[i].type == Reg_Request)) { - if (check_url_start(req.url, resource_list[i].url)) { - resource_list[i].cb(req); - return; - } - } - } - - console.log("on_request: exit. no service handler."); -} - -export function on_response(buffer_offset: i32, size: i32): void { - var buffer = new ArrayBuffer(size); - var dataview = new DataView(buffer); - - for (let i = 0; i < size; i++) { - dataview.setUint8(i, load(buffer_offset + i, 0, 1)); - } - - var resp = unpack_response(buffer, size); - var trans = transaction_find(resp.mid); - - if (trans != null) { - if (transaction_list.indexOf(trans) == 0) { - if (transaction_list.length >= 2) { - var elpased_ms: number, ms_to_expiry: number; - var now = timer.now(); - if (now < transaction_list[1].time) { - elpased_ms = now + (0xFFFFFFFF - transaction_list[1].time) + 1; - } else { - elpased_ms = now - transaction_list[1].time; - } - ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms; - timer.timer_restart(g_trans_timer, ms_to_expiry); - } else { - timer.timer_cancel(g_trans_timer); - } - } - - trans.cb(resp); - } -} diff --git a/assembly-script/wamr_app_lib/timer.ts b/assembly-script/wamr_app_lib/timer.ts deleted file mode 100644 index ea8363e8c..000000000 --- a/assembly-script/wamr_app_lib/timer.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -@external("env", "wasm_create_timer") -declare function wasm_create_timer(a: i32, b: bool, c: bool): i32; - -@external("env", "wasm_timer_cancel") -declare function wasm_timer_cancel(a: i32): void; - -@external("env", "wasm_timer_restart") -declare function wasm_timer_restart(a: i32, b: i32): void; - -@external("env", "wasm_get_sys_tick_ms") -declare function wasm_get_sys_tick_ms(): i32; - -export var timer_list = new Array(); - -export class user_timer { - timer_id: i32 = 0; - timeout: i32; - period: bool = false; - cb: () => void; - - constructor(cb: () => void, timeout: i32, period: bool) { - this.cb = cb; - this.timeout = timeout; - this.period = period - this.timer_id = timer_create(this.timeout, this.period, true); - } -} - -export function timer_create(a: i32, b: bool, c: bool): i32 { - return wasm_create_timer(a, b, c); -} - -export function setTimeout(cb: () => void, timeout: i32): user_timer { - var timer = new user_timer(cb, timeout, false); - timer_list.push(timer); - - return timer; -} - -export function setInterval(cb: () => void, timeout: i32): user_timer { - var timer = new user_timer(cb, timeout, true); - timer_list.push(timer); - - return timer; -} - -export function timer_cancel(timer: user_timer): void { - wasm_timer_cancel(timer.timer_id); - - var i = 0; - for (i = 0; i < timer_list.length; i++) { - if (timer_list[i].timer_id == timer.timer_id) - break; - } - - timer_list.splice(i, 1); -} - -export function timer_restart(timer: user_timer, interval: number): void { - wasm_timer_restart(timer.timer_id, i32(interval)); -} - -export function now(): i32 { - return wasm_get_sys_tick_ms(); -} - -// This export function need to be copied to the top application file -// -export function on_timer_callback(on_timer_id: i32): void { - for (let i = 0; i < timer_list.length; i++) { - if (timer_list[i].timer_id == on_timer_id) { - timer_list[i].cb(); - } - } -} \ No newline at end of file diff --git a/assembly-script/wamr_app_lib/tsconfig.json b/assembly-script/wamr_app_lib/tsconfig.json deleted file mode 100644 index c614e5c8e..000000000 --- a/assembly-script/wamr_app_lib/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "../node_modules/assemblyscript/std/assembly.json", - "include": [ - "./**/*.ts" - ] -} \ No newline at end of file diff --git a/build-scripts/SConscript b/build-scripts/SConscript index d2bee9581..648373b38 100644 --- a/build-scripts/SConscript +++ b/build-scripts/SConscript @@ -13,8 +13,6 @@ objs = [] WAMR_ROOT_DIR = os.path.join(cwd, "..") SHARED_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'shared') IWASM_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'iwasm') -APP_MGR_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-mgr') -APP_FRAMEWORK_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-framework') DEPS_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'deps') if GetDepend(['WAMR_BUILD_INTERP']): @@ -28,12 +26,6 @@ if GetDepend(['WAMR_BUILD_AOT']): script_path = os.path.join(IWASM_DIR, 'compilation', 'SConscript') objs += SConscript(script_path) -if GetDepend(['WAMR_BUILD_APP_FRAMEWORK']): - objs += SConscript(os.path.join(APP_FRAMEWORK_DIR, 'SConscript')) - objs += SConscript(os.path.join(SHARED_DIR, 'coap', 'SConscript')) - objs += SConscript(os.path.join(APP_MGR_DIR, 'app-manager', 'SConscript')) - objs += SConscript(os.path.join(APP_MGR_DIR, 'app-mgr-shared', 'SConscript')) - if GetDepend(['WAMR_BUILD_LIBC_BUILTIN']): objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-builtin', 'SConscript')) diff --git a/build-scripts/runtime_lib.cmake b/build-scripts/runtime_lib.cmake index 832629c01..3ab0cff4f 100644 --- a/build-scripts/runtime_lib.cmake +++ b/build-scripts/runtime_lib.cmake @@ -10,12 +10,6 @@ endif () if (NOT DEFINED IWASM_DIR) set (IWASM_DIR ${WAMR_ROOT_DIR}/core/iwasm) endif () -if (NOT DEFINED APP_MGR_DIR) - set (APP_MGR_DIR ${WAMR_ROOT_DIR}/core/app-mgr) -endif () -if (NOT DEFINED APP_FRAMEWORK_DIR) - set (APP_FRAMEWORK_DIR ${WAMR_ROOT_DIR}/core/app-framework) -endif () if (NOT DEFINED DEPS_DIR) set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps) endif () @@ -88,13 +82,6 @@ if (WAMR_BUILD_GC EQUAL 1) set (WAMR_BUILD_REF_TYPES 1) endif () -if (WAMR_BUILD_APP_FRAMEWORK EQUAL 1) - include (${APP_FRAMEWORK_DIR}/app_framework.cmake) - include (${SHARED_DIR}/coap/lib_coap.cmake) - include (${APP_MGR_DIR}/app-manager/app_mgr.cmake) - include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake) -endif () - if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1) include (${IWASM_DIR}/libraries/libc-builtin/libc_builtin.cmake) endif () @@ -200,9 +187,6 @@ set (source_all ${IWASM_COMPL_SOURCE} ${IWASM_FAST_JIT_SOURCE} ${IWASM_GC_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} - ${NATIVE_INTERFACE_SOURCE} - ${APP_MGR_SOURCE} ${LIB_WASI_THREADS_SOURCE} ${LIB_PTHREAD_SOURCE} ${THREAD_MGR_SOURCE} diff --git a/ci/coding_guidelines_check.py b/ci/coding_guidelines_check.py index 062614597..924a24280 100644 --- a/ci/coding_guidelines_check.py +++ b/ci/coding_guidelines_check.py @@ -21,7 +21,6 @@ EXCLUDE_PATHS = [ "**/.git/*", "**/.github/*", "**/.vscode/*", - "**/assembly-script/*", "**/build/*", "**/build-scripts/*", "**/ci/*", @@ -30,9 +29,7 @@ EXCLUDE_PATHS = [ "**/samples/wasm-c-api/src/*.*", "**/samples/workload/*", "**/test-tools/wasi-sdk/*", - "**/test-tools/IoT-APP-Store-Demo/*", "**/tests/wamr-test-suites/workspace/*", - "**/wamr-sdk/*", ] C_SUFFIXES = [".c", ".cpp", ".h"] diff --git a/core/app-framework/README.md b/core/app-framework/README.md deleted file mode 100644 index d1476fd8b..000000000 --- a/core/app-framework/README.md +++ /dev/null @@ -1,120 +0,0 @@ -# Application framework - -By using the WAMR VM core, we are flexible to build different application frameworks for the specific domains, although it would take quite some effort. - -The WAMR has offered a comprehensive framework for programming WASM applications for device and IoT usages. The framework supports running multiple applications, that are based on the event driven programming model. Here are the supporting API sets by the [WAMR application framework library](../doc/wamr_api.md) : - -- Timer, Inter-app communication (request/response and pub/sub), Sensor, Connectivity and data transmission, 2D graphic UI - -Browse the folder [core/app-framework](./app-framework) for how to extend the application framework. - - -## Directory structure -This folder "app-native-shared" is for the source files shared by both WASM APP and native runtime - -- The c files in this directory are compiled into both the WASM APP and runtime. -- The header files for distributing to SDK are placed in the "bi-inc" folder. - -This folder "template" contains a pre-defined directory structure for a framework component. The developers can copy the template folder to create new components to the application framework. - -Every other subfolder is framework component. Each component contains two library parts: **app and native**. - -- The "base" component provide timer API and inter-app communication support. It must be enabled if other components are selected. -- Under the "app" folder of a component, the subfolder "wa_inc" holds all header files that should be included by the WASM applications - -## Application framework basic model - -The app framework is built on top of two fundamental operations: - -- [Native calls into WASM function](../../doc/embed_wamr.md) - -- [WASM app calls into native API](../../doc/export_native_api.md) - -Asynchronized programming model is supported for WASM applications - -- Every WASM app has its own sandbox and thread - -- Queue and messaging - - - - - -## Customized building of app framework - -A component can be compilation configurable to the runtime. The wamr SDK tool "build_sdk.sh" supports menu config to select app components for building a customized runtime. - -A number of CMAKE variables are defined to control build of framework and components. You can create a cmake file for defining these variables and include it in the CMakeList.txt for your software, or pass it in "-x" argument when run the [build_sdk.sh](../../wamr-sdk/build_sdk.sh) for building the runtime SDK. - -```cmake -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE) -``` - -Variables: - -- **WAMR_BUILD_APP_FRAMEWORK**: enable the application framework -- **WAMR_BUILD_APP_LIST**: the selected components to be built into the final runtime - - - -The configuration file can be generated through the wamr-sdk menu config: - -```bash -cd wamr-sdk -./build_sdk -n [profile] -i -``` - - - -## Create new components - -Generally you should follow following steps to create a new component: - -- Copy the “template” for creating a new folder - -- Implement the app part - - - If your component exports native function to WASM, ensure your created a header file under app for declaring the function prototype. - - If you component provides header files for the WASM applications to include, ensure it is placed under subfolder "wa_inc". - -- Implement the native part - - - If your native function is exported to WASM, you need to create an inl file for the registration. It can be any file name, assuming the file name is "my_component.inl" here: - - ```c - //use right signature for your functions - EXPORT_WASM_API_WITH_SIG(wasm_my_component_api_1, "(i*~)i"), - EXPORT_WASM_API_WITH_SIG(wasm_my_component_api_2, "(i)i"), - ``` - - - Ensure "wasm_lib.cmake" is provided as it will be included by the WAMR SDK building script - - - Add a definition in "wasm_lib.cmake" for your component, e.g. - - ```cmake - add_definitions (-DAPP_FRAMEWORK_MY_COMPONENT) - ``` - -- Modify the file [app_ext_lib_export.c](./app_ext_lib_export.c) to register native APIs exported for the new introduced component. Skip it if not exporting native functions. - - ``` - #include "lib_export.h" - - ... - #ifdef APP_FRAMEWORK_MY_COMPONENT // this definition is created in wasm_lib.cmake - #include "my_component_native_api.h" - #endif - - static NativeSymbol extended_native_symbol_defs[] = { - ... - #ifdef APP_FRAMEWORK_MY_COMPONENT - #include "my_component.inl" - #endif - }; - ``` - - -## Sensor component working flow -![](../../doc/pics/sensor_callflow.PNG) - diff --git a/core/app-framework/app-native-shared/README.md b/core/app-framework/app-native-shared/README.md deleted file mode 100644 index b166e0b3a..000000000 --- a/core/app-framework/app-native-shared/README.md +++ /dev/null @@ -1,11 +0,0 @@ - Notes: -======= -This folder is for the source files shared by both WASM APP and native runtime - -- The c files in this directory are compiled into both the WASM APP and runtime. -- The header files for distributing to SDK are placed in the "bi-inc" folder. - - - - - diff --git a/core/app-framework/app-native-shared/attr_container.c b/core/app-framework/app-native-shared/attr_container.c deleted file mode 100644 index e1e9f4e35..000000000 --- a/core/app-framework/app-native-shared/attr_container.c +++ /dev/null @@ -1,986 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "bi-inc/attr_container.h" - -typedef union jvalue { - bool z; - int8_t i8; - uint8_t u8; - int16_t i16; - uint16_t u16; - int32_t i32; - uint32_t u32; - int64_t i64; - uint64_t u64; - float f; - double d; -} jvalue; - -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) -{ - uint16_t ret; - bh_memcpy_s(&ret, sizeof(uint16_t), buf, sizeof(uint16_t)); - return ret; -} - -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) -{ - uint32_t ret; - bh_memcpy_s(&ret, sizeof(uint32_t), buf, sizeof(uint32_t)); - return ret; -} - -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) -{ - uint64_t ret; - bh_memcpy_s(&ret, sizeof(uint64_t), buf, sizeof(uint64_t)); - return ret; -} - -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) -{ - bh_memcpy_s(buf, sizeof(uint16_t), &v, sizeof(uint16_t)); -} - -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) -{ - bh_memcpy_s(buf, sizeof(uint32_t), &v, sizeof(uint32_t)); -} - -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) -{ - bh_memcpy_s(buf, sizeof(uint64_t), &v, sizeof(uint64_t)); -} - -char * -attr_container_get_attr_begin(const attr_container_t *attr_cont, - uint32_t *p_total_length, uint16_t *p_attr_num) -{ - char *p = (char *)attr_cont->buf; - uint16_t str_len, attr_num; - uint32_t total_length; - - /* skip total length */ - total_length = get_uint32(p); - p += sizeof(uint32_t); - if (!total_length) - return NULL; - - /* tag length */ - str_len = get_uint16(p); - p += sizeof(uint16_t); - if (!str_len) - return NULL; - - /* tag content */ - p += str_len; - if ((uint32_t)(p - attr_cont->buf) >= total_length) - return NULL; - - /* attribute num */ - attr_num = get_uint16(p); - p += sizeof(uint16_t); - if ((uint32_t)(p - attr_cont->buf) >= total_length) - return NULL; - - if (p_total_length) - *p_total_length = total_length; - - if (p_attr_num) - *p_attr_num = attr_num; - - /* first attribute */ - return p; -} - -static char * -attr_container_get_attr_next(const char *curr_attr) -{ - char *p = (char *)curr_attr; - uint8_t type; - - /* key length and key */ - p += sizeof(uint16_t) + get_uint16(p); - type = *p++; - - /* Byte type to Boolean type */ - if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN) { - p += 1 << (type & 3); - return p; - } - /* String type */ - else if (type == ATTR_TYPE_STRING) { - p += sizeof(uint16_t) + get_uint16(p); - return p; - } - /* ByteArray type */ - else if (type == ATTR_TYPE_BYTEARRAY) { - p += sizeof(uint32_t) + get_uint32(p); - return p; - } - - return NULL; -} - -static const char * -attr_container_find_attr(const attr_container_t *attr_cont, const char *key) -{ - uint32_t total_length; - uint16_t str_len, attr_num, i; - const char *p = attr_cont->buf; - - if (!key) - return NULL; - - if (!(p = attr_container_get_attr_begin(attr_cont, &total_length, - &attr_num))) - return NULL; - - for (i = 0; i < attr_num; i++) { - /* key length */ - if (!(str_len = get_uint16(p))) - 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) - return NULL; - return p; - } - - if (!(p = attr_container_get_attr_next(p))) - return NULL; - } - - return NULL; -} - -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))) - return NULL; - - for (i = 0; i < attr_num; i++) - if (!(p = attr_container_get_attr_next(p))) - return NULL; - - return p; -} - -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 str_len; - /* skip total length */ - const char *p = attr_cont->buf + sizeof(uint32_t); - - str_len = get_uint16(p); - /* skip tag length and tag */ - p += sizeof(uint16_t) + str_len; - - /* attribute num */ - return get_uint16(p); -} - -static void -attr_container_inc_attr_num(attr_container_t *attr_cont) -{ - uint16_t str_len, attr_num; - /* skip total length */ - char *p = attr_cont->buf + sizeof(uint32_t); - - str_len = get_uint16(p); - /* skip tag length and tag */ - p += sizeof(uint16_t) + str_len; - - /* attribute num */ - attr_num = get_uint16(p) + 1; - set_uint16(p, attr_num); -} - -attr_container_t * -attr_container_create(const char *tag) -{ - attr_container_t *attr_cont; - int length, tag_length; - char *p; - - 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; - - if (!(attr_cont = attr_container_malloc(length))) { - attr_container_printf( - "Create attr_container failed: allocate memory failed.\r\n"); - return NULL; - } - - memset(attr_cont, 0, length); - p = attr_cont->buf; - - /* total length */ - set_uint32(p, length - offsetof(attr_container_t, buf)); - p += 4; - - /* tag length, tag */ - set_uint16(p, tag_length); - p += 2; - if (tag) - bh_memcpy_s(p, tag_length, tag, tag_length); - - return attr_cont; -} - -void -attr_container_destroy(const attr_container_t *attr_cont) -{ - if (attr_cont) - attr_container_free((char *)attr_cont); -} - -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"); - return false; - } - - 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"); - 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) -{ - attr_container_t *attr_cont, *attr_cont1; - uint16_t str_len; - uint32_t total_length, attr_len; - char *p, *p1, *attr_end, *msg_end, *attr_buf; - - if (!check_set_attr(p_attr_cont, key)) { - return false; - } - - attr_cont = *p_attr_cont; - p = attr_cont->buf; - total_length = get_uint32(p); - - if (!(attr_end = attr_container_get_attr_end(attr_cont))) { - attr_container_printf("Set attr failed: get attr end failed.\r\n"); - return false; - } - - msg_end = attr_container_get_msg_end(attr_cont); - - /* key len + key + '\0' + type */ - attr_len = sizeof(uint16_t) + strlen(key) + 1 + 1; - if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN) - attr_len += 1 << (type & 3); - else if (type == ATTR_TYPE_STRING) - attr_len += sizeof(uint16_t) + value_length; - else if (type == ATTR_TYPE_BYTEARRAY) - attr_len += sizeof(uint32_t) + value_length; - - if (!(p = attr_buf = attr_container_malloc(attr_len))) { - attr_container_printf("Set attr failed: allocate memory failed.\r\n"); - return false; - } - - /* Set the attr buf */ - str_len = (uint16_t)(strlen(key) + 1); - set_uint16(p, str_len); - p += sizeof(uint16_t); - bh_memcpy_s(p, str_len, key, str_len); - p += str_len; - - *p++ = type; - if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN) - bh_memcpy_s(p, 1 << (type & 3), value, 1 << (type & 3)); - else if (type == ATTR_TYPE_STRING) { - set_uint16(p, value_length); - p += sizeof(uint16_t); - bh_memcpy_s(p, value_length, value, value_length); - } - 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))) { - /* key found */ - p1 = attr_container_get_attr_next(p); - - if (p1 - p == attr_len) { - bh_memcpy_s(p, attr_len, attr_buf, attr_len); - attr_container_free(attr_buf); - return true; - } - - if ((uint32_t)(p1 - p + msg_end - attr_end) >= attr_len) { - memmove(p, p1, attr_end - p1); - bh_memcpy_s(p + (attr_end - p1), attr_len, attr_buf, attr_len); - attr_container_free(attr_buf); - return true; - } - - total_length += attr_len + 100; - if (!(attr_cont1 = attr_container_malloc(offsetof(attr_container_t, buf) - + total_length))) { - attr_container_printf( - "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); - p = attr_cont1->buf; - set_uint32(p, total_length); - *p_attr_cont = attr_cont1; - /* Free original buffer */ - attr_container_free(attr_cont); - attr_container_free(attr_buf); - return true; - } - 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); - attr_container_inc_attr_num(attr_cont); - attr_container_free(attr_buf); - return true; - } - - total_length += attr_len + 100; - if (!(attr_cont1 = attr_container_malloc(offsetof(attr_container_t, buf) - + total_length))) { - attr_container_printf( - "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); - attr_container_inc_attr_num(attr_cont1); - p = attr_cont1->buf; - set_uint32(p, total_length); - *p_attr_cont = attr_cont1; - /* Free original buffer */ - attr_container_free(attr_cont); - attr_container_free(attr_buf); - return true; - } - - return false; -} - -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); -} - -bool -attr_container_set_int16(attr_container_t **p_attr_cont, const char *key, - int16_t value) -{ - return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT16, &value, - 2); -} - -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_int32(attr_container_t **p_attr_cont, const char *key, - int32_t value) -{ - return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT32, &value, - 4); -} - -bool -attr_container_set_uint32(attr_container_t **p_attr_cont, const char *key, - uint32_t value) -{ - return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT32, &value, - 4); -} - -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); -} - -bool -attr_container_set_uint64(attr_container_t **p_attr_cont, const char *key, - uint64_t value) -{ - return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT64, &value, - 8); -} - -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_int8(attr_container_t **p_attr_cont, const char *key, - int8_t value) -{ - return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT8, &value, 1); -} - -bool -attr_container_set_uint8(attr_container_t **p_attr_cont, const char *key, - uint8_t value) -{ - return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT8, &value, - 1); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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"); - return NULL; - } - - if (!(attr_addr = attr_container_find_attr(attr_cont, key))) { - attr_container_printf("Get attribute failed: lookup key failed.\r\n"); - return NULL; - } - - /* key len + key + '\0' */ - 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.i64 = 0; \ - type = *(uint8_t *)addr++; \ - switch (type) { \ - case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ \ - case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ \ - case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ \ - case ATTR_TYPE_INT64: \ - case ATTR_TYPE_UINT8: \ - case ATTR_TYPE_UINT16: \ - case ATTR_TYPE_UINT32: \ - case ATTR_TYPE_UINT64: \ - 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, i16); -} - -int16_t -attr_container_get_as_int16(const attr_container_t *attr_cont, const char *key) -{ - return (int16_t)attr_container_get_as_short(attr_cont, key); -} - -int -attr_container_get_as_int(const attr_container_t *attr_cont, const char *key) -{ - TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i32); -} - -int32_t -attr_container_get_as_int32(const attr_container_t *attr_cont, const char *key) -{ - return (int32_t)attr_container_get_as_int(attr_cont, key); -} - -uint32_t -attr_container_get_as_uint32(const attr_container_t *attr_cont, const char *key) -{ - return (uint32_t)attr_container_get_as_int(attr_cont, 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, i64); -} - -uint64_t -attr_container_get_as_uint64(const attr_container_t *attr_cont, const char *key) -{ - return (uint64_t)attr_container_get_as_int64(attr_cont, 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, i8); -} - -int8_t -attr_container_get_as_int8(const attr_container_t *attr_cont, const char *key) -{ - return attr_container_get_as_byte(attr_cont, key); -} - -uint8_t -attr_container_get_as_uint8(const attr_container_t *attr_cont, const char *key) -{ - return (uint8_t)attr_container_get_as_byte(attr_cont, key); -} - -uint16_t -attr_container_get_as_uint16(const attr_container_t *attr_cont, const char *key) -{ - return (uint16_t)attr_container_get_as_short(attr_cont, 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) -{ - TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, d); -} - -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 * -attr_container_get_as_bytearray(const attr_container_t *attr_cont, - const char *key, unsigned *array_length) -{ - const char *addr = attr_container_get_attr(attr_cont, key); - uint8_t type; - uint32_t length; - - if (!addr) - return NULL; - - if (!array_length) { - attr_container_printf("Get attribute failed: invalid input arguments."); - return NULL; - } - - type = *(uint8_t *)addr++; - switch (type) { - case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ - case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ - case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ - case ATTR_TYPE_INT64: - case ATTR_TYPE_UINT8: - case ATTR_TYPE_UINT16: - case ATTR_TYPE_UINT32: - case ATTR_TYPE_UINT64: - 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; -} - -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); -} - -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; -} - -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"); - 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) -{ - const char *p; - - if (!attr_cont) { - attr_container_printf("Get container serialize length failed: invalid " - "input arguments.\r\n"); - return 0; - } - - p = attr_cont->buf; - return sizeof(uint16_t) + get_uint32(p); -} - -bool -attr_container_serialize(char *buf, const attr_container_t *attr_cont) -{ - const char *p; - uint16_t flags; - uint32_t length; - - if (!buf || !attr_cont) { - attr_container_printf( - "Container serialize failed: invalid input arguments.\r\n"); - return false; - } - - p = attr_cont->buf; - length = sizeof(uint16_t) + get_uint32(p); - bh_memcpy_s(buf, length, attr_cont, length); - /* Set readonly */ - 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) -{ - uint16_t flags; - - if (!attr_cont) { - attr_container_printf( - "Container check const: invalid input arguments.\r\n"); - return false; - } - - 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) -{ - uint32_t total_length; - uint16_t attr_num, i, type; - const char *p, *tag, *key; - jvalue value; - - if (!attr_cont) - return; - - tag = attr_container_get_tag(attr_cont); - if (!tag) - return; - - attr_container_printf("Attribute container dump:\n"); - attr_container_printf("Tag: %s\n", tag); - - p = attr_container_get_attr_begin(attr_cont, &total_length, &attr_num); - if (!p) - return; - - attr_container_printf("Attribute list:\n"); - for (i = 0; i < attr_num; i++) { - key = p + 2; - /* Skip key len and key */ - p += 2 + get_uint16(p); - type = *p++; - attr_container_printf(" key: %s", key); - - switch (type) { - case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ - bh_memcpy_s(&value.i8, 1, p, 1); - attr_container_printf(", type: byte, value: 0x%x\n", - value.i8 & 0xFF); - p++; - break; - case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ - bh_memcpy_s(&value.i16, sizeof(int16_t), p, sizeof(int16_t)); - attr_container_printf(", type: short, value: 0x%x\n", - value.i16 & 0xFFFF); - p += 2; - break; - case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ - bh_memcpy_s(&value.i32, sizeof(int32_t), p, sizeof(int32_t)); - attr_container_printf(", type: int, value: 0x%x\n", value.i32); - p += 4; - break; - case ATTR_TYPE_INT64: - bh_memcpy_s(&value.i64, sizeof(int64_t), p, sizeof(int64_t)); - attr_container_printf(", type: int64, value: 0x%llx\n", - (long long unsigned int)(value.i64)); - p += 8; - break; - case ATTR_TYPE_UINT8: - bh_memcpy_s(&value.u8, 1, p, 1); - attr_container_printf(", type: uint8, value: 0x%x\n", value.u8); - p++; - break; - case ATTR_TYPE_UINT16: - bh_memcpy_s(&value.u16, sizeof(uint16_t), p, sizeof(uint16_t)); - attr_container_printf(", type: uint16, value: 0x%x\n", - value.u16); - p += 2; - break; - case ATTR_TYPE_UINT32: - bh_memcpy_s(&value.u32, sizeof(uint32_t), p, sizeof(uint32_t)); - attr_container_printf(", type: uint32, value: 0x%x\n", - value.u32); - p += 4; - break; - case ATTR_TYPE_UINT64: - bh_memcpy_s(&value.u64, sizeof(uint64_t), p, sizeof(uint64_t)); - attr_container_printf(", type: int64, value: 0x%llx\n", - (long long unsigned int)(value.u64)); - p += 8; - 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"); -} diff --git a/core/app-framework/app-native-shared/bi-inc/attr_container.h b/core/app-framework/app-native-shared/bi-inc/attr_container.h deleted file mode 100644 index f5d8759b8..000000000 --- a/core/app-framework/app-native-shared/bi-inc/attr_container.h +++ /dev/null @@ -1,596 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _ATTR_CONTAINER_H_ -#define _ATTR_CONTAINER_H_ - -#include -#include -#include -#include -#include -#include -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Attribute type */ -enum { - ATTR_TYPE_BEGIN = 0, - ATTR_TYPE_BYTE = ATTR_TYPE_BEGIN, - ATTR_TYPE_INT8 = ATTR_TYPE_BYTE, - ATTR_TYPE_SHORT, - ATTR_TYPE_INT16 = ATTR_TYPE_SHORT, - ATTR_TYPE_INT, - ATTR_TYPE_INT32 = ATTR_TYPE_INT, - ATTR_TYPE_INT64, - ATTR_TYPE_UINT8, - ATTR_TYPE_UINT16, - ATTR_TYPE_UINT32, - ATTR_TYPE_UINT64, - /** - * Why ATTR_TYPE_FLOAT = 10? - * We determine the number of bytes that should be copied through 1<<(type & - * 3). ATTR_TYPE_BYTE = 0, so the number of bytes is 1 << 0 = 1. - * ATTR_TYPE_UINT64 = 7, so the number of bytes is 1 << 3 = 8. - * Since the float type takes up 4 bytes, ATTR_TYPE_FLOAT should be 10. - * Calculation: (1 << (10&3)) = (1 << 2) = 4 - */ - ATTR_TYPE_FLOAT = 10, - ATTR_TYPE_DOUBLE, - ATTR_TYPE_BOOLEAN, - ATTR_TYPE_STRING, - ATTR_TYPE_BYTEARRAY, - ATTR_TYPE_END = ATTR_TYPE_BYTEARRAY -}; - -#define ATTR_CONT_READONLY_SHIFT 2 - -typedef struct attr_container { - /* container flag: - * bit0, bit1 denote the implemenation algorithm, 00: buffer, 01: link list - * bit2 denotes the readonly flag: 1 is readonly and attr cannot be set - */ - char flags[2]; - /** - * Buffer format - * for buffer implementation: - * buf length (4 bytes) - * tag length (2 bytes) - * tag - * attr num (2bytes) - * attr[0..n-1]: - * attr key length (2 bytes) - * attr type (1byte) - * attr value (length depends on attr type) - */ - char buf[1]; -} attr_container_t; - -/** - * Create attribute container - * - * @param tag tag of current attribute container - * - * @return the created attribute container, NULL if failed - */ -attr_container_t * -attr_container_create(const char *tag); - -/** - * Destroy attribute container - * - * @param attr_cont the attribute container to destroy - */ -void -attr_container_destroy(const attr_container_t *attr_cont); - -/** - * Set short attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_short(attr_container_t **p_attr_cont, const char *key, - short value); - -/** - * Set int16 attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_int16(attr_container_t **p_attr_cont, const char *key, - int16_t value); - -/** - * Set int attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_int(attr_container_t **p_attr_cont, const char *key, - int value); - -/** - * Set int32 attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_int32(attr_container_t **p_attr_cont, const char *key, - int32_t value); - -/** - * Set uint32 attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_uint32(attr_container_t **p_attr_cont, const char *key, - uint32_t value); - -/** - * Set int64 attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_int64(attr_container_t **p_attr_cont, const char *key, - int64_t value); - -/** - * Set uint64 attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_uint64(attr_container_t **p_attr_cont, const char *key, - uint64_t value); - -/** - * Set byte attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_byte(attr_container_t **p_attr_cont, const char *key, - int8_t value); - -/** - * Set int8 attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_int8(attr_container_t **p_attr_cont, const char *key, - int8_t value); - -/** - * Set uint8 attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_uint8(attr_container_t **p_attr_cont, const char *key, - uint8_t value); - -/** - * Set uint16 attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_uint16(attr_container_t **p_attr_cont, const char *key, - uint16_t value); - -/** - * Set float attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_float(attr_container_t **p_attr_cont, const char *key, - float value); - -/** - * Set double attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_double(attr_container_t **p_attr_cont, const char *key, - double value); - -/** - * Set bool attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_bool(attr_container_t **p_attr_cont, const char *key, - bool value); - -/** - * Set string attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the attribute value - * - * @return true if success, false otherwise - */ -bool -attr_container_set_string(attr_container_t **p_attr_cont, const char *key, - const char *value); - -/** - * Set bytearray attribute in attribute container - * - * @param p_attr_cont pointer to attribute container to set attribute, and - * return the new attribute container if it is re-created - * @param key the attribute key - * @param value the bytearray buffer - * @param length the bytearray length - * - * @return true if success, false otherwise - */ -bool -attr_container_set_bytearray(attr_container_t **p_attr_cont, const char *key, - const int8_t *value, unsigned length); - -/** - * Get tag of current attribute container - * - * @param attr_cont the attribute container - * - * @return tag of current attribute container - */ -const char * -attr_container_get_tag(const attr_container_t *attr_cont); - -/** - * Get attribute number of current attribute container - * - * @param attr_cont the attribute container - * - * @return attribute number of current attribute container - */ -uint16_t -attr_container_get_attr_num(const attr_container_t *attr_cont); - -/** - * Whether the attribute container contains an attribute key. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return true if key is contained in message, false otherwise - */ -bool -attr_container_contain_key(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as short value, - * return 0 if attribute isn't found in message. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the short value of the attribute, 0 if key isn't found - */ -short -attr_container_get_as_short(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as int16 value, - * return 0 if attribute isn't found in message. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the short value of the attribute, 0 if key isn't found - */ -int16_t -attr_container_get_as_int16(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as int value, - * return 0 if attribute isn't found in message. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the int value of the attribute, 0 if key isn't found - */ -int -attr_container_get_as_int(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as int32 value, - * return 0 if attribute isn't found in message. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the int value of the attribute, 0 if key isn't found - */ -int32_t -attr_container_get_as_int32(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as uint32 value, - * return 0 if attribute isn't found in message. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the unsigned int value of the attribute, 0 if key isn't found - */ -uint32_t -attr_container_get_as_uint32(const attr_container_t *attr_cont, - const char *key); - -/** - * Get attribute from attribute container and return it as int64 value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the long value of the attribute, 0 if key isn't found - */ -int64_t -attr_container_get_as_int64(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as uint64 value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the unsigned long value of the attribute, 0 if key isn't found - */ -uint64_t -attr_container_get_as_uint64(const attr_container_t *attr_cont, - const char *key); - -/** - * Get attribute from attribute container and return it as byte value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the byte value of the attribute, 0 if key isn't found - */ -int8_t -attr_container_get_as_byte(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as int8 value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the byte value of the attribute, 0 if key isn't found - */ -int8_t -attr_container_get_as_int8(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as uint8 value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the uint8 value of the attribute, 0 if key isn't found - */ -uint8_t -attr_container_get_as_uint8(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as uint16 value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the char value of the attribute, 0 if key isn't found - */ -uint16_t -attr_container_get_as_uint16(const attr_container_t *attr_cont, - const char *key); - -/** - * Get attribute from attribute container and return it as float value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the float value of the attribute, 0 if key isn't found - */ -float -attr_container_get_as_float(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as double value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the double value of the attribute, 0 if key isn't found - */ -double -attr_container_get_as_double(const attr_container_t *attr_cont, - const char *key); - -/** - * Get attribute from attribute container and return it as bool value, - * return false if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the bool value of the attribute, 0 if key isn't found - */ -bool -attr_container_get_as_bool(const attr_container_t *attr_cont, const char *key); - -/** - * Get attribute from attribute container and return it as string value, - * return NULL if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the string value of the attribute, NULL if key isn't found - */ -char * -attr_container_get_as_string(const attr_container_t *attr_cont, - const char *key); - -/** - * Get attribute from attribute container and return it as bytearray value, - * return 0 if attribute isn't found in attribute container. - * - * @param attr_cont the attribute container - * @param key the attribute key - * - * @return the bytearray value of the attribute, NULL if key isn't found - */ -const int8_t * -attr_container_get_as_bytearray(const attr_container_t *attr_cont, - const char *key, unsigned *array_length); - -/** - * Get the buffer size of attribute container - * - * @param attr_cont the attribute container - * - * @return the buffer size of attribute container - */ -unsigned -attr_container_get_serialize_length(const attr_container_t *attr_cont); - -/** - * Serialize attribute container to a buffer - * - * @param buf the buffer to receive the serialized data - * @param attr_cont the attribute container to be serialized - * - * @return true if success, false otherwise - */ -bool -attr_container_serialize(char *buf, const attr_container_t *attr_cont); - -/** - * Whether the attribute container is const, or set attribute isn't supported - * - * @param attr_cont the attribute container - * - * @return true if const, false otherwise - */ -bool -attr_container_is_constant(const attr_container_t *attr_cont); - -void -attr_container_dump(const attr_container_t *attr_cont); - -#ifndef attr_container_malloc -#define attr_container_malloc WA_MALLOC -#endif - -#ifndef attr_container_free -#define attr_container_free WA_FREE -#endif - -#ifndef attr_container_printf -#define attr_container_printf printf -#endif - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif /* end of _ATTR_CONTAINER_H_ */ diff --git a/core/app-framework/app-native-shared/bi-inc/shared_utils.h b/core/app-framework/app-native-shared/bi-inc/shared_utils.h deleted file mode 100644 index 8155ea1f7..000000000 --- a/core/app-framework/app-native-shared/bi-inc/shared_utils.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _SHARED_UTILS_H_ -#define _SHARED_UTILS_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define FMT_ATTR_CONTAINER 99 -#define FMT_APP_RAW_BINARY 98 - -/* the request structure */ -typedef struct request { - // message id - uint32 mid; - - // url of the request - char *url; - - // action of the request, can be PUT/GET/POST/DELETE - int action; - - // payload format, currently only support attr_container_t type - int fmt; - - // payload of the request, currently only support attr_container_t type - void *payload; - - // length in bytes of the payload - int payload_len; - - // sender of the request - unsigned long sender; -} request_t; - -/* the response structure */ -typedef struct response { - // message id - uint32 mid; - - // status of the response - int status; - - // payload format - int fmt; - - // payload of the response, - void *payload; - - // length in bytes of the payload - int payload_len; - - // receiver of the response - unsigned long reciever; -} response_t; - -int -check_url_start(const char *url, int url_len, const char *leading_str); - -bool -match_url(char *pattern, char *matched); - -char * -find_key_value(char *buffer, int buffer_len, char *key, char *value, - int value_len, char delimiter); - -request_t * -clone_request(request_t *request); - -void -request_cleaner(request_t *request); - -response_t * -clone_response(response_t *response); - -void -response_cleaner(response_t *response); - -/** - * @brief Set fields of response. - * - * @param response pointer of the response to be set - * @param status status of response - * @param fmt format of the response payload - * @param payload payload of the response - * @param payload_len length in bytes of the response payload - * - * @return pointer to the 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); - -/** - * @brief Make a response for a request. - * - * @param request pointer of the request - * @param response pointer of the response to be made - * - * @return pointer to the response - * - * @warning the request and response pointers MUST NOT be NULL - */ -response_t * -make_response_for_request(request_t *request, response_t *response); - -/** - * @brief Initialize a request. - * - * @param request pointer of the request to be initialized - * @param url url of the request - * @param action action of the request - * @param fmt format of the request payload - * @param payload payload of the request - * @param payload_len length in bytes of the request payload - * - * @return pointer to the request - * - * @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); - -char * -pack_request(request_t *request, int *size); - -request_t * -unpack_request(char *packet, int size, request_t *request); - -char * -pack_response(response_t *response, int *size); - -response_t * -unpack_response(char *packet, int size, response_t *response); - -void -free_req_resp_packet(char *packet); - -char * -wa_strdup(const char *str); - -#ifdef __cplusplus -} -#endif - -#endif /* end of _SHARED_UTILS_H_ */ diff --git a/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h b/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h deleted file mode 100644 index 86d864e41..000000000 --- a/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H -#define WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* Object native function IDs */ -enum { - OBJ_FUNC_ID_DEL, - OBJ_FUNC_ID_DEL_ASYNC, - OBJ_FUNC_ID_CLEAN, - OBJ_FUNC_ID_SET_EVT_CB, - OBJ_FUNC_ID_ALIGN, - - /* Number of functions */ - _OBJ_FUNC_ID_NUM, -}; - -/* Button native function IDs */ -enum { - BTN_FUNC_ID_CREATE, - BTN_FUNC_ID_SET_TOGGLE, - BTN_FUNC_ID_SET_STATE, - BTN_FUNC_ID_TOGGLE, - BTN_FUNC_ID_SET_INK_IN_TIME, - BTN_FUNC_ID_SET_INK_WAIT_TIME, - BTN_FUNC_ID_SET_INK_OUT_TIME, - BTN_FUNC_ID_GET_STATE, - BTN_FUNC_ID_GET_TOGGLE, - BTN_FUNC_ID_GET_INK_IN_TIME, - BTN_FUNC_ID_GET_INK_WAIT_TIME, - BTN_FUNC_ID_GET_INK_OUT_TIME, - /* Number of functions */ - _BTN_FUNC_ID_NUM, -}; - -/* Check box native function IDs */ -enum { - CB_FUNC_ID_CREATE, - CB_FUNC_ID_SET_TEXT, - CB_FUNC_ID_SET_STATIC_TEXT, - CB_FUNC_ID_GET_TEXT, - CB_FUNC_ID_GET_TEXT_LENGTH, - - /* Number of functions */ - _CB_FUNC_ID_NUM, -}; - -/* List native function IDs */ -enum { - LIST_FUNC_ID_CREATE, - LIST_FUNC_ID_ADD_BTN, - - /* Number of functions */ - _LIST_FUNC_ID_NUM, -}; - -/* Label native function IDs */ -enum { - LABEL_FUNC_ID_CREATE, - LABEL_FUNC_ID_SET_TEXT, - LABEL_FUNC_ID_SET_ARRAY_TEXT, - LABEL_FUNC_ID_SET_STATIC_TEXT, - LABEL_FUNC_ID_SET_LONG_MODE, - LABEL_FUNC_ID_SET_ALIGN, - LABEL_FUNC_ID_SET_RECOLOR, - LABEL_FUNC_ID_SET_BODY_DRAW, - LABEL_FUNC_ID_SET_ANIM_SPEED, - LABEL_FUNC_ID_SET_TEXT_SEL_START, - LABEL_FUNC_ID_SET_TEXT_SEL_END, - LABEL_FUNC_ID_GET_TEXT, - LABEL_FUNC_ID_GET_TEXT_LENGTH, - LABEL_FUNC_ID_GET_LONG_MODE, - LABEL_FUNC_ID_GET_ALIGN, - LABEL_FUNC_ID_GET_RECOLOR, - LABEL_FUNC_ID_GET_BODY_DRAW, - LABEL_FUNC_ID_GET_ANIM_SPEED, - LABEL_FUNC_ID_GET_LETTER_POS, - LABEL_FUNC_ID_GET_TEXT_SEL_START, - LABEL_FUNC_ID_GET_TEXT_SEL_END, - LABEL_FUNC_ID_INS_TEXT, - LABEL_FUNC_ID_CUT_TEXT, - /* Number of functions */ - _LABEL_FUNC_ID_NUM, -}; - -#ifdef __cplusplus -} -#endif - -#endif /* WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H */ diff --git a/core/app-framework/app-native-shared/native_interface.cmake b/core/app-framework/app-native-shared/native_interface.cmake deleted file mode 100644 index 48ebe0a33..000000000 --- a/core/app-framework/app-native-shared/native_interface.cmake +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (NATIVE_INTERFACE_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${NATIVE_INTERFACE_DIR}) - - -file (GLOB_RECURSE source_all ${NATIVE_INTERFACE_DIR}/*.c) - -set (NATIVE_INTERFACE_SOURCE ${source_all}) - -set (WASM_APP_BI_INC_DIR "${NATIVE_INTERFACE_DIR}/bi-inc") -LIST (APPEND RUNTIME_LIB_HEADER_LIST "${NATIVE_INTERFACE_DIR}/native_interface.h") - diff --git a/core/app-framework/app-native-shared/native_interface.h b/core/app-framework/app-native-shared/native_interface.h deleted file mode 100644 index ce9f24780..000000000 --- a/core/app-framework/app-native-shared/native_interface.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _NATIVE_INTERFACE_H_ -#define _NATIVE_INTERFACE_H_ - -/* Note: the bh_plaform.h is the only head file separately - implemented by both [app] and [native] worlds */ -#include "bh_platform.h" - -#endif /* end of _NATIVE_INTERFACE_H */ diff --git a/core/app-framework/app-native-shared/restful_utils.c b/core/app-framework/app-native-shared/restful_utils.c deleted file mode 100644 index 03e86a699..000000000 --- a/core/app-framework/app-native-shared/restful_utils.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include -#include - -#include "bi-inc/shared_utils.h" - -/* Serialization of request and response message - * - * Choices: - * We considered a few options: - * 1. coap - * 2. flatbuffer - * 3. cbor - * 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 - * - * 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 - */ -#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 RESPONSE_PACKET_FIX_PART_LEN 16 - -char * -pack_request(request_t *request, int *size) -{ - int url_len = strlen(request->url) + 1; - int len = REQUEST_PACKET_FIX_PART_LEN + url_len + request->payload_len; - uint16 u16; - uint32 u32; - char *packet; - - 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; - - u16 = htons(request->fmt); - memcpy(packet + 2, &u16, 2); - - u32 = htonl(request->mid); - memcpy(packet + 4, &u32, 4); - - u32 = htonl(request->sender); - memcpy(packet + 8, &u32, 4); - - u16 = htons(url_len); - memcpy(packet + 12, &u16, 2); - - u32 = htonl(request->payload_len); - memcpy(packet + 14, &u32, 4); - - strcpy(packet + REQUEST_PACKET_URL_OFFSET, request->url); - memcpy(packet + REQUEST_PACKET_URL_OFFSET + url_len, request->payload, - request->payload_len); - - *size = len; - return packet; -} - -void -free_req_resp_packet(char *packet) -{ - WA_FREE(packet); -} - -request_t * -unpack_request(char *packet, int size, request_t *request) -{ - uint16 url_len, u16; - uint32 payload_len, u32; - - if (*packet != REQUES_PACKET_VER) { - return NULL; - } - if (size < REQUEST_PACKET_FIX_PART_LEN) { - return NULL; - } - - memcpy(&u16, packet + 12, 2); - url_len = ntohs(u16); - - memcpy(&u32, packet + 14, 4); - payload_len = ntohl(u32); - - if (size != (REQUEST_PACKET_FIX_PART_LEN + url_len + payload_len)) { - return NULL; - } - - if (*(packet + REQUEST_PACKET_FIX_PART_LEN + url_len - 1) != 0) { - return NULL; - } - - request->action = *((uint8 *)(packet + 1)); - - memcpy(&u16, packet + 2, 2); - request->fmt = ntohs(u16); - - memcpy(&u32, packet + 4, 4); - request->mid = ntohl(u32); - - memcpy(&u32, packet + 8, 4); - request->sender = ntohl(u32); - - request->payload_len = payload_len; - request->url = REQUEST_PACKET_URL(packet); - - if (payload_len > 0) - request->payload = packet + REQUEST_PACKET_URL_OFFSET + url_len; - else - request->payload = NULL; - - return request; -} - -char * -pack_response(response_t *response, int *size) -{ - int len = RESPONSE_PACKET_FIX_PART_LEN + response->payload_len; - uint16 u16; - uint32 u32; - char *packet; - - 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; - - u16 = htons(response->fmt); - memcpy(packet + 2, &u16, 2); - - u32 = htonl(response->mid); - memcpy(packet + 4, &u32, 4); - - u32 = htonl(response->reciever); - memcpy(packet + 8, &u32, 4); - - u32 = htonl(response->payload_len); - memcpy(packet + 12, &u32, 4); - - memcpy(packet + RESPONSE_PACKET_FIX_PART_LEN, response->payload, - response->payload_len); - - *size = len; - return packet; -} - -response_t * -unpack_response(char *packet, int size, response_t *response) -{ - uint16 u16; - uint32 payload_len, u32; - - if (*packet != REQUES_PACKET_VER) - return NULL; - - if (size < RESPONSE_PACKET_FIX_PART_LEN) - return NULL; - - memcpy(&u32, packet + 12, 4); - payload_len = ntohl(u32); - if (size != (RESPONSE_PACKET_FIX_PART_LEN + payload_len)) - return NULL; - - response->status = *((uint8 *)(packet + 1)); - - memcpy(&u16, packet + 2, 2); - response->fmt = ntohs(u16); - - memcpy(&u32, packet + 4, 4); - response->mid = ntohl(u32); - - memcpy(&u32, packet + 8, 4); - response->reciever = ntohl(u32); - - response->payload_len = payload_len; - if (payload_len > 0) - response->payload = packet + RESPONSE_PACKET_FIX_PART_LEN; - else - response->payload = NULL; - - return response; -} - -request_t * -clone_request(request_t *request) -{ - /* deep clone */ - request_t *req = (request_t *)WA_MALLOC(sizeof(request_t)); - if (req == NULL) - return NULL; - - memset(req, 0, sizeof(*req)); - req->action = request->action; - req->fmt = request->fmt; - req->url = wa_strdup(request->url); - req->sender = request->sender; - req->mid = request->mid; - - if (req->url == NULL) - goto fail; - - req->payload_len = request->payload_len; - - if (request->payload_len) { - req->payload = (char *)WA_MALLOC(request->payload_len); - if (!req->payload) - goto fail; - memcpy(req->payload, request->payload, request->payload_len); - } - else { - /* when payload_len is 0, the payload may be used for - carrying some handle or integer */ - req->payload = request->payload; - } - - return req; - -fail: - request_cleaner(req); - return NULL; -} - -void -request_cleaner(request_t *request) -{ - if (request->url != NULL) - WA_FREE(request->url); - if (request->payload != NULL && request->payload_len > 0) - WA_FREE(request->payload); - - WA_FREE(request); -} - -void -response_cleaner(response_t *response) -{ - if (response->payload != NULL && response->payload_len > 0) - WA_FREE(response->payload); - - WA_FREE(response); -} - -response_t * -clone_response(response_t *response) -{ - response_t *clone = (response_t *)WA_MALLOC(sizeof(response_t)); - - if (clone == NULL) - return NULL; - - memset(clone, 0, sizeof(*clone)); - clone->fmt = response->fmt; - clone->mid = response->mid; - clone->status = response->status; - clone->reciever = response->reciever; - clone->payload_len = response->payload_len; - if (clone->payload_len) { - clone->payload = (char *)WA_MALLOC(response->payload_len); - if (!clone->payload) - goto fail; - memcpy(clone->payload, response->payload, response->payload_len); - } - else { - /* when payload_len is 0, the payload may be used for - carrying some handle or integer */ - clone->payload = response->payload; - } - return clone; - -fail: - response_cleaner(clone); - return NULL; -} - -response_t * -set_response(response_t *response, int status, int fmt, const char *payload, - int payload_len) -{ - response->payload = (void *)payload; - response->payload_len = payload_len; - response->status = status; - response->fmt = fmt; - return response; -} - -response_t * -make_response_for_request(request_t *request, response_t *response) -{ - response->mid = request->mid; - response->reciever = request->sender; - - return response; -} - -static unsigned int mid = 0; - -request_t * -init_request(request_t *request, char *url, int action, int fmt, void *payload, - int payload_len) -{ - request->url = url; - request->action = action; - request->fmt = fmt; - request->payload = payload; - request->payload_len = payload_len; - request->mid = ++mid; - - return request; -} - -/* - 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" - 2. it omit the '/' at the first char - 3. it ensure the leading_str "/abc" can pass "/abc?cde - */ - -int -check_url_start(const char *url, int url_len, const char *leading_str) -{ - int offset = 0; - if (*leading_str == '/') - leading_str++; - if (url_len > 0 && *url == '/') { - url_len--; - url++; - offset++; - } - - int len = strlen(leading_str); - if (len == 0) - return 0; - - /* ensure leading_str not end with "/" */ - if (leading_str[len - 1] == '/') { - len--; - if (len == 0) - return 0; - } - - /* equal length */ - if (url_len == len) { - if (memcmp(url, leading_str, url_len) == 0) { - return (offset + len); - } - else { - return 0; - } - } - - if (url_len < len) - return 0; - else if (memcmp(url, leading_str, len) != 0) - return 0; - else if (url[len] != '/' && url[len] != '?') - return 0; - else - return (offset + len + 1); -} - -// * @pattern: -// * sample 1: /abcd, match /abcd only -// * sample 2: /abcd/ match match "/abcd" and "/abcd/*" -// * sample 3: /abcd*, match any url started with "/abcd" -// * sample 4: /abcd/*, exclude "/abcd" - -bool -match_url(char *pattern, char *matched) -{ - if (*pattern == '/') - pattern++; - if (*matched == '/') - matched++; - - int matched_len = strlen(matched); - if (matched_len == 0) - return false; - - if (matched[matched_len - 1] == '/') { - matched_len--; - if (matched_len == 0) - return false; - } - - int len = strlen(pattern); - if (len == 0) - return false; - - if (pattern[len - 1] == '/') { - len--; - if (strncmp(pattern, matched, len) != 0) - return false; - - if (len == matched_len) - return true; - - if (matched_len > len && matched[len] == '/') - return true; - - return false; - } - else if (pattern[len - 1] == '*') { - if (pattern[len - 2] == '/') { - if (strncmp(pattern, matched, len - 1) == 0) - return true; - else - return false; - } - else { - return (strncmp(pattern, matched, len - 1) == 0); - } - } - else { - return (strcmp(pattern, matched) == 0); - } -} - -/* - * get the value of the key from following format buffer: - * key1=value1;key2=value2;key3=value3 - */ -char * -find_key_value(char *buffer, int buffer_len, char *key, char *value, - int value_len, char delimiter) -{ - char *p = buffer; - int remaining = buffer_len; - int key_len = strlen(key); - - while (*p != 0 && remaining > 0) { - while (*p == ' ' || *p == delimiter) { - p++; - remaining--; - } - - if (remaining <= key_len) - return NULL; - - /* find the key */ - if (0 == strncmp(p, key, key_len) && p[key_len] == '=') { - p += (key_len + 1); - remaining -= (key_len + 1); - char *v = value; - memset(value, 0, value_len); - value_len--; /* ensure last char is 0 */ - while (*p != delimiter && remaining > 0 && value_len > 0) { - *v++ = *p++; - remaining--; - value_len--; - } - return value; - } - - /* goto next key */ - while (*p != delimiter && remaining > 0) { - p++; - remaining--; - } - } - - return NULL; -} diff --git a/core/app-framework/app_ext_lib_export.c b/core/app-framework/app_ext_lib_export.c deleted file mode 100644 index 532491b43..000000000 --- a/core/app-framework/app_ext_lib_export.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "lib_export.h" - -#ifdef APP_FRAMEWORK_SENSOR -#include "sensor_native_api.h" -#endif - -#ifdef APP_FRAMEWORK_CONNECTION -#include "connection_native_api.h" -#endif - -#ifdef APP_FRAMEWORK_WGL -#include "gui_native_api.h" -#endif - -/* More header file here */ - -static NativeSymbol extended_native_symbol_defs[] = { -#ifdef APP_FRAMEWORK_SENSOR -#include "runtime_sensor.inl" -#endif - -#ifdef APP_FRAMEWORK_CONNECTION -#include "connection.inl" -#endif - -#ifdef APP_FRAMEWORK_WGL -#include "wamr_gui.inl" -#endif - - /* More inl file here */ -}; - -int -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); -} diff --git a/core/app-framework/app_framework.cmake b/core/app-framework/app_framework.cmake deleted file mode 100644 index b8a63d856..000000000 --- a/core/app-framework/app_framework.cmake +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - - -add_definitions (-DWASM_ENABLE_APP_FRAMEWORK=1) - -set (APP_FRAMEWORK_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}) - -if ( NOT DEFINED APP_FRAMEWORK_INCLUDE_TYPE ) - LIST (APPEND WASM_APP_LIB_SOURCE_ALL ${CMAKE_CURRENT_LIST_DIR}/app_ext_lib_export.c) -endif() - -# app-native-shared and base are required -include (${APP_FRAMEWORK_ROOT_DIR}/app-native-shared/native_interface.cmake) -LIST (APPEND WASM_APP_SOURCE_ALL ${NATIVE_INTERFACE_SOURCE}) - -MACRO(SUBDIRLIST result curdir) - FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) - SET(dirlist "") - FOREACH(child ${children}) - IF(IS_DIRECTORY ${curdir}/${child}) - LIST(APPEND dirlist ${child}) - ENDIF() - ENDFOREACH() - SET(${result} ${dirlist}) -ENDMACRO() - -function (add_module_native arg) - message ("Add native module ${ARGV0}") - include (${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/wasm_lib.cmake) - - file (GLOB header - ${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/*.h - ${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/*.inl - ) - - LIST (APPEND WASM_APP_LIBS_DIR ${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native) - set (WASM_APP_LIBS_DIR ${WASM_APP_LIBS_DIR} PARENT_SCOPE) - - LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header}) - set (RUNTIME_LIB_HEADER_LIST ${RUNTIME_LIB_HEADER_LIST} PARENT_SCOPE) - - LIST (APPEND WASM_APP_LIB_SOURCE_ALL ${WASM_APP_LIB_CURRENT_SOURCE}) - set (WASM_APP_LIB_SOURCE_ALL ${WASM_APP_LIB_SOURCE_ALL} PARENT_SCOPE) -endfunction () - -function (add_module_app arg) - message ("Add app module ${ARGV0}") - include (${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/app/wasm_app.cmake) - - LIST (APPEND WASM_APP_WA_INC_DIR_LIST "${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/app/wa-inc") - set (WASM_APP_WA_INC_DIR_LIST ${WASM_APP_WA_INC_DIR_LIST} PARENT_SCOPE) - - LIST (APPEND WASM_APP_NAME ${ARGV0}) - set (WASM_APP_NAME ${WASM_APP_NAME} PARENT_SCOPE) - - LIST (APPEND WASM_APP_SOURCE_ALL ${WASM_APP_CURRENT_SOURCE}) - set (WASM_APP_SOURCE_ALL ${WASM_APP_SOURCE_ALL} PARENT_SCOPE) -endfunction () - -if ("${WAMR_BUILD_APP_LIST}" STREQUAL "WAMR_APP_BUILD_ALL") - # add all modules under this folder - SUBDIRLIST(SUBDIRS ${APP_FRAMEWORK_ROOT_DIR}) - - FOREACH(subdir ${SUBDIRS}) - if ("${subdir}" STREQUAL "app-native-shared") - continue() - endif () - if ("${subdir}" STREQUAL "template") - continue() - endif () - - if ( NOT DEFINED APP_FRAMEWORK_INCLUDE_TYPE ) - add_module_native (${subdir}) - else () - add_module_app (${subdir}) - endif () - ENDFOREACH() - -else () - # add each module in the list - FOREACH (dir IN LISTS WAMR_BUILD_APP_LIST) - string(REPLACE "WAMR_APP_BUILD_" "" dir ${dir}) - string(TOLOWER ${dir} dir) - - if ( NOT DEFINED APP_FRAMEWORK_INCLUDE_TYPE ) - add_module_native (${dir}) - else () - add_module_app (${dir}) - endif () - ENDFOREACH (dir) - -endif() diff --git a/core/app-framework/base/app/bh_platform.c b/core/app-framework/base/app/bh_platform.c deleted file mode 100644 index 1848d0792..000000000 --- a/core/app-framework/base/app/bh_platform.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "bh_platform.h" -#include -#include -#include - -/* - * - * - */ - -static bool -is_little_endian() -{ - long i = 0x01020304; - unsigned char *c = (unsigned char *)&i; - return (*c == 0x04) ? true : false; -} - -static void -swap32(uint8 *pData) -{ - uint8 value = *pData; - *pData = *(pData + 3); - *(pData + 3) = value; - - value = *(pData + 1); - *(pData + 1) = *(pData + 2); - *(pData + 2) = value; -} - -static void -swap16(uint8 *pData) -{ - uint8 value = *pData; - *(pData) = *(pData + 1); - *(pData + 1) = value; -} - -uint32 -htonl(uint32 value) -{ - uint32 ret; - if (is_little_endian()) { - ret = value; - swap32((uint8 *)&ret); - return ret; - } - - return value; -} - -uint32 -ntohl(uint32 value) -{ - return htonl(value); -} - -uint16 -htons(uint16 value) -{ - uint16 ret; - if (is_little_endian()) { - ret = value; - swap16((uint8 *)&ret); - return ret; - } - - return value; -} - -uint16 -ntohs(uint16 value) -{ - return htons(value); -} - -char * -wa_strdup(const char *s) -{ - char *s1 = NULL; - if (s && (s1 = WA_MALLOC(strlen(s) + 1))) - memcpy(s1, s, strlen(s) + 1); - return s1; -} diff --git a/core/app-framework/base/app/bh_platform.h b/core/app-framework/base/app/bh_platform.h deleted file mode 100644 index 8e10dcb64..000000000 --- a/core/app-framework/base/app/bh_platform.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef DEPS_IWASM_APP_LIBS_BASE_BH_PLATFORM_H_ -#define DEPS_IWASM_APP_LIBS_BASE_BH_PLATFORM_H_ - -#include - -typedef unsigned char uint8; -typedef char int8; -typedef unsigned short uint16; -typedef short int16; -typedef unsigned int uint32; -typedef int int32; - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#ifndef __cplusplus -#define true 1 -#define false 0 -#define inline __inline -#endif - -// all wasm-app<->native shared source files should use WA_MALLOC/WA_FREE. -// they will be mapped to different implementations in each side -#ifndef WA_MALLOC -#define WA_MALLOC malloc -#endif - -#ifndef WA_FREE -#define WA_FREE free -#endif - -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) - -#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) -#endif - -#endif /* DEPS_IWASM_APP_LIBS_BASE_BH_PLATFORM_H_ */ diff --git a/core/app-framework/base/app/req_resp_api.h b/core/app-framework/base/app/req_resp_api.h deleted file mode 100644 index 575c35732..000000000 --- a/core/app-framework/base/app/req_resp_api.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _REQ_RESP_API_H_ -#define _REQ_RESP_API_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -bool -wasm_response_send(const char *buf, int size); - -void -wasm_register_resource(const char *url); - -void -wasm_post_request(const char *buf, int size); - -void -wasm_sub_event(const char *url); - -#ifdef __cplusplus -} -#endif - -#endif /* end of _REQ_RESP_API_H_ */ diff --git a/core/app-framework/base/app/request.c b/core/app-framework/base/app/request.c deleted file mode 100644 index 3ba44fbc7..000000000 --- a/core/app-framework/base/app/request.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "bi-inc/attr_container.h" -#include "wa-inc/request.h" -#include "wa-inc/timer_wasm_app.h" -#include "bi-inc/shared_utils.h" -#include "wasm_app.h" -#include "req_resp_api.h" -#include "timer_api.h" - -#define TRANSACTION_TIMEOUT_MS 5000 - -typedef enum { Reg_Event, Reg_Request } reg_type_t; - -typedef struct _res_register { - struct _res_register *next; - const char *url; - reg_type_t reg_type; - void (*request_handler)(request_t *); -} res_register_t; - -typedef struct transaction { - struct transaction *next; - int mid; - unsigned int time; /* start time */ - response_handler_f handler; - void *user_data; -} transaction_t; - -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) -{ - transaction_t *t = g_transactions; - - while (t) { - if (t->mid == mid) - return t; - t = t->next; - } - - return NULL; -} - -/* - * 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) -{ - transaction_t *t; - - if (g_transactions == NULL) { - g_transactions = trans; - return; - } - - t = g_transactions; - while (t) { - if (t->next == NULL) { - t->next = trans; - return; - } - } -} - -static void -transaction_remove(transaction_t *trans) -{ - transaction_t *prev = NULL, *current = g_transactions; - - while (current) { - if (current == trans) { - if (prev == NULL) { - g_transactions = current->next; - free(current); - return; - } - prev->next = current->next; - free(current); - return; - } - prev = current; - current = current->next; - } -} - -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) -{ - res_register_t *r = g_resources; - - while (r) { - if (reg_type == r->reg_type && strcmp(r->url, url) == 0) { - r->request_handler = request_handler; - return true; - } - r = r->next; - } - - r = (res_register_t *)malloc(sizeof(res_register_t)); - if (r == NULL) - return false; - - memset(r, 0, sizeof(*r)); - - r->url = strdup(url); - if (!r->url) { - free(r); - return false; - } - - r->request_handler = request_handler; - r->reg_type = reg_type; - r->next = g_resources; - g_resources = r; - - // tell app mgr to route this url to me - if (reg_type == Reg_Request) - wasm_register_resource(url); - else - wasm_sub_event(url); - - return true; -} - -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) -{ - transaction_t *cur, *expired = NULL; - unsigned int elpased_ms, now = wasm_get_sys_tick_ms(); - - /* - * Since he transaction list is sorted by expiry time naturally, - * we can easily get all expired transactions. - * */ - cur = g_transactions; - while (cur) { - if (now < cur->time) - elpased_ms = now + (0xFFFFFFFF - cur->time) + 1; - else - elpased_ms = now - cur->time; - - if (elpased_ms >= TRANSACTION_TIMEOUT_MS) { - g_transactions = cur->next; - cur->next = expired; - expired = cur; - cur = g_transactions; - } - else { - break; - } - } - - /* call each transaction's handler with response set to NULL */ - cur = expired; - while (cur) { - transaction_t *tmp = cur; - cur->handler(NULL, cur->user_data); - cur = cur->next; - free(tmp); - } - - /* - * If the transaction list is not empty, restart the timer according - * to the first transaction. Otherwise, stop the timer. - */ - if (g_transactions != NULL) { - 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 { - elpased_ms = now - g_transactions->time; - } - ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms; - api_timer_restart(g_trans_timer, ms_to_expiry); - } - 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) -{ - int size; - char *buffer; - transaction_t *trans; - - if ((trans = (transaction_t *)malloc(sizeof(transaction_t))) == NULL) { - printf( - "send request: allocate memory for request transaction failed!\n"); - return; - } - - memset(trans, 0, sizeof(transaction_t)); - trans->handler = response_handler; - trans->mid = request->mid; - trans->time = wasm_get_sys_tick_ms(); - trans->user_data = user_data; - - if ((buffer = pack_request(request, &size)) == NULL) { - printf("send request: pack request failed!\n"); - free(trans); - return; - } - - transaction_add(trans); - - /* if the trans is the 1st one, start the timer */ - 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); - } - } - - wasm_post_request(buffer, size); - - free_req_resp_packet(buffer); -} - -/* - * - * APIs for the native layers to callback for request/response arrived to this - * app - * - */ - -void -on_response(char *buffer, int size) -{ - response_t response[1]; - transaction_t *trans; - - if (NULL == unpack_response(buffer, size, response)) { - printf("unpack response failed\n"); - return; - } - - if ((trans = transaction_find(response->mid)) == NULL) { - printf("cannot find the transaction\n"); - return; - } - - /* - * When the 1st transaction get response: - * 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) { - if (trans->next != NULL) { - 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 { - elpased_ms = now - trans->next->time; - } - ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms; - api_timer_restart(g_trans_timer, ms_to_expiry); - } - else { - api_timer_cancel(g_trans_timer); - g_trans_timer = NULL; - } - } - - trans->handler(response, trans->user_data); - transaction_remove(trans); -} - -void -on_request(char *buffer, int size) -{ - request_t request[1]; - bool is_event; - res_register_t *r = g_resources; - - if (NULL == unpack_request(buffer, size, request)) { - printf("unpack request failed\n"); - return; - } - - is_event = is_event_type(request); - - while (r) { - if ((is_event && r->reg_type == Reg_Event) - || (!is_event && r->reg_type == Reg_Request)) { - if (check_url_start(request->url, strlen(request->url), r->url) - > 0) { - r->request_handler(request); - return; - } - } - - r = r->next; - } - - printf("on_request: exit. no service handler\n"); -} - -void -api_response_send(response_t *response) -{ - int size; - char *buffer = pack_response(response, &size); - if (buffer == NULL) - return; - - wasm_response_send(buffer, size); - free_req_resp_packet(buffer); -} - -/// event api - -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); - if (buffer == NULL) - return false; - wasm_post_request(buffer, size); - - free_req_resp_packet(buffer); - - return true; -} - -bool -api_subscribe_event(const char *url, request_handler_f handler) -{ - return register_url_handler(url, handler, Reg_Event); -} diff --git a/core/app-framework/base/app/timer.c b/core/app-framework/base/app/timer.c deleted file mode 100644 index 692626ca3..000000000 --- a/core/app-framework/base/app/timer.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include - -#include "wa-inc/timer_wasm_app.h" -#include "timer_api.h" - -#if 1 -#include -#else -#define printf (...) -#endif - -struct user_timer { - struct user_timer *next; - int timer_id; - void (*user_timer_callback)(user_timer_t); -}; - -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) -{ - - int timer_id = wasm_create_timer(interval, is_period, auto_start); - - // 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"); - return NULL; - } - - memset(timer, 0, sizeof(*timer)); - timer->timer_id = timer_id; - timer->user_timer_callback = on_timer_update; - - if (g_timers == NULL) - g_timers = timer; - else { - timer->next = g_timers; - g_timers = timer; - } - - return timer; -} - -void -api_timer_cancel(user_timer_t timer) -{ - user_timer_t t = g_timers, prev = NULL; - - wasm_timer_cancel(timer->timer_id); - - while (t) { - if (t == timer) { - if (prev == NULL) { - g_timers = t->next; - free(t); - } - else { - prev->next = t->next; - free(t); - } - return; - } - else { - prev = t; - t = t->next; - } - } -} - -void -api_timer_restart(user_timer_t timer, int interval) -{ - wasm_timer_restart(timer->timer_id, interval); -} - -void -on_timer_callback(int timer_id) -{ - struct user_timer *t = g_timers; - - while (t) { - if (t->timer_id == timer_id) { - t->user_timer_callback(t); - break; - } - t = t->next; - } -} diff --git a/core/app-framework/base/app/timer_api.h b/core/app-framework/base/app/timer_api.h deleted file mode 100644 index 1fc7555ef..000000000 --- a/core/app-framework/base/app/timer_api.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _TIMER_API_H_ -#define _TIMER_API_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef unsigned int timer_id_t; - -timer_id_t -wasm_create_timer(int interval, bool is_period, bool auto_start); - -void -wasm_timer_destroy(timer_id_t timer_id); - -void -wasm_timer_cancel(timer_id_t timer_id); - -void -wasm_timer_restart(timer_id_t timer_id, int interval); - -uint32 -wasm_get_sys_tick_ms(void); - -#ifdef __cplusplus -} -#endif - -#endif /* end of _TIMER_API_H_ */ diff --git a/core/app-framework/base/app/wa-inc/request.h b/core/app-framework/base/app/wa-inc/request.h deleted file mode 100644 index 25830f0a4..000000000 --- a/core/app-framework/base/app/wa-inc/request.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _AEE_REQUEST_H_ -#define _AEE_REQUEST_H_ - -#include "bi-inc/shared_utils.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* CoAP request method codes */ -typedef enum { - COAP_GET = 1, - COAP_POST, - COAP_PUT, - COAP_DELETE, - COAP_EVENT = (COAP_DELETE + 2) -} coap_method_t; - -/* CoAP response codes */ -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 */ - 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 */ - REQUEST_ENTITY_TOO_LARGE_4_13 = 141, /* REQUEST_ENTITY_TOO_LARGE */ - 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 */ - PROXYING_NOT_SUPPORTED_5_05 = 165, /* PROXYING_NOT_SUPPORTED */ - - /* Erbium errors */ - MEMORY_ALLOCATION_ERROR = 192, - PACKET_SERIALIZATION_ERROR, - - /* Erbium hooks */ - MANUAL_RESPONSE, - PING_RESPONSE -} coap_status_t; - -/** - * @typedef request_handler_f - * - * @brief Define the signature of callback function for API - * api_register_resource_handler() to handle request or for API - * api_subscribe_event() to handle event. - * - * @param request pointer of the request to be handled - * - * @see api_register_resource_handler - * @see api_subscribe_event - */ -typedef void (*request_handler_f)(request_t *request); - -/** - * @typedef response_handler_f - * - * @brief Define the signature of callback function for API - * api_send_request() to handle response of a request. - * - * @param response pointer of the response to be handled - * @param user_data user data associated with the request which is set when - * calling api_send_request(). - * - * @see api_send_request - */ -typedef void (*response_handler_f)(response_t *response, void *user_data); - -/* - ***************** - * Request APIs - ***************** - */ - -/** - * @brief Register resource. - * - * @param url url of the resource - * @param handler callback function to handle the request to the resource - * - * @return true if success, false otherwise - */ -bool -api_register_resource_handler(const char *url, request_handler_f handler); - -/** - * @brief Send request asynchronously. - * - * @param request pointer of the request to be sent - * @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); - -/** - * @brief Send response. - * - * @param response pointer of the response to be sent - * - * @par - * @code - * void res1_handler(request_t *request) - * { - * response_t response[1]; - * make_response_for_request(request, response); - * set_response(response, DELETED_2_02, 0, NULL, 0); - * api_response_send(response); - * } - * @endcode - */ -void -api_response_send(response_t *response); - -/* - ***************** - * Event APIs - ***************** - */ - -/** - * @brief Publish an event. - * - * @param url url of the event - * @param fmt format of the event payload - * @param payload payload of the event - * @param payload_len length in bytes of the event payload - * - * @return true if success, false otherwise - */ -bool -api_publish_event(const char *url, int fmt, void *payload, int payload_len); - -/** - * @brief Subscribe an event. - * - * @param url url of the event - * @param handler callback function to handle the event. - * - * @return true if success, false otherwise - */ -bool -api_subscribe_event(const char *url, request_handler_f handler); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/app-framework/base/app/wa-inc/timer_wasm_app.h b/core/app-framework/base/app/wa-inc/timer_wasm_app.h deleted file mode 100644 index cf158a365..000000000 --- a/core/app-framework/base/app/wa-inc/timer_wasm_app.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _AEE_TIMER_H_ -#define _AEE_TIMER_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* board producer define user_timer */ -struct user_timer; -typedef struct user_timer *user_timer_t; - -/** - * @typedef on_user_timer_update_f - * - * @brief Define the signature of callback function for API api_timer_create(). - * - * @param timer the timer - * - * @see api_timer_create - */ -typedef void (*on_user_timer_update_f)(user_timer_t timer); - -/* - ***************** - * Timer APIs - ***************** - */ - -/** - * @brief Create timer. - * - * @param interval timer interval - * @param is_period whether the timer is periodic - * @param auto_start whether start the timer immediately after created - * @param on_timer_update callback function called when timer expired - * - * @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); - -/** - * @brief Cancel timer. - * - * @param timer the timer to cancel - */ -void -api_timer_cancel(user_timer_t timer); - -/** - * @brief Restart timer. - * - * @param timer the timer to cancel - * @param interval the timer interval - */ -void -api_timer_restart(user_timer_t timer, int interval); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/app-framework/base/app/wasm_app.cmake b/core/app-framework/base/app/wasm_app.cmake deleted file mode 100644 index 2313df99d..000000000 --- a/core/app-framework/base/app/wasm_app.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_APP_BASE_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${WASM_APP_BASE_DIR}) - -add_definitions (-DWASM_ENABLE_BASE_LIB) - -file (GLOB_RECURSE source_all ${WASM_APP_BASE_DIR}/*.c) - -set (WASM_APP_CURRENT_SOURCE ${source_all}) -set (WASM_APP_BASE_DIR ${WASM_APP_BASE_DIR} PARENT_SCOPE) diff --git a/core/app-framework/base/app/wasm_app.h b/core/app-framework/base/app/wasm_app.h deleted file mode 100644 index e7be8a4c1..000000000 --- a/core/app-framework/base/app/wasm_app.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _LIB_AEE_H_ -#define _LIB_AEE_H_ - -#include "bi-inc/shared_utils.h" -#include "bi-inc/attr_container.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* end of _LIB_AEE_H_ */ diff --git a/core/app-framework/base/native/base_lib.inl b/core/app-framework/base/native/base_lib.inl deleted file mode 100644 index 3c228cc93..000000000 --- a/core/app-framework/base/native/base_lib.inl +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - - EXPORT_WASM_API_WITH_SIG(wasm_register_resource, "($)"), - EXPORT_WASM_API_WITH_SIG(wasm_response_send, "(*~)i"), - EXPORT_WASM_API_WITH_SIG(wasm_post_request, "(*~)"), - EXPORT_WASM_API_WITH_SIG(wasm_sub_event, "($)"), - EXPORT_WASM_API_WITH_SIG(wasm_create_timer, "(iii)i"), - EXPORT_WASM_API_WITH_SIG(wasm_timer_destroy, "(i)"), - EXPORT_WASM_API_WITH_SIG(wasm_timer_cancel, "(i)"), - EXPORT_WASM_API_WITH_SIG(wasm_timer_restart, "(ii)"), - EXPORT_WASM_API_WITH_SIG(wasm_get_sys_tick_ms, "()i"), diff --git a/core/app-framework/base/native/base_lib_export.c b/core/app-framework/base/native/base_lib_export.c deleted file mode 100644 index 19ac7185c..000000000 --- a/core/app-framework/base/native/base_lib_export.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include -#include "lib_export.h" -#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" -}; - -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); -} diff --git a/core/app-framework/base/native/req_resp_native_api.h b/core/app-framework/base/native/req_resp_native_api.h deleted file mode 100644 index 3e5938772..000000000 --- a/core/app-framework/base/native/req_resp_native_api.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _REQ_RESP_API_H_ -#define _REQ_RESP_API_H_ - -#include "bh_platform.h" -#include "wasm_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -bool -wasm_response_send(wasm_exec_env_t exec_env, char *buffer, int size); -void -wasm_register_resource(wasm_exec_env_t exec_env, char *url); -void -wasm_post_request(wasm_exec_env_t exec_env, char *buffer, int size); -void -wasm_sub_event(wasm_exec_env_t exec_env, char *url); - -#ifdef __cplusplus -} -#endif - -#endif /* end of _REQ_RESP_API_H_ */ diff --git a/core/app-framework/base/native/request_response.c b/core/app-framework/base/native/request_response.c deleted file mode 100644 index 674ba5e9d..000000000 --- a/core/app-framework/base/native/request_response.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "app_manager_export.h" -#include "coap_ext.h" -#include "wasm_export.h" -#include "bh_assert.h" - -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) -{ - if (buffer != NULL) { - response_t response[1]; - - if (NULL == unpack_response(buffer, size, response)) - return false; - - am_send_response(response); - - return true; - } - - return false; -} - -void -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); - bh_assert(mod_id != ID_NONE); - am_register_resource(url, module_request_handler, mod_id); - } -} - -void -wasm_post_request(wasm_exec_env_t exec_env, char *buffer, int size) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (buffer != NULL) { - request_t req[1]; - - if (!unpack_request(buffer, size, req)) - return; - - // 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); - bh_assert(mod_id != ID_NONE); - req->sender = mod_id; - - if (req->action == COAP_EVENT) { - am_publish_event(req); - return; - } - - am_dispatch_request(req); - } -} - -void -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); - - bh_assert(mod_id != ID_NONE); - am_register_event(url, mod_id); - } -} diff --git a/core/app-framework/base/native/runtime_lib.h b/core/app-framework/base/native/runtime_lib.h deleted file mode 100644 index 477b663b2..000000000 --- a/core/app-framework/base/native/runtime_lib.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef LIB_BASE_RUNTIME_LIB_H_ -#define LIB_BASE_RUNTIME_LIB_H_ - -#include "runtime_timer.h" - -bool -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_ */ diff --git a/core/app-framework/base/native/timer_native_api.h b/core/app-framework/base/native/timer_native_api.h deleted file mode 100644 index 138e7c60d..000000000 --- a/core/app-framework/base/native/timer_native_api.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _TIMER_API_H_ -#define _TIMER_API_H_ - -#include "bh_platform.h" -#include "wasm_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef unsigned int timer_id_t; - -/* - * timer interfaces - */ - -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); -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); -uint32 -wasm_get_sys_tick_ms(wasm_exec_env_t exec_env); - -#ifdef __cplusplus -} -#endif - -#endif /* end of _TIMER_API_H_ */ diff --git a/core/app-framework/base/native/timer_wrapper.c b/core/app-framework/base/native/timer_wrapper.c deleted file mode 100644 index 246868849..000000000 --- a/core/app-framework/base/native/timer_wrapper.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "bh_platform.h" -#include "app_manager_export.h" -#include "../app-manager/module_wasm_app.h" -#include "timer_native_api.h" - -typedef struct { - bh_list_link l; - timer_ctx_t timer_ctx; -} timer_ctx_node_t; - -static bool timer_thread_run = true; - -static bh_list g_timer_ctx_list; -static korp_cond g_timer_ctx_list_cond; -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); - if (module == NULL) - return; - - // !!! the length parameter must be 0, so the receiver will - // not free the payload pointer. - bh_post_msg(module->queue, TIMER_EVENT_WASM, (char *)(uintptr_t)id, 0); -} - -/** - * why we create a separate link for module timer contexts - * rather than traverse the module list? - * It helps to reduce the lock frequency for the module list. - * Also when we lock the module list and then call the callback for - * timer expire, the callback is request the list lock again for lookup - * the module from module id. It is for avoiding that situation. - */ - -void * -thread_modulers_timer_check(void *arg) -{ - uint32 ms_to_expiry; - uint64 us_to_wait; - - 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); - while (elem) { - uint32 next = check_app_timers(elem->timer_ctx); - if (next != (uint32)-1) { - if (ms_to_expiry == (uint32)-1 || ms_to_expiry > next) - ms_to_expiry = next; - } - - elem = (timer_ctx_node_t *)bh_list_elem_next(elem); - } - os_mutex_unlock(&g_timer_ctx_list_mutex); - - if (ms_to_expiry == (uint32)-1) - us_to_wait = BHT_WAIT_FOREVER; - else - us_to_wait = (uint64)ms_to_expiry * 1000; - os_mutex_lock(&g_timer_ctx_list_mutex); - os_cond_reltimedwait(&g_timer_ctx_list_cond, &g_timer_ctx_list_mutex, - us_to_wait); - os_mutex_unlock(&g_timer_ctx_list_mutex); - } - - return NULL; -} - -void -wakeup_modules_timer_thread(timer_ctx_t ctx) -{ - os_mutex_lock(&g_timer_ctx_list_mutex); - os_cond_signal(&g_timer_ctx_list_cond); - os_mutex_unlock(&g_timer_ctx_list_mutex); -} - -bool -init_wasm_timer() -{ - korp_tid tm_tid; - bh_list_init(&g_timer_ctx_list); - - if (os_cond_init(&g_timer_ctx_list_cond) != 0) { - return false; - } - /* temp solution for: thread_modulers_timer_check thread - would recursive lock the mutex */ - if (os_recursive_mutex_init(&g_timer_ctx_list_mutex) != 0) { - goto fail1; - } - - if (0 - != os_thread_create(&tm_tid, thread_modulers_timer_check, NULL, - BH_APPLET_PRESERVED_STACK_SIZE)) { - goto fail2; - } - - return true; - -fail2: - os_mutex_destroy(&g_timer_ctx_list_mutex); - -fail1: - os_cond_destroy(&g_timer_ctx_list_cond); - - return false; -} - -void -exit_wasm_timer() -{ - timer_thread_run = false; -} - -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); - - if (ctx == NULL) - return NULL; - - 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; - } - memset(node, 0, sizeof(*node)); - node->timer_ctx = ctx; - - os_mutex_lock(&g_timer_ctx_list_mutex); - bh_list_insert(&g_timer_ctx_list, node); - os_mutex_unlock(&g_timer_ctx_list_mutex); - - return ctx; -} - -void -destroy_module_timer_ctx(unsigned int module_id) -{ - 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); - while (elem) { - if (timer_ctx_get_owner(elem->timer_ctx) == module_id) { - bh_list_remove(&g_timer_ctx_list, elem); - destroy_timer_ctx(elem->timer_ctx); - wasm_runtime_free(elem); - break; - } - - elem = (timer_ctx_node_t *)bh_list_elem_next(elem); - } - os_mutex_unlock(&g_timer_ctx_list_mutex); -} - -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); - 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_module_inst_t module_inst = get_module_inst(exec_env); - timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst); - bh_assert(timer_ctx); - return sys_create_timer(timer_ctx, interval, is_period, auto_start); -} - -void -wasm_timer_destroy(wasm_exec_env_t exec_env, timer_id_t timer_id) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst); - bh_assert(timer_ctx); - sys_timer_destroy(timer_ctx, timer_id); -} - -void -wasm_timer_cancel(wasm_exec_env_t exec_env, timer_id_t timer_id) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst); - bh_assert(timer_ctx); - sys_timer_cancel(timer_ctx, timer_id); -} - -void -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); - bh_assert(timer_ctx); - sys_timer_restart(timer_ctx, timer_id, interval); -} - -uint32 -wasm_get_sys_tick_ms(wasm_exec_env_t exec_env) -{ - return (uint32)bh_get_tick_ms(); -} diff --git a/core/app-framework/base/native/wasm_lib.cmake b/core/app-framework/base/native/wasm_lib.cmake deleted file mode 100644 index 223320b32..000000000 --- a/core/app-framework/base/native/wasm_lib.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_LIB_BASE_DIR ${CMAKE_CURRENT_LIST_DIR}) - -add_definitions (-DWASM_ENABLE_BASE_LIB) - -include_directories(${WASM_LIB_BASE_DIR}) - -file (GLOB_RECURSE source_all ${WASM_LIB_BASE_DIR}/*.c) - -set (WASM_APP_LIB_CURRENT_SOURCE ${source_all}) - diff --git a/core/app-framework/connection/app/connection.c b/core/app-framework/connection/app/connection.c deleted file mode 100644 index b5b2bfc54..000000000 --- a/core/app-framework/connection/app/connection.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wa-inc/connection.h" -#include "connection_api.h" - -/* Raw connection structure */ -typedef struct _connection { - /* Next connection */ - struct _connection *next; - - /* Handle of the connection */ - uint32 handle; - - /* Callback function called when event on this connection occurs */ - on_connection_event_f on_event; - - /* User data */ - void *user_data; -} connection_t; - -/* 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 *conn; - char *args_buffer = (char *)args; - uint32 handle, args_len = attr_container_get_serialize_length(args); - - handle = wasm_open_connection(name, args_buffer, args_len); - if (handle == -1) - return NULL; - - conn = (connection_t *)malloc(sizeof(*conn)); - if (conn == NULL) { - wasm_close_connection(handle); - return NULL; - } - - memset(conn, 0, sizeof(*conn)); - conn->handle = handle; - conn->on_event = on_event; - conn->user_data = user_data; - - if (g_conns != NULL) { - conn->next = g_conns; - g_conns = conn; - } - else { - g_conns = conn; - } - - return conn; -} - -void -api_close_connection(connection_t *c) -{ - connection_t *conn = g_conns, *prev = NULL; - - while (conn) { - if (conn == c) { - wasm_close_connection(c->handle); - if (prev != NULL) - prev->next = conn->next; - else - g_conns = conn->next; - free(conn); - return; - } - else { - prev = conn; - conn = conn->next; - } - } -} - -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) -{ - char *cfg_buffer = (char *)cfg; - uint32 cfg_len = attr_container_get_serialize_length(cfg); - - return wasm_config_connection(conn->handle, cfg_buffer, cfg_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->user_data); - } - else { - conn->on_event(conn, CONN_EVENT_TYPE_DATA, buffer, len, - conn->user_data); - } - - return; - } - conn = conn->next; - } -} diff --git a/core/app-framework/connection/app/connection_api.h b/core/app-framework/connection/app/connection_api.h deleted file mode 100644 index 22bd5a182..000000000 --- a/core/app-framework/connection/app/connection_api.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef CONNECTION_API_H_ -#define CONNECTION_API_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -uint32 -wasm_open_connection(const char *name, char *args_buf, uint32 args_buf_len); - -void -wasm_close_connection(uint32 handle); - -int -wasm_send_on_connection(uint32 handle, const char *data, uint32 data_len); - -bool -wasm_config_connection(uint32 handle, const char *cfg_buf, uint32 cfg_buf_len); - -#ifdef __cplusplus -} -#endif - -#endif /* end of CONNECTION_API_H_ */ diff --git a/core/app-framework/connection/app/wa-inc/connection.h b/core/app-framework/connection/app/wa-inc/connection.h deleted file mode 100644 index 823eaec74..000000000 --- a/core/app-framework/connection/app/wa-inc/connection.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _CONNECTION_H_ -#define _CONNECTION_H_ - -#include "bi-inc/attr_container.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct _connection; -typedef struct _connection connection_t; - -/* Connection event type */ -typedef enum { - /* Data is received */ - CONN_EVENT_TYPE_DATA = 1, - /* Connection is disconnected */ - CONN_EVENT_TYPE_DISCONNECT -} conn_event_type_t; - -/* - * @typedef on_connection_event_f - * - * @param conn the connection that the event belongs to - * @param type event type - * @param data the data received for CONN_EVENT_TYPE_DATA event - * @param len length of the data in byte - * @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); - -/* - ***************** - * Connection API's - ***************** - */ - -/* - * @brief Open a connection. - * - * @param name name of the connection, "TCP", "UDP" or "UART" - * @param args connection arguments, such as: ip:127.0.0.1, port:8888 - * @param on_event callback function called when event occurs - * @param user_data user data - * - * @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); - -/* - * @brief Close a connection. - * - * @param conn connection - */ -void -api_close_connection(connection_t *conn); - -/* - * Send data to the connection in non-blocking manner which returns immediately - * - * @param conn the connection - * @param data data buffer to be sent - * @param len length of the data in byte - * - * @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); - -/* - * @brief Configure connection. - * - * @param conn the connection - * @param cfg configurations - * - * @return true if success, false otherwise - */ -bool -api_config_connection(connection_t *conn, attr_container_t *cfg); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/app-framework/connection/app/wasm_app.cmake b/core/app-framework/connection/app/wasm_app.cmake deleted file mode 100644 index ca4e02599..000000000 --- a/core/app-framework/connection/app/wasm_app.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_APP_CONN_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${WASM_APP_CONN_DIR}) - - -file (GLOB source_all ${WASM_APP_CONN_DIR}/*.c) - -set (WASM_APP_CURRENT_SOURCE ${source_all}) diff --git a/core/app-framework/connection/native/connection.inl b/core/app-framework/connection/native/connection.inl deleted file mode 100644 index b2d01aa9f..000000000 --- a/core/app-framework/connection/native/connection.inl +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -EXPORT_WASM_API_WITH_SIG(wasm_open_connection, "($*~)i"), -EXPORT_WASM_API_WITH_SIG(wasm_close_connection, "(i)"), -EXPORT_WASM_API_WITH_SIG(wasm_send_on_connection, "(i*~)i"), -EXPORT_WASM_API_WITH_SIG(wasm_config_connection, "(i*~)i"), diff --git a/core/app-framework/connection/native/connection_lib.h b/core/app-framework/connection/native/connection_lib.h deleted file mode 100644 index 3e182cbb8..000000000 --- a/core/app-framework/connection/native/connection_lib.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef CONNECTION_LIB_H_ -#define CONNECTION_LIB_H_ - -#include "bi-inc/attr_container.h" -#include "wasm_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * This file defines connection library which should be implemented by - * different platforms - */ - -/* - * @brief Open a connection. - * - * @param name name of the connection, "TCP", "UDP" or "UART" - * @param args connection arguments, such as: ip:127.0.0.1, port:8888 - * - * @return 0~0xFFFFFFFE means id of the connection, otherwise(-1) means fail - */ -typedef uint32 (*connection_open_f)(wasm_module_inst_t module_inst, - const char *name, attr_container_t *args); - -/* - * @brief Close a connection. - * - * @param handle of the connection - */ -typedef void (*connection_close_f)(uint32 handle); - -/* - * @brief Send data to the connection in non-blocking manner. - * - * @param handle of the connection - * @param data data buffer to be sent - * @param len length of the data in byte - * - * @return actual length sent, -1 if fail - */ -typedef int (*connection_send_f)(uint32 handle, const char *data, int len); - -/* - * @brief Configure connection. - * - * @param handle of the connection - * @param cfg configurations - * - * @return true if success, false otherwise - */ -typedef bool (*connection_config_f)(uint32 handle, attr_container_t *cfg); - -/* Raw connection interface for platform to implement */ -typedef struct _connection_interface { - connection_open_f _open; - connection_close_f _close; - connection_send_f _send; - connection_config_f _config; -} connection_interface_t; - -/* Platform must define this interface */ -extern connection_interface_t connection_impl; - -#ifdef __cplusplus -} -#endif - -#endif /* CONNECTION_LIB_H_ */ diff --git a/core/app-framework/connection/native/connection_native_api.h b/core/app-framework/connection/native/connection_native_api.h deleted file mode 100644 index 42a2508f1..000000000 --- a/core/app-framework/connection/native/connection_native_api.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef CONNECTION_API_H_ -#define CONNECTION_API_H_ - -#include "bh_platform.h" -#include "wasm_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * connection interfaces - */ - -uint32 -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); -int -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); - -#ifdef __cplusplus -} -#endif - -#endif /* end of CONNECTION_API_H_ */ diff --git a/core/app-framework/connection/native/connection_wrapper.c b/core/app-framework/connection/native/connection_wrapper.c deleted file mode 100644 index 7c20b51d0..000000000 --- a/core/app-framework/connection/native/connection_wrapper.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "connection_lib.h" -#include "wasm_export.h" -#include "native_interface.h" -#include "connection_native_api.h" - -/* Note: - * - * 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_module_inst_t module_inst = get_module_inst(exec_env); - attr_container_t *args; - - args = (attr_container_t *)args_buf; - - if (connection_impl._open != NULL) - return connection_impl._open(module_inst, name, args); - - return -1; -} - -void -wasm_close_connection(wasm_exec_env_t exec_env, uint32 handle) -{ - if (connection_impl._close != NULL) - connection_impl._close(handle); -} - -int -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); - - return -1; -} - -bool -wasm_config_connection(wasm_exec_env_t exec_env, uint32 handle, char *cfg_buf, - uint32 len) -{ - attr_container_t *cfg; - - cfg = (attr_container_t *)cfg_buf; - - if (connection_impl._config != NULL) - return connection_impl._config(handle, cfg); - - return false; -} diff --git a/core/app-framework/connection/native/linux/conn_tcp.c b/core/app-framework/connection/native/linux/conn_tcp.c deleted file mode 100644 index 054eb59fd..000000000 --- a/core/app-framework/connection/native/linux/conn_tcp.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "conn_tcp.h" - -#include -#include -#include -#include -#include - -int -tcp_open(char *address, uint16 port) -{ - int sock, ret; - struct sockaddr_in servaddr; - - memset(&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr(address); - servaddr.sin_port = htons(port); - - sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock == -1) - return -1; - - ret = connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)); - if (ret == -1) { - close(sock); - return -1; - } - - /* Put the socket in non-blocking mode */ - if (fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK) < 0) { - close(sock); - return -1; - } - - return sock; -} - -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) -{ - return recv(sock, buffer, buf_size, 0); -} diff --git a/core/app-framework/connection/native/linux/conn_tcp.h b/core/app-framework/connection/native/linux/conn_tcp.h deleted file mode 100644 index c4d5cc86a..000000000 --- a/core/app-framework/connection/native/linux/conn_tcp.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef CONN_LINUX_TCP_H_ -#define CONN_LINUX_TCP_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int -tcp_open(char *address, uint16 port); - -int -tcp_send(int sock, const char *data, int size); - -int -tcp_recv(int sock, char *buffer, int buf_size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/app-framework/connection/native/linux/conn_uart.c b/core/app-framework/connection/native/linux/conn_uart.c deleted file mode 100644 index 0bcdc93f7..000000000 --- a/core/app-framework/connection/native/linux/conn_uart.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "conn_uart.h" - -#include -#include -#include - -static int -parse_baudrate(int baud) -{ - switch (baud) { - case 9600: - return B9600; - case 19200: - return B19200; - case 38400: - return B38400; - case 57600: - return B57600; - case 115200: - return B115200; - case 230400: - return B230400; - case 460800: - return B460800; - case 500000: - return B500000; - case 576000: - return B576000; - case 921600: - return B921600; - case 1000000: - return B1000000; - case 1152000: - return B1152000; - case 1500000: - return B1500000; - case 2000000: - return B2000000; - case 2500000: - return B2500000; - case 3000000: - return B3000000; - case 3500000: - return B3500000; - case 4000000: - return B4000000; - default: - return -1; - } -} - -int -uart_open(char *device, int baudrate) -{ - int uart_fd; - struct termios uart_term; - - uart_fd = open(device, O_RDWR | O_NOCTTY); - - if (uart_fd < 0) - return -1; - - memset(&uart_term, 0, sizeof(uart_term)); - uart_term.c_cflag = parse_baudrate(baudrate) | CS8 | CLOCAL | CREAD; - uart_term.c_iflag = IGNPAR; - uart_term.c_oflag = 0; - - /* set noncanonical mode */ - uart_term.c_lflag = 0; - uart_term.c_cc[VTIME] = 30; - uart_term.c_cc[VMIN] = 1; - tcflush(uart_fd, TCIFLUSH); - - if (tcsetattr(uart_fd, TCSANOW, &uart_term) != 0) { - close(uart_fd); - return -1; - } - - /* Put the fd in non-blocking mode */ - if (fcntl(uart_fd, F_SETFL, fcntl(uart_fd, F_GETFL) | O_NONBLOCK) < 0) { - close(uart_fd); - return -1; - } - - return uart_fd; -} - -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) -{ - return read(fd, buffer, buf_size); -} diff --git a/core/app-framework/connection/native/linux/conn_uart.h b/core/app-framework/connection/native/linux/conn_uart.h deleted file mode 100644 index 443167026..000000000 --- a/core/app-framework/connection/native/linux/conn_uart.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef CONN_LINUX_UART_H_ -#define CONN_LINUX_UART_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int -uart_open(char *device, int baudrate); - -int -uart_send(int fd, const char *data, int size); - -int -uart_recv(int fd, char *buffer, int buf_size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/app-framework/connection/native/linux/conn_udp.c b/core/app-framework/connection/native/linux/conn_udp.c deleted file mode 100644 index 61652b14d..000000000 --- a/core/app-framework/connection/native/linux/conn_udp.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "conn_udp.h" - -#include -#include -#include -#include -#include - -int -udp_open(uint16 port) -{ - int sock, ret; - struct sockaddr_in addr; - - sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock == -1) - return -1; - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(INADDR_ANY); - addr.sin_port = htons(port); - - ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); - if (ret == -1) { - close(sock); - return -1; - } - - /* Put the socket in non-blocking mode */ - if (fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK) < 0) { - close(sock); - return -1; - } - - return sock; -} - -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) -{ - struct sockaddr_in remaddr; - socklen_t addrlen = sizeof(remaddr); - - return recvfrom(sock, buffer, buf_size, 0, (struct sockaddr *)&remaddr, - &addrlen); -} diff --git a/core/app-framework/connection/native/linux/conn_udp.h b/core/app-framework/connection/native/linux/conn_udp.h deleted file mode 100644 index 377c26eb1..000000000 --- a/core/app-framework/connection/native/linux/conn_udp.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef CONN_LINUX_UDP_H_ -#define CONN_LINUX_UDP_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int -udp_open(uint16 port); - -int -udp_send(int sock, struct sockaddr *dest, const char *data, int size); - -int -udp_recv(int sock, char *buffer, int buf_size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/app-framework/connection/native/linux/connection_mgr.c b/core/app-framework/connection/native/linux/connection_mgr.c deleted file mode 100644 index 001446206..000000000 --- a/core/app-framework/connection/native/linux/connection_mgr.c +++ /dev/null @@ -1,609 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -/* - * Note: - * This file implements the linux version connection library which is - * defined in connection_lib.h. - * It also provides a reference implementation of connections manager. - */ - -#include "connection_lib.h" -#include "bh_platform.h" -#include "app_manager_export.h" -#include "module_wasm_app.h" -#include "conn_tcp.h" -#include "conn_udp.h" -#include "conn_uart.h" - -#include -#include -#include -#include -#include - -#define MAX_EVENTS 10 -#define IO_BUF_SIZE 256 - -static bool polling_thread_run = true; - -/* Connection type */ -typedef enum conn_type { - CONN_TYPE_TCP, - CONN_TYPE_UDP, - CONN_TYPE_UART, - CONN_TYPE_UNKNOWN -} conn_type_t; - -/* Sys connection */ -typedef struct sys_connection { - /* Next connection */ - struct sys_connection *next; - - /* Type */ - conn_type_t type; - - /* Handle to interact with wasm app */ - uint32 handle; - - /* Underlying connection ID, may be socket fd */ - int fd; - - /* Module id that the connection belongs to */ - uint32 module_id; - - /* Argument, such as dest addr for udp */ - void *arg; -} sys_connection_t; - -/* Epoll instance */ -static int epollfd; - -/* Connections list */ -static sys_connection_t *g_connections = NULL; - -/* Max handle */ -static uint32 g_handle_max = 0; - -/* Lock to protect g_connections and g_handle_max */ -static korp_mutex g_lock; - -/* Epoll events */ -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); - -/* 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 -}; -/* clang-format on */ - -static void -add_connection(sys_connection_t *conn) -{ - os_mutex_lock(&g_lock); - - g_handle_max++; - if (g_handle_max == -1) - g_handle_max++; - conn->handle = g_handle_max; - - if (g_connections) { - conn->next = g_connections; - g_connections = conn; - } - 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) - -static int -get_app_conns_num(uint32 module_id) -{ - sys_connection_t *conn; - int num = 0; - - os_mutex_lock(&g_lock); - - conn = g_connections; - while (conn) { - if (conn->module_id == module_id) - num++; - conn = conn->next; - } - - os_mutex_unlock(&g_lock); - - return num; -} - -static sys_connection_t * -find_connection(uint32 handle, bool remove_found) -{ - sys_connection_t *conn, *prev = NULL; - - os_mutex_lock(&g_lock); - - conn = g_connections; - while (conn) { - if (conn->handle == handle) { - if (remove_found) { - if (prev != NULL) { - prev->next = conn->next; - } - else { - g_connections = conn->next; - } - } - os_mutex_unlock(&g_lock); - return conn; - } - else { - prev = conn; - conn = conn->next; - } - } - - os_mutex_unlock(&g_lock); - - return NULL; -} - -static void -cleanup_connections(uint32 module_id) -{ - sys_connection_t *conn, *prev = NULL; - - os_mutex_lock(&g_lock); - - conn = g_connections; - while (conn) { - if (conn->module_id == module_id) { - epoll_ctl(epollfd, EPOLL_CTL_DEL, conn->fd, NULL); - close(conn->fd); - - if (prev != NULL) { - prev->next = conn->next; - FREE_CONNECTION(conn); - conn = prev->next; - } - else { - g_connections = conn->next; - FREE_CONNECTION(conn); - conn = g_connections; - } - } - else { - prev = conn; - conn = conn->next; - } - } - - os_mutex_unlock(&g_lock); -} - -static conn_type_t -get_conn_type(const char *name) -{ - if (strcmp(name, "TCP") == 0) - return CONN_TYPE_TCP; - if (strcmp(name, "UDP") == 0) - return CONN_TYPE_UDP; - if (strcmp(name, "UART") == 0) - return CONN_TYPE_UART; - - return CONN_TYPE_UNKNOWN; -} - -/* --- connection lib function --- */ -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); - bh_assert(module_id != ID_NONE); - - if (get_app_conns_num(module_id) >= MAX_CONNECTION_PER_APP) - return -1; - - conn = (sys_connection_t *)wasm_runtime_malloc(sizeof(*conn)); - if (conn == NULL) - return -1; - - memset(conn, 0, sizeof(*conn)); - conn->module_id = module_id; - conn->type = get_conn_type(name); - - /* Generate a handle and add to list */ - add_connection(conn); - - if (conn->type == CONN_TYPE_TCP) { - char *address; - uint16 port; - - /* Check and parse connection parameters */ - if (!attr_container_contain_key(args, "address") - || !attr_container_contain_key(args, "port")) - goto fail; - - address = attr_container_get_as_string(args, "address"); - port = attr_container_get_as_uint16(args, "port"); - - /* Connect to TCP server */ - if (!address || (fd = tcp_open(address, port)) == -1) - goto fail; - } - else if (conn->type == CONN_TYPE_UDP) { - uint16 port; - - /* Check and parse connection parameters */ - if (!attr_container_contain_key(args, "bind port")) - goto fail; - port = attr_container_get_as_uint16(args, "bind port"); - - /* Bind port */ - if ((fd = udp_open(port)) == -1) - goto fail; - } - 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")) - goto fail; - device = attr_container_get_as_string(args, "device"); - baud = attr_container_get_as_int(args, "baudrate"); - - /* Open device */ - if (!device || (fd = uart_open(device, baud)) == -1) - goto fail; - } - else { - goto fail; - } - - conn->fd = fd; - - /* Set current connection as event data */ - ev.events = EPOLLIN; - ev.data.ptr = conn; - - /* Monitor incoming data */ - if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) { - close(fd); - goto fail; - } - - return conn->handle; - -fail: - find_connection(conn->handle, true); - wasm_runtime_free(conn); - return -1; -} - -/* --- connection lib function --- */ -static void -_conn_close(uint32 handle) -{ - sys_connection_t *conn = find_connection(handle, true); - - if (conn != NULL) { - epoll_ctl(epollfd, EPOLL_CTL_DEL, conn->fd, NULL); - close(conn->fd); - FREE_CONNECTION(conn); - } -} - -/* --- connection lib function --- */ -static int -_conn_send(uint32 handle, const char *data, int len) -{ - sys_connection_t *conn = find_connection(handle, false); - - if (conn == NULL) - return -1; - - if (conn->type == CONN_TYPE_TCP) - return tcp_send(conn->fd, data, len); - - if (conn->type == CONN_TYPE_UDP) { - struct sockaddr *addr = (struct sockaddr *)conn->arg; - return udp_send(conn->fd, addr, data, len); - } - - if (conn->type == CONN_TYPE_UART) - return uart_send(conn->fd, data, len); - - return -1; -} - -/* --- connection lib function --- */ -static bool -_conn_config(uint32 handle, attr_container_t *cfg) -{ - sys_connection_t *conn = find_connection(handle, false); - - if (conn == NULL) - return false; - - if (conn->type == CONN_TYPE_UDP) { - char *address; - uint16_t port; - struct sockaddr_in *addr; - - /* Parse remote address/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; - port = attr_container_get_as_uint16(cfg, "port"); - - if (conn->arg == NULL) { - addr = (struct sockaddr_in *)wasm_runtime_malloc(sizeof(*addr)); - if (addr == NULL) - return false; - - memset(addr, 0, sizeof(*addr)); - addr->sin_family = AF_INET; - addr->sin_addr.s_addr = inet_addr(address); - addr->sin_port = htons(port); - - /* Set remote address as connection arg */ - conn->arg = addr; - } - else { - addr = (struct sockaddr_in *)conn->arg; - addr->sin_addr.s_addr = inet_addr(address); - addr->sin_port = htons(port); - } - - return true; - } - - return false; -} - -/* --- connection manager reference implementation ---*/ - -typedef struct connection_event { - uint32 handle; - char *data; - uint32 len; -} connection_event_t; - -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) -{ - module_data *module = module_data_list_lookup_id(conn->module_id); - char *data_copy = NULL; - connection_event_t *conn_data_event; - bh_message_t msg; - - if (module == NULL) - return; - - conn_data_event = - (connection_event_t *)wasm_runtime_malloc(sizeof(*conn_data_event)); - if (conn_data_event == NULL) - return; - - if (len > 0) { - data_copy = (char *)wasm_runtime_malloc(len); - if (data_copy == NULL) { - wasm_runtime_free(conn_data_event); - return; - } - bh_memcpy_s(data_copy, len, data, len); - } - - memset(conn_data_event, 0, sizeof(*conn_data_event)); - conn_data_event->handle = conn->handle; - 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); - if (!msg) { - connection_event_cleaner(conn_data_event); - return; - } - - bh_post_msg2(module->queue, msg); -} - -static void * -polling_thread_routine(void *arg) -{ - while (polling_thread_run) { - int i, n; - - n = epoll_wait(epollfd, epoll_events, MAX_EVENTS, -1); - - if (n == -1 && errno != EINTR) - continue; - - for (i = 0; i < n; i++) { - 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); - if (count <= 0) { - /* Connection is closed by peer */ - post_msg_to_module(conn, NULL, 0); - _conn_close(conn->handle); - } - else { - /* Data is received */ - post_msg_to_module(conn, io_buf, count); - } - } - 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) { - int count = uart_recv(conn->fd, io_buf, IO_BUF_SIZE); - if (count > 0) - post_msg_to_module(conn, io_buf, count); - } - } - } - - return NULL; -} - -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_module_inst_t inst = wasm_app_data->wasm_module_inst; - 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)"); - if (!func_on_conn_data) - 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; - } - - /* 0 len means connection closed */ - if (conn_event->len == 0) { - argv[0] = conn_event->handle; - argv[1] = 0; - argv[2] = 0; - 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); - wasm_runtime_clear_exception(inst); - return; - } - } - 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); - wasm_runtime_clear_exception(inst); - } - return; - } - - argv[0] = conn_event->handle; - 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); - wasm_runtime_clear_exception(inst); - wasm_runtime_module_free(inst, data_offset); - return; - } - wasm_runtime_module_free(inst, data_offset); - } -} - -bool -init_connection_framework() -{ - korp_tid tid; - - epollfd = epoll_create(MAX_EVENTS); - if (epollfd == -1) - return false; - - if (os_mutex_init(&g_lock) != 0) { - close(epollfd); - return false; - } - - if (!wasm_register_cleanup_callback(cleanup_connections)) { - goto fail; - } - - if (!wasm_register_msg_callback(CONNECTION_EVENT_WASM, - app_mgr_connection_event_callback)) { - goto fail; - } - - if (os_thread_create(&tid, polling_thread_routine, NULL, - BH_APPLET_PRESERVED_STACK_SIZE) - != 0) { - goto fail; - } - - return true; - -fail: - os_mutex_destroy(&g_lock); - close(epollfd); - return false; -} - -void -exit_connection_framework() -{ - polling_thread_run = false; -} diff --git a/core/app-framework/connection/native/linux/connection_mgr.cmake b/core/app-framework/connection/native/linux/connection_mgr.cmake deleted file mode 100644 index c8f2b487e..000000000 --- a/core/app-framework/connection/native/linux/connection_mgr.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_LIB_CONN_MGR_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${WASM_LIB_CONN_MGR_DIR}) - - -file (GLOB_RECURSE source_all ${WASM_LIB_CONN_MGR_DIR}/*.c) - -set (WASM_LIB_CONN_MGR_SOURCE ${source_all}) - - diff --git a/core/app-framework/connection/native/wasm_lib.cmake b/core/app-framework/connection/native/wasm_lib.cmake deleted file mode 100644 index 58db0c1d8..000000000 --- a/core/app-framework/connection/native/wasm_lib.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_LIB_CONN_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${WASM_LIB_CONN_DIR}) - -add_definitions (-DAPP_FRAMEWORK_CONNECTION) - - -include (${CMAKE_CURRENT_LIST_DIR}/${WAMR_BUILD_PLATFORM}/connection_mgr.cmake) - -file (GLOB source_all - ${WASM_LIB_CONN_MGR_SOURCE} - ${WASM_LIB_CONN_DIR}/*.c -) - -set (WASM_APP_LIB_CURRENT_SOURCE ${source_all}) diff --git a/core/app-framework/connection/native/zephyr/connection_lib_impl.c b/core/app-framework/connection/native/zephyr/connection_lib_impl.c deleted file mode 100644 index a812a71a2..000000000 --- a/core/app-framework/connection/native/zephyr/connection_lib_impl.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -/* - * Note: - * This file implements the linux version connection library which is - * defined in connection_lib.h. - * It also provides a reference impl of connections manager. - */ - -#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 -}; -/* clang-format on */ diff --git a/core/app-framework/connection/native/zephyr/connection_mgr.cmake b/core/app-framework/connection/native/zephyr/connection_mgr.cmake deleted file mode 100644 index c8f2b487e..000000000 --- a/core/app-framework/connection/native/zephyr/connection_mgr.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_LIB_CONN_MGR_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${WASM_LIB_CONN_MGR_DIR}) - - -file (GLOB_RECURSE source_all ${WASM_LIB_CONN_MGR_DIR}/*.c) - -set (WASM_LIB_CONN_MGR_SOURCE ${source_all}) - - diff --git a/core/app-framework/sensor/app/sensor.c b/core/app-framework/sensor/app/sensor.c deleted file mode 100644 index d898a1d3a..000000000 --- a/core/app-framework/sensor/app/sensor.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wa-inc/sensor.h" - -#include "sensor_api.h" - -typedef struct _sensor { - struct _sensor *next; - char *name; - uint32 handle; - void (*sensor_callback)(sensor_t, attr_container_t *, void *); - void *user_data; -} 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) -{ - 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)); - if (sensor == NULL) - return NULL; - - memset(sensor, 0, sizeof(struct _sensor)); - sensor->handle = id; - sensor->name = strdup(name); - sensor->user_data = user_data; - sensor->sensor_callback = sensor_event_handler; - - if (!sensor->name) { - free(sensor); - return NULL; - } - - if (g_sensors == NULL) { - g_sensors = sensor; - } - else { - sensor->next = g_sensors; - g_sensors = sensor; - } - - return sensor; -} - -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); - - 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 ret = wasm_sensor_config(sensor->handle, interval, bit_cfg, delay); - return ret; -} - -bool -sensor_close(sensor_t sensor) -{ - wasm_sensor_close(sensor->handle); - - // remove local node - sensor_t s = g_sensors; - sensor_t prev = NULL; - while (s) { - if (s == sensor) { - if (prev == NULL) { - g_sensors = s->next; - } - else { - prev->next = s->next; - } - free(s->name); - free(s); - return true; - } - else { - prev = s; - s = s->next; - } - } - - return false; -} - -/* - * - * API for native layer to callback for sensor events - * - */ - -void -on_sensor_event(uint32 sensor_id, char *buffer, int len) -{ - attr_container_t *sensor_data = (attr_container_t *)buffer; - - // lookup the sensor and call the handlers - sensor_t s = g_sensors; - sensor_t prev = NULL; - while (s) { - if (s->handle == sensor_id) { - s->sensor_callback(s, sensor_data, s->user_data); - break; - } - - s = s->next; - } -} diff --git a/core/app-framework/sensor/app/sensor_api.h b/core/app-framework/sensor/app/sensor_api.h deleted file mode 100644 index ad6a7aa24..000000000 --- a/core/app-framework/sensor/app/sensor_api.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _SENSOR_API_H_ -#define _SENSOR_API_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -uint32 -wasm_sensor_open(const char *name, int instance); - -bool -wasm_sensor_config(uint32 sensor, uint32 interval, int bit_cfg, uint32 delay); - -bool -wasm_sensor_config_with_attr_container(uint32 sensor, char *buffer, uint32 len); - -bool -wasm_sensor_close(uint32 sensor); - -#ifdef __cplusplus -} -#endif - -#endif /* end of _SENSOR_API_H_ */ diff --git a/core/app-framework/sensor/app/wa-inc/sensor.h b/core/app-framework/sensor/app/wa-inc/sensor.h deleted file mode 100644 index 109f895d3..000000000 --- a/core/app-framework/sensor/app/wa-inc/sensor.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _AEE_SENSOR_H_ -#define _AEE_SENSOR_H_ - -#include "bi-inc/attr_container.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* board producer define sensor */ -struct _sensor; -typedef struct _sensor *sensor_t; - -/** - * @typedef sensor_event_handler_f - * - * @brief Define the signature of callback function for API - * sensor_open() to handle sensor event. - * - * @param sensor the sensor which the event belong to - * @param sensor_event the sensor event - * @param user_data user data associated with the sensor which is set when - * calling sensor_open(). - * - * @see sensor_open - */ -typedef void (*sensor_event_handler_f)(sensor_t sensor, - attr_container_t *sensor_event, - void *user_data); - -/* - ***************** - * Sensor APIs - ***************** - */ - -/** - * @brief Open sensor. - * - * @param name sensor name - * @param index sensor index - * @param handler callback function to handle the sensor event - * @param user_data user data - * - * @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); - -/** - * @brief Configure sensor with interval/bit_cfg/delay values. - * - * @param sensor the sensor to be configured - * @param interval sensor event interval - * @param bit_cfg sensor bit config - * @param delay sensor delay - * - * @return true if success, false otherwise - */ -bool -sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay); - -/** - * @brief Configure sensor with attr_container_t object. - * - * @param sensor the sensor to be configured - * @param cfg the configuration - * - * @return true if success, false otherwise - */ -bool -sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg); - -/** - * @brief Close sensor. - * - * @param sensor the sensor to be closed - * - * @return true if success, false otherwise - */ -bool -sensor_close(sensor_t sensor); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/core/app-framework/sensor/app/wasm_app.cmake b/core/app-framework/sensor/app/wasm_app.cmake deleted file mode 100644 index 4b14a8bef..000000000 --- a/core/app-framework/sensor/app/wasm_app.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_APP_SENSOR_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${WASM_APP_SENSOR_DIR}) - - -file (GLOB_RECURSE source_all ${WASM_APP_SENSOR_DIR}/*.c) - -set (WASM_APP_CURRENT_SOURCE ${source_all}) diff --git a/core/app-framework/sensor/native/runtime_sensor.c b/core/app-framework/sensor/native/runtime_sensor.c deleted file mode 100644 index ad7a3fbf5..000000000 --- a/core/app-framework/sensor/native/runtime_sensor.c +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "runtime_sensor.h" -#include "app_manager_export.h" -#include "module_wasm_app.h" -#include "bh_platform.h" - -static sys_sensor_t *g_sys_sensors = NULL; -static uint32 g_sensor_id_max = 0; - -static sensor_client_t * -find_sensor_client(sys_sensor_t *sensor, unsigned int client_id, - bool remove_if_found); - -void (*rechedule_sensor_callback)() = NULL; - -/* - * API for the applications to call - don't call it from the runtime - * - */ - -static void -sensor_event_cleaner(sensor_event_data_t *sensor_event) -{ - if (sensor_event->data != NULL) { - if (sensor_event->data_fmt == FMT_ATTR_CONTAINER) - attr_container_destroy(sensor_event->data); - else - wasm_runtime_free(sensor_event->data); - } - - wasm_runtime_free(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_clone; - int sensor_data_len; - sensor_event_data_t *sensor_event; - bh_message_t msg; - 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; - - sensor_data_len = attr_container_get_serialize_length(sensor_data); - 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); - - sensor_event = - (sensor_event_data_t *)wasm_runtime_malloc(sizeof(*sensor_event)); - if (sensor_event == NULL) { - wasm_runtime_free(sensor_data_clone); - return; - } - - memset(sensor_event, 0, sizeof(*sensor_event)); - sensor_event->sensor_id = sensor_id; - 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), - sensor_event_cleaner); - if (!msg) { - sensor_event_cleaner(sensor_event); - return; - } - - bh_post_msg2(module->queue, msg); -} - -bool -wasm_sensor_config(wasm_exec_env_t exec_env, uint32 sensor, uint32 interval, - int bit_cfg, uint32 delay) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - 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); - bh_assert(mod_id != ID_NONE); - - os_mutex_lock(&s->lock); - - c = find_sensor_client(s, mod_id, false); - if (c == NULL) { - os_mutex_unlock(&s->lock); - return false; - } - - c->interval = interval; - c->bit_cfg = bit_cfg; - c->delay = delay; - - os_mutex_unlock(&s->lock); - - if (s->config != NULL) { - attr_cont = attr_container_create("config sensor"); - attr_container_set_int(&attr_cont, "interval", (int)interval); - attr_container_set_int(&attr_cont, "bit_cfg", bit_cfg); - attr_container_set_int(&attr_cont, "delay", (int)delay); - s->config(s, attr_cont); - attr_container_destroy(attr_cont); - } - - refresh_read_interval(s); - - reschedule_sensor_read(); - - return true; -} - -uint32 -wasm_sensor_open(wasm_exec_env_t exec_env, char *name, int instance) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (name != NULL) { - sensor_client_t *c; - sys_sensor_t *s = find_sys_sensor(name, instance); - if (s == NULL) - return (uint32)-1; - - 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); - - c = find_sensor_client(s, mod_id, false); - if (c) { - // the app already opened this sensor - os_mutex_unlock(&s->lock); - return (uint32)-1; - } - - sensor_client_t *client = - (sensor_client_t *)wasm_runtime_malloc(sizeof(sensor_client_t)); - if (client == NULL) { - os_mutex_unlock(&s->lock); - return (uint32)-1; - } - - memset(client, 0, sizeof(sensor_client_t)); - client->client_id = mod_id; - client->client_callback = (void *)wasm_sensor_callback; - client->interval = s->default_interval; - client->next = s->clients; - s->clients = client; - - os_mutex_unlock(&s->lock); - - refresh_read_interval(s); - - reschedule_sensor_read(); - - return s->sensor_id; - } - - return (uint32)-1; -} - -bool -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; - sensor_obj_t s = find_sys_sensor_id(sensor); - if (s == NULL) - return false; - - if (s->config == NULL) - return false; - - return s->config(s, cfg); - } - - return false; -} - -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 client_id = mod_id; - sensor_obj_t s = find_sys_sensor_id(sensor); - sensor_client_t *c; - - bh_assert(mod_id != ID_NONE); - - if (s == NULL) - return false; - - os_mutex_lock(&s->lock); - if ((c = find_sensor_client(s, client_id, true)) != NULL) - wasm_runtime_free(c); - os_mutex_unlock(&s->lock); - - refresh_read_interval(s); - - reschedule_sensor_read(); - - return true; -} - -/* - * - * sensor framework API - don't expose to the applications - * - */ -void -set_sensor_reshceduler(void (*callback)()) -{ - rechedule_sensor_callback = callback; -} - -// used for other threads to wakeup the sensor read thread -void -reschedule_sensor_read() -{ - if (rechedule_sensor_callback) - rechedule_sensor_callback(); -} - -void -refresh_read_interval(sensor_obj_t sensor) -{ - sensor_client_t *c; - uint32 interval = sensor->default_interval; - os_mutex_lock(&sensor->lock); - - c = sensor->clients; - if (c) - interval = c->interval; - - while (c) { - if (c->interval < interval) - interval = c->interval; - c = c->next; - } - - os_mutex_unlock(&sensor->lock); - - sensor->read_interval = interval; -} - -sensor_obj_t -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)); - if (s == NULL) - return NULL; - - memset(s, 0, sizeof(*s)); - s->name = bh_strdup(name); - s->sensor_instance = instance; - s->default_interval = default_interval; - - if (!s->name) { - wasm_runtime_free(s); - return NULL; - } - - if (description) { - s->description = bh_strdup(description); - if (!s->description) { - wasm_runtime_free(s->name); - wasm_runtime_free(s); - return NULL; - } - } - - g_sensor_id_max++; - if (g_sensor_id_max == UINT32_MAX) - g_sensor_id_max++; - s->sensor_id = g_sensor_id_max; - - s->read = read_func; - s->config = config_func; - - if (g_sys_sensors == NULL) { - g_sys_sensors = s; - } - else { - s->next = g_sys_sensors; - g_sys_sensors = s; - } - - if (os_mutex_init(&s->lock) != 0) { - if (s->description) { - wasm_runtime_free(s->description); - } - wasm_runtime_free(s->name); - wasm_runtime_free(s); - } - - return s; -} - -sensor_obj_t -find_sys_sensor(const char *name, int instance) -{ - sys_sensor_t *s = g_sys_sensors; - while (s) { - if (strcmp(s->name, name) == 0 && s->sensor_instance == instance) - return s; - - s = s->next; - } - return NULL; -} - -sensor_obj_t -find_sys_sensor_id(uint32 sensor_id) -{ - sys_sensor_t *s = g_sys_sensors; - while (s) { - if (s->sensor_id == sensor_id) - return s; - - s = s->next; - } - return NULL; -} - -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; - - while (c) { - sensor_client_t *next = c->next; - if (c->client_id == client_id) { - if (remove_if_found) { - if (prev) - prev->next = next; - else - sensor->clients = next; - } - return c; - } - else { - prev = c; - c = c->next; - } - } - - return NULL; -} - -// return the milliseconds to next check -uint32 -check_sensor_timers() -{ - uint32 ms_to_next_check = UINT32_MAX; - uint32 now = (uint32)bh_get_tick_ms(); - - sys_sensor_t *s = g_sys_sensors; - while (s) { - uint32 last_read = s->last_read; - uint32 elpased_ms = bh_get_elpased_ms(&last_read); - - if (s->read_interval <= 0 || s->clients == NULL) { - s = s->next; - continue; - } - - if (elpased_ms >= s->read_interval) { - attr_container_t *data = s->read(s); - if (data) { - sensor_client_t *client = s->clients; - while (client) { - client->client_callback(client, s->sensor_id, data); - client = client->next; - } - attr_container_destroy(data); - } - - s->last_read = now; - - if (s->read_interval < ms_to_next_check) - ms_to_next_check = s->read_interval; - } - else { - uint32 remaining = s->read_interval - elpased_ms; - if (remaining < ms_to_next_check) - ms_to_next_check = remaining; - } - - s = s->next; - } - - return ms_to_next_check; -} - -void -sensor_cleanup_callback(uint32 module_id) -{ - sys_sensor_t *s = g_sys_sensors; - - while (s) { - sensor_client_t *c; - os_mutex_lock(&s->lock); - if ((c = find_sensor_client(s, module_id, true)) != NULL) { - wasm_runtime_free(c); - } - os_mutex_unlock(&s->lock); - s = s->next; - } -} diff --git a/core/app-framework/sensor/native/runtime_sensor.h b/core/app-framework/sensor/native/runtime_sensor.h deleted file mode 100644 index d7c893111..000000000 --- a/core/app-framework/sensor/native/runtime_sensor.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef LIB_EXTENSION_RUNTIME_SENSOR_H_ -#define LIB_EXTENSION_RUNTIME_SENSOR_H_ - -#include "bh_platform.h" -#include "bi-inc/attr_container.h" -#include "wasm_export.h" -#include "sensor_native_api.h" - -struct _sys_sensor; -typedef struct _sys_sensor *sensor_obj_t; - -typedef struct _sensor_client { - struct _sensor_client *next; - unsigned int client_id; // the app id - uint32 interval; - int bit_cfg; - uint32 delay; - void (*client_callback)(void *client, uint32, attr_container_t *); -} sensor_client_t; - -typedef struct _sys_sensor { - struct _sys_sensor *next; - char *name; - int sensor_instance; - char *description; - uint32 sensor_id; - 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 */ - korp_mutex lock; - uint32 last_read; - uint32 read_interval; - uint32 default_interval; - - /* 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); -uint32 -check_sensor_timers(); -void -reschedule_sensor_read(); - -bool -init_sensor_framework(); -void -start_sensor_framework(); -void -exit_sensor_framework(); - -#endif /* LIB_EXTENSION_RUNTIME_SENSOR_H_ */ diff --git a/core/app-framework/sensor/native/runtime_sensor.inl b/core/app-framework/sensor/native/runtime_sensor.inl deleted file mode 100644 index a7b9f4778..000000000 --- a/core/app-framework/sensor/native/runtime_sensor.inl +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -EXPORT_WASM_API_WITH_SIG(wasm_sensor_open, "($i)i"), -EXPORT_WASM_API_WITH_SIG(wasm_sensor_config, "(iiii)i"), -EXPORT_WASM_API_WITH_SIG(wasm_sensor_config_with_attr_container, "(i*~)i"), -EXPORT_WASM_API_WITH_SIG(wasm_sensor_close, "(i)i"), diff --git a/core/app-framework/sensor/native/sensor_mgr_ref.c b/core/app-framework/sensor/native/sensor_mgr_ref.c deleted file mode 100644 index 474ec738d..000000000 --- a/core/app-framework/sensor/native/sensor_mgr_ref.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "bh_platform.h" -#include "runtime_sensor.h" -#include "bi-inc/attr_container.h" -#include "module_wasm_app.h" -#include "wasm_export.h" - -/* - * - * One reference implementation for sensor manager - * - * - */ -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) -{ - 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_module_inst_t inst = wasm_app_data->wasm_module_inst; - - 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)"); - if (!func_onSensorEvent) - func_onSensorEvent = wasm_runtime_lookup_function( - inst, "on_sensor_event", "(i32i32i32)"); - if (!func_onSensorEvent) { - printf("Cannot find function on_sensor_event\n"); - } - 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 { - 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); - if (sensor_data_offset == 0) { - const char *exception = wasm_runtime_get_exception(inst); - if (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[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); - wasm_runtime_clear_exception(inst); - wasm_runtime_module_free(inst, sensor_data_offset); - return; - } - - wasm_runtime_module_free(inst, sensor_data_offset); - } -} - -static void -thread_sensor_check(void *arg) -{ - while (sensor_check_thread_run) { - uint32 ms_to_expiry = check_sensor_timers(); - if (ms_to_expiry == UINT32_MAX) - ms_to_expiry = 5000; - os_mutex_lock(&mutex); - os_cond_reltimedwait(&cond, &mutex, ms_to_expiry * 1000); - os_mutex_unlock(&mutex); - } -} - -static void -cb_wakeup_thread() -{ - os_cond_signal(&cond); -} - -void -set_sensor_reshceduler(void (*callback)()); - -bool -init_sensor_framework() -{ - /* init the mutext and conditions */ - if (os_cond_init(&cond) != 0) { - return false; - } - - if (os_mutex_init(&mutex) != 0) { - os_cond_destroy(&cond); - return false; - } - - 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); - - return true; -} - -void -start_sensor_framework() -{ - korp_tid tid; - - os_thread_create(&tid, (void *)thread_sensor_check, NULL, - BH_APPLET_PRESERVED_STACK_SIZE); -} - -void -exit_sensor_framework() -{ - sensor_check_thread_run = false; - reschedule_sensor_read(); - - // todo: wait the sensor thread termination -} diff --git a/core/app-framework/sensor/native/sensor_native_api.h b/core/app-framework/sensor/native/sensor_native_api.h deleted file mode 100644 index 0bbb315ca..000000000 --- a/core/app-framework/sensor/native/sensor_native_api.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _SENSOR_NATIVE_API_H_ -#define _SENSOR_NATIVE_API_H_ - -#include "bh_platform.h" -#include "wasm_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -bool -wasm_sensor_config(wasm_exec_env_t exec_env, uint32 sensor, uint32 interval, - int bit_cfg, uint32 delay); -uint32 -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); - -bool -wasm_sensor_close(wasm_exec_env_t exec_env, uint32 sensor); - -#ifdef __cplusplus -} -#endif - -#endif /* end of _SENSOR_NATIVE_API_H_ */ diff --git a/core/app-framework/sensor/native/wasm_lib.cmake b/core/app-framework/sensor/native/wasm_lib.cmake deleted file mode 100644 index 65a83ba59..000000000 --- a/core/app-framework/sensor/native/wasm_lib.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_LIB_SENSOR_DIR ${CMAKE_CURRENT_LIST_DIR}) - -add_definitions (-DAPP_FRAMEWORK_SENSOR) - -include_directories(${WASM_LIB_SENSOR_DIR}) - - -file (GLOB_RECURSE source_all ${WASM_LIB_SENSOR_DIR}/*.c) - -set (WASM_APP_LIB_CURRENT_SOURCE ${source_all}) - diff --git a/core/app-framework/template/app/wa-inc/app_xxx.h b/core/app-framework/template/app/wa-inc/app_xxx.h deleted file mode 100644 index ac30842f0..000000000 --- a/core/app-framework/template/app/wa-inc/app_xxx.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -/* - header file for wasm application -*/ \ No newline at end of file diff --git a/core/app-framework/template/app/wasm_app.cmake b/core/app-framework/template/app/wasm_app.cmake deleted file mode 100644 index 16ca237ae..000000000 --- a/core/app-framework/template/app/wasm_app.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_APP_CURRENT_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories( - ${WASM_APP_CURRENT_DIR} - # Add your include dir here -) - -file (GLOB_RECURSE source_all - ${WASM_APP_CURRENT_DIR}/*.c - # Add your source file here -) - -set (WASM_APP_CURRENT_SOURCE ${source_all}) diff --git a/core/app-framework/template/native/app_xxx.inl b/core/app-framework/template/native/app_xxx.inl deleted file mode 100644 index 2503fe454..000000000 --- a/core/app-framework/template/native/app_xxx.inl +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -/* EXPORT_WASM_API(your_api_here), */ diff --git a/core/app-framework/template/native/wasm_lib.cmake b/core/app-framework/template/native/wasm_lib.cmake deleted file mode 100644 index 2601c1d27..000000000 --- a/core/app-framework/template/native/wasm_lib.cmake +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_LIB_CURRENT_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories( - ${WASM_LIB_CURRENT_DIR} - # Add your include dir here -) - -file (GLOB_RECURSE source_all - ${WASM_LIB_CURRENT_DIR}/*.c - # Add your source file here -) - -set (WASM_APP_LIB_CURRENT_SOURCE ${source_all}) - diff --git a/core/app-framework/wgl/app/gui_api.h b/core/app-framework/wgl/app/gui_api.h deleted file mode 100644 index 7547cdcdc..000000000 --- a/core/app-framework/wgl/app/gui_api.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _GUI_API_H_ -#define _GUI_API_H_ - -#include "bh_platform.h" -#include "bi-inc/wgl_shared_utils.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void -wasm_obj_native_call(int32 func_id, uint32 *argv, uint32 argc); - -void -wasm_btn_native_call(int32 func_id, uint32 *argv, uint32 argc); - -void -wasm_label_native_call(int32 func_id, uint32 *argv, uint32 argc); - -void -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_ */ diff --git a/core/app-framework/wgl/app/prepare_headers.sh b/core/app-framework/wgl/app/prepare_headers.sh deleted file mode 100755 index 261257952..000000000 --- a/core/app-framework/wgl/app/prepare_headers.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -WGL_ROOT=$(cd "$(dirname "$0")/" && pwd) -LVGL_REPO_DIR=${WGL_ROOT}/../../../deps/lvgl -ls $LVGL_REPO_DIR - -#if [ ! -d "${LVGL_REPO_DIR}" ]; then -# echo "lvgl repo not exist, please git pull the lvgl v6.0 first" -# exit 1 -#fi - -cd ${WGL_ROOT}/wa-inc/lvgl -pwd - -if [ -d src ]; then - rm -rf src - echo "deleted the src folder from previous preparation." -fi - -mkdir src -cd src - -cp ${LVGL_REPO_DIR}/src/*.h ./ - -for folder in lv_core lv_draw lv_hal lv_objx lv_font lv_misc lv_themes -do - echo "Prepare fold $folder...done" - mkdir $folder - cp ${LVGL_REPO_DIR}/src/${folder}/*.h ./${folder}/ -done - -cp -f ../lv_obj.h ./lv_core/lv_obj.h - -echo "test the header files..." -cd .. - -gcc test.c -o test.out -if [ $? != 0 ];then - echo "failed to compile the test.c" - exit 1 -else - echo "okay" - rm test.out -fi - -echo "lvgl header files for WASM application ready." diff --git a/core/app-framework/wgl/app/src/wgl_btn.c b/core/app-framework/wgl/app/src/wgl_btn.c deleted file mode 100644 index 680124e5f..000000000 --- a/core/app-framework/wgl/app/src/wgl_btn.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wa-inc/lvgl/lvgl.h" -#include "bh_platform.h" -#include "gui_api.h" - -#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) -{ - uint32 argv[2] = { 0 }; - - argv[0] = (uint32)par; - argv[1] = (uint32)copy; - CALL_BTN_NATIVE_FUNC(BTN_FUNC_ID_CREATE); - return (lv_obj_t *)argv[0]; -} - -void -lv_btn_set_toggle(lv_obj_t *btn, bool tgl) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -//{ -// //TODO: pack style -// //wasm_btn_set_style(btn, type, style); -//} -// -lv_btn_state_t -lv_btn_get_state(const lv_obj_t *btn) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -//{ -// //TODO: pack style -// //wasm_btn_get_style(btn, type); -// return NULL; -//} diff --git a/core/app-framework/wgl/app/src/wgl_cb.c b/core/app-framework/wgl/app/src/wgl_cb.c deleted file mode 100644 index bd172d3b0..000000000 --- a/core/app-framework/wgl/app/src/wgl_cb.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wa-inc/lvgl/lvgl.h" -#include "gui_api.h" - -#include - -#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) -{ - uint32 argv[2] = { 0 }; - - argv[0] = (uint32)par; - argv[1] = (uint32)copy; - CALL_CB_NATIVE_FUNC(CB_FUNC_ID_CREATE); - return (lv_obj_t *)argv[0]; -} - -void -lv_cb_set_text(lv_obj_t *cb, const char *txt) -{ - 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) -{ - 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) -//{ -// //TODO: -//} -// - -static unsigned int -wgl_cb_get_text_length(lv_obj_t *cb) -{ - 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) -{ - uint32 argv[3] = { 0 }; - argv[0] = (uint32)cb; - argv[1] = (uint32)buffer; - argv[2] = buffer_len; - CALL_CB_NATIVE_FUNC(CB_FUNC_ID_GET_TEXT); - return (char *)argv[0]; -} - -// TODO: need to use a global data buffer for the returned text -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) -//{ -// //TODO -// return NULL; -//} -// diff --git a/core/app-framework/wgl/app/src/wgl_label.c b/core/app-framework/wgl/app/src/wgl_label.c deleted file mode 100644 index 81c6dcf5f..000000000 --- a/core/app-framework/wgl/app/src/wgl_label.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wa-inc/lvgl/lvgl.h" -#include "gui_api.h" -#include - -#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) -{ - uint32 argv[2] = { 0 }; - - argv[0] = (uint32)par; - argv[1] = (uint32)copy; - CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_CREATE); - return (lv_obj_t *)argv[0]; -} - -void -lv_label_set_text(lv_obj_t *label, const char *text) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - uint32 argv[3] = { 0 }; - argv[0] = (uint32)label; - argv[1] = (uint32)buffer; - argv[2] = buffer_len; - CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_TEXT); - return (char *)argv[0]; -} - -// 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - 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) -{ - uint32 argv[4] = { 0 }; - argv[0] = (uint32)label; - argv[1] = index; - CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LETTER_POS); - pos->x = argv[2]; - pos->y = argv[3]; -} - -uint16_t -lv_label_get_letter_on(const lv_obj_t *label, lv_point_t *pos) -{ - uint32 argv[3] = { 0 }; - argv[0] = (uint32)label; - argv[1] = pos->x; - argv[2] = pos->y; - CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LETTER_POS); - return (uint16_t)argv[0]; -} - -bool -lv_label_is_char_under_pos(const lv_obj_t *label, lv_point_t *pos) -{ - uint32 argv[3] = { 0 }; - argv[0] = (uint32)label; - argv[1] = pos->x; - argv[2] = pos->y; - CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_GET_LETTER_POS); - return (bool)argv[0]; -} - -uint16_t -lv_label_get_text_sel_start(const lv_obj_t *label) -{ - 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) -{ - 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) -{ - uint32 argv[4] = { 0 }; - argv[0] = (uint32)label; - argv[1] = pos; - argv[2] = (uint32)txt; - argv[3] = strlen(txt) + 1; - CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_INS_TEXT); -} - -void -lv_label_cut_text(lv_obj_t *label, uint32_t pos, uint32_t cnt) -{ - uint32 argv[3] = { 0 }; - argv[0] = (uint32)label; - argv[1] = pos; - argv[2] = cnt; - CALL_LABEL_NATIVE_FUNC(LABEL_FUNC_ID_CUT_TEXT); -} diff --git a/core/app-framework/wgl/app/src/wgl_list.c b/core/app-framework/wgl/app/src/wgl_list.c deleted file mode 100644 index 1ca95a6e8..000000000 --- a/core/app-framework/wgl/app/src/wgl_list.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wa-inc/lvgl/lvgl.h" -#include "gui_api.h" - -#include - -#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) -{ - uint32 argv[2] = { 0 }; - - argv[0] = (uint32)par; - argv[1] = (uint32)copy; - - CALL_LIST_NATIVE_FUNC(LIST_FUNC_ID_CREATE); - return (lv_obj_t *)argv[0]; -} -// -// -// 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) -{ - uint32 argv[3] = { 0 }; - - (void)img_src; /* doesn't support img src currently */ - - argv[0] = (uint32)list; - argv[1] = (uint32)txt; - argv[2] = strlen(txt) + 1; - CALL_LIST_NATIVE_FUNC(LIST_FUNC_ID_ADD_BTN); - return (lv_obj_t *)argv[0]; -} -// -// -// 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) -//{ -// wasm_list_set_single_mode(list, mode); -//} -// -//#if LV_USE_GROUP -// -// -// 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) -//{ -// //TODO -//} -// -// -// 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) -//{ -// return wasm_list_get_btn_text(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) -//{ -// 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) -//{ -// 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) -//{ -// 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) -//{ -// return wasm_list_get_btn_index(list, btn); -//} -// -// -// 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) -//{ -// return wasm_list_get_btn_selected(list); -//} -//#endif -// -// -// -// 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) -//{ -// wasm_list_up(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) -//{ -// wasm_list_focus(btn, anim); -//} -// diff --git a/core/app-framework/wgl/app/src/wgl_obj.c b/core/app-framework/wgl/app/src/wgl_obj.c deleted file mode 100644 index e1fe152c5..000000000 --- a/core/app-framework/wgl/app/src/wgl_obj.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wa-inc/lvgl/lvgl.h" -#include "gui_api.h" -#include -#include - -#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_event_cb_t event_cb; -} obj_evt_cb_t; - -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) -{ - 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) -{ - 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) -{ - 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) -{ - uint32 argv[5] = { 0 }; - argv[0] = (uint32)obj; - argv[1] = (uint32)base; - argv[2] = align; - argv[3] = x_mod; - argv[4] = y_mod; - CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_ALIGN); -} - -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) { - if (obj_evt_cb->obj == obj) { - return obj_evt_cb->event_cb; - } - obj_evt_cb = obj_evt_cb->next; - } - - return NULL; -} - -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 }; - - obj_evt_cb = g_obj_evt_cb_list; - while (obj_evt_cb) { - if (obj_evt_cb->obj == obj) { - obj_evt_cb->event_cb = event_cb; - return; - } - } - - obj_evt_cb = (obj_evt_cb_t *)malloc(sizeof(*obj_evt_cb)); - if (obj_evt_cb == NULL) - return; - - memset(obj_evt_cb, 0, sizeof(*obj_evt_cb)); - obj_evt_cb->obj = obj; - obj_evt_cb->event_cb = 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 { - g_obj_evt_cb_list = obj_evt_cb; - } - - argv[0] = (uint32)obj; - CALL_OBJ_NATIVE_FUNC(OBJ_FUNC_ID_SET_EVT_CB); -} - -void -on_widget_event(lv_obj_t *obj, lv_event_t event) -{ - obj_evt_cb_t *obj_evt_cb = g_obj_evt_cb_list; - - while (obj_evt_cb != NULL) { - if (obj_evt_cb->obj == obj) { - obj_evt_cb->event_cb(obj, event); - return; - } - obj_evt_cb = obj_evt_cb->next; - } -} diff --git a/core/app-framework/wgl/app/wa-inc/lv_conf.h b/core/app-framework/wgl/app/wa-inc/lv_conf.h deleted file mode 100644 index b9f3de8c3..000000000 --- a/core/app-framework/wgl/app/wa-inc/lv_conf.h +++ /dev/null @@ -1,497 +0,0 @@ -/** - * @file lv_conf.h - * - */ - -/* - * COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER - */ - -#if 1 /*Set it to "1" to enable content*/ - -#ifndef LV_CONF_H -#define LV_CONF_H -/* clang-format off */ - -#include - - - -/*==================== - Graphical settings - *====================*/ - -/* Maximal horizontal and vertical resolution to support by the library.*/ -#define LV_HOR_RES_MAX (480) -#define LV_VER_RES_MAX (320) - -/* Color depth: - * - 1: 1 byte per pixel - * - 8: RGB233 - * - 16: RGB565 - * - 32: ARGB8888 - */ -#define LV_COLOR_DEPTH 16 - -/* Swap the 2 bytes of RGB565 color. - * Useful if the display has a 8 bit interface (e.g. SPI)*/ -#define LV_COLOR_16_SWAP 0 - -/* 1: Enable screen transparency. - * Useful for OSD or other overlapping GUIs. - * Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/ -#define LV_COLOR_SCREEN_TRANSP 0 - -/*Images pixels with this color will not be drawn (with chroma keying)*/ -#define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/ - -/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ -#define LV_ANTIALIAS 1 - -/* Default display refresh period. - * Can be changed in the display driver (`lv_disp_drv_t`).*/ -#define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/ - -/* Dot Per Inch: used to initialize default sizes. - * E.g. a button with width = LV_DPI / 2 -> half inch wide - * (Not so important, you can adjust it to modify default sizes and spaces)*/ -#define LV_DPI 100 /*[px]*/ - -/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */ -typedef int16_t lv_coord_t; - -/*========================= - Memory manager settings - *=========================*/ - -/* LittelvGL's internal memory manager's settings. - * The graphical objects and other related data are stored here. */ - -/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */ -#define LV_MEM_CUSTOM 0 -#if LV_MEM_CUSTOM == 0 -/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ -# define LV_MEM_SIZE (32U * 1024U) - -/* Complier prefix for a big array declaration */ -# define LV_MEM_ATTR - -/* Set an address for the memory pool instead of allocating it as an array. - * Can be in external SRAM too. */ -# define LV_MEM_ADR 0 - -/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */ -# define LV_MEM_AUTO_DEFRAG 1 -#else /*LV_MEM_CUSTOM*/ -# define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ -# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ -# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ -#endif /*LV_MEM_CUSTOM*/ - -/* Garbage Collector settings - * Used if lvgl is binded to higher level language and the memory is managed by that language */ -#define LV_ENABLE_GC 0 -#if LV_ENABLE_GC != 0 -# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ -# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/ -# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/ -#endif /* LV_ENABLE_GC */ - -/*======================= - Input device settings - *=======================*/ - -/* Input device default settings. - * Can be changed in the Input device driver (`lv_indev_drv_t`)*/ - -/* Input device read period in milliseconds */ -#define LV_INDEV_DEF_READ_PERIOD 30 - -/* Drag threshold in pixels */ -#define LV_INDEV_DEF_DRAG_LIMIT 10 - -/* Drag throw slow-down in [%]. Greater value -> faster slow-down */ -#define LV_INDEV_DEF_DRAG_THROW 20 - -/* Long press time in milliseconds. - * Time to send `LV_EVENT_LONG_PRESSSED`) */ -#define LV_INDEV_DEF_LONG_PRESS_TIME 400 - -/* Repeated trigger period in long press [ms] - * Time between `LV_EVENT_LONG_PRESSED_REPEAT */ -#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100 - -/*================== - * Feature usage - *==================*/ - -/*1: Enable the Animations */ -#define LV_USE_ANIMATION 1 -#if LV_USE_ANIMATION - -/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_anim_user_data_t; - -#endif - -/* 1: Enable shadow drawing*/ -#define LV_USE_SHADOW 1 - -/* 1: Enable object groups (for keyboard/encoder navigation) */ -#define LV_USE_GROUP 1 -#if LV_USE_GROUP -typedef void * lv_group_user_data_t; -#endif /*LV_USE_GROUP*/ - -/* 1: Enable GPU interface*/ -#define LV_USE_GPU 1 - -/* 1: Enable file system (might be required for images */ -#define LV_USE_FILESYSTEM 1 -#if LV_USE_FILESYSTEM -/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_fs_drv_user_data_t; -#endif - -/*1: Add a `user_data` to drivers and objects*/ -#define LV_USE_USER_DATA 0 - -/*======================== - * Image decoder and cache - *========================*/ - -/* 1: Enable indexed (palette) images */ -#define LV_IMG_CF_INDEXED 1 - -/* 1: Enable alpha indexed images */ -#define LV_IMG_CF_ALPHA 1 - -/* Default image cache size. Image caching keeps the images opened. - * If only the built-in image formats are used there is no real advantage of caching. - * (I.e. no new image decoder is added) - * With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images. - * However the opened images might consume additional RAM. - * LV_IMG_CACHE_DEF_SIZE must be >= 1 */ -#define LV_IMG_CACHE_DEF_SIZE 1 - -/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_img_decoder_user_data_t; - -/*===================== - * Compiler settings - *====================*/ -/* Define a custom attribute to `lv_tick_inc` function */ -#define LV_ATTRIBUTE_TICK_INC - -/* Define a custom attribute to `lv_task_handler` function */ -#define LV_ATTRIBUTE_TASK_HANDLER - -/* With size optimization (-Os) the compiler might not align data to - * 4 or 8 byte boundary. This alignment will be explicitly applied where needed. - * E.g. __attribute__((aligned(4))) */ -#define LV_ATTRIBUTE_MEM_ALIGN - -/* Attribute to mark large constant arrays for example - * font's bitmaps */ -#define LV_ATTRIBUTE_LARGE_CONST - -/*=================== - * HAL settings - *==================*/ - -/* 1: use a custom tick source. - * It removes the need to manually update the tick with `lv_tick_inc`) */ -#define LV_TICK_CUSTOM 0 -#if LV_TICK_CUSTOM == 1 -#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/ -#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/ -#endif /*LV_TICK_CUSTOM*/ - -typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ -typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/ - -/*================ - * Log settings - *===============*/ - -/*1: Enable the log module*/ -#define LV_USE_LOG 0 -#if LV_USE_LOG -/* How important log should be added: - * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information - * LV_LOG_LEVEL_INFO Log important events - * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem - * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail - * LV_LOG_LEVEL_NONE Do not log anything - */ -# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN - -/* 1: Print the log with 'printf'; - * 0: user need to register a callback with `lv_log_register_print`*/ -# define LV_LOG_PRINTF 0 -#endif /*LV_USE_LOG*/ - -/*================ - * THEME USAGE - *================*/ -#define LV_THEME_LIVE_UPDATE 0 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/ - -#define LV_USE_THEME_TEMPL 0 /*Just for test*/ -#define LV_USE_THEME_DEFAULT 0 /*Built mainly from the built-in styles. Consumes very few RAM*/ -#define LV_USE_THEME_ALIEN 0 /*Dark futuristic theme*/ -#define LV_USE_THEME_NIGHT 0 /*Dark elegant theme*/ -#define LV_USE_THEME_MONO 0 /*Mono color theme for monochrome displays*/ -#define LV_USE_THEME_MATERIAL 0 /*Flat theme with bold colors and light shadows*/ -#define LV_USE_THEME_ZEN 0 /*Peaceful, mainly light theme */ -#define LV_USE_THEME_NEMO 0 /*Water-like theme based on the movie "Finding Nemo"*/ - -/*================== - * FONT USAGE - *===================*/ - -/* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel. - * The symbols are available via `LV_SYMBOL_...` defines - * More info about fonts: https://docs.littlevgl.com/#Fonts - * To create a new font go to: https://littlevgl.com/ttf-font-to-c-array - */ - -/* Robot fonts with bpp = 4 - * https://fonts.google.com/specimen/Roboto */ -#define LV_FONT_ROBOTO_12 0 -#define LV_FONT_ROBOTO_16 1 -#define LV_FONT_ROBOTO_22 0 -#define LV_FONT_ROBOTO_28 0 - -/*Pixel perfect monospace font - * http://pelulamu.net/unscii/ */ -#define LV_FONT_UNSCII_8 0 - -/* Optionally declare your custom fonts here. - * You can use these fonts as default font too - * and they will be available globally. E.g. - * #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \ - * LV_FONT_DECLARE(my_font_2) - */ -#define LV_FONT_CUSTOM_DECLARE - -/*Always set a default font from the built-in fonts*/ -#define LV_FONT_DEFAULT &lv_font_roboto_16 - -/* Enable it if you have fonts with a lot of characters. - * The limit depends on the font size, font face and bpp - * but with > 10,000 characters if you see issues probably you need to enable it.*/ -#define LV_FONT_FMT_TXT_LARGE 0 - -/*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_font_user_data_t; - -/*================= - * Text settings - *=================*/ - -/* Select a character encoding for strings. - * Your IDE or editor should have the same character encoding - * - LV_TXT_ENC_UTF8 - * - LV_TXT_ENC_ASCII - * */ -#define LV_TXT_ENC LV_TXT_ENC_UTF8 - - /*Can break (wrap) texts on these chars*/ -#define LV_TXT_BREAK_CHARS " ,.;:-_" - -/*=================== - * LV_OBJ SETTINGS - *==================*/ - -/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_obj_user_data_t; - -/*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/ -#define LV_USE_OBJ_REALIGN 1 - -/* Enable to make the object clickable on a larger area. - * LV_EXT_CLICK_AREA_OFF or 0: Disable this feature - * LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px) - * LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px) - */ -#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_OFF - -/*================== - * LV OBJ X USAGE - *================*/ -/* - * Documentation of the object types: https://docs.littlevgl.com/#Object-types - */ - -/*Arc (dependencies: -)*/ -#define LV_USE_ARC 1 - -/*Bar (dependencies: -)*/ -#define LV_USE_BAR 1 - -/*Button (dependencies: lv_cont*/ -#define LV_USE_BTN 1 -#if LV_USE_BTN != 0 -/*Enable button-state animations - draw a circle on click (dependencies: LV_USE_ANIMATION)*/ -# define LV_BTN_INK_EFFECT 0 -#endif - -/*Button matrix (dependencies: -)*/ -#define LV_USE_BTNM 1 - -/*Calendar (dependencies: -)*/ -#define LV_USE_CALENDAR 1 - -/*Canvas (dependencies: lv_img)*/ -#define LV_USE_CANVAS 1 - -/*Check box (dependencies: lv_btn, lv_label)*/ -#define LV_USE_CB 1 - -/*Chart (dependencies: -)*/ -#define LV_USE_CHART 1 -#if LV_USE_CHART -# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 20 -#endif - -/*Container (dependencies: -*/ -#define LV_USE_CONT 1 - -/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ -#define LV_USE_DDLIST 1 -#if LV_USE_DDLIST != 0 -/*Open and close default animation time [ms] (0: no animation)*/ -# define LV_DDLIST_DEF_ANIM_TIME 200 -#endif - -/*Gauge (dependencies:lv_bar, lv_lmeter)*/ -#define LV_USE_GAUGE 1 - -/*Image (dependencies: lv_label*/ -#define LV_USE_IMG 1 - -/*Image Button (dependencies: lv_btn*/ -#define LV_USE_IMGBTN 1 -#if LV_USE_IMGBTN -/*1: The imgbtn requires left, mid and right parts and the width can be set freely*/ -# define LV_IMGBTN_TILED 0 -#endif - -/*Keyboard (dependencies: lv_btnm)*/ -#define LV_USE_KB 1 - -/*Label (dependencies: -*/ -#define LV_USE_LABEL 1 -#if LV_USE_LABEL != 0 -/*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/ -# define LV_LABEL_DEF_SCROLL_SPEED 25 - -/* Waiting period at beginning/end of animation cycle */ -# define LV_LABEL_WAIT_CHAR_COUNT 3 - -/*Enable selecting text of the label */ -# define LV_LABEL_TEXT_SEL 0 - -/*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/ -# define LV_LABEL_LONG_TXT_HINT 0 -#endif - -/*LED (dependencies: -)*/ -#define LV_USE_LED 1 - -/*Line (dependencies: -*/ -#define LV_USE_LINE 1 - -/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ -#define LV_USE_LIST 1 -#if LV_USE_LIST != 0 -/*Default animation time of focusing to a list element [ms] (0: no animation) */ -# define LV_LIST_DEF_ANIM_TIME 100 -#endif - -/*Line meter (dependencies: *;)*/ -#define LV_USE_LMETER 1 - -/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ -#define LV_USE_MBOX 1 - -/*Page (dependencies: lv_cont)*/ -#define LV_USE_PAGE 1 -#if LV_USE_PAGE != 0 -/*Focus default animation time [ms] (0: no animation)*/ -# define LV_PAGE_DEF_ANIM_TIME 400 -#endif - -/*Preload (dependencies: lv_arc, lv_anim)*/ -#define LV_USE_PRELOAD 1 -#if LV_USE_PRELOAD != 0 -# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/ -# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/ -# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC -#endif - -/*Roller (dependencies: lv_ddlist)*/ -#define LV_USE_ROLLER 1 -#if LV_USE_ROLLER != 0 -/*Focus animation time [ms] (0: no animation)*/ -# define LV_ROLLER_DEF_ANIM_TIME 200 - -/*Number of extra "pages" when the roller is infinite*/ -# define LV_ROLLER_INF_PAGES 7 -#endif - -/*Slider (dependencies: lv_bar)*/ -#define LV_USE_SLIDER 1 - -/*Spinbox (dependencies: lv_ta)*/ -#define LV_USE_SPINBOX 1 - -/*Switch (dependencies: lv_slider)*/ -#define LV_USE_SW 1 - -/*Text area (dependencies: lv_label, lv_page)*/ -#define LV_USE_TA 1 -#if LV_USE_TA != 0 -# define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/ -# define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/ -#endif - -/*Table (dependencies: lv_label)*/ -#define LV_USE_TABLE 1 -#if LV_USE_TABLE -# define LV_TABLE_COL_MAX 12 -#endif - -/*Tab (dependencies: lv_page, lv_btnm)*/ -#define LV_USE_TABVIEW 1 -# if LV_USE_TABVIEW != 0 -/*Time of slide animation [ms] (0: no animation)*/ -# define LV_TABVIEW_DEF_ANIM_TIME 300 -#endif - -/*Tileview (dependencies: lv_page) */ -#define LV_USE_TILEVIEW 1 -#if LV_USE_TILEVIEW -/*Time of slide animation [ms] (0: no animation)*/ -# define LV_TILEVIEW_DEF_ANIM_TIME 300 -#endif - -/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ -#define LV_USE_WIN 1 - -/*================== - * Non-user section - *==================*/ - -#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ -# define _CRT_SECURE_NO_WARNINGS -#endif - -/*--END OF LV_CONF_H--*/ - -/*Be sure every define has a default value*/ -//#include "../lv_conf_checker.h" - -#endif /*LV_CONF_H*/ - -#endif /*End of "Content enable"*/ diff --git a/core/app-framework/wgl/app/wa-inc/lvgl/LICENCE.txt b/core/app-framework/wgl/app/wa-inc/lvgl/LICENCE.txt deleted file mode 100644 index beaef1d26..000000000 --- a/core/app-framework/wgl/app/wa-inc/lvgl/LICENCE.txt +++ /dev/null @@ -1,8 +0,0 @@ -MIT licence -Copyright (c) 2016 Gábor Kiss-Vámosi - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/core/app-framework/wgl/app/wa-inc/lvgl/lv_obj.h b/core/app-framework/wgl/app/wa-inc/lvgl/lv_obj.h deleted file mode 100644 index 5497b0b62..000000000 --- a/core/app-framework/wgl/app/wa-inc/lvgl/lv_obj.h +++ /dev/null @@ -1,1046 +0,0 @@ -/** - * @file lv_obj.h - * - */ - -#ifndef LV_OBJ_H -#define LV_OBJ_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "../../../lv_conf.h" -#endif - -#include -#include -#include "lv_style.h" -#include "../lv_misc/lv_types.h" -#include "../lv_misc/lv_area.h" -#include "../lv_misc/lv_mem.h" -#include "../lv_misc/lv_ll.h" -#include "../lv_misc/lv_color.h" -#include "../lv_misc/lv_log.h" -#include "../lv_hal/lv_hal.h" - -/********************* - * DEFINES - *********************/ - -/*Error check of lv_conf.h*/ -#if LV_HOR_RES_MAX == 0 || LV_VER_RES_MAX == 0 -#error "LittlevGL: LV_HOR_RES_MAX and LV_VER_RES_MAX must be greater than 0" -#endif - -#if LV_ANTIALIAS > 1 -#error "LittlevGL: LV_ANTIALIAS can be only 0 or 1" -#endif - -#define LV_MAX_ANCESTOR_NUM 8 - -#define LV_EXT_CLICK_AREA_OFF 0 -#define LV_EXT_CLICK_AREA_TINY 1 -#define LV_EXT_CLICK_AREA_FULL 2 - -/********************** - * TYPEDEFS - **********************/ - -struct _lv_obj_t; - -/** Design modes */ -enum { - LV_DESIGN_DRAW_MAIN, /* Draw the main portion of the object */ - LV_DESIGN_DRAW_POST, /* Draw extras on the object */ - LV_DESIGN_COVER_CHK, /* Check if the object fully covers the 'mask_p' - area */ -}; -typedef uint8_t lv_design_mode_t; - -/** - * The design callback is used to draw the object on the screen. - * It accepts the object, a mask area, and the mode in which to draw the object. - */ -typedef bool (*lv_design_cb_t)(struct _lv_obj_t *obj, const lv_area_t *mask_p, - lv_design_mode_t mode); - -enum { - LV_EVENT_PRESSED, /* The object has been pressed */ - LV_EVENT_PRESSING, /* The object is being pressed (called continuously - while pressing) */ - LV_EVENT_PRESS_LOST, /* User is still pressing but slid cursor/finger off - of the object */ - LV_EVENT_SHORT_CLICKED, /* User pressed object for a short period of time, - then released it. Not called if dragged. */ - LV_EVENT_LONG_PRESSED, /* Object has been pressed for at least - `LV_INDEV_LONG_PRESS_TIME`. Not called if - dragged. */ - LV_EVENT_LONG_PRESSED_REPEAT, /* Called after `LV_INDEV_LONG_PRESS_TIME` - in every `LV_INDEV_LONG_PRESS_REP_TIME` - ms. Not called if dragged.*/ - LV_EVENT_CLICKED, /* Called on release if not dragged (regardless to long - press) */ - LV_EVENT_RELEASED, /* Called in every cases when the object has been - released */ - LV_EVENT_DRAG_BEGIN, - LV_EVENT_DRAG_END, - LV_EVENT_DRAG_THROW_BEGIN, - LV_EVENT_KEY, - LV_EVENT_FOCUSED, - LV_EVENT_DEFOCUSED, - LV_EVENT_VALUE_CHANGED, /* The object's value has changed (i.e. slider - moved) */ - LV_EVENT_INSERT, - LV_EVENT_REFRESH, - LV_EVENT_APPLY, /* "Ok", "Apply" or similar specific button has clicked */ - LV_EVENT_CANCEL, /* "Close", "Cancel" or similar specific button has - clicked */ - LV_EVENT_DELETE, /* Object is being deleted */ -}; - -typedef uint8_t lv_event_t; /* Type of event being sent to the object. */ - -/** - * @brief Event callback. - * Events are used to notify the user of some action being taken on the object. - * For details, see ::lv_event_t. - */ -typedef void (*lv_event_cb_t)(struct _lv_obj_t *obj, lv_event_t event); - -/** Signals are for use by the object itself or to extend the object's - * functionality. Applications should use ::lv_obj_set_event_cb to be notified - * of events that occur on the object. */ -enum { - /*General signals*/ - LV_SIGNAL_CLEANUP, /* Object is being deleted */ - LV_SIGNAL_CHILD_CHG, /* Child was removed/added */ - LV_SIGNAL_CORD_CHG, /* Object coordinates/size have changed */ - LV_SIGNAL_PARENT_SIZE_CHG, /* Parent's size has changed */ - LV_SIGNAL_STYLE_CHG, /* Object's style has changed */ - LV_SIGNAL_REFR_EXT_DRAW_PAD, /* Object's extra padding has changed */ - LV_SIGNAL_GET_TYPE, /* LittlevGL needs to retrieve the object's type */ - - /*Input device related*/ - LV_SIGNAL_PRESSED, /* The object has been pressed*/ - LV_SIGNAL_PRESSING, /* The object is being pressed (called continuously - while pressing)*/ - LV_SIGNAL_PRESS_LOST, /* User is still pressing but slid cursor/finger off - of the object */ - LV_SIGNAL_RELEASED, /* User pressed object for a short period of time, - then released it. Not called if dragged. */ - LV_SIGNAL_LONG_PRESS, /* Object has been pressed for at least - `LV_INDEV_LONG_PRESS_TIME`. Not called if - dragged.*/ - LV_SIGNAL_LONG_PRESS_REP, /* Called after `LV_INDEV_LONG_PRESS_TIME` in - every `LV_INDEV_LONG_PRESS_REP_TIME` ms. Not - called if dragged.*/ - LV_SIGNAL_DRAG_BEGIN, - LV_SIGNAL_DRAG_END, - /*Group related*/ - LV_SIGNAL_FOCUS, - LV_SIGNAL_DEFOCUS, - LV_SIGNAL_CONTROL, - LV_SIGNAL_GET_EDITABLE, -}; - -typedef uint8_t lv_signal_t; - -typedef lv_res_t (*lv_signal_cb_t)(struct _lv_obj_t *obj, lv_signal_t sign, - void *param); - -/** Object alignment. */ -enum { - LV_ALIGN_CENTER = 0, - LV_ALIGN_IN_TOP_LEFT, - LV_ALIGN_IN_TOP_MID, - LV_ALIGN_IN_TOP_RIGHT, - LV_ALIGN_IN_BOTTOM_LEFT, - LV_ALIGN_IN_BOTTOM_MID, - LV_ALIGN_IN_BOTTOM_RIGHT, - LV_ALIGN_IN_LEFT_MID, - LV_ALIGN_IN_RIGHT_MID, - LV_ALIGN_OUT_TOP_LEFT, - LV_ALIGN_OUT_TOP_MID, - LV_ALIGN_OUT_TOP_RIGHT, - LV_ALIGN_OUT_BOTTOM_LEFT, - LV_ALIGN_OUT_BOTTOM_MID, - LV_ALIGN_OUT_BOTTOM_RIGHT, - LV_ALIGN_OUT_LEFT_TOP, - LV_ALIGN_OUT_LEFT_MID, - LV_ALIGN_OUT_LEFT_BOTTOM, - LV_ALIGN_OUT_RIGHT_TOP, - LV_ALIGN_OUT_RIGHT_MID, - LV_ALIGN_OUT_RIGHT_BOTTOM, -}; -typedef uint8_t lv_align_t; - -#if LV_USE_OBJ_REALIGN -typedef struct { - const struct _lv_obj_t *base; - lv_coord_t xofs; - lv_coord_t yofs; - lv_align_t align; - uint8_t auto_realign : 1; - uint8_t origo_align : 1; /* 1: the origo (center of the object) was - aligned with `lv_obj_align_origo`*/ -} lv_reailgn_t; -#endif - -enum { - LV_DRAG_DIR_HOR = 0x1, /* Object can be dragged horizontally. */ - LV_DRAG_DIR_VER = 0x2, /* Object can be dragged vertically. */ - LV_DRAG_DIR_ALL = 0x3, /* Object can be dragged in all directions. */ -}; - -typedef uint8_t lv_drag_dir_t; - -typedef void lv_obj_t; -typedef void lv_obj_type_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init. the 'lv' library. - */ -void -lv_init(void); - -/*-------------------- - * Create and delete - *-------------------*/ - -/** - * Create a basic object - * @param parent pointer to a parent object. - * If NULL then a screen will be created - * @param copy pointer to a base object, if not NULL then - * the new object will be copied from it - * @return pointer to the new object - */ -lv_obj_t * -lv_obj_create(lv_obj_t *parent, const lv_obj_t *copy); - -/** - * Delete 'obj' and all of its children - * @param obj pointer to an object to delete - * @return LV_RES_INV because the object is deleted - */ -lv_res_t -lv_obj_del(lv_obj_t *obj); - -/** - * Helper function for asynchronously deleting objects. - * Useful for cases where you can't delete an object directly in an - * `LV_EVENT_DELETE` handler (i.e. parent). - * @param obj object to delete - * @see lv_async_call - */ -void -lv_obj_del_async(struct _lv_obj_t *obj); - -/** - * Delete all children of an object - * @param obj pointer to an object - */ -void -lv_obj_clean(lv_obj_t *obj); - -/** - * Mark the object as invalid therefore its current position will be redrawn by - * 'lv_refr_task' - * @param obj pointer to an object - */ -void -lv_obj_invalidate(const lv_obj_t *obj); - -/*===================== - * Setter functions - *====================*/ - -/*-------------------- - * Parent/children set - *--------------------*/ - -/** - * Set a new parent for an object. Its relative position will be the same. - * @param obj pointer to an object. Can't be a screen. - * @param parent pointer to the new parent object. (Can't be NULL) - */ -void -lv_obj_set_parent(lv_obj_t *obj, lv_obj_t *parent); - -/** - * Move and object to the foreground - * @param obj pointer to an object - */ -void -lv_obj_move_foreground(lv_obj_t *obj); - -/** - * Move and object to the background - * @param obj pointer to an object - */ -void -lv_obj_move_background(lv_obj_t *obj); - -/*-------------------- - * Coordinate set - * ------------------*/ - -/** - * Set relative the position of an object (relative to the parent) - * @param obj pointer to an object - * @param x new distance from the left side of the parent - * @param y new distance from the top of the parent - */ -void -lv_obj_set_pos(lv_obj_t *obj, lv_coord_t x, lv_coord_t y); - -/** - * Set the x coordinate of a object - * @param obj pointer to an object - * @param x new distance from the left side from the parent - */ -void -lv_obj_set_x(lv_obj_t *obj, lv_coord_t x); - -/** - * Set the y coordinate of a object - * @param obj pointer to an object - * @param y new distance from the top of the parent - */ -void -lv_obj_set_y(lv_obj_t *obj, lv_coord_t y); - -/** - * Set the size of an object - * @param obj pointer to an object - * @param w new width - * @param h new height - */ -void -lv_obj_set_size(lv_obj_t *obj, lv_coord_t w, lv_coord_t h); - -/** - * Set the width of an object - * @param obj pointer to an object - * @param w new width - */ -void -lv_obj_set_width(lv_obj_t *obj, lv_coord_t w); - -/** - * Set the height of an object - * @param obj pointer to an object - * @param h new height - */ -void -lv_obj_set_height(lv_obj_t *obj, lv_coord_t h); - -/** - * Align an object to an other object. - * @param obj pointer to an object to align - * @param base pointer to an object (if NULL the parent is used). 'obj' will be - * aligned to it. - * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment - */ -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); - -/** - * Align an object to an other object. - * @param obj pointer to an object to align - * @param base pointer to an object (if NULL the parent is used). 'obj' will be - * aligned to it. - * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment - */ -void -lv_obj_align_origo(lv_obj_t *obj, const lv_obj_t *base, lv_align_t align, - lv_coord_t x_mod, lv_coord_t y_mod); - -/** - * Realign the object based on the last `lv_obj_align` parameters. - * @param obj pointer to an object - */ -void -lv_obj_realign(lv_obj_t *obj); - -/** - * Enable the automatic realign of the object when its size has changed based on - * the last `lv_obj_align` parameters. - * @param obj pointer to an object - * @param en true: enable auto realign; false: disable auto realign - */ -void -lv_obj_set_auto_realign(lv_obj_t *obj, bool en); - -/** - * Set the size of an extended clickable area - * @param obj pointer to an object - * @param left extended clickable are on the left [px] - * @param right extended clickable are on the right [px] - * @param top extended clickable are on the top [px] - * @param bottom extended clickable are on the bottom [px] - */ -void -lv_obj_set_ext_click_area(lv_obj_t *obj, lv_coord_t left, lv_coord_t right, - lv_coord_t top, lv_coord_t bottom); - -/*--------------------- - * Appearance set - *--------------------*/ - -/** - * Set a new style for an object - * @param obj pointer to an object - * @param style_p pointer to the new style - */ -void -lv_obj_set_style(lv_obj_t *obj, const lv_style_t *style); - -/** - * Notify an object about its style is modified - * @param obj pointer to an object - */ -void -lv_obj_refresh_style(lv_obj_t *obj); - -/** - * Notify all object if a style is modified - * @param style pointer to a style. Only the objects with this style will be - * notified (NULL to notify all objects) - */ -void -lv_obj_report_style_mod(lv_style_t *style); - -/*----------------- - * Attribute set - *----------------*/ - -/** - * Hide an object. It won't be visible and clickable. - * @param obj pointer to an object - * @param en true: hide the object - */ -void -lv_obj_set_hidden(lv_obj_t *obj, bool en); - -/** - * Enable or disable the clicking of an object - * @param obj pointer to an object - * @param en true: make the object clickable - */ -void -lv_obj_set_click(lv_obj_t *obj, bool en); - -/** - * Enable to bring this object to the foreground if it - * or any of its children is clicked - * @param obj pointer to an object - * @param en true: enable the auto top feature - */ -void -lv_obj_set_top(lv_obj_t *obj, bool en); - -/** - * Enable the dragging of an object - * @param obj pointer to an object - * @param en true: make the object dragable - */ -void -lv_obj_set_drag(lv_obj_t *obj, bool en); - -/** - * Set the directions an object can be dragged in - * @param obj pointer to an object - * @param drag_dir bitwise OR of allowed drag directions - */ -void -lv_obj_set_drag_dir(lv_obj_t *obj, lv_drag_dir_t drag_dir); - -/** - * Enable the throwing of an object after is is dragged - * @param obj pointer to an object - * @param en true: enable the drag throw - */ -void -lv_obj_set_drag_throw(lv_obj_t *obj, bool en); - -/** - * Enable to use parent for drag related operations. - * If trying to drag the object the parent will be moved instead - * @param obj pointer to an object - * @param en true: enable the 'drag parent' for the object - */ -void -lv_obj_set_drag_parent(lv_obj_t *obj, bool en); - -/** - * Propagate the events to the parent too - * @param obj pointer to an object - * @param en true: enable the event propagation - */ -void -lv_obj_set_parent_event(lv_obj_t *obj, bool en); - -/** - * Set the opa scale enable parameter (required to set opa_scale with - * `lv_obj_set_opa_scale()`) - * @param obj pointer to an object - * @param en true: opa scaling is enabled for this object and all children; - * false: no opa scaling - */ -void -lv_obj_set_opa_scale_enable(lv_obj_t *obj, bool en); - -/** - * Set the opa scale of an object. - * The opacity of this object and all it's children will be scaled down with - * this factor. `lv_obj_set_opa_scale_enable(obj, true)` needs to be called to - * enable it. (not for all children just for the parent where to start the opa - * scaling) - * @param obj pointer to an object - * @param opa_scale a factor to scale down opacity [0..255] - */ -void -lv_obj_set_opa_scale(lv_obj_t *obj, lv_opa_t opa_scale); - -/** - * Set a bit or bits in the protect filed - * @param obj pointer to an object - * @param prot 'OR'-ed values from `lv_protect_t` - */ -void -lv_obj_set_protect(lv_obj_t *obj, uint8_t prot); - -/** - * Clear a bit or bits in the protect filed - * @param obj pointer to an object - * @param prot 'OR'-ed values from `lv_protect_t` - */ -void -lv_obj_clear_protect(lv_obj_t *obj, uint8_t prot); - -/** - * Set a an event handler function for an object. - * Used by the user to react on event which happens with the object. - * @param obj pointer to an object - * @param event_cb the new event function - */ -void -lv_obj_set_event_cb(lv_obj_t *obj, lv_event_cb_t event_cb); - -/** - * Send an event to the object - * @param obj pointer to an object - * @param event the type of the event from `lv_event_t`. - * @param data arbitrary data depending on the object type and the event. - * (Usually `NULL`) - * @return LV_RES_OK: `obj` was not deleted in the event; LV_RES_INV: `obj` - * was deleted in the event - */ -lv_res_t -lv_event_send(lv_obj_t *obj, lv_event_t event, const void *data); - -/** - * Call an event function with an object, event, and data. - * @param event_xcb an event callback function. If `NULL` `LV_RES_OK` will - * return without any actions. (the 'x' in the argument name indicates - * that its not a fully generic function because it not follows the - * `func_name(object, callback, ...)` convention) - * @param obj pointer to an object to associate with the event (can be `NULL` - * to simply call the `event_cb`) - * @param event an event - * @param data pointer to a custom data - * @return LV_RES_OK: `obj` was not deleted in the event; LV_RES_INV: `obj` - * was deleted in the event - */ -lv_res_t -lv_event_send_func(lv_event_cb_t event_xcb, lv_obj_t *obj, lv_event_t event, - const void *data); - -/** - * Get the `data` parameter of the current event - * @return the `data` parameter - */ -const void * -lv_event_get_data(void); - -/** - * Set the a signal function of an object. Used internally by the library. - * Always call the previous signal function in the new. - * @param obj pointer to an object - * @param signal_cb the new signal function - */ -void -lv_obj_set_signal_cb(lv_obj_t *obj, lv_signal_cb_t signal_cb); - -/** - * Send an event to the object - * @param obj pointer to an object - * @param event the type of the event from `lv_event_t`. - */ -void -lv_signal_send(lv_obj_t *obj, lv_signal_t signal, void *param); - -/** - * Set a new design function for an object - * @param obj pointer to an object - * @param design_cb the new design function - */ -void -lv_obj_set_design_cb(lv_obj_t *obj, lv_design_cb_t design_cb); - -/*---------------- - * Other set - *--------------*/ - -/** - * Allocate a new ext. data for an object - * @param obj pointer to an object - * @param ext_size the size of the new ext. data - * @return pointer to the allocated ext - */ -void * -lv_obj_allocate_ext_attr(lv_obj_t *obj, uint16_t ext_size); - -/** - * Send a 'LV_SIGNAL_REFR_EXT_SIZE' signal to the object - * @param obj pointer to an object - */ -void -lv_obj_refresh_ext_draw_pad(lv_obj_t *obj); - -/*======================= - * Getter functions - *======================*/ - -/** - * Return with the screen of an object - * @param obj pointer to an object - * @return pointer to a screen - */ -lv_obj_t * -lv_obj_get_screen(const lv_obj_t *obj); - -/** - * Get the display of an object - * @param scr pointer to an object - * @return pointer the object's display - */ -lv_disp_t * -lv_obj_get_disp(const lv_obj_t *obj); - -/*--------------------- - * Parent/children get - *--------------------*/ - -/** - * Returns with the parent of an object - * @param obj pointer to an object - * @return pointer to the parent of 'obj' - */ -lv_obj_t * -lv_obj_get_parent(const lv_obj_t *obj); - -/** - * Iterate through the children of an object (start from the "youngest, lastly - * created") - * @param obj pointer to an object - * @param child NULL at first call to get the next children - * and the previous return value later - * @return the child after 'act_child' or NULL if no more child - */ -lv_obj_t * -lv_obj_get_child(const lv_obj_t *obj, const lv_obj_t *child); - -/** - * Iterate through the children of an object (start from the "oldest", firstly - * created) - * @param obj pointer to an object - * @param child NULL at first call to get the next children - * and the previous return value later - * @return the child after 'act_child' or NULL if no more child - */ -lv_obj_t * -lv_obj_get_child_back(const lv_obj_t *obj, const lv_obj_t *child); - -/** - * Count the children of an object (only children directly on 'obj') - * @param obj pointer to an object - * @return children number of 'obj' - */ -uint16_t -lv_obj_count_children(const lv_obj_t *obj); - -/** Recursively count the children of an object - * @param obj pointer to an object - * @return children number of 'obj' - */ -uint16_t -lv_obj_count_children_recursive(const lv_obj_t *obj); - -/*--------------------- - * Coordinate get - *--------------------*/ - -/** - * Copy the coordinates of an object to an area - * @param obj pointer to an object - * @param cords_p pointer to an area to store the coordinates - */ -void -lv_obj_get_coords(const lv_obj_t *obj, lv_area_t *cords_p); - -/** - * Reduce area retried by `lv_obj_get_coords()` the get graphically usable area - * of an object. (Without the size of the border or other extra graphical - * elements) - * @param coords_p store the result area here - */ -void -lv_obj_get_inner_coords(const lv_obj_t *obj, lv_area_t *coords_p); - -/** - * Get the x coordinate of object - * @param obj pointer to an object - * @return distance of 'obj' from the left side of its parent - */ -lv_coord_t -lv_obj_get_x(const lv_obj_t *obj); - -/** - * Get the y coordinate of object - * @param obj pointer to an object - * @return distance of 'obj' from the top of its parent - */ -lv_coord_t -lv_obj_get_y(const lv_obj_t *obj); - -/** - * Get the width of an object - * @param obj pointer to an object - * @return the width - */ -lv_coord_t -lv_obj_get_width(const lv_obj_t *obj); - -/** - * Get the height of an object - * @param obj pointer to an object - * @return the height - */ -lv_coord_t -lv_obj_get_height(const lv_obj_t *obj); - -/** - * Get that width reduced by the left and right padding. - * @param obj pointer to an object - * @return the width which still fits into the container - */ -lv_coord_t -lv_obj_get_width_fit(lv_obj_t *obj); - -/** - * Get that height reduced by the top an bottom padding. - * @param obj pointer to an object - * @return the height which still fits into the container - */ -lv_coord_t -lv_obj_get_height_fit(lv_obj_t *obj); - -/** - * Get the automatic realign property of the object. - * @param obj pointer to an object - * @return true: auto realign is enabled; false: auto realign is disabled - */ -bool -lv_obj_get_auto_realign(lv_obj_t *obj); - -/** - * Get the left padding of extended clickable area - * @param obj pointer to an object - * @return the extended left padding - */ -lv_coord_t -lv_obj_get_ext_click_pad_left(const lv_obj_t *obj); - -/** - * Get the right padding of extended clickable area - * @param obj pointer to an object - * @return the extended right padding - */ -lv_coord_t -lv_obj_get_ext_click_pad_right(const lv_obj_t *obj); - -/** - * Get the top padding of extended clickable area - * @param obj pointer to an object - * @return the extended top padding - */ -lv_coord_t -lv_obj_get_ext_click_pad_top(const lv_obj_t *obj); - -/** - * Get the bottom padding of extended clickable area - * @param obj pointer to an object - * @return the extended bottom padding - */ -lv_coord_t -lv_obj_get_ext_click_pad_bottom(const lv_obj_t *obj); - -/** - * Get the extended size attribute of an object - * @param obj pointer to an object - * @return the extended size attribute - */ -lv_coord_t -lv_obj_get_ext_draw_pad(const lv_obj_t *obj); - -/*----------------- - * Appearance get - *---------------*/ - -/** - * Get the style pointer of an object (if NULL get style of the parent) - * @param obj pointer to an object - * @return pointer to a style - */ -const lv_style_t * -lv_obj_get_style(const lv_obj_t *obj); - -/*----------------- - * Attribute get - *----------------*/ - -/** - * Get the hidden attribute of an object - * @param obj pointer to an object - * @return true: the object is hidden - */ -bool -lv_obj_get_hidden(const lv_obj_t *obj); - -/** - * Get the click enable attribute of an object - * @param obj pointer to an object - * @return true: the object is clickable - */ -bool -lv_obj_get_click(const lv_obj_t *obj); - -/** - * Get the top enable attribute of an object - * @param obj pointer to an object - * @return true: the auto top feature is enabled - */ -bool -lv_obj_get_top(const lv_obj_t *obj); - -/** - * Get the drag enable attribute of an object - * @param obj pointer to an object - * @return true: the object is dragable - */ -bool -lv_obj_get_drag(const lv_obj_t *obj); - -/** - * Get the directions an object can be dragged - * @param obj pointer to an object - * @return bitwise OR of allowed directions an object can be dragged in - */ -lv_drag_dir_t -lv_obj_get_drag_dir(const lv_obj_t *obj); - -/** - * Get the drag throw enable attribute of an object - * @param obj pointer to an object - * @return true: drag throw is enabled - */ -bool -lv_obj_get_drag_throw(const lv_obj_t *obj); - -/** - * Get the drag parent attribute of an object - * @param obj pointer to an object - * @return true: drag parent is enabled - */ -bool -lv_obj_get_drag_parent(const lv_obj_t *obj); - -/** - * Get the drag parent attribute of an object - * @param obj pointer to an object - * @return true: drag parent is enabled - */ -bool -lv_obj_get_parent_event(const lv_obj_t *obj); - -/** - * Get the opa scale enable parameter - * @param obj pointer to an object - * @return true: opa scaling is enabled for this object and all children; false: - * no opa scaling - */ -lv_opa_t -lv_obj_get_opa_scale_enable(const lv_obj_t *obj); - -/** - * Get the opa scale parameter of an object - * @param obj pointer to an object - * @return opa scale [0..255] - */ -lv_opa_t -lv_obj_get_opa_scale(const lv_obj_t *obj); - -/** - * Get the protect field of an object - * @param obj pointer to an object - * @return protect field ('OR'ed values of `lv_protect_t`) - */ -uint8_t -lv_obj_get_protect(const lv_obj_t *obj); - -/** - * Check at least one bit of a given protect bitfield is set - * @param obj pointer to an object - * @param prot protect bits to test ('OR'ed values of `lv_protect_t`) - * @return false: none of the given bits are set, true: at least one bit is set - */ -bool -lv_obj_is_protected(const lv_obj_t *obj, uint8_t prot); - -/** - * Get the signal function of an object - * @param obj pointer to an object - * @return the signal function - */ -lv_signal_cb_t -lv_obj_get_signal_cb(const lv_obj_t *obj); - -/** - * Get the design function of an object - * @param obj pointer to an object - * @return the design function - */ -lv_design_cb_t -lv_obj_get_design_cb(const lv_obj_t *obj); - -/** - * Get the event function of an object - * @param obj pointer to an object - * @return the event function - */ -lv_event_cb_t -lv_obj_get_event_cb(const lv_obj_t *obj); - -/*------------------ - * Other get - *-----------------*/ - -/** - * Get the ext pointer - * @param obj pointer to an object - * @return the ext pointer but not the dynamic version - * Use it as ext->data1, and NOT da(ext)->data1 - */ -void * -lv_obj_get_ext_attr(const lv_obj_t *obj); - -/** - * Get object's and its ancestors type. Put their name in `type_buf` starting - * with the current type. E.g. buf.type[0]="lv_btn", buf.type[1]="lv_cont", - * buf.type[2]="lv_obj" - * @param obj pointer to an object which type should be get - * @param buf pointer to an `lv_obj_type_t` buffer to store the types - */ -void -lv_obj_get_type(lv_obj_t *obj, lv_obj_type_t *buf); - -#if LV_USE_USER_DATA -/** - * Get the object's user data - * @param obj pointer to an object - * @return user data - */ -lv_obj_user_data_t -lv_obj_get_user_data(lv_obj_t *obj); - -/** - * Get a pointer to the object's user data - * @param obj pointer to an object - * @return pointer to the user data - */ -lv_obj_user_data_t * -lv_obj_get_user_data_ptr(lv_obj_t *obj); - -/** - * Set the object's user data. The data will be copied. - * @param obj pointer to an object - * @param data user data - */ -void -lv_obj_set_user_data(lv_obj_t *obj, lv_obj_user_data_t data); - -#endif - -#if LV_USE_GROUP -/** - * Get the group of the object - * @param obj pointer to an object - * @return the pointer to group of the object - */ -void * -lv_obj_get_group(const lv_obj_t *obj); - -/** - * Tell whether the object is the focused object of a group or not. - * @param obj pointer to an object - * @return true: the object is focused, - * false: the object is not focused or not in a group - */ -bool -lv_obj_is_focused(const lv_obj_t *obj); - -#endif - -/********************** - * MACROS - **********************/ - -/** - * Helps to quickly declare an event callback function. - * Will be expanded to: `void (lv_obj_t * obj, lv_event_t e)` - * - * Examples: - * static LV_EVENT_CB_DECLARE(my_event1); //Protoype declaration - * - * static LV_EVENT_CB_DECLARE(my_event1) - * { - * if(e == LV_EVENT_CLICKED) { - * lv_obj_set_hidden(obj ,true); - * } - * } - */ -#define LV_EVENT_CB_DECLARE(name) void name(lv_obj_t *obj, lv_event_t e) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_OBJ_H*/ diff --git a/core/app-framework/wgl/app/wa-inc/lvgl/lvgl.h b/core/app-framework/wgl/app/wa-inc/lvgl/lvgl.h deleted file mode 100644 index 7c4c7b2fe..000000000 --- a/core/app-framework/wgl/app/wa-inc/lvgl/lvgl.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef WAMR_GRAPHIC_LIBRARY_LVGL_COMPATIBLE_H -#define WAMR_GRAPHIC_LIBRARY_LVGL_COMPATIBLE_H - -#ifdef __cplusplus -extern "C" { -#endif - -//#include "bi-inc/wgl_shared_utils.h" /* shared types between app and native */ -/* -#include "lvgl-compatible/lv_types.h" -#include "lvgl-compatible/lv_obj.h" -#include "lvgl-compatible/lv_btn.h" -#include "lvgl-compatible/lv_cb.h" -#include "lvgl-compatible/lv_label.h" -#include "lvgl-compatible/lv_list.h" -*/ - -#include "src/lv_version.h" - -#include "src/lv_misc/lv_log.h" -#include "src/lv_misc/lv_task.h" -#include "src/lv_misc/lv_math.h" -//#include "src/lv_misc/lv_async.h" - -//#include "src/lv_hal/lv_hal.h" - -#include "src/lv_core/lv_obj.h" -#include "src/lv_core/lv_group.h" - -#include "src/lv_core/lv_refr.h" -#include "src/lv_core/lv_disp.h" - -#include "src/lv_themes/lv_theme.h" - -#include "src/lv_font/lv_font.h" -#include "src/lv_font/lv_font_fmt_txt.h" - -#include "src/lv_objx/lv_btn.h" -#include "src/lv_objx/lv_imgbtn.h" -#include "src/lv_objx/lv_img.h" -#include "src/lv_objx/lv_label.h" -#include "src/lv_objx/lv_line.h" -#include "src/lv_objx/lv_page.h" -#include "src/lv_objx/lv_cont.h" -#include "src/lv_objx/lv_list.h" -#include "src/lv_objx/lv_chart.h" -#include "src/lv_objx/lv_table.h" -#include "src/lv_objx/lv_cb.h" -#include "src/lv_objx/lv_bar.h" -#include "src/lv_objx/lv_slider.h" -#include "src/lv_objx/lv_led.h" -#include "src/lv_objx/lv_btnm.h" -#include "src/lv_objx/lv_kb.h" -#include "src/lv_objx/lv_ddlist.h" -#include "src/lv_objx/lv_roller.h" -#include "src/lv_objx/lv_ta.h" -#include "src/lv_objx/lv_canvas.h" -#include "src/lv_objx/lv_win.h" -#include "src/lv_objx/lv_tabview.h" -#include "src/lv_objx/lv_tileview.h" -#include "src/lv_objx/lv_mbox.h" -#include "src/lv_objx/lv_gauge.h" -#include "src/lv_objx/lv_lmeter.h" -#include "src/lv_objx/lv_sw.h" -#include "src/lv_objx/lv_kb.h" -#include "src/lv_objx/lv_arc.h" -#include "src/lv_objx/lv_preload.h" -#include "src/lv_objx/lv_calendar.h" -#include "src/lv_objx/lv_spinbox.h" - -#include "src/lv_draw/lv_img_cache.h" - -#ifdef __cplusplus -} -#endif - -#endif /* WAMR_GRAPHIC_LIBRARY_LVGL_COMPATIBLE_H */ diff --git a/core/app-framework/wgl/app/wa-inc/lvgl/test.c b/core/app-framework/wgl/app/wa-inc/lvgl/test.c deleted file mode 100644 index 2262aa551..000000000 --- a/core/app-framework/wgl/app/wa-inc/lvgl/test.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "lvgl.h" - -int -main() - -{ - - return 0; -} diff --git a/core/app-framework/wgl/app/wasm_app.cmake b/core/app-framework/wgl/app/wasm_app.cmake deleted file mode 100644 index f01be9ff6..000000000 --- a/core/app-framework/wgl/app/wasm_app.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_APP_GUI_DIR ${CMAKE_CURRENT_LIST_DIR}) - -set (DEPS_DIR ${WASM_APP_GUI_DIR}/../../../deps) - -if (NOT EXISTS "${DEPS_DIR}/lvgl") - message (FATAL_ERROR "Can not find third party dependency: ${DEPS_DIR}/lvgl") -endif () - -include_directories(${WASM_APP_GUI_DIR} - ${DEPS_DIR} - ${DEPS_DIR}/lvgl - ${DEPS_DIR}/lvgl/src) - -file (GLOB_RECURSE source_all ${WASM_APP_GUI_DIR}/src/*.c) - -set (WASM_APP_CURRENT_SOURCE ${source_all}) diff --git a/core/app-framework/wgl/native/gui_native_api.h b/core/app-framework/wgl/native/gui_native_api.h deleted file mode 100644 index ee91b0eaa..000000000 --- a/core/app-framework/wgl/native/gui_native_api.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _GUI_API_H_ -#define _GUI_API_H_ - -#include "bh_platform.h" -#include "wasm_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * gui interfaces - */ - -void -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); - -void -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); - -void -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_ */ diff --git a/core/app-framework/wgl/native/wamr_gui.inl b/core/app-framework/wgl/native/wamr_gui.inl deleted file mode 100644 index c7855b17b..000000000 --- a/core/app-framework/wgl/native/wamr_gui.inl +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -/* button */ -EXPORT_WASM_API_WITH_SIG(wasm_btn_native_call, "(i*i)"), - -/* obj */ -EXPORT_WASM_API_WITH_SIG(wasm_obj_native_call, "(i*i)"), - -/* label */ -EXPORT_WASM_API_WITH_SIG(wasm_label_native_call, "(i*i)"), - -/* cont */ -//EXPORT_WASM_API_WITH_SIG(wasm_cont_native_call, "(i*i)"), - -/* page */ -//EXPORT_WASM_API_WITH_SIG(wasm_page_native_call, "(i*i)"), - -/* list */ -EXPORT_WASM_API_WITH_SIG(wasm_list_native_call, "(i*i)"), - -/* drop down list */ -//EXPORT_WASM_API_WITH_SIG(wasm_ddlist_native_call, "(i*i)"), - -/* check box */ -EXPORT_WASM_API_WITH_SIG(wasm_cb_native_call, "(i*i)"), diff --git a/core/app-framework/wgl/native/wasm_lib.cmake b/core/app-framework/wgl/native/wasm_lib.cmake deleted file mode 100644 index b452fb114..000000000 --- a/core/app-framework/wgl/native/wasm_lib.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (WASM_LIB_GUI_DIR ${CMAKE_CURRENT_LIST_DIR}) - -set (DEPS_DIR ${WASM_LIB_GUI_DIR}/../../../deps) - -add_definitions(-DLV_CONF_INCLUDE_SIMPLE) -add_definitions (-DAPP_FRAMEWORK_WGL) - -include_directories(${WASM_LIB_GUI_DIR} - ${DEPS_DIR} - ${DEPS_DIR}/lvgl - ${DEPS_DIR}/lvgl/src) - -file (GLOB_RECURSE lvgl_source ${DEPS_DIR}/lvgl/*.c) -file (GLOB_RECURSE wrapper_source ${WASM_LIB_GUI_DIR}/*.c) - -set (WASM_APP_LIB_CURRENT_SOURCE ${wrapper_source} ${lvgl_source}) diff --git a/core/app-framework/wgl/native/wgl.h b/core/app-framework/wgl/native/wgl.h deleted file mode 100644 index ad5843115..000000000 --- a/core/app-framework/wgl/native/wgl.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef WAMR_GRAPHIC_LIBRARY_H -#define WAMR_GRAPHIC_LIBRARY_H - -#ifdef __cplusplus -extern "C" { -#endif - -void -wgl_init(void); -void -wgl_exit(void); - -#ifdef __cplusplus -} -#endif - -#endif /* WAMR_GRAPHIC_LIBRARY_H */ diff --git a/core/app-framework/wgl/native/wgl_btn_wrapper.c b/core/app-framework/wgl/native/wgl_btn_wrapper.c deleted file mode 100644 index 4c3a23239..000000000 --- a/core/app-framework/wgl/native/wgl_btn_wrapper.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "native_interface.h" -#include "lvgl.h" -#include "module_wasm_app.h" -#include "wgl_native_utils.h" - -/* ------------------------------------------------------------------------- - * Button widget native function wrappers - * -------------------------------------------------------------------------*/ -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_create_wrapper) -{ - int32 res; - wgl_native_return_type(int32); - wgl_native_get_arg(uint32, par_obj_id); - 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); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_toggle_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, btn); - wgl_native_get_arg(bool, tgl); - - (void)exec_env; - lv_btn_set_toggle(btn, tgl); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_state_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, btn); - wgl_native_get_arg(lv_btn_state_t, state); - - (void)exec_env; - lv_btn_set_state(btn, state); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_in_time_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, btn); - wgl_native_get_arg(uint16_t, time); - - (void)exec_env; - lv_btn_set_ink_in_time(btn, time); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_out_time_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, btn); - wgl_native_get_arg(uint16_t, time); - - (void)exec_env; - lv_btn_set_ink_out_time(btn, time); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_wait_time_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, btn); - wgl_native_get_arg(uint16_t, time); - - (void)exec_env; - lv_btn_set_ink_wait_time(btn, time); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_in_time_wrapper) -{ - uint16_t res; - wgl_native_return_type(uint16_t); - wgl_native_get_arg(lv_obj_t *, btn); - - (void)exec_env; - res = lv_btn_get_ink_in_time(btn); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_out_time_wrapper) -{ - uint16_t res; - wgl_native_return_type(uint16_t); - wgl_native_get_arg(lv_obj_t *, btn); - - (void)exec_env; - res = lv_btn_get_ink_out_time(btn); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_wait_time_wrapper) -{ - uint16_t res; - wgl_native_return_type(uint16_t); - wgl_native_get_arg(lv_obj_t *, btn); - - (void)exec_env; - res = lv_btn_get_ink_wait_time(btn); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_state_wrapper) -{ - lv_btn_state_t res; - wgl_native_return_type(lv_btn_state_t); - wgl_native_get_arg(lv_obj_t *, btn); - - (void)exec_env; - res = lv_btn_get_state(btn); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_toggle_wrapper) -{ - bool res; - wgl_native_return_type(bool); - wgl_native_get_arg(lv_obj_t *, btn); - - (void)exec_env; - res = lv_btn_get_toggle(btn); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_btn_toggle_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, btn); - - (void)exec_env; - 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 }, -}; -/* 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) -{ - uint32 size = sizeof(btn_native_func_defs) / sizeof(WGLNativeFuncDef); - - wgl_native_func_call(exec_env, btn_native_func_defs, size, func_id, argv, - argc); -} diff --git a/core/app-framework/wgl/native/wgl_cb_wrapper.c b/core/app-framework/wgl/native/wgl_cb_wrapper.c deleted file mode 100644 index 51510b997..000000000 --- a/core/app-framework/wgl/native/wgl_cb_wrapper.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "lvgl.h" -#include "wasm_export.h" -#include "native_interface.h" -#include "module_wasm_app.h" -#include "wgl_native_utils.h" - -/* ------------------------------------------------------------------------- - * Label widget native function wrappers - * -------------------------------------------------------------------------*/ -DEFINE_WGL_NATIVE_WRAPPER(lv_cb_create_wrapper) -{ - int32 res; - wgl_native_return_type(int32); - wgl_native_get_arg(uint32, par_obj_id); - 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); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_cb_set_text_wrapper) -{ - char *text; - wgl_native_get_arg(lv_obj_t *, cb); - wgl_native_get_arg(uint32, text_offset); - wgl_native_get_arg(uint32, text_len); - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (!validate_app_addr(text_offset, text_len) - || !(text = addr_app_to_native(text_offset))) - return; - - lv_cb_set_text(cb, text); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_cb_set_static_text_wrapper) -{ - char *text; - wgl_native_get_arg(lv_obj_t *, cb); - wgl_native_get_arg(uint32, text_offset); - wgl_native_get_arg(uint32, text_len); - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (!validate_app_addr(text_offset, text_len) - || !(text = addr_app_to_native(text_offset))) - return; - - lv_cb_set_static_text(cb, text); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_length_wrapper) -{ - const char *text; - wgl_native_return_type(int32); - wgl_native_get_arg(lv_obj_t *, cb); - - (void)exec_env; - - text = lv_cb_get_text(cb); - wgl_native_set_return(text ? strlen(text) : 0); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_wrapper) -{ - const char *text; - char *buffer; - wgl_native_return_type(uint32); - wgl_native_get_arg(lv_obj_t *, cb); - wgl_native_get_arg(uint32, buffer_offset); - wgl_native_get_arg(int, buffer_len); - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (!validate_app_addr(buffer_offset, buffer_len) - || !(buffer = addr_app_to_native(buffer_offset))) - return; - - if ((text = lv_cb_get_text(cb))) { - strncpy(buffer, text, buffer_len - 1); - buffer[buffer_len - 1] = '\0'; - } - - wgl_native_set_return(buffer_offset); -} - -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 }, -}; - -/*************** Native Interface to Wasm App ***********/ -void -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, - argc); -} diff --git a/core/app-framework/wgl/native/wgl_cont_wrapper.c b/core/app-framework/wgl/native/wgl_cont_wrapper.c deleted file mode 100644 index 70eeb0f48..000000000 --- a/core/app-framework/wgl/native/wgl_cont_wrapper.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "lvgl.h" -#include "module_wasm_app.h" diff --git a/core/app-framework/wgl/native/wgl_label_wrapper.c b/core/app-framework/wgl/native/wgl_label_wrapper.c deleted file mode 100644 index dbdefec14..000000000 --- a/core/app-framework/wgl/native/wgl_label_wrapper.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "lvgl.h" -#include "wasm_export.h" -#include "native_interface.h" -#include "module_wasm_app.h" -#include "wgl_native_utils.h" - -/* ------------------------------------------------------------------------- - * Label widget native function wrappers - * -------------------------------------------------------------------------*/ -DEFINE_WGL_NATIVE_WRAPPER(lv_label_create_wrapper) -{ - int32 res; - wgl_native_return_type(int32); - wgl_native_get_arg(uint32, par_obj_id); - 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); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_label_set_text_wrapper) -{ - char *text; - wgl_native_get_arg(lv_obj_t *, label); - wgl_native_get_arg(uint32, text_offset); - wgl_native_get_arg(uint32, text_len); - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (!validate_app_addr(text_offset, text_len) - || !(text = addr_app_to_native(text_offset))) - return; - - lv_label_set_text(label, text); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_label_get_text_length_wrapper) -{ - wgl_native_return_type(int32); - wgl_native_get_arg(lv_obj_t *, label); - const char *text; - - (void)exec_env; - - text = lv_label_get_text(label); - wgl_native_set_return(text ? strlen(text) : 0); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_label_get_text_wrapper) -{ - const char *text; - char *buffer; - wgl_native_return_type(uint32); - wgl_native_get_arg(lv_obj_t *, label); - wgl_native_get_arg(uint32, buffer_offset); - wgl_native_get_arg(int, buffer_len); - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (!validate_app_addr(buffer_offset, buffer_len) - || !(buffer = addr_app_to_native(buffer_offset))) - return; - - if ((text = lv_label_get_text(label))) { - strncpy(buffer, text, buffer_len - 1); - buffer[buffer_len - 1] = '\0'; - } - - 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 }, -}; -/* 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) -{ - uint32 size = sizeof(label_native_func_defs) / sizeof(WGLNativeFuncDef); - - wgl_native_func_call(exec_env, label_native_func_defs, size, func_id, argv, - argc); -} diff --git a/core/app-framework/wgl/native/wgl_list_wrapper.c b/core/app-framework/wgl/native/wgl_list_wrapper.c deleted file mode 100644 index c77f44930..000000000 --- a/core/app-framework/wgl/native/wgl_list_wrapper.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "native_interface.h" -#include "lvgl.h" -#include "module_wasm_app.h" -#include "wgl_native_utils.h" -#include "bh_assert.h" - -/* ------------------------------------------------------------------------- - * List widget native function wrappers - * -------------------------------------------------------------------------*/ -DEFINE_WGL_NATIVE_WRAPPER(lv_list_create_wrapper) -{ - int32 res; - wgl_native_return_type(int32); - wgl_native_get_arg(uint32, par_obj_id); - 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); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_list_add_btn_wrapper) -{ - wgl_native_return_type(int32); - wgl_native_get_arg(lv_obj_t *, list); - wgl_native_get_arg(uint32, text_offset); - wgl_native_get_arg(uint32, text_len); - uint32 btn_obj_id; - lv_obj_t *btn; - uint32 mod_id; - char *text; - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (!validate_app_addr(text_offset, text_len) - || !(text = addr_app_to_native(text_offset))) - return; - - if (!(btn = lv_list_add_btn(list, NULL, text))) { - wasm_runtime_set_exception(module_inst, "add button to list fail."); - return; - } - - mod_id = app_manager_get_module_id(Module_WASM_App, module_inst); - 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."); - return; - } - - wgl_native_set_return(btn_obj_id); -} - -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 }, -}; - -/*************** Native Interface to Wasm App ***********/ -void -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, - argc); -} diff --git a/core/app-framework/wgl/native/wgl_native_utils.c b/core/app-framework/wgl/native/wgl_native_utils.c deleted file mode 100644 index 6683fff97..000000000 --- a/core/app-framework/wgl/native/wgl_native_utils.c +++ /dev/null @@ -1,126 +0,0 @@ - - -#include "wgl_native_utils.h" -#include "lvgl.h" -#include "module_wasm_app.h" -#include "wasm_export.h" -#include "bh_assert.h" - -#include - -#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 obj_id; - lv_obj_t *wigdet = NULL, *par = NULL, *copy = NULL; - uint32 mod_id; - - // 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)) { - THROW_EXC("create widget with invalid parent object."); - return 0; - } - /* validate the copy object id if not equal to 0 */ - if (copy_obj_id != 0 && !wgl_native_validate_object(copy_obj_id, ©)) { - THROW_EXC("create widget with invalid copy object."); - return 0; - } - - if (par == NULL) - par = lv_disp_get_scr_act(NULL); - - if (widget_type == WIDGET_TYPE_BTN) - wigdet = lv_btn_create(par, copy); - else if (widget_type == WIDGET_TYPE_LABEL) - wigdet = lv_label_create(par, copy); - else if (widget_type == WIDGET_TYPE_CB) - wigdet = lv_cb_create(par, copy); - else if (widget_type == WIDGET_TYPE_LIST) - wigdet = lv_list_create(par, copy); - else if (widget_type == WIDGET_TYPE_DDLIST) - wigdet = lv_ddlist_create(par, copy); - - if (wigdet == NULL) - return 0; - - mod_id = app_manager_get_module_id(Module_WASM_App, module_inst); - bh_assert(mod_id != ID_NONE); - - if (wgl_native_add_object(wigdet, mod_id, &obj_id)) - return obj_id; /* success return */ - - return 0; -} - -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 *); - WGLNativeFuncPtr wglNativeFuncPtr; - wasm_module_inst_t module_inst = get_module_inst(exec_env); - WGLNativeFuncDef *func_def = funcs; - WGLNativeFuncDef *func_def_end = func_def + size; - - /* 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))) - return; - - while (func_def < func_def_end) { - 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; - - if (argc > sizeof(argv_copy_buf) / sizeof(uint64)) { - size = sizeof(uint64) * (uint64)argc; - if (size >= UINT32_MAX - || !(argv_copy = wasm_runtime_malloc((uint32)size))) { - THROW_EXC("allocate memory failed."); - return; - } - memset(argv_copy, 0, (uint32)size); - } - - /* Init argv_copy */ - for (i = 0; i < func_def->arg_num; i++) - *(uint32 *)&argv_copy[i] = argv[i]; - - /* Validate the first argument which is a lvgl object if needed */ - if (func_def->check_obj) { - lv_obj_t *obj = NULL; - if (!wgl_native_validate_object(argv[0], &obj)) { - THROW_EXC("the object is invalid"); - goto fail; - } - *(lv_obj_t **)&argv_copy[0] = obj; - } - - wglNativeFuncPtr = (WGLNativeFuncPtr)func_def->func_ptr; - wglNativeFuncPtr(exec_env, argv_copy, argv); - - if (argv_copy != argv_copy_buf) - wasm_runtime_free(argv_copy); - - /* success return */ - return; - - fail: - if (argv_copy != argv_copy_buf) - wasm_runtime_free(argv_copy); - return; - } - - func_def++; - } - - THROW_EXC("the native widget function is not found!"); -} diff --git a/core/app-framework/wgl/native/wgl_native_utils.h b/core/app-framework/wgl/native/wgl_native_utils.h deleted file mode 100644 index f550dcc71..000000000 --- a/core/app-framework/wgl/native/wgl_native_utils.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef WAMR_GRAPHIC_LIBRARY_NATIVE_UTILS_H -#define WAMR_GRAPHIC_LIBRARY_NATIVE_UTILS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "bh_platform.h" -#include "lvgl.h" -#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_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) - -enum { - WIDGET_TYPE_BTN, - WIDGET_TYPE_LABEL, - WIDGET_TYPE_CB, - WIDGET_TYPE_LIST, - WIDGET_TYPE_DDLIST, - - _WIDGET_TYPE_NUM, -}; - -typedef struct WGLNativeFuncDef { - /* Function id */ - int32 func_id; - - /* Native function pointer */ - void *func_ptr; - - /* argument number */ - uint8 arg_num; - - /* whether the first argument is lvgl object and needs validate */ - bool check_obj; -} WGLNativeFuncDef; - -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); - -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); - -#ifdef __cplusplus -} -#endif - -#endif /* WAMR_GRAPHIC_LIBRARY_NATIVE_UTILS_H */ diff --git a/core/app-framework/wgl/native/wgl_obj_wrapper.c b/core/app-framework/wgl/native/wgl_obj_wrapper.c deleted file mode 100644 index 41f605b48..000000000 --- a/core/app-framework/wgl/native/wgl_obj_wrapper.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "lvgl.h" -#include "app_manager_export.h" -#include "module_wasm_app.h" -#include "bh_platform.h" -#include "wgl_native_utils.h" -#include "wgl.h" - -typedef struct { - bh_list_link l; - - /* The object id. */ - uint32 obj_id; - - /* The lv object */ - lv_obj_t *obj; - - /* Module id that the obj belongs to */ - uint32 module_id; -} object_node_t; - -typedef struct { - int32 obj_id; - lv_event_t event; -} object_event_t; - -/* Max obj id */ -static uint32 g_obj_id_max = 0; - -static bh_list g_object_list; - -static korp_mutex g_object_list_mutex; - -static bool lv_task_handler_thread_run = true; - -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) -{ - 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_module_inst_t inst = wasm_app_data->wasm_module_inst; - 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)"); - if (!func_on_object_event) - 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; - } - - argv[0] = object_event->obj_id; - argv[1] = object_event->event; - if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_on_object_event, - 2, argv)) { - const char *exception = wasm_runtime_get_exception(inst); - bh_assert(exception); - printf(":Got exception running wasm code: %s\n", exception); - wasm_runtime_clear_exception(inst); - return; - } -} - -static void -cleanup_object_list(uint32 module_id) -{ - object_node_t *elem; - - os_mutex_lock(&g_object_list_mutex); - - while (true) { - bool found = false; - 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) { - object_node_t *next = (object_node_t *)bh_list_elem_next(elem); - - found = true; - lv_obj_del(elem->obj); - bh_list_remove(&g_object_list, elem); - wasm_runtime_free(elem); - elem = next; - } - else { - elem = (object_node_t *)bh_list_elem_next(elem); - } - } - - if (!found) - break; - } - - os_mutex_unlock(&g_object_list_mutex); -} - -static bool -init_object_event_callback_framework() -{ - if (!wasm_register_cleanup_callback(cleanup_object_list)) { - goto fail; - } - - if (!wasm_register_msg_callback(WIDGET_EVENT_WASM, - app_mgr_object_event_callback)) { - goto fail; - } - - return true; - -fail: - return false; -} - -bool -wgl_native_validate_object(int32 obj_id, lv_obj_t **obj) -{ - object_node_t *elem; - - os_mutex_lock(&g_object_list_mutex); - - elem = (object_node_t *)bh_list_first_elem(&g_object_list); - while (elem) { - if (obj_id == elem->obj_id) { - if (obj != NULL) - *obj = elem->obj; - os_mutex_unlock(&g_object_list_mutex); - return true; - } - elem = (object_node_t *)bh_list_elem_next(elem); - } - - os_mutex_unlock(&g_object_list_mutex); - - return false; -} - -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)); - - if (node == NULL) - return false; - - /* Generate an obj id */ - g_obj_id_max++; - if (g_obj_id_max == -1) - g_obj_id_max = 1; - - memset(node, 0, sizeof(*node)); - node->obj = obj; - node->obj_id = g_obj_id_max; - node->module_id = module_id; - - os_mutex_lock(&g_object_list_mutex); - bh_list_insert(&g_object_list, node); - os_mutex_unlock(&g_object_list_mutex); - - if (obj_id != NULL) - *obj_id = node->obj_id; - - return true; -} - -static void -_obj_del_recursive(lv_obj_t *obj) -{ - object_node_t *elem; - lv_obj_t *i; - lv_obj_t *i_next; - - i = lv_ll_get_head(&(obj->child_ll)); - - while (i != NULL) { - /*Get the next object before delete this*/ - i_next = lv_ll_get_next(&(obj->child_ll), i); - - /*Call the recursive del to the child too*/ - _obj_del_recursive(i); - - /*Set i to the next node*/ - i = i_next; - } - - os_mutex_lock(&g_object_list_mutex); - - elem = (object_node_t *)bh_list_first_elem(&g_object_list); - while (elem) { - if (obj == elem->obj) { - bh_list_remove(&g_object_list, elem); - wasm_runtime_free(elem); - os_mutex_unlock(&g_object_list_mutex); - return; - } - 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) -{ - lv_obj_t *i; - lv_obj_t *i_next; - - i = lv_ll_get_head(&(obj->child_ll)); - - while (i != NULL) { - /*Get the next object before delete this*/ - i_next = lv_ll_get_next(&(obj->child_ll), i); - - /*Call the recursive del to the child too*/ - _obj_del_recursive(i); - - /*Set i to the next node*/ - i = i_next; - } -} - -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; - - if (module == NULL) - return; - - object_event = (object_event_t *)wasm_runtime_malloc(sizeof(*object_event)); - if (object_event == NULL) - return; - - memset(object_event, 0, sizeof(*object_event)); - object_event->obj_id = object_node->obj_id; - object_event->event = 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) -{ - object_node_t *elem; - - os_mutex_lock(&g_object_list_mutex); - - elem = (object_node_t *)bh_list_first_elem(&g_object_list); - while (elem) { - if (obj == elem->obj) { - post_widget_msg_to_module(elem, event); - os_mutex_unlock(&g_object_list_mutex); - return; - } - 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) -{ - os_mutex_lock(&task_handler_lock); - - while (lv_task_handler_thread_run) { - os_cond_reltimedwait(&task_handler_cond, &task_handler_lock, - 100 * 1000); - lv_task_handler(); - } - - os_mutex_unlock(&task_handler_lock); - return NULL; -} - -void -wgl_init(void) -{ - korp_tid tid; - - if (os_mutex_init(&task_handler_lock) != 0) - return; - - if (os_cond_init(&task_handler_cond) != 0) { - os_mutex_destroy(&task_handler_lock); - return; - } - - lv_init(); - - bh_list_init(&g_object_list); - os_recursive_mutex_init(&g_object_list_mutex); - init_object_event_callback_framework(); - - /* new a thread, call lv_task_handler periodically */ - os_thread_create(&tid, lv_task_handler_thread_routine, NULL, - BH_APPLET_PRESERVED_STACK_SIZE); -} - -void -wgl_exit(void) -{ - lv_task_handler_thread_run = false; - os_cond_destroy(&task_handler_cond); - os_mutex_destroy(&task_handler_lock); -} - -/* ------------------------------------------------------------------------- - * Obj native function wrappers - * -------------------------------------------------------------------------*/ -DEFINE_WGL_NATIVE_WRAPPER(lv_obj_del_wrapper) -{ - lv_res_t res; - wgl_native_return_type(lv_res_t); - wgl_native_get_arg(lv_obj_t *, obj); - - (void)exec_env; - - /* Recursively delete object node in the list belong to this - * parent object including itself */ - _obj_del_recursive(obj); - res = lv_obj_del(obj); - wgl_native_set_return(res); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_obj_del_async_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, obj); - - (void)exec_env; - lv_obj_del_async(obj); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_obj_clean_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, obj); - - (void)exec_env; - - /* Recursively delete child object node in the list belong to this - * parent object */ - _obj_clean_recursive(obj); - - /* Delete all of its children */ - lv_obj_clean(obj); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_obj_align_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, obj); - wgl_native_get_arg(uint32, base_obj_id); - wgl_native_get_arg(lv_align_t, align); - wgl_native_get_arg(lv_coord_t, x_mod); - wgl_native_get_arg(lv_coord_t, y_mod); - lv_obj_t *base = NULL; - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - /* 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."); - return; - } - - lv_obj_align(obj, base, align, x_mod, y_mod); -} - -DEFINE_WGL_NATIVE_WRAPPER(lv_obj_set_event_cb_wrapper) -{ - wgl_native_get_arg(lv_obj_t *, obj); - (void)exec_env; - lv_obj_set_event_cb(obj, internal_lv_obj_event_cb); -} - -/* ------------------------------------------------------------------------- */ - -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 }, -}; - -/*************** Native Interface to Wasm App ***********/ -void -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, - argc); -} diff --git a/core/app-framework/wgl/readme.MD b/core/app-framework/wgl/readme.MD deleted file mode 100644 index f929a5c11..000000000 --- a/core/app-framework/wgl/readme.MD +++ /dev/null @@ -1,97 +0,0 @@ -WASM Graphic Layer (WGL) -======= - -The WGL builds the littlevgl v6.0 into the runtime and exports a API layer for WASM appication programming graphic user interfaces. This approach will make the WASM application small footprint. Another option is to build the whole littlevgl library into WASM, which is how the sample littlevgl is implemented. - -# Challenges - -When the littlevgl library is compiled into the runtime, all the widget data is actually located in the runtime native space. As the WASM sandbox won't allow the WASM application to directly access the native data, it introduced a few problems for the littlevgl API exporting: - -1. Reference to the widget object - - Almost each littlevgl API takes the widget object as the first argument, which leads to either reading or writing the data associated with the object in native space. We have to prevent the WASM app utilize this method to access unauthorized memmory address. - - The solution is to track the objects created by the WASM App in the native layer. Every access to the object must be validated in advance. To simplify implementing native wrapper function, the wgl_native_func_call() will do the validation for the object presented in the first argument. - - When multiple WASM apps are creating their own UI, the object should also validated for its owner module instance. - -2. Access the object properties - - As the data structure of widget objects is no longer visible to the applications, the app has to call APIs to get/set the properties of an object. - -3. Pass function arguments in stucture pointers - - We have to do serialization for the structure passing between the WASM and native. - -4. Callbacks - -# API compatibility with littlevgl -We wish the application continue to use the littlevgl API and keep existing header files inclusion, however it is also a bit challenging since we have to redefine some data types such as lv_obj_t in the APIs exposed to the WASM app. - -''' -typedef void lv_obj_t; -''' - - - -# Prepare the lvgl header files for WASM applicaitons - -Run the below script to setup the lvgl header files for the wasm appliation. - -``` -core/app-framework/wgl/app/prepare_headers.sh -``` - -The script is also automatically executed after downloading the lvgl repo in the wamr-sdk building process. - - - -# How to extend a little vgl wideget -Currently the wgl has exported the API for a few common used widgets such as button, label etc. - -Refer to the implementation of these widgets for extending more widgets. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/core/app-mgr/app-manager/app_manager.c b/core/app-mgr/app-manager/app_manager.c deleted file mode 100644 index b27ee96eb..000000000 --- a/core/app-mgr/app-manager/app_manager.c +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "app_manager.h" -#include "app_manager_host.h" -#include "bh_platform.h" -#include "bi-inc/attr_container.h" -#include "event.h" -#include "watchdog.h" -#include "coap_ext.h" - -/* Queue of app manager */ -static bh_queue *g_app_mgr_queue; -static bool g_app_mgr_started; - -void * -get_app_manager_queue() -{ - return g_app_mgr_queue; -} - -void -app_manager_post_applets_update_event() -{ - module_data *m_data; - attr_container_t *attr_cont; - request_t msg; - int num = 0, i = 0; - char *url = "/applets"; - - if (!event_is_registered(url)) - return; - - if (!(attr_cont = attr_container_create("All Applets"))) { - app_manager_printf("Post applets update event failed: " - "allocate memory failed."); - return; - } - - os_mutex_lock(&module_data_list_lock); - - m_data = module_data_list; - while (m_data) { - num++; - m_data = m_data->next; - } - - if (!(attr_container_set_int(&attr_cont, "num", num))) { - app_manager_printf("Post applets update event failed: " - "set attr container key failed."); - goto fail; - } - - m_data = module_data_list; - while (m_data) { - char buf[32]; - i++; - snprintf(buf, sizeof(buf), "%s%d", "applet", i); - 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; - } - snprintf(buf, sizeof(buf), "%s%d", "heap", i); - if (!(attr_container_set_int(&attr_cont, buf, m_data->heap_size))) { - app_manager_printf("Post applets update event failed: " - "set attr heap key failed."); - goto fail; - } - m_data = m_data->next; - } - - memset(&msg, 0, sizeof(msg)); - msg.url = url; - msg.action = COAP_EVENT; - msg.payload = (char *)attr_cont; - send_request_to_host(&msg); - - app_manager_printf("Post applets update event success!\n"); - attr_container_dump(attr_cont); - -fail: - os_mutex_unlock(&module_data_list_lock); - attr_container_destroy(attr_cont); -} - -static int -get_applets_count() -{ - module_data *m_data; - int num = 0; - - os_mutex_lock(&module_data_list_lock); - - m_data = module_data_list; - while (m_data) { - num++; - m_data = m_data->next; - } - - os_mutex_unlock(&module_data_list_lock); - - return num; -} - -/* Query fw apps info if name = NULL, otherwise query specify app */ -static bool -app_manager_query_applets(request_t *msg, const char *name) -{ - module_data *m_data; - attr_container_t *attr_cont; - int num = 0, i = 0, len; - bool ret = false, found = false; - response_t response[1] = { 0 }; - - attr_cont = attr_container_create("Applets Info"); - if (!attr_cont) { - SEND_ERR_RESPONSE(msg->mid, - "Query Applets failed: allocate memory failed."); - return false; - } - - os_mutex_lock(&module_data_list_lock); - - m_data = module_data_list; - while (m_data) { - num++; - m_data = m_data->next; - } - - if (name == NULL && !(attr_container_set_int(&attr_cont, "num", num))) { - SEND_ERR_RESPONSE( - msg->mid, "Query Applets failed: set attr container key failed."); - goto fail; - } - - m_data = module_data_list; - while (m_data) { - char buf[32]; - - if (name == NULL) { - 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."); - goto fail; - } - snprintf(buf, sizeof(buf), "%s%d", "heap", i); - if (!(attr_container_set_int(&attr_cont, buf, m_data->heap_size))) { - SEND_ERR_RESPONSE(msg->mid, - "Query Applets failed: " - "set attr container heap key failed."); - goto fail; - } - } - 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."); - goto fail; - } - 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."); - goto fail; - } - } - - m_data = m_data->next; - } - - if (name != NULL && !found) { - SEND_ERR_RESPONSE(msg->mid, - "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); - send_response_to_host(response); - - ret = true; - app_manager_printf("Query Applets success!\n"); - attr_container_dump(attr_cont); - -fail: - os_mutex_unlock(&module_data_list_lock); - attr_container_destroy(attr_cont); - return ret; -} - -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 */ - request_t *req = clone_request(request); - - if (!req) - return; - - msg = bh_new_msg(RESTFUL_REQUEST, req, sizeof(*req), request_cleaner); - if (!msg) { - request_cleaner(req); - return; - } - - bh_post_msg2(get_app_manager_queue(), msg); -} - -/* return -1 for error */ -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, '&'); - - if (strlen(type_str) == 0) - module_type = Module_WASM_App; - else if (strcmp(type_str, "jeff") == 0) - module_type = Module_Jeff; - else if (strcmp(type_str, "wasm") == 0) - module_type = Module_WASM_App; - else if (strcmp(type_str, "wasmlib") == 0) - module_type = Module_WASM_Lib; - - return module_type; -} - -#define APP_NAME_MAX_LEN 128 - -/* Queue callback of App Manager */ - -static void -app_manager_queue_callback(void *message, void *arg) -{ - 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) { - module_type = get_module_type(request->url + offset); - - if (module_type == -1) { - SEND_ERR_RESPONSE(mid, - "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."); - goto fail; - } - - if (!request->payload) { - SEND_ERR_RESPONSE(mid, - "Install Applet failed: invalid payload."); - goto fail; - } - if (g_module_interfaces[module_type] - && g_module_interfaces[module_type]->module_install) { - if (!g_module_interfaces[module_type]->module_install(request)) - goto fail; - } - } - /* Uninstall Applet */ - 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."); - goto fail; - } - - if (g_module_interfaces[module_type] - && g_module_interfaces[module_type]->module_uninstall) { - if (!g_module_interfaces[module_type]->module_uninstall( - request)) - goto fail; - } - } - /* Query Applets installed */ - else if (request->action == COAP_GET) { - char name[APP_NAME_MAX_LEN] = { 0 }; - char *properties = request->url + offset; - find_key_value(properties, strlen(properties), "name", name, - sizeof(name) - 1, '&'); - if (strlen(name) > 0) - app_manager_query_applets(request, name); - else - app_manager_query_applets(request, NULL); - } - else { - SEND_ERR_RESPONSE(mid, "Invalid request of applet: invalid action"); - } - } - /* Event Register/Unregister */ - else if ((offset = check_url_start(request->url, strlen(request->url), - "/event/")) - > 0) { - char url_buf[256] = { 0 }; - - strncpy(url_buf, request->url + offset, sizeof(url_buf) - 1); - - if (!event_handle_event_request(request->action, url_buf, ID_HOST)) { - SEND_ERR_RESPONSE(mid, "Handle event request failed."); - goto fail; - } - send_error_response_to_host(mid, CONTENT_2_05, NULL); /* OK */ - } - else { - int i; - for (i = 0; i < Module_Max; i++) { - if (g_module_interfaces[i] - && g_module_interfaces[i]->module_handle_host_url) { - if (g_module_interfaces[i]->module_handle_host_url(request)) - break; - } - } - } - -fail: - return; -} - -static void -module_interfaces_init() -{ - int i; - for (i = 0; i < Module_Max; i++) { - if (g_module_interfaces[i] && g_module_interfaces[i]->module_init) - g_module_interfaces[i]->module_init(); - } -} - -void -app_manager_startup(host_interface *interface) -{ - module_interfaces_init(); - - /* Create queue of App Manager */ - g_app_mgr_queue = bh_queue_create(); - if (!g_app_mgr_queue) - return; - - if (!module_data_list_init()) - goto fail1; - - if (!watchdog_startup()) - goto fail2; - - /* Initialize Host */ - app_manager_host_init(interface); - - am_register_resource("/app/", targeted_app_request_handler, ID_APP_MGR); - - /* /app/ and /event/ are both processed by applet_mgt_reqeust_handler */ - am_register_resource("/applet", applet_mgt_reqeust_handler, ID_APP_MGR); - am_register_resource("/event/", applet_mgt_reqeust_handler, ID_APP_MGR); - - app_manager_printf("App Manager started.\n"); - - g_app_mgr_started = true; - - /* Enter loop run */ - bh_queue_enter_loop_run(g_app_mgr_queue, app_manager_queue_callback, NULL); - - g_app_mgr_started = false; - - /* Destroy registered resources */ - am_cleanup_registeration(ID_APP_MGR); - - /* Destroy watchdog */ - watchdog_destroy(); - -fail2: - module_data_list_destroy(); - -fail1: - bh_queue_destroy(g_app_mgr_queue); -} - -bool -app_manager_is_started(void) -{ - return g_app_mgr_started; -} - -#include "module_config.h" - -module_interface *g_module_interfaces[Module_Max] = { -#if ENABLE_MODULE_JEFF != 0 - &jeff_module_interface, -#else - NULL, -#endif - -#if ENABLE_MODULE_WASM_APP != 0 - &wasm_app_module_interface, -#else - NULL, -#endif - -#if ENABLE_MODULE_WASM_LIB != 0 - &wasm_lib_module_interface -#else - NULL -#endif -}; diff --git a/core/app-mgr/app-manager/app_manager.h b/core/app-mgr/app-manager/app_manager.h deleted file mode 100644 index ce83bd170..000000000 --- a/core/app-mgr/app-manager/app_manager.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef APP_MANAGER_H -#define APP_MANAGER_H - -#include "bh_platform.h" -#include "app_manager_export.h" -#include "native_interface.h" -#include "bi-inc/shared_utils.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define APP_MGR_MALLOC wasm_runtime_malloc -#define APP_MGR_FREE wasm_runtime_free - -/* 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) - -extern module_interface *g_module_interfaces[Module_Max]; - -/* Lock of the module data list */ -extern korp_mutex module_data_list_lock; - -/* Module data list */ -extern module_data *module_data_list; - -void -app_manager_add_module_data(module_data *m_data); - -void -app_manager_del_module_data(module_data *m_data); - -bool -module_data_list_init(); - -void -module_data_list_destroy(); - -bool -app_manager_is_interrupting_module(uint32 module_type, void *module_inst); - -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_destroy(void *timer); - -void -app_manager_timer_start(void *timer, int timeout); - -void -app_manager_timer_stop(void *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); - -void -targeted_app_request_handler(request_t *request, void *unused); - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif diff --git a/core/app-mgr/app-manager/app_manager_host.c b/core/app-mgr/app-manager/app_manager_host.c deleted file mode 100644 index 08b5df309..000000000 --- a/core/app-mgr/app-manager/app_manager_host.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "bh_platform.h" -#include "app_manager_host.h" -#include "app_manager.h" -#include "app_manager_export.h" -#include "coap_ext.h" - -/* host communication interface */ -static host_interface host_commu; - -/* IMRTLink Two leading bytes */ -static unsigned char leadings[] = { (unsigned char)0x12, (unsigned char)0x34 }; - -/* IMRTLink Receiving Phase */ -typedef enum recv_phase_t { - Phase_Non_Start, - Phase_Leading, - Phase_Type, - Phase_Size, - Phase_Payload, - Phase_Ignoring -} recv_phase_t; - -/* IMRTLink Receive Context */ -typedef struct recv_context_t { - recv_phase_t phase; - bh_link_msg_t message; - int size_in_phase; -} recv_context_t; - -/* Current IMRTLink receive context */ -static recv_context_t recv_ctx; - -/* Lock for device write */ -static korp_mutex host_lock; - -static bool enable_log = false; - -static bool -is_little_endian() -{ - long i = 0x01020304; - unsigned char *c = (unsigned char *)&i; - return (*c == 0x04) ? true : false; -} - -static void -exchange32(uint8 *pData) -{ - uint8 value = *pData; - *pData = *(pData + 3); - *(pData + 3) = value; - - value = *(pData + 1); - *(pData + 1) = *(pData + 2); - *(pData + 2) = value; -} - -/* return: - * 1: complete message received - * 0: incomplete message received - */ -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; - - if (ctx->message.payload) { - APP_MGR_FREE(ctx->message.payload); - ctx->message.payload = NULL; - } - - if (ch == leadings[0]) { - if (enable_log) - app_manager_printf("##On byte arrive: got leading 0\n"); - ctx->phase = Phase_Leading; - } - - return 0; - } - else if (ctx->phase == Phase_Leading) { - if (ch == leadings[1]) { - if (enable_log) - app_manager_printf("##On byte arrive: got leading 1\n"); - ctx->phase = Phase_Type; - } - else - ctx->phase = Phase_Non_Start; - - return 0; - } - else if (ctx->phase == Phase_Type) { - if (ctx->size_in_phase++ == 0) { - if (enable_log) - app_manager_printf("##On byte arrive: got type 0\n"); - ctx->message.message_type = ch; - } - else { - if (enable_log) - app_manager_printf("##On byte arrive: got type 1\n"); - ctx->message.message_type |= (ch << 8); - ctx->message.message_type = ntohs(ctx->message.message_type); - ctx->phase = Phase_Size; - ctx->size_in_phase = 0; - } - - return 0; - } - else if (ctx->phase == Phase_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", - ctx->size_in_phase); - p[ctx->size_in_phase++] = ch; - - if (ctx->size_in_phase == sizeof(ctx->message.payload_size)) { - ctx->message.payload_size = ntohl(ctx->message.payload_size); - ctx->phase = Phase_Payload; - - if (enable_log) - app_manager_printf("##On byte arrive: payload_size: %d\n", - ctx->message.payload_size); - if (ctx->message.payload) { - APP_MGR_FREE(ctx->message.payload); - ctx->message.payload = NULL; - } - - /* message completion */ - if (ctx->message.payload_size == 0) { - ctx->phase = Phase_Non_Start; - if (enable_log) - app_manager_printf("##On byte arrive: receive end, " - "payload_size is 0.\n"); - return 1; - } - - if (ctx->message.message_type != INSTALL_WASM_APP) { - ctx->message.payload = - (char *)APP_MGR_MALLOC(ctx->message.payload_size); - if (!ctx->message.payload) { - ctx->phase = Phase_Non_Start; - return 0; - } - } - - ctx->phase = Phase_Payload; - ctx->size_in_phase = 0; - } - - return 0; - } - else if (ctx->phase == Phase_Payload) { - 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; - - ctx->size_in_phase++; - - if (module_on_install != NULL) { - if (module_on_install(ch, ctx->message.payload_size, - &received_size)) { - if (received_size == ctx->message.payload_size) { - /* whole wasm app received */ - ctx->phase = Phase_Non_Start; - return 1; - } - } - else { - /* receive or handle fail */ - if (ctx->size_in_phase < ctx->message.payload_size) { - ctx->phase = Phase_Ignoring; - } - else { - ctx->phase = Phase_Non_Start; - ctx->size_in_phase = 0; - } - return 0; - } - } - else { - ctx->phase = Phase_Non_Start; - ctx->size_in_phase = 0; - return 0; - } - } - else { - ctx->message.payload[ctx->size_in_phase++] = ch; - - if (ctx->size_in_phase == ctx->message.payload_size) { - ctx->phase = Phase_Non_Start; - if (enable_log) - app_manager_printf("##On byte arrive: receive end, " - "payload_size is %d.\n", - ctx->message.payload_size); - return 1; - } - return 0; - } - } - else if (ctx->phase == Phase_Ignoring) { - ctx->size_in_phase++; - if (ctx->size_in_phase == ctx->message.payload_size) { - if (ctx->message.payload) - APP_MGR_FREE(ctx->message.payload); - memset(ctx, 0, sizeof(*ctx)); - return 0; - } - } - - return 0; -} - -int -aee_host_msg_callback(void *msg, uint32_t msg_len) -{ - unsigned char *p = msg, *p_end = p + msg_len; - - /*app_manager_printf("App Manager receive %d bytes from Host\n", msg_len);*/ - - for (; p < p_end; p++) { - int ret = on_imrt_link_byte_arrive(*p, &recv_ctx); - - if (ret == 1) { - if (recv_ctx.message.payload) { - int msg_type = recv_ctx.message.message_type; - - if (msg_type == REQUEST_PACKET) { - request_t request; - memset(&request, 0, sizeof(request)); - - if (!unpack_request(recv_ctx.message.payload, - recv_ctx.message.payload_size, - &request)) - continue; - - request.sender = ID_HOST; - - am_dispatch_request(&request); - } - else { - app_manager_printf("unexpected host msg type: %d\n", - msg_type); - } - - APP_MGR_FREE(recv_ctx.message.payload); - recv_ctx.message.payload = NULL; - recv_ctx.message.payload_size = 0; - } - - memset(&recv_ctx, 0, sizeof(recv_ctx)); - } - } - - return 0; -} - -bool -app_manager_host_init(host_interface *interface) -{ - if (os_mutex_init(&host_lock) != 0) { - return false; - } - memset(&recv_ctx, 0, sizeof(recv_ctx)); - - host_commu.init = interface->init; - host_commu.send = interface->send; - host_commu.destroy = interface->destroy; - - if (host_commu.init != NULL) { - if (!host_commu.init()) { - os_mutex_destroy(&host_lock); - return false; - } - } - - return true; -} - -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) { - int size_s = size, n; - char header[16]; - - os_mutex_lock(&host_lock); - /* leading bytes */ - bh_memcpy_s(header, 2, leadings, 2); - - /* message type */ - /* TODO: check if use network byte order!!! */ - *((uint16 *)(header + 2)) = htons(msg_type); - - /* payload length */ - if (is_little_endian()) - exchange32((uint8 *)&size_s); - - bh_memcpy_s(header + 4, 4, &size_s, 4); - n = host_commu.send(NULL, header, 8); - if (n != 8) { - os_mutex_unlock(&host_lock); - return 0; - } - - /* payload */ - n = host_commu.send(NULL, buf, size); - os_mutex_unlock(&host_lock); - - app_manager_printf("sent %d bytes to host\n", n); - return n; - } - else { - app_manager_printf("no send api provided\n"); - } - return 0; -} diff --git a/core/app-mgr/app-manager/app_manager_host.h b/core/app-mgr/app-manager/app_manager_host.h deleted file mode 100644 index b19404f91..000000000 --- a/core/app-mgr/app-manager/app_manager_host.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _APP_MANAGER_HOST_H_ -#define _APP_MANAGER_HOST_H_ - -#include "wasm_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define HOST_MODE_AON 1 -#define HOST_MODE_UART 2 -#define HOST_MODE_TEST 3 - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif diff --git a/core/app-mgr/app-manager/app_mgr.cmake b/core/app-mgr/app-manager/app_mgr.cmake deleted file mode 100644 index fd6e69098..000000000 --- a/core/app-mgr/app-manager/app_mgr.cmake +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (__APP_MGR_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${__APP_MGR_DIR}) - - -file (GLOB source_all ${__APP_MGR_DIR}/*.c ${__APP_MGR_DIR}/platform/${WAMR_BUILD_PLATFORM}/*.c) - -set (APP_MGR_SOURCE ${source_all}) - -file (GLOB header - ${__APP_MGR_DIR}/module_wasm_app.h -) -LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header}) - diff --git a/core/app-mgr/app-manager/ble_msg.c b/core/app-mgr/app-manager/ble_msg.c deleted file mode 100644 index 1d19dddaf..000000000 --- a/core/app-mgr/app-manager/ble_msg.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#if 0 - -#define BLUETOOTH_INTERFACE_ADVERTISMENT_DATA_LENGTH 31 -/* ble_device_info */ -typedef struct ble_device_info { - - /* address type */ - uint8_t address_type; - /* MAC of Device */ - uint8_t mac[6]; - /* security level */ - uint8_t security_level; - /* signal strength */ - int8_t rssi; - /* uuid_16_type */ - int8_t uuid_16_type; - /* uuid_32_type */ - int8_t uuid_32_type; - /* uuid_128_type */ - int8_t uuid_128_type; - /* error code */ - uint8_t error_code; - /* scan response length*/ - uint16_t adv_data_len; - /* advertisement data */ - uint8_t *adv_data; - /* scan response length*/ - uint16_t scan_response_len; - /* scan response */ - uint8_t *scan_response; - /* next device */ - struct ble_device_info *next; - /* private data length */ - int private_data_length; - /* private data */ - uint8_t *private_data; - /* value handle*/ - uint16_t value_handle; - /* ccc handle*/ - uint16_t ccc_handle; - -}ble_device_info; - -/* BLE message sub type */ -typedef enum BLE_SUB_EVENT_TYPE { - BLE_SUB_EVENT_DISCOVERY, - BLE_SUB_EVENT_CONNECTED, - BLE_SUB_EVENT_DISCONNECTED, - BLE_SUB_EVENT_NOTIFICATION, - BLE_SUB_EVENT_INDICATION, - BLE_SUB_EVENT_PASSKEYENTRY, - BLE_SUB_EVENT_SECURITY_LEVEL_CHANGE -}BLE_SUB_EVENT_TYPE; - -/* Queue message, for BLE Event */ -typedef struct bh_queue_ble_sub_msg_t { - /* message type, should be one of QUEUE_MSG_TYPE */ - BLE_SUB_EVENT_TYPE type; - /* payload size */ - /*uint32_t payload_size;*/ - char payload[1]; -}bh_queue_ble_sub_msg_t; - -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; - - 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_queue_free_callback(bh_message_t queue_msg) -{ - - char * payload = (char *)bh_message_payload(queue_msg); - if(payload == NULL) - return; - - switch (bh_message_type(queue_msg)) - { - /* - case SENSOR_EVENT: { - bh_sensor_event_t *sensor_event = (bh_sensor_event_t *) payload; - attr_container_t *event = sensor_event->event; - attr_container_destroy(event); - } - break; - */ - case BLE_EVENT: { - app_instance_free_ble_msg(payload); - break; - } - } -} - -#endif diff --git a/core/app-mgr/app-manager/coding_rule.txt b/core/app-mgr/app-manager/coding_rule.txt deleted file mode 100644 index 4598872a3..000000000 --- a/core/app-mgr/app-manager/coding_rule.txt +++ /dev/null @@ -1,15 +0,0 @@ -Coding rules: - -1. module implementation can include the export head files of associated runtime - -2. app manager only call access the module implementation through the interface API - -3. module implementation can call the app manager API from following files: - - util.c - - message.c - -4. platform API: To define it - -5. Any platform dependent implementation of app manager should be implemented in the - platform specific source file, such as app_mgr_zephyr.c - diff --git a/core/app-mgr/app-manager/event.c b/core/app-mgr/app-manager/event.c deleted file mode 100644 index a21065fab..000000000 --- a/core/app-mgr/app-manager/event.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include - -#include "event.h" - -#include "app_manager.h" -#include "coap_ext.h" - -typedef struct _subscribe { - struct _subscribe *next; - uint32 subscriber_id; -} subscribe_t; - -typedef struct _event { - struct _event *next; - int subscriber_size; - 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) -{ - subscribe_t *c = reg->subscribers; - subscribe_t *prev = NULL; - while (c) { - subscribe_t *next = c->next; - if (c->subscriber_id == id) { - if (remove_found) { - if (prev) - prev->next = next; - else - reg->subscribers = next; - - APP_MGR_FREE(c); - } - - return true; - } - else { - prev = c; - c = next; - } - } - - return false; -} - -static bool -check_url(const char *url) -{ - if (*url == 0) - return false; - - return true; -} - -bool -am_register_event(const char *url, uint32_t reg_client) -{ - event_reg_t *current = g_events; - - app_manager_printf("am_register_event adding url:(%s)\n", url); - - if (!check_url(url)) { - app_manager_printf("am_register_event: invaild url:(%s)\n", url); - return false; - } - while (current) { - if (strcmp(url, current->url) == 0) - break; - current = current->next; - } - - if (current == NULL) { - if (NULL - == (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; - } - - memset(current, 0, sizeof(event_reg_t)); - bh_strcpy_s(current->url, strlen(url) + 1, url); - current->next = g_events; - g_events = current; - } - - if (find_subscriber(current, reg_client, false)) { - return true; - } - else { - subscribe_t *s = (subscribe_t *)APP_MGR_MALLOC(sizeof(subscribe_t)); - if (s == NULL) - return false; - - memset(s, 0, sizeof(subscribe_t)); - s->subscriber_id = reg_client; - s->next = current->subscribers; - current->subscribers = s; - app_manager_printf("client: %d registered event (%s)\n", reg_client, - 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) -{ - 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; - if (find_subscriber(current, reg_client, true)) { - app_manager_printf("client: %d deregistered event (%s)\n", - 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); - if (pre) - pre->next = next; - else - g_events = next; - APP_MGR_FREE(current); - current = next; - continue; - } - } - pre = current; - current = current->next; - } - - return true; -} - -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 */ - return am_unregister_event(event_url, reg_client); - } - else { - /* invalid request */ - return false; - } -} - -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; - while (c) { - if (c->subscriber_id == ID_HOST) { - send_request_to_host(event); - } - else { - module_request_handler(event, - (void *)(uintptr_t)c->subscriber_id); - } - c = c->next; - } - - return; - } - - current = current->next; - } -} - -bool -event_is_registered(const char *event_url) -{ - event_reg_t *current = g_events; - - while (current != NULL) { - if (strcmp(current->url, event_url) == 0) { - return true; - } - current = current->next; - } - - return false; -} diff --git a/core/app-mgr/app-manager/event.h b/core/app-mgr/app-manager/event.h deleted file mode 100644 index 36ced521d..000000000 --- a/core/app-mgr/app-manager/event.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _EVENT_H_ -#define _EVENT_H_ - -#include "bh_platform.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Handle event request from host agent - * - * @param code the coap packet code - * @param event_url the event url - * - * @return true if success, false otherwise - */ -bool -event_handle_event_request(uint8_t code, const char *event_url, - uint32_t register); - -/** - * Test whether the event is registered - * - * @param event_url the event url - * - * @return true for registered, false for not registered - */ -bool -event_is_registered(const char *event_url); - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif /* _EVENT_H_ */ diff --git a/core/app-mgr/app-manager/message.c b/core/app-mgr/app-manager/message.c deleted file mode 100644 index aac7a2364..000000000 --- a/core/app-mgr/app-manager/message.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "app_manager.h" -#include "app_manager_host.h" -#include "event.h" -#include "bi-inc/attr_container.h" -#include "coap_ext.h" - -#if 0 -bool send_coap_packet_to_host(coap_packet_t * packet) -{ - int size; - uint8_t *buf; - - size = coap_serialize_message_tcp(&packet, &buf); - if (!buf || size == 0) - return false; - - app_manager_host_send_msg(buf, size); - APP_MGR_FREE(buf); - - return true; -} -#endif - -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"); - return false; - } - - int size; - char *packet = pack_request(msg, &size); - if (packet == NULL) - return false; - - app_manager_host_send_msg(REQUEST_PACKET, packet, size); - - free_req_resp_packet(packet); - - return true; -} - -bool -send_response_to_host(response_t *response) -{ - int size; - char *packet = pack_response(response, &size); - if (packet == NULL) - return false; - - app_manager_host_send_msg(RESPONSE_PACKET, packet, size); - - free_req_resp_packet(packet); - - return true; -} - -bool -send_error_response_to_host(int mid, int status, const char *msg) -{ - int payload_len = 0; - attr_container_t *payload = NULL; - response_t response[1] = { 0 }; - - if (msg) { - payload = attr_container_create(""); - if (payload) { - attr_container_set_string(&payload, "error message", msg); - payload_len = attr_container_get_serialize_length(payload); - } - } - - set_response(response, status, FMT_ATTR_CONTAINER, (const char *)payload, - payload_len); - response->mid = mid; - - send_response_to_host(response); - - if (payload) - attr_container_destroy(payload); - return true; -} diff --git a/core/app-mgr/app-manager/module_config.h b/core/app-mgr/app-manager/module_config.h deleted file mode 100644 index b742fed3a..000000000 --- a/core/app-mgr/app-manager/module_config.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _MODULE_CONFIG_H_ -#define _MODULE_CONFIG_H_ - -#define ENABLE_MODULE_JEFF 0 -#define ENABLE_MODULE_WASM_APP 1 -#define ENABLE_MODULE_WASM_LIB 1 - -#ifdef ENABLE_MODULE_JEFF -#include "module_jeff.h" -#endif -#ifdef ENABLE_MODULE_WASM_APP -#include "module_wasm_app.h" -#endif -#ifdef ENABLE_MODULE_WASM_LIB -#include "module_wasm_lib.h" -#endif - -#endif /* _MODULE_CONFIG_H_ */ diff --git a/core/app-mgr/app-manager/module_jeff.c b/core/app-mgr/app-manager/module_jeff.c deleted file mode 100644 index 7c7f9510d..000000000 --- a/core/app-mgr/app-manager/module_jeff.c +++ /dev/null @@ -1,1883 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifdef ENABLE_JEFF - -#include "module_jeff.h" -#include "jeff_export.h" -#include "../vmcore_jeff/jeff-runtime.h" -#include "../vmcore_jeff/jeff-thread.h" -#include "../vmcore_jeff/jeff-buffer.h" -#include "../vmcore_jeff/jeff-tool.h" -#include "../vmcore_jeff/jeff-tool-priv.h" -#include "app_manager-host.h" -#include "bh_queue.h" -#include "attr-container.h" -#include "attr-container-util.h" -#include "bh_thread.h" -#include "ems_gc.h" -#include "coap_ext.h" -#include "libcore.h" -#include "event.h" -#include "watchdog.h" - -#define DEFAULT_APPLET_TIMEOUT (3 * 60 * 1000) -#define DEFAULT_APPLET_HEAP_SIZE (48 * 1024) -#define MIN_APPLET_HEAP_SIZE (2 * 1024) -#define MAX_APPLET_HEAP_SIZE (1024 * 1024) - -typedef struct jeff_applet_data { - /* Java Applet Object */ - JeffObjectRef applet_obj; - -#if BEIHAI_ENABLE_TOOL_AGENT != 0 - /* Whether the applet is in debug mode */ - bool debug_mode; - /* Queue of the tool agent */ - bh_queue *tool_agent_queue; -#endif - - /* VM instance */ - JeffInstanceLocalRoot *vm_instance; - /* Applet Main file */ - JeffFileHeaderLinked *main_file; - /* Permissions of the Java Applet */ - char *perms; -} jeff_applet_data; - -/* Jeff class com.intel.aee.AEEApplet */ -static JeffClassHeaderLinked *class_AEEApplet; -/* Jeff class com.intel.aee.Request */ -static JeffClassHeaderLinked *class_AEERequest; -/* Jeff class com.intel.aee.Timer */ -static JeffClassHeaderLinked *class_Timer; -/* Jeff class com.intel.aee.Sensor */ -static JeffClassHeaderLinked *class_Sensor; -/* Jeff class com.intel.aee.ble.BLEManager */ -static JeffClassHeaderLinked *class_BLEManager; -/* Jeff class com.intel.aee.ble.BLEDevice */ -static JeffClassHeaderLinked *class_BLEDevice; -/* Jeff class com.intel.aee.ble.BLEGattService */ -JeffClassHeaderLinked *class_BLEGattService; -/* Jeff class com.intel.aee.ble.BLEGattCharacteristic */ -JeffClassHeaderLinked *class_BLEGattCharacteristic; -/* Jeff class com.intel.aee.ble.BLEGattDescriptor */ -JeffClassHeaderLinked *class_BLEGattDescriptor; -/* Jeff class com.intel.aee.gpio.GPIOChannel */ -static JeffClassHeaderLinked *class_GPIOChannel; -/* Jeff method void com.intel.aee.AEEApplet.onInit() */ -static JeffMethodLinked *method_AEEApplet_onInit; -/* Jeff method void com.intel.aee.AEEApplet.onDestroy() */ -static JeffMethodLinked *method_AEEApplet_onDestroy; -/* Jeff method void com.intel.aee.AEEApplet.callOnRequest(Request request) */ -static JeffMethodLinked *method_AEEApplet_callOnRequest; -/* Jeff method void com.intel.aee.Timer.callOnTimer() */ -static JeffMethodLinked *method_callOnTimer; -/* Jeff method void com.intel.aee.Sensor.callOnSensorEvent() */ -static JeffMethodLinked *method_callOnSensorEvent; -/* Jeff method void com.intel.aee.ble.BLEManager.callOnBLEStartDiscovery() */ -static JeffMethodLinked *method_callOnBLEStartDiscovery; -/* Jeff method void com.intel.aee.ble.BLEManager.callOnBLEConnected() */ -static JeffMethodLinked *method_callOnBLEConnected; -/* Jeff method void com.intel.aee.ble.BLEManager.callOnBLEDisonnected() */ -static JeffMethodLinked *method_callOnBLEDisconnected; -/* Jeff method void com.intel.aee.ble.BLEManager.callOnBLENotification() */ -static JeffMethodLinked *method_callOnBLENotification; -/* Jeff method void com.intel.aee.ble.BLEManager.callOnBLEIndication() */ -static JeffMethodLinked *method_callOnBLEIndication; -/* Jeff method void com.intel.aee.ble.BLEManager.callOnBLEPasskeyEntry() */ -static JeffMethodLinked *method_callOnBLEPasskeyEntry; -/* Jeff method void com.intel.aee.gpio.GPIOChannel.callOnGPIOInterrupt() */ -static JeffMethodLinked *method_callOnGPIOInterrupt; -/* Jeff method void com.intel.aee.ble.BLEManager.getBLEDevice() */ -static JeffMethodLinked *method_callOnBLEManagerGetBLEDevice; - -static jeff_applet_data * -app_manager_get_jeff_applet_data() -{ - module_data *m_data = app_manager_get_module_data(Module_Jeff); - return (jeff_applet_data *)m_data->internal_data; -} - -#if BEIHAI_ENABLE_TOOL_AGENT != 0 -void * -app_manager_get_tool_agent_queue() -{ - return app_manager_get_jeff_applet_data()->tool_agent_queue; -} -#endif - -#if BEIHAI_ENABLE_TOOL_AGENT != 0 -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 - && applet_data->vm_instance->tool_agent); -} -#endif - -static char * -get_class_qname(const JeffString *pname, const JeffString *cname) -{ - unsigned int length = - pname->length ? pname->length + 2 + cname->length : cname->length + 1; - char *buf = APP_MGR_MALLOC(length), *p; - - if (!buf) - return NULL; - - p = buf; - if (pname->length) { - bh_memcpy_s(p, pname->length, pname->value, pname->length); - p += pname->length; - *p++ = '.'; - } - - bh_memcpy_s(p, cname->length, cname->value, cname->length); - p += cname->length; - *p = '\0'; - - return buf; -} - -static void -send_exception_event_to_host(const char *applet_name, const char *exc_name) -{ - attr_container_t *payload; - bh_request_msg_t msg; - char *url; - int url_len; - - payload = attr_container_create("exception detail"); - if (!payload) { - app_manager_printf("Send exception to host fail: allocate memory"); - return; - } - - 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)) { - app_manager_printf("Send exception to host fail: set attr"); - goto fail; - } - - url_len = strlen("/exception/") + strlen(applet_name); - url = APP_MGR_MALLOC(url_len + 1); - if (!url) { - app_manager_printf("Send exception to host fail: allocate memory"); - goto fail; - } - memset(url, 0, url_len + 1); - bh_strcpy_s(url, url_len + 1, "/exception/"); - bh_strcat_s(url, url_len + 1, applet_name); - - memset(&msg, 0, sizeof(msg)); - msg.url = url; - msg.action = COAP_PUT; - msg.payload = (char *)payload; - - app_send_request_msg_to_host(&msg); - - APP_MGR_FREE(url); - -fail: - attr_container_destroy(payload); -} - -static bool -check_exception() -{ - if (jeff_runtime_get_exception()) { - jeff_printf("V1.Exception thrown when running applet '%s':\n", - 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); - - 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; -} - -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; - -#if BEIHAI_ENABLE_TOOL_AGENT != 0 - /* 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; -#if BEIHAI_ENABLE_TOOL_AGENT != 0 - } -#endif - - 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); - } - - return !check_exception(); -} - -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); - - if (!ref.val) { - jeff_runtime_pop_local_object_ref(1); - return NULL; - } - - 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; -} - -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; - } - } - - 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; - } - - 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"); - - 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; - } - } - 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; - } - } - break; - } - - 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; - } - } - break; - } - - 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); - } - - 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; - - dev_info = (ble_device_info *)ble_msg->payload; - - 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_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; - } - - case TIMER_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; - - attr_container_destroy(event); - APP_MGR_FREE(sensor_event); - } - break; - } - - case BLE_EVENT: - { - if (msg->payload) { - app_instance_free_ble_msg(msg->payload); - APP_MGR_FREE(msg->payload); - } - break; - } - - case GPIO_INTERRUPT_EVENT: - { - break; - } - - default: - { - break; - } - } - - APP_MGR_FREE(msg); -} - -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]; - - if (app_manager_is_interrupting_module(Module_Jeff)) { - app_instance_queue_free_callback(queue_msg); - return; - } - - 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; - } - - jeff_runtime_push_local_object_ref(&ref); - ref.val = (JeffObjectRef)req_obj; - - req_obj->mid = req_msg->mid; - req_obj->action = req_msg->action; - req_obj->fmt = req_msg->fmt; - - /* 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; - } - } - - /* 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; - } - - /* 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; - } - - 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; - } - - case BLE_EVENT: - { - if (msg->payload) { - app_instance_process_ble_msg(msg->payload); - APP_MGR_FREE(msg->payload); - } - break; - } - - 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; - } - - default: - { - app_manager_printf( - "Invalid message type of applet queue message.\n"); - break; - } - } - - APP_MGR_FREE(msg); -} - -static JeffClassHeaderLinked * -find_main_class(JeffFileHeaderLinked *main_file) -{ - JeffClassHeaderLinked *c = NULL, *ci; - unsigned int i; - - for (i = 0; i < main_file->internal_class_count; i++) { - ci = main_file->class_header[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; - } - - c = ci; - } - } - - if (!c) - jeff_printe_no_main_class(); - - 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]; - - app_manager_printf("Java Applet '%s' started\n", m_data->module_name); - -#if BEIHAI_ENABLE_TOOL_AGENT != 0 - 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 */ - if (!app_manager_initialize_class(object_class)) { - app_manager_printf("Call fail\n"); - goto fail; - } - - /* Initialize applet object which call */ - if (!app_manager_initialize_object(applet_data->applet_obj)) { - app_manager_printf("Call 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 - */ - 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; -} - -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) - return true; -#endif - - 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; - - 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; - } - - /* 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; - } - - /* Check applet name */ - applet_name = attr_container_get_as_string(attr_cont, "name"); - - if (!applet_name || strlen(applet_name) == 0) { - SEND_ERR_RESPONSE(msg->mid, - "Install Applet failed: invalid applet name."); - return false; - } - - if (app_manager_lookup_module_data(applet_name)) { - SEND_ERR_RESPONSE(msg->mid, - "Install Applet failed: applet already installed."); - 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); - - /* 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; - } - - /* 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; - } - - 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")) - 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; - } - - 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) - heap_size = MIN_APPLET_HEAP_SIZE; - else if (heap_size > MAX_APPLET_HEAP_SIZE) - heap_size = MAX_APPLET_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 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; - } - -#if BEIHAI_ENABLE_TOOL_AGENT != 0 - /* 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; - - /* 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; - } - - /* 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; - } -#endif - - app_manager_printf("Install Applet success!\n"); - app_send_response_to_host(msg->mid, CREATED_2_01, NULL); /* CREATED */ - return true; - -fail6: -#if BEIHAI_ENABLE_TOOL_AGENT != 0 - if (debug) - bh_queue_destroy(applet_data->tool_agent_queue); -#endif - -fail5_1: - watchdog_timer_destroy(&m_data->wd_timer); - -fail5: - gc_destroy_for_instance(m_data->heap); - -fail4: - bh_queue_destroy(m_data->queue, NULL); - -fail3_1: - APP_MGR_FREE(applet_data->perms); - -fail3: - APP_MGR_FREE(applet_data); - -fail2: - jeff_runtime_unload(main_file); - -fail1: - APP_MGR_FREE(main_file); - - return false; -} - -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); - - /* Destroy queue */ - bh_queue_destroy(m_data->queue, app_instance_queue_free_callback); - - /* Destroy heap */ - gc_destroy_for_instance(m_data->heap); - - /* 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); -} - -/* 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 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 - app_manager_printf("Uninstall Applet failed: invalid url."); - return false; - } - - 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 - app_manager_printf("Uninstall Applet failed: invalid applet name."); - 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 - app_manager_printf("Uninstall Applet failed: no applet found."); - 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 - app_manager_printf("Uninstall Applet failed: invalid module type."); - 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); - - 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); - } -#endif - - /* 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); - - cleanup_applet_resource(m_data); - app_manager_post_applets_update_event(); - - app_manager_printf("Uninstall Applet success!\n"); - - if (!do_not_reply) - app_send_response_to_host(msg->mid, DELETED_2_02, NULL); /* DELETED */ - return true; -} - -#define PERM_PREFIX "AEE.permission." - -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 - || *(p = perm + strlen(prefix)) == '\0') - return false; - - do { - if (!(*p == '.' || ('A' <= *p && *p <= 'Z') - || ('a' <= *p && *p <= 'z'))) - return false; - } while (*++p != '\0'); - - return true; -} - -static bool -match(const char *haystack, const char *needle, char delim) -{ - const char *p = needle; - - if (haystack == NULL || *haystack == '\0' || needle == NULL - || *needle == '\0') - return false; - - while (true) { - while (true) { - if ((*haystack == '\0' || *haystack == delim) && *p == '\0') { - return true; - } - else if (*p == *haystack) { - ++p; - ++haystack; - } - 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 } }; - - /* 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.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.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; - } - - /* 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( - "com.intel.aee.ble.BLEGattService"); - 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( - "com.intel.aee.ble.BLEGattCharacteristic"); - 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( - "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; - } - - /* 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.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.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.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.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.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.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,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) */ - 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) */ - 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; - } - - 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; - } - - return true; -} - -static void -jeff_module_watchdog_kill(module_data *m_data) -{ - jeff_applet_data *applet_data = (jeff_applet_data *)m_data->internal_data; - - app_manager_printf("Watchdog interrupt the applet %s\n", - m_data->module_name); - - jeff_runtime_interrupt_instance(applet_data->vm_instance, true); - - /* Exit applet queue loop run */ - bh_queue_exit_loop_run(m_data->queue); - - /* 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); - - 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); */ - } - - 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') - 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); - - /* 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; - } - - 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); */ - } - - return true; - } - } -#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; -} - -#if BEIHAI_ENABLE_TOOL_AGENT != 0 - -#define JDWP_HANDSHAKE_MAGIC "JDWP-Handshake" -#define JDWP_HANDSHAKE_LEN (sizeof(JDWP_HANDSHAKE_MAGIC) - 1) - -#define JDWP_PAYLOAD_KEY "jdwp" - -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; - - 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); - - if (payload) - attr_container_destroy(payload); - - 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_packet_response(int mid, int code, JeffBuffer *packet) -{ - int size; - - 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); -} - -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))) - return; - - 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)) - 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."); - 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. */ - 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); - } - 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); - } - - APP_MGR_FREE(msg); -} - -void -tool_agent_queue_free_callback(void *message) -{ - bh_queue_msg_t *msg = (bh_queue_msg_t *)message; - - if (msg->message_type == JDWP_REQUEST) { - bh_request_msg_t *req_msg = (bh_request_msg_t *)msg->payload; - APP_MGR_FREE(req_msg); - } - - APP_MGR_FREE(msg); -} - -#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 diff --git a/core/app-mgr/app-manager/module_jeff.h b/core/app-mgr/app-manager/module_jeff.h deleted file mode 100644 index bb39f27e4..000000000 --- a/core/app-mgr/app-manager/module_jeff.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _MODULE_JEFF_H_ -#define _MODULE_JEFF_H_ - -#include "app_manager.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern module_interface jeff_module_interface; - -/* sensor event */ -typedef struct bh_sensor_event_t { - /* Java sensor object */ - void *sensor; - /* event of attribute container from context core */ - void *event; -} bh_sensor_event_t; - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif /* _MODULE_JEFF_H_ */ diff --git a/core/app-mgr/app-manager/module_utils.c b/core/app-mgr/app-manager/module_utils.c deleted file mode 100644 index b4b25e4a9..000000000 --- a/core/app-mgr/app-manager/module_utils.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "app_manager.h" -#include "app_manager_host.h" -#include "bh_platform.h" -#include "bi-inc/attr_container.h" -#include "event.h" -#include "watchdog.h" -#include "coap_ext.h" - -/* Lock of the module data list */ -korp_mutex module_data_list_lock; - -/* Module data list */ -module_data *module_data_list; - -bool -module_data_list_init() -{ - module_data_list = NULL; - return !os_mutex_init(&module_data_list_lock) ? true : false; -} - -void -module_data_list_destroy() -{ - - os_mutex_lock(&module_data_list_lock); - if (module_data_list) { - while (module_data_list) { - module_data *p = module_data_list->next; - APP_MGR_FREE(module_data_list); - module_data_list = p; - } - } - os_mutex_unlock(&module_data_list_lock); - os_mutex_destroy(&module_data_list_lock); -} - -static void -module_data_list_add(module_data *m_data) -{ - static uint32 module_id_max = 1; - os_mutex_lock(&module_data_list_lock); - // reserve some special ID - // TODO: check the new id is not already occupied! - if (module_id_max == 0xFFFFFFF0) - module_id_max = 1; - m_data->id = module_id_max++; - if (!module_data_list) { - module_data_list = m_data; - } - else { - /* Set as head */ - m_data->next = module_data_list; - module_data_list = m_data; - } - os_mutex_unlock(&module_data_list_lock); -} - -void -module_data_list_remove(module_data *m_data) -{ - os_mutex_lock(&module_data_list_lock); - if (module_data_list) { - if (module_data_list == m_data) - module_data_list = module_data_list->next; - else { - /* Search and remove it */ - module_data *p = module_data_list; - - while (p && p->next != m_data) - p = p->next; - if (p && p->next == m_data) - p->next = p->next->next; - } - } - os_mutex_unlock(&module_data_list_lock); -} - -module_data * -module_data_list_lookup(const char *module_name) -{ - os_mutex_lock(&module_data_list_lock); - if (module_data_list) { - module_data *p = module_data_list; - - while (p) { - /* Search by module name */ - if (!strcmp(module_name, p->module_name)) { - os_mutex_unlock(&module_data_list_lock); - return p; - } - p = p->next; - } - } - os_mutex_unlock(&module_data_list_lock); - return NULL; -} - -module_data * -module_data_list_lookup_id(unsigned int module_id) -{ - os_mutex_lock(&module_data_list_lock); - if (module_data_list) { - module_data *p = module_data_list; - - while (p) { - /* Search by module name */ - if (module_id == p->id) { - os_mutex_unlock(&module_data_list_lock); - return p; - } - p = p->next; - } - } - os_mutex_unlock(&module_data_list_lock); - return NULL; -} - -module_data * -app_manager_get_module_data(uint32 module_type, void *module_inst) -{ - 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 NULL; -} - -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 * -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) -{ - module_data *m_data = app_manager_get_module_data(module_type, module_inst); - return m_data ? m_data->id : ID_NONE; -} - -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 * -app_manager_lookup_module_data(const char *name) -{ - return module_data_list_lookup(name); -} - -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) -{ - module_data_list_remove(m_data); - - release_module(m_data); -} - -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); - -void -release_module(module_data *m_data) -{ - watchdog_timer_destroy(&m_data->wd_timer); - -#ifdef HEAP_ENABLED /* TODO */ - if (m_data->heap) - gc_destroy_for_instance(m_data->heap); -#endif - - if (m_data->queue) - bh_queue_destroy(m_data->queue); - - m_data->timer_ctx = NULL; - - destroy_module_timer_ctx(m_data->id); - - APP_MGR_FREE(m_data); -} - -uint32 -check_modules_timer_expiry() -{ - os_mutex_lock(&module_data_list_lock); - module_data *p = module_data_list; - uint32 ms_to_expiry = (uint32)-1; - - while (p) { - uint32 next = get_expiry_ms(p->timer_ctx); - if (next != (uint32)-1) { - if (ms_to_expiry == (uint32)-1 || ms_to_expiry > next) - ms_to_expiry = next; - } - - p = p->next; - } - os_mutex_unlock(&module_data_list_lock); - return ms_to_expiry; -} diff --git a/core/app-mgr/app-manager/module_wasm_app.h b/core/app-mgr/app-manager/module_wasm_app.h deleted file mode 100644 index 8a7ae4e54..000000000 --- a/core/app-mgr/app-manager/module_wasm_app.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _MODULE_WASM_APP_H_ -#define _MODULE_WASM_APP_H_ - -#include "bh_queue.h" -#include "app_manager_export.h" -#include "wasm_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SECTION_TYPE_USER 0 -#define SECTION_TYPE_TYPE 1 -#define SECTION_TYPE_IMPORT 2 -#define SECTION_TYPE_FUNC 3 -#define SECTION_TYPE_TABLE 4 -#define SECTION_TYPE_MEMORY 5 -#define SECTION_TYPE_GLOBAL 6 -#define SECTION_TYPE_EXPORT 7 -#define SECTION_TYPE_START 8 -#define SECTION_TYPE_ELEM 9 -#define SECTION_TYPE_CODE 10 -#define SECTION_TYPE_DATA 11 - -typedef enum AOTSectionType { - AOT_SECTION_TYPE_TARGET_INFO = 0, - AOT_SECTION_TYPE_INIT_DATA = 1, - AOT_SECTION_TYPE_TEXT = 2, - AOT_SECTION_TYPE_FUNCTION = 3, - AOT_SECTION_TYPE_EXPORT = 4, - AOT_SECTION_TYPE_RELOCATION = 5, - AOT_SECTION_TYPE_SIGANATURE = 6, - AOT_SECTION_TYPE_CUSTOM = 100, -} AOTSectionType; - -enum { - WASM_Msg_Start = BASE_EVENT_MAX, - TIMER_EVENT_WASM, - SENSOR_EVENT_WASM, - CONNECTION_EVENT_WASM, - WIDGET_EVENT_WASM, - WASM_Msg_End = WASM_Msg_Start + 100 -}; - -typedef struct wasm_data { - /* for easily access the containing wasm module */ - wasm_module_t wasm_module; - wasm_module_inst_t wasm_module_inst; - /* Permissions of the WASM app */ - char *perms; - /* thread list mapped with this WASM module */ - korp_tid thread_id; - /* for easily access the containing module data */ - module_data *m_data; - /* is bytecode or aot */ - bool is_bytecode; - /* sections of wasm bytecode or aot file */ - void *sections; - /* execution environment */ - wasm_exec_env_t exec_env; -} wasm_data; - -/* sensor event */ -typedef struct _sensor_event_data { - uint32 sensor_id; - - int data_fmt; - /* event of attribute container from context core */ - void *data; -} sensor_event_data_t; - -/* WASM Bytecode File */ -typedef struct wasm_bytecode_file { - /* magics */ - int magic; - /* current version */ - int version; - /* WASM section list */ - wasm_section_list_t sections; - /* Last WASM section in the list */ - wasm_section_t *section_end; -} wasm_bytecode_file_t; - -/* WASM AOT File */ -typedef struct wasm_aot_file { - /* magics */ - int magic; - /* current version */ - int version; - /* AOT section list */ - aot_section_list_t sections; - /* Last AOT section in the list */ - aot_section_t *section_end; -} wasm_aot_file_t; - -/* WASM App File */ -typedef struct wasm_app_file_t { - union { - wasm_bytecode_file_t bytecode; - wasm_aot_file_t aot; - } u; -} 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); - -typedef void (*resource_cleanup_handler_t)(uint32 module_id); -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. - * - * @param root_dir the root dir to set - * @return true for success, false otherwise - */ -bool -wasm_set_wasi_root_dir(const char *root_dir); - -/** - * Get WASI root dir - * - * @return the WASI root dir - */ -const char * -wasm_get_wasi_root_dir(); - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif /* _MODULE_WASM_APP_H_ */ diff --git a/core/app-mgr/app-manager/module_wasm_lib.c b/core/app-mgr/app-manager/module_wasm_lib.c deleted file mode 100644 index 0b5c07ea7..000000000 --- a/core/app-mgr/app-manager/module_wasm_lib.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "module_wasm_lib.h" - -static bool -wasm_lib_module_init(void) -{ - return false; -} - -static bool -wasm_lib_module_install(request_t *msg) -{ - (void)msg; - return false; -} - -static bool -wasm_lib_module_uninstall(request_t *msg) -{ - (void)msg; - return false; -} - -static void -wasm_lib_module_watchdog_kill(module_data *m_data) -{ - (void)m_data; -} - -static bool -wasm_lib_module_handle_host_url(void *queue_msg) -{ - (void)queue_msg; - return false; -} - -static module_data * -wasm_lib_module_get_module_data(void *inst) -{ - (void)inst; - return 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 */ diff --git a/core/app-mgr/app-manager/module_wasm_lib.h b/core/app-mgr/app-manager/module_wasm_lib.h deleted file mode 100644 index 63ffd92b5..000000000 --- a/core/app-mgr/app-manager/module_wasm_lib.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _MODULE_WASM_LIB_H_ -#define _MODULE_WASM_LIB_H_ - -#include "app_manager.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern module_interface wasm_lib_module_interface; - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif /* _MODULE_WASM_LIB_H_ */ diff --git a/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c b/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c deleted file mode 100644 index 1c7409f55..000000000 --- a/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c +++ /dev/null @@ -1 +0,0 @@ -#include "../linux/app_mgr_linux.c" diff --git a/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c b/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c deleted file mode 100644 index 5e51788bc..000000000 --- a/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "app_manager.h" - -void * -app_manager_timer_create(void (*timer_callback)(void *), - watchdog_timer *wd_timer) -{ - /* TODO */ - return NULL; -} - -void -app_manager_timer_destroy(void *timer) -{ - /* TODO */ -} - -void -app_manager_timer_start(void *timer, int timeout) -{ - /* TODO */ -} - -void -app_manager_timer_stop(void *timer) -{ - /* TODO */ -} - -watchdog_timer * -app_manager_get_wd_timer_from_timer_handle(void *timer) -{ - /* TODO */ - return NULL; -} - -int -app_manager_signature_verify(const uint8_t *file, unsigned int file_len, - const uint8_t *signature, unsigned int sig_size) -{ - return 1; -} diff --git a/core/app-mgr/app-manager/resource_reg.c b/core/app-mgr/app-manager/resource_reg.c deleted file mode 100644 index 4e930890e..000000000 --- a/core/app-mgr/app-manager/resource_reg.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "native_interface.h" -#include "app_manager.h" -#include "app_manager_export.h" -#include "bi-inc/shared_utils.h" -#include "bi-inc/attr_container.h" -#include "coap_ext.h" - -typedef struct _app_res_register { - struct _app_res_register *next; - char *url; - void (*request_handler)(request_t *, void *); - uint32 register_id; -} app_res_register_t; - -static app_res_register_t *g_resources = NULL; - -void -module_request_handler(request_t *request, void *user_data) -{ - unsigned int mod_id = (unsigned int)(uintptr_t)user_data; - bh_message_t msg; - module_data *m_data; - request_t *req; - - /* Check module name */ - m_data = module_data_list_lookup_id(mod_id); - if (!m_data) { - return; - } - - if (m_data->wd_timer.is_interrupting) { - return; - } - - req = clone_request(request); - if (!req) { - return; - } - - /* Set queue message and send to applet's queue */ - msg = bh_new_msg(RESTFUL_REQUEST, req, sizeof(*req), request_cleaner); - if (!msg) { - request_cleaner(req); - return; - } - - if (!bh_post_msg2(m_data->queue, msg)) { - return; - } - - app_manager_printf("Send request to app %s success.\n", - m_data->module_name); -} - -void -targeted_app_request_handler(request_t *request, void *unused) -{ - char applet_name[128] = { 0 }; - int offset; - char *url = request->url; - module_data *m_data; - - offset = check_url_start(request->url, strlen(request->url), "/app/"); - - if (offset <= 0) { - return; - } - - strncpy(applet_name, request->url + offset, sizeof(applet_name) - 1); - char *p = strchr(applet_name, '/'); - if (p) { - *p = 0; - } - else - return; - app_manager_printf("Send request to applet: %s\n", applet_name); - - request->url = p + 1; - - /* Check module name */ - m_data = module_data_list_lookup(applet_name); - if (!m_data) { - SEND_ERR_RESPONSE(request->mid, - "Send request to applet failed: invalid applet name"); - goto end; - } - - module_request_handler(request, (void *)(uintptr_t)m_data->id); -end: - request->url = url; -} - -void -am_send_response(response_t *response) -{ - module_data *m_data; - - // if the receiver is not any of modules, just forward it to the host - 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); - if (!resp_for_send) { - return; - } - - bh_message_t msg = bh_new_msg(RESTFUL_RESPONSE, resp_for_send, - sizeof(*resp_for_send), response_cleaner); - if (!msg) { - response_cleaner(resp_for_send); - return; - } - - if (!bh_post_msg2(m_data->queue, msg)) { - return; - } - } -} - -void * -am_dispatch_request(request_t *request) -{ - app_res_register_t *r = g_resources; - - while (r) { - if (check_url_start(request->url, strlen(request->url), r->url) > 0) { - r->request_handler(request, (void *)(uintptr_t)r->register_id); - return r; - } - r = r->next; - } - return NULL; -} - -bool -am_register_resource(const char *url, - void (*request_handler)(request_t *, void *), - uint32 register_id) -{ - app_res_register_t *r = g_resources; - int register_num = 0; - - while (r) { - if (strcmp(r->url, url) == 0) { - return false; - } - - if (r->register_id == register_id) - register_num++; - - r = r->next; - } - - if (strlen(url) > RESOUCE_EVENT_URL_LEN_MAX) - return false; - - if (register_num >= RESOURCE_REGISTRATION_NUM_MAX) - return false; - - r = (app_res_register_t *)APP_MGR_MALLOC(sizeof(app_res_register_t)); - if (r == NULL) - return false; - - memset(r, 0, sizeof(*r)); - r->url = bh_strdup(url); - if (r->url == NULL) { - APP_MGR_FREE(r); - return false; - } - - r->request_handler = request_handler; - r->next = g_resources; - r->register_id = register_id; - g_resources = r; - - return true; -} - -void -am_cleanup_registeration(uint32 register_id) -{ - app_res_register_t *r = g_resources; - app_res_register_t *prev = NULL; - - while (r) { - app_res_register_t *next = r->next; - - if (register_id == r->register_id) { - if (prev) - prev->next = next; - else - g_resources = next; - - APP_MGR_FREE(r->url); - APP_MGR_FREE(r); - } - else - /* if r is freed, should not change prev. Only set prev to r - when r isn't freed. */ - prev = r; - - r = next; - } -} diff --git a/core/app-mgr/app-manager/watchdog.c b/core/app-mgr/app-manager/watchdog.c deleted file mode 100644 index ba5bb05f5..000000000 --- a/core/app-mgr/app-manager/watchdog.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "watchdog.h" -#include "bh_platform.h" - -#define WATCHDOG_THREAD_PRIORITY 5 - -/* Queue of watchdog */ -static bh_queue *watchdog_queue; - -#ifdef WATCHDOG_ENABLED /* TODO */ -static void -watchdog_timer_callback(void *timer) -{ - watchdog_timer *wd_timer = - app_manager_get_wd_timer_from_timer_handle(timer); - - watchdog_timer_stop(wd_timer); - - os_mutex_lock(&wd_timer->lock); - - if (!wd_timer->is_stopped) { - - wd_timer->is_interrupting = true; - - bh_post_msg(watchdog_queue, WD_TIMEOUT, wd_timer->module_data, - sizeof(module_data)); - } - - os_mutex_unlock(&wd_timer->lock); -} -#endif - -bool -watchdog_timer_init(module_data *m_data) -{ -#ifdef WATCHDOG_ENABLED /* TODO */ - watchdog_timer *wd_timer = &m_data->wd_timer; - - if (0 != os_mutex_init(&wd_timer->lock)) - return false; - - if (!(wd_timer->timer_handle = - app_manager_timer_create(watchdog_timer_callback, wd_timer))) { - os_mutex_destroy(&wd_timer->lock); - return false; - } - - wd_timer->module_data = m_data; - wd_timer->is_interrupting = false; - wd_timer->is_stopped = false; -#endif - return true; -} - -void -watchdog_timer_destroy(watchdog_timer *wd_timer) -{ -#ifdef WATCHDOG_ENABLED /* TODO */ - app_manager_timer_destroy(wd_timer->timer_handle); - os_mutex_destroy(&wd_timer->lock); -#endif -} - -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); - - os_mutex_unlock(&wd_timer->lock); -} - -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) -{ - if (bh_message_type(queue_msg) == WD_TIMEOUT) { - 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( - m_data); - app_manager_post_applets_update_event(); - } - } -} -#endif - -#ifdef WATCHDOG_ENABLED /* TODO */ -static void * -watchdog_thread_routine(void *arg) -{ - /* Enter loop run */ - bh_queue_enter_loop_run(watchdog_queue, watchdog_queue_callback); - - (void)arg; - return NULL; -} -#endif - -bool -watchdog_startup() -{ - if (!(watchdog_queue = bh_queue_create())) { - app_manager_printf( - "App Manager start failed: create watchdog queue failed.\n"); - return false; - } -#if 0 -//todo: enable watchdog - /* Start watchdog thread */ - if (!jeff_runtime_create_supervisor_thread_with_prio(watchdog_thread_routine, NULL, - WATCHDOG_THREAD_PRIORITY)) { - bh_queue_destroy(watchdog_queue); - return false; - } -#endif - return true; -} - -void -watchdog_destroy() -{ - bh_queue_exit_loop_run(watchdog_queue); - bh_queue_destroy(watchdog_queue); -} diff --git a/core/app-mgr/app-manager/watchdog.h b/core/app-mgr/app-manager/watchdog.h deleted file mode 100644 index d960df03b..000000000 --- a/core/app-mgr/app-manager/watchdog.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _WATCHDOG_H_ -#define _WATCHDOG_H_ - -#include "app_manager.h" - -#ifdef __cplusplus -extern "C" { -#endif - -bool -watchdog_timer_init(module_data *module_data); - -void -watchdog_timer_destroy(watchdog_timer *wd_timer); - -void -watchdog_timer_start(watchdog_timer *wd_timer); - -void -watchdog_timer_stop(watchdog_timer *wd_timer); - -watchdog_timer * -app_manager_get_watchdog_timer(void *timer); - -bool -watchdog_startup(); - -void -watchdog_destroy(); - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif /* _WATCHDOG_H_ */ diff --git a/core/app-mgr/app-mgr-shared/app_manager_export.h b/core/app-mgr/app-mgr-shared/app_manager_export.h deleted file mode 100644 index 54b59b944..000000000 --- a/core/app-mgr/app-mgr-shared/app_manager_export.h +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _APP_MANAGER_EXPORT_H_ -#define _APP_MANAGER_EXPORT_H_ - -#include "native_interface.h" -#include "bi-inc/shared_utils.h" -#include "bh_queue.h" -#include "host_link.h" -#include "runtime_timer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Special module IDs */ -#define ID_HOST -3 -#define ID_APP_MGR -2 -/* Invalid module ID */ -#define ID_NONE ((uint32)-1) - -struct attr_container; - -/* Queue message type */ -typedef enum QUEUE_MSG_TYPE { - COAP_PARSED = LINK_MSG_TYPE_MAX + 1, - RESTFUL_REQUEST, - RESTFUL_RESPONSE, - TIMER_EVENT = 5, - SENSOR_EVENT = 6, - GPIO_INTERRUPT_EVENT = 7, - BLE_EVENT = 8, - JDWP_REQUEST = 9, - WD_TIMEOUT = 10, - BASE_EVENT_MAX = 100 - -} QUEUE_MSG_TYPE; - -typedef enum { - Module_Jeff, - Module_WASM_App, - Module_WASM_Lib, - Module_Max -} Module_Type; - -struct module_data; - -/* Watchdog timer of module */ -typedef struct watchdog_timer { - /* Timer handle of the platform */ - void *timer_handle; - /* Module of the watchdog timer */ - struct module_data *module_data; - /* Lock of the watchdog timer */ - korp_mutex lock; - /* Flag indicates module is being interrupted by watchdog */ - bool is_interrupting; - /* Flag indicates watchdog timer is stopped */ - bool is_stopped; -} watchdog_timer; - -typedef struct module_data { - struct module_data *next; - - /* ID of the module */ - uint32 id; - - /* Type of the module */ - Module_Type module_type; - - /* Heap of the module */ - void *heap; - - /* Heap size of the module */ - int heap_size; - - /* Module execution timeout in millisecond */ - int timeout; - - /* Queue of the module */ - bh_queue *queue; - - /* Watchdog timer of the module*/ - struct watchdog_timer wd_timer; - - timer_ctx_t timer_ctx; - - /* max timers number app can create */ - int timers; - - /* Internal data of the module */ - void *internal_data; - - /* Module name */ - char module_name[1]; -} module_data; - -/* Module function types */ -typedef bool (*module_init_func)(void); -typedef bool (*module_install_func)(request_t *msg); -typedef bool (*module_uninstall_func)(request_t *msg); -typedef void (*module_watchdog_kill_func)(module_data *module_data); -typedef bool (*module_handle_host_url_func)(void *queue_msg); -typedef module_data *(*module_get_module_data_func)(void *inst); - -/** - * @typedef module_on_install_request_byte_arrive_func - * - * @brief Define the signature of function to handle one byte of - * module app install request for struct module_interface. - * - * @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 - * - * @return true if success, false otherwise - */ -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 { - module_init_func module_init; - module_install_func module_install; - module_uninstall_func module_uninstall; - module_watchdog_kill_func module_watchdog_kill; - module_handle_host_url_func module_handle_host_url; - module_get_module_data_func module_get_module_data; - module_on_install_request_byte_arrive_func module_on_install; -} module_interface; - -/** - * @typedef host_init_func - * @brief Define the host initialize callback function signature for - * struct host_interface. - * - * @return true if success, false if fail - */ -typedef bool (*host_init_func)(void); - -/** - * @typedef host_send_fun - * @brief Define the host send callback function signature for - * struct host_interface. - * - * @param buf data buffer to send. - * @param size size of the data to send. - * - * @return size of the data sent in bytes - */ -typedef int (*host_send_fun)(void *ctx, const char *buf, int size); - -/** - * @typedef host_destroy_fun - * @brief Define the host receive callback function signature for - * struct host_interface. - * - */ -typedef void (*host_destroy_fun)(); - -/* Interfaces of host communication */ -typedef struct host_interface { - host_init_func init; - host_send_fun send; - host_destroy_fun destroy; -} host_interface; - -/** - * Initialize communication with Host - * - * @param interface host communication interface - * - * @return true if success, false otherwise - */ -bool -app_manager_host_init(host_interface *intf); - -/* Startup app manager */ -void -app_manager_startup(host_interface *intf); - -/* Return whether app manager is started */ -bool -app_manager_is_started(void); - -/* Get queue of current applet */ -void * -app_manager_get_module_queue(uint32 module_type, void *module_inst); - -/* Get applet name of current applet */ -const char * -app_manager_get_module_name(uint32 module_type, void *module_inst); - -/* Get heap of current applet */ -void * -app_manager_get_module_heap(uint32 module_type, void *module_inst); - -void * -get_app_manager_queue(); - -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 * -app_manager_lookup_module_data(const char *name); - -module_data * -module_data_list_lookup(const char *module_name); - -module_data * -module_data_list_lookup_id(unsigned int module_id); - -void -app_manager_post_applets_update_event(); - -bool -am_register_resource(const char *url, - void (*request_handler)(request_t *, void *), - uint32 register_id); - -void -am_cleanup_registeration(uint32 register_id); - -bool -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_dispatch_request(request_t *request); - -void -am_send_response(response_t *response); - -void -module_request_handler(request_t *request, void *user_data); - -/** - * Send request message to host - * - * @param msg the request or event message. - * It is event when msg->action==COAP_EVENT - * - * @return true if success, false otherwise - */ -bool -send_request_to_host(request_t *msg); - -/** - * Send response message to host - * - * @param msg the response message - * - * @return true if success, false otherwise - */ -bool -send_response_to_host(response_t *msg); - -/** - * Send response with mid and code to host - * - * @param mid the message id of response - * @param code the code/status of response - * @param msg the detailed message - * - * @return true if success, false otherwise - */ -bool -send_error_response_to_host(int mid, int code, const char *msg); - -/** - * Check whether the applet has the permission - * - * @param perm the permission needed to check - * - * @return true if success, false otherwise - */ -bool -bh_applet_check_permission(const char *perm); - -/** - * Send message to Host - * - * @param buf buffer to send - * @param size size of buffer - * - * @return size of buffer sent - */ -int -app_manager_host_send_msg(int msg_type, const char *buf, int size); - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif diff --git a/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake b/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake deleted file mode 100644 index f370e8b29..000000000 --- a/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (APP_MGR_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${APP_MGR_SHARED_DIR}) - - -file (GLOB_RECURSE source_all ${APP_MGR_SHARED_DIR}/*.c) - -set (APP_MGR_SHARED_SOURCE ${source_all}) - -file (GLOB header - ${APP_MGR_SHARED_DIR}/*.h -) -LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header}) diff --git a/core/app-mgr/app-mgr-shared/host_link.h b/core/app-mgr/app-mgr-shared/host_link.h deleted file mode 100644 index e3a37fb40..000000000 --- a/core/app-mgr/app-mgr-shared/host_link.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef DEPS_APP_MGR_APP_MGR_SHARED_HOST_LINK_H_ -#define DEPS_APP_MGR_APP_MGR_SHARED_HOST_LINK_H_ - -typedef enum LINK_MSG_TYPE { - COAP_TCP_RAW = 0, - COAP_UDP_RAW = 1, - REQUEST_PACKET, - RESPONSE_PACKET, - INSTALL_WASM_APP, - CBOR_GENERIC = 30, - - LINK_MSG_TYPE_MAX = 50 -} LINK_MSG_TYPE; - -/* Link message, or message between host and app manager */ -typedef struct bh_link_msg_t { - /* 2 bytes leading */ - uint16_t leading_bytes; - /* message type, must be COAP_TCP or COAP_UDP */ - uint16_t message_type; - /* size of payload */ - uint32_t payload_size; - char *payload; -} bh_link_msg_t; - -#endif /* DEPS_APP_MGR_APP_MGR_SHARED_HOST_LINK_H_ */ diff --git a/core/app-mgr/module.json b/core/app-mgr/module.json deleted file mode 100644 index b2faeca5f..000000000 --- a/core/app-mgr/module.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "name": "aee", - "version": "0.0.1", - "description": "aee", - "type": "source", - "category": "middleware", - "arch": "x86, arc, posix", - "includes": [ - "Beihai/classlib/include", - "Beihai/runtime/include", - "Beihai/runtime/platform/include", - "Beihai/runtime/platform/zephyr", - "Beihai/runtime/utils/coap/er-coap", - "Beihai/runtime/utils/coap/extension", - "iwasm/runtime/include", - "iwasm/runtime/platform/include", - "iwasm/runtime/platform/zephyr", - "iwasm/runtime/vmcore_wasm" - ], - "sources": [ - "Beihai/classlib/native/internal/*.c", - "Beihai/classlib/native/*.c", - "Beihai/runtime/gc/*.c", - "Beihai/runtime/platform/zephyr/*.c", - "Beihai/runtime/utils/*.c", - "Beihai/runtime/utils/coap/er-coap/*.c", - "Beihai/runtime/utils/coap/extension/*.c", - "Beihai/runtime/vmcore_jeff/*.c", - "app-manager/app-manager.c", - "app-manager/app-manager-host.c", - "app-manager/app_mgr_zephyr.c", - "app-manager/event.c", - "app-manager/message.c", - "app-manager/module_jeff.c", - "app-manager/module_wasm_lib.c", - "app-manager/module_wasm_app.c", - "app-manager/watchdog.c", - "Beihai/products/iMRT/*.c", - "iwasm/runtime/utils/*.c", - "iwasm/runtime/platform/zephyr/*.c", - "iwasm/runtime/vmcore_wasm/*.c", - "iwasm/lib/lib-export\.c", - "iwasm/lib/aee/*.c", - "iwasm/products/zephyr/sample/src/*.c" - ], - "compile_definitions": [ - "__JLF__", - "__ZEPHYR__" - ], - "target": "aee", - "dependencies": [] -} diff --git a/core/deps/download.sh b/core/deps/download.sh deleted file mode 100755 index 46b30d7ef..000000000 --- a/core/deps/download.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -DEPS_ROOT=$(cd "$(dirname "$0")/" && pwd) -cd ${DEPS_ROOT} - - -if [ ! -d "lvgl" ]; then - echo "git pull lvgl..." - git clone https://github.com/lvgl/lvgl.git --branch v6.0.1 - [ $? -eq 0 ] || exit $? - - ../app-framework/wgl/app/prepare_headers.sh -fi -if [ ! -d "lv_drivers" ]; then - echo "git pull lv_drivers..." - git clone https://github.com/lvgl/lv_drivers.git --branch v6.0.1 - [ $? -eq 0 ] || exit $? -fi - -exit 0 diff --git a/doc/export_native_api.md b/doc/export_native_api.md index ed7385539..a4123d12c 100644 --- a/doc/export_native_api.md +++ b/doc/export_native_api.md @@ -211,17 +211,17 @@ API that way unless necessary because it needs extra carefulness. We must do data serialization for passing structured data or class objects between the two worlds of WASM and native. There are two serialization methods available in WASM as below, and yet you can introduce more like json, cbor etc. -- [attributes container](../core/app-framework/app-native-shared/attr_container.c) -- [restful request/response](../core/app-framework/app-native-shared/restful_utils.c) +- [attributes container](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/app-native-shared/attr_container.c) +- [restful request/response](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/app-native-shared/restful_utils.c) -Note the serialization library is separately compiled into WASM and runtime. And the source files are located in the folder "[core/app-framework/app-native-shared](../core/app-framework/app-native-shared)“ where all source files will be compiled into both worlds. +Note the serialization library is separately compiled into WASM and runtime. And the source files are located in the folder "[wamr-app-framework/app-framework/app-native-shared](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/app-native-shared)“ where all source files will be compiled into both worlds. The following sample code demonstrates WASM app packs a response structure to buffer, then pass the buffer pointer to the native: ```c -/*** file name: core/app-framework/base/app/request.c ***/ +/*** file name: https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/base/app/request.c ***/ void api_response_send(response_t *response) { @@ -240,7 +240,7 @@ void api_response_send(response_t *response) The following code demonstrates the native API unpack the WASM buffer to local native data structure: ```c -/*** file name: core/app-framework/base/native/request_response.c ***/ +/*** file name: https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/base/native/request_response.c ***/ bool wasm_response_send(wasm_exec_env_t exec_env, char *buffer, int size) diff --git a/doc/wamr_api.md b/doc/wamr_api.md deleted file mode 100644 index 3eff86927..000000000 --- a/doc/wamr_api.md +++ /dev/null @@ -1,351 +0,0 @@ - -WAMR application framework -======================== - -## Application system callbacks -The `on_init` and `on_destroy` functions are wamr application system callbacks which must be implemented in the wasm application if you want to use the APP framework. -``` C -void on_init() -{ - /* - Your init functions here, for example: - * platform initialization - * timer registration - * service / event registration - * ...... - */ -} - -void on_destroy() -{ - /* - your destroy functions here - */ -} -``` - -## Base App library - -The base library of application framework supports the essential API for WASM applications, such as inter-app communication, timers, etc. Other application framework components rely on the base library. - -When building the WAMR SDK, once application framework is enabled, the base library will automatically enabled. - -### Timer -The *timer* API's can be used to create some `soft timers` with single-shot mode or periodic mode. Here is a reference of how to use timer API's to execute a function every one second. -``` C -/* User global variable */ -static int num = 0; - -/* Timer callback */ -void timer1_update(user_timer_t timer) -{ - printf("Timer update %d\n", num++); -} - -void on_init() -{ - user_timer_t timer; - - /* set up a timer */ - timer = api_timer_create(1000, true, false, timer1_update); - api_timer_restart(timer, 1000); -} - -void on_destroy() -{ - -} -``` - -### Micro-service model (request/response) -The microservice model is also known as request and response model. One WASM application acts as the server which provides a specific service. Other WASM applications or host/cloud applications request that service and get the response. - -
- -Below is the reference implementation of the server application. It provides room temperature measurement service. - -``` C -void on_init() -{ - api_register_resource_handler("/room_temp", room_temp_handler); -} - -void on_destroy() -{ -} - -void room_temp_handler(request_t *request) -{ - response_t response[1]; - attr_container_t *payload; - payload = attr_container_create("room_temp payload"); - if (payload == NULL) - return; - - attr_container_set_string(&payload, "temp unit", "centigrade"); - attr_container_set_int(&payload, "value", 26); - - make_response_for_request(request, response); - set_response(response, - CONTENT_2_05, - FMT_ATTR_CONTAINER, - payload, - attr_container_get_serialize_length(payload)); - - api_response_send(response); - attr_container_destroy(payload); -} -``` - - -### Pub/sub model -One WASM application acts as the event publisher. It publishes events to notify WASM applications or host/cloud applications which subscribe to the events. - -
- -Below is the reference implementation of the pub application. It utilizes a timer to repeatedly publish an overheat alert event to the subscriber applications. Then the subscriber applications receive the events immediately. - -``` C -/* Timer callback */ -void timer_update(user_timer_t timer) -{ - attr_container_t *event; - - event = attr_container_create("event"); - attr_container_set_string(&event, - "warning", - "temperature is over high"); - - api_publish_event("alert/overheat", - FMT_ATTR_CONTAINER, - event, - attr_container_get_serialize_length(event)); - - attr_container_destroy(event); -} - -void on_init() -{ - user_timer_t timer; - timer = api_timer_create(1000, true, true, timer_update); -} - -void on_destroy() -{ -} -``` - -Below is the reference implementation of the sub application. -``` C -void overheat_handler(request_t *event) -{ - printf("Event: %s\n", event->url); - - if (event->payload != NULL && event->fmt == FMT_ATTR_CONTAINER) - attr_container_dump((attr_container_t *) event->payload); -} - -void on_init( -{ - api_subscribe_event ("alert/overheat", overheat_handler); -} - -void on_destroy() -{ -} -``` -**Note:** You can also subscribe this event from host side by using host tool. Please refer `samples/simple` project for detail usage. - - -## Sensor API - -The API set is defined in the header file ```core/app-framework/sensor/app/wa-inc/sensor.h```. - -Here is a reference of how to use sensor API's: - -``` C -static sensor_t sensor = NULL; - -/* Sensor event callback*/ -void sensor_event_handler(sensor_t sensor, attr_container_t *event, - void *user_data) -{ - printf("### app get sensor event\n"); - attr_container_dump(event); -} - -void on_init() -{ - char *user_data; - attr_container_t *config; - - printf("### app on_init 1\n"); - /* open a sensor */ - user_data = malloc(100); - printf("### app on_init 2\n"); - sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data); - printf("### app on_init 3\n"); - - /* config the sensor */ - sensor_config(sensor, 1000, 0, 0); - printf("### app on_init 4\n"); -} - -void on_destroy() -{ - if (NULL != sensor) { - sensor_config(sensor, 0, 0, 0); - } -} -``` - -## Connection API: - -The API set is defined in the header file `core/app-framework/connection/app/wa-inc/connection.h` - -Here is a reference of how to use connection API's: -``` C -/* User global variable */ -static int num = 0; -static user_timer_t g_timer; -static connection_t *g_conn = NULL; - -void on_data1(connection_t *conn, - conn_event_type_t type, - const char *data, - uint32 len, - void *user_data) -{ - if (type == CONN_EVENT_TYPE_DATA) { - char message[64] = {0}; - memcpy(message, data, len); - printf("Client got a message from server -> %s\n", message); - } else if (type == CONN_EVENT_TYPE_DISCONNECT) { - printf("connection is close by server!\n"); - } else { - printf("error: got unknown event type!!!\n"); - } -} - -/* Timer callback */ -void timer1_update(user_timer_t timer) -{ - char message[64] = {0}; - /* Reply to server */ - snprintf(message, sizeof(message), "Hello %d", num++); - api_send_on_connection(g_conn, message, strlen(message)); -} - -void my_close_handler(request_t * request) -{ - response_t response[1]; - - if (g_conn != NULL) { - api_timer_cancel(g_timer); - api_close_connection(g_conn); - } - - make_response_for_request(request, response); - set_response(response, DELETED_2_02, 0, NULL, 0); - api_response_send(response); -} - -void on_init() -{ - user_timer_t timer; - attr_container_t *args; - char *str = "this is client!"; - - api_register_resource_handler("/close", my_close_handler); - - args = attr_container_create(""); - attr_container_set_string(&args, "address", "127.0.0.1"); - attr_container_set_uint16(&args, "port", 7777); - - g_conn = api_open_connection("TCP", args, on_data1, NULL); - if (g_conn == NULL) { - printf("connect to server fail!\n"); - return; - } - - printf("connect to server success! handle: %p\n", g_conn); - - /* set up a timer */ - timer = api_timer_create(1000, true, false, timer1_update); - api_timer_restart(timer, 1000); -} - -void on_destroy() -{ - -} -``` - -## GUI API - -The API's is listed in header file ```core/app-framework/wgl/app/wa-inc/wgl.h``` which is implemented based on open source 2D graphic library [LVGL](https://docs.lvgl.io/master/index.html). - -``` C -static void btn_event_cb(wgl_obj_t btn, wgl_event_t event); - -uint32_t count = 0; -char count_str[11] = { 0 }; -wgl_obj_t hello_world_label; -wgl_obj_t count_label; -wgl_obj_t btn1; -wgl_obj_t label_count1; -int label_count1_value = 0; -char label_count1_str[11] = { 0 }; - -void timer1_update(user_timer_t timer1) -{ - if ((count % 100) == 0) { - snprintf(count_str, sizeof(count_str), "%d", count / 100); - wgl_label_set_text(count_label, count_str); - } - ++count; -} - -void on_init() -{ - hello_world_label = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL); - wgl_label_set_text(hello_world_label, "Hello world!"); - wgl_obj_align(hello_world_label, (wgl_obj_t)NULL, WGL_ALIGN_IN_TOP_LEFT, 0, 0); - - count_label = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL); - wgl_obj_align(count_label, (wgl_obj_t)NULL, WGL_ALIGN_IN_TOP_MID, 0, 0); - - btn1 = wgl_btn_create((wgl_obj_t)NULL, (wgl_obj_t)NULL); /*Create a button on the currently loaded screen*/ - wgl_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/ - wgl_obj_align(btn1, (wgl_obj_t)NULL, WGL_ALIGN_CENTER, 0, 0); /*Align below the label*/ - - /*Create a label on the button*/ - wgl_obj_t btn_label = wgl_label_create(btn1, (wgl_obj_t)NULL); - wgl_label_set_text(btn_label, "Click ++"); - - label_count1 = wgl_label_create((wgl_obj_t)NULL, (wgl_obj_t)NULL); - wgl_label_set_text(label_count1, "0"); - wgl_obj_align(label_count1, (wgl_obj_t)NULL, WGL_ALIGN_IN_BOTTOM_MID, 0, 0); - - /* set up a timer */ - user_timer_t timer; - timer = api_timer_create(10, true, false, timer1_update); - if (timer) - api_timer_restart(timer, 10); - else - printf("Fail to create timer.\n"); -} - -static void btn_event_cb(wgl_obj_t btn, wgl_event_t event) -{ - if(event == WGL_EVENT_RELEASED) { - label_count1_value++; - snprintf(label_count1_str, sizeof(label_count1_str), - "%d", label_count1_value); - wgl_label_set_text(label_count1, label_count1_str); - } -} - -``` - -Currently supported widgets include button, label, list and check box and more widgets would be provided in future. diff --git a/product-mini/README.md b/product-mini/README.md index 4a8275618..8d7e799a4 100644 --- a/product-mini/README.md +++ b/product-mini/README.md @@ -10,7 +10,7 @@ cmake .. -DCMAKE_TOOLCHAIN_FILE=$TOOL_CHAIN_FILE \ -DWAMR_BUILD_TARGET=ARM ``` -Refer to toolchain sample file [`samples/simple/profiles/arm-interp/toolchain.cmake`](../samples/simple/profiles/arm-interp/toolchain.cmake) for how to build mini product for ARM target architecture. +Refer to toolchain sample file [`wamr-app-framework/samples/simple/profiles/arm-interp/toolchain.cmake`](https://github.com/bytecodealliance/wamr-app-framework/blob/main/samples/simple/profiles/arm-interp/toolchain.cmake) for how to build mini product for ARM target architecture. If you compile for ESP-IDF, make sure to set the right toolchain file for the chip you're using (e.g. `$IDF_PATH/tools/cmake/toolchain-esp32c3.cmake`). Note that all ESP-IDF toolchain files live under `$IDF_PATH/tools/cmake/`. @@ -250,7 +250,6 @@ Note: WAMR provides some features which can be easily configured by passing options to cmake, please see [WAMR vmcore cmake building configurations](../doc/build_wamr.md#wamr-vmcore-cmake-building-configurations) for details. Currently in VxWorks, interpreter and builtin libc are enabled by default. ## Zephyr - Please refer to this [README](./platforms/zephyr/simple/README.md) under the Zephyr sample directory for details. Note: diff --git a/samples/README.md b/samples/README.md index 21a735268..4113fcad1 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,10 +1,7 @@ # Samples - [**basic**](./basic): Demonstrating how to use runtime exposed API's to call WASM functions, how to register native functions and call them, and how to call WASM function from native function. -- **[simple](./simple/README.md)**: The runtime is integrated with most of the WAMR APP libraries, and a few WASM applications are provided for testing the WAMR APP API set. It uses **built-in libc** and executes apps in **interpreter** mode by default. - **[file](./file/README.md)**: Demonstrating the supported file interaction API of WASI. This sample can also demonstrate the SGX IPFS (Intel Protected File System), enabling an enclave to seal and unseal data at rest. -- **[littlevgl](./littlevgl/README.md)**: Demonstrating the graphic user interface application usage on WAMR. The whole [LVGL](https://github.com/lvgl/lvgl) 2D user graphic library and the UI application are built into WASM application. It uses **WASI libc** and executes apps in **AOT mode** by default. -- **[gui](./gui/README.md)**: Move the [LVGL](https://github.com/lvgl/lvgl) library into the runtime and define a WASM application interface by wrapping the littlevgl API. It uses **WASI libc** and executes apps in **interpreter** mode by default. - **[multi-thread](./multi-thread/)**: Demonstrating how to run wasm application which creates multiple threads to execute wasm functions concurrently, and uses mutex/cond by calling pthread related API's. - **[spawn-thread](./spawn-thread)**: Demonstrating how to execute wasm functions of the same wasm application concurrently, in threads created by host embedder or runtime, but not the wasm application itself. - **[wasi-threads](./wasi-threads/README.md)**: Demonstrating how to run wasm application which creates multiple threads to execute wasm functions concurrently based on lib wasi-threads. diff --git a/samples/gui/README.md b/samples/gui/README.md deleted file mode 100644 index d79453c3e..000000000 --- a/samples/gui/README.md +++ /dev/null @@ -1,138 +0,0 @@ -"gui" sample introduction -============== -This sample demonstrates that a graphic user interface application in WebAssembly programming with WAMR graphic library(WGL) which is part of WAMR app-framework. - -Compared with the [littlevgl](../littlevgl) sample, WGL compiles LittlevGL source code into the WAMR runtime and defines a set of wrapper API's for exporting to Webassembly application. - -Below picture shows the WASM application is running on an STM board with an LCD touch panel. - -![WAMR UI SAMPLE](../../doc/pics/vgl_demo2.png "WAMR UI DEMO") - - When user clicks the blue button, the WASM application increases the counter, and the latest counter value is displayed on the top banner of the touch panel. The number on top will plus one each second, and the number on the bottom will plus one when clicked. - -# Test on Linux - -Install required SDK and libraries --------------- -- 32 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_32` when building WAMR runtime) -Use apt-get: - ```bash - sudo apt-get install libsdl2-dev:i386 - ``` -Or download source from www.libsdl.org: - ```bash - ./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32 - make - sudo make install - ``` -- 64 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_64` when building WAMR runtime) -Use apt-get: - - ```bash - sudo apt-get install libsdl2-dev - ``` - Or download source from www.libsdl.org: - ```bash - ./configure - make - sudo make install - ``` - -Build and Run --------------- - -- Build - ```bash - ./build.sh - ``` - All binaries are in "out", which contains "host_tool", "ui_decrease.wasm", "ui_increase.wasm" and "wasm_runtime_wgl". - -- Run WASM VM Linux applicaton & install WASM APP - First start wasm_runtime_wgl in server mode. - ```bash - ./wasm_runtime_wgl -s - ``` - Then install wasm APP by using host tool. - ```bash - ./host_tool -i inc -f ui_increase.wasm - # or - ./host_tool -i dec -f ui_decrease.wasm - ``` - -Test on Zephyr -================================ - -We can use a STM32 NUCLEO_F767ZI board with ILI9341 display and XPT2046 touch screen to run the test. Then use host_tool to remotely install wasm app into STM32. -- Build WASM VM into Zephyr system - a. clone zephyr source code -Refer to [Zephyr getting started](https://docs.zephyrproject.org/latest/getting_started/index.html). - - ```bash - west init zephyrproject - cd zephyrproject/zephyr - git checkout zephyr-v2.3.0 - cd .. - west update - ``` - b. copy samples - ```bash - cd zephyr/samples - cp -a /samples/gui/wasm-runtime-wgl wasm-runtime-wgl - cd wasm-runtime-wgl/zephyr_build - ``` - c. create a link to wamr root dir - ```bash - ln -s wamr - ``` - d. build source code - ```bash - mkdir build && cd build - source ../../../../zephyr-env.sh - cmake -GNinja -DBOARD=nucleo_f767zi .. - ninja flash - ``` - -- Hardware Connections - -``` -+-------------------+-+------------------+ -|NUCLEO-F767ZI | ILI9341 Display | -+-------------------+-+------------------+ -| CN7.10 | CLK | -+-------------------+-+------------------+ -| CN7.12 | MISO | -+-------------------+-+------------------+ -| CN7.14 | MOSI | -+-------------------+-+------------------+ -| CN11.1 | CS1 for ILI9341 | -+-------------------+-+------------------+ -| CN11.2 | D/C | -+-------------------+-+------------------+ -| CN11.3 | RESET | -+-------------------+-+------------------+ -| CN9.25 | PEN interrupt | -+-------------------+-+------------------+ -| CN9.27 | CS2 for XPT2046 | -+-------------------+-+------------------+ -| CN10.14 | PC UART RX | -+-------------------+-+------------------+ -| CN11.16 | PC UART RX | -+-------------------+-+------------------+ -``` - -- Install WASM application to Zephyr using host_tool -First, connect PC and STM32 with UART. Then install to use host_tool. - ```bash - sudo ./host_tool -D /dev/ttyUSBXXX -i inc -f ui_increase.wasm - # /dev/ttyUSBXXX is the UART device, e.g. /dev/ttyUSB0 - ``` - -- Install AOT version WASM application - ```bash - wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app.aot ui_increase.wasm - ./host_tool -D /dev/ttyUSBXXX -i inc -f ui_app.aot - ``` - -The graphic user interface demo photo: - -![WAMR samples diagram](../../doc/pics/vgl_demo.png "WAMR samples diagram") diff --git a/samples/gui/build.sh b/samples/gui/build.sh deleted file mode 100755 index f910f450b..000000000 --- a/samples/gui/build.sh +++ /dev/null @@ -1,75 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -#!/bin/bash - -PROJECT_DIR=$PWD -WAMR_DIR=${PWD}/../.. -OUT_DIR=${PWD}/out -BUILD_DIR=${PWD}/build -WAMR_RUNTIME_CFG=${PROJECT_DIR}/wamr_config_gui.cmake -LV_CFG_PATH=${PROJECT_DIR}/lv_config - -if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then - echo "Local Build Env" - cmakewrap="cmake" - makewrap="make" -else - echo "Klocwork Build Env" - cmakewrap="cmake -DCMAKE_BUILD_TYPE=Debug" - makewrap="kwinject -o $KW_OUT_FILE make" -fi - -if [ ! -d $BUILD_DIR ]; then - mkdir ${BUILD_DIR} -fi - -rm -rf ${OUT_DIR} -mkdir ${OUT_DIR} - - -echo -e "\n\n" -echo "##################### 1. build wamr-sdk gui start#####################" -cd ${WAMR_DIR}/wamr-sdk -./build_sdk.sh -n gui -x ${WAMR_RUNTIME_CFG} -e ${LV_CFG_PATH} -[ $? -eq 0 ] || exit $? - -echo "#####################build wamr-sdk success" - - - -echo "##################### 2. build wasm runtime start#####################" -cd $BUILD_DIR -mkdir -p wasm-runtime-wgl -cd wasm-runtime-wgl -$cmakewrap ${PROJECT_DIR}/wasm-runtime-wgl/linux-build -DWAMR_BUILD_SDK_PROFILE=gui -[ $? -eq 0 ] || exit $? -$makewrap -[ $? -eq 0 ] || exit $? -cp wasm_runtime_wgl ${OUT_DIR}/ - -echo "##################### build littlevgl wasm runtime end#####################" -echo -e "\n\n" - - -echo "#####################build host-tool" -cd $BUILD_DIR -mkdir -p host-tool -cd host-tool -$cmakewrap ${WAMR_DIR}/test-tools/host-tool -$makewrap -if [ $? != 0 ];then - echo "BUILD_FAIL host tool exit as $?\n" - exit 2 -fi -cp host_tool ${OUT_DIR} -echo "#####################build host-tool success" -echo -e "\n\n" - -echo "##################### 3. build wasm ui app start#####################" -cd ${PROJECT_DIR}/wasm-apps -export OUT_DIR=${OUT_DIR} -./build_apps.sh - diff --git a/samples/gui/lv_config/lv_conf.h b/samples/gui/lv_config/lv_conf.h deleted file mode 100644 index 2f9fc77a7..000000000 --- a/samples/gui/lv_config/lv_conf.h +++ /dev/null @@ -1,498 +0,0 @@ -/** - * @file lv_conf.h - * - */ - -/* - * COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER - */ - -#if 1 /*Set it to "1" to enable content*/ - -#ifndef LV_CONF_H -#define LV_CONF_H -/* clang-format off */ - -#include - -/*==================== - Graphical settings - *====================*/ - -/* Maximal horizontal and vertical resolution to support by the library.*/ -#define LV_HOR_RES_MAX (320) -#define LV_VER_RES_MAX (240) - -/* Color depth: - * - 1: 1 byte per pixel - * - 8: RGB233 - * - 16: RGB565 - * - 32: ARGB8888 - */ -#define LV_COLOR_DEPTH 32 - -/* Swap the 2 bytes of RGB565 color. - * Useful if the display has a 8 bit interface (e.g. SPI)*/ -#define LV_COLOR_16_SWAP 0 - -/* 1: Enable screen transparency. - * Useful for OSD or other overlapping GUIs. - * Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/ -#define LV_COLOR_SCREEN_TRANSP 0 - -/*Images pixels with this color will not be drawn (with chroma keying)*/ -#define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/ - -/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ -#define LV_ANTIALIAS 1 - -/* Default display refresh period. - * Can be changed in the display driver (`lv_disp_drv_t`).*/ -#define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/ - -/* Dot Per Inch: used to initialize default sizes. - * E.g. a button with width = LV_DPI / 2 -> half inch wide - * (Not so important, you can adjust it to modify default sizes and spaces)*/ -#define LV_DPI 100 /*[px]*/ - -/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */ -typedef int16_t lv_coord_t; - -/*========================= - Memory manager settings - *=========================*/ - -/* LittelvGL's internal memory manager's settings. - * The graphical objects and other related data are stored here. */ - -/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */ -#ifndef LV_MEM_CUSTOM -#define LV_MEM_CUSTOM 0 -#endif - -#if LV_MEM_CUSTOM == 0 -/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ -# define LV_MEM_SIZE (128U * 1024U) - -/* Complier prefix for a big array declaration */ -# define LV_MEM_ATTR - -/* Set an address for the memory pool instead of allocating it as an array. - * Can be in external SRAM too. */ -# define LV_MEM_ADR 0 - -/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */ -# define LV_MEM_AUTO_DEFRAG 1 -#else /*LV_MEM_CUSTOM*/ -# define LV_MEM_CUSTOM_INCLUDE "bh_platform.h" /*Header for the dynamic memory function*/ -# define LV_MEM_CUSTOM_ALLOC BH_MALLOC /*Wrapper to malloc*/ -# define LV_MEM_CUSTOM_FREE BH_FREE /*Wrapper to free*/ -#endif /*LV_MEM_CUSTOM*/ - -/* Garbage Collector settings - * Used if lvgl is binded to higher level language and the memory is managed by that language */ -#define LV_ENABLE_GC 0 -#if LV_ENABLE_GC != 0 -# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ -# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/ -# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/ -#endif /* LV_ENABLE_GC */ - -/*======================= - Input device settings - *=======================*/ - -/* Input device default settings. - * Can be changed in the Input device driver (`lv_indev_drv_t`)*/ - -/* Input device read period in milliseconds */ -#define LV_INDEV_DEF_READ_PERIOD 30 - -/* Drag threshold in pixels */ -#define LV_INDEV_DEF_DRAG_LIMIT 10 - -/* Drag throw slow-down in [%]. Greater value -> faster slow-down */ -#define LV_INDEV_DEF_DRAG_THROW 20 - -/* Long press time in milliseconds. - * Time to send `LV_EVENT_LONG_PRESSSED`) */ -#define LV_INDEV_DEF_LONG_PRESS_TIME 400 - -/* Repeated trigger period in long press [ms] - * Time between `LV_EVENT_LONG_PRESSED_REPEAT */ -#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100 - -/*================== - * Feature usage - *==================*/ - -/*1: Enable the Animations */ -#define LV_USE_ANIMATION 1 -#if LV_USE_ANIMATION - -/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_anim_user_data_t; - -#endif - -/* 1: Enable shadow drawing*/ -#define LV_USE_SHADOW 1 - -/* 1: Enable object groups (for keyboard/encoder navigation) */ -#define LV_USE_GROUP 1 -#if LV_USE_GROUP -typedef void * lv_group_user_data_t; -#endif /*LV_USE_GROUP*/ - -/* 1: Enable GPU interface*/ -#define LV_USE_GPU 1 - -/* 1: Enable file system (might be required for images */ -#define LV_USE_FILESYSTEM 1 -#if LV_USE_FILESYSTEM -/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_fs_drv_user_data_t; -#endif - -/*1: Add a `user_data` to drivers and objects*/ -#define LV_USE_USER_DATA 1 - -/*======================== - * Image decoder and cache - *========================*/ - -/* 1: Enable indexed (palette) images */ -#define LV_IMG_CF_INDEXED 1 - -/* 1: Enable alpha indexed images */ -#define LV_IMG_CF_ALPHA 1 - -/* Default image cache size. Image caching keeps the images opened. - * If only the built-in image formats are used there is no real advantage of caching. - * (I.e. no new image decoder is added) - * With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images. - * However the opened images might consume additional RAM. - * LV_IMG_CACHE_DEF_SIZE must be >= 1 */ -#define LV_IMG_CACHE_DEF_SIZE 1 - -/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_img_decoder_user_data_t; - -/*===================== - * Compiler settings - *====================*/ -/* Define a custom attribute to `lv_tick_inc` function */ -#define LV_ATTRIBUTE_TICK_INC - -/* Define a custom attribute to `lv_task_handler` function */ -#define LV_ATTRIBUTE_TASK_HANDLER - -/* With size optimization (-Os) the compiler might not align data to - * 4 or 8 byte boundary. This alignment will be explicitly applied where needed. - * E.g. __attribute__((aligned(4))) */ -#define LV_ATTRIBUTE_MEM_ALIGN - -/* Attribute to mark large constant arrays for example - * font's bitmaps */ -#define LV_ATTRIBUTE_LARGE_CONST - -/*=================== - * HAL settings - *==================*/ - -/* 1: use a custom tick source. - * It removes the need to manually update the tick with `lv_tick_inc`) */ -#define LV_TICK_CUSTOM 1 -#if LV_TICK_CUSTOM == 1 -#define LV_TICK_CUSTOM_INCLUDE "system_header.h" /*Header for the sys time function*/ -#define LV_TICK_CUSTOM_SYS_TIME_EXPR (time_get_ms()) /*Expression evaluating to current systime in ms*/ -#endif /*LV_TICK_CUSTOM*/ - -typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ -typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/ - -/*================ - * Log settings - *===============*/ - -/*1: Enable the log module*/ -#define LV_USE_LOG 1 -#if LV_USE_LOG -/* How important log should be added: - * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information - * LV_LOG_LEVEL_INFO Log important events - * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem - * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail - * LV_LOG_LEVEL_NONE Do not log anything - */ -# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN - -/* 1: Print the log with 'printf'; - * 0: user need to register a callback with `lv_log_register_print`*/ -# define LV_LOG_PRINTF 1 -#endif /*LV_USE_LOG*/ - -/*================ - * THEME USAGE - *================*/ -#define LV_THEME_LIVE_UPDATE 1 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/ - -#define LV_USE_THEME_TEMPL 1 /*Just for test*/ -#define LV_USE_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/ -#define LV_USE_THEME_ALIEN 1 /*Dark futuristic theme*/ -#define LV_USE_THEME_NIGHT 1 /*Dark elegant theme*/ -#define LV_USE_THEME_MONO 1 /*Mono color theme for monochrome displays*/ -#define LV_USE_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/ -#define LV_USE_THEME_ZEN 1 /*Peaceful, mainly light theme */ -#define LV_USE_THEME_NEMO 1 /*Water-like theme based on the movie "Finding Nemo"*/ - -/*================== - * FONT USAGE - *===================*/ - -/* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel. - * The symbols are available via `LV_SYMBOL_...` defines - * More info about fonts: https://docs.littlevgl.com/#Fonts - * To create a new font go to: https://littlevgl.com/ttf-font-to-c-array - */ - -/* Robot fonts with bpp = 4 - * https://fonts.google.com/specimen/Roboto */ -#define LV_FONT_ROBOTO_12 1 -#define LV_FONT_ROBOTO_16 1 -#define LV_FONT_ROBOTO_22 1 -#define LV_FONT_ROBOTO_28 1 - -/*Pixel perfect monospace font - * http://pelulamu.net/unscii/ */ -#define LV_FONT_UNSCII_8 1 - -/* Optionally declare your custom fonts here. - * You can use these fonts as default font too - * and they will be available globally. E.g. - * #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \ - * LV_FONT_DECLARE(my_font_2) - */ -#define LV_FONT_CUSTOM_DECLARE - -/*Always set a default font from the built-in fonts*/ -#define LV_FONT_DEFAULT &lv_font_roboto_16 - -/* Enable it if you have fonts with a lot of characters. - * The limit depends on the font size, font face and bpp - * but with > 10,000 characters if you see issues probably you need to enable it.*/ -#define LV_FONT_FMT_TXT_LARGE 1 - -/*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_font_user_data_t; - -/*================= - * Text settings - *=================*/ - -/* Select a character encoding for strings. - * Your IDE or editor should have the same character encoding - * - LV_TXT_ENC_UTF8 - * - LV_TXT_ENC_ASCII - * */ -#define LV_TXT_ENC LV_TXT_ENC_UTF8 - - /*Can break (wrap) texts on these chars*/ -#define LV_TXT_BREAK_CHARS " ,.;:-_" - -/*=================== - * LV_OBJ SETTINGS - *==================*/ - -/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/ -typedef void * lv_obj_user_data_t; - -/*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/ -#define LV_USE_OBJ_REALIGN 1 - -/* Enable to make the object clickable on a larger area. - * LV_EXT_CLICK_AREA_OFF or 0: Disable this feature - * LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px) - * LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px) - */ -#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_FULL - -/*================== - * LV OBJ X USAGE - *================*/ -/* - * Documentation of the object types: https://docs.littlevgl.com/#Object-types - */ - -/*Arc (dependencies: -)*/ -#define LV_USE_ARC 1 - -/*Bar (dependencies: -)*/ -#define LV_USE_BAR 1 - -/*Button (dependencies: lv_cont*/ -#define LV_USE_BTN 1 -#if LV_USE_BTN != 0 -/*Enable button-state animations - draw a circle on click (dependencies: LV_USE_ANIMATION)*/ -# define LV_BTN_INK_EFFECT 1 -#endif - -/*Button matrix (dependencies: -)*/ -#define LV_USE_BTNM 1 - -/*Calendar (dependencies: -)*/ -#define LV_USE_CALENDAR 1 - -/*Canvas (dependencies: lv_img)*/ -#define LV_USE_CANVAS 1 - -/*Check box (dependencies: lv_btn, lv_label)*/ -#define LV_USE_CB 1 - -/*Chart (dependencies: -)*/ -#define LV_USE_CHART 1 -#if LV_USE_CHART -# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 20 -#endif - -/*Container (dependencies: -*/ -#define LV_USE_CONT 1 - -/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ -#define LV_USE_DDLIST 1 -#if LV_USE_DDLIST != 0 -/*Open and close default animation time [ms] (0: no animation)*/ -# define LV_DDLIST_DEF_ANIM_TIME 200 -#endif - -/*Gauge (dependencies:lv_bar, lv_lmeter)*/ -#define LV_USE_GAUGE 1 - -/*Image (dependencies: lv_label*/ -#define LV_USE_IMG 1 - -/*Image Button (dependencies: lv_btn*/ -#define LV_USE_IMGBTN 1 -#if LV_USE_IMGBTN -/*1: The imgbtn requires left, mid and right parts and the width can be set freely*/ -# define LV_IMGBTN_TILED 0 -#endif - -/*Keyboard (dependencies: lv_btnm)*/ -#define LV_USE_KB 1 - -/*Label (dependencies: -*/ -#define LV_USE_LABEL 1 -#if LV_USE_LABEL != 0 -/*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/ -# define LV_LABEL_DEF_SCROLL_SPEED 25 - -/* Waiting period at beginning/end of animation cycle */ -# define LV_LABEL_WAIT_CHAR_COUNT 3 - -/*Enable selecting text of the label */ -# define LV_LABEL_TEXT_SEL 1 - -/*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/ -# define LV_LABEL_LONG_TXT_HINT 0 -#endif - -/*LED (dependencies: -)*/ -#define LV_USE_LED 1 - -/*Line (dependencies: -*/ -#define LV_USE_LINE 1 - -/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ -#define LV_USE_LIST 1 -#if LV_USE_LIST != 0 -/*Default animation time of focusing to a list element [ms] (0: no animation) */ -# define LV_LIST_DEF_ANIM_TIME 100 -#endif - -/*Line meter (dependencies: *;)*/ -#define LV_USE_LMETER 1 - -/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ -#define LV_USE_MBOX 1 - -/*Page (dependencies: lv_cont)*/ -#define LV_USE_PAGE 1 -#if LV_USE_PAGE != 0 -/*Focus default animation time [ms] (0: no animation)*/ -# define LV_PAGE_DEF_ANIM_TIME 400 -#endif - -/*Preload (dependencies: lv_arc, lv_anim)*/ -#define LV_USE_PRELOAD 1 -#if LV_USE_PRELOAD != 0 -# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/ -# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/ -# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC -#endif - -/*Roller (dependencies: lv_ddlist)*/ -#define LV_USE_ROLLER 1 -#if LV_USE_ROLLER != 0 -/*Focus animation time [ms] (0: no animation)*/ -# define LV_ROLLER_DEF_ANIM_TIME 200 - -/*Number of extra "pages" when the roller is infinite*/ -# define LV_ROLLER_INF_PAGES 7 -#endif - -/*Slider (dependencies: lv_bar)*/ -#define LV_USE_SLIDER 1 - -/*Spinbox (dependencies: lv_ta)*/ -#define LV_USE_SPINBOX 1 - -/*Switch (dependencies: lv_slider)*/ -#define LV_USE_SW 1 - -/*Text area (dependencies: lv_label, lv_page)*/ -#define LV_USE_TA 1 -#if LV_USE_TA != 0 -# define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/ -# define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/ -#endif - -/*Table (dependencies: lv_label)*/ -#define LV_USE_TABLE 1 -#if LV_USE_TABLE -# define LV_TABLE_COL_MAX 12 -#endif - -/*Tab (dependencies: lv_page, lv_btnm)*/ -#define LV_USE_TABVIEW 1 -# if LV_USE_TABVIEW != 0 -/*Time of slide animation [ms] (0: no animation)*/ -# define LV_TABVIEW_DEF_ANIM_TIME 300 -#endif - -/*Tileview (dependencies: lv_page) */ -#define LV_USE_TILEVIEW 1 -#if LV_USE_TILEVIEW -/*Time of slide animation [ms] (0: no animation)*/ -# define LV_TILEVIEW_DEF_ANIM_TIME 300 -#endif - -/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ -#define LV_USE_WIN 1 - -/*================== - * Non-user section - *==================*/ - -#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ -# define _CRT_SECURE_NO_WARNINGS -#endif - -/*--END OF LV_CONF_H--*/ - -/*Be sure every define has a default value*/ -#include "lvgl/src/lv_conf_checker.h" - -#endif /*LV_CONF_H*/ - -#endif /*End of "Content enable"*/ diff --git a/samples/gui/lv_config/lv_drv_conf.h b/samples/gui/lv_config/lv_drv_conf.h deleted file mode 100644 index d216a3e90..000000000 --- a/samples/gui/lv_config/lv_drv_conf.h +++ /dev/null @@ -1,310 +0,0 @@ -/** - * @file lv_drv_conf.h - * - */ - -/* - * COPY THIS FILE AS lv_drv_conf.h - */ - -#if 1 /*Set it to "1" to enable the content*/ - -#ifndef LV_DRV_CONF_H -#define LV_DRV_CONF_H - -#include "lv_conf.h" - -/********************* - * DELAY INTERFACE - *********************/ -#define LV_DRV_DELAY_INCLUDE /*Dummy include by default*/ -#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/ -#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/ - -/********************* - * DISPLAY INTERFACE - *********************/ - -/*------------ - * Common - *------------*/ -#define LV_DRV_DISP_INCLUDE /*Dummy include by default*/ -#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/ -#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/ - -/*--------- - * SPI - *---------*/ -#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/ -#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/ -#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/ - -/*------------------ - * Parallel port - *-----------------*/ -#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/ -#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/ -#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/ -#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/ -#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/ - -/*************************** - * INPUT DEVICE INTERFACE - ***************************/ - -/*---------- - * Common - *----------*/ -#define LV_DRV_INDEV_INCLUDE /*Dummy include by default*/ -#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/ -#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/ - -/*--------- - * SPI - *---------*/ -#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/ -#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/ - -/*--------- - * I2C - *---------*/ -#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/ -#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/ -#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/ -#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/ -#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/ - - -/********************* - * DISPLAY DRIVERS - *********************/ - -/*------------------- - * Monitor of PC - *-------------------*/ -#ifndef USE_MONITOR -# define USE_MONITOR 1 -#endif - -#if USE_MONITOR -# define MONITOR_HOR_RES LV_HOR_RES_MAX -# define MONITOR_VER_RES LV_VER_RES_MAX - -/* Scale window by this factor (useful when simulating small screens) */ -# define MONITOR_ZOOM 1 - -/* Used to test true double buffering with only address changing. - * Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */ -# define MONITOR_DOUBLE_BUFFERED 0 - -/*Eclipse: Visual Studio: */ -# define MONITOR_SDL_INCLUDE_PATH - -/*Different rendering might be used if running in a Virtual machine*/ -# define MONITOR_VIRTUAL_MACHINE 0 - -/*Open two windows to test multi display support*/ -# define MONITOR_DUAL 0 -#endif - -/*----------------------------------- - * Native Windows (including mouse) - *----------------------------------*/ -#ifndef USE_WINDOWS -# define USE_WINDOWS 0 -#endif - -#define USE_WINDOWS 0 -#if USE_WINDOWS -# define WINDOW_HOR_RES 480 -# define WINDOW_VER_RES 320 -#endif - -/*---------------- - * SSD1963 - *--------------*/ -#ifndef USE_SSD1963 -# define USE_SSD1963 0 -#endif - -#if USE_SSD1963 -# define SSD1963_HOR_RES LV_HOR_RES -# define SSD1963_VER_RES LV_VER_RES -# define SSD1963_HT 531 -# define SSD1963_HPS 43 -# define SSD1963_LPS 8 -# define SSD1963_HPW 10 -# define SSD1963_VT 288 -# define SSD1963_VPS 12 -# define SSD1963_FPS 4 -# define SSD1963_VPW 10 -# define SSD1963_HS_NEG 0 /*Negative hsync*/ -# define SSD1963_VS_NEG 0 /*Negative vsync*/ -# define SSD1963_ORI 0 /*0, 90, 180, 270*/ -# define SSD1963_COLOR_DEPTH 16 -#endif - -/*---------------- - * R61581 - *--------------*/ -#ifndef USE_R61581 -# define USE_R61581 0 -#endif - -#if USE_R61581 -# define R61581_HOR_RES LV_HOR_RES -# define R61581_VER_RES LV_VER_RES -# define R61581_HSPL 0 /*HSYNC signal polarity*/ -# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/ -# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/ -# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */ -# define R61581_VSPL 0 /*VSYNC signal polarity*/ -# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/ -# define R61581_VFP 8 /*Vertical Front poarch*/ -# define R61581_VBP 8 /*Vertical Back poarch */ -# define R61581_DPL 0 /*DCLK signal polarity*/ -# define R61581_EPL 1 /*ENABLE signal polarity*/ -# define R61581_ORI 0 /*0, 180*/ -# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/ -#endif - -/*------------------------------ - * ST7565 (Monochrome, low res.) - *-----------------------------*/ -#ifndef USE_ST7565 -# define USE_ST7565 0 -#endif - -#if USE_ST7565 -/*No settings*/ -#endif /*USE_ST7565*/ - -/*----------------------------------------- - * Linux frame buffer device (/dev/fbx) - *-----------------------------------------*/ -#ifndef USE_FBDEV -# define USE_FBDEV 1 -#endif - -#if USE_FBDEV -# define FBDEV_PATH "/dev/fb0" -#endif - -/********************* - * INPUT DEVICES - *********************/ - -/*-------------- - * XPT2046 - *--------------*/ -#ifndef USE_XPT2046 -# define USE_XPT2046 0 -#endif - -#if USE_XPT2046 -# define XPT2046_HOR_RES 480 -# define XPT2046_VER_RES 320 -# define XPT2046_X_MIN 200 -# define XPT2046_Y_MIN 200 -# define XPT2046_X_MAX 3800 -# define XPT2046_Y_MAX 3800 -# define XPT2046_AVG 4 -# define XPT2046_INV 0 -#endif - -/*----------------- - * FT5406EE8 - *-----------------*/ -#ifndef USE_FT5406EE8 -# define USE_FT5406EE8 0 -#endif - -#if USE_FT5406EE8 -# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/ -#endif - -/*--------------- - * AD TOUCH - *--------------*/ -#ifndef USE_AD_TOUCH -# define USE_AD_TOUCH 0 -#endif - -#if USE_AD_TOUCH -/*No settings*/ -#endif - - -/*--------------------------------------- - * Mouse or touchpad on PC (using SDL) - *-------------------------------------*/ -#ifndef USE_MOUSE -# define USE_MOUSE 1 -#endif - -#if USE_MOUSE -/*No settings*/ -#endif - -/*------------------------------------------- - * Mousewheel as encoder on PC (using SDL) - *------------------------------------------*/ -#ifndef USE_MOUSEWHEEL -# define USE_MOUSEWHEEL 1 -#endif - -#if USE_MOUSEWHEEL -/*No settings*/ -#endif - -/*------------------------------------------------- - * Touchscreen as libinput interface (for Linux based systems) - *------------------------------------------------*/ -#ifndef USE_LIBINPUT -# define USE_LIBINPUT 0 -#endif - -#if USE_LIBINPUT -# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -#endif /*USE_LIBINPUT*/ - -/*------------------------------------------------- - * Mouse or touchpad as evdev interface (for Linux based systems) - *------------------------------------------------*/ -#ifndef USE_EVDEV -# define USE_EVDEV 0 -#endif - -#if USE_EVDEV -# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/ - -# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */ -# if EVDEV_SCALE -# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */ -# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */ -# endif /*EVDEV_SCALE*/ - -# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/ -# if EVDEV_CALIBRATE -# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/ -# define EVDEV_HOR_MAX 200 -# define EVDEV_VER_MIN 200 -# define EVDEV_VER_MAX 3800 -# endif /*EVDEV_SCALE*/ -#endif /*USE_EVDEV*/ - -/*------------------------------- - * Keyboard of a PC (using SDL) - *------------------------------*/ -#ifndef USE_KEYBOARD -# define USE_KEYBOARD 1 -#endif - -#if USE_KEYBOARD -/*No settings*/ -#endif - -#endif /*LV_DRV_CONF_H*/ - -#endif /*End of "Content enable"*/ diff --git a/samples/gui/lv_config/system_header.h b/samples/gui/lv_config/system_header.h deleted file mode 100644 index a0d790c8e..000000000 --- a/samples/gui/lv_config/system_header.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include - -int -time_get_ms(); diff --git a/samples/gui/wamr_config_gui.cmake b/samples/gui/wamr_config_gui.cmake deleted file mode 100644 index 3b33d33b2..000000000 --- a/samples/gui/wamr_config_gui.cmake +++ /dev/null @@ -1,9 +0,0 @@ -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET "X86_64") -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_ALL) diff --git a/samples/gui/wasm-apps/build_apps.sh b/samples/gui/wasm-apps/build_apps.sh deleted file mode 100755 index 18c76caf4..000000000 --- a/samples/gui/wasm-apps/build_apps.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -APPS_ROOT=$(cd "$(dirname "$0")/" && pwd) -cd ${APPS_ROOT} - -echo "OUT_DIR: ${OUT_DIR}" - -if [ -z ${OUT_DIR} ]; then - OUT_DIR=${APPS_ROOT}/out - echo "set the wasm app folder: ${OUT_DIR}" - - if [ -d ${OUT_DIR} ]; then - rm -rf ${OUT_DIR} - echo "removed the present output folder: ${OUT_DIR}" - fi - mkdir ${OUT_DIR} - -fi - -if [ -z ${WAMR_DIR} ]; then - WAMR_DIR=${APPS_ROOT}/../../.. -fi - - -cd ${APPS_ROOT}/increase - -rm -rf build -mkdir build && cd build -cmake .. -DCMAKE_TOOLCHAIN_FILE=${WAMR_DIR}/wamr-sdk/out/gui/app-sdk/wamr_toolchain.cmake \ - -DWASI_SDK_DIR=/opt/wasi-sdk -make -[ $? -eq 0 ] || exit $? -mv ui_increase.wasm ${OUT_DIR}/ - -# $makewrap -# mv ui_app.wasm ${OUT_DIR}/ - -cd ${APPS_ROOT}/decrease -make -[ $? -eq 0 ] || exit $? -mv ui_decrease.wasm ${OUT_DIR}/ - -echo "WASM files generated in folder ${OUT_DIR}" - -echo "##################### build WASM APPs finished #####################" diff --git a/samples/gui/wasm-apps/decrease/Makefile b/samples/gui/wasm-apps/decrease/Makefile deleted file mode 100644 index d99008beb..000000000 --- a/samples/gui/wasm-apps/decrease/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CC = /opt/wasi-sdk/bin/clang -APP_DIR = ${shell pwd} -IWASM_DIR = $(APP_DIR)/../../../../core/iwasm -SDK_DIR = $(APP_DIR)/../../../../wamr-sdk/out/gui/app-sdk -APP_FRAMEWORK_DIR = $(APP_DIR)/../../../../wamr-sdk/out/gui/app-sdk/wamr-app-framework -DEPS_DIR = $(APP_DIR)/../../../../core/deps - -CFLAGS += -O3 \ - -Wno-int-conversion \ - -I$(APP_DIR)/src \ - -I$(APP_FRAMEWORK_DIR)/include \ - -I${DEPS_DIR} - -SRCS += $(APP_DIR)/src/main.c - -all: - @$(CC) $(CFLAGS) $(SRCS) \ - --target=wasm32 -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \ - --sysroot=$(SDK_DIR)/libc-builtin-sysroot \ - -L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \ - -Wl,--allow-undefined-file=$(SDK_DIR)/libc-builtin-sysroot/share/defined-symbols.txt \ - -Wl,--strip-all,--no-entry -nostdlib \ - -Wl,--export=on_init -Wl,--export=on_timer_callback \ - -Wl,--export=on_widget_event \ - -Wl,--export=__heap_base,--export=__data_end \ - -o ui_decrease.wasm diff --git a/samples/gui/wasm-apps/increase/CMakeLists.txt b/samples/gui/wasm-apps/increase/CMakeLists.txt deleted file mode 100644 index ce55fb1e6..000000000 --- a/samples/gui/wasm-apps/increase/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -project(wgl) - -set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../) - -include_directories( - ${WAMR_ROOT_DIR}/wamr-sdk/out/gui/app-sdk/wamr-app-framework/include - ${WAMR_ROOT_DIR}/core/deps -) - -set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS},-L${WAMR_ROOT_DIR}/wamr-sdk/out/gui/app-sdk/wamr-app-framework/lib") -set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS},--export=on_init,--export=on_timer_callback,--export=on_widget_event,--export=__heap_base,--export=__data_end") -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wno-unused-command-line-argument") - -add_executable(ui_increase.wasm - ${CMAKE_CURRENT_LIST_DIR}/src/main.c -) - -target_link_libraries(ui_increase.wasm app_framework) diff --git a/samples/gui/wasm-apps/increase/Makefile b/samples/gui/wasm-apps/increase/Makefile deleted file mode 100644 index 5f250d6ef..000000000 --- a/samples/gui/wasm-apps/increase/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CC = /opt/wasi-sdk/bin/clang -APP_DIR = ${shell pwd} -IWASM_DIR = ../../../../core/iwasm -APP_FRAMEWORK_DIR = ../../../../core/app-framework -DEPS_DIR = ../../../../core/deps - -CFLAGS += -O3 \ - -Wno-int-conversion \ - -I$(APP_DIR)/src \ - -I$(APP_FRAMEWORK_DIR)/base/app \ - -I$(APP_FRAMEWORK_DIR)/app-native-shared \ - -I$(APP_FRAMEWORK_DIR)/sensor/app \ - -I$(APP_FRAMEWORK_DIR)/wgl/app \ - -I$(APP_FRAMEWORK_DIR)/connection/app \ - -I${DEPS_DIR} - -SRCS += $(APP_DIR)/src/main.c - -# For app size consideration, not all but necessary app libs are included -SRCS += $(APP_FRAMEWORK_DIR)/base/app/timer.c -SRCS += $(APP_FRAMEWORK_DIR)/wgl/app/src/*.c - -all: - @$(CC) $(CFLAGS) $(SRCS) \ - --target=wasm32-wasi -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \ - -nostdlib -Wl,--allow-undefined \ - -Wl,--strip-all,--no-entry \ - -Wl,--export=on_init -Wl,--export=on_timer_callback \ - -Wl,--export=on_widget_event \ - -Wl,--export=__heap_base,--export=__data_end \ - -o ui_app.wasm diff --git a/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt b/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt deleted file mode 100644 index a2c9c0465..000000000 --- a/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required (VERSION 2.9) - -project (wasm_runtime_wgl) - -set (WAMR_BUILD_PLATFORM "linux") - -# Reset default linker flags -set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") -set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") - -################ wamr runtime settings ################ - -set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..) -set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps) - - -add_definitions(-DLV_CONF_INCLUDE_SIMPLE) - -## use library and headers in the SDK -link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/lib) -include_directories( - ${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/include - ${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/include/bi-inc/deps - ${WAMR_ROOT_DIR}/core/shared/utils - ${WAMR_ROOT_DIR}/core/shared/platform/${WAMR_BUILD_PLATFORM} -) - -################ application related ################ - -set (LV_DRIVERS_DIR ${WAMR_ROOT_DIR}/core/deps/lv_drivers) -file (GLOB_RECURSE LV_DRIVERS_SOURCES "${LV_DRIVERS_DIR}/*.c") - -set (PROJECT_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../src/platform/${WAMR_BUILD_PLATFORM}) -include_directories( - ${PROJECT_SRC_DIR} - ${DEPS_DIR} - ${DEPS_DIR}/lvgl - ${DEPS_DIR}/lvgl/src -) - -set (SOURCES - ${PROJECT_SRC_DIR}/main.c - ${PROJECT_SRC_DIR}/iwasm_main.c - ${LV_DRIVERS_SOURCES} - ) - -add_executable (wasm_runtime_wgl ${SOURCES}) - -target_link_libraries (wasm_runtime_wgl vmlib -lm -ldl -lpthread -lSDL2) -#target_link_libraries(wasm_runtime_wgl PRIVATE SDL2 ) - diff --git a/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c b/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c deleted file mode 100644 index 61c7bb39d..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c +++ /dev/null @@ -1,564 +0,0 @@ - -#ifndef CONNECTION_UART -#include -#include -#include -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "runtime_lib.h" -#include "runtime_timer.h" -#include "native_interface.h" -#include "app_manager_export.h" -#include "bh_platform.h" -#include "runtime_sensor.h" -#include "bi-inc/attr_container.h" -#include "module_wasm_app.h" -#include "wasm_export.h" -#include "wgl.h" - -#include "lv_drivers/display/monitor.h" -#include "lv_drivers/indev/mouse.h" - -#define MAX 2048 - -#ifndef CONNECTION_UART -#define SA struct sockaddr -static char *host_address = "127.0.0.1"; -static int port = 8888; -#else -static char *uart_device = "/dev/ttyS2"; -static int baudrate = B115200; -#endif - -extern bool -init_sensor_framework(); -extern void -exit_sensor_framework(); -extern void -exit_connection_framework(); -extern int -aee_host_msg_callback(void *msg, uint32_t msg_len); -extern bool -init_connection_framework(); - -#ifndef CONNECTION_UART -int listenfd = -1; -int sockfd = -1; -static pthread_mutex_t sock_lock = PTHREAD_MUTEX_INITIALIZER; -#else -int uartfd = -1; -#endif - -#ifndef CONNECTION_UART -static bool server_mode = false; - -// Function designed for chat between client and server. -void * -func(void *arg) -{ - char buff[MAX]; - int n; - struct sockaddr_in servaddr; - - while (1) { - if (sockfd != -1) - close(sockfd); - // socket create and verification - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd == -1) { - printf("socket creation failed...\n"); - return NULL; - } - else - printf("Socket successfully created..\n"); - bzero(&servaddr, sizeof(servaddr)); - // assign IP, PORT - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr(host_address); - servaddr.sin_port = htons(port); - - // connect the client socket to server socket - if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) { - printf("connection with the server failed...\n"); - sleep(10); - continue; - } - else { - printf("connected to the server..\n"); - } - - // infinite loop for chat - for (;;) { - bzero(buff, MAX); - - // read the message from client and copy it in buffer - n = read(sockfd, buff, sizeof(buff)); - // print buffer which contains the client contents - // fprintf(stderr, "recieved %d bytes from host: %s", n, buff); - - // socket disconnected - if (n <= 0) - break; - - aee_host_msg_callback(buff, n); - } - } - - // After chatting close the socket - close(sockfd); -} - -static bool -host_init() -{ - return true; -} - -int -host_send(void *ctx, const char *buf, int size) -{ - int ret; - - if (pthread_mutex_trylock(&sock_lock) == 0) { - if (sockfd == -1) { - pthread_mutex_unlock(&sock_lock); - return 0; - } - - ret = write(sockfd, buf, size); - - pthread_mutex_unlock(&sock_lock); - return ret; - } - - return -1; -} - -void -host_destroy() -{ - if (server_mode) - close(listenfd); - - pthread_mutex_lock(&sock_lock); - close(sockfd); - pthread_mutex_unlock(&sock_lock); -} - -/* clang-format off */ -host_interface interface = { - .init = host_init, - .send = host_send, - .destroy = host_destroy -}; -/* clang-format on */ - -void * -func_server_mode(void *arg) -{ - int clilent; - struct sockaddr_in serv_addr, cli_addr; - int n; - char buff[MAX]; - struct sigaction sa; - - sa.sa_handler = SIG_IGN; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sigaction(SIGPIPE, &sa, 0); - - /* First call to socket() function */ - listenfd = socket(AF_INET, SOCK_STREAM, 0); - - if (listenfd < 0) { - perror("ERROR opening socket"); - exit(1); - } - - /* Initialize socket structure */ - bzero((char *)&serv_addr, sizeof(serv_addr)); - - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; - serv_addr.sin_port = htons(port); - - /* Now bind the host address using bind() call.*/ - if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { - perror("ERROR on binding"); - exit(1); - } - - listen(listenfd, 5); - clilent = sizeof(cli_addr); - - while (1) { - pthread_mutex_lock(&sock_lock); - - sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent); - - pthread_mutex_unlock(&sock_lock); - - if (sockfd < 0) { - perror("ERROR on accept"); - exit(1); - } - - printf("connection established!\n"); - - for (;;) { - bzero(buff, MAX); - - // read the message from client and copy it in buffer - n = read(sockfd, buff, sizeof(buff)); - - // socket disconnected - if (n <= 0) { - pthread_mutex_lock(&sock_lock); - close(sockfd); - sockfd = -1; - pthread_mutex_unlock(&sock_lock); - - sleep(2); - break; - } - - aee_host_msg_callback(buff, n); - } - } -} - -#else -static int -parse_baudrate(int baud) -{ - switch (baud) { - case 9600: - return B9600; - case 19200: - return B19200; - case 38400: - return B38400; - case 57600: - return B57600; - case 115200: - return B115200; - case 230400: - return B230400; - case 460800: - return B460800; - case 500000: - return B500000; - case 576000: - return B576000; - case 921600: - return B921600; - case 1000000: - return B1000000; - case 1152000: - return B1152000; - case 1500000: - return B1500000; - case 2000000: - return B2000000; - case 2500000: - return B2500000; - case 3000000: - return B3000000; - case 3500000: - return B3500000; - case 4000000: - return B4000000; - default: - return -1; - } -} -static bool -uart_init(const char *device, int baudrate, int *fd) -{ - int uart_fd; - struct termios uart_term; - - uart_fd = open(device, O_RDWR | O_NOCTTY); - - if (uart_fd <= 0) - return false; - - memset(&uart_term, 0, sizeof(uart_term)); - uart_term.c_cflag = baudrate | CS8 | CLOCAL | CREAD; - uart_term.c_iflag = IGNPAR; - uart_term.c_oflag = 0; - - /* set noncanonical mode */ - uart_term.c_lflag = 0; - uart_term.c_cc[VTIME] = 30; - uart_term.c_cc[VMIN] = 1; - tcflush(uart_fd, TCIFLUSH); - - if (tcsetattr(uart_fd, TCSANOW, &uart_term) != 0) { - close(uart_fd); - return false; - } - - *fd = uart_fd; - - return true; -} - -static void * -func_uart_mode(void *arg) -{ - int n; - char buff[MAX]; - - if (!uart_init(uart_device, baudrate, &uartfd)) { - printf("open uart fail! %s\n", uart_device); - return NULL; - } - - for (;;) { - bzero(buff, MAX); - - n = read(uartfd, buff, sizeof(buff)); - - if (n <= 0) { - close(uartfd); - uartfd = -1; - break; - } - - aee_host_msg_callback(buff, n); - } - - return NULL; -} - -static int -uart_send(void *ctx, const char *buf, int size) -{ - int ret; - - ret = write(uartfd, buf, size); - - return ret; -} - -static void -uart_destroy() -{ - close(uartfd); -} - -/* clang-format off */ -static host_interface interface = { - .send = uart_send, - .destroy = uart_destroy -}; -/* clang-format on */ - -#endif - -static char global_heap_buf[270 * 1024] = { 0 }; - -/* clang-format off */ -static void showUsage() -{ -#ifndef CONNECTION_UART - printf("Usage:\n"); - printf("\nWork as TCP server mode:\n"); - printf("\tvgl_wasm_runtime -s|--server_mode -p|--port \n"); - printf("where\n"); - printf("\t represents the port that would be listened on and the default is 8888\n"); - printf("\nWork as TCP client mode:\n"); - printf("\tvgl_wasm_runtime -a|--host_address -p|--port \n"); - printf("where\n"); - printf("\t represents the network address of host and the default is 127.0.0.1\n"); - printf("\t represents the listen port of host and the default is 8888\n"); -#else - printf("Usage:\n"); - printf("\tvgl_wasm_runtime -u -b \n\n"); - printf("where\n"); - printf("\t represents the UART device name and the default is /dev/ttyS2\n"); - printf("\t represents the UART device baudrate and the default is 115200\n"); -#endif -} -/* clang-format on */ - -static bool -parse_args(int argc, char *argv[]) -{ - int c; - - while (1) { - int optIndex = 0; - static struct option longOpts[] = { -#ifndef CONNECTION_UART - { "server_mode", no_argument, NULL, 's' }, - { "host_address", required_argument, NULL, 'a' }, - { "port", required_argument, NULL, 'p' }, -#else - { "uart", required_argument, NULL, 'u' }, - { "baudrate", required_argument, NULL, 'b' }, -#endif - { "help", required_argument, NULL, 'h' }, - { 0, 0, 0, 0 } - }; - - c = getopt_long(argc, argv, "sa:p:u:b:h", longOpts, &optIndex); - if (c == -1) - break; - - switch (c) { -#ifndef CONNECTION_UART - case 's': - server_mode = true; - break; - case 'a': - host_address = optarg; - printf("host address: %s\n", host_address); - break; - case 'p': - port = atoi(optarg); - printf("port: %d\n", port); - break; -#else - case 'u': - uart_device = optarg; - printf("uart device: %s\n", uart_device); - break; - case 'b': - baudrate = parse_baudrate(atoi(optarg)); - printf("uart baudrate: %s\n", optarg); - break; -#endif - case 'h': - showUsage(); - return false; - default: - showUsage(); - return false; - } - } - - return true; -} - -/** - * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics - * library - */ -static void -hal_init(void) -{ - /* Use the 'monitor' driver which creates window on PC's monitor to simulate - * a display*/ - monitor_init(); - - /*Create a display buffer*/ - static lv_disp_buf_t disp_buf1; - static lv_color_t buf1_1[480 * 10]; - lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 480 * 10); - - /*Create a display*/ - lv_disp_drv_t disp_drv; - - /*Basic initialization*/ - memset(&disp_drv, 0, sizeof(disp_drv)); - lv_disp_drv_init(&disp_drv); - disp_drv.buffer = &disp_buf1; - disp_drv.flush_cb = monitor_flush; - // disp_drv.hor_res = 200; - // disp_drv.ver_res = 100; - lv_disp_drv_register(&disp_drv); - - /* Add the mouse as input device - * Use the 'mouse' driver which reads the PC's mouse*/ - mouse_init(); - lv_indev_drv_t indev_drv; - lv_indev_drv_init(&indev_drv); /*Basic initialization*/ - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read_cb = - mouse_read; /*This function will be called periodically (by the library) - to get the mouse position and state*/ - lv_indev_drv_register(&indev_drv); -} - -// Driver function -int -iwasm_main(int argc, char *argv[]) -{ - RuntimeInitArgs init_args; - korp_tid tid; - - if (!parse_args(argc, argv)) - return -1; - - memset(&init_args, 0, sizeof(RuntimeInitArgs)); - - init_args.mem_alloc_type = Alloc_With_Pool; - init_args.mem_alloc_option.pool.heap_buf = global_heap_buf; - init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); - - /* initialize runtime environment */ - if (!wasm_runtime_full_init(&init_args)) { - printf("Init runtime environment failed.\n"); - return -1; - } - - if (!init_connection_framework()) { - goto fail1; - } - - wgl_init(); - - hal_init(); - - if (!init_sensor_framework()) { - goto fail2; - } - - /* timer manager */ - if (!init_wasm_timer()) { - goto fail3; - } - -#ifndef CONNECTION_UART - if (server_mode) - os_thread_create(&tid, func_server_mode, NULL, - BH_APPLET_PRESERVED_STACK_SIZE); - else - os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE); -#else - os_thread_create(&tid, func_uart_mode, NULL, - BH_APPLET_PRESERVED_STACK_SIZE); -#endif - - app_manager_startup(&interface); - - exit_wasm_timer(); - -fail3: - exit_sensor_framework(); - -fail2: - wgl_exit(); - exit_connection_framework(); - -fail1: - wasm_runtime_destroy(); - return -1; -} diff --git a/samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h b/samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h deleted file mode 100644 index d216a3e90..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h +++ /dev/null @@ -1,310 +0,0 @@ -/** - * @file lv_drv_conf.h - * - */ - -/* - * COPY THIS FILE AS lv_drv_conf.h - */ - -#if 1 /*Set it to "1" to enable the content*/ - -#ifndef LV_DRV_CONF_H -#define LV_DRV_CONF_H - -#include "lv_conf.h" - -/********************* - * DELAY INTERFACE - *********************/ -#define LV_DRV_DELAY_INCLUDE /*Dummy include by default*/ -#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/ -#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/ - -/********************* - * DISPLAY INTERFACE - *********************/ - -/*------------ - * Common - *------------*/ -#define LV_DRV_DISP_INCLUDE /*Dummy include by default*/ -#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/ -#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/ - -/*--------- - * SPI - *---------*/ -#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/ -#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/ -#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/ - -/*------------------ - * Parallel port - *-----------------*/ -#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/ -#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/ -#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/ -#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/ -#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/ - -/*************************** - * INPUT DEVICE INTERFACE - ***************************/ - -/*---------- - * Common - *----------*/ -#define LV_DRV_INDEV_INCLUDE /*Dummy include by default*/ -#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/ -#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/ - -/*--------- - * SPI - *---------*/ -#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/ -#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/ - -/*--------- - * I2C - *---------*/ -#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/ -#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/ -#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/ -#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/ -#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/ - - -/********************* - * DISPLAY DRIVERS - *********************/ - -/*------------------- - * Monitor of PC - *-------------------*/ -#ifndef USE_MONITOR -# define USE_MONITOR 1 -#endif - -#if USE_MONITOR -# define MONITOR_HOR_RES LV_HOR_RES_MAX -# define MONITOR_VER_RES LV_VER_RES_MAX - -/* Scale window by this factor (useful when simulating small screens) */ -# define MONITOR_ZOOM 1 - -/* Used to test true double buffering with only address changing. - * Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */ -# define MONITOR_DOUBLE_BUFFERED 0 - -/*Eclipse: Visual Studio: */ -# define MONITOR_SDL_INCLUDE_PATH - -/*Different rendering might be used if running in a Virtual machine*/ -# define MONITOR_VIRTUAL_MACHINE 0 - -/*Open two windows to test multi display support*/ -# define MONITOR_DUAL 0 -#endif - -/*----------------------------------- - * Native Windows (including mouse) - *----------------------------------*/ -#ifndef USE_WINDOWS -# define USE_WINDOWS 0 -#endif - -#define USE_WINDOWS 0 -#if USE_WINDOWS -# define WINDOW_HOR_RES 480 -# define WINDOW_VER_RES 320 -#endif - -/*---------------- - * SSD1963 - *--------------*/ -#ifndef USE_SSD1963 -# define USE_SSD1963 0 -#endif - -#if USE_SSD1963 -# define SSD1963_HOR_RES LV_HOR_RES -# define SSD1963_VER_RES LV_VER_RES -# define SSD1963_HT 531 -# define SSD1963_HPS 43 -# define SSD1963_LPS 8 -# define SSD1963_HPW 10 -# define SSD1963_VT 288 -# define SSD1963_VPS 12 -# define SSD1963_FPS 4 -# define SSD1963_VPW 10 -# define SSD1963_HS_NEG 0 /*Negative hsync*/ -# define SSD1963_VS_NEG 0 /*Negative vsync*/ -# define SSD1963_ORI 0 /*0, 90, 180, 270*/ -# define SSD1963_COLOR_DEPTH 16 -#endif - -/*---------------- - * R61581 - *--------------*/ -#ifndef USE_R61581 -# define USE_R61581 0 -#endif - -#if USE_R61581 -# define R61581_HOR_RES LV_HOR_RES -# define R61581_VER_RES LV_VER_RES -# define R61581_HSPL 0 /*HSYNC signal polarity*/ -# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/ -# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/ -# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */ -# define R61581_VSPL 0 /*VSYNC signal polarity*/ -# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/ -# define R61581_VFP 8 /*Vertical Front poarch*/ -# define R61581_VBP 8 /*Vertical Back poarch */ -# define R61581_DPL 0 /*DCLK signal polarity*/ -# define R61581_EPL 1 /*ENABLE signal polarity*/ -# define R61581_ORI 0 /*0, 180*/ -# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/ -#endif - -/*------------------------------ - * ST7565 (Monochrome, low res.) - *-----------------------------*/ -#ifndef USE_ST7565 -# define USE_ST7565 0 -#endif - -#if USE_ST7565 -/*No settings*/ -#endif /*USE_ST7565*/ - -/*----------------------------------------- - * Linux frame buffer device (/dev/fbx) - *-----------------------------------------*/ -#ifndef USE_FBDEV -# define USE_FBDEV 1 -#endif - -#if USE_FBDEV -# define FBDEV_PATH "/dev/fb0" -#endif - -/********************* - * INPUT DEVICES - *********************/ - -/*-------------- - * XPT2046 - *--------------*/ -#ifndef USE_XPT2046 -# define USE_XPT2046 0 -#endif - -#if USE_XPT2046 -# define XPT2046_HOR_RES 480 -# define XPT2046_VER_RES 320 -# define XPT2046_X_MIN 200 -# define XPT2046_Y_MIN 200 -# define XPT2046_X_MAX 3800 -# define XPT2046_Y_MAX 3800 -# define XPT2046_AVG 4 -# define XPT2046_INV 0 -#endif - -/*----------------- - * FT5406EE8 - *-----------------*/ -#ifndef USE_FT5406EE8 -# define USE_FT5406EE8 0 -#endif - -#if USE_FT5406EE8 -# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/ -#endif - -/*--------------- - * AD TOUCH - *--------------*/ -#ifndef USE_AD_TOUCH -# define USE_AD_TOUCH 0 -#endif - -#if USE_AD_TOUCH -/*No settings*/ -#endif - - -/*--------------------------------------- - * Mouse or touchpad on PC (using SDL) - *-------------------------------------*/ -#ifndef USE_MOUSE -# define USE_MOUSE 1 -#endif - -#if USE_MOUSE -/*No settings*/ -#endif - -/*------------------------------------------- - * Mousewheel as encoder on PC (using SDL) - *------------------------------------------*/ -#ifndef USE_MOUSEWHEEL -# define USE_MOUSEWHEEL 1 -#endif - -#if USE_MOUSEWHEEL -/*No settings*/ -#endif - -/*------------------------------------------------- - * Touchscreen as libinput interface (for Linux based systems) - *------------------------------------------------*/ -#ifndef USE_LIBINPUT -# define USE_LIBINPUT 0 -#endif - -#if USE_LIBINPUT -# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -#endif /*USE_LIBINPUT*/ - -/*------------------------------------------------- - * Mouse or touchpad as evdev interface (for Linux based systems) - *------------------------------------------------*/ -#ifndef USE_EVDEV -# define USE_EVDEV 0 -#endif - -#if USE_EVDEV -# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/ - -# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */ -# if EVDEV_SCALE -# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */ -# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */ -# endif /*EVDEV_SCALE*/ - -# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/ -# if EVDEV_CALIBRATE -# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/ -# define EVDEV_HOR_MAX 200 -# define EVDEV_VER_MIN 200 -# define EVDEV_VER_MAX 3800 -# endif /*EVDEV_SCALE*/ -#endif /*USE_EVDEV*/ - -/*------------------------------- - * Keyboard of a PC (using SDL) - *------------------------------*/ -#ifndef USE_KEYBOARD -# define USE_KEYBOARD 1 -#endif - -#if USE_KEYBOARD -/*No settings*/ -#endif - -#endif /*LV_DRV_CONF_H*/ - -#endif /*End of "Content enable"*/ diff --git a/samples/gui/wasm-runtime-wgl/src/platform/linux/main.c b/samples/gui/wasm-runtime-wgl/src/platform/linux/main.c deleted file mode 100644 index 741e54fd8..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/linux/main.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#include -#include - -extern int -iwasm_main(int argc, char *argv[]); - -int -main(int argc, char *argv[]) -{ - return iwasm_main(argc, argv); -} - -int -time_get_ms() -{ - static struct timeval tv; - gettimeofday(&tv, NULL); - long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000; - - return (int)time_in_mill; -} diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE deleted file mode 100644 index 8f71f43fe..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h deleted file mode 100644 index 228321dcc..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h +++ /dev/null @@ -1,65 +0,0 @@ -/** - * @file XPT2046.h - * - */ - -#ifndef XPT2046_H -#define XPT2046_H - -#define USE_XPT2046 1 - -#define XPT2046_HOR_RES 320 -#define XPT2046_VER_RES 240 -#define XPT2046_X_MIN 200 -#define XPT2046_Y_MIN 200 -#define XPT2046_X_MAX 3800 -#define XPT2046_Y_MAX 3800 -#define XPT2046_AVG 4 -#define XPT2046_INV 0 - -#define CMD_X_READ 0b10010000 -#define CMD_Y_READ 0b11010000 - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -#if USE_XPT2046 -#include -#include -#include -#include "lv_hal/lv_hal_indev.h" -#include "device.h" -#include "drivers/gpio.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void -xpt2046_init(void); -bool -xpt2046_read(lv_indev_data_t *data); - -/********************** - * MACROS - **********************/ - -#endif /* USE_XPT2046 */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* XPT2046_H */ diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h deleted file mode 100644 index d7ea279a9..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#ifndef __BOARD_CONFIG_H__ -#define __BOARD_CONFIG_H__ -#include "pin_config_stm32.h" - -#endif /* __BOARD_CONFIG_H__ */ diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h deleted file mode 100644 index 8354ca378..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright (c) 2017 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Public API for display drivers and applications - */ - -#ifndef ZEPHYR_INCLUDE_DISPLAY_H_ -#define ZEPHYR_INCLUDE_DISPLAY_H_ - -/** - * @brief Display Interface - * @defgroup display_interface Display Interface - * @ingroup display_interfaces - * @{ - */ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -enum display_pixel_format { - PIXEL_FORMAT_RGB_888 = BIT(0), - PIXEL_FORMAT_MONO01 = BIT(1), /* 0=Black 1=White */ - PIXEL_FORMAT_MONO10 = BIT(2), /* 1=Black 0=White */ - PIXEL_FORMAT_ARGB_8888 = BIT(3), - PIXEL_FORMAT_RGB_565 = BIT(4), -}; - -enum display_screen_info { - /** - * If selected, one octet represents 8 pixels ordered vertically, - * otherwise ordered horizontally. - */ - SCREEN_INFO_MONO_VTILED = BIT(0), - /** - * If selected, the MSB represents the first pixel, - * otherwise MSB represents the last pixel. - */ - SCREEN_INFO_MONO_MSB_FIRST = BIT(1), - /** - * Electrophoretic Display. - */ - SCREEN_INFO_EPD = BIT(2), - /** - * Screen has two alternating ram buffers - */ - SCREEN_INFO_DOUBLE_BUFFER = BIT(3), -}; - -/** - * @enum display_orientation - * @brief Enumeration with possible display orientation - * - */ -enum display_orientation { - DISPLAY_ORIENTATION_NORMAL, - DISPLAY_ORIENTATION_ROTATED_90, - DISPLAY_ORIENTATION_ROTATED_180, - DISPLAY_ORIENTATION_ROTATED_270, -}; - -/** - * @struct display_capabilities - * @brief Structure holding display capabilities - * - * @var u16_t display_capabilities::x_resolution - * Display resolution in the X direction - * - * @var u16_t display_capabilities::y_resolution - * Display resolution in the Y direction - * - * @var u32_t display_capabilities::supported_pixel_formats - * Bitwise or of pixel formats supported by the display - * - * @var u32_t display_capabilities::screen_info - * Information about display panel - * - * @var enum display_pixel_format display_capabilities::current_pixel_format - * Currently active pixel format for the display - * - * @var enum display_orientation display_capabilities::current_orientation - * Current display orientation - * - */ -struct display_capabilities { - u16_t x_resolution; - u16_t y_resolution; - u32_t supported_pixel_formats; - u32_t screen_info; - enum display_pixel_format current_pixel_format; - enum display_orientation current_orientation; -}; - -/** - * @struct display_buffer_descriptor - * @brief Structure to describe display data buffer layout - * - * @var u32_t display_buffer_descriptor::buf_size - * Data buffer size in bytes - * - * @var u16_t display_buffer_descriptor::width - * Data buffer row width in pixels - * - * @var u16_t display_buffer_descriptor::height - * Data buffer column height in pixels - * - * @var u16_t display_buffer_descriptor::pitch - * Number of pixels between consecutive rows in the data buffer - * - */ -struct display_buffer_descriptor { - u32_t buf_size; - u16_t width; - u16_t height; - u16_t pitch; -}; - -/** - * @typedef display_blanking_on_api - * @brief Callback API to turn on display blanking - * See display_blanking_on() for argument description - */ -typedef int (*display_blanking_on_api)(const struct device *dev); - -/** - * @typedef display_blanking_off_api - * @brief Callback API to turn off display blanking - * See display_blanking_off() for argument description - */ -typedef int (*display_blanking_off_api)(const struct device *dev); - -/** - * @typedef display_write_api - * @brief Callback API for writing data to the display - * See display_write() for argument description - */ -typedef int (*display_write_api)(const struct device *dev, const u16_t x, - const u16_t y, - const struct display_buffer_descriptor *desc, - const void *buf); - -/** - * @typedef display_read_api - * @brief Callback API for reading data from the display - * See display_read() for argument description - */ -typedef int (*display_read_api)(const struct device *dev, const u16_t x, - const u16_t y, - const struct display_buffer_descriptor *desc, - void *buf); - -/** - * @typedef display_get_framebuffer_api - * @brief Callback API to get framebuffer pointer - * See display_get_framebuffer() for argument description - */ -typedef void *(*display_get_framebuffer_api)(const struct device *dev); - -/** - * @typedef display_set_brightness_api - * @brief Callback API to set display brightness - * See display_set_brightness() for argument description - */ -typedef int (*display_set_brightness_api)(const struct device *dev, - const u8_t brightness); - -/** - * @typedef display_set_contrast_api - * @brief Callback API to set display contrast - * See display_set_contrast() for argument description - */ -typedef int (*display_set_contrast_api)(const struct device *dev, - const u8_t contrast); - -/** - * @typedef display_get_capabilities_api - * @brief Callback API to get display capabilities - * See display_get_capabilities() for argument description - */ -typedef void (*display_get_capabilities_api)( - const struct device *dev, struct display_capabilities *capabilities); - -/** - * @typedef display_set_pixel_format_api - * @brief Callback API to set pixel format used by the display - * See display_set_pixel_format() for argument description - */ -typedef int (*display_set_pixel_format_api)( - const struct device *dev, const enum display_pixel_format pixel_format); - -/** - * @typedef display_set_orientation_api - * @brief Callback API to set orientation used by the display - * See display_set_orientation() for argument description - */ -typedef int (*display_set_orientation_api)( - const struct device *dev, const enum display_orientation orientation); - -/** - * @brief Display driver API - * API which a display driver should expose - */ -struct display_driver_api { - display_blanking_on_api blanking_on; - display_blanking_off_api blanking_off; - display_write_api write; - display_read_api read; - display_get_framebuffer_api get_framebuffer; - display_set_brightness_api set_brightness; - display_set_contrast_api set_contrast; - display_get_capabilities_api get_capabilities; - display_set_pixel_format_api set_pixel_format; - display_set_orientation_api set_orientation; -}; -extern struct ili9340_data ili9340_data1; -extern struct display_driver_api ili9340_api1; -/** - * @brief Write data to display - * - * @param dev Pointer to device structure - * @param x x Coordinate of the upper left corner where to write the buffer - * @param y y Coordinate of the upper left corner where to write the buffer - * @param desc Pointer to a structure describing the buffer layout - * @param buf Pointer to buffer array - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_write(const struct device *dev, const u16_t x, const u16_t y, - const struct display_buffer_descriptor *desc, const void *buf) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->write(dev, x, y, desc, buf); -} - -/** - * @brief Read data from display - * - * @param dev Pointer to device structure - * @param x x Coordinate of the upper left corner where to read from - * @param y y Coordinate of the upper left corner where to read from - * @param desc Pointer to a structure describing the buffer layout - * @param buf Pointer to buffer array - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_read(const struct device *dev, const u16_t x, const u16_t y, - const struct display_buffer_descriptor *desc, void *buf) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->read(dev, x, y, desc, buf); -} - -/** - * @brief Get pointer to framebuffer for direct access - * - * @param dev Pointer to device structure - * - * @retval Pointer to frame buffer or NULL if direct framebuffer access - * is not supported - * - */ -static inline void * -display_get_framebuffer(const struct device *dev) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->get_framebuffer(dev); -} - -/** - * @brief Turn display blanking on - * - * @param dev Pointer to device structure - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_blanking_on(const struct device *dev) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->blanking_on(dev); -} - -/** - * @brief Turn display blanking off - * - * @param dev Pointer to device structure - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_blanking_off(const struct device *dev) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->blanking_off(dev); -} - -/** - * @brief Set the brightness of the display - * - * Set the brightness of the display in steps of 1/256, where 255 is full - * brightness and 0 is minimal. - * - * @param dev Pointer to device structure - * @param brightness Brightness in steps of 1/256 - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_set_brightness(const struct device *dev, u8_t brightness) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->set_brightness(dev, brightness); -} - -/** - * @brief Set the contrast of the display - * - * Set the contrast of the display in steps of 1/256, where 255 is maximum - * difference and 0 is minimal. - * - * @param dev Pointer to device structure - * @param contrast Contrast in steps of 1/256 - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_set_contrast(const struct device *dev, u8_t contrast) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->set_contrast(dev, contrast); -} - -/** - * @brief Get display capabilities - * - * @param dev Pointer to device structure - * @param capabilities Pointer to capabilities structure to populate - */ -static inline void -display_get_capabilities(const struct device *dev, - struct display_capabilities *capabilities) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - api->get_capabilities(dev, capabilities); -} - -/** - * @brief Set pixel format used by the display - * - * @param dev Pointer to device structure - * @param pixel_format Pixel format to be used by display - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_set_pixel_format(const struct device *dev, - const enum display_pixel_format pixel_format) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->set_pixel_format(dev, pixel_format); -} - -/** - * @brief Set display orientation - * - * @param dev Pointer to device structure - * @param orientation Orientation to be used by display - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_set_orientation(const struct device *dev, - const enum display_orientation orientation) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->set_orientation(dev, orientation); -} - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* ZEPHYR_INCLUDE_DISPLAY_H_*/ diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c deleted file mode 100644 index 6dd8a330a..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (c) 2017 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "display_ili9340.h" -#include - -//#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL -//#include -// LOG_MODULE_REGISTER(display_ili9340); -#define LOG_ERR printf -#define LOG_DBG printf -#define LOG_WRN printf - -#include -#include -#include -#include -#include - -struct ili9340_data { - struct device *reset_gpio; - struct device *command_data_gpio; - struct device *spi_dev; - struct spi_config spi_config; -#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER - struct spi_cs_control cs_ctrl; -#endif -}; - -struct ili9340_data ili9340_data1; - -#define ILI9340_CMD_DATA_PIN_COMMAND 0 -#define ILI9340_CMD_DATA_PIN_DATA 1 - -static void -ili9340_exit_sleep(struct ili9340_data *data) -{ - ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0); - // k_sleep(Z_TIMEOUT_MS(120)); -} - -int -ili9340_init() -{ - struct ili9340_data *data = &ili9340_data1; - printf("Initializing display driver\n"); - data->spi_dev = device_get_binding(DT_ILITEK_ILI9340_0_BUS_NAME); - if (data->spi_dev == NULL) { - return -EPERM; - } - data->spi_config.frequency = DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY; - data->spi_config.operation = - SPI_OP_MODE_MASTER - | SPI_WORD_SET(8); // SPI_OP_MODE_MASTER | SPI_WORD_SET(8); - data->spi_config.slave = DT_ILITEK_ILI9340_0_BASE_ADDRESS; - -#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER - data->cs_ctrl.gpio_dev = - device_get_binding(DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER); - data->cs_ctrl.gpio_pin = DT_ILITEK_ILI9340_0_CS_GPIO_PIN; - data->cs_ctrl.delay = 0; - data->spi_config.cs = &(data->cs_ctrl); -#else - data->spi_config.cs = NULL; -#endif - data->reset_gpio = - device_get_binding(DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER); - if (data->reset_gpio == NULL) { - return -EPERM; - } - - gpio_pin_configure(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, - GPIO_OUTPUT); - - data->command_data_gpio = - device_get_binding(DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER); - if (data->command_data_gpio == NULL) { - return -EPERM; - } - - gpio_pin_configure(data->command_data_gpio, - DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, GPIO_OUTPUT); - - LOG_DBG("Resetting display driver\n"); - gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1); - k_sleep(Z_TIMEOUT_MS(1)); - gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 0); - k_sleep(Z_TIMEOUT_MS(1)); - gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1); - k_sleep(Z_TIMEOUT_MS(5)); - - LOG_DBG("Initializing LCD\n"); - ili9340_lcd_init(data); - - LOG_DBG("Exiting sleep mode\n"); - ili9340_exit_sleep(data); - - return 0; -} - -static void -ili9340_set_mem_area(struct ili9340_data *data, const u16_t x, const u16_t y, - const u16_t w, const u16_t h) -{ - u16_t spi_data[2]; - - spi_data[0] = sys_cpu_to_be16(x); - spi_data[1] = sys_cpu_to_be16(x + w - 1); - ili9340_transmit(data, ILI9340_CMD_COLUMN_ADDR, &spi_data[0], 4); - - spi_data[0] = sys_cpu_to_be16(y); - spi_data[1] = sys_cpu_to_be16(y + h - 1); - ili9340_transmit(data, ILI9340_CMD_PAGE_ADDR, &spi_data[0], 4); -} - -static int -ili9340_write(const struct device *dev, const u16_t x, const u16_t y, - const struct display_buffer_descriptor *desc, const void *buf) -{ - struct ili9340_data *data = (struct ili9340_data *)&ili9340_data1; - const u8_t *write_data_start = (u8_t *)buf; - struct spi_buf tx_buf; - struct spi_buf_set tx_bufs; - u16_t write_cnt; - u16_t nbr_of_writes; - u16_t write_h; - - __ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width"); - __ASSERT((3 * desc->pitch * desc->height) <= desc->buf_size, - "Input buffer to small"); - ili9340_set_mem_area(data, x, y, desc->width, desc->height); - - if (desc->pitch > desc->width) { - write_h = 1U; - nbr_of_writes = desc->height; - } - else { - write_h = desc->height; - nbr_of_writes = 1U; - } - ili9340_transmit(data, ILI9340_CMD_MEM_WRITE, (void *)write_data_start, - 3 * desc->width * write_h); - - tx_bufs.buffers = &tx_buf; - tx_bufs.count = 1; - - write_data_start += (3 * desc->pitch); - for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) { - tx_buf.buf = (void *)write_data_start; - tx_buf.len = 3 * desc->width * write_h; - spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); - write_data_start += (3 * desc->pitch); - } - - return 0; -} - -static int -ili9340_read(const struct device *dev, const u16_t x, const u16_t y, - const struct display_buffer_descriptor *desc, void *buf) -{ - LOG_ERR("Reading not supported\n"); - return -ENOTSUP; -} - -static void * -ili9340_get_framebuffer(const struct device *dev) -{ - LOG_ERR("Direct framebuffer access not supported\n"); - return NULL; -} - -static int -ili9340_display_blanking_off(const struct device *dev) -{ - struct ili9340_data *data = (struct ili9340_data *)dev->driver_data; - - LOG_DBG("Turning display blanking off\n"); - ili9340_transmit(data, ILI9340_CMD_DISPLAY_ON, NULL, 0); - return 0; -} - -static int -ili9340_display_blanking_on(const struct device *dev) -{ - struct ili9340_data *data = (struct ili9340_data *)dev->driver_data; - - LOG_DBG("Turning display blanking on\n"); - ili9340_transmit(data, ILI9340_CMD_DISPLAY_OFF, NULL, 0); - return 0; -} - -static int -ili9340_set_brightness(const struct device *dev, const u8_t brightness) -{ - LOG_WRN("Set brightness not implemented\n"); - return -ENOTSUP; -} - -static int -ili9340_set_contrast(const struct device *dev, const u8_t contrast) -{ - LOG_ERR("Set contrast not supported\n"); - return -ENOTSUP; -} - -static int -ili9340_set_pixel_format(const struct device *dev, - const enum display_pixel_format pixel_format) -{ - if (pixel_format == PIXEL_FORMAT_RGB_888) { - return 0; - } - LOG_ERR("Pixel format change not implemented\n"); - return -ENOTSUP; -} - -static int -ili9340_set_orientation(const struct device *dev, - const enum display_orientation orientation) -{ - if (orientation == DISPLAY_ORIENTATION_NORMAL) { - return 0; - } - LOG_ERR("Changing display orientation not implemented\n"); - return -ENOTSUP; -} - -static void -ili9340_get_capabilities(const struct device *dev, - struct display_capabilities *capabilities) -{ - memset(capabilities, 0, sizeof(struct display_capabilities)); - capabilities->x_resolution = 320; - capabilities->y_resolution = 240; - capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_888; - capabilities->current_pixel_format = PIXEL_FORMAT_RGB_888; - capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL; -} - -void -ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data, - size_t tx_len) -{ - data = (struct ili9340_data *)&ili9340_data1; - struct spi_buf tx_buf = { .buf = &cmd, .len = 1 }; - struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 }; - - gpio_pin_set(data->command_data_gpio, - DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, - ILI9340_CMD_DATA_PIN_COMMAND); - spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); - if (tx_data != NULL) { - tx_buf.buf = tx_data; - tx_buf.len = tx_len; - gpio_pin_set(data->command_data_gpio, - DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, - ILI9340_CMD_DATA_PIN_DATA); - spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); - } -} - -struct display_driver_api ili9340_api1 = { - .blanking_on = ili9340_display_blanking_on, - .blanking_off = ili9340_display_blanking_off, - .write = ili9340_write, - .read = ili9340_read, - .get_framebuffer = ili9340_get_framebuffer, - .set_brightness = ili9340_set_brightness, - .set_contrast = ili9340_set_contrast, - .get_capabilities = ili9340_get_capabilities, - .set_pixel_format = ili9340_set_pixel_format, - .set_orientation = ili9340_set_orientation -}; - -/* - DEVICE_AND_API_INIT(ili9340, DT_ILITEK_ILI9340_0_LABEL, &ili9340_init, - &ili9340_data, NULL, APPLICATION, - CONFIG_APPLICATION_INIT_PRIORITY, &ili9340_api); - */ diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c deleted file mode 100644 index 1077a87f1..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2017 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "display_ili9340.h" - -void -ili9340_lcd_init(struct ili9340_data *data) -{ - u8_t tx_data[15]; - - tx_data[0] = 0x23; - ili9340_transmit(data, ILI9340_CMD_POWER_CTRL_1, tx_data, 1); - - tx_data[0] = 0x10; - ili9340_transmit(data, ILI9340_CMD_POWER_CTRL_2, tx_data, 1); - - tx_data[0] = 0x3e; - tx_data[1] = 0x28; - ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_1, tx_data, 2); - - tx_data[0] = 0x86; - ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1); - - tx_data[0] = - ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR; - ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1); - - tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT - | ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT; - ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1); - - tx_data[0] = 0x00; - tx_data[1] = 0x18; - ili9340_transmit(data, ILI9340_CMD_FRAME_CTRL_NORMAL_MODE, tx_data, 2); - - tx_data[0] = 0x08; - tx_data[1] = 0x82; - tx_data[2] = 0x27; - ili9340_transmit(data, ILI9340_CMD_DISPLAY_FUNCTION_CTRL, tx_data, 3); - - tx_data[0] = 0x01; - ili9340_transmit(data, ILI9340_CMD_GAMMA_SET, tx_data, 1); - - tx_data[0] = 0x0F; - tx_data[1] = 0x31; - tx_data[2] = 0x2B; - tx_data[3] = 0x0C; - tx_data[4] = 0x0E; - tx_data[5] = 0x08; - tx_data[6] = 0x4E; - tx_data[7] = 0xF1; - tx_data[8] = 0x37; - tx_data[9] = 0x07; - tx_data[10] = 0x10; - tx_data[11] = 0x03; - tx_data[12] = 0x0E; - tx_data[13] = 0x09; - tx_data[14] = 0x00; - ili9340_transmit(data, ILI9340_CMD_POSITVE_GAMMA_CORRECTION, tx_data, 15); - - tx_data[0] = 0x00; - tx_data[1] = 0x0E; - tx_data[2] = 0x14; - tx_data[3] = 0x03; - tx_data[4] = 0x11; - tx_data[5] = 0x07; - tx_data[6] = 0x31; - tx_data[7] = 0xC1; - tx_data[8] = 0x48; - tx_data[9] = 0x08; - tx_data[10] = 0x0F; - tx_data[11] = 0x0C; - tx_data[12] = 0x31; - tx_data[13] = 0x36; - tx_data[14] = 0x0F; - ili9340_transmit(data, ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION, tx_data, 15); -} diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c deleted file mode 100644 index e6254e5b9..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include "bh_platform.h" -#include "bh_assert.h" -#include "bh_log.h" -#include "wasm_export.h" - -extern int -iwasm_main(); - -void -main(void) -{ - iwasm_main(); - for (;;) { - k_sleep(Z_TIMEOUT_MS(1000)); - } -} - -int -time_get_ms() -{ - return k_uptime_get_32(); -} diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h deleted file mode 100644 index bb20ecbb8..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#ifndef __PIN_CONFIG_JLF_H__ -#define __PIN_CONFIG_JLF_H__ - -#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2" -#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10 * 1000 - -#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1 -#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIO_0" -#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 5 -#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIO_0" -#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4 - -#define XPT2046_SPI_DEVICE_NAME "SPI_2" -#define XPT2046_SPI_MAX_FREQUENCY 10 * 1000 -#define XPT2046_CS_GPIO_CONTROLLER "GPIO_0" -#define XPT2046_CS_GPIO_PIN 6 - -#define XPT2046_PEN_GPIO_CONTROLLER "GPIO_0" -#define XPT2046_PEN_GPIO_PIN 7 - -#define HOST_DEVICE_COMM_UART_NAME "UART_1" -#endif /* __PIN_CONFIG_JLF_H__ */ diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h deleted file mode 100644 index 523ce2308..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#ifndef __PIN_CONFIG_STM32_H__ -#define __PIN_CONFIG_STM32_H__ - -#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_1" -#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 24 * 1000 * 1000 - -#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1 -#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIOC" -#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 12 -#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIOC" -#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 11 - -#define DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER "GPIOC" -#define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10 - -#define XPT2046_SPI_DEVICE_NAME "SPI_1" -#define XPT2046_SPI_MAX_FREQUENCY 12 * 1000 * 1000 -#define XPT2046_CS_GPIO_CONTROLLER "GPIOD" -#define XPT2046_CS_GPIO_PIN 0 - -#define XPT2046_PEN_GPIO_CONTROLLER "GPIOD" -#define XPT2046_PEN_GPIO_PIN 1 - -#define HOST_DEVICE_COMM_UART_NAME "UART_6" - -#endif /* __PIN_CONFIG_STM32_H__ */ diff --git a/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt b/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt deleted file mode 100644 index 005358c72..000000000 --- a/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required(VERSION 3.8.2) - -include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) -project(NONE) - -set (WAMR_BUILD_PLATFORM "zephyr") - -enable_language (ASM) - -add_definitions(-DWA_MALLOC=wasm_runtime_malloc) -add_definitions(-DWA_FREE=wasm_runtime_free) - -# Build as THUMB by default -# change to "ARM[sub]", "THUMB[sub]", "X86_32", "MIPS" or "XTENSA" -# if we want to support arm_32, x86, mips or xtensa -if (NOT DEFINED WAMR_BUILD_TARGET) - set (WAMR_BUILD_TARGET "THUMBV7") -endif () - -if (NOT DEFINED WAMR_BUILD_INTERP) - # Enable Interpreter by default - set (WAMR_BUILD_INTERP 1) -endif () - -if (NOT DEFINED WAMR_BUILD_AOT) - set (WAMR_BUILD_AOT 1) -endif () - -if (NOT DEFINED WAMR_BUILD_JIT) - # Disable JIT by default. - set (WAMR_BUILD_JIT 0) -endif () - -if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) - # Enable libc builtin support by default - set (WAMR_BUILD_LIBC_BUILTIN 1) -endif () - -if (NOT DEFINED WAMR_BUILD_LIBC_WASI) - # Disable libc wasi support by default - set (WAMR_BUILD_LIBC_WASI 0) -endif () - -if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK) - set (WAMR_BUILD_APP_FRAMEWORK 1) -endif () - -if (NOT DEFINED WAMR_BUILD_APP_LIST) - set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_ALL) -endif () - -################ wamr runtime settings ################ -set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wamr) -include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) - -################ sample project related ################ -add_definitions(-DLV_CONF_INCLUDE_SIMPLE) -add_definitions(-DLV_MEM_CUSTOM=1) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr) -include_directories(${WAMR_ROOT_DIR}/samples/gui/lv_config) - -set (LVGL_DRV_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340_adafruit_1480.c - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340.c - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/XPT2046.c - ) - -target_sources(app PRIVATE - ${WAMR_RUNTIME_LIB_SOURCE} - ${LVGL_DRV_SRCS} - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/iwasm_main.c - ) diff --git a/samples/gui/wasm-runtime-wgl/zephyr-build/prj.conf b/samples/gui/wasm-runtime-wgl/zephyr-build/prj.conf deleted file mode 100644 index f9f13f9a7..000000000 --- a/samples/gui/wasm-runtime-wgl/zephyr-build/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_SPI=y -CONFIG_SPI_STM32=y -CONFIG_SPI_1=y -CONFIG_PRINTK=y -CONFIG_LOG=y -#CONFIG_UART_2=y -CONFIG_UART_INTERRUPT_DRIVEN=y -CONFIG_STACK_SENTINEL=y -CONFIG_MAIN_STACK_SIZE=2048 -CONFIG_ARM_MPU=y diff --git a/samples/littlevgl/LICENCE.txt b/samples/littlevgl/LICENCE.txt deleted file mode 100644 index beaef1d26..000000000 --- a/samples/littlevgl/LICENCE.txt +++ /dev/null @@ -1,8 +0,0 @@ -MIT licence -Copyright (c) 2016 Gábor Kiss-Vámosi - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/samples/littlevgl/README.md b/samples/littlevgl/README.md deleted file mode 100644 index 87fd2bd42..000000000 --- a/samples/littlevgl/README.md +++ /dev/null @@ -1,174 +0,0 @@ -"littlevgl" sample introduction -============== -This sample demonstrates that a graphic user interface application in WebAssembly by compiling the LittlevGL v5.3, an open-source embedded 2d graphic library into the WASM bytecode. - -In this sample, the whole LittlevGL v5.3 source code is built into the WebAssembly code with the user application. The platform interfaces defined by LittlevGL is implemented in the runtime and registered for WASM application through calling wasm_runtime_full_init(). - -```C -static NativeSymbol native_symbols[] = { - EXPORT_WASM_API_WITH_SIG(display_input_read, "(*)i"), - EXPORT_WASM_API_WITH_SIG(display_flush, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(display_fill, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(display_vdb_write, "(*iii*i)"), - EXPORT_WASM_API_WITH_SIG(display_map, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i") -}; -``` - -The runtime component supports building target for Linux and Zephyr/STM Nucleo board. The beauty of this sample is the WebAssembly application can have identical display and behavior when running from both runtime environments. That implies we can do majority of application validation from desktop environment as long as two runtime distributions support the same set of application interface. - - -Below pictures show the WASM application is running on an STM board with an LCD touch panel. - -![WAMR UI SAMPLE](../../doc/pics/vgl_demo2.png "WAMR UI DEMO STM32") - -![WAMR UI SAMPLE](../../doc/pics/vgl_demo_linux.png "WAMR UI DEMO LINUX") - - -The number on top will plus one each second, and the number on the bottom will plus one when clicked. When users click the blue button, the WASM application increases the counter, and the latest counter value is displayed on the top banner of the touch panel. - -The sample also provides the native Linux version of application without the runtime under folder "vgl-native-ui-app". It can help to check differences between the implementations in native and WebAssembly. - -Test on Linux -================================ - -Install required SDK and libraries --------------- -- 32 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_32` when building WAMR runtime) -Use apt-get: - ```bash - sudo apt-get install libsdl2-dev:i386 - ``` -Or download source from www.libsdl.org: - ```bash - ./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32 - make - sudo make install - ``` -- 64 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_64` when building WAMR runtime) -Use apt-get: - ```bash - sudo apt-get install libsdl2-dev - ``` -Or download source from www.libsdl.org: - ```bash - ./configure - make - sudo make install - ``` - -Build and Run --------------- - -- Build - ```bash - ./build.sh - ``` - All binaries are in "out", which contains "host_tool", "vgl_native_ui_app", "ui_app.wasm" "ui_app_no_wasi.wasm "and "vgl_wasm_runtime". -- Run the native Linux build of the lvgl sample (no wasm) - ```bash - ./vgl_native_ui_app - ``` - -- Run WASM VM Linux applicaton & install WASM APP - First start vgl_wasm_runtime in server mode. - ```bash - ./vgl_wasm_runtime -s - ``` - Then install and uninstall wasm APPs by using host tool. - ```bash - ./host_tool -i ui_wasi -f ui_app_wasi.wasm - ./host_tool -q - ./host_tool -u ui_wasi - ./host_tool -i ui_no_wasi -f ui_app_builtin_libc.wasm - ./host_tool -q - ./host_tool -u ui_no_wasi - ``` - -Test on Zephyr -================================ -We can use a STM32 NUCLEO_F767ZI board with ILI9341 display and XPT2046 touch screen to run the test. Then use host_tool to remotely install wasm app into STM32. -- Build WASM VM into Zephyr system - a. clone zephyr source code - Refer to [Zephyr getting started](https://docs.zephyrproject.org/latest/getting_started/index.html). - - ```bash - west init zephyrproject - cd zephyrproject/zephyr - git checkout zephyr-v2.3.0 - cd .. - west update - ``` - - b. copy samples - ```bash - cd zephyr/samples/ - cp -a /samples/littlevgl/vgl-wasm-runtime vgl-wasm-runtime - cd vgl-wasm-runtime/zephyr_build - ``` - c. create a link to wamr root dir - ```bash - ln -s wamr - ``` - -d. build source code - Since ui_app incorporated LittlevGL source code, so it needs more RAM on the device to install the application. It is recommended that RAM SIZE not less than 380KB. In our test use nucleo_f767zi, which is supported by Zephyr. Since the littlevgl wasm app is quite big (~100KB in wasm format and ~200KB in AOT format ), there isn't enough SRAM to build interpreter and AOT together. You can only choose one of them: - - - Interpreter - ```bash - mkdir build && cd build - source ../../../../zephyr-env.sh - cmake -GNinja -DBOARD=nucleo_f767zi -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_AOT=0 .. - ninja flash - ``` - - - AOT - ```bash - mkdir build && cd build - source ../../../../zephyr-env.sh - cmake -GNinja -DBOARD=nucleo_f767zi -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_AOT=1 .. - ninja flash - ``` - -- Hardware Connections - -``` -+-------------------+-+------------------+ -|NUCLEO-F767ZI | ILI9341 Display | -+-------------------+-+------------------+ -| CN7.10 | CLK | -+-------------------+-+------------------+ -| CN7.12 | MISO | -+-------------------+-+------------------+ -| CN7.14 | MOSI | -+-------------------+-+------------------+ -| CN11.1 | CS1 for ILI9341 | -+-------------------+-+------------------+ -| CN11.2 | D/C | -+-------------------+-+------------------+ -| CN11.3 | RESET | -+-------------------+-+------------------+ -| CN9.25 | PEN interrupt | -+-------------------+-+------------------+ -| CN9.27 | CS2 for XPT2046 | -+-------------------+-+------------------+ -| CN10.14 | PC UART RX | -+-------------------+-+------------------+ -| CN11.16 | PC UART RX | -+-------------------+-+------------------+ -``` - -- Install WASM application to Zephyr using host_tool -First, connect PC and STM32 with UART. Then install to use host_tool. - ```bash - sudo ./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app_builtin_libc.wasm - # /dev/ttyUSBXXX is the UART device, e.g. /dev/ttyUSB0 - ``` -**Note**: WASI is unavailable on zephyr currently, so you have to use the ui_app_builtin_libc.wasm which doesn't depend on WASI. - -- Install AOT version WASM application - ```bash - wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app_no_wasi.aot ui_app_builtin_libc.wasm - ./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app_no_wasi.aot - ``` - diff --git a/samples/littlevgl/build.sh b/samples/littlevgl/build.sh deleted file mode 100755 index 81f2e67f4..000000000 --- a/samples/littlevgl/build.sh +++ /dev/null @@ -1,102 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -#!/bin/bash - -PROJECT_DIR=$PWD -WAMR_DIR=${PWD}/../.. -OUT_DIR=${PWD}/out -BUILD_DIR=${PWD}/build -LV_CFG_PATH=${PROJECT_DIR}/lv_config - - - -if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then - echo "Local Build Env" - cmakewrap="cmake" - makewrap="make" -else - echo "Klocwork Build Env" - cmakewrap="cmake -DCMAKE_BUILD_TYPE=Debug" - makewrap="kwinject -o $KW_OUT_FILE make" -fi - -if [ ! -d $BUILD_DIR ]; then - mkdir ${BUILD_DIR} -fi - -rm -rf ${OUT_DIR} -mkdir ${OUT_DIR} - - -cd ${BUILD_DIR} -if [ ! -d "lvgl" ]; then - echo "starting download lvgl for v5.3 ..." - git clone https://github.com/lvgl/lvgl.git --branch v5.3 - if [ $? != 0 ];then - echo "download lvgl repo failed: $?\n" - exit 2 - fi -fi - -echo "##################### 0. build wamr-sdk littlevgl start#####################" -cd ${WAMR_DIR}/wamr-sdk -./build_sdk.sh -n littlevgl -x ${PROJECT_DIR}/wamr_config_littlevgl.cmake -e ${LV_CFG_PATH} -c -[ $? -eq 0 ] || exit $? -echo "#####################build wamr-sdk littlevgl success" - -echo -e "\n\n" -echo "##################### 1. build native-ui-app start#####################" -cd $BUILD_DIR -mkdir -p vgl-native-ui-app -cd vgl-native-ui-app -$cmakewrap ${PROJECT_DIR}/vgl-native-ui-app -$makewrap -if [ $? != 0 ];then - echo "BUILD_FAIL native-ui-app $?\n" - exit 2 -fi -echo $PWD -cp vgl_native_ui_app ${OUT_DIR} -echo "#####################build native-ui-app success" - -echo -e "\n\n" -echo "##################### 2. build littlevgl wasm runtime start#####################" -cd $BUILD_DIR -mkdir -p vgl-wasm-runtime -cd vgl-wasm-runtime -$cmakewrap ${PROJECT_DIR}/vgl-wasm-runtime -$makewrap -[ $? -eq 0 ] || exit $? -cp vgl_wasm_runtime ${OUT_DIR}/ - -echo "##################### build littlevgl wasm runtime end#####################" - -echo -e "\n\n" -echo "#####################build host-tool" -cd $BUILD_DIR -mkdir -p host-tool -cd host-tool -$cmakewrap ${WAMR_DIR}/test-tools/host-tool -$makewrap -if [ $? != 0 ];then - echo "BUILD_FAIL host tool exit as $?\n" - exit 2 -fi -cp host_tool ${OUT_DIR} -echo "#####################build host-tool success" - -echo -e "\n\n" -echo "##################### 3. build wasm ui app start#####################" -cd ${PROJECT_DIR}/wasm-apps -if [ ! -d "${PROJECT_DIR}/wasm-apps/lvgl" ]; then - if [ -d "$BUILD_DIR/vgl-native-ui-app/lvgl" ]; then - cp -fr $BUILD_DIR/vgl-native-ui-app/lvgl ${PROJECT_DIR}/wasm-apps - fi -fi -./build_wasm_app.sh -mv *.wasm ${OUT_DIR}/ - -echo "##################### build wasm ui app end#####################" diff --git a/samples/littlevgl/lv_config/lv_conf.h b/samples/littlevgl/lv_config/lv_conf.h deleted file mode 100644 index 76533a8e1..000000000 --- a/samples/littlevgl/lv_config/lv_conf.h +++ /dev/null @@ -1,389 +0,0 @@ -/** - * @file lv_conf.h - * - */ - -#if 1 /*Set it to "1" to enable content*/ - -#ifndef LV_CONF_H -#define LV_CONF_H -/*=================== - Dynamic memory - *===================*/ - -/* Memory size which will be used by the library - * to store the graphical objects and other data */ -#define LV_MEM_CUSTOM 1 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/ -#if LV_MEM_CUSTOM == 0 -# define LV_MEM_SIZE (64U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ -# define LV_MEM_ATTR /*Complier prefix for big array declaration*/ -# define LV_MEM_ADR 0 /*Set an address for memory pool instead of allocation it as an array. Can be in external SRAM too.*/ -# define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/ -#else /*LV_MEM_CUSTOM*/ -# define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ -# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ -# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ -#endif /*LV_MEM_CUSTOM*/ - -/* Garbage Collector settings - * Used if lvgl is binded to higher language and the memory is managed by that language */ -#define LV_ENABLE_GC 0 -#if LV_ENABLE_GC != 0 -# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/ -# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/ -# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ -#endif /* LV_ENABLE_GC */ - -/*=================== - Graphical settings - *===================*/ - -/* Horizontal and vertical resolution of the library.*/ -#define LV_HOR_RES (320) -#define LV_VER_RES (240) - -/* Dot Per Inch: used to initialize default sizes. E.g. a button with width = LV_DPI / 2 -> half inch wide - * (Not so important, you can adjust it to modify default sizes and spaces)*/ -#define LV_DPI 100 - -/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ -#define LV_ANTIALIAS 0 /*1: Enable anti-aliasing*/ - -/*Screen refresh period in milliseconds*/ -#define LV_REFR_PERIOD 30 - -/*----------------- - * VDB settings - *----------------*/ - -/* VDB (Virtual Display Buffer) is an internal graphics buffer. - * The GUI will be drawn into this buffer first and then - * the buffer will be passed to your `disp_drv.disp_flush` function to - * copy it to your frame buffer. - * VDB is required for: buffered drawing, opacity, anti-aliasing and shadows - * Learn more: https://docs.littlevgl.com/#Drawing*/ - -/* Size of the VDB in pixels. Typical size: ~1/10 screen. Must be >= LV_HOR_RES - * Setting it to 0 will disable VDB and `disp_drv.disp_fill` and `disp_drv.disp_map` functions - * will be called to draw to the frame buffer directly*/ -#define LV_VDB_SIZE ((LV_VER_RES * LV_HOR_RES) / 10) - -/* Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays. - * Special formats are handled with `disp_drv.vdb_wr`)*/ -#define LV_VDB_PX_BPP LV_COLOR_SIZE /*LV_COLOR_SIZE comes from LV_COLOR_DEPTH below to set 8, 16 or 32 bit pixel size automatically */ - -/* Place VDB to a specific address (e.g. in external RAM) - * 0: allocate automatically into RAM - * LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/ -#define LV_VDB_ADR 0 - -/* Use two Virtual Display buffers (VDB) to parallelize rendering and flushing - * The flushing should use DMA to write the frame buffer in the background */ -#define LV_VDB_DOUBLE 0 - -/* Place VDB2 to a specific address (e.g. in external RAM) - * 0: allocate automatically into RAM - * LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/ -#define LV_VDB2_ADR 0 - -/* Using true double buffering in `disp_drv.disp_flush` you will always get the image of the whole screen. - * Your only task is to set the rendered image (`color_p` parameter) as frame buffer address or send it to your display. - * The best if you do in the blank period of you display to avoid tearing effect. - * Requires: - * - LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES - * - LV_VDB_DOUBLE = 1 - */ -#define LV_VDB_TRUE_DOUBLE_BUFFERED 0 - -/*================= - Misc. setting - *=================*/ - -/*Input device settings*/ -#define LV_INDEV_READ_PERIOD 50 /*Input device read period in milliseconds*/ -#define LV_INDEV_POINT_MARKER 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/ -#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */ -#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */ -#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/ -#define LV_INDEV_LONG_PRESS_REP_TIME 100 /*Repeated trigger period in long press [ms] */ - -/*Color settings*/ -#define LV_COLOR_DEPTH 32 /*Color depth: 1/8/16/32*/ -#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/ -#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/ -#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/ - -/*Text settings*/ -#define LV_TXT_UTF8 1 /*Enable UTF-8 coded Unicode character usage */ -#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/ -#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */ -#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */ -#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */ - -/*Feature usage*/ -#define USE_LV_ANIMATION 1 /*1: Enable all animations*/ -#define USE_LV_SHADOW 1 /*1: Enable shadows*/ -#define USE_LV_GROUP 1 /*1: Enable object groups (for keyboards)*/ -#define USE_LV_GPU 0 /*1: Enable GPU interface*/ -#define USE_LV_REAL_DRAW 1 /*1: Enable function which draw directly to the frame buffer instead of VDB (required if LV_VDB_SIZE = 0)*/ -#define USE_LV_FILESYSTEM 0 /*1: Enable file system (might be required for images*/ -#define USE_LV_MULTI_LANG 0 /* Number of languages for labels to store (0: to disable this feature)*/ - -/*Compiler settings*/ -#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */ -#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */ -#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/ -#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 /* 1: Initialization with non constant values are supported */ - -/*HAL settings*/ -#define LV_TICK_CUSTOM 1 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */ -#if LV_TICK_CUSTOM == 1 -#define LV_TICK_CUSTOM_INCLUDE "system_header.h" /*Header for the sys time function*/ -#define LV_TICK_CUSTOM_SYS_TIME_EXPR (time_get_ms()) /*Expression evaluating to current systime in ms*/ -#endif /*LV_TICK_CUSTOM*/ - -/*Log settings*/ -#define USE_LV_LOG 1 /*Enable/disable the log module*/ -#if USE_LV_LOG -/* How important log should be added: - * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information - * LV_LOG_LEVEL_INFO Log important events - * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't caused problem - * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail - */ -# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN -/* 1: Print the log with 'printf'; 0: user need to register a callback*/ - -# define LV_LOG_PRINTF 0 -#endif /*USE_LV_LOG*/ - -/*================ - * THEME USAGE - *================*/ -#define LV_THEME_LIVE_UPDATE 1 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/ - -#define USE_LV_THEME_TEMPL 0 /*Just for test*/ -#define USE_LV_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/ -#define USE_LV_THEME_ALIEN 0 /*Dark futuristic theme*/ -#define USE_LV_THEME_NIGHT 0 /*Dark elegant theme*/ -#define USE_LV_THEME_MONO 0 /*Mono color theme for monochrome displays*/ -#define USE_LV_THEME_MATERIAL 0 /*Flat theme with bold colors and light shadows*/ -#define USE_LV_THEME_ZEN 0 /*Peaceful, mainly light theme */ -#define USE_LV_THEME_NEMO 0 /*Water-like theme based on the movie "Finding Nemo"*/ - -/*================== - * FONT USAGE - *===================*/ - -/* More info about fonts: https://docs.littlevgl.com/#Fonts - * To enable a built-in font use 1,2,4 or 8 values - * which will determine the bit-per-pixel. Higher value means smoother fonts */ -#define USE_LV_FONT_DEJAVU_10 0 -#define USE_LV_FONT_DEJAVU_10_LATIN_SUP 0 -#define USE_LV_FONT_DEJAVU_10_CYRILLIC 0 -#define USE_LV_FONT_SYMBOL_10 0 - -#define USE_LV_FONT_DEJAVU_20 4 -#define USE_LV_FONT_DEJAVU_20_LATIN_SUP 0 -#define USE_LV_FONT_DEJAVU_20_CYRILLIC 0 -#define USE_LV_FONT_SYMBOL_20 0 - -#define USE_LV_FONT_DEJAVU_30 0 -#define USE_LV_FONT_DEJAVU_30_LATIN_SUP 0 -#define USE_LV_FONT_DEJAVU_30_CYRILLIC 0 -#define USE_LV_FONT_SYMBOL_30 0 - -#define USE_LV_FONT_DEJAVU_40 0 -#define USE_LV_FONT_DEJAVU_40_LATIN_SUP 0 -#define USE_LV_FONT_DEJAVU_40_CYRILLIC 0 -#define USE_LV_FONT_SYMBOL_40 0 - -#define USE_LV_FONT_MONOSPACE_8 1 - -/* Optionally declare your custom fonts here. - * You can use these fonts as default font too - * and they will be available globally. E.g. - * #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \ - * LV_FONT_DECLARE(my_font_2) \ - */ -#define LV_FONT_CUSTOM_DECLARE - -#define LV_FONT_DEFAULT &lv_font_dejavu_20 /*Always set a default font from the built-in fonts*/ - -/*=================== - * LV_OBJ SETTINGS - *==================*/ -#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/ -#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/ -#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/ - -/*================== - * LV OBJ X USAGE - *================*/ -/* - * Documentation of the object types: https://docs.littlevgl.com/#Object-types - */ - -/***************** - * Simple object - *****************/ - -/*Label (dependencies: -*/ -#define USE_LV_LABEL 1 -#if USE_LV_LABEL != 0 -# define LV_LABEL_SCROLL_SPEED 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/ -#endif - -/*Image (dependencies: lv_label*/ -#define USE_LV_IMG 1 -#if USE_LV_IMG != 0 -# define LV_IMG_CF_INDEXED 1 /*Enable indexed (palette) images*/ -# define LV_IMG_CF_ALPHA 1 /*Enable alpha indexed images*/ -#endif - -/*Line (dependencies: -*/ -#define USE_LV_LINE 1 - -/*Arc (dependencies: -)*/ -#define USE_LV_ARC 1 - -/******************* - * Container objects - *******************/ - -/*Container (dependencies: -*/ -#define USE_LV_CONT 1 - -/*Page (dependencies: lv_cont)*/ -#define USE_LV_PAGE 1 - -/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ -#define USE_LV_WIN 1 - -/*Tab (dependencies: lv_page, lv_btnm)*/ -#define USE_LV_TABVIEW 1 -# if USE_LV_TABVIEW != 0 -# define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/ -#endif - -/*Tileview (dependencies: lv_page) */ -#define USE_LV_TILEVIEW 1 -#if USE_LV_TILEVIEW -# define LV_TILEVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/ -#endif - -/************************* - * Data visualizer objects - *************************/ - -/*Bar (dependencies: -)*/ -#define USE_LV_BAR 1 - -/*Line meter (dependencies: *;)*/ -#define USE_LV_LMETER 1 - -/*Gauge (dependencies:lv_bar, lv_lmeter)*/ -#define USE_LV_GAUGE 1 - -/*Chart (dependencies: -)*/ -#define USE_LV_CHART 1 - -/*Table (dependencies: lv_label)*/ -#define USE_LV_TABLE 1 -#if USE_LV_TABLE -# define LV_TABLE_COL_MAX 12 -#endif - -/*LED (dependencies: -)*/ -#define USE_LV_LED 1 - -/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ -#define USE_LV_MBOX 1 - -/*Text area (dependencies: lv_label, lv_page)*/ -#define USE_LV_TA 1 -#if USE_LV_TA != 0 -# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/ -# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/ -#endif - -/*Spinbox (dependencies: lv_ta)*/ -#define USE_LV_SPINBOX 1 - -/*Calendar (dependencies: -)*/ -#define USE_LV_CALENDAR 1 - -/*Preload (dependencies: lv_arc)*/ -#define USE_LV_PRELOAD 1 -#if USE_LV_PRELOAD != 0 -# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/ -# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/ -# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC -#endif - -/*Canvas (dependencies: lv_img)*/ -#define USE_LV_CANVAS 1 -/************************* - * User input objects - *************************/ - -/*Button (dependencies: lv_cont*/ -#define USE_LV_BTN 1 -#if USE_LV_BTN != 0 -# define LV_BTN_INK_EFFECT 1 /*Enable button-state animations - draw a circle on click (dependencies: USE_LV_ANIMATION)*/ -#endif - -/*Image Button (dependencies: lv_btn*/ -#define USE_LV_IMGBTN 1 -#if USE_LV_IMGBTN -# define LV_IMGBTN_TILED 0 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/ -#endif - -/*Button matrix (dependencies: -)*/ -#define USE_LV_BTNM 1 - -/*Keyboard (dependencies: lv_btnm)*/ -#define USE_LV_KB 1 - -/*Check box (dependencies: lv_btn, lv_label)*/ -#define USE_LV_CB 1 - -/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ -#define USE_LV_LIST 1 -#if USE_LV_LIST != 0 -# define LV_LIST_FOCUS_TIME 100 /*Default animation time of focusing to a list element [ms] (0: no animation) */ -#endif - -/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ -#define USE_LV_DDLIST 1 -#if USE_LV_DDLIST != 0 -# define LV_DDLIST_ANIM_TIME 200 /*Open and close default animation time [ms] (0: no animation)*/ -#endif - -/*Roller (dependencies: lv_ddlist)*/ -#define USE_LV_ROLLER 1 -#if USE_LV_ROLLER != 0 -# define LV_ROLLER_ANIM_TIME 200 /*Focus animation time [ms] (0: no animation)*/ -#endif - -/*Slider (dependencies: lv_bar)*/ -#define USE_LV_SLIDER 1 - -/*Switch (dependencies: lv_slider)*/ -#define USE_LV_SW 1 - -/************************* - * Non-user section - *************************/ -#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ -# define _CRT_SECURE_NO_WARNINGS -#endif - -/*--END OF LV_CONF_H--*/ - -/*Be sure every define has a default value*/ -#include "lvgl/lv_conf_checker.h" - -#endif /*LV_CONF_H*/ - -#endif /*End of "Content enable"*/ diff --git a/samples/littlevgl/lv_config/lv_drv_conf.h b/samples/littlevgl/lv_config/lv_drv_conf.h deleted file mode 100644 index d216a3e90..000000000 --- a/samples/littlevgl/lv_config/lv_drv_conf.h +++ /dev/null @@ -1,310 +0,0 @@ -/** - * @file lv_drv_conf.h - * - */ - -/* - * COPY THIS FILE AS lv_drv_conf.h - */ - -#if 1 /*Set it to "1" to enable the content*/ - -#ifndef LV_DRV_CONF_H -#define LV_DRV_CONF_H - -#include "lv_conf.h" - -/********************* - * DELAY INTERFACE - *********************/ -#define LV_DRV_DELAY_INCLUDE /*Dummy include by default*/ -#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/ -#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/ - -/********************* - * DISPLAY INTERFACE - *********************/ - -/*------------ - * Common - *------------*/ -#define LV_DRV_DISP_INCLUDE /*Dummy include by default*/ -#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/ -#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/ - -/*--------- - * SPI - *---------*/ -#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/ -#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/ -#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/ - -/*------------------ - * Parallel port - *-----------------*/ -#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/ -#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/ -#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/ -#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/ -#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/ - -/*************************** - * INPUT DEVICE INTERFACE - ***************************/ - -/*---------- - * Common - *----------*/ -#define LV_DRV_INDEV_INCLUDE /*Dummy include by default*/ -#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/ -#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/ - -/*--------- - * SPI - *---------*/ -#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/ -#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/ - -/*--------- - * I2C - *---------*/ -#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/ -#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/ -#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/ -#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/ -#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/ - - -/********************* - * DISPLAY DRIVERS - *********************/ - -/*------------------- - * Monitor of PC - *-------------------*/ -#ifndef USE_MONITOR -# define USE_MONITOR 1 -#endif - -#if USE_MONITOR -# define MONITOR_HOR_RES LV_HOR_RES_MAX -# define MONITOR_VER_RES LV_VER_RES_MAX - -/* Scale window by this factor (useful when simulating small screens) */ -# define MONITOR_ZOOM 1 - -/* Used to test true double buffering with only address changing. - * Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */ -# define MONITOR_DOUBLE_BUFFERED 0 - -/*Eclipse: Visual Studio: */ -# define MONITOR_SDL_INCLUDE_PATH - -/*Different rendering might be used if running in a Virtual machine*/ -# define MONITOR_VIRTUAL_MACHINE 0 - -/*Open two windows to test multi display support*/ -# define MONITOR_DUAL 0 -#endif - -/*----------------------------------- - * Native Windows (including mouse) - *----------------------------------*/ -#ifndef USE_WINDOWS -# define USE_WINDOWS 0 -#endif - -#define USE_WINDOWS 0 -#if USE_WINDOWS -# define WINDOW_HOR_RES 480 -# define WINDOW_VER_RES 320 -#endif - -/*---------------- - * SSD1963 - *--------------*/ -#ifndef USE_SSD1963 -# define USE_SSD1963 0 -#endif - -#if USE_SSD1963 -# define SSD1963_HOR_RES LV_HOR_RES -# define SSD1963_VER_RES LV_VER_RES -# define SSD1963_HT 531 -# define SSD1963_HPS 43 -# define SSD1963_LPS 8 -# define SSD1963_HPW 10 -# define SSD1963_VT 288 -# define SSD1963_VPS 12 -# define SSD1963_FPS 4 -# define SSD1963_VPW 10 -# define SSD1963_HS_NEG 0 /*Negative hsync*/ -# define SSD1963_VS_NEG 0 /*Negative vsync*/ -# define SSD1963_ORI 0 /*0, 90, 180, 270*/ -# define SSD1963_COLOR_DEPTH 16 -#endif - -/*---------------- - * R61581 - *--------------*/ -#ifndef USE_R61581 -# define USE_R61581 0 -#endif - -#if USE_R61581 -# define R61581_HOR_RES LV_HOR_RES -# define R61581_VER_RES LV_VER_RES -# define R61581_HSPL 0 /*HSYNC signal polarity*/ -# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/ -# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/ -# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */ -# define R61581_VSPL 0 /*VSYNC signal polarity*/ -# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/ -# define R61581_VFP 8 /*Vertical Front poarch*/ -# define R61581_VBP 8 /*Vertical Back poarch */ -# define R61581_DPL 0 /*DCLK signal polarity*/ -# define R61581_EPL 1 /*ENABLE signal polarity*/ -# define R61581_ORI 0 /*0, 180*/ -# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/ -#endif - -/*------------------------------ - * ST7565 (Monochrome, low res.) - *-----------------------------*/ -#ifndef USE_ST7565 -# define USE_ST7565 0 -#endif - -#if USE_ST7565 -/*No settings*/ -#endif /*USE_ST7565*/ - -/*----------------------------------------- - * Linux frame buffer device (/dev/fbx) - *-----------------------------------------*/ -#ifndef USE_FBDEV -# define USE_FBDEV 1 -#endif - -#if USE_FBDEV -# define FBDEV_PATH "/dev/fb0" -#endif - -/********************* - * INPUT DEVICES - *********************/ - -/*-------------- - * XPT2046 - *--------------*/ -#ifndef USE_XPT2046 -# define USE_XPT2046 0 -#endif - -#if USE_XPT2046 -# define XPT2046_HOR_RES 480 -# define XPT2046_VER_RES 320 -# define XPT2046_X_MIN 200 -# define XPT2046_Y_MIN 200 -# define XPT2046_X_MAX 3800 -# define XPT2046_Y_MAX 3800 -# define XPT2046_AVG 4 -# define XPT2046_INV 0 -#endif - -/*----------------- - * FT5406EE8 - *-----------------*/ -#ifndef USE_FT5406EE8 -# define USE_FT5406EE8 0 -#endif - -#if USE_FT5406EE8 -# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/ -#endif - -/*--------------- - * AD TOUCH - *--------------*/ -#ifndef USE_AD_TOUCH -# define USE_AD_TOUCH 0 -#endif - -#if USE_AD_TOUCH -/*No settings*/ -#endif - - -/*--------------------------------------- - * Mouse or touchpad on PC (using SDL) - *-------------------------------------*/ -#ifndef USE_MOUSE -# define USE_MOUSE 1 -#endif - -#if USE_MOUSE -/*No settings*/ -#endif - -/*------------------------------------------- - * Mousewheel as encoder on PC (using SDL) - *------------------------------------------*/ -#ifndef USE_MOUSEWHEEL -# define USE_MOUSEWHEEL 1 -#endif - -#if USE_MOUSEWHEEL -/*No settings*/ -#endif - -/*------------------------------------------------- - * Touchscreen as libinput interface (for Linux based systems) - *------------------------------------------------*/ -#ifndef USE_LIBINPUT -# define USE_LIBINPUT 0 -#endif - -#if USE_LIBINPUT -# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -#endif /*USE_LIBINPUT*/ - -/*------------------------------------------------- - * Mouse or touchpad as evdev interface (for Linux based systems) - *------------------------------------------------*/ -#ifndef USE_EVDEV -# define USE_EVDEV 0 -#endif - -#if USE_EVDEV -# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/ -# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/ - -# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */ -# if EVDEV_SCALE -# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */ -# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */ -# endif /*EVDEV_SCALE*/ - -# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/ -# if EVDEV_CALIBRATE -# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/ -# define EVDEV_HOR_MAX 200 -# define EVDEV_VER_MIN 200 -# define EVDEV_VER_MAX 3800 -# endif /*EVDEV_SCALE*/ -#endif /*USE_EVDEV*/ - -/*------------------------------- - * Keyboard of a PC (using SDL) - *------------------------------*/ -#ifndef USE_KEYBOARD -# define USE_KEYBOARD 1 -#endif - -#if USE_KEYBOARD -/*No settings*/ -#endif - -#endif /*LV_DRV_CONF_H*/ - -#endif /*End of "Content enable"*/ diff --git a/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt b/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt deleted file mode 100644 index 9778e821b..000000000 --- a/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt +++ /dev/null @@ -1,137 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required (VERSION 2.9) -message ("vgl_native_ui_app...") -project (vgl_native_ui_app) - - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_NATIVE_LINUX -DUSE_MONITOR -DUSE_MOUSE=1") - -# Currently build as 64-bit by default. Set to "NO" to build 32-bit binaries. -set (BUILD_AS_64BIT_SUPPORT "YES") - -if (CMAKE_SIZEOF_VOID_P EQUAL 8) - if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES") - # Add -fPIC flag if build as 64-bit - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") - else () - add_definitions (-m32) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") - set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") - endif () -endif () - -set(lv_name lvgl) -set(LVGL_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../build/lvgl) -set(LVGL_DRIVER_DIR ${CMAKE_CURRENT_LIST_DIR}/lv-drivers) - -message(${LVGL_SOURCE_DIR}) -include( ExternalProject ) - -add_definitions(-DLV_CONF_INCLUDE_SIMPLE) - -SET (LVGL_SOURCES - ${LVGL_SOURCE_DIR}/lv_core/lv_group.c - ${LVGL_SOURCE_DIR}/lv_core/lv_indev.c - ${LVGL_SOURCE_DIR}/lv_core/lv_lang.c - ${LVGL_SOURCE_DIR}/lv_core/lv_obj.c - ${LVGL_SOURCE_DIR}/lv_core/lv_refr.c - ${LVGL_SOURCE_DIR}/lv_core/lv_style.c - ${LVGL_SOURCE_DIR}/lv_core/lv_vdb.c - - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw.c - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_arc.c - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_img.c - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_label.c - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_line.c - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_rbasic.c - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_rect.c - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_triangle.c - ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_vbasic.c - - ${LVGL_SOURCE_DIR}/lv_hal/lv_hal_disp.c - ${LVGL_SOURCE_DIR}/lv_hal/lv_hal_indev.c - ${LVGL_SOURCE_DIR}/lv_hal/lv_hal_tick.c - - ${LVGL_SOURCE_DIR}/lv_misc/lv_anim.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_area.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_circ.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_color.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_font.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_fs.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_gc.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_ll.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_log.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_math.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_mem.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_task.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_templ.c - ${LVGL_SOURCE_DIR}/lv_misc/lv_txt.c - - ${LVGL_SOURCE_DIR}/lv_objx/lv_arc.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_bar.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_btn.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_btnm.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_calendar.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_canvas.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_cb.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_chart.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_cont.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_ddlist.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_gauge.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_img.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_imgbtn.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_kb.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_label.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_led.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_line.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_list.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_lmeter.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_mbox.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_objx_templ.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_page.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_preload.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_roller.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_slider.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_spinbox.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_sw.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_ta.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_table.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_tabview.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_tileview.c - ${LVGL_SOURCE_DIR}/lv_objx/lv_win.c - - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme.c - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_alien.c - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_default.c - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_material.c - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_mono.c - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_nemo.c - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_night.c - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_templ.c - ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_zen.c - - ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_builtin.c - ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_20.c - ${LVGL_DRIVER_DIR}/linux_display_indev.c - ${LVGL_DRIVER_DIR}/indev/mouse.c - -) -SET(SOURCES - ${LVGL_SOURCES} - ${CMAKE_CURRENT_LIST_DIR}/main.c - ) -include_directories( - ${LVGL_DRIVER_DIR} - ${LVGL_DRIVER_DIR}/display - ${LVGL_DRIVER_DIR}/indev - ${LVGL_SOURCE_DIR} - ${LVGL_SOURCE_DIR}/.. - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/../lv_config -) -add_executable(vgl_native_ui_app ${SOURCES} ) -target_link_libraries( vgl_native_ui_app -lSDL2) diff --git a/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in b/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in deleted file mode 100644 index 25f4db955..000000000 --- a/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required(VERSION 2.8.2) - -project(lvgl_download NONE) - -include(ExternalProject) -ExternalProject_Add(${lv_name} - GIT_REPOSITORY https://github.com/lvgl/lvgl.git - GIT_TAG v5.3 - BINARY_DIR "" - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/../build/lvgl" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" - ) diff --git a/samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore b/samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore deleted file mode 100644 index 2372cca06..000000000 --- a/samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore +++ /dev/null @@ -1 +0,0 @@ -**/*.o \ No newline at end of file diff --git a/samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h b/samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h deleted file mode 100644 index 95136e285..000000000 --- a/samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef DISPLAY_INDEV_H_ -#define DISPLAY_INDEV_H_ -#include -#include -#include "mouse.h" -#include "lvgl/lv_misc/lv_color.h" -#include "lvgl/lv_hal/lv_hal_indev.h" -extern void -display_init(void); -extern void -display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color_p); -extern bool -display_input_read(lv_indev_data_t *data); -extern void -display_deinit(void); -extern void -display_vdb_write(void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t *color, lv_opa_t opa); -extern int -time_get_ms(); - -#endif diff --git a/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c b/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c deleted file mode 100644 index 848b2eca2..000000000 --- a/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c +++ /dev/null @@ -1,96 +0,0 @@ -/** - * @file mouse.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "mouse.h" -#if USE_MOUSE != 0 - -/********************* - * DEFINES - *********************/ -#ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 -#endif - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ -static bool left_button_down = false; -static int16_t last_x = 0; -static int16_t last_y = 0; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the mouse - */ -void -mouse_init(void) -{} - -/** - * Get the current position and state of the mouse - * @param data store the mouse data here - * @return false: because the points are not buffered, so no more data to be - * read - */ -bool -mouse_read(lv_indev_data_t *data) -{ - /*Store the collected data*/ - data->point.x = last_x; - data->point.y = last_y; - data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; - - return false; -} - -/** - * It will be called from the main SDL thread - */ -void -mouse_handler(SDL_Event *event) -{ - switch (event->type) { - case SDL_MOUSEBUTTONUP: - if (event->button.button == SDL_BUTTON_LEFT) - left_button_down = false; - break; - case SDL_MOUSEBUTTONDOWN: - if (event->button.button == SDL_BUTTON_LEFT) { - left_button_down = true; - last_x = event->motion.x / MONITOR_ZOOM; - last_y = event->motion.y / MONITOR_ZOOM; - } - break; - case SDL_MOUSEMOTION: - last_x = event->motion.x / MONITOR_ZOOM; - last_y = event->motion.y / MONITOR_ZOOM; - - break; - } -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -#endif diff --git a/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h b/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h deleted file mode 100644 index 07e492f96..000000000 --- a/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @file mouse.h - * - */ - -#ifndef MOUSE_H -#define MOUSE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -#include "lv_drv_conf.h" - -#if USE_MOUSE - -#include -#include -#include "lvgl/lv_hal/lv_hal_indev.h" - -#ifndef MONITOR_SDL_INCLUDE_PATH -#define MONITOR_SDL_INCLUDE_PATH -#endif - -#include MONITOR_SDL_INCLUDE_PATH - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the mouse - */ -void -mouse_init(void); -/** - * Get the current position and state of the mouse - * @param data store the mouse data here - * @return false: because the points are not buffered, so no more data to be - * read - */ -bool -mouse_read(lv_indev_data_t *data); - -/** - * It will be called from the main SDL thread - */ -void -mouse_handler(SDL_Event *event); - -/********************** - * MACROS - **********************/ - -#endif /* USE_MOUSE */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* MOUSE_H */ diff --git a/samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c b/samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c deleted file mode 100644 index bd5071067..000000000 --- a/samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include "display_indev.h" -#include "sys/time.h" -#include "SDL2/SDL.h" -#define MONITOR_HOR_RES 320 -#define MONITOR_VER_RES 240 -#ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 -#endif -#define SDL_REFR_PERIOD 50 -void -monitor_sdl_init(void); -void -monitor_sdl_refr_core(void); -void -monitor_sdl_clean_up(void); -static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES]; - -void -display_vdb_write(void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t *color, lv_opa_t opa) -{ - unsigned char *buf_xy = buf + 4 * x + 4 * y * buf_w; - lv_color_t *temp = (lv_color_t *)buf_xy; - *temp = *color; - /* - if (opa != LV_OPA_COVER) { - lv_color_t mix_color; - - mix_color.red = *buf_xy; - mix_color.green = *(buf_xy+1); - mix_color.blue = *(buf_xy+2); - color = lv_color_mix(color, mix_color, opa); - } - */ -} -int -time_get_ms() -{ - static struct timeval tv; - gettimeofday(&tv, NULL); - long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000; - - return (int)time_in_mill; -} - -SDL_Window *window; -SDL_Renderer *renderer; -SDL_Texture *texture; -static volatile bool sdl_inited = false; -static volatile bool sdl_refr_qry = false; -static volatile bool sdl_quit_qry = false; - -void -monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color_p) -{ - /*Return if the area is out the screen*/ - if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1 - || y1 > MONITOR_VER_RES - 1) { - return; - } - - int32_t y; - uint32_t w = x2 - x1 + 1; - for (y = y1; y <= y2; y++) { - memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color_p, - w * sizeof(lv_color_t)); - - color_p += w; - } - sdl_refr_qry = true; - - /*IMPORTANT! It must be called to tell the system the flush is ready*/ -} - -/** - * Fill out the marked area with a color - * @param x1 left coordinate - * @param y1 top coordinate - * @param x2 right coordinate - * @param y2 bottom coordinate - * @param color fill color - */ -void -monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color) -{ - /*Return if the area is out the screen*/ - if (x2 < 0) - return; - if (y2 < 0) - return; - if (x1 > MONITOR_HOR_RES - 1) - return; - if (y1 > MONITOR_VER_RES - 1) - return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2; - - int32_t x; - int32_t y; - uint32_t color32 = color.full; // lv_color_to32(color); - - for (x = act_x1; x <= act_x2; x++) { - for (y = act_y1; y <= act_y2; y++) { - tft_fb[y * MONITOR_HOR_RES + x] = color32; - } - } - - sdl_refr_qry = true; -} - -/** - * Put a color map to the marked area - * @param x1 left coordinate - * @param y1 top coordinate - * @param x2 right coordinate - * @param y2 bottom coordinate - * @param color_p an array of colors - */ -void -monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color_p) -{ - /*Return if the area is out the screen*/ - if (x2 < 0) - return; - if (y2 < 0) - return; - if (x1 > MONITOR_HOR_RES - 1) - return; - if (y1 > MONITOR_VER_RES - 1) - return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2; - - int32_t x; - int32_t y; - - for (y = act_y1; y <= act_y2; y++) { - for (x = act_x1; x <= act_x2; x++) { - tft_fb[y * MONITOR_HOR_RES + x] = - color_p->full; // lv_color_to32(*color_p); - color_p++; - } - - color_p += x2 - act_x2; - } - - sdl_refr_qry = true; -} - -void -display_init(void) -{} - -void -display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color_p) -{ - monitor_flush(x1, y1, x2, y2, color_p); -} -void -display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color_p) -{ - monitor_fill(x1, y1, x2, y2, color_p); -} -void -display_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color_p) -{ - monitor_map(x1, y1, x2, y2, color_p); -} - -bool -display_input_read(lv_indev_data_t *data) -{ - return mouse_read(data); -} - -void -display_deinit(void) -{} - -int -monitor_sdl_refr_thread(void *param) -{ - (void)param; - - /*If not OSX initialize SDL in the Thread*/ - monitor_sdl_init(); - /*Run until quit event not arrives*/ - while (sdl_quit_qry == false) { - /*Refresh handling*/ - monitor_sdl_refr_core(); - } - - monitor_sdl_clean_up(); - exit(0); - - return 0; -} - -void -monitor_sdl_refr_core(void) -{ - if (sdl_refr_qry != false) { - sdl_refr_qry = false; - - SDL_UpdateTexture(texture, NULL, tft_fb, - MONITOR_HOR_RES * sizeof(uint32_t)); - SDL_RenderClear(renderer); - /*Test: Draw a background to test transparent screens - * (LV_COLOR_SCREEN_TRANSP)*/ - // SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff); - // SDL_Rect r; - // r.x = 0; r.y = 0; r.w = MONITOR_HOR_RES; r.w = - // MONITOR_VER_RES; SDL_RenderDrawRect(renderer, &r); - /*Update the renderer with the texture containing the rendered image*/ - SDL_RenderCopy(renderer, texture, NULL, NULL); - SDL_RenderPresent(renderer); - } - - SDL_Event event; - while (SDL_PollEvent(&event)) { -#if USE_MOUSE != 0 - mouse_handler(&event); -#endif - if ((&event)->type == SDL_WINDOWEVENT) { - switch ((&event)->window.event) { -#if SDL_VERSION_ATLEAST(2, 0, 5) - case SDL_WINDOWEVENT_TAKE_FOCUS: -#endif - case SDL_WINDOWEVENT_EXPOSED: - - SDL_UpdateTexture(texture, NULL, tft_fb, - MONITOR_HOR_RES * sizeof(uint32_t)); - SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, texture, NULL, NULL); - SDL_RenderPresent(renderer); - break; - default: - break; - } - } - } - - /*Sleep some time*/ - SDL_Delay(SDL_REFR_PERIOD); -} -int -quit_filter(void *userdata, SDL_Event *event) -{ - (void)userdata; - - if (event->type == SDL_QUIT) { - sdl_quit_qry = true; - } - - return 1; -} - -void -monitor_sdl_clean_up(void) -{ - SDL_DestroyTexture(texture); - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); - SDL_Quit(); -} - -void -monitor_sdl_init(void) -{ - /*Initialize the SDL*/ - SDL_Init(SDL_INIT_VIDEO); - - SDL_SetEventFilter(quit_filter, NULL); - - window = SDL_CreateWindow( - "TFT Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, - 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/ - - renderer = SDL_CreateRenderer(window, -1, 0); - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, - MONITOR_VER_RES); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); - - /*Initialize the frame buffer to gray (77 is an empirical value) */ - memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t)); - SDL_UpdateTexture(texture, NULL, tft_fb, - MONITOR_HOR_RES * sizeof(uint32_t)); - sdl_refr_qry = true; - sdl_inited = true; -} - -void -display_SDL_init() -{ - SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL); - while (sdl_inited == false) - ; /*Wait until 'sdl_refr' initializes the SDL*/ -} diff --git a/samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h b/samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h deleted file mode 100644 index a0d790c8e..000000000 --- a/samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include - -int -time_get_ms(); diff --git a/samples/littlevgl/vgl-native-ui-app/main.c b/samples/littlevgl/vgl-native-ui-app/main.c deleted file mode 100644 index e67847c6c..000000000 --- a/samples/littlevgl/vgl-native-ui-app/main.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -/** - * @file main - * - */ - -/********************* - * INCLUDES - *********************/ -#include -#include -#include "lvgl/lvgl.h" -#include "display_indev.h" -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static void -hal_init(void); -// static int tick_thread(void * data); -// static void memory_monitor(void * param); - -/********************** - * STATIC VARIABLES - **********************/ - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ -uint32_t count = 0; -char count_str[11] = { 0 }; -lv_obj_t *hello_world_label; -lv_obj_t *count_label; -lv_obj_t *btn1; - -lv_obj_t *label_count1; -int label_count1_value = 0; -char label_count1_str[11] = { 0 }; -static lv_res_t -btn_rel_action(lv_obj_t *btn) -{ - label_count1_value++; - snprintf(label_count1_str, sizeof(label_count1_str), "%d", - label_count1_value); - lv_label_set_text(label_count1, label_count1_str); - return LV_RES_OK; -} - -int -main() -{ - void display_SDL_init(); - display_SDL_init(); - - /*Initialize LittlevGL*/ - lv_init(); - - /*Initialize the HAL (display, input devices, tick) for LittlevGL*/ - hal_init(); - - hello_world_label = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text(hello_world_label, "Hello world!"); - lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - - count_label = lv_label_create(lv_scr_act(), NULL); - lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); - - btn1 = lv_btn_create( - lv_scr_act(), NULL); /*Create a button on the currently loaded screen*/ - lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, - btn_rel_action); /*Set function to be called when the - button is released*/ - lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 20); /*Align below the label*/ - - /*Create a label on the button*/ - lv_obj_t *btn_label = lv_label_create(btn1, NULL); - lv_label_set_text(btn_label, "Click ++"); - - label_count1 = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text(label_count1, "0"); - lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - - while (1) { - /* Periodically call the lv_task handler. - * It could be done in a timer interrupt or an OS task too.*/ - if ((count % 100) == 0) { - snprintf(count_str, sizeof(count_str), "%d", count / 100); - lv_label_set_text(count_label, count_str); - } - lv_task_handler(); - ++count; - usleep(10 * 1000); /*Just to let the system breath*/ - } - - return 0; -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -/** - * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics - * library - */ -void -display_flush_wrapper(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color_p) -{ - display_flush(x1, y1, x2, y2, color_p); - lv_flush_ready(); -} -void -display_vdb_write_wrapper(uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, - lv_coord_t y, lv_color_t color, lv_opa_t opa) -{ - display_vdb_write(buf, buf_w, x, y, &color, opa); -} -extern void -display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - lv_color_t color_p); -extern void -display_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color_p); -static void -hal_init(void) -{ - /* Add a display*/ - lv_disp_drv_t disp_drv; - lv_disp_drv_init(&disp_drv); /*Basic initialization*/ - disp_drv.disp_flush = - display_flush_wrapper; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h - (buffered drawing)*/ - disp_drv.disp_fill = display_fill; /*Used when `LV_VDB_SIZE == 0` in - lv_conf.h (unbuffered drawing)*/ - disp_drv.disp_map = display_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h - (unbuffered drawing)*/ -#if LV_VDB_SIZE != 0 - disp_drv.vdb_wr = display_vdb_write_wrapper; -#endif - lv_disp_drv_register(&disp_drv); - - /* Add the mouse as input device - * Use the 'mouse' driver which reads the PC's mouse*/ - // mouse_init(); - lv_indev_drv_t indev_drv; - lv_indev_drv_init(&indev_drv); /*Basic initialization*/ - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read = - display_input_read; /*This function will be called periodically (by the - library) to get the mouse position and state*/ - lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv); -} diff --git a/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt b/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt deleted file mode 100644 index a99959ad5..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required (VERSION 2.9) - -project (vgl_wasm_runtime) - -set (WAMR_BUILD_PLATFORM "linux") - -# Reset default linker flags -set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") -set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") - -################ wamr runtime settings ################ - -set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..) - -## use library and headers in the SDK -link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/lib) -include_directories( - ${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/include - ${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/include/bi-inc/deps - ${WAMR_ROOT_DIR}/core/shared/utils - ${WAMR_ROOT_DIR}/core/shared/platform/${WAMR_BUILD_PLATFORM} -) - -############### application related ############### -include_directories(${CMAKE_CURRENT_LIST_DIR}/src) - -add_executable (vgl_wasm_runtime src/platform/${WAMR_BUILD_PLATFORM}/main.c - src/platform/${WAMR_BUILD_PLATFORM}/iwasm_main.c - src/platform/${WAMR_BUILD_PLATFORM}/display_indev.c - src/platform/${WAMR_BUILD_PLATFORM}/mouse.c) - -target_link_libraries (vgl_wasm_runtime vmlib -lm -ldl -lpthread -lSDL2) - diff --git a/samples/littlevgl/vgl-wasm-runtime/src/display_indev.h b/samples/littlevgl/vgl-wasm-runtime/src/display_indev.h deleted file mode 100644 index 273d0ad03..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/display_indev.h +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef DISPLAY_INDEV_H_ -#define DISPLAY_INDEV_H_ -#include -#include -#include -#include "bh_platform.h" -#include "wasm_export.h" - -#define USE_MOUSE 1 -typedef union { - struct { - uint8_t blue; - uint8_t green; - uint8_t red; - uint8_t alpha; - }; - uint32_t full; -} lv_color32_t; - -typedef lv_color32_t lv_color_t; -typedef uint8_t lv_indev_state_t; -typedef int16_t lv_coord_t; -typedef uint8_t lv_opa_t; -typedef struct { - lv_coord_t x; - lv_coord_t y; -} lv_point_t; - -typedef struct { - union { - lv_point_t - point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/ - uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ - uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/ - int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the - previous read*/ - }; - void *user_data; /*'lv_indev_drv_t.priv' for this driver*/ - lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ -} lv_indev_data_t; - -enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR }; -enum { - LV_OPA_TRANSP = 0, - LV_OPA_0 = 0, - LV_OPA_10 = 25, - LV_OPA_20 = 51, - LV_OPA_30 = 76, - LV_OPA_40 = 102, - LV_OPA_50 = 127, - LV_OPA_60 = 153, - LV_OPA_70 = 178, - LV_OPA_80 = 204, - LV_OPA_90 = 229, - LV_OPA_100 = 255, - LV_OPA_COVER = 255, -}; - -extern void -xpt2046_init(void); - -extern bool -touchscreen_read(lv_indev_data_t *data); - -extern bool -mouse_read(lv_indev_data_t *data); - -extern void -display_init(void); - -extern void -display_deinit(wasm_exec_env_t exec_env); - -extern int -time_get_ms(wasm_exec_env_t exec_env); - -extern void -display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, lv_color_t *color); - -extern void -display_fill(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, lv_color_t *color); - -extern void -display_map(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, const lv_color_t *color); - -extern bool -display_input_read(wasm_exec_env_t exec_env, void *data); - -void -display_vdb_write(wasm_exec_env_t exec_env, void *buf, lv_coord_t buf_w, - lv_coord_t x, lv_coord_t y, lv_color_t *color, lv_opa_t opa); - -#endif diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c deleted file mode 100644 index 2b3b00067..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include "display_indev.h" -#include "SDL2/SDL.h" -#include "sys/time.h" -#include "wasm_export.h" -#include "app_manager_export.h" - -#define MONITOR_HOR_RES 320 -#define MONITOR_VER_RES 240 -#ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 -#endif -#define SDL_REFR_PERIOD 50 -void -monitor_sdl_init(void); -void -monitor_sdl_refr_core(void); -void -monitor_sdl_clean_up(void); - -static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES]; - -int -time_get_ms(wasm_exec_env_t exec_env) -{ - static struct timeval tv; - gettimeofday(&tv, NULL); - long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000; - - return (int)time_in_mill; -} - -SDL_Window *window; -SDL_Renderer *renderer; -SDL_Texture *texture; -static volatile bool sdl_inited = false; -static volatile bool sdl_refr_qry = false; -static volatile bool sdl_quit_qry = false; - -void -monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color) -{ - /*Return if the area is out the screen*/ - if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1 - || y1 > MONITOR_VER_RES - 1) { - return; - } - - int32_t y; - uint32_t w = x2 - x1 + 1; - - for (y = y1; y <= y2; y++) { - memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color, - w * sizeof(lv_color_t)); - - color += w; - } - sdl_refr_qry = true; - - /*IMPORTANT! It must be called to tell the system the flush is ready*/ -} - -/** - * Fill out the marked area with a color - * @param x1 left coordinate - * @param y1 top coordinate - * @param x2 right coordinate - * @param y2 bottom coordinate - * @param color fill color - */ -void -monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color) -{ - /*Return if the area is out the screen*/ - if (x2 < 0) - return; - if (y2 < 0) - return; - if (x1 > MONITOR_HOR_RES - 1) - return; - if (y1 > MONITOR_VER_RES - 1) - return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2; - - int32_t x; - int32_t y; - uint32_t color32 = color->full; // lv_color_to32(color); - - for (x = act_x1; x <= act_x2; x++) { - for (y = act_y1; y <= act_y2; y++) { - tft_fb[y * MONITOR_HOR_RES + x] = color32; - } - } - - sdl_refr_qry = true; -} - -/** - * Put a color map to the marked area - * @param x1 left coordinate - * @param y1 top coordinate - * @param x2 right coordinate - * @param y2 bottom coordinate - * @param color an array of colors - */ -void -monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color) -{ - /*Return if the area is out the screen*/ - if (x2 < 0) - return; - if (y2 < 0) - return; - if (x1 > MONITOR_HOR_RES - 1) - return; - if (y1 > MONITOR_VER_RES - 1) - return; - - /*Truncate the area to the screen*/ - int32_t act_x1 = x1 < 0 ? 0 : x1; - int32_t act_y1 = y1 < 0 ? 0 : y1; - int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2; - int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2; - - int32_t x; - int32_t y; - - for (y = act_y1; y <= act_y2; y++) { - for (x = act_x1; x <= act_x2; x++) { - tft_fb[y * MONITOR_HOR_RES + x] = - color->full; // lv_color_to32(*color); - color++; - } - - color += x2 - act_x2; - } - - sdl_refr_qry = true; -} - -void -display_init(void) -{} - -void -display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, lv_color_t *color) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - - if (!wasm_runtime_validate_native_addr(module_inst, color, - sizeof(lv_color_t))) - return; - - monitor_flush(x1, y1, x2, y2, color); -} - -void -display_fill(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, lv_color_t *color) -{ - monitor_fill(x1, y1, x2, y2, color); -} - -void -display_map(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, const lv_color_t *color) -{ - monitor_map(x1, y1, x2, y2, color); -} - -typedef struct display_input_data { - lv_point_t point; - uint32 user_data_offset; - uint8 state; -} display_input_data; - -bool -display_input_read(wasm_exec_env_t exec_env, void *input_data_app) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - display_input_data *data_app = (display_input_data *)input_data_app; - bool ret; - - if (!wasm_runtime_validate_native_addr(module_inst, data_app, - sizeof(display_input_data))) - return false; - - lv_indev_data_t data = { 0 }; - - ret = mouse_read(&data); - - data_app->point = data.point; - data_app->user_data_offset = - wasm_runtime_addr_native_to_app(module_inst, data.user_data); - data_app->state = data.state; - - return ret; -} - -void -display_deinit(wasm_exec_env_t exec_env) -{} - -void -display_vdb_write(wasm_exec_env_t exec_env, void *buf, lv_coord_t buf_w, - lv_coord_t x, lv_coord_t y, lv_color_t *color, lv_opa_t opa) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - unsigned char *buf_xy = (unsigned char *)buf + 4 * x + 4 * y * buf_w; - - if (!wasm_runtime_validate_native_addr(module_inst, color, - sizeof(lv_color_t))) - return; - - *(lv_color_t *)buf_xy = *color; -} - -int -monitor_sdl_refr_thread(void *param) -{ - (void)param; - - /*If not OSX initialize SDL in the Thread*/ - monitor_sdl_init(); - /*Run until quit event not arrives*/ - while (sdl_quit_qry == false) { - /*Refresh handling*/ - monitor_sdl_refr_core(); - } - - monitor_sdl_clean_up(); - exit(0); - - return 0; -} -extern void -mouse_handler(SDL_Event *event); -void -monitor_sdl_refr_core(void) -{ - if (sdl_refr_qry != false) { - sdl_refr_qry = false; - - SDL_UpdateTexture(texture, NULL, tft_fb, - MONITOR_HOR_RES * sizeof(uint32_t)); - SDL_RenderClear(renderer); - /*Update the renderer with the texture containing the rendered image*/ - SDL_RenderCopy(renderer, texture, NULL, NULL); - SDL_RenderPresent(renderer); - } - - SDL_Event event; - while (SDL_PollEvent(&event)) { - - mouse_handler(&event); - - if ((&event)->type == SDL_WINDOWEVENT) { - switch ((&event)->window.event) { -#if SDL_VERSION_ATLEAST(2, 0, 5) - case SDL_WINDOWEVENT_TAKE_FOCUS: -#endif - case SDL_WINDOWEVENT_EXPOSED: - - SDL_UpdateTexture(texture, NULL, tft_fb, - MONITOR_HOR_RES * sizeof(uint32_t)); - SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, texture, NULL, NULL); - SDL_RenderPresent(renderer); - break; - default: - break; - } - } - } - - /*Sleep some time*/ - SDL_Delay(SDL_REFR_PERIOD); -} -int -quit_filter(void *userdata, SDL_Event *event) -{ - (void)userdata; - - if (event->type == SDL_QUIT) { - sdl_quit_qry = true; - } - - return 1; -} - -void -monitor_sdl_clean_up(void) -{ - SDL_DestroyTexture(texture); - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); - SDL_Quit(); -} - -void -monitor_sdl_init(void) -{ - /*Initialize the SDL*/ - SDL_Init(SDL_INIT_VIDEO); - - SDL_SetEventFilter(quit_filter, NULL); - - window = SDL_CreateWindow( - "TFT Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, - 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/ - - renderer = SDL_CreateRenderer(window, -1, 0); - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, - MONITOR_VER_RES); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); - - /*Initialize the frame buffer to gray (77 is an empirical value) */ - memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t)); - SDL_UpdateTexture(texture, NULL, tft_fb, - MONITOR_HOR_RES * sizeof(uint32_t)); - sdl_refr_qry = true; - sdl_inited = true; -} - -void -display_SDL_init() -{ - SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL); - while (sdl_inited == false) - ; /*Wait until 'sdl_refr' initializes the SDL*/ -} diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c deleted file mode 100644 index e2253bb5e..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c +++ /dev/null @@ -1,544 +0,0 @@ - -#ifndef CONNECTION_UART -#include -#include -#include -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "runtime_lib.h" -#include "runtime_timer.h" -#include "native_interface.h" -#include "app_manager_export.h" -#include "bh_platform.h" -#include "bi-inc/attr_container.h" -#include "module_wasm_app.h" -#include "wasm_export.h" -#include "sensor_native_api.h" -#include "connection_native_api.h" -#include "display_indev.h" - -#define MAX 2048 - -#ifndef CONNECTION_UART -#define SA struct sockaddr -static char *host_address = "127.0.0.1"; -static int port = 8888; -#else -static char *uart_device = "/dev/ttyS2"; -static int baudrate = B115200; -#endif - -extern bool -init_sensor_framework(); -extern void -exit_sensor_framework(); -extern void -exit_connection_framework(); -extern int -aee_host_msg_callback(void *msg, uint32_t msg_len); -extern bool -init_connection_framework(); - -#ifndef CONNECTION_UART -int listenfd = -1; -int sockfd = -1; -static pthread_mutex_t sock_lock = PTHREAD_MUTEX_INITIALIZER; -#else -int uartfd = -1; -#endif - -#ifndef CONNECTION_UART -static bool server_mode = false; - -// Function designed for chat between client and server. -void * -func(void *arg) -{ - char buff[MAX]; - int n; - struct sockaddr_in servaddr; - - while (1) { - if (sockfd != -1) - close(sockfd); - // socket create and verification - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd == -1) { - printf("socket creation failed...\n"); - return NULL; - } - else - printf("Socket successfully created..\n"); - bzero(&servaddr, sizeof(servaddr)); - // assign IP, PORT - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr(host_address); - servaddr.sin_port = htons(port); - - // connect the client socket to server socket - if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) { - printf("connection with the server failed...\n"); - sleep(10); - continue; - } - else { - printf("connected to the server..\n"); - } - - // infinite loop for chat - for (;;) { - bzero(buff, MAX); - - // read the message from client and copy it in buffer - n = read(sockfd, buff, sizeof(buff)); - // print buffer which contains the client contents - // fprintf(stderr, "recieved %d bytes from host: %s", n, buff); - - // socket disconnected - if (n <= 0) - break; - - aee_host_msg_callback(buff, n); - } - } - - // After chatting close the socket - close(sockfd); -} - -static bool -host_init() -{ - return true; -} - -int -host_send(void *ctx, const char *buf, int size) -{ - int ret; - - if (pthread_mutex_trylock(&sock_lock) == 0) { - if (sockfd == -1) { - pthread_mutex_unlock(&sock_lock); - return 0; - } - - ret = write(sockfd, buf, size); - - pthread_mutex_unlock(&sock_lock); - return ret; - } - - return -1; -} - -void -host_destroy() -{ - if (server_mode) - close(listenfd); - - pthread_mutex_lock(&sock_lock); - close(sockfd); - pthread_mutex_unlock(&sock_lock); -} - -host_interface interface = { .init = host_init, - .send = host_send, - .destroy = host_destroy }; - -void * -func_server_mode(void *arg) -{ - int clilent; - struct sockaddr_in serv_addr, cli_addr; - int n; - char buff[MAX]; - struct sigaction sa; - - sa.sa_handler = SIG_IGN; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sigaction(SIGPIPE, &sa, 0); - - /* First call to socket() function */ - listenfd = socket(AF_INET, SOCK_STREAM, 0); - - if (listenfd < 0) { - perror("ERROR opening socket"); - exit(1); - } - - /* Initialize socket structure */ - bzero((char *)&serv_addr, sizeof(serv_addr)); - - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; - serv_addr.sin_port = htons(port); - - /* Now bind the host address using bind() call.*/ - if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { - perror("ERROR on binding"); - exit(1); - } - - listen(listenfd, 5); - clilent = sizeof(cli_addr); - - while (1) { - pthread_mutex_lock(&sock_lock); - - sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent); - - pthread_mutex_unlock(&sock_lock); - - if (sockfd < 0) { - perror("ERROR on accept"); - exit(1); - } - - printf("connection established!\n"); - - for (;;) { - bzero(buff, MAX); - - // read the message from client and copy it in buffer - n = read(sockfd, buff, sizeof(buff)); - - // socket disconnected - if (n <= 0) { - pthread_mutex_lock(&sock_lock); - close(sockfd); - sockfd = -1; - pthread_mutex_unlock(&sock_lock); - - sleep(2); - break; - } - - aee_host_msg_callback(buff, n); - } - } -} - -#else -static int -parse_baudrate(int baud) -{ - switch (baud) { - case 9600: - return B9600; - case 19200: - return B19200; - case 38400: - return B38400; - case 57600: - return B57600; - case 115200: - return B115200; - case 230400: - return B230400; - case 460800: - return B460800; - case 500000: - return B500000; - case 576000: - return B576000; - case 921600: - return B921600; - case 1000000: - return B1000000; - case 1152000: - return B1152000; - case 1500000: - return B1500000; - case 2000000: - return B2000000; - case 2500000: - return B2500000; - case 3000000: - return B3000000; - case 3500000: - return B3500000; - case 4000000: - return B4000000; - default: - return -1; - } -} -static bool -uart_init(const char *device, int baudrate, int *fd) -{ - int uart_fd; - struct termios uart_term; - - uart_fd = open(device, O_RDWR | O_NOCTTY); - - if (uart_fd <= 0) - return false; - - memset(&uart_term, 0, sizeof(uart_term)); - uart_term.c_cflag = baudrate | CS8 | CLOCAL | CREAD; - uart_term.c_iflag = IGNPAR; - uart_term.c_oflag = 0; - - /* set noncanonical mode */ - uart_term.c_lflag = 0; - uart_term.c_cc[VTIME] = 30; - uart_term.c_cc[VMIN] = 1; - tcflush(uart_fd, TCIFLUSH); - - if (tcsetattr(uart_fd, TCSANOW, &uart_term) != 0) { - close(uart_fd); - return false; - } - - *fd = uart_fd; - - return true; -} - -static void * -func_uart_mode(void *arg) -{ - int n; - char buff[MAX]; - - if (!uart_init(uart_device, baudrate, &uartfd)) { - printf("open uart fail! %s\n", uart_device); - return NULL; - } - - for (;;) { - bzero(buff, MAX); - - n = read(uartfd, buff, sizeof(buff)); - - if (n <= 0) { - close(uartfd); - uartfd = -1; - break; - } - - aee_host_msg_callback(buff, n); - } - - return NULL; -} - -static int -uart_send(void *ctx, const char *buf, int size) -{ - int ret; - - ret = write(uartfd, buf, size); - - return ret; -} - -static void -uart_destroy() -{ - close(uartfd); -} - -static host_interface interface = { .send = uart_send, - .destroy = uart_destroy }; - -#endif - -#ifdef __x86_64__ -static char global_heap_buf[400 * 1024] = { 0 }; -#else -static char global_heap_buf[270 * 1024] = { 0 }; -#endif - -/* clang-format off */ -static void showUsage() -{ -#ifndef CONNECTION_UART - printf("Usage:\n"); - printf("\nWork as TCP server mode:\n"); - printf("\tvgl_wasm_runtime -s|--server_mode -p|--port \n"); - printf("where\n"); - printf("\t represents the port that would be listened on and the default is 8888\n"); - printf("\nWork as TCP client mode:\n"); - printf("\tvgl_wasm_runtime -a|--host_address -p|--port \n"); - printf("where\n"); - printf("\t represents the network address of host and the default is 127.0.0.1\n"); - printf("\t represents the listen port of host and the default is 8888\n"); -#else - printf("Usage:\n"); - printf("\tvgl_wasm_runtime -u -b \n\n"); - printf("where\n"); - printf("\t represents the UART device name and the default is /dev/ttyS2\n"); - printf("\t represents the UART device baudrate and the default is 115200\n"); -#endif - printf("\nNote:\n"); - printf("\tUse -w|--wasi_root to specify the root dir (default to '.') of WASI wasm modules. \n"); -} -/* clang-format on */ - -static bool -parse_args(int argc, char *argv[]) -{ - int c; - - while (1) { - int optIndex = 0; - static struct option longOpts[] = { -#ifndef CONNECTION_UART - { "server_mode", no_argument, NULL, 's' }, - { "host_address", required_argument, NULL, 'a' }, - { "port", required_argument, NULL, 'p' }, -#else - { "uart", required_argument, NULL, 'u' }, - { "baudrate", required_argument, NULL, 'b' }, -#endif -#if WASM_ENABLE_LIBC_WASI != 0 - { "wasi_root", required_argument, NULL, 'w' }, -#endif - { "help", required_argument, NULL, 'h' }, - { 0, 0, 0, 0 } - }; - - c = getopt_long(argc, argv, "sa:p:u:b:w:h", longOpts, &optIndex); - if (c == -1) - break; - - switch (c) { -#ifndef CONNECTION_UART - case 's': - server_mode = true; - break; - case 'a': - host_address = optarg; - printf("host address: %s\n", host_address); - break; - case 'p': - port = atoi(optarg); - printf("port: %d\n", port); - break; -#else - case 'u': - uart_device = optarg; - printf("uart device: %s\n", uart_device); - break; - case 'b': - baudrate = parse_baudrate(atoi(optarg)); - printf("uart baudrate: %s\n", optarg); - break; -#endif -#if WASM_ENABLE_LIBC_WASI != 0 - case 'w': - if (!wasm_set_wasi_root_dir(optarg)) { - printf("Fail to set wasi root dir: %s\n", optarg); - return false; - } - break; -#endif - case 'h': - showUsage(); - return false; - default: - showUsage(); - return false; - } - } - - return true; -} - -static NativeSymbol native_symbols[] = { - EXPORT_WASM_API_WITH_SIG(display_input_read, "(*)i"), - EXPORT_WASM_API_WITH_SIG(display_flush, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(display_fill, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(display_vdb_write, "(*iii*i)"), - EXPORT_WASM_API_WITH_SIG(display_map, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i") -}; - -// Driver function -int -iwasm_main(int argc, char *argv[]) -{ - RuntimeInitArgs init_args; - korp_tid tid; - uint32 n_native_symbols; - - if (!parse_args(argc, argv)) - return -1; - - memset(&init_args, 0, sizeof(RuntimeInitArgs)); - - init_args.mem_alloc_type = Alloc_With_Pool; - init_args.mem_alloc_option.pool.heap_buf = global_heap_buf; - init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); - - init_args.native_module_name = "env"; - init_args.n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol); - init_args.native_symbols = native_symbols; - - /* initialize runtime environment */ - if (!wasm_runtime_full_init(&init_args)) { - printf("Init runtime environment failed.\n"); - return -1; - } - - if (!init_connection_framework()) { - goto fail1; - } - - extern void display_SDL_init(); - display_SDL_init(); - - if (!init_sensor_framework()) { - goto fail2; - } - - /* timer manager */ - if (!init_wasm_timer()) { - goto fail3; - } - -#ifndef CONNECTION_UART - if (server_mode) - os_thread_create(&tid, func_server_mode, NULL, - BH_APPLET_PRESERVED_STACK_SIZE); - else - os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE); -#else - os_thread_create(&tid, func_uart_mode, NULL, - BH_APPLET_PRESERVED_STACK_SIZE); -#endif - - app_manager_startup(&interface); - - exit_wasm_timer(); - -fail3: - exit_sensor_framework(); - -fail2: - exit_connection_framework(); - -fail1: - wasm_runtime_destroy(); - - return -1; -} diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c deleted file mode 100644 index 63e24f11d..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -extern int -iwasm_main(int argc, char *argv[]); -int -main(int argc, char *argv[]) -{ - return iwasm_main(argc, argv); -} diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c deleted file mode 100644 index 45eb8cfe5..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c +++ /dev/null @@ -1,97 +0,0 @@ -/** - * @file mouse.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "display_indev.h" -#include "SDL2/SDL.h" -#if USE_MOUSE != 0 - -/********************* - * DEFINES - *********************/ -#ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 -#endif - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ -static bool left_button_down = false; -static int16_t last_x = 0; -static int16_t last_y = 0; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the mouse - */ -void -mouse_init(void) -{} - -/** - * Get the current position and state of the mouse - * @param data store the mouse data here - * @return false: because the points are not buffered, so no more data to be - * read - */ -bool -mouse_read(lv_indev_data_t *data) -{ - /*Store the collected data*/ - data->point.x = last_x; - data->point.y = last_y; - data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; - - return false; -} - -/** - * It will be called from the main SDL thread - */ -void -mouse_handler(SDL_Event *event) -{ - switch (event->type) { - case SDL_MOUSEBUTTONUP: - if (event->button.button == SDL_BUTTON_LEFT) - left_button_down = false; - break; - case SDL_MOUSEBUTTONDOWN: - if (event->button.button == SDL_BUTTON_LEFT) { - left_button_down = true; - last_x = event->motion.x / MONITOR_ZOOM; - last_y = event->motion.y / MONITOR_ZOOM; - } - break; - case SDL_MOUSEMOTION: - last_x = event->motion.x / MONITOR_ZOOM; - last_y = event->motion.y / MONITOR_ZOOM; - - break; - } -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -#endif diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE deleted file mode 100644 index 8f71f43fe..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h deleted file mode 100644 index 3cd3a571d..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @file XPT2046.h - * - */ - -#ifndef XPT2046_H -#define XPT2046_H - -#define USE_XPT2046 1 - -#define XPT2046_HOR_RES 320 -#define XPT2046_VER_RES 240 -#define XPT2046_X_MIN 200 -#define XPT2046_Y_MIN 200 -#define XPT2046_X_MAX 3800 -#define XPT2046_Y_MAX 3800 -#define XPT2046_AVG 4 -#define XPT2046_INV 0 - -#define CMD_X_READ 0b10010000 -#define CMD_Y_READ 0b11010000 - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -#if USE_XPT2046 -#include -#include -#include -//#include "lvgl/lv_hal/lv_hal_indev.h" -#include "device.h" -#include "drivers/gpio.h" -#if 1 -enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR }; -typedef uint8_t lv_indev_state_t; -typedef int16_t lv_coord_t; -typedef struct { - lv_coord_t x; - lv_coord_t y; -} lv_point_t; - -typedef struct { - union { - lv_point_t - point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/ - uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ - uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/ - int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the - previous read*/ - }; - void *user_data; /*'lv_indev_drv_t.priv' for this driver*/ - lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ -} lv_indev_data_t; -#endif - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -void -xpt2046_init(void); -bool -xpt2046_read(lv_indev_data_t *data); - -/********************** - * MACROS - **********************/ - -#endif /* USE_XPT2046 */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* XPT2046_H */ diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h deleted file mode 100644 index d7ea279a9..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#ifndef __BOARD_CONFIG_H__ -#define __BOARD_CONFIG_H__ -#include "pin_config_stm32.h" - -#endif /* __BOARD_CONFIG_H__ */ diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h deleted file mode 100644 index c6657a40a..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright (c) 2017 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Public API for display drivers and applications - */ - -#ifndef ZEPHYR_INCLUDE_DISPLAY_H_ -#define ZEPHYR_INCLUDE_DISPLAY_H_ - -/** - * @brief Display Interface - * @defgroup display_interface Display Interface - * @ingroup display_interfaces - * @{ - */ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -enum display_pixel_format { - PIXEL_FORMAT_RGB_888 = BIT(0), - PIXEL_FORMAT_MONO01 = BIT(1), /* 0=Black 1=White */ - PIXEL_FORMAT_MONO10 = BIT(2), /* 1=Black 0=White */ - PIXEL_FORMAT_ARGB_8888 = BIT(3), - PIXEL_FORMAT_RGB_565 = BIT(4), -}; - -enum display_screen_info { - /** - * If selected, one octet represents 8 pixels ordered vertically, - * otherwise ordered horizontally. - */ - SCREEN_INFO_MONO_VTILED = BIT(0), - /** - * If selected, the MSB represents the first pixel, - * otherwise MSB represents the last pixel. - */ - SCREEN_INFO_MONO_MSB_FIRST = BIT(1), - /** - * Electrophoretic Display. - */ - SCREEN_INFO_EPD = BIT(2), - /** - * Screen has two alternating ram buffers - */ - SCREEN_INFO_DOUBLE_BUFFER = BIT(3), -}; - -/** - * @enum display_orientation - * @brief Enumeration with possible display orientation - * - */ -enum display_orientation { - DISPLAY_ORIENTATION_NORMAL, - DISPLAY_ORIENTATION_ROTATED_90, - DISPLAY_ORIENTATION_ROTATED_180, - DISPLAY_ORIENTATION_ROTATED_270, -}; - -/** - * @struct display_capabilities - * @brief Structure holding display capabilities - * - * @var u16_t display_capabilities::x_resolution - * Display resolution in the X direction - * - * @var u16_t display_capabilities::y_resolution - * Display resolution in the Y direction - * - * @var u32_t display_capabilities::supported_pixel_formats - * Bitwise or of pixel formats supported by the display - * - * @var u32_t display_capabilities::screen_info - * Information about display panel - * - * @var enum display_pixel_format display_capabilities::current_pixel_format - * Currently active pixel format for the display - * - * @var enum display_orientation display_capabilities::current_orientation - * Current display orientation - * - */ -struct display_capabilities { - uint16_t x_resolution; - uint16_t y_resolution; - uint32_t supported_pixel_formats; - uint32_t screen_info; - enum display_pixel_format current_pixel_format; - enum display_orientation current_orientation; -}; - -/** - * @struct display_buffer_descriptor - * @brief Structure to describe display data buffer layout - * - * @var u32_t display_buffer_descriptor::buf_size - * Data buffer size in bytes - * - * @var u16_t display_buffer_descriptor::width - * Data buffer row width in pixels - * - * @var u16_t display_buffer_descriptor::height - * Data buffer column height in pixels - * - * @var u16_t display_buffer_descriptor::pitch - * Number of pixels between consecutive rows in the data buffer - * - */ -struct display_buffer_descriptor { - uint32_t buf_size; - uint16_t width; - uint16_t height; - uint16_t pitch; -}; - -/** - * @typedef display_blanking_on_api - * @brief Callback API to turn on display blanking - * See display_blanking_on() for argument description - */ -typedef int (*display_blanking_on_api)(const struct device *dev); - -/** - * @typedef display_blanking_off_api - * @brief Callback API to turn off display blanking - * See display_blanking_off() for argument description - */ -typedef int (*display_blanking_off_api)(const struct device *dev); - -/** - * @typedef display_write_api - * @brief Callback API for writing data to the display - * See display_write() for argument description - */ -typedef int (*display_write_api)(const struct device *dev, const uint16_t x, - const uint16_t y, - const struct display_buffer_descriptor *desc, - const void *buf); - -/** - * @typedef display_read_api - * @brief Callback API for reading data from the display - * See display_read() for argument description - */ -typedef int (*display_read_api)(const struct device *dev, const uint16_t x, - const uint16_t y, - const struct display_buffer_descriptor *desc, - void *buf); - -/** - * @typedef display_get_framebuffer_api - * @brief Callback API to get framebuffer pointer - * See display_get_framebuffer() for argument description - */ -typedef void *(*display_get_framebuffer_api)(const struct device *dev); - -/** - * @typedef display_set_brightness_api - * @brief Callback API to set display brightness - * See display_set_brightness() for argument description - */ -typedef int (*display_set_brightness_api)(const struct device *dev, - const uint8_t brightness); - -/** - * @typedef display_set_contrast_api - * @brief Callback API to set display contrast - * See display_set_contrast() for argument description - */ -typedef int (*display_set_contrast_api)(const struct device *dev, - const uint8_t contrast); - -/** - * @typedef display_get_capabilities_api - * @brief Callback API to get display capabilities - * See display_get_capabilities() for argument description - */ -typedef void (*display_get_capabilities_api)( - const struct device *dev, struct display_capabilities *capabilities); - -/** - * @typedef display_set_pixel_format_api - * @brief Callback API to set pixel format used by the display - * See display_set_pixel_format() for argument description - */ -typedef int (*display_set_pixel_format_api)( - const struct device *dev, const enum display_pixel_format pixel_format); - -/** - * @typedef display_set_orientation_api - * @brief Callback API to set orientation used by the display - * See display_set_orientation() for argument description - */ -typedef int (*display_set_orientation_api)( - const struct device *dev, const enum display_orientation orientation); - -/** - * @brief Display driver API - * API which a display driver should expose - */ -struct display_driver_api { - display_blanking_on_api blanking_on; - display_blanking_off_api blanking_off; - display_write_api write; - display_read_api read; - display_get_framebuffer_api get_framebuffer; - display_set_brightness_api set_brightness; - display_set_contrast_api set_contrast; - display_get_capabilities_api get_capabilities; - display_set_pixel_format_api set_pixel_format; - display_set_orientation_api set_orientation; -}; -extern struct ili9340_data ili9340_data1; -extern struct display_driver_api ili9340_api1; -/** - * @brief Write data to display - * - * @param dev Pointer to device structure - * @param x x Coordinate of the upper left corner where to write the buffer - * @param y y Coordinate of the upper left corner where to write the buffer - * @param desc Pointer to a structure describing the buffer layout - * @param buf Pointer to buffer array - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_write(const struct device *dev, const uint16_t x, const uint16_t y, - const struct display_buffer_descriptor *desc, const void *buf) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->write(dev, x, y, desc, buf); -} - -/** - * @brief Read data from display - * - * @param dev Pointer to device structure - * @param x x Coordinate of the upper left corner where to read from - * @param y y Coordinate of the upper left corner where to read from - * @param desc Pointer to a structure describing the buffer layout - * @param buf Pointer to buffer array - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_read(const struct device *dev, const uint16_t x, const uint16_t y, - const struct display_buffer_descriptor *desc, void *buf) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->read(dev, x, y, desc, buf); -} - -/** - * @brief Get pointer to framebuffer for direct access - * - * @param dev Pointer to device structure - * - * @retval Pointer to frame buffer or NULL if direct framebuffer access - * is not supported - * - */ -static inline void * -display_get_framebuffer(const struct device *dev) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->get_framebuffer(dev); -} - -/** - * @brief Turn display blanking on - * - * @param dev Pointer to device structure - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_blanking_on(const struct device *dev) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->blanking_on(dev); -} - -/** - * @brief Turn display blanking off - * - * @param dev Pointer to device structure - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_blanking_off(const struct device *dev) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->blanking_off(dev); -} - -/** - * @brief Set the brightness of the display - * - * Set the brightness of the display in steps of 1/256, where 255 is full - * brightness and 0 is minimal. - * - * @param dev Pointer to device structure - * @param brightness Brightness in steps of 1/256 - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_set_brightness(const struct device *dev, uint8_t brightness) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->set_brightness(dev, brightness); -} - -/** - * @brief Set the contrast of the display - * - * Set the contrast of the display in steps of 1/256, where 255 is maximum - * difference and 0 is minimal. - * - * @param dev Pointer to device structure - * @param contrast Contrast in steps of 1/256 - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_set_contrast(const struct device *dev, uint8_t contrast) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->set_contrast(dev, contrast); -} - -/** - * @brief Get display capabilities - * - * @param dev Pointer to device structure - * @param capabilities Pointer to capabilities structure to populate - */ -static inline void -display_get_capabilities(const struct device *dev, - struct display_capabilities *capabilities) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - api->get_capabilities(dev, capabilities); -} - -/** - * @brief Set pixel format used by the display - * - * @param dev Pointer to device structure - * @param pixel_format Pixel format to be used by display - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_set_pixel_format(const struct device *dev, - const enum display_pixel_format pixel_format) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->set_pixel_format(dev, pixel_format); -} - -/** - * @brief Set display orientation - * - * @param dev Pointer to device structure - * @param orientation Orientation to be used by display - * - * @retval 0 on success else negative errno code. - */ -static inline int -display_set_orientation(const struct device *dev, - const enum display_orientation orientation) -{ - struct display_driver_api *api = &ili9340_api1; - //(struct display_driver_api *)dev->driver_api; - - return api->set_orientation(dev, orientation); -} - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* ZEPHYR_INCLUDE_DISPLAY_H_*/ diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c deleted file mode 100644 index e5b0d771a..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) 2017 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "display_ili9340.h" -#include - -//#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL -//#include -// LOG_MODULE_REGISTER(display_ili9340); -#define LOG_ERR printf -#define LOG_DBG printf -#define LOG_WRN printf - -#include -#include -#include -#include -#include - -struct ili9340_data { - struct device *reset_gpio; - struct device *command_data_gpio; - struct device *spi_dev; - struct spi_config spi_config; -#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER - struct spi_cs_control cs_ctrl; -#endif -}; - -struct ili9340_data ili9340_data1; - -#define ILI9340_CMD_DATA_PIN_COMMAND 0 -#define ILI9340_CMD_DATA_PIN_DATA 1 - -static void -ili9340_exit_sleep(struct ili9340_data *data) -{ - ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0); - // k_sleep(Z_TIMEOUT_MS(120)); -} - -int -ili9340_init() -{ - struct ili9340_data *data = &ili9340_data1; - - printf("Initializing display driver\n"); - data->spi_dev = device_get_binding(DT_ILITEK_ILI9340_0_BUS_NAME); - if (data->spi_dev == NULL) { - return -EPERM; - } - data->spi_config.frequency = DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY; - data->spi_config.operation = - SPI_OP_MODE_MASTER - | SPI_WORD_SET(8); // SPI_OP_MODE_MASTER | SPI_WORD_SET(8); - data->spi_config.slave = DT_ILITEK_ILI9340_0_BASE_ADDRESS; - -#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER - data->cs_ctrl.gpio_dev = - device_get_binding(DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER); - data->cs_ctrl.gpio_pin = DT_ILITEK_ILI9340_0_CS_GPIO_PIN; - data->cs_ctrl.delay = 0; - data->spi_config.cs = &(data->cs_ctrl); -#else - data->spi_config.cs = NULL; -#endif - data->reset_gpio = - device_get_binding(DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER); - if (data->reset_gpio == NULL) { - return -EPERM; - } - - gpio_pin_configure(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, - GPIO_OUTPUT); - - data->command_data_gpio = - device_get_binding(DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER); - if (data->command_data_gpio == NULL) { - return -EPERM; - } - - gpio_pin_configure(data->command_data_gpio, - DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, GPIO_OUTPUT); - - LOG_DBG("Resetting display driver\n"); - gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1); - k_sleep(Z_TIMEOUT_MS(1)); - gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 0); - k_sleep(Z_TIMEOUT_MS(1)); - gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1); - k_sleep(Z_TIMEOUT_MS(5)); - - LOG_DBG("Initializing LCD\n"); - ili9340_lcd_init(data); - - LOG_DBG("Exiting sleep mode\n"); - ili9340_exit_sleep(data); - - return 0; -} - -static void -ili9340_set_mem_area(struct ili9340_data *data, const uint16_t x, - const uint16_t y, const uint16_t w, const uint16_t h) -{ - uint16_t spi_data[2]; - - spi_data[0] = sys_cpu_to_be16(x); - spi_data[1] = sys_cpu_to_be16(x + w - 1); - ili9340_transmit(data, ILI9340_CMD_COLUMN_ADDR, &spi_data[0], 4); - - spi_data[0] = sys_cpu_to_be16(y); - spi_data[1] = sys_cpu_to_be16(y + h - 1); - ili9340_transmit(data, ILI9340_CMD_PAGE_ADDR, &spi_data[0], 4); -} - -static int -ili9340_write(const struct device *dev, const uint16_t x, const uint16_t y, - const struct display_buffer_descriptor *desc, const void *buf) -{ - struct ili9340_data *data = (struct ili9340_data *)&ili9340_data1; - const uint8_t *write_data_start = (uint8_t *)buf; - struct spi_buf tx_buf; - struct spi_buf_set tx_bufs; - uint16_t write_cnt; - uint16_t nbr_of_writes; - uint16_t write_h; - - __ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width"); - __ASSERT((3 * desc->pitch * desc->height) <= desc->buf_size, - "Input buffer to small"); - ili9340_set_mem_area(data, x, y, desc->width, desc->height); - - if (desc->pitch > desc->width) { - write_h = 1U; - nbr_of_writes = desc->height; - } - else { - write_h = desc->height; - nbr_of_writes = 1U; - } - ili9340_transmit(data, ILI9340_CMD_MEM_WRITE, (void *)write_data_start, - 3 * desc->width * write_h); - - tx_bufs.buffers = &tx_buf; - tx_bufs.count = 1; - - write_data_start += (3 * desc->pitch); - for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) { - tx_buf.buf = (void *)write_data_start; - tx_buf.len = 3 * desc->width * write_h; - spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); - write_data_start += (3 * desc->pitch); - } - - return 0; -} - -static int -ili9340_read(const struct device *dev, const uint16_t x, const uint16_t y, - const struct display_buffer_descriptor *desc, void *buf) -{ - LOG_ERR("Reading not supported\n"); - return -ENOTSUP; -} - -static void * -ili9340_get_framebuffer(const struct device *dev) -{ - LOG_ERR("Direct framebuffer access not supported\n"); - return NULL; -} - -static int -ili9340_display_blanking_off(const struct device *dev) -{ - struct ili9340_data *data = (struct ili9340_data *)dev->driver_data; - - LOG_DBG("Turning display blanking off\n"); - ili9340_transmit(data, ILI9340_CMD_DISPLAY_ON, NULL, 0); - return 0; -} - -static int -ili9340_display_blanking_on(const struct device *dev) -{ - struct ili9340_data *data = (struct ili9340_data *)dev->driver_data; - - LOG_DBG("Turning display blanking on\n"); - ili9340_transmit(data, ILI9340_CMD_DISPLAY_OFF, NULL, 0); - return 0; -} - -static int -ili9340_set_brightness(const struct device *dev, const uint8_t brightness) -{ - LOG_WRN("Set brightness not implemented\n"); - return -ENOTSUP; -} - -static int -ili9340_set_contrast(const struct device *dev, const uint8_t contrast) -{ - LOG_ERR("Set contrast not supported\n"); - return -ENOTSUP; -} - -static int -ili9340_set_pixel_format(const struct device *dev, - const enum display_pixel_format pixel_format) -{ - if (pixel_format == PIXEL_FORMAT_RGB_888) { - return 0; - } - LOG_ERR("Pixel format change not implemented\n"); - return -ENOTSUP; -} - -static int -ili9340_set_orientation(const struct device *dev, - const enum display_orientation orientation) -{ - if (orientation == DISPLAY_ORIENTATION_NORMAL) { - return 0; - } - LOG_ERR("Changing display orientation not implemented\n"); - return -ENOTSUP; -} - -static void -ili9340_get_capabilities(const struct device *dev, - struct display_capabilities *capabilities) -{ - memset(capabilities, 0, sizeof(struct display_capabilities)); - capabilities->x_resolution = 320; - capabilities->y_resolution = 240; - capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_888; - capabilities->current_pixel_format = PIXEL_FORMAT_RGB_888; - capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL; -} - -void -ili9340_transmit(struct ili9340_data *data, uint8_t cmd, void *tx_data, - size_t tx_len) -{ - struct spi_buf tx_buf = { .buf = &cmd, .len = 1 }; - struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 }; - - data = (struct ili9340_data *)&ili9340_data1; - gpio_pin_set(data->command_data_gpio, - DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, - ILI9340_CMD_DATA_PIN_COMMAND); - spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); - if (tx_data != NULL) { - tx_buf.buf = tx_data; - tx_buf.len = tx_len; - gpio_pin_set(data->command_data_gpio, - DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, - ILI9340_CMD_DATA_PIN_DATA); - spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); - } -} - -struct display_driver_api ili9340_api1 = { - .blanking_on = ili9340_display_blanking_on, - .blanking_off = ili9340_display_blanking_off, - .write = ili9340_write, - .read = ili9340_read, - .get_framebuffer = ili9340_get_framebuffer, - .set_brightness = ili9340_set_brightness, - .set_contrast = ili9340_set_contrast, - .get_capabilities = ili9340_get_capabilities, - .set_pixel_format = ili9340_set_pixel_format, - .set_orientation = ili9340_set_orientation -}; - -/* -DEVICE_AND_API_INIT(ili9340, DT_ILITEK_ILI9340_0_LABEL, &ili9340_init, - &ili9340_data, NULL, APPLICATION, - CONFIG_APPLICATION_INIT_PRIORITY, &ili9340_api); -*/ diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c deleted file mode 100644 index 65aa618b5..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2017 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "display_ili9340.h" - -void -ili9340_lcd_init(struct ili9340_data *data) -{ - uint8_t tx_data[15]; - - tx_data[0] = 0x23; - ili9340_transmit(data, ILI9340_CMD_POWER_CTRL_1, tx_data, 1); - - tx_data[0] = 0x10; - ili9340_transmit(data, ILI9340_CMD_POWER_CTRL_2, tx_data, 1); - - tx_data[0] = 0x3e; - tx_data[1] = 0x28; - ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_1, tx_data, 2); - - tx_data[0] = 0x86; - ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1); - - tx_data[0] = - ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR; - ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1); - - tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT - | ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT; - ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1); - - tx_data[0] = 0x00; - tx_data[1] = 0x18; - ili9340_transmit(data, ILI9340_CMD_FRAME_CTRL_NORMAL_MODE, tx_data, 2); - - tx_data[0] = 0x08; - tx_data[1] = 0x82; - tx_data[2] = 0x27; - ili9340_transmit(data, ILI9340_CMD_DISPLAY_FUNCTION_CTRL, tx_data, 3); - - tx_data[0] = 0x01; - ili9340_transmit(data, ILI9340_CMD_GAMMA_SET, tx_data, 1); - - tx_data[0] = 0x0F; - tx_data[1] = 0x31; - tx_data[2] = 0x2B; - tx_data[3] = 0x0C; - tx_data[4] = 0x0E; - tx_data[5] = 0x08; - tx_data[6] = 0x4E; - tx_data[7] = 0xF1; - tx_data[8] = 0x37; - tx_data[9] = 0x07; - tx_data[10] = 0x10; - tx_data[11] = 0x03; - tx_data[12] = 0x0E; - tx_data[13] = 0x09; - tx_data[14] = 0x00; - ili9340_transmit(data, ILI9340_CMD_POSITVE_GAMMA_CORRECTION, tx_data, 15); - - tx_data[0] = 0x00; - tx_data[1] = 0x0E; - tx_data[2] = 0x14; - tx_data[3] = 0x03; - tx_data[4] = 0x11; - tx_data[5] = 0x07; - tx_data[6] = 0x31; - tx_data[7] = 0xC1; - tx_data[8] = 0x48; - tx_data[9] = 0x08; - tx_data[10] = 0x0F; - tx_data[11] = 0x0C; - tx_data[12] = 0x31; - tx_data[13] = 0x36; - tx_data[14] = 0x0F; - ili9340_transmit(data, ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION, tx_data, 15); -} diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c deleted file mode 100644 index b2f9f8e52..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#include -#include -#include "display_indev.h" -#include "display.h" -#include "wasm_export.h" -#include "app_manager_export.h" - -#define MONITOR_HOR_RES 320 -#define MONITOR_VER_RES 240 -#ifndef MONITOR_ZOOM -#define MONITOR_ZOOM 1 -#endif - -extern int -ili9340_init(); - -static int lcd_initialized = 0; - -void -display_init(void) -{ - if (lcd_initialized != 0) { - return; - } - lcd_initialized = 1; - xpt2046_init(); - ili9340_init(); - display_blanking_off(NULL); -} - -void -display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, lv_color_t *color) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - struct display_buffer_descriptor desc; - - if (!wasm_runtime_validate_native_addr(module_inst, color, - sizeof(lv_color_t))) - return; - - uint16_t w = x2 - x1 + 1; - uint16_t h = y2 - y1 + 1; - - desc.buf_size = 3 * w * h; - desc.width = w; - desc.pitch = w; - desc.height = h; - display_write(NULL, x1, y1, &desc, (void *)color); - - /*lv_flush_ready();*/ -} - -void -display_fill(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, lv_color_t *color) -{} - -void -display_map(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2, - int32_t y2, const lv_color_t *color) -{} - -bool -display_input_read(wasm_exec_env_t exec_env, void *data) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - lv_indev_data_t *lv_data = (lv_indev_data_t *)data; - - if (!wasm_runtime_validate_native_addr(module_inst, lv_data, - sizeof(lv_indev_data_t))) - return false; - - return touchscreen_read(lv_data); -} - -void -display_deinit(wasm_exec_env_t exec_env) -{} - -void -display_vdb_write(wasm_exec_env_t exec_env, void *buf, lv_coord_t buf_w, - lv_coord_t x, lv_coord_t y, lv_color_t *color, lv_opa_t opa) -{ - wasm_module_inst_t module_inst = get_module_inst(exec_env); - uint8_t *buf_xy = (uint8_t *)buf + 3 * x + 3 * y * buf_w; - - if (!wasm_runtime_validate_native_addr(module_inst, color, - sizeof(lv_color_t))) - return; - - *buf_xy = color->red; - *(buf_xy + 1) = color->green; - *(buf_xy + 2) = color->blue; -} - -int -time_get_ms(wasm_exec_env_t exec_env) -{ - return k_uptime_get_32(); -} diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c deleted file mode 100644 index c331306ed..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include "bh_platform.h" -#include "bh_assert.h" -#include "bh_log.h" -#include "wasm_export.h" - -extern void -display_init(void); -extern int -iwasm_main(); - -void -main(void) -{ - display_init(); - iwasm_main(); - for (;;) { - k_sleep(Z_TIMEOUT_MS(1000)); - } -} diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h deleted file mode 100644 index bb20ecbb8..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#ifndef __PIN_CONFIG_JLF_H__ -#define __PIN_CONFIG_JLF_H__ - -#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2" -#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10 * 1000 - -#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1 -#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIO_0" -#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 5 -#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIO_0" -#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4 - -#define XPT2046_SPI_DEVICE_NAME "SPI_2" -#define XPT2046_SPI_MAX_FREQUENCY 10 * 1000 -#define XPT2046_CS_GPIO_CONTROLLER "GPIO_0" -#define XPT2046_CS_GPIO_PIN 6 - -#define XPT2046_PEN_GPIO_CONTROLLER "GPIO_0" -#define XPT2046_PEN_GPIO_PIN 7 - -#define HOST_DEVICE_COMM_UART_NAME "UART_1" -#endif /* __PIN_CONFIG_JLF_H__ */ diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h deleted file mode 100644 index 523ce2308..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#ifndef __PIN_CONFIG_STM32_H__ -#define __PIN_CONFIG_STM32_H__ - -#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_1" -#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 24 * 1000 * 1000 - -#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1 -#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIOC" -#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 12 -#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIOC" -#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 11 - -#define DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER "GPIOC" -#define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10 - -#define XPT2046_SPI_DEVICE_NAME "SPI_1" -#define XPT2046_SPI_MAX_FREQUENCY 12 * 1000 * 1000 -#define XPT2046_CS_GPIO_CONTROLLER "GPIOD" -#define XPT2046_CS_GPIO_PIN 0 - -#define XPT2046_PEN_GPIO_CONTROLLER "GPIOD" -#define XPT2046_PEN_GPIO_PIN 1 - -#define HOST_DEVICE_COMM_UART_NAME "UART_6" - -#endif /* __PIN_CONFIG_STM32_H__ */ diff --git a/samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt b/samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt deleted file mode 100644 index 723ff8fa9..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required(VERSION 3.8.2) - -include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) -project(NONE) - -set (WAMR_BUILD_PLATFORM "zephyr") - -enable_language (ASM) - -add_definitions(-DWA_MALLOC=wasm_runtime_malloc) -add_definitions(-DWA_FREE=wasm_runtime_free) - -# Build as THUMB by default -# change to "ARM[sub]", "THUMB[sub]", "X86_32", "MIPS_32" or "XTENSA_32" -# if we want to support arm_32, x86, mips or xtensa -if (NOT DEFINED WAMR_BUILD_TARGET) - set (WAMR_BUILD_TARGET "THUMBV7") -endif () - -if (NOT DEFINED WAMR_BUILD_INTERP) - # Enable Interpreter by default - set (WAMR_BUILD_INTERP 1) -endif () - -if (NOT DEFINED WAMR_BUILD_AOT) - set (WAMR_BUILD_AOT 1) -endif () - -if (NOT DEFINED WAMR_BUILD_JIT) - # Disable JIT by default. - set (WAMR_BUILD_JIT 0) -endif () - -if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) - set (WAMR_BUILD_LIBC_BUILTIN 1) -endif () - -if (NOT DEFINED WAMR_BUILD_LIBC_WASI) - set (WAMR_BUILD_LIBC_WASI 0) -endif () - -if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK) - set (WAMR_BUILD_APP_FRAMEWORK 1) -endif () - -if (NOT DEFINED WAMR_BUILD_APP_LIST) - set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_SENSOR WAMR_APP_BUILD_CONNECTION) -endif () - -set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wamr) -include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr) - -set (LVGL_DRV_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340_adafruit_1480.c - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340.c - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_indev.c - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/XPT2046.c - ) - -target_sources(app PRIVATE - ${WAMR_RUNTIME_LIB_SOURCE} - ${LVGL_DRV_SRCS} - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/iwasm_main.c - ) diff --git a/samples/littlevgl/vgl-wasm-runtime/zephyr-build/prj.conf b/samples/littlevgl/vgl-wasm-runtime/zephyr-build/prj.conf deleted file mode 100644 index 6ca7f4426..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/zephyr-build/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_SPI=y -CONFIG_SPI_STM32=y -CONFIG_PRINTK=y -CONFIG_LOG=y -#CONFIG_UART_2=y -CONFIG_UART_INTERRUPT_DRIVEN=y -CONFIG_STACK_SENTINEL=y -CONFIG_MAIN_STACK_SIZE=2048 -CONFIG_ARM_MPU=y diff --git a/samples/littlevgl/wamr_config_littlevgl.cmake b/samples/littlevgl/wamr_config_littlevgl.cmake deleted file mode 100644 index 7a9065ab5..000000000 --- a/samples/littlevgl/wamr_config_littlevgl.cmake +++ /dev/null @@ -1,9 +0,0 @@ -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET X86_64) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 1) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_SENSOR WAMR_APP_BUILD_CONNECTION) diff --git a/samples/littlevgl/wasm-apps/Makefile_wasm_app b/samples/littlevgl/wasm-apps/Makefile_wasm_app deleted file mode 100644 index 8c053cc6d..000000000 --- a/samples/littlevgl/wasm-apps/Makefile_wasm_app +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CC = /opt/wasi-sdk/bin/clang -LVGL_DIR = ${shell pwd} -SDK_DIR = $(LVGL_DIR)/../../../wamr-sdk/out/littlevgl/app-sdk -APP_FRAMEWORK_DIR = $(SDK_DIR)/wamr-app-framework -LVGL_REPO_PATH=../build/lvgl - -CFLAGS += -O3 \ - -I$(LVGL_DIR) \ - -I$(LVGL_DIR)/../build \ - -I$(LVGL_DIR)/lv_drivers \ - -I$(LVGL_DIR)/src \ - -I$(LVGL_DIR)/../lv_config \ - -I$(APP_FRAMEWORK_DIR)/include - -SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw_line.c ${LVGL_REPO_PATH}/lv_draw/lv_draw_rbasic.c -SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw_img.c ${LVGL_REPO_PATH}/lv_draw/lv_draw_arc.c -SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw_rect.c ${LVGL_REPO_PATH}/lv_draw/lv_draw_triangle.c -SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw.c ${LVGL_REPO_PATH}/lv_draw/lv_draw_label.c -SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw_vbasic.c ${LVGL_REPO_PATH}/lv_fonts/lv_font_builtin.c -SRCS += ${LVGL_REPO_PATH}/lv_fonts/lv_font_dejavu_20.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_img.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_roller.c ${LVGL_REPO_PATH}/lv_objx/lv_cb.c ${LVGL_REPO_PATH}/lv_objx/lv_led.c ${LVGL_REPO_PATH}/lv_objx/lv_cont.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_calendar.c ${LVGL_REPO_PATH}/lv_objx/lv_gauge.c ${LVGL_REPO_PATH}/lv_objx/lv_page.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_list.c ${LVGL_REPO_PATH}/lv_objx/lv_bar.c ${LVGL_REPO_PATH}/lv_objx/lv_tabview.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_mbox.c ${LVGL_REPO_PATH}/lv_objx/lv_objx_templ.c ${LVGL_REPO_PATH}/lv_objx/lv_sw.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_label.c ${LVGL_REPO_PATH}/lv_objx/lv_slider.c ${LVGL_REPO_PATH}/lv_objx/lv_ddlist.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_imgbtn.c ${LVGL_REPO_PATH}/lv_objx/lv_line.c ${LVGL_REPO_PATH}/lv_objx/lv_chart.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_btnm.c ${LVGL_REPO_PATH}/lv_objx/lv_arc.c ${LVGL_REPO_PATH}/lv_objx/lv_preload.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_win.c ${LVGL_REPO_PATH}/lv_objx/lv_lmeter.c ${LVGL_REPO_PATH}/lv_objx/lv_btn.c -SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_ta.c ${LVGL_REPO_PATH}/lv_misc/lv_log.c ${LVGL_REPO_PATH}/lv_misc/lv_fs.c -SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_task.c ${LVGL_REPO_PATH}/lv_misc/lv_circ.c ${LVGL_REPO_PATH}/lv_misc/lv_anim.c -SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_color.c ${LVGL_REPO_PATH}/lv_misc/lv_txt.c ${LVGL_REPO_PATH}/lv_misc/lv_math.c -SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_mem.c ${LVGL_REPO_PATH}/lv_misc/lv_font.c ${LVGL_REPO_PATH}/lv_misc/lv_ll.c -SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_area.c ${LVGL_REPO_PATH}/lv_misc/lv_templ.c ${LVGL_REPO_PATH}/lv_misc/lv_ufs.c -SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_gc.c -SRCS += ${LVGL_REPO_PATH}/lv_hal/lv_hal_tick.c ${LVGL_REPO_PATH}/lv_hal/lv_hal_indev.c ${LVGL_REPO_PATH}/lv_hal/lv_hal_disp.c -SRCS += ${LVGL_REPO_PATH}/lv_themes/lv_theme_mono.c ${LVGL_REPO_PATH}/lv_themes/lv_theme_templ.c -SRCS += ${LVGL_REPO_PATH}/lv_themes/lv_theme_material.c ${LVGL_REPO_PATH}/lv_themes/lv_theme.c -SRCS += ${LVGL_REPO_PATH}/lv_themes/lv_theme_night.c ${LVGL_REPO_PATH}/lv_themes/lv_theme_zen.c ${LVGL_REPO_PATH}/lv_themes/lv_theme_nemo.c -SRCS += ${LVGL_REPO_PATH}/lv_themes/lv_theme_alien.c ${LVGL_REPO_PATH}/lv_themes/lv_theme_default.c -SRCS += ${LVGL_REPO_PATH}/lv_core/lv_group.c ${LVGL_REPO_PATH}/lv_core/lv_style.c ${LVGL_REPO_PATH}/lv_core/lv_indev.c -SRCS += ${LVGL_REPO_PATH}/lv_core/lv_vdb.c ${LVGL_REPO_PATH}/lv_core/lv_obj.c ${LVGL_REPO_PATH}/lv_core/lv_refr.c -SRCS += $(LVGL_DIR)/src/main.c - -all: - @$(CC) $(CFLAGS) $(SRCS) \ - -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \ - -DLV_CONF_INCLUDE_SIMPLE \ - -L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \ - -Wl,--allow-undefined \ - -Wl,--strip-all,--no-entry \ - -Wl,--export=on_init -Wl,--export=on_timer_callback \ - -Wl,--export=__heap_base,--export=__data_end \ - -o ui_app_wasi.wasm diff --git a/samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi b/samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi deleted file mode 100644 index d18c0a222..000000000 --- a/samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CC = /opt/wasi-sdk/bin/clang -LVGL_DIR = ${shell pwd} -WAMR_DIR = ${LVGL_DIR}/../../.. -SDK_DIR = $(LVGL_DIR)/../../../wamr-sdk/out/littlevgl/app-sdk -APP_FRAMEWORK_DIR = $(SDK_DIR)/wamr-app-framework -LVGL_REPO_PATH=../build/lvgl - -CFLAGS += -O3 \ - -I$(LVGL_DIR) \ - -I$(LVGL_DIR)/../build \ - -I$(LVGL_DIR)/lv_drivers \ - -I$(LVGL_DIR)/src \ - -I$(LVGL_DIR)/../lv_config \ - -I$(APP_FRAMEWORK_DIR)/include - -SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw_line.c $(LVGL_REPO_PATH)/lv_draw/lv_draw_rbasic.c -SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw_img.c $(LVGL_REPO_PATH)/lv_draw/lv_draw_arc.c -SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw_rect.c $(LVGL_REPO_PATH)/lv_draw/lv_draw_triangle.c -SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw.c $(LVGL_REPO_PATH)/lv_draw/lv_draw_label.c -SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw_vbasic.c $(LVGL_REPO_PATH)/lv_fonts/lv_font_builtin.c -SRCS += $(LVGL_REPO_PATH)/lv_fonts/lv_font_dejavu_20.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_img.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_roller.c $(LVGL_REPO_PATH)/lv_objx/lv_cb.c $(LVGL_REPO_PATH)/lv_objx/lv_led.c $(LVGL_REPO_PATH)/lv_objx/lv_cont.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_calendar.c $(LVGL_REPO_PATH)/lv_objx/lv_gauge.c $(LVGL_REPO_PATH)/lv_objx/lv_page.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_list.c $(LVGL_REPO_PATH)/lv_objx/lv_bar.c $(LVGL_REPO_PATH)/lv_objx/lv_tabview.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_mbox.c $(LVGL_REPO_PATH)/lv_objx/lv_objx_templ.c $(LVGL_REPO_PATH)/lv_objx/lv_sw.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_label.c $(LVGL_REPO_PATH)/lv_objx/lv_slider.c $(LVGL_REPO_PATH)/lv_objx/lv_ddlist.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_imgbtn.c $(LVGL_REPO_PATH)/lv_objx/lv_line.c $(LVGL_REPO_PATH)/lv_objx/lv_chart.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_btnm.c $(LVGL_REPO_PATH)/lv_objx/lv_arc.c $(LVGL_REPO_PATH)/lv_objx/lv_preload.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_win.c $(LVGL_REPO_PATH)/lv_objx/lv_lmeter.c $(LVGL_REPO_PATH)/lv_objx/lv_btn.c -SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_ta.c $(LVGL_REPO_PATH)/lv_misc/lv_log.c $(LVGL_REPO_PATH)/lv_misc/lv_fs.c -SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_task.c $(LVGL_REPO_PATH)/lv_misc/lv_circ.c $(LVGL_REPO_PATH)/lv_misc/lv_anim.c -SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_color.c $(LVGL_REPO_PATH)/lv_misc/lv_txt.c $(LVGL_REPO_PATH)/lv_misc/lv_math.c -SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_mem.c $(LVGL_REPO_PATH)/lv_misc/lv_font.c $(LVGL_REPO_PATH)/lv_misc/lv_ll.c -SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_area.c $(LVGL_REPO_PATH)/lv_misc/lv_templ.c $(LVGL_REPO_PATH)/lv_misc/lv_ufs.c -SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_gc.c -SRCS += $(LVGL_REPO_PATH)/lv_hal/lv_hal_tick.c $(LVGL_REPO_PATH)/lv_hal/lv_hal_indev.c $(LVGL_REPO_PATH)/lv_hal/lv_hal_disp.c -SRCS += $(LVGL_REPO_PATH)/lv_themes/lv_theme_mono.c $(LVGL_REPO_PATH)/lv_themes/lv_theme_templ.c -SRCS += $(LVGL_REPO_PATH)/lv_themes/lv_theme_material.c $(LVGL_REPO_PATH)/lv_themes/lv_theme.c -SRCS += $(LVGL_REPO_PATH)/lv_themes/lv_theme_night.c $(LVGL_REPO_PATH)/lv_themes/lv_theme_zen.c $(LVGL_REPO_PATH)/lv_themes/lv_theme_nemo.c -SRCS += $(LVGL_REPO_PATH)/lv_themes/lv_theme_alien.c $(LVGL_REPO_PATH)/lv_themes/lv_theme_default.c -SRCS += $(LVGL_REPO_PATH)/lv_core/lv_group.c $(LVGL_REPO_PATH)/lv_core/lv_style.c $(LVGL_REPO_PATH)/lv_core/lv_indev.c -SRCS += $(LVGL_REPO_PATH)/lv_core/lv_vdb.c $(LVGL_REPO_PATH)/lv_core/lv_obj.c $(LVGL_REPO_PATH)/lv_core/lv_refr.c -SRCS += $(LVGL_DIR)/src/main.c - -all: - @$(CC) $(CFLAGS) $(SRCS) \ - --target=wasm32 -Wl,--allow-undefined \ - --sysroot=$(WAMR_DIR)/wamr-sdk/app/libc-builtin-sysroot \ - -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \ - -DLV_CONF_INCLUDE_SIMPLE \ - -L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \ - -Wl,--allow-undefined \ - -Wl,--strip-all,--no-entry -nostdlib \ - -Wl,--export=on_init -Wl,--export=on_timer_callback \ - -o ui_app_builtin_libc.wasm diff --git a/samples/littlevgl/wasm-apps/build_wasm_app.sh b/samples/littlevgl/wasm-apps/build_wasm_app.sh deleted file mode 100755 index a86784e2a..000000000 --- a/samples/littlevgl/wasm-apps/build_wasm_app.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -WAMR_DIR=${PWD}/../../.. - -if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then - echo "Local Build Env" - makewrap="make" -else - echo "Klocwork Build Env" - makewrap="kwinject -o $KW_OUT_FILE make" -fi - -echo "make Makefile_wasm_app" -$makewrap -f Makefile_wasm_app - -echo "make Makefile_wasm_app_no_wasi" -$makewrap -f Makefile_wasm_app_no_wasi - -echo "completed." \ No newline at end of file diff --git a/samples/littlevgl/wasm-apps/src/display_indev.h b/samples/littlevgl/wasm-apps/src/display_indev.h deleted file mode 100644 index 9285699b6..000000000 --- a/samples/littlevgl/wasm-apps/src/display_indev.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef DISPLAY_INDEV_H_ -#define DISPLAY_INDEV_H_ -#include -#include - -#include "lvgl/lv_misc/lv_color.h" -#include "lvgl/lv_hal/lv_hal_indev.h" - -extern void -display_init(void); - -extern void -display_deinit(void); - -extern void -display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color); - -extern bool -display_input_read(lv_indev_data_t *data); - -extern void -display_vdb_write(void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t *color, lv_opa_t opa); - -void -display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color); - -void -display_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color); - -extern uint32_t -time_get_ms(void); - -#endif diff --git a/samples/littlevgl/wasm-apps/src/main.c b/samples/littlevgl/wasm-apps/src/main.c deleted file mode 100644 index 8676d41b5..000000000 --- a/samples/littlevgl/wasm-apps/src/main.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -/** - * @file main - * - */ - -/********************* - * INCLUDES - *********************/ -#include -//#include -#include -#include "lvgl/lvgl.h" -#include "display_indev.h" -#include "wasm_app.h" -#include "wa-inc/timer_wasm_app.h" -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static void -hal_init(void); -// static int tick_thread(void * data); -// static void memory_monitor(void * param); - -/********************** - * STATIC VARIABLES - **********************/ - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ -uint32_t count = 0; -char count_str[11] = { 0 }; -lv_obj_t *hello_world_label; -lv_obj_t *count_label; -lv_obj_t *btn1; - -lv_obj_t *label_count1; -int label_count1_value = 0; -char label_count1_str[11] = { 0 }; - -void -timer1_update(user_timer_t timer1) -{ - if ((count % 100) == 0) { - snprintf(count_str, sizeof(count_str), "%d", count / 100); - lv_label_set_text(count_label, count_str); - } - lv_task_handler(); - ++count; -} - -static lv_res_t -btn_rel_action(lv_obj_t *btn) -{ - label_count1_value++; - snprintf(label_count1_str, sizeof(label_count1_str), "%d", - label_count1_value); - lv_label_set_text(label_count1, label_count1_str); - return LV_RES_OK; -} - -void -on_init() -{ - /* Initialize LittlevGL */ - lv_init(); - - /* Initialize the HAL (display, input devices, tick) for LittlevGL */ - hal_init(); - - hello_world_label = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text(hello_world_label, "Hello world!"); - lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - - count_label = lv_label_create(lv_scr_act(), NULL); - lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); - - btn1 = lv_btn_create( - lv_scr_act(), - NULL); /* Create a button on the currently loaded screen */ - lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, - btn_rel_action); /* Set function to be called when the - button is released */ - lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, - 20); /* Align below the label */ - - /* Create a label on the button */ - lv_obj_t *btn_label = lv_label_create(btn1, NULL); - lv_label_set_text(btn_label, "Click ++"); - - label_count1 = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text(label_count1, "0"); - lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - - /* set up a timer */ - user_timer_t timer; - timer = api_timer_create(10, true, false, timer1_update); - if (timer) - api_timer_restart(timer, 10); - else - printf("Fail to create timer.\n"); -} - -/********************** - * STATIC FUNCTIONS - **********************/ - -/** - * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics - * library - */ -void -display_flush_wrapper(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - const lv_color_t *color_p) -{ - display_flush(x1, y1, x2, y2, color_p); - lv_flush_ready(); -} - -void -display_vdb_write_wrapper(uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, - lv_coord_t y, lv_color_t color, lv_opa_t opa) -{ - display_vdb_write(buf, buf_w, x, y, &color, opa); -} - -void -display_fill_wrapper(int32_t x1, int32_t y1, int32_t x2, int32_t y2, - lv_color_t color) -{ - display_fill(x1, y1, x2, y2, &color); -} - -static void -hal_init(void) -{ - /* Add a display */ - lv_disp_drv_t disp_drv; - lv_disp_drv_init(&disp_drv); /* Basic initialization */ - disp_drv.disp_flush = - display_flush_wrapper; /* Used when `LV_VDB_SIZE != 0` in lv_conf.h - (buffered drawing) */ - disp_drv.disp_fill = - display_fill_wrapper; /* Used when `LV_VDB_SIZE == 0` in lv_conf.h - (unbuffered drawing) */ - disp_drv.disp_map = display_map; /* Used when `LV_VDB_SIZE == 0` in - lv_conf.h (unbuffered drawing) */ -#if LV_VDB_SIZE != 0 - disp_drv.vdb_wr = display_vdb_write_wrapper; -#endif - lv_disp_drv_register(&disp_drv); - - /* Add the mouse as input device - * Use the 'mouse' driver which reads the PC's mouse */ - // mouse_init(); - lv_indev_drv_t indev_drv; - lv_indev_drv_init(&indev_drv); /* Basic initialization */ - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read = - display_input_read; /* This function will be called periodically (by the - library) to get the mouse position and state */ - lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv); -} - -/* Implement empry main function as wasi start function calls it */ -int -main(int argc, char **argv) -{ - (void)argc; - (void)argv; - return 0; -} diff --git a/samples/littlevgl/wasm-apps/src/system_header.h b/samples/littlevgl/wasm-apps/src/system_header.h deleted file mode 100644 index 59fd59aeb..000000000 --- a/samples/littlevgl/wasm-apps/src/system_header.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include - -uint32_t -time_get_ms(void); diff --git a/samples/simple/.gitignore b/samples/simple/.gitignore deleted file mode 100644 index e2e7327cd..000000000 --- a/samples/simple/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/out diff --git a/samples/simple/CMakeLists.txt b/samples/simple/CMakeLists.txt deleted file mode 100644 index f3a0848fe..000000000 --- a/samples/simple/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required (VERSION 2.9) - -project (simple) - -################ wamr runtime settings ################ -message(STATUS "WAMR_BUILD_SDK_PROFILE=${WAMR_BUILD_SDK_PROFILE}") - -# Reset default linker flags -set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") -set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") - -if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") -endif () - -set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) - -## use library and headers in the SDK -link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/${WAMR_BUILD_SDK_PROFILE}/runtime-sdk/lib) -include_directories( - ${WAMR_ROOT_DIR}/wamr-sdk/out/${WAMR_BUILD_SDK_PROFILE}/runtime-sdk/include - ${WAMR_ROOT_DIR}/core/shared/utils - ${WAMR_ROOT_DIR}/core/shared/platform/linux -) - -################ application related ################ - -include_directories(${CMAKE_CURRENT_LIST_DIR}/src) - -#Note: uncomment below line to use UART mode -#add_definitions (-DCONNECTION_UART) - -add_executable (simple src/main.c src/iwasm_main.c) -target_link_libraries (simple vmlib -lm -ldl -lpthread -lrt) - - diff --git a/samples/simple/README.md b/samples/simple/README.md deleted file mode 100644 index 5625212f9..000000000 --- a/samples/simple/README.md +++ /dev/null @@ -1,342 +0,0 @@ - - -"simple" sample introduction -============== - -This sample demonstrates following scenarios: - -- Use tool "host_tool" to remotely install/uninstall wasm applications from the WAMR runtime over either TCP socket or UART cable -- Inter-app communication programming models -- Communication between WASM applications and the remote app host_tool -- A number of WASM applications built on top of WAMR application framework API sets - - - -Directory structure ------------------------------- -``` -simple/ -├── build.sh -├── CMakeLists.txt -├── README.md -├── src -│   ├── ext_lib_export.c -│   ├── iwasm_main.c -│   └── main.c -└── wasm-apps - ├── connection.c - ├── event_publisher.c - ├── event_subscriber.c - ├── request_handler.c - ├── request_sender.c - ├── sensor.c - └── timer.c -``` - -- src/ext_lib_export.c
- This file is used to export native APIs. See the `The mechanism of exporting Native API to WASM application` section in WAMR README.md for detail. -- src/iwam_main.c
- This file is the implementation by platform integrator. It implements the interfaces that enable the application manager communicating with the host side. See `{WAMR_ROOT}/core/app-mgr/app-mgr-shared/app_manager_export.h` for the definition of the host interface. -## Set physical communication between device and remote - - - -``` -/* Interfaces of host communication */ -typedef struct host_interface { - host_init_func init; - host_send_fun send; - host_destroy_fun destroy; -} host_interface; - -``` -The `host_init_func` is called when the application manager starts up. And `host_send_fun` is called by the application manager to send data to the host. - -Define a global variable "interface" of the data structure: - -``` - -host_interface interface = { - .init = host_init, - .send = host_send, - .destroy = host_destroy -}; -``` -This interface is passed to application manager during the runtime startup: -``` -app_manager_startup(&interface); -``` - -> - -**Note:** The connection between simple and host_tool is TCP by default. The simple application works as a server and the host_tool works as a client. You can also use UART connection. To achieve this you have to uncomment the below line in CMakeLists.txt and rebuild. - -``` -#add_definitions (-DCONNECTION_UART)` -``` - -To run the UART based test, you have to set up a UART hardware connection between host_tool and the simple application. See the help of host_tool for how to specify UART device parameters. - - -Build the sample -============== -Execute the build.sh script then all binaries including wasm application files would be generated in 'out' directory. - -``` -$ ./build.sh -Enter build target profile (default=host-interp) --> -arm-interp -host-aot -host-interp -\>: - -``` - -Enter the profile name for starting your build. "host-***" profiles build the sample for executing on your development machine, and "arm-interp" profile will do cross building for ARM target platform. If "arm-interp" is entered, please ensure the ARM cross compiler toolchain is already installed in your development machine. Your should set *ARM_A7_COMPILER_DIR* and *ARM_A7_SDKTARGETSYSROOT* environment variable in your ~/.bashrc correctly. refer to the file [profiles/arm-interp/toolchain.cmake](./profiles/arm-interp/toolchain.cmake). - -``` -~/.bashrc: -export ARM_A7_COMPILER_DIR="/home/beihai/cross-toolchains/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin" -export ARM_A7_SDKTARGETSYSROOT="/home/beihai/cross-toolchains/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/arm-linux-gnueabihf/libc" - -notes: please set the value to the actual path of your cross toolchain. -``` - -If you need to create additional profile for customizing your runtime, application framework or the target platforms, a new subfolder can be created under the *profiles* folder, and place your own version of "toolchain.cmake" and "wamr_config_simple.cmake" in it. - -``` -$wamr-root/samples/simple/profiles$ ls -arm-interp host-aot host-interp -$wamr-root/samples/simple/profiles$ ls arm-interp/ -toolchain.cmake wamr_config_simple.cmake - -``` - - - - - -**Out directory structure** - -``` -out/ -├── host_tool -├── simple -└── wasm-apps - ├── connection.wasm - ├── event_publisher.wasm - ├── event_subscriber.wasm - ├── request_handler.wasm - ├── request_sender.wasm - ├── sensor.wasm - └── timer.wasm -``` - -- host_tool: - A small testing tool to interact with WAMR. See the usage of this tool by executing "./host_tool -h". - `./host_tool -h` - -- simple: - A simple testing tool running on the host side that interact with WAMR. It is used to install, uninstall and query WASM applications in WAMR, and send request or subscribe event, etc. See the usage of this application by executing "./simple -h". - `./simple -h` -> - -Run the sample -========================== -- Enter the out directory -``` -$ cd ./out/ -``` - -- Startup the 'simple' process works in TCP server mode and you would see "App Manager started." is printed. -``` -$ ./simple -s -App Manager started. -``` - -- Query all installed applications -``` -$ ./host_tool -q - -response status 69 -{ - "num": 0 -} -``` - -The `69` stands for response code SUCCESS. The payload is printed with JSON format where the `num` stands for application installations number and value `0` means currently no application is installed yet. - -- Install the request handler wasm application
-``` -$ ./host_tool -i request_handler -f ./wasm-apps/request_handler.wasm - -response status 65 -``` -Now the request handler application is running and waiting for host or other wasm application to send a request. - -- Query again -``` -$ ./host_tool -q - -response status 69 -{ - "num": 1, - "applet1": "request_handler", - "heap1": 49152 -} -``` -In the payload, we can see `num` is 1 which means 1 application is installed. `applet1`stands for the name of the 1st application. `heap1` stands for the heap size of the 1st application. - -- Send request from host to specific wasm application -``` -$ ./host_tool -r /app/request_handler/url1 -A GET - -response status 69 -{ - "key1": "value1", - "key2": "value2" -} -``` - -We can see a response with status `69` and a payload is received. - -Output of simple application: -``` -connection established! -Send request to applet: request_handler -Send request to app request_handler success. -App request_handler got request, url url1, action 1 -[resp] ### user resource 1 handler called -sent 150 bytes to host -Wasm app process request success. -``` - -- Send a general request from host (not specify target application name)
-``` -$ ./host_tool -r /url1 -A GET - -response status 69 -{ - "key1": "value1", - "key2": "value2" -} -``` - -Output of simple application: -``` -connection established! -Send request to app request_handler success. -App request_handler got request, url /url1, action 1 -[resp] ### user resource 1 handler called -sent 150 bytes to host -Wasm app process request success. -``` - -- Install the event publisher wasm application -``` -$ ./host_tool -i pub -f ./wasm-apps/event_publisher.wasm - -response status 65 -``` - -- Subscribe event by host_tool
-``` -$ ./host_tool -s /alert/overheat -a 3000 - -response status 69 - -received an event alert/overheat -{ - "warning": "temperature is over high" -} -received an event alert/overheat -{ - "warning": "temperature is over high" -} -received an event alert/overheat -{ - "warning": "temperature is over high" -} -received an event alert/overheat -{ - "warning": "temperature is over high" -} -``` -We can see 4 `alert/overheat` events are received in 3 seconds which is published by the `pub` application. - -Output of simple -``` -connection established! -am_register_event adding url:(alert/overheat) -client: -3 registered event (alert/overheat) -sent 16 bytes to host -sent 142 bytes to host -sent 142 bytes to host -sent 142 bytes to host -sent 142 bytes to host -``` -- Install the event subscriber wasm application
-``` -$ ./host_tool -i sub -f ./wasm-apps/event_subscriber.wasm - -response status 65 -``` -The `sub` application is installed. - -Output of simple -``` -connection established! -Install WASM app success! -WASM app 'sub' started -am_register_event adding url:(alert/overheat) -client: 3 registered event (alert/overheat) -sent 16 bytes to host -Send request to app sub success. -App sub got request, url alert/overheat, action 6 -### user over heat event handler called -Attribute container dump: -Tag: -Attribute list: - key: warning, type: string, value: temperature is over high - -Wasm app process request success. -``` - -We can see the `sub` application receives the `alert/overheat` event and dumps it out.
-At device side, the event is represented by an attribute container which contains key-value pairs like below: -``` -Attribute container dump: -Tag: -Attribute list: - key: warning, type: string, value: temperature is over high -``` -`warning` is the key's name. `string` means this is a string value and `temperature is over high` is the value. - -- Uninstall the wasm application
-``` -$ ./host_tool -u request_handler - -response status 66 - -$ ./host_tool -u pub - -response status 66 - -$ ./host_tool -u sub - -response status 66 -``` - -- Query again
-``` -$ ./host_tool -q - -response status 69 -{ - "num": 0 -} -``` - - >**Note:** Here we only installed part of the sample WASM applications. You can try others by yourself. - - >**Note:** You have to manually kill the simple process by Ctrl+C after use. diff --git a/samples/simple/build.sh b/samples/simple/build.sh deleted file mode 100755 index 9d9d1874d..000000000 --- a/samples/simple/build.sh +++ /dev/null @@ -1,166 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -#!/bin/bash - -CURR_DIR=$PWD -WAMR_DIR=${PWD}/../.. -OUT_DIR=${PWD}/out -BUILD_DIR=${PWD}/build - -IWASM_ROOT=${PWD}/../../core/iwasm -APP_FRAMEWORK_DIR=${PWD}/../../core/app-framework -NATIVE_LIBS=${APP_FRAMEWORK_DIR}/app-native-shared -APP_LIB_SRC="${APP_FRAMEWORK_DIR}/base/app/*.c ${APP_FRAMEWORK_DIR}/sensor/app/*.c \ - ${APP_FRAMEWORK_DIR}/connection/app/*.c ${NATIVE_LIBS}/*.c" -WASM_APPS=${PWD}/wasm-apps -CLEAN= -CM_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Debug" -CM_TOOLCHAIN="" - -usage () -{ - echo "build.sh [options]" - echo " -p [profile]" - echo " -d [target]" - echo " -c, rebuild SDK" - exit 1 -} - - -while getopts "p:dch" opt -do - case $opt in - p) - PROFILE=$OPTARG - ;; - d) - CM_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Debug" - ;; - c) - CLEAN="TRUE" - ;; - h) - usage - exit 1; - ;; - ?) - echo "Unknown arg: $arg" - usage - exit 1 - ;; - esac -done - - -if [ "$CLEAN" = "TRUE" ]; then - rm -rf $CURR_DIR/cmake-build -fi - - -while [ ! -n "$PROFILE" ] -do - support_profiles=`ls -l "profiles/" |grep '^d' | awk '{print $9}'` - read -p "Enter build target profile (default=host-interp) --> -$support_profiles -\>:" read_platform - if [ ! -n "$read_platform" ]; then - PROFILE="host-interp" - else - PROFILE=$read_platform - fi -done - -ARG_TOOLCHAIN="" -TOOL_CHAIN_FILE=$CURR_DIR/profiles/$PROFILE/toolchain.cmake -if [ -f $TOOL_CHAIN_FILE ]; then - CM_TOOLCHAIN="-DCMAKE_TOOLCHAIN_FILE=$TOOL_CHAIN_FILE" - ARG_TOOLCHAIN="-t $TOOL_CHAIN_FILE" - echo "toolchain file: $TOOL_CHAIN_FILE" -fi - - -SDK_CONFIG_FILE=$CURR_DIR/profiles/$PROFILE/wamr_config_simple.cmake -if [ ! -f $SDK_CONFIG_FILE ]; then - echo "SDK config file [$SDK_CONFIG_FILE] doesn't exit. quit.." - exit 1 -fi - - - -rm -rf ${OUT_DIR} -mkdir ${OUT_DIR} -mkdir ${OUT_DIR}/wasm-apps - -cd ${WAMR_DIR}/core/shared/mem-alloc - -PROFILE="simple-$PROFILE" - - -echo "#####################build wamr sdk" -cd ${WAMR_DIR}/wamr-sdk -./build_sdk.sh -n $PROFILE -x $SDK_CONFIG_FILE $ARG_TOOLCHAIN -[ $? -eq 0 ] || exit $? - - -echo "#####################build simple project" -cd ${CURR_DIR} -mkdir -p cmake-build/$PROFILE -cd cmake-build/$PROFILE -cmake ../.. -DWAMR_BUILD_SDK_PROFILE=$PROFILE $CM_TOOLCHAIN $CM_BUILD_TYPE -make -if [ $? != 0 ];then - echo "BUILD_FAIL simple exit as $?\n" - exit 2 -fi -cp -a simple ${OUT_DIR} -echo "#####################build simple project success" - -echo -e "\n\n" -echo "#####################build host-tool" -cd ${WAMR_DIR}/test-tools/host-tool -mkdir -p bin -cd bin -cmake .. $CM_TOOLCHAIN $CM_BUILD_TYPE -make -if [ $? != 0 ];then - echo "BUILD_FAIL host tool exit as $?\n" - exit 2 -fi -cp host_tool ${OUT_DIR} -echo "#####################build host-tool success" - -echo -e "\n\n" -echo "#####################build wasm apps" - -cd ${WASM_APPS} - -for i in `ls *.c` -do -APP_SRC="$i" -OUT_FILE=${i%.*}.wasm - -/opt/wasi-sdk/bin/clang \ - -I${WAMR_DIR}/wamr-sdk/out/$PROFILE/app-sdk/wamr-app-framework/include \ - -L${WAMR_DIR}/wamr-sdk/out/$PROFILE/app-sdk/wamr-app-framework/lib \ - -lapp_framework \ - --target=wasm32 -O3 -z stack-size=4096 -Wl,--initial-memory=65536 \ - --sysroot=${WAMR_DIR}/wamr-sdk/out/$PROFILE/app-sdk/libc-builtin-sysroot \ - -Wl,--allow-undefined-file=${WAMR_DIR}/wamr-sdk/out/$PROFILE/app-sdk/libc-builtin-sysroot/share/defined-symbols.txt \ - -Wl,--strip-all,--no-entry -nostdlib \ - -Wl,--export=on_init -Wl,--export=on_destroy \ - -Wl,--export=on_request -Wl,--export=on_response \ - -Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \ - -Wl,--export=on_connection_data \ - -Wl,--export=__heap_base -Wl,--export=__data_end \ - -o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC} -if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then - echo "build ${OUT_FILE} success" -else - echo "build ${OUT_FILE} fail" -fi -done - -echo "#####################build wasm apps done" diff --git a/samples/simple/profiles/arm-interp/toolchain.cmake b/samples/simple/profiles/arm-interp/toolchain.cmake deleted file mode 100644 index 604141d0a..000000000 --- a/samples/simple/profiles/arm-interp/toolchain.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -INCLUDE(CMakeForceCompiler) - -SET(CMAKE_SYSTEM_NAME Linux) # this one is important -SET(CMAKE_SYSTEM_VERSION 1) # this one not so much - -message(STATUS "*** ARM A7 toolchain file ***") -set(CMAKE_VERBOSE_MAKEFILE ON) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE") - - -if (NOT $ENV{ARM_A7_COMPILER_DIR} STREQUAL "") - SET (toolchain_sdk_dir $ENV{ARM_A7_COMPILER_DIR}/) -endif () - -if (NOT $ENV{ARM_A7_SDKTARGETSYSROOT} STREQUAL "") - SET(SDKTARGETSYSROOT $ENV{ARM_A7_SDKTARGETSYSROOT}) - #SET(CMAKE_SYSROOT SDKTARGETSYSROOT) -endif () - -message(STATUS "SDKTARGETSYSROOT=${SDKTARGETSYSROOT}") -message(STATUS "toolchain_sdk_dir=${toolchain_sdk_dir}") - -SET(CMAKE_C_COMPILER ${toolchain_sdk_dir}arm-linux-gnueabihf-gcc) -SET(CMAKE_CXX_COMPILER ${toolchain_sdk_dir}arm-linux-gnueabihf-g++) - - -# this is the file system root of the target -SET(CMAKE_FIND_ROOT_PATH ${SDKTARGETSYSROOT}) - -# search for programs in the build host directories -SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - -# for libraries and headers in the target directories -SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - diff --git a/samples/simple/profiles/arm-interp/wamr_config_simple.cmake b/samples/simple/profiles/arm-interp/wamr_config_simple.cmake deleted file mode 100644 index 90bb2f8d1..000000000 --- a/samples/simple/profiles/arm-interp/wamr_config_simple.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET ARM) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 0) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR) diff --git a/samples/simple/profiles/arm64-aot/toolchain.cmake b/samples/simple/profiles/arm64-aot/toolchain.cmake deleted file mode 100644 index 182504fea..000000000 --- a/samples/simple/profiles/arm64-aot/toolchain.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -INCLUDE(CMakeForceCompiler) - -SET(CMAKE_SYSTEM_NAME Linux) # this one is important -SET(CMAKE_SYSTEM_VERSION 1) # this one not so much - -message(STATUS "*** ARM A7 toolchain file ***") -set(CMAKE_VERBOSE_MAKEFILE ON) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE") - - -if (NOT $ENV{ARM_A7_COMPILER_DIR} STREQUAL "") - SET (toolchain_sdk_dir $ENV{ARM_A7_COMPILER_DIR}/) -endif () - -if (NOT $ENV{ARM_A7_SDKTARGETSYSROOT} STREQUAL "") - SET(SDKTARGETSYSROOT $ENV{ARM_A7_SDKTARGETSYSROOT}) -endif () - -message(STATUS "SDKTARGETSYSROOT=${SDKTARGETSYSROOT}") -message(STATUS "toolchain_sdk_dir=${toolchain_sdk_dir}") - -SET(CMAKE_C_COMPILER ${toolchain_sdk_dir}aarch64-linux-gnu-gcc) -SET(CMAKE_CXX_COMPILER ${toolchain_sdk_dir}aarch64-linux-gnu-g++) - - -# this is the file system root of the target -SET(CMAKE_FIND_ROOT_PATH ${SDKTARGETSYSROOT}) - -# search for programs in the build host directories -SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - -# for libraries and headers in the target directories -SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/samples/simple/profiles/arm64-aot/wamr_config_simple.cmake b/samples/simple/profiles/arm64-aot/wamr_config_simple.cmake deleted file mode 100644 index 7e6604885..000000000 --- a/samples/simple/profiles/arm64-aot/wamr_config_simple.cmake +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET AARCH64) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_SIMD 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR) diff --git a/samples/simple/profiles/arm64-interp/toolchain.cmake b/samples/simple/profiles/arm64-interp/toolchain.cmake deleted file mode 100644 index 182504fea..000000000 --- a/samples/simple/profiles/arm64-interp/toolchain.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -INCLUDE(CMakeForceCompiler) - -SET(CMAKE_SYSTEM_NAME Linux) # this one is important -SET(CMAKE_SYSTEM_VERSION 1) # this one not so much - -message(STATUS "*** ARM A7 toolchain file ***") -set(CMAKE_VERBOSE_MAKEFILE ON) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE") - - -if (NOT $ENV{ARM_A7_COMPILER_DIR} STREQUAL "") - SET (toolchain_sdk_dir $ENV{ARM_A7_COMPILER_DIR}/) -endif () - -if (NOT $ENV{ARM_A7_SDKTARGETSYSROOT} STREQUAL "") - SET(SDKTARGETSYSROOT $ENV{ARM_A7_SDKTARGETSYSROOT}) -endif () - -message(STATUS "SDKTARGETSYSROOT=${SDKTARGETSYSROOT}") -message(STATUS "toolchain_sdk_dir=${toolchain_sdk_dir}") - -SET(CMAKE_C_COMPILER ${toolchain_sdk_dir}aarch64-linux-gnu-gcc) -SET(CMAKE_CXX_COMPILER ${toolchain_sdk_dir}aarch64-linux-gnu-g++) - - -# this is the file system root of the target -SET(CMAKE_FIND_ROOT_PATH ${SDKTARGETSYSROOT}) - -# search for programs in the build host directories -SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - -# for libraries and headers in the target directories -SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/samples/simple/profiles/arm64-interp/wamr_config_simple.cmake b/samples/simple/profiles/arm64-interp/wamr_config_simple.cmake deleted file mode 100644 index 13fb9ac13..000000000 --- a/samples/simple/profiles/arm64-interp/wamr_config_simple.cmake +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET AARCH64) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 0) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_SIMD 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR) diff --git a/samples/simple/profiles/host-aot/wamr_config_simple.cmake b/samples/simple/profiles/host-aot/wamr_config_simple.cmake deleted file mode 100644 index 1f8cf9f8f..000000000 --- a/samples/simple/profiles/host-aot/wamr_config_simple.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET X86_64) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR) diff --git a/samples/simple/profiles/host-interp/wamr_config_simple.cmake b/samples/simple/profiles/host-interp/wamr_config_simple.cmake deleted file mode 100644 index 1f8cf9f8f..000000000 --- a/samples/simple/profiles/host-interp/wamr_config_simple.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET X86_64) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR) diff --git a/samples/simple/profiles/macos-interp/wamr_config_simple.cmake b/samples/simple/profiles/macos-interp/wamr_config_simple.cmake deleted file mode 100644 index d13c06d97..000000000 --- a/samples/simple/profiles/macos-interp/wamr_config_simple.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set (WAMR_BUILD_PLATFORM "darwin") -set (WAMR_BUILD_TARGET X86_64) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR) diff --git a/samples/simple/sample_test_run.py b/samples/simple/sample_test_run.py deleted file mode 100755 index 09c36db5e..000000000 --- a/samples/simple/sample_test_run.py +++ /dev/null @@ -1,224 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import argparse -import shlex -import subprocess -import sys -import time -import traceback -import glob - -WAMRC_CMD = "../../wamr-compiler/build/wamrc" - -def compile_wasm_files_to_aot(wasm_apps_dir): - wasm_files = glob.glob(wasm_apps_dir + "/*.wasm") - print("Compile wasm app into aot files") - for wasm_file in wasm_files: - aot_file = wasm_file[0 : len(wasm_file) - 5] + ".aot"; - cmd = [ WAMRC_CMD, "-o", aot_file, wasm_file ] - subprocess.check_call(cmd) - -def start_server(cwd): - """ - Startup the 'simple' process works in TCP server mode - """ - app_server = subprocess.Popen(shlex.split("./simple -s "), cwd=cwd) - return app_server - - -def query_installed_application(cwd): - """ - Query all installed applications - """ - qry_prc = subprocess.run( - shlex.split("./host_tool -q"), cwd=cwd, check=False, capture_output=True - ) - assert qry_prc.returncode == 69 - return qry_prc.returncode, qry_prc.stdout - - -def install_wasm_application(wasm_name, wasm_file, cwd): - """ - Install a wasm application - """ - inst_prc = subprocess.run( - shlex.split(f"./host_tool -i {wasm_name} -f {wasm_file}"), - cwd=cwd, - check=False, - capture_output=True, - ) - assert inst_prc.returncode == 65 - return inst_prc.returncode, inst_prc.stdout - - -def uninstall_wasm_application(wasm_name, cwd): - """ - Uninstall a wasm application - """ - - unst_prc = subprocess.run( - shlex.split(f"./host_tool -u {wasm_name}"), - cwd=cwd, - check=False, - capture_output=True, - ) - assert unst_prc.returncode == 66 - return unst_prc.returncode, unst_prc.stdout - - -def send_get_to_wasm_application(wasm_name, url, cwd): - """ - send a request (GET) from host to an applicaton - """ - qry_prc = subprocess.run( - shlex.split(f"./host_tool -r /app/{wasm_name}{url} -A GET"), - cwd=cwd, - check=False, - capture_output=True, - ) - assert qry_prc.returncode == 69 - return qry_prc.returncode, qry_prc.stdout - - -def main(): - """ - GO!GO!!GO!!! - """ - parser = argparse.ArgumentParser(description="run the sample and examine outputs") - parser.add_argument("working_directory", type=str) - parser.add_argument("--aot", action='store_true', help="Test with AOT") - args = parser.parse_args() - - test_aot = False - suffix = ".wasm" - if not args.aot: - print("Test with interpreter mode") - else: - print("Test with AOT mode") - test_aot = True - suffix = ".aot" - wasm_apps_dir = args.working_directory + "/wasm-apps" - compile_wasm_files_to_aot(wasm_apps_dir) - - ret = 1 - app_server = None - try: - app_server = start_server(args.working_directory) - - # wait for a second - time.sleep(1) - - print("--> Install timer" + suffix + "...") - install_wasm_application( - "timer", "./wasm-apps/timer" + suffix, args.working_directory - ) - - # wait for a second - time.sleep(3) - - print("--> Query all installed applications...") - query_installed_application(args.working_directory) - - print("--> Install event_publisher" + suffix + "...") - install_wasm_application( - "event_publisher", - "./wasm-apps/event_publisher" + suffix, - args.working_directory, - ) - - print("--> Install event_subscriber" + suffix + "...") - install_wasm_application( - "event_subscriber", - "./wasm-apps/event_subscriber" + suffix, - args.working_directory, - ) - - print("--> Query all installed applications...") - query_installed_application(args.working_directory) - - print("--> Uninstall timer" + suffix + "...") - uninstall_wasm_application("timer", args.working_directory) - - print("--> Query all installed applications...") - query_installed_application(args.working_directory) - - print("--> Uninstall event_publisher" + suffix + "...") - uninstall_wasm_application( - "event_publisher", - args.working_directory, - ) - - print("--> Uninstall event_subscriber" + suffix + "...") - uninstall_wasm_application( - "event_subscriber", - args.working_directory, - ) - - print("--> Query all installed applications...") - query_installed_application(args.working_directory) - - print("--> Install request_handler" + suffix + "...") - install_wasm_application( - "request_handler", - "./wasm-apps/request_handler" + suffix, - args.working_directory, - ) - - print("--> Query again...") - query_installed_application(args.working_directory) - - print("--> Install request_sender" + suffix + "...") - install_wasm_application( - "request_sender", - "./wasm-apps/request_sender" + suffix, - args.working_directory, - ) - - print("--> Send GET to the Wasm application named request_handler...") - send_get_to_wasm_application("request_handler", "/url1", args.working_directory) - - print("--> Uninstall request_handler" + suffix + "...") - uninstall_wasm_application( - "request_handler", - args.working_directory, - ) - - print("--> Uninstall request_sender" + suffix + "...") - uninstall_wasm_application( - "request_sender", - args.working_directory, - ) - - # Install a wasm app named "__exit_app_manager__" just to make app manager exit - # while the wasm app is uninstalled, so as to collect the code coverage data. - # Only available when collecting code coverage is enabled. - print("--> Install timer" + suffix + "...") - install_wasm_application( - "__exit_app_manager__", "./wasm-apps/timer" + suffix, args.working_directory - ) - - print("--> Uninstall timer" + suffix + "...") - uninstall_wasm_application( - "__exit_app_manager__", - args.working_directory, - ) - - # wait for a second - time.sleep(1) - - print("--> All pass") - ret = 0 - except AssertionError: - traceback.print_exc() - finally: - app_server.kill() - - return ret - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/samples/simple/src/iwasm_main.c b/samples/simple/src/iwasm_main.c deleted file mode 100644 index 36fb35b12..000000000 --- a/samples/simple/src/iwasm_main.c +++ /dev/null @@ -1,568 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef CONNECTION_UART -#include -#include -#include -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "runtime_lib.h" -#include "runtime_timer.h" -#include "native_interface.h" -#include "app_manager_export.h" -#include "bh_platform.h" -#include "runtime_sensor.h" -#include "bi-inc/attr_container.h" -#include "module_wasm_app.h" -#include "wasm_export.h" - -#define MAX 2048 - -#ifndef CONNECTION_UART -#define SA struct sockaddr -static char *host_address = "127.0.0.1"; -static int port = 8888; -#else -static char *uart_device = "/dev/ttyS2"; -static int baudrate = B115200; -#endif - -extern bool -init_sensor_framework(); -extern void -exit_sensor_framework(); -extern void -exit_connection_framework(); -extern int -aee_host_msg_callback(void *msg, uint32_t msg_len); -extern bool -init_connection_framework(); - -#ifndef CONNECTION_UART -int listenfd = -1; -int sockfd = -1; -static pthread_mutex_t sock_lock = PTHREAD_MUTEX_INITIALIZER; -#else -int uartfd = -1; -#endif - -#ifndef CONNECTION_UART -static bool server_mode = false; - -// Function designed for chat between client and server. -void * -func(void *arg) -{ - char buff[MAX]; - int n; - struct sockaddr_in servaddr; - - while (1) { - if (sockfd != -1) - close(sockfd); - // socket create and verification - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd == -1) { - printf("socket creation failed...\n"); - return NULL; - } - else - printf("Socket successfully created..\n"); - bzero(&servaddr, sizeof(servaddr)); - // assign IP, PORT - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr(host_address); - servaddr.sin_port = htons(port); - - // connect the client socket to server socket - if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) { - printf("connection with the server failed...\n"); - sleep(10); - continue; - } - else { - printf("connected to the server..\n"); - } - - // infinite loop for chat - for (;;) { - bzero(buff, MAX); - - // read the message from client and copy it in buffer - n = read(sockfd, buff, sizeof(buff)); - // print buffer which contains the client contents - // fprintf(stderr, "recieved %d bytes from host: %s", n, buff); - - // socket disconnected - if (n <= 0) - break; - - aee_host_msg_callback(buff, n); - } - } - - // After chatting close the socket - close(sockfd); -} - -static bool -host_init() -{ - return true; -} - -int -host_send(void *ctx, const char *buf, int size) -{ - int ret; - - if (pthread_mutex_trylock(&sock_lock) == 0) { - if (sockfd == -1) { - pthread_mutex_unlock(&sock_lock); - return 0; - } - - ret = write(sockfd, buf, size); - - pthread_mutex_unlock(&sock_lock); - return ret; - } - - return -1; -} - -void -host_destroy() -{ - if (server_mode) - close(listenfd); - - pthread_mutex_lock(&sock_lock); - close(sockfd); - pthread_mutex_unlock(&sock_lock); -} - -/* clang-format off */ -host_interface interface = { - .init = host_init, - .send = host_send, - .destroy = host_destroy -}; -/* clang-format on */ - -/* Change it to 1 when fuzzing test */ -#define WASM_ENABLE_FUZZ_TEST 0 - -void * -func_server_mode(void *arg) -{ - int clilent; - struct sockaddr_in serv_addr, cli_addr; - int n; - char buff[MAX]; - struct sigaction sa; - - sa.sa_handler = SIG_IGN; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sigaction(SIGPIPE, &sa, 0); - - /* First call to socket() function */ - listenfd = socket(AF_INET, SOCK_STREAM, 0); - - if (listenfd < 0) { - perror("ERROR opening socket"); - exit(1); - } - - /* Initialize socket structure */ - bzero((char *)&serv_addr, sizeof(serv_addr)); - - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; - serv_addr.sin_port = htons(port); - - /* Now bind the host address using bind() call.*/ - if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { - perror("ERROR on binding"); - exit(1); - } - - listen(listenfd, 5); - clilent = sizeof(cli_addr); - - while (1) { - pthread_mutex_lock(&sock_lock); - - sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent); - - pthread_mutex_unlock(&sock_lock); - - if (sockfd < 0) { - perror("ERROR on accept"); - exit(1); - } - - printf("connection established!\n"); - - for (;;) { - bzero(buff, MAX); - - // read the message from client and copy it in buffer - n = read(sockfd, buff, sizeof(buff)); - - // socket disconnected - if (n <= 0) { - pthread_mutex_lock(&sock_lock); - close(sockfd); - sockfd = -1; - pthread_mutex_unlock(&sock_lock); - - sleep(1); - break; - } - - aee_host_msg_callback(buff, n); - } -#if WASM_ENABLE_FUZZ_TEST != 0 - /* Exit the process when host disconnect. - This is helpful for reproducing failure case. */ - close(sockfd); - exit(1); -#endif - } -} - -#else -static int -parse_baudrate(int baud) -{ - switch (baud) { - case 9600: - return B9600; - case 19200: - return B19200; - case 38400: - return B38400; - case 57600: - return B57600; - case 115200: - return B115200; - case 230400: - return B230400; - case 460800: - return B460800; - case 500000: - return B500000; - case 576000: - return B576000; - case 921600: - return B921600; - case 1000000: - return B1000000; - case 1152000: - return B1152000; - case 1500000: - return B1500000; - case 2000000: - return B2000000; - case 2500000: - return B2500000; - case 3000000: - return B3000000; - case 3500000: - return B3500000; - case 4000000: - return B4000000; - default: - return -1; - } -} -static bool -uart_init(const char *device, int baudrate, int *fd) -{ - int uart_fd; - struct termios uart_term; - - uart_fd = open(device, O_RDWR | O_NOCTTY); - - if (uart_fd <= 0) - return false; - - memset(&uart_term, 0, sizeof(uart_term)); - uart_term.c_cflag = baudrate | CS8 | CLOCAL | CREAD; - uart_term.c_iflag = IGNPAR; - uart_term.c_oflag = 0; - - /* set noncanonical mode */ - uart_term.c_lflag = 0; - uart_term.c_cc[VTIME] = 30; - uart_term.c_cc[VMIN] = 1; - tcflush(uart_fd, TCIFLUSH); - - if (tcsetattr(uart_fd, TCSANOW, &uart_term) != 0) { - close(uart_fd); - return false; - } - - *fd = uart_fd; - - return true; -} - -static void * -func_uart_mode(void *arg) -{ - int n; - char buff[MAX]; - - if (!uart_init(uart_device, baudrate, &uartfd)) { - printf("open uart fail! %s\n", uart_device); - return NULL; - } - - for (;;) { - bzero(buff, MAX); - - n = read(uartfd, buff, sizeof(buff)); - - if (n <= 0) { - close(uartfd); - uartfd = -1; - break; - } - - aee_host_msg_callback(buff, n); - } - - return NULL; -} - -static int -uart_send(void *ctx, const char *buf, int size) -{ - int ret; - - ret = write(uartfd, buf, size); - - return ret; -} - -static void -uart_destroy() -{ - close(uartfd); -} - -/* clang-format off */ -static host_interface interface = { - .send = uart_send, - .destroy = uart_destroy -}; -/* clang-format on */ - -#endif - -static attr_container_t * -read_test_sensor(void *sensor) -{ - attr_container_t *attr_obj = attr_container_create("read test sensor data"); - if (attr_obj) { - bool ret = - attr_container_set_string(&attr_obj, "name", "read test sensor"); - if (!ret) { - attr_container_destroy(attr_obj); - return NULL; - } - return attr_obj; - } - return NULL; -} - -static bool -config_test_sensor(void *s, void *config) -{ - return false; -} - -static char global_heap_buf[1024 * 1024] = { 0 }; - -/* clang-format off */ -static void -showUsage() -{ -#ifndef CONNECTION_UART - printf("Usage:\n"); - printf("\nWork as TCP server mode:\n"); - printf("\tsimple -s|--server_mode -p|--port \n"); - printf("where\n"); - printf("\t represents the port that would be listened on and the default is 8888\n"); - printf("\nWork as TCP client mode:\n"); - printf("\tsimple -a|--host_address -p|--port \n"); - printf("where\n"); - printf("\t represents the network address of host and the default is 127.0.0.1\n"); - printf("\t represents the listen port of host and the default is 8888\n"); -#else - printf("Usage:\n"); - printf("\tsimple -u -b \n\n"); - printf("where\n"); - printf("\t represents the UART device name and the default is /dev/ttyS2\n"); - printf("\t represents the UART device baudrate and the default is 115200\n"); -#endif -} -/* clang-format on */ - -static bool -parse_args(int argc, char *argv[]) -{ - int c; - - while (1) { - int optIndex = 0; - static struct option longOpts[] = { -#ifndef CONNECTION_UART - { "server_mode", no_argument, NULL, 's' }, - { "host_address", required_argument, NULL, 'a' }, - { "port", required_argument, NULL, 'p' }, -#else - { "uart", required_argument, NULL, 'u' }, - { "baudrate", required_argument, NULL, 'b' }, -#endif - { "help", required_argument, NULL, 'h' }, - { 0, 0, 0, 0 } - }; - - c = getopt_long(argc, argv, "sa:p:u:b:w:h", longOpts, &optIndex); - if (c == -1) - break; - - switch (c) { -#ifndef CONNECTION_UART - case 's': - server_mode = true; - break; - case 'a': - host_address = optarg; - printf("host address: %s\n", host_address); - break; - case 'p': - port = atoi(optarg); - printf("port: %d\n", port); - break; -#else - case 'u': - uart_device = optarg; - printf("uart device: %s\n", uart_device); - break; - case 'b': - baudrate = parse_baudrate(atoi(optarg)); - printf("uart baudrate: %s\n", optarg); - break; -#endif - case 'h': - showUsage(); - return false; - default: - showUsage(); - return false; - } - } - - return true; -} - -// Driver function -int -iwasm_main(int argc, char *argv[]) -{ - RuntimeInitArgs init_args; - korp_tid tid; - - if (!parse_args(argc, argv)) - return -1; - - memset(&init_args, 0, sizeof(RuntimeInitArgs)); - -#if USE_GLOBAL_HEAP_BUF != 0 - init_args.mem_alloc_type = Alloc_With_Pool; - init_args.mem_alloc_option.pool.heap_buf = global_heap_buf; - init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); -#else - init_args.mem_alloc_type = Alloc_With_Allocator; - init_args.mem_alloc_option.allocator.malloc_func = malloc; - init_args.mem_alloc_option.allocator.realloc_func = realloc; - init_args.mem_alloc_option.allocator.free_func = free; -#endif - - /* initialize runtime environment */ - if (!wasm_runtime_full_init(&init_args)) { - printf("Init runtime environment failed.\n"); - return -1; - } - - /* connection framework */ - if (!init_connection_framework()) { - goto fail1; - } - - /* sensor framework */ - if (!init_sensor_framework()) { - goto fail2; - } - - /* timer manager */ - if (!init_wasm_timer()) { - goto fail3; - } - - /* add the sys sensor objects */ - add_sys_sensor("sensor_test1", "This is a sensor for test", 0, 1000, - read_test_sensor, config_test_sensor); - add_sys_sensor("sensor_test2", "This is a sensor for test", 0, 1000, - read_test_sensor, config_test_sensor); - start_sensor_framework(); - -#ifndef CONNECTION_UART - if (server_mode) - os_thread_create(&tid, func_server_mode, NULL, - BH_APPLET_PRESERVED_STACK_SIZE); - else - os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE); -#else - os_thread_create(&tid, func_uart_mode, NULL, - BH_APPLET_PRESERVED_STACK_SIZE); -#endif - - app_manager_startup(&interface); - - exit_wasm_timer(); - -fail3: - exit_sensor_framework(); - -fail2: - exit_connection_framework(); - -fail1: - wasm_runtime_destroy(); - - return -1; -} diff --git a/samples/simple/src/main.c b/samples/simple/src/main.c deleted file mode 100644 index e603420ee..000000000 --- a/samples/simple/src/main.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -extern void -iwasm_main(); - -int -main(int argc, char *argv[]) -{ - iwasm_main(argc, argv); - return 0; -} diff --git a/samples/simple/wasm-apps/connection.c b/samples/simple/wasm-apps/connection.c deleted file mode 100644 index d8efefdcf..000000000 --- a/samples/simple/wasm-apps/connection.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/connection.h" -#include "wa-inc/timer_wasm_app.h" -#include "wa-inc/request.h" - -/* User global variable */ -static int num = 0; -static user_timer_t g_timer; -static connection_t *g_conn = NULL; - -void -on_data1(connection_t *conn, conn_event_type_t type, const char *data, - uint32 len, void *user_data) -{ - if (type == CONN_EVENT_TYPE_DATA) { - char message[64] = { 0 }; - memcpy(message, data, len); - printf("Client got a message from server -> %s\n", message); - } - else if (type == CONN_EVENT_TYPE_DISCONNECT) { - printf("connection is close by server!\n"); - } - else { - printf("error: got unknown event type!!!\n"); - } -} - -/* Timer callback */ -void -timer1_update(user_timer_t timer) -{ - char message[64] = { 0 }; - /* Reply to server */ - snprintf(message, sizeof(message), "Hello %d", num++); - api_send_on_connection(g_conn, message, strlen(message)); -} - -void -my_close_handler(request_t *request) -{ - response_t response[1]; - - if (g_conn != NULL) { - api_timer_cancel(g_timer); - api_close_connection(g_conn); - } - - make_response_for_request(request, response); - set_response(response, DELETED_2_02, 0, NULL, 0); - api_response_send(response); -} - -void -on_init() -{ - user_timer_t timer; - attr_container_t *args; - char *str = "this is client!"; - - api_register_resource_handler("/close", my_close_handler); - - args = attr_container_create(""); - attr_container_set_string(&args, "address", "127.0.0.1"); - attr_container_set_uint16(&args, "port", 7777); - - g_conn = api_open_connection("TCP", args, on_data1, NULL); - if (g_conn == NULL) { - printf("connect to server fail!\n"); - return; - } - - printf("connect to server success! handle: %p\n", g_conn); - - /* set up a timer */ - timer = api_timer_create(1000, true, false, timer1_update); - api_timer_restart(timer, 1000); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - accomplished in wasm app library version of on_destroy() */ -} diff --git a/samples/simple/wasm-apps/event_publisher.c b/samples/simple/wasm-apps/event_publisher.c deleted file mode 100644 index 2fa4418ca..000000000 --- a/samples/simple/wasm-apps/event_publisher.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" -#include "wa-inc/timer_wasm_app.h" - -int num = 0; - -void -publish_overheat_event() -{ - attr_container_t *event; - - event = attr_container_create("event"); - attr_container_set_string(&event, "warning", "temperature is over high"); - - api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event, - attr_container_get_serialize_length(event)); - - attr_container_destroy(event); -} - -/* Timer callback */ -void -timer1_update(user_timer_t timer) -{ - publish_overheat_event(); -} - -void -start_timer() -{ - user_timer_t timer; - - /* set up a timer */ - timer = api_timer_create(1000, true, false, timer1_update); - api_timer_restart(timer, 1000); -} - -void -on_init() -{ - start_timer(); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - accomplished in wasm app library version of on_destroy() */ -} diff --git a/samples/simple/wasm-apps/event_subscriber.c b/samples/simple/wasm-apps/event_subscriber.c deleted file mode 100644 index 7ebd309e7..000000000 --- a/samples/simple/wasm-apps/event_subscriber.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" - -void -over_heat_event_handler(request_t *request) -{ - printf("### user over heat event handler called\n"); - - if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER) - attr_container_dump((attr_container_t *)request->payload); -} - -void -on_init() -{ - api_subscribe_event("alert/overheat", over_heat_event_handler); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - accomplished in wasm app library version of on_destroy() */ -} diff --git a/samples/simple/wasm-apps/request_handler.c b/samples/simple/wasm-apps/request_handler.c deleted file mode 100644 index be6c56030..000000000 --- a/samples/simple/wasm-apps/request_handler.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" - -static void -url1_request_handler(request_t *request) -{ - response_t response[1]; - attr_container_t *payload; - - printf("[resp] ### user resource 1 handler called\n"); - - if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER) - attr_container_dump((attr_container_t *)request->payload); - - payload = attr_container_create("wasm app response payload"); - if (payload == NULL) - return; - - attr_container_set_string(&payload, "key1", "value1"); - attr_container_set_string(&payload, "key2", "value2"); - - make_response_for_request(request, response); - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, (void *)payload, - attr_container_get_serialize_length(payload)); - api_response_send(response); - - attr_container_destroy(payload); -} - -static void -url2_request_handler(request_t *request) -{ - response_t response[1]; - make_response_for_request(request, response); - set_response(response, DELETED_2_02, 0, NULL, 0); - api_response_send(response); - - printf("### user resource 2 handler called\n"); -} - -void -on_init() -{ - /* register resource uri */ - api_register_resource_handler("/url1", url1_request_handler); - api_register_resource_handler("/url2", url2_request_handler); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - accomplished in wasm app library version of on_destroy() */ -} diff --git a/samples/simple/wasm-apps/request_sender.c b/samples/simple/wasm-apps/request_sender.c deleted file mode 100644 index 823f7f62c..000000000 --- a/samples/simple/wasm-apps/request_sender.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" - -static void -my_response_handler(response_t *response, void *user_data) -{ - char *tag = (char *)user_data; - - if (response == NULL) { - printf("[req] request timeout!\n"); - return; - } - - printf("[req] response handler called mid:%d, status:%d, fmt:%d, " - "payload:%p, len:%d, tag:%s\n", - response->mid, response->status, response->fmt, response->payload, - response->payload_len, tag); - - if (response->payload != NULL && response->payload_len > 0 - && response->fmt == FMT_ATTR_CONTAINER) { - printf("[req] dump the response payload:\n"); - attr_container_dump((attr_container_t *)response->payload); - } -} - -static void -test_send_request(char *url, char *tag) -{ - request_t request[1]; - - init_request(request, url, COAP_PUT, 0, NULL, 0); - api_send_request(request, my_response_handler, tag); -} - -void -on_init() -{ - test_send_request("/app/request_handler/url1", "a request to target app"); - test_send_request("url1", "a general request"); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - accomplished in wasm app library version of on_destroy() */ -} diff --git a/samples/simple/wasm-apps/sensor.c b/samples/simple/wasm-apps/sensor.c deleted file mode 100644 index c45ff67d9..000000000 --- a/samples/simple/wasm-apps/sensor.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/sensor.h" - -static sensor_t sensor1 = NULL; -static sensor_t sensor2 = NULL; -static char *user_data = NULL; - -/* Sensor event callback*/ -void -sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data) -{ - if (sensor == sensor1) { - printf("### app get sensor event from sensor1\n"); - attr_container_dump(event); - } - else { - printf("### app get sensor event from sensor2\n"); - attr_container_dump(event); - } -} - -void -on_init() -{ - attr_container_t *config; - - printf("### app on_init 1\n"); - /* open a sensor */ - user_data = malloc(100); - if (!user_data) { - printf("allocate memory failed\n"); - return; - } - - printf("### app on_init 2\n"); - sensor1 = sensor_open("sensor_test1", 0, sensor_event_handler, user_data); - if (!sensor1) { - printf("open sensor1 failed\n"); - return; - } - /* config the sensor */ - sensor_config(sensor1, 1000, 0, 0); - - printf("### app on_init 3\n"); - sensor2 = sensor_open("sensor_test2", 0, sensor_event_handler, user_data); - if (!sensor2) { - printf("open sensor2 failed\n"); - return; - } - /* config the sensor */ - sensor_config(sensor2, 5000, 0, 0); - - printf("### app on_init 4\n"); - /* - config = attr_container_create("sensor config"); - sensor_config(sensor, config); - attr_container_destroy(config); - */ -} - -void -on_destroy() -{ - if (NULL != sensor1) { - sensor_config(sensor1, 0, 0, 0); - } - - if (NULL != sensor2) { - sensor_config(sensor2, 0, 0, 0); - } - - if (NULL != user_data) { - free(user_data); - } - - /* real destroy work including killing timer and closing sensor is - accomplished in wasm app library version of on_destroy() */ -} diff --git a/samples/simple/wasm-apps/timer.c b/samples/simple/wasm-apps/timer.c deleted file mode 100644 index 5bf0822cd..000000000 --- a/samples/simple/wasm-apps/timer.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/timer_wasm_app.h" - -/* User global variable */ -static int num = 0; - -/* Timer callback */ -void -timer1_update(user_timer_t timer) -{ - printf("Timer update %d\n", num++); -} - -void -on_init() -{ - user_timer_t timer; - - /* set up a timer */ - timer = api_timer_create(1000, true, false, timer1_update); - api_timer_restart(timer, 1000); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/IoT-APP-Store-Demo/README.md b/test-tools/IoT-APP-Store-Demo/README.md deleted file mode 100644 index 266255c0c..000000000 --- a/test-tools/IoT-APP-Store-Demo/README.md +++ /dev/null @@ -1,50 +0,0 @@ -# IoT Application Store -Wasm application management portal for WAMR - -## Start the server - -### Using docker -1. install docker and docker-compose - ``` bash - sudo apt install docker.io docker-compose - ``` - -2. start - ``` bash - docker-compose up - ``` -### Using commands -> Note: must use python3.5. If you don't have python3.5 on your machine, had better using docker -1. install the required package - ``` bash - pip3 install django - ``` - -2. Start device server - ``` bash - cd wasm_django/server - python3 wasm_server.py - ``` - -3. Start IoT application management web portal - ``` bash - cd wasm_django - python3 manage.py runserver 0.0.0.0:80 - ``` - -## Start the runtime -1. Download WAMR runtime from [help](http://localhost/help/) page - > NOTE: You need to start the server before accessing this link! - -2. Start a WAMR runtime from localhost - ``` bash - chmod +x simple - ./simple - ``` - or from other computers - ``` bash - ./simple -a [your.server.ip.address] - ``` - -## Online demo - http://82.156.57.236/ diff --git a/test-tools/IoT-APP-Store-Demo/docker-compose.yml b/test-tools/IoT-APP-Store-Demo/docker-compose.yml deleted file mode 100644 index 331d064cd..000000000 --- a/test-tools/IoT-APP-Store-Demo/docker-compose.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: '2.0' - -services: - web_portal: - build: ./wasm_django - network_mode: "host" - depends_on: - - 'device_server' - restart: always - volumes: - - store:/app/static/upload/ - device_server: - build: - context: ./wasm_django - dockerfile: ./server/Dockerfile - network_mode: "host" - restart: always - volumes: - - store:/app/static/upload/ - -volumes: - store: \ No newline at end of file diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile b/test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile deleted file mode 100644 index a796725fa..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM python:3.5 - -WORKDIR /app -COPY . /app - -# hadolint ignore=DL3013 -RUN pip install django --no-cache-dir - -ENTRYPOINT ["python", "manage.py", "runserver", "0.0.0.0:80"] diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/db.sqlite3 b/test-tools/IoT-APP-Store-Demo/wasm_django/db.sqlite3 deleted file mode 100755 index 211576ca3e5992d4ec1abe50c687985dcaa1f3f0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 45056 zcmeHQYit|Iec#zxaz$H|Wj(xpNT(HL*=A%(eC(2<4rz~P>wKy$`6V^ypa*tIu4JAm zQYIIDU;vy-A}KLrSo0=+8&1SrrJXoCVtk@Q1R6h&L41&TE3BNw18&_jW=Y5F1g zaDDw}c9y#&R}xRE?`+*Hq~XrYe}40y-|Reg=D)jlZ{H}?Om(GPSu<*CT#y8WgqKuR z5QGu0B7g|I44zbKTgppr^!~ijf@U$(xR#>eVHORBte+;sb@n;15@Axn9-{U{Tzkxr4KmXA&!*k{g zd|Vjlk(5D1TQ_OW@_;ma4pmLs8C2P?e@Gf1L#%a^#$9!t`-0NoAnis-dZ|YmRH%=3 zAGlu{9Hm~TixE#s%5Z>o36L%H7nSWGkS*gk1^jRL@9>}FZ{m0GFN2pKoB__j(`6ti zOM)`kX#f3wNf8a)#lypzgv=o!9g+~AniYh!KV-(ZU22Dct?rXY5yk? zk`1guW->AHwMWC-|%Q*YOj)hChX`VGWPsUW~*aitmcw62B(CEj|%T;?IfK z#F#iD_M-nmKY)b%cxD+mA)yf@Zx+lgI(r;CDWNeW=gp#7Gik^Z9ak)NTkK*b7VKrHYSMfVdd7BYBBLX*fx;au1Bz-b9Z zk&i*TBKoZe2J4FG8Mk2#qg@d2&b482=?Pv5w4j|I+M1zcLM9RgF?&XB`9i(RskN}GNcUG?;%;4o<=(c#bkHZ&P{Y%fY^i^YKuQmofzxuA$8NJK$EUqis^c| z(H?+SqU-LlkhEAZp(W*wnprEXnT@1jGXEFR*9Gw_;5-4(6Y3tO6Zo*wc70eGJ&XC& z-#F2w)Nu;!j1@|G^AYVk+Zw;s??Ov+4Iso9$>rlQJsZhvlnM{MlMb+JczJRD_VS!M zzj$@-HP&w)ESr#eb8$BS(jXdrPFpV#-g&KCR?=zo_(i9Wr2RZ~oF2k8z_iBnHaAIU zsA&~EP}`&+opqN)w6mV9jfeJuux&_lxaceo+WvclpB3<*;xFPn9u>bM{)+fA`fv0N zw1qU`J>eaQ{J_Vx9-lC{oF*(sB9ThV{C0Cd*|nsEaWv<`5R+RTg|yWR~ruiH3DhO=oD3(zH& zE7c5{6PcAtxsq9f6&PdHta>Sxh)3g*SQ>Us2j^|DM5Y3xOQB-Ar=ryilso1Hp=;4( zJpS@AfVgf$==lGLtr z0m6cf5O*V(Yeu2CPZdSA2vpIlGJt%_28l5c=R)kHvLo@7o=m;!_X*?I(ykeOm9Pl> zu9Y_%^wKqM3ffMMHkFD+poZpsK0yJU$l^CZ#2eFHTF*v~tbJ!zipFXtcfVYKd4U(y zOf(hI6KM&cfMo_1bD)@7aFLe@tQSN=i|NT&1Ovo)10tF!lnS+i;Ze2Pl%~zZwV7!V zIE55e``I%=Ow;0;o$vUfYViJh5;+pVN(puUy&Oy7TGCjr)bt{o4;FmeaXM=Kb92 z!YjqwpIk2&i`y;tCb3y9F%{Di$wZ9o{~`Pn0si>G8Q=_jJQ(Q0N`UqZWc>Gu-x0v} zcN<^DeQ?ST&cJidz-&LPxTVr`71h0jNLQfg(xyEk#xylDGplQ}F>NXy*Hdvl(nnY8 z?6jV1Xc}3h)>Bi_nPe;;iJ$Zd!{cdY`QahN|$DS;s12B2X=?Tru z8i`hcQDzvz3|v~H+tOQREUjY1+Ja6l!3ZQ=zceB%8BpoAw@Pe-+uFz`s%hDrIb&v9 zK}YscZ8x0VRcuKS3cvM>FHnQc&rQ2c+vsLD+30T7DAa64(-wUYgH5&@Pt4Lh4Aj5~ zrks7l%+;v5V9k6~qb8tEaK&5)dzyw_TqM$D7su>hnN3GXwE&nMDS)&R;+WVFJ5#rL z4J)fVL1!j5kc)j~IOw(|t2>8=O;X3WE<=WpT3s`WMKG0BH%isQYRSwujQrFqug+b$ z4t3Kc|5Kk-BjGT$|HrQj_`mQ^@PEQnK=0vy#Q%W*2LBcQGyKQ!JmA;x@8RFVUxDX> zzJ$Mke-(cY*YTTp1DA0D=O7_JI0KvkZw7oAA$f?p=cs#@x@U;%KTTbDh!@UJQFoBI zz5(j?Q@4-0Cy6WdQuhRPd#D>EF7Br8aq1qUZh*LA7jf9L^ctRId;OHtes=U@vs&4ly6L`_Q>sn z6cmQoCZrI&vI>#cR`Fv$2FUo&?f>>;iN|vWjwS=V{U6PG<)z{bbizOo_X|GZmLQtw zH-&$}YjAp~quxItE4N|oOK+KR(tXLQ^FUfEsp~0S)0|1NC2@AQsqt5Xr{_{J>oM#$Va0>!Hldc=C>znGd|MK)Td0X%S$Q3l zU)W1|3khxmv(Z>2mt9HGOQQ{cup_SkZ0iU1fHOkqWY}F}nW8=l{Fb7?0o#9BBsl{QpQ-FE1Qt zU{3~k``?ou9?2Ov(hTtSf26CI7mhQqCj-3w?@14jtXCKgZ{PM+RT zzk5MewkOce31=19S-iI2p5<7@mh&ckj42W|vhk#DIBW4vD*x_F@s3c3(5}@|CoNel zb=!QB?F4E!YAF{A?~ISjb-ZItUH1!5omi5W=S$@Fdf#cQa(mmD z9>$6_$123JwvDz}+mh;XVw>Jk8Lq#29&EzmsQxCceGf%4@S4g@(a4(c-Z99km`NtG z`FK8_r4{dyK=Q1755c{Wt$O!JM(U%X6RCBo7VO2$kI70rj&@RRqiJ_Vc!2qutKLK6 zK-KT)*RX+Ztrbga?`XdM|MdDhj?5W&<{9Ag|7X66xPqL4r^Wzp|4)rt4$K*N<{1d$ zPk{a3mj&@H;k)=-I3;`;-^F*ICAH(aU%57l1bW-ZzR>`;)n)3>xNO9t&iRG6!ZBGH z89|>Nb?(ZE%@Y+NC*94rV~y|w-Gr?h)#_Hc0v}kgpF@qtW}2QubzbW2e#RA^F@?Lz zLN!y}fK>pZR!Gg3%f-f%n-EJvoA0aPjc^XOYCUrUf-8jzd$YQuM%*O{BJ|BSPHarq z93ZAh%~)A!R{~Td&yH@w-F>Tm^sO~-Ky7$_Ujk4YFMM}0ZYn{ze*Pj@2Tn9u2Re%) zZHqUt6)l-CHOn~8k?Ug>>i$rH6T2%)$BRD1ERcLW+dk?iHCY)QMfEl33ZrIt&Q&<> zag9-t16^eMUj*T3+^@`y?AcVv<&?2n3ONn(@!zgc{>vHo_%XoW|MT&yb6#T3fX#pp zP7r>dcqgnMJBI&q1~>ypn}JW9;q(8aUBkR|oPoU<;Pd~z*x_-Ufuqd;AODYb{qoXr z2KHhgh$TTnTY`99>_J=jCVq)Zzq3~w9(QO4>H{;fayN|XDYrE&`+`Kqe6&u!Crr22 z3_X{KB@%IFFv>(OHScycM|!4jvT|i8WFN|vS19~q(y!bM@3w)|l1sGNf4-hb$Vxbj zb}qWjVp&$rvd5Zt#+oCERyGq4%x!1eP;>2OsxF&o*krWjfik20Ex+zEs)SYYvf;)i zE7{q*e&`yt0P0h-bXSmZV134!Y_vINmz&G(L>y>Wuzh>jy*mudwC_#31-Sk1|5L?t z7|sA^fHS}u;0!!Z43PD|Gs0B?e-D2Z{}RsPS==ptU;KUXi(*Aw6sN>K^dIOi(eI)s zXbFu8KNh|%{I>8|_<2auIL@B&321m+Hu8D;3bHFkNriKj%uPb4A#QxqzgaN1GHjMc z;)!2n{tF7ogrk0V=F5anpt+>1kcQkTOOAci!6j#f*mCM1$c;_-i9RkNq7w5?41mOB z(nqyo4{p`A*Ug4zEKDVV)9^7l6n)Xh)N2uEDmEp6FUXMuOwX1COjmb;FnmA`P3S(N zaEmli+ATT+pN&H!7bU7WA-JJ3@u=`gI4HTqRJG%oj#Q$@l3=>o5=<%LJsSjx;c-;iJmSTe^f8Kyx)hN(dPLjjN(xrm7l z4FRGA^<3(L*onAEwQy|w8mc%!mt~NgPKrz)CxXZ_rJTUaeoLBZ=0p%_rk)dc!3Wae zs7Q2lLWw9*)CoB+`Gmm5C{-3F`(~+D*>0!`0V)l-gh6UTXNtPzn3|5HNF|w)Zb_zM zLo$Rwa(tR7=oTaDHDpNp$M|gle; - -{% load static %} - - - - - - - Wasm-Micro-Runtime - - - - - - - - - - -
-
- -
-
-

WebAssembly Micro Runtime - APP Store Demo

-
-
- - - -
-
-
-
-

- -

-
-
IP :
-
Port :
-
Installed apps :
-
-
-
- - - - - -
-

app is downloading now

-
-
-
-
- - -
-
-
×
-
HOT Applications
- -
-
- -

Product Name:

-

Current Version:

- -
-
-
-
- - -
-

List of Installed Apps:

- -
- - -
-
- -
Product Name:
-
Staus:
-
Current Version:
-
-
-
- -
Copyright© intel.com
- - - - - - - - - - - diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html b/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html deleted file mode 100644 index 46ecedf15..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html +++ /dev/null @@ -1,98 +0,0 @@ - - -{% load static %} - - - - - - - - Wasm-Micro-Runtime - - - - - - - - - - -
-
- -
-
-

WebAssembly Micro Runtime - APP Store Demo

-
-
- - - - - -
-
-
-
The products
-
Application List
-
-
- {%csrf_token%} -
- - Choose File -
-
- -
-
-
-
-
-
-
-

Product Name:

-

Product Version:

-

Preloaded Apps

- -
-
-
-
-
- - -
- Copyright© intel.com -
- - - - - - - - - diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html b/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html deleted file mode 100644 index 5610a2d84..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html +++ /dev/null @@ -1,125 +0,0 @@ - - - - - -wasm-micro-runtime - - - - - - - - - - -
-

404

-

Server Not Found

-

Github

-
- - - - - - - - - - diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html b/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html deleted file mode 100755 index 4ad7427ba..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html +++ /dev/null @@ -1,102 +0,0 @@ - - -{% load static %} - - - - - - - Wasm-Micro-Runtime - - - - - - - - - - - - -
-
-
-
-

- How to use? -

-

- 1. Download a simple runtime (build for ubuntu 20.04 64 bits, other platforms please build - from the source code) -

-

- 2. In the terminal: cd ~/Download && ./simple -a 82.156.57.236 -

-
-
- -
- Notes: -
We also have a UI-enabled runtime, please download here and enjoy. It may require - a few more setups. -

Before running the UI-enabled runtime, please install some required softwares:

-

sudo apt-get install libsdl2-2.0-0:i386

-

For more details please refer to this guide -

-

cd ~/Download && ./wasm_runtime_wgl -a 82.156.57.236

-
-
-

- 3. Return to device page, find your device according to the IP address and click it, you - will enter application installation page -

-

- 4. In the application installation page, click the Install Application button, and chose an - app to install. (The "ui_app" is only for UI_enabled_runtimes, simple runtime can't install - this app) -

-

- 5. If you want to upload a new application, go to App Store page, choose a file and click - upload -

-

- Go Back - Download - simple_runtime - Download - UI_enabled_runtime -

-
-
-
-
-

Like this project?

-

Join us and build a powerful and interesting world for embedded - devices!

- - -

- View - on GitHub -

-
-
-
-
-
-
- - - diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html b/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html deleted file mode 100644 index 3832791d1..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html +++ /dev/null @@ -1,91 +0,0 @@ - - -{% load static %} - - - - - - - Wasm-Micro-Runtime - - - - - - - - - - -
-
- -
-
-

WebAssembly Micro Runtime - APP Store Demo

-
-
- -
-
-
-
-

- -

-
-

The devices

-
-
- -
- - -
-
-
-
-

- -

-
-
IP :
-
Port :
-
Installed apps :
-
-
-

- -

-
-
-
- - - - -
- Copyright© intel.com -
- - - - - - - - diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py b/test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py deleted file mode 100755 index 7ce503c2d..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py b/test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py deleted file mode 100755 index 1afa1f954..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py +++ /dev/null @@ -1,273 +0,0 @@ -''' - /* Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -''' - -# _*_ -from django.shortcuts import render, render_to_response -from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound -import json -import socket -import os - -# Create your views here. - - -avaliable_list = [ - {'ID': 'timer', 'Version': '1.0'}, - {'ID': 'connection', 'Version': '1.0'}, - {'ID': 'event_publisher', 'Version': '3.0'}, - {'ID': 'event_subscriber', 'Version': '1.0'}, - {'ID': 'request_handler', 'Version': '1.0'}, - {'ID': 'sensor', 'Version': '1.0'}, - {'ID': 'ui_app', 'Version': '1.0'} -] - -# Help -def help(req): -# return "Help" page - return render(req, "help.html") - -# View -def index(req): - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - - host = '127.0.0.1' - port = 8889 - msg = "" - err = "" - - try: - s.connect((host, port)) - s.send(bytes("query:all", encoding='utf8')) - s.settimeout(10) - msg = s.recv(1024) - except socket.timeout as e: - err = "empty" - print("no client connected") - except socket.error as e: - err = "refused" - print("server not started") - - s.close() - - device_list = [] - if msg != "": - devices = msg.decode('utf-8').split("*") - for dev in devices: - dev_info = eval(dev) - addr = dev_info['addr'] - port = dev_info['port'] - apps = dev_info['num'] - device_list.append({'IP': addr, 'Port': port, 'apps': apps}) - else: - if err == "refused": - return render(req, "empty.html") - - dlist = device_list - - return render(req, 'mysite.html', {'dlist': json.dumps(dlist)}) - - -def apps(req): - open_status = '' - search_node = [] - if req.method == "POST": - dev_search = req.POST['mykey'] - dev_addr = req.POST['voip'] - dev_port = req.POST['voport'] - open_status = 'open' - for i in avaliable_list: - if i['ID'] == dev_search: - search_node = [{'ID':dev_search, 'Version': '1.0'}] - print("search_node:",search_node) - break - else: - search_node = ["Nothing find"] - print( "final:",search_node) - else: - dev_addr = req.GET['ip'] - dev_port = req.GET['port'] - open_status = 'close' - - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - host = '127.0.0.1' - port = 8889 - msg = "" - err = "" - - try: - s.connect((host, port)) - s.send(bytes("query:"+dev_addr+":"+str(dev_port), encoding='utf8')) - msg = s.recv(1024) - except socket.error as e: - print("unable to connect to server") - msg = b"fail" - s.close() - - app_list = [] - - if msg != "": - if msg.decode() == "fail": - return render(req, "empty.html") - else: - dic = eval(msg.decode(encoding='utf8')) - app_num = dic["num"] - for i in range(app_num): - app_list.append( - {'pname': dic["applet"+str(i+1)], 'status': 'Installed', 'current_version': '1.0'}) - - alist = app_list - device_info = [] - device_info.append( - {'IP': dev_addr, 'Port': str(dev_port), 'apps': app_num}) - - print(device_info) - return render(req, 'application.html', {'alist': json.dumps(alist), 'dlist': json.dumps(device_info), 'llist': json.dumps(avaliable_list), - "open_status":json.dumps(open_status),"search_node": json.dumps(search_node),}) - - -def appDownload(req): - dev_addr = req.GET['ip'] - dev_port = req.GET['port'] - app_name = req.GET['name'] - - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - - host = '127.0.0.1' - port = 8889 - msg = "" - - app_path = os.path.abspath(os.path.join(os.getcwd(), "static", "upload")) - if app_path[-1] != '/': - app_path += '/' - - try: - s.connect((host, port)) - s.send(bytes("install:"+dev_addr+":"+str(dev_port)+":"+app_name + - ":"+app_path + app_name + ".wasm", encoding='utf8')) - msg = s.recv(1024) - except socket.error as e: - print("unable to connect to server") - s.close() - - success = "ok" - fail = "Fail!" - status = [success, fail] - print(msg) - if msg == b"fail": - return HttpResponse(json.dumps({ - "status": fail - })) - elif msg == b"success": - return HttpResponse(json.dumps({ - "status": success - })) - else: - return HttpResponse(json.dumps({ - "status": eval(msg.decode())["error message"].split(':')[1] - })) - - -def appDelete(req): - dev_addr = req.GET['ip'] - dev_port = req.GET['port'] - app_name = req.GET['name'] - - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - - host = '127.0.0.1' - port = 8889 - s.connect((host, port)) - s.send(bytes("uninstall:"+dev_addr+":" + - str(dev_port)+":"+app_name, encoding='utf8')) - msg = s.recv(1024) - s.close() - r = HttpResponse("ok") - return r - -static_list = [{'ID': 'timer', 'Version': '1.0'}, {'ID': 'connection', 'Version': '1.0'}, {'ID': 'event_publisher', 'Version': '3.0'}, { - 'ID': 'event_subscriber', 'Version': '1.0'}, {'ID': 'reuqest_handler', 'Version': '1.0'}, {'ID': 'sensor', 'Version': '1.0'}, {'ID': 'ui_app', 'Version': '1.0'}] - -def store(req): - - store_path = os.path.join('static', 'upload') - status = [] - - print(user_file_list) - return render(req, 'appstore.html', {'staticlist': json.dumps(static_list), 'flist': json.dumps(user_file_list),'ulist':json.dumps(status)}) - -user_file_list = [] -files_list = [] -def uploadapps(req): - status = [] - local_list = ['timer','connection','event_publisher','event_subscriber','reuqest_handler','sensor'] - req.encoding = 'utf-8' - if req.method == 'POST': - myfile = req.FILES.get("myfile", None) - obj = req.FILES.get('myfile') - store_path = os.path.join('static', 'upload') - file_path = os.path.join('static', 'upload', obj.name) - - if not os.path.exists(store_path): - os.makedirs(store_path) - - file_name = obj.name.split(".")[0] - file_prefix = obj.name.split(".")[-1] - - - if file_prefix != "wasm": - status = ["Not a wasm file"] - elif file_name in local_list: - status = ["This App is preloaded"] - elif file_name in files_list: - status = ["This App is already uploaded"] - else: - status = [] - avaliable_list.append({'ID': file_name, 'Version': '1.0'}) - user_file_list.append({'ID': file_name, 'Version': '1.0'}) - files_list.append(file_name) - - print(user_file_list) - f = open(file_path, 'wb') - for chunk in obj.chunks(): - f.write(chunk) - f.close() - return render(req, 'appstore.html', {'staticlist': json.dumps(static_list), 'flist': json.dumps(user_file_list),'ulist':json.dumps(status)}) - -appname_list = [] - -def addapps(request): - types = '' - print("enter addapps") - request.encoding = 'utf-8' - app_dic = {'ID': '', 'Version': ''} - - # if request.method == 'get': - if "NAME" in request.GET: - a_name = request.GET['NAME'] - if a_name != "" and a_name not in appname_list: - appname_list.append(a_name) - message = request.GET['NAME'] + request.GET['Version'] - app_dic['ID'] = request.GET['NAME'] - app_dic['Version'] = request.GET['Version'] - avaliable_list.append(app_dic) - else: - types = "Exist" - print(avaliable_list) - return render(request, 'appstore.html', {'alist': json.dumps(avaliable_list)}) - -def removeapps(req): - app_name = req.GET['name'] - app_version = req.GET['version'] - remove_app = {'ID': app_name, 'Version': app_version} - avaliable_list.remove(remove_app) - user_file_list.remove(remove_app) - files_list.remove(app_name) - return render(req, 'appstore.html', {'alist': json.dumps(avaliable_list),'flist': json.dumps(user_file_list)}) - -# Test -# if __name__ == "__main__": -# print(device_list[0]['IP']) -# print(device['IP']) diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/manage.py b/test-tools/IoT-APP-Store-Demo/wasm_django/manage.py deleted file mode 100755 index 341863cf6..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/manage.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" -import os -import sys - - -def main(): - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc - execute_from_command_line(sys.argv) - - -if __name__ == '__main__': - main() diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/__init__.py b/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/__init__.py deleted file mode 100755 index e69de29bb..000000000 diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py b/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py deleted file mode 100755 index 7eb3685c4..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py +++ /dev/null @@ -1,136 +0,0 @@ -""" -Django settings for mysite project. - -Generated by 'django-admin startproject' using Django 2.2.2. - -For more information on this file, see -https://docs.djangoproject.com/en/2.2/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.2/ref/settings/ -""" - -import os -from django.conf.global_settings import STATIC_ROOT - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '8m05#6yx5wcygj*a+v6+=-y(#o+(z58-3!epq$u@5)64!mmu8q' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = ['*'] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - - - 'devices', -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'mysite.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'mysite.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/2.2/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - - -# Password validation -# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/2.2/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - -APPEND_SLASH = False - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/2.2/howto/static-files/ - -STATIC_URL = '/static/' -HERE = os.path.dirname(os.path.abspath(__file__)) -HERE = os.path.join(HERE,'../') -STATICFILES_DIRS = (os.path.join(HERE,'static/'),) -#STATICFILES_DIRS = (os.path.join(BASE_DIR,'static'),) -#STATIC_ROOT = (os.path.join(os.path.dirname(_file_),'static') -#templates -TEMPLATE_DIRS=[ - '/home/xujun/mysite/templates', -] - diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py b/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py deleted file mode 100755 index 8a74b5509..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py +++ /dev/null @@ -1,41 +0,0 @@ -#config:utf-8 - -"""mysite URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/2.2/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" -from django.contrib import admin -#from django.conf.urls import include,url -from django.urls import path,include -from devices import views as devices_views -#from login import views as login_views - - -urlpatterns = [ - - path('admin/', admin.site.urls), - path('',devices_views.index), - path('apps/',devices_views.apps), - path('appDownload/', devices_views.appDownload), - path('appDelete/', devices_views.appDelete), - path('appstore/',devices_views.store), -## path('apps/appstore/',devices_views.storeofdevic), -## path('search/',devices_views.search), - path('upload',devices_views.uploadapps), - path('removeapps/',devices_views.removeapps), - path('help/',devices_views.help), - -] - - diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py b/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py deleted file mode 100755 index 45e28c9a1..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for mysite project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') - -application = get_wsgi_application() diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile b/test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile deleted file mode 100644 index 371fa45b0..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM python:3.5 - -WORKDIR /app -COPY server/wasm_server.py /app/server/ - -ENTRYPOINT ["python", "server/wasm_server.py"] diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py b/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py deleted file mode 100755 index 970ec6f60..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py +++ /dev/null @@ -1,621 +0,0 @@ -''' - /* Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -''' -import select -import socket -import queue -from time import sleep -import struct -import threading -import time -from ctypes import * -import json -import logging -import os - -attr_type_list = [ - "ATTR_TYPE_BYTE", # = ATTR_TYPE_INT8 - "ATTR_TYPE_SHORT",# = ATTR_TYPE_INT16 - "ATTR_TYPE_INT", # = ATTR_TYPE_INT32 - "ATTR_TYPE_INT64", - "ATTR_TYPE_UINT8", - "ATTR_TYPE_UINT16", - "ATTR_TYPE_UINT32", - "ATTR_TYPE_UINT64", - "ATTR_TYPE_FLOAT", - "ATTR_TYPE_DOUBLE", - "ATTR_NONE", - "ATTR_NONE", - "ATTR_TYPE_BOOLEAN", - "ATTR_TYPE_STRING", - "ATTR_TYPE_BYTEARRAY" -] - - -Phase_Non_Start = 0 -Phase_Leading = 1 -Phase_Type = 2 -Phase_Size = 3 -Phase_Payload = 4 - - - -class imrt_link_message(object): - def __init__(self): - self.leading = bytes([0x12, 0x34]) - self.phase = Phase_Non_Start - self.size_in_phase = 0 - self.message_type = bytes() - self.message_size = bytes() - self.payload = bytes() - self.msg = bytes() - - def set_recv_phase(self, phase): - self.phase = phase - - def on_imrt_link_byte_arrive(self, ch): - self.msg += ch - if self.phase == Phase_Non_Start: - if ch == b'\x12': - self.set_recv_phase(Phase_Leading) - else: - return -1 - elif self.phase == Phase_Leading: - if ch == b'\x34': - self.set_recv_phase(Phase_Type) - else: - self.set_recv_phase(Phase_Non_Start) - return -1 - elif self.phase == Phase_Type: - self.message_type += ch - self.size_in_phase += 1 - - if self.size_in_phase == 2: - (self.message_type, ) = struct.unpack('!H', self.message_type) - self.size_in_phase = 0 - self.set_recv_phase(Phase_Size) - elif self.phase == Phase_Size: - self.message_size += ch - self.size_in_phase += 1 - - if self.size_in_phase == 4: - (self.message_size, ) = struct.unpack('!I', self.message_size) - self.size_in_phase = 0 - self.set_recv_phase(Phase_Payload) - - if self.message_size == b'\x00': - self.set_recv_phase(Phase_Non_Start) - return 0 - - self.set_recv_phase(Phase_Payload) - - elif self.phase == Phase_Payload: - self.payload += ch - self.size_in_phase += 1 - - if self.size_in_phase == self.message_size: - self.set_recv_phase(Phase_Non_Start) - return 0 - - return 2 - - return 1 - - - -def read_file_to_buffer(file_name): - file_object = open(file_name, 'rb') - buffer = None - - if not os.path.exists(file_name): - logging.error("file {} not found.".format(file_name)) - return "file not found" - - try: - buffer = file_object.read() - finally: - file_object.close() - - return buffer - -def decode_attr_container(msg): - - attr_dict = {} - - buf = msg[26 : ] - (total_len, tag_len) = struct.unpack('@IH', buf[0 : 6]) - tag_name = buf[6 : 6 + tag_len].decode() - buf = buf[6 + tag_len : ] - (attr_num, ) = struct.unpack('@H', buf[0 : 2]) - buf = buf[2 : ] - - logging.info("parsed attr:") - logging.info("total_len:{}, tag_len:{}, tag_name:{}, attr_num:{}" - .format(str(total_len), str(tag_len), str(tag_name), str(attr_num))) - - for i in range(attr_num): - (key_len, ) = struct.unpack('@H', buf[0 : 2]) - key_name = buf[2 : 2 + key_len - 1].decode() - buf = buf[2 + key_len : ] - (type_index, ) = struct.unpack('@c', buf[0 : 1]) - - attr_type = attr_type_list[int(type_index[0])] - buf = buf[1 : ] - - if attr_type == "ATTR_TYPE_BYTE": # = ATTR_TYPE_INT8 - (attr_value, ) = struct.unpack('@c', buf[0 : 1]) - buf = buf[1 : ] - # continue - elif attr_type == "ATTR_TYPE_SHORT": # = ATTR_TYPE_INT16 - (attr_value, ) = struct.unpack('@h', buf[0 : 2]) - buf = buf[2 : ] - # continue - elif attr_type == "ATTR_TYPE_INT": # = ATTR_TYPE_INT32 - (attr_value, ) = struct.unpack('@i', buf[0 : 4]) - buf = buf[4 : ] - # continue - elif attr_type == "ATTR_TYPE_INT64": - (attr_value, ) = struct.unpack('@q', buf[0 : 8]) - buf = buf[8 : ] - # continue - elif attr_type == "ATTR_TYPE_UINT8": - (attr_value, ) = struct.unpack('@B', buf[0 : 1]) - buf = buf[1 : ] - # continue - elif attr_type == "ATTR_TYPE_UINT16": - (attr_value, ) = struct.unpack('@H', buf[0 : 2]) - buf = buf[2 : ] - # continue - elif attr_type == "ATTR_TYPE_UINT32": - (attr_value, ) = struct.unpack('@I', buf[0 : 4]) - buf = buf[4 : ] - # continue - elif attr_type == "ATTR_TYPE_UINT64": - (attr_value, ) = struct.unpack('@Q', buf[0 : 8]) - buf = buf[8 : ] - # continue - elif attr_type == "ATTR_TYPE_FLOAT": - (attr_value, ) = struct.unpack('@f', buf[0 : 4]) - buf = buf[4 : ] - # continue - elif attr_type == "ATTR_TYPE_DOUBLE": - (attr_value, ) = struct.unpack('@d', buf[0 : 8]) - buf = buf[8 : ] - # continue - elif attr_type == "ATTR_TYPE_BOOLEAN": - (attr_value, ) = struct.unpack('@?', buf[0 : 1]) - buf = buf[1 : ] - # continue - elif attr_type == "ATTR_TYPE_STRING": - (str_len, ) = struct.unpack('@H', buf[0 : 2]) - attr_value = buf[2 : 2 + str_len - 1].decode() - buf = buf[2 + str_len : ] - # continue - elif attr_type == "ATTR_TYPE_BYTEARRAY": - (byte_len, ) = struct.unpack('@I', buf[0 : 4]) - attr_value = buf[4 : 4 + byte_len] - buf = buf[4 + byte_len : ] - # continue - - attr_dict[key_name] = attr_value - - logging.info(str(attr_dict)) - return attr_dict - -class Request(): - mid = 0 - url = "" - action = 0 - fmt = 0 - payload = "" - payload_len = 0 - sender = 0 - - def __init__(self, url, action, fmt, payload, payload_len): - self.url = url - self.action = action - self.fmt = fmt - # if type(payload) == bytes: - # self.payload = bytes(payload, encoding = "utf8") - # else: - self.payload_len = payload_len - if self.payload_len > 0: - self.payload = payload - - - def pack_request(self): - url_len = len(self.url) + 1 - buffer_len = url_len + self.payload_len - - req_buffer = struct.pack('!2BH2IHI',1, self.action, self.fmt, self.mid, self.sender, url_len, self.payload_len) - for i in range(url_len - 1): - req_buffer += struct.pack('!c', bytes(self.url[i], encoding = "utf8")) - req_buffer += bytes([0]) - for i in range(self.payload_len): - req_buffer += struct.pack('!B', self.payload[i]) - - return req_buffer, len(req_buffer) - - - def send(self, conn, is_install): - leading = struct.pack('!2B', 0x12, 0x34) - - if not is_install: - msg_type = struct.pack('!H', 0x0002) - else: - msg_type = struct.pack('!H', 0x0004) - buff, buff_len = self.pack_request() - lenth = struct.pack('!I', buff_len) - - try: - conn.send(leading) - conn.send(msg_type) - conn.send(lenth) - conn.send(buff) - except socket.error as e: - logging.error("device closed") - for dev in tcpserver.devices: - if dev.conn == conn: - tcpserver.devices.remove(dev) - return -1 - - -def query(conn): - req = Request("/applet", 1, 0, "", 0) - if req.send(conn, False) == -1: - return "fail" - time.sleep(0.05) - try: - receive_context = imrt_link_message() - start = time.time() - while True: - if receive_context.on_imrt_link_byte_arrive(conn.recv(1)) == 0: - break - elif time.time() - start >= 5.0: - return "fail" - query_resp = receive_context.msg - print(query_resp) - except OSError as e: - logging.error("OSError exception occur") - return "fail" - - res = decode_attr_container(query_resp) - - logging.info('Query device infomation success') - return res - -def install(conn, app_name, wasm_file): - wasm = read_file_to_buffer(wasm_file) - if wasm == "file not found": - return "failed to install: file not found" - - print("wasm file len:") - print(len(wasm)) - req = Request("/applet?name=" + app_name, 3, 98, wasm, len(wasm)) - if req.send(conn, True) == -1: - return "fail" - time.sleep(0.05) - try: - receive_context = imrt_link_message() - start = time.time() - while True: - if receive_context.on_imrt_link_byte_arrive(conn.recv(1)) == 0: - break - elif time.time() - start >= 5.0: - return "fail" - msg = receive_context.msg - except OSError as e: - logging.error("OSError exception occur") - # TODO: check return message - - if len(msg) == 24 and msg[8 + 1] == 65: - logging.info('Install application success') - return "success" - else: - res = decode_attr_container(msg) - logging.warning('Install application failed: %s' % (str(res))) - print(str(res)) - - return str(res) - - -def uninstall(conn, app_name): - req = Request("/applet?name=" + app_name, 4, 99, "", 0) - if req.send(conn, False) == -1: - return "fail" - time.sleep(0.05) - try: - receive_context = imrt_link_message() - start = time.time() - while True: - if receive_context.on_imrt_link_byte_arrive(conn.recv(1)) == 0: - break - elif time.time() - start >= 5.0: - return "fail" - msg = receive_context.msg - except OSError as e: - logging.error("OSError exception occur") - # TODO: check return message - - if len(msg) == 24 and msg[8 + 1] == 66: - logging.info('Uninstall application success') - return "success" - else: - res = decode_attr_container(msg) - logging.warning('Uninstall application failed: %s' % (str(res))) - print(str(res)) - - return str(res) - -class Device: - def __init__(self, conn, addr, port): - self.conn = conn - self.addr = addr - self.port = port - self.app_num = 0 - self.apps = [] - -cmd = [] - -class TCPServer: - def __init__(self, server, server_address, inputs, outputs, message_queues): - # Create a TCP/IP - self.server = server - self.server.setblocking(False) - - # Bind the socket to the port - self.server_address = server_address - print('starting up on %s port %s' % self.server_address) - self.server.bind(self.server_address) - - # Listen for incoming connections - self.server.listen(10) - - self.cmd_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.cmd_sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) - - self.cmd_sock.bind(('127.0.0.1', 8889)) - self.cmd_sock.listen(5) - - - # Sockets from which we expect to read - self.inputs = inputs - self.inputs.append(self.cmd_sock) - - # Sockets to which we expect to write - # 处理要发送的消息 - self.outputs = outputs - # Outgoing message queues (socket: Queue) - self.message_queues = message_queues - - self.devices = [] - self.conn_dict = {} - - def handler_recever(self, readable): - # Handle inputs - for s in readable: - if s is self.server: - # A "readable" socket is ready to accept a connection - connection, client_address = s.accept() - self.client_address = client_address - print('connection from', client_address) - # this is connection not server - # connection.setblocking(0) - self.inputs.append(connection) - - # Give the connection a queue for data we want to send - # self.message_queues[connection] = queue.Queue() - - res = query(connection) - - if res != "fail": - dev = Device(connection, client_address[0], client_address[1]) - self.devices.append(dev) - self.conn_dict[client_address] = connection - - dev_info = {} - dev_info['addr'] = dev.addr - dev_info['port'] = dev.port - dev_info['apps'] = 0 - - logging.info('A new client connected from ("%s":"%s")' % (dev.conn, dev.port)) - - elif s is self.cmd_sock: - connection, client_address = s.accept() - print("web server socket connected") - logging.info("Django server connected") - self.inputs.append(connection) - self.message_queues[connection] = queue.Queue() - - else: - data = s.recv(1024) - if data != b'': - # A readable client socket has data - logging.info('received "%s" from %s' % (data, s.getpeername())) - - # self.message_queues[s].put(data) - # # Add output channel for response - - # if s not in self.outputs: - # self.outputs.append(s) - - if(data.decode().split(':')[0] == "query"): - if data.decode().split(':')[1] == "all": - resp = [] - print('start query all devices') - for dev in self.devices: - dev_info = query(dev.conn) - if dev_info == "fail": - continue - dev_info["addr"] = dev.addr - dev_info["port"] = dev.port - resp.append(str(dev_info)) - - print(resp) - - if self.message_queues[s] is not None: - # '*' is used in web server to sperate the string - self.message_queues[s].put(bytes("*".join(resp), encoding = 'utf8')) - if s not in self.outputs: - self.outputs.append(s) - else: - client_addr = (data.decode().split(':')[1],int(data.decode().split(':')[2])) - - if client_addr in self.conn_dict.keys(): - print('start query device from (%s:%s)' % (client_addr[0], client_addr[1])) - resp = query(self.conn_dict[client_addr]) - print(resp) - - if self.message_queues[s] is not None: - self.message_queues[s].put(bytes(str(resp), encoding = 'utf8')) - if s not in self.outputs: - self.outputs.append(s) - else: # no connection - if self.message_queues[s] is not None: - self.message_queues[s].put(bytes(str("fail"), encoding = 'utf8')) - if s not in self.outputs: - self.outputs.append(s) - elif(data.decode().split(':')[0] == "install"): - client_addr = (data.decode().split(':')[1],int(data.decode().split(':')[2])) - app_name = data.decode().split(':')[3] - app_file = data.decode().split(':')[4] - - if client_addr in self.conn_dict.keys(): - print('start install application %s to ("%s":"%s")' % (app_name, client_addr[0], client_addr[1])) - res = install(self.conn_dict[client_addr], app_name, app_file) - if self.message_queues[s] is not None: - logging.info("response {} to cmd server".format(res)) - self.message_queues[s].put(bytes(res, encoding = 'utf8')) - if s not in self.outputs: - self.outputs.append(s) - elif(data.decode().split(':')[0] == "uninstall"): - client_addr = (data.decode().split(':')[1],int(data.decode().split(':')[2])) - app_name = data.decode().split(':')[3] - - if client_addr in self.conn_dict.keys(): - print("start uninstall") - res = uninstall(self.conn_dict[client_addr], app_name) - if self.message_queues[s] is not None: - logging.info("response {} to cmd server".format(res)) - self.message_queues[s].put(bytes(res, encoding = 'utf8')) - if s not in self.outputs: - self.outputs.append(s) - - - # if self.message_queues[s] is not None: - # self.message_queues[s].put(data) - # if s not in self.outputs: - # self.outputs.append(s) - else: - logging.warning(data) - - # Interpret empty result as closed connection - try: - for dev in self.devices: - if s == dev.conn: - self.devices.remove(dev) - # Stop listening for input on the connection - if s in self.outputs: - self.outputs.remove(s) - self.inputs.remove(s) - - # Remove message queue - if s in self.message_queues.keys(): - del self.message_queues[s] - s.close() - except OSError as e: - logging.error("OSError raised, unknown connection") - return "got it" - - def handler_send(self, writable): - # Handle outputs - for s in writable: - try: - message_queue = self.message_queues.get(s) - send_data = '' - if message_queue is not None: - send_data = message_queue.get_nowait() - except queue.Empty: - self.outputs.remove(s) - else: - # print "sending %s to %s " % (send_data, s.getpeername) - # print "send something" - if message_queue is not None: - s.send(send_data) - else: - print("client has closed") - # del message_queues[s] - # writable.remove(s) - # print "Client %s disconnected" % (client_address) - return "got it" - - def handler_exception(self, exceptional): - # # Handle "exceptional conditions" - for s in exceptional: - print('exception condition on', s.getpeername()) - # Stop listening for input on the connection - self.inputs.remove(s) - if s in self.outputs: - self.outputs.remove(s) - s.close() - - # Remove message queue - del self.message_queues[s] - return "got it" - - -def event_loop(tcpserver, inputs, outputs): - while inputs: - # Wait for at least one of the sockets to be ready for processing - print('waiting for the next event') - readable, writable, exceptional = select.select(inputs, outputs, inputs) - if readable is not None: - tcp_recever = tcpserver.handler_recever(readable) - if tcp_recever == 'got it': - print("server have received") - if writable is not None: - tcp_send = tcpserver.handler_send(writable) - if tcp_send == 'got it': - print("server have send") - if exceptional is not None: - tcp_exception = tcpserver.handler_exception(exceptional) - if tcp_exception == 'got it': - print("server have exception") - - - sleep(0.1) - -def run_wasm_server(): - server_address = ('localhost', 8888) - server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) - inputs = [server] - outputs = [] - message_queues = {} - tcpserver = TCPServer(server, server_address, inputs, outputs, message_queues) - - task = threading.Thread(target=event_loop,args=(tcpserver,inputs,outputs)) - task.start() - -if __name__ == '__main__': - logging.basicConfig(level=logging.DEBUG, - filename='wasm_server.log', - filemode='a', - format= - '%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s' - ) - server_address = ('0.0.0.0', 8888) - server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) - inputs = [server] - outputs = [] - message_queues = {} - tcpserver = TCPServer(server, server_address, inputs, outputs, message_queues) - logging.info("TCP Server start at {}:{}".format(server_address[0], "8888")) - - task = threading.Thread(target=event_loop,args=(tcpserver,inputs,outputs)) - task.start() - - # event_loop(tcpserver, inputs, outputs) \ No newline at end of file diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css b/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css deleted file mode 100644 index 220d4b618..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css +++ /dev/null @@ -1,400 +0,0 @@ -/* Copyright (C) 2019 Intel Corporation. All rights reserved. -* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -*/ - -{% load static %} - diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js b/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js deleted file mode 100644 index 0510fb901..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js +++ /dev/null @@ -1,217 +0,0 @@ -/* Copyright (C) 2019 Intel Corporation. All rights reserved. -* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -*/ - -/* - * Dom Location - * - */ - - function setDivCenter(divname) -// make qn element center aligned - { - var Top =($(window).height()-$(divname).height())/2; - var Left = ($(window).width()-$(divname).width())/2; - var scrollTop = $(document).scrollTop(); - var scrollLeft = $(document).scrollLeft(); - $(divname).css({posisiton:'absolute','top':Top+scrollTop,'left':Left+scrollLeft}); - -}; - -setDivCenter(".middlebox"); -setDivCenter(".deletebox"); - -function setmain(divname){ -// Set the pop-up window of apps for download at the right place - var x = $('#btn').offset().top; - var Top = x + $('#btn').height()+15; - var y = $('#btn').offset().left; - var Left = y + ($('#btn').width()/2)-($(divname).width()/2); - console.log(Top,Left) - $(divname).css({'top':Top,'left':Left}); -} -setmain(".main") - -/* - * download apps - * - */ - -function getthis(val) -//Telling background which app to be loaded from appstore_list and to be installed in the current device. -{ - - /* Get the ip adress and the port of a device, as well as the application ID to be downloaded on this device*/ - var ip,port,name,version; - var ipArr=$("#IPs").text().split(":"); - ip=ipArr[1]; - var portArr=$("#ports").text().split(":"); - port=portArr[1]; - name = $(val).parent().find("#appsinfo1").text().split(":")[1]; - version = $(val).parent().find("#appsinfo2").text().split(":")[1]; - $(".main").fadeOut(); - - for (num in alist){ - if (alist[num]['pname'].trim() == name.trim()) - {alert("This app has been downloaded."); - return;}}; - $("#loading").fadeIn(); - var sNode = document.getElementById("APPS"); - var tempNode= sNode.cloneNode(true); - sNode.parentNode.appendChild(tempNode); - $("#appinfo1").html("Product Name : "+ name); - $("#appinfo2").html("Status : "+"Installing"); - $("#appinfo3").html("Current_Version : "+ version); - - $.get("/appDownload/",{'ip':ip.trim(),'port':port.trim(),'name':name.trim(),},function (ret) { - var status = $.trim(ret.split(":")[1].split("}")[0]); - $(".loadapp").html(name+" is downloading now"); - var msg = JSON.parse(status) - console.log(msg) - if (JSON.parse(status)=="ok"){ - $(".middlebox").fadeIn(); - $(".sourceapp").fadeOut(); - $("#loading").fadeOut(); - $(".findapp").html("Download "+name +" successfully"); - $(".surebtn").click(function (){ - $(".middlebox").fadeOut(); - window.location.reload(); - })} - else if (JSON.parse(status)=="Fail!"){ - alert("Download failed!"); - $("#loading").fadeOut(); - sNode.remove(); - } - else { - alert("Install app failed:" + msg) - $("#loading").fadeOut(); - sNode.remove(); - } - }) -}; - -window.onload = function clone() -//Add & Delete apps to the device. -{ - /*Install Apps*/ - var sourceNode = document.getElementById("APPS"); - if (alist.length != 0) - { - $("#appinfo1").html("Product Name : "+ alist[0]['pname']); - $("#appinfo2").html("Status : "+ alist[0]['status']); - $("#appinfo3").html("Current_Version : "+ alist[0]['current_version']); - $("#delete").attr('class','delet0'); - $("#APPS").attr('class','app0'); - - for (var i=1; i=3){ - alert("Install app failed: exceed max app installations.") - } - $(".main").fadeOut(); - getthis(".mybtn2"); - var newurl = "?"+"ip="+ip+"&port="+port; - window.location.href= newurl; - }); - - } -} -givevalue(); - -function popbox(){ -/*Open and close the "install apps" window*/ - $(".btn").click(function(){ - $(".main").fadeIn(); - }); - $(".close").click(function(){ - $(".main").fadeOut(); - }); -}; -popbox(); diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js b/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js deleted file mode 100644 index 71d029efa..000000000 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright (C) 2019 Intel Corporation. All rights reserved. -* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -*/ - -function setDivCenter(divname) -//Center a dom -{ - var Top =($(window).height()-$(divname).height())/2; - var Left = ($(window).width()-$(divname).width())/2; - var scrollTop = $(document).scrollTop(); - var scrollLeft = $(document).scrollLeft(); - $(divname).css({posisiton:'absolute','top':Top+scrollTop,'left':Left+scrollLeft}); - -}; -setDivCenter(".deletebox"); - -function setDivheight(divname) -//set the height of "appbook" to contain all its child elements. -{ - var leng = elist.length + flist.length; - var heig = 51 * leng; - $(divname).css({height:'heig'}); -}; -setDivheight(".appbook"); - -function setfooterposition(divname) -//Locate footer on the right place -{ - var Top = flist.length* $("#devices").height()+300; - var scrollTop = $(document).scrollTop(); - if (flist.length >=4){ - $(divname).css({posisiton:'absolute','top':Top+scrollTop}); - } -} -setfooterposition(".footer"); - -function deleteClick (obj) -//Remove an app from apppstore if clicks the "OK" button -{ - var indexapp = $(obj).attr('class').match(/\d+\b/); - var removeitem = $(".applic"+indexapp); - var name=removeitem.find('#appinfo1').text().split(":")[1].trim(); - var version=removeitem.find('#appinfo2').text().split(":")[1].trim(); - - if (flist.length >= 1){ - $(".deletebox").fadeIn(); - $(".findapp").html("Are you sure to delete "+name); - $(".suresbtn").click(function (){ - removeitem.remove(); - $.get("/removeapps/",{'name':name,'version':version},function (ret) { - console.log(ret);}); - $(".deletebox").fadeOut(); - window.location.href="/appstore/"; - }) - $(".delsbtn").click(function (){ - $(".deletebox").fadeOut(); })} -}; - -function upload_file() -//Make sure the uploading file is eligible -{ - var type = ulist[0]; - console.log(type); - if (type == "Not a wasm file"){ - alert(type); - window.location.href="/appstore/"; - } - if (type == "This App is preloaded"){ - alert(type); - window.location.href="/appstore/"; - } - if (type == "This App is already uploaded"){ - alert(type); - window.location.href="/appstore/"; - } -}; -upload_file(); - - -function clone() -//Render a interface that shows all the apps for installing in appstore, -//including preloaded ones and locally uploaded ones. -{ - - var sourceNode = document.getElementById("applications"); - $("#appinfo1").html("product name : "+ elist[0]['ID']); - $("#appinfo2").html("product Version : "+ elist[0]['Version']); - $("#delbutton").attr('class','del0'); - $("#applications").attr('class','applic0'); - - - for (var i=1; i=4){ - $(divname).css({posisiton:'absolute','top':Top+scrollTop}); - } -} -setfooterposition(".footer"); - -window.onload = function clone() -//Show the list of connected devices -{ - var sourceNode = document.getElementById("devices"); - $("#IPs").html("IP : "+ dlist[0]['IP']); - $("#ports").html("Port : "+ dlist[0]['Port']); - $("#installs").html("Installed Apps : "+ dlist[0]['apps']); - $("#devices").attr('class','devic0'); - $("#dbutton").attr('class','bt0'); - $("#choose").attr('class','chos0'); - - for (var i=1; i>start run [" + case + "] >>") - module_name = 'suites.' + suite + ".cases." + case + ".case" - try: - module = my_import(module_name) - except Exception as e: - report_fail("load case fail: " + str(e)) - api_log_error("load case fail: " + str(e)) - self.load_fails = self.load_fails +1 - print(traceback.format_exc()) - return False - - try: - case = module.CTestCase(suite_instance) - except Exception as e: - report_fail("initialize case fail: " + str(e)) - api_log_error("initialize case fail: " + str(e)) - self.load_fails = self.load_fails +1 - return False - - # call the case on setup callback - try: - case_description = case.on_get_case_description() - result, message = case.on_setup_case() - except Exception as e: - result = False - message = str(e); - if not result: - api_log_error(message) - report_fail (message, case_description) - self.failed_cases = self.failed_cases+1 - return False - - # call the case execution callaback - try: - result, message = case.on_run_case() - except Exception as e: - result = False - message = str(e); - if not result: - report_fail (message, case_description) - api_log_error(message) - self.failed_cases = self.failed_cases+1 - else: - report_success(case_description) - self.sucess_cases = self.sucess_cases +1 - - # call the case cleanup callback - try: - clean_result, message = case.on_cleanup_case() - except Exception as e: - clean_result = False - message = str(e) - - if not clean_result: - api_log(message) - - return result - - def run_suite(self, suite, cases): - # suite setup - message = '' - api_log("\n>>> Suite [" + suite + "] starting >>>") - running_folder = self.get_running_path()+ "/suites/" + suite; - - module_name = 'suites.' + suite + ".suite_setup" - try: - module = my_import(module_name) - except Exception as e: - report_fail("load suite [" + suite +"] fail: " + str(e)) - self.load_fails = self.load_fails +1 - return False - - try: - suite_instance = module.CTestSuite(suite, \ - self.root_path + '/suites/' + suite, running_folder) - except Exception as e: - report_fail("initialize suite fail: " + str(e)) - self.load_fails = self.load_fails +1 - return False - - result, message = suite_instance.load_settings() - if not result: - report_fail("load settings fail: " + str(e)) - self.load_fails = self.load_fails +1 - return False - - try: - result, message = suite_instance.on_suite_setup() - except Exception as e: - result = False - message = str(e); - if not result: - api_log_error(message) - report_fail (message) - self.setup_fails = self.setup_fails + 1 - return False - - self.running_suite = suite - - cases.sort() - - # run cases - for case in cases: - if not os.path.isdir(self.root_path + '/suites/' + suite + '/cases/' + case): - continue - - self.running_case = case - self.run_case(suite_instance, case) - self.running_case = '' - - # suites cleanup - self.running_suite = '' - try: - result, message = suite_instance.on_suite_cleanup() - except Exception as e: - result = False - message = str(e); - if not result: - api_log_error(message) - report_fail (message) - self.setup_fails = self.setup_fails + 1 - return - - def start_run(self): - if self.target_suites is None: - print("\n\nstart run: no target suites, exit..") - return - - cur_time = time.localtime() - time_prefix = "{:02}-{:02}-{:02}-{:02}".format( - cur_time.tm_mon, cur_time.tm_mday, cur_time.tm_hour, cur_time.tm_min) - - debug = api_get_value('debug', False) - if debug: - self.running_folder = 'debug' - else: - self.running_folder = 'run-' + time_prefix - - folder = self.root_path + "/run/" +self.running_folder; - - if os.path.exists(folder): - shutil.rmtree(folder, ignore_errors=True) - - if not os.path.exists(folder): - os.makedirs(folder ) - os.makedirs(folder + "/suites") - - api_init_log(folder + "/test.log") - - self.report = open(folder + "/report.txt", 'a') - - self.target_suites.sort() - - for suite in self.target_suites: - if not os.path.isdir(self.root_path + '/suites/' + suite): - continue - self.report.write("suite " + suite + " cases:\n") - if self.target_cases is None: - cases = os.listdir(self.root_path + "/suites/" + suite + "/cases") - self.run_suite(suite, cases) - else: - self.run_suite(suite, self.target_cases) - self.report.write("\n") - - self.report.write("\n\n") - summary = self.gen_execution_stats() - self.report.write(summary); - self.report.flush() - self.report.close() - print(summary) - - -def report_fail(message, case_description=''): - global framework - if framework is not None: - framework.report_result(False, message, case_description) - - api_log_error(message) - - return - -def report_success(case_description=''): - global framework - if framework is not None: - framework.report_result(True , "OK", case_description) - return diff --git a/test-tools/component-test/framework/suite.py b/test-tools/component-test/framework/suite.py deleted file mode 100644 index 2b690b08f..000000000 --- a/test-tools/component-test/framework/suite.py +++ /dev/null @@ -1,40 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import os -import json - -class CTestSuiteBase(object): - def __init__(self, name, suite_path, run_path): - self.suite_path=suite_path - self.run_path=run_path - self.m_name = name - self.settings = {} - - def get_settings_item(self, item): - if item in self.settings: - return self.settings[item] - else: - return None - - def load_settings(self): - path = self.suite_path + "/settings.cfg" - if os.path.isfile(path): - try: - fp = open(path, 'r') - self.settings = json.load(fp) - fp.close() - except Exception, e: - return False, 'Load settings fail: ' + e.message - return True, 'OK' - else: - return True, 'No file' - - def on_suite_setup(self): - return True, 'OK' - - def on_suite_cleanup(self): - return True, 'OK' - diff --git a/test-tools/component-test/framework/test_api.py b/test-tools/component-test/framework/test_api.py deleted file mode 100644 index 82a7e6dd0..000000000 --- a/test-tools/component-test/framework/test_api.py +++ /dev/null @@ -1,99 +0,0 @@ -from __future__ import print_function -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import logging -import threading -from .test_utils import * - -global logger -logger = None - -def api_init_log(log_path): - global logger - print("api_init_log: " + log_path) - logger = logging.getLogger(__name__) - - logger.setLevel(level = logging.INFO) - handler = logging.FileHandler(log_path) - handler.setLevel(logging.INFO) - formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') - handler.setFormatter(formatter) - - console = logging.StreamHandler() - console.setLevel(logging.INFO) - - logger.addHandler(handler) - logger.addHandler(console) - - return - -def api_log(message): - global logger - if logger is None: - print(message) - else: - logger.info (message) - return - -def api_log_error(message): - global logger - if logger is None: - print(message) - else: - logger.error (message) - return - -def api_logv(message): - global logger - if logger is None: - print(message) - else: - logger.info(message) - return - -#####################################3 -global g_case_runner_event -def api_wait_case_event(timeout): - global g_case_runner_event - g_case_runner_event.clear() - g_case_runner_event.wait(timeout) - -def api_notify_case_runner(): - global g_case_runner_event - g_case_runner_event.set() - -def api_create_case_event(): - global g_case_runner_event - g_case_runner_event = threading.Event() - -####################################### - -def api_init_globals(): - global _global_dict - _global_dict = {} - -def api_set_value(name, value): - _global_dict[name] = value - -def api_get_value(name, defValue=None): - try: - return _global_dict[name] - except KeyError: - return defValue - - -######################################### -global root_path -def api_set_root_path(root): - global root_path - root_path = root - -def api_get_root_path(): - global root_path - return root_path; - - - diff --git a/test-tools/component-test/framework/test_utils.py b/test-tools/component-test/framework/test_utils.py deleted file mode 100644 index e3eb645ae..000000000 --- a/test-tools/component-test/framework/test_utils.py +++ /dev/null @@ -1,71 +0,0 @@ -from __future__ import print_function -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import datetime -import os -import random -import re -import shlex -import subprocess -import sys -import time -import shutil -from subprocess import check_output, CalledProcessError - -def t_getPIDs(process): - try: - pidlist = map(int, check_output(["pidof", process]).split()) - except CalledProcessError: - pidlist = [] - #print process + ':list of PIDs = ' + ', '.join(str(e) for e in pidlist) - return pidlist - - -def t_kill_process_by_name(p_keywords): - pid_list = [] - ps_info = subprocess.check_output(shlex.split("ps aux")).split("\n") - for p in ps_info: - if p_keywords in p: - tmp = p.split(" ") - tmp = [x for x in tmp if len(x) > 0] - pid_list.append(tmp[1]) - - for pid in pid_list: - cmd = "kill -9 {}".format(pid) - subprocess.call(shlex.split(cmd)) - - return pid_list - - - -#proc -> name of the process -#kill = 1 -> search for pid for kill -#kill = 0 -> search for name (default) - -def t_process_exists(proc, kill = 0): - ret = False - processes = t_getPIDs(proc) - - for pid in processes: - if kill == 0: - return True - else: - print("kill [" + proc + "], pid=" + str(pid)) - os.kill((pid), 9) - ret = True - return ret - -def t_copy_files(source_dir, pattern, dest_dir): - files = os.listdir(source_dir) - for file in files: - if file in ('/', '.', '..'): - continue - - if pattern in ('*', '') or files.endswith(pattern): - shutil.copy(source_dir+"/"+ file, dest_dir) - - - diff --git a/test-tools/component-test/harness/__init__.py b/test-tools/component-test/harness/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/harness/harness_api.py b/test-tools/component-test/harness/harness_api.py deleted file mode 100644 index e35aa6b4c..000000000 --- a/test-tools/component-test/harness/harness_api.py +++ /dev/null @@ -1,150 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import os -import shutil -import subprocess -import json -import time - -from framework import test_api -from framework.test_utils import * - -output = "output.txt" - -def start_env(): - os.system("./start.sh") - -def stop_env(): - os.system("./stop.sh") - time.sleep(0.5) - os.chdir("../") #reset path for other cases in the same suite - -def check_is_timeout(): - line_num = 0 - ft = open(output, 'r') - lines = ft.readlines() - - for line in reversed(lines): - if (line[0:36] == "--------one operation begin.--------"): - break - line_num = line_num + 1 - - ft.close() - if (lines[-(line_num)] == "operation timeout"): - return True - else: - return False - -def parse_ret(file): - ft = open(file, 'a') - ft.writelines("\n") - ft.writelines("--------one operation finish.--------") - ft.writelines("\n") - ft.close() - - ft = open(file, 'r') - for line in reversed(ft.readlines()): - if (line[0:16] == "response status "): - ret = line[16:] - ft.close() - return int(ret) - -def run_host_tool(cmd, file): - ft = open(file, 'a') - ft.writelines("--------one operation begin.--------") - ft.writelines("\n") - ft.close() - os.system(cmd + " -o" + file) - if (check_is_timeout() == True): - return -1 - return parse_ret(file) - -def install_app(app_name, file_name): - return run_host_tool("./host_tool -i " + app_name + " -f ../test-app/" + file_name, output) - -def uninstall_app(app_name): - return run_host_tool("./host_tool -u " + app_name, output) - -def query_app(): - return run_host_tool("./host_tool -q ", output) - -def send_request(url, action, payload): - if (payload is None): - return run_host_tool("./host_tool -r " + url + " -A " + action, output) - else: - return run_host_tool("./host_tool -r " + url + " -A " + action + " -p " + payload, output) - -def register(url, timeout, alive_time): - return run_host_tool("./host_tool -s " + url + " -t " + str(timeout) + " -a " + str(alive_time), output) - -def deregister(url): - return run_host_tool("./host_tool -d " + url, output) - -def get_response_payload(): - line_num = 0 - ft = open(output, 'r') - lines = ft.readlines() - - for line in reversed(lines): - if (line[0:16] == "response status "): - break - line_num = line_num + 1 - - payload_lines = lines[-(line_num):-1] - ft.close() - - return payload_lines - -def check_query_apps(expected_app_list): - if (check_is_timeout() == True): - return False - json_lines = get_response_payload() - json_str = " ".join(json_lines) - json_dict = json.loads(json_str) - app_list = [] - - for key, value in json_dict.items(): - if key[0:6] == "applet": - app_list.append(value) - - if (sorted(app_list) == sorted(expected_app_list)): - return True - else: - return False - -def check_response_payload(expected_payload): - if (check_is_timeout() == True): - return False - json_lines = get_response_payload() - json_str = " ".join(json_lines) - - if (json_str.strip() != ""): - json_dict = json.loads(json_str) - else: - json_dict = {} - - if (json_dict == expected_payload): - return True - else: - return False - -def check_get_event(): - line_num = 0 - ft = open(output, 'r') - lines = ft.readlines() - - for line in reversed(lines): - if (line[0:16] == "response status "): - break - line_num = line_num + 1 - - payload_lines = lines[-(line_num):-1] - ft.close() - - if (payload_lines[1][0:17] == "received an event"): - return True - else: - return False diff --git a/test-tools/component-test/host-clients/src/host_app_sample.c b/test-tools/component-test/host-clients/src/host_app_sample.c deleted file mode 100644 index c4010de6a..000000000 --- a/test-tools/component-test/host-clients/src/host_app_sample.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include -#include -#include "host_api.h" -#include "bi-inc/attr_container.h" -#include "er-coap-constants.h" - -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) -{ - if (response == NULL) { - printf("########## request timeout!!! \n"); - } - 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); - } -} - -void -f_aee_event_listener(const char *url, void *event, int fmt) -{ - printf("######## event is received. url: %s, fmt:%d ############\n", url, - fmt); - - attr_container_t *attr_obj = (attr_container_t *)event; - - attr_container_dump(attr_obj); - /* - if (0 == strcmp(url, "alert/overheat")) - { - event_listener_counter++; - printf("event :%d \n", event_listener_counter); - } - */ -} - -static int -print_menu_and_select(void) -{ - char s[256]; - int choice; - do { - printf("\n"); - printf("1. Install TestApplet1\n"); - printf("2. Install TestApplet2\n"); - printf("3. Install TestApplet3\n"); - printf("4. Uninstall TestApplet1\n"); - printf("5. Uninstall TestApplet2\n"); - printf("6. Uninstall TestApplet3\n"); - printf("7. Send Request to TestApplet1\n"); - printf("8. Register Event to TestApplet1\n"); - printf("9. UnRegister Event to TestApplet1\n"); - printf("a. Query Applets\n"); - printf("t. Auto Test\n"); - printf("q. Exit\n"); - printf("Please Select: "); - - if (fgets(s, sizeof(s), stdin)) { - if (!strncmp(s, "q", 1)) - return 0; - if (!strncmp(s, "a", 1)) - return 10; - if (!strncmp(s, "t", 1)) - return 20; - choice = atoi(s); - if (choice >= 1 && choice <= 9) - return choice; - } - } while (1); - return 0; -} - -static void -install_applet(int index) -{ - char applet_name[64]; - char applet_file_name[64]; - char *buf; - int size; - int ret; - - 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); - buf = read_file_to_buffer(applet_file_name, &size); - if (!buf) { - printf("Install Applet failed: read file %s error.\n", - applet_file_name); - return; - } - - // step2. install applet - ret = aee_applet_install(buf, "wasm", size, applet_name, 5000); - if (ret) { - printf("%s install success\n", applet_name); - } - free(buf); -} - -static void -uninstall_applet(int index) -{ - int ret; - char applet_name[64]; - snprintf(applet_name, sizeof(applet_name), "TestApplet%d", index); - ret = aee_applet_uninstall(applet_name, "wasm", 5000); - if (ret) { - printf("uninstall %s success\n", applet_name); - } - else { - printf("uninstall %s failed\n", applet_name); - } -} - -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_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 - snprintf(url, sizeof(url), "/app/TestApplet%d/url1", index); - - // 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); - - if (ret) { - printf("send request to TestApplet1 success\n"); - } -} - -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) -{ - hostclient_unregister_event(event_path); -} - -static void -query_applets() -{ - aee_applet_list_t applet_lst; - aee_applet_list_init(&applet_lst); - aee_applet_list(5000, &applet_lst); - aee_applet_list_clean(&applet_lst); -} - -static char * -read_file_to_buffer(const char *filename, int *ret_size) -{ - FILE *fl = NULL; - char *buffer = NULL; - int file_size = 0; - if (!(fl = fopen(filename, "rb"))) { - printf("file open failed\n"); - return NULL; - } - - fseek(fl, 0, SEEK_END); - file_size = ftell(fl); - - if (file_size == 0) { - printf("file length 0\n"); - return NULL; - } - - if (!(buffer = (char *)malloc(file_size))) { - fclose(fl); - return NULL; - } - - fseek(fl, 0, SEEK_SET); - - if (!fread(buffer, 1, file_size, fl)) { - printf("file read failed\n"); - return NULL; - } - - fclose(fl); - *ret_size = file_size; - return buffer; -} - -static void -auto_test() -{ - int i; - int interval = 1000; /* ms */ - while (1) { - uninstall_applet(1); - uninstall_applet(2); - uninstall_applet(3); - install_applet(1); - install_applet(2); - install_applet(3); - - for (i = 0; i < 60 * 1000 / interval; i++) { - query_applets(); - send_request(1); - send_request(2); - send_request(3); - usleep(interval * 1000); - } - } -} - -void -exit_program() -{ - hostclient_shutdown(); - exit(0); -} - -int - -main() -{ - bool ret; - - // step1. host client init - ret = hostclient_initialize(host_agent_ip, 3456); - - if (!ret) { - printf("host client initialize failed\n"); - return -1; - } - - do { - int choice = print_menu_and_select(); - printf("\n"); - - if (choice == 0) - exit_program(); - if (choice <= 3) - install_applet(choice); - else if (choice <= 6) - uninstall_applet(choice - 3); - else if (choice <= 7) - send_request(1); - else if (choice <= 8) - register_event("alert/overheat"); - else if (choice <= 9) - unregister_event("alert/overheat"); - else if (choice == 10) - query_applets(); - else if (choice == 20) - auto_test(); - } while (1); - - return 0; -} - -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu - -// Tips for Getting Started: -// 1. Use the Solution Explorer window to add/manage files -// 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 diff --git a/test-tools/component-test/host-clients/src/makefile b/test-tools/component-test/host-clients/src/makefile deleted file mode 100644 index 763a60c38..000000000 --- a/test-tools/component-test/host-clients/src/makefile +++ /dev/null @@ -1,44 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -CC = gcc -CFLAGS := -Wall -g - -# Add this to make compiler happy -CFLAGS += -DWASM_ENABLE_INTERP=1 - -host_api_c=../../../../host-agent/host-api-c -attr_container_dir=../../../../wamr/core/app-framework/app-native-shared -coap_dir=../../../../host-agent/coap -shared_dir=../../../../wamr/core/shared - -# core -INCLUDE_PATH = -I$(host_api_c)/src -I$(attr_container_dir)/ \ - -I$(coap_dir)/er-coap -I$(coap_dir)/er-coap/extension \ - -I$(shared_dir)/include \ - -I$(shared_dir)/utils \ - -I$(shared_dir)/platform/include/ \ - -I$(shared_dir)/platform/linux/ - -LIB := $(host_api_c)/src/libhostapi.a -EXE := ./hostapp - -App_C_Files := host_app_sample.c - -OBJS := $(App_C_Files:.c=.o) - -all: $(EXE) - -%.o: %.c - @$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE_PATH) - -$(EXE): $(OBJS) - @rm -f $(EXE) - @$(CC) $(OBJS) -o $(EXE) $(LIB) -lpthread -lrt - @rm -f $(OBJS) - -.PHONY: clean -clean: - rm -f $(OBJS) $(EXE) diff --git a/test-tools/component-test/set_dev_env.sh b/test-tools/component-test/set_dev_env.sh deleted file mode 100755 index 1abe23b80..000000000 --- a/test-tools/component-test/set_dev_env.sh +++ /dev/null @@ -1,7 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -#!/bin/sh - diff --git a/test-tools/component-test/start.py b/test-tools/component-test/start.py deleted file mode 100755 index 2cbc4fe63..000000000 --- a/test-tools/component-test/start.py +++ /dev/null @@ -1,152 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -#!/usr/bin/env python - -# -*- coding: utf-8 -*- -""" -It is the entrance of the iagent test framework. - -""" -from __future__ import print_function - -import argparse -import datetime -import os -import pprint -import random -import re -import shlex -import subprocess -import signal -import sys -import time - -sys.path.append('../../../app-sdk/python') -from framework.test_utils import * -from framework.framework import * - - -def signal_handler(signal, frame): - print('Pressed Ctrl+C!') - sys.exit(0) - -def Register_signal_handler(): - signal.signal(signal.SIGINT, signal_handler) -# signal.pause() - - -def flatten_args_list(l): - if l is None: - return None - - return [x for y in l for x in y] - - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description = "to run specific case(s) "\ - "in specific suite(s) with FC test framework") - parser.add_argument('-s', dest = 'suite_id', action = 'append', - nargs = '+', - help = 'one or multiple suite ids, which are also setup ids.'\ - 'by default if it isn\'t passed from argument, all '\ - 'suites are going to be run.') - parser.add_argument('-t', dest = 'case_id', action = 'append', - nargs = '+', - help = 'one or multiple cases ids.'\ - 'by default if it isn\'t passed from argument, all '\ - 'cases in specific suites are going to be run.') - parser.add_argument('-n', dest = 'repeat_time', action = 'store', - default = 1, - help = 'how many times do you want to run. there is 40s '\ - 'break time between two rounds. each round includs '\ - 'init_setup, run_test_case and deinit_setup.') - parser.add_argument('--shuffle_all', dest = 'shuffle_all', - default = False, action = 'store_true', - help = 'shuffle_all test cases in per test suite '\ - 'by default, all cases under per suite should '\ - 'be executed by input order.') - parser.add_argument('--cases_list', dest='cases_list_file_path', - default=None, - action='store', - help="read cases list from a flie ") - parser.add_argument('--skip_proc', dest='skip_proc', - default = False, action = 'store_true', - help='do not start the test process.'\ - 'sometimes the gw_broker process will be started in eclipse for debug purpose') - parser.add_argument('-b', dest = 'binaries', action = 'store', - help = 'The path of target folder ') - parser.add_argument('-d', dest = 'debug', action = 'store_true', - help = 'wait user to attach the target process after launch processes ') - parser.add_argument('--rebuild', dest = 'rebuild', action = 'store_true', - help = 'rebuild all test binaries') - args = parser.parse_args() - - print("------------------------------------------------------------") - print("parsing arguments ... ...") - print(args) - - ''' - logger = logging.getLogger('coapthon.server.coap') - logger.setLevel(logging.DEBUG) - console = logging.StreamHandler() - console.setLevel(logging.DEBUG) - logger.addHandler(console) - ''' - print("------------------------------------------------------------") - print("preparing wamr binary and test tools ... ...") - os.system("cd ../../samples/simple/ && bash build.sh -p host-interp") - - Register_signal_handler() - - api_init_globals(); - - api_create_case_event(); - - suites_list = flatten_args_list(args.suite_id) - cases_list = flatten_args_list(args.case_id) - - dirname, filename = os.path.split(os.path.abspath(sys.argv[0])) - api_set_root_path(dirname); - - framework = CTestFramework(dirname); - framework.repeat_time = int(args.repeat_time) - framework.shuffle_all = args.shuffle_all - framework.skip_proc=args.skip_proc - - api_set_value('keep_env', args.skip_proc) - api_set_value('debug', args.debug) - api_set_value('rebuild', args.rebuild) - - binary_path = args.binaries - if binary_path is None: - binary_path = os.path.abspath(dirname + '/../..') - - print("checking execution binary path: " + binary_path) - if not os.path.exists(binary_path): - print("The execution binary path was not available. quit...") - os._exit(0) - api_set_value('binary_path', binary_path) - - if suites_list is not None: - framework.target_suites = suites_list - else: - framework.load_suites() - - framework.target_cases = cases_list - framework.start_run() - - print("\n\n------------------------------------------------------------") - print("The run folder is [" + framework.running_folder +"]") - print("that's all. bye") - - print("kill to quit..") - t_kill_process_by_name("start.py") - - sys.exit(0) - os._exit() - - diff --git a/test-tools/component-test/suites/01-life-cycle/__init__.py b/test-tools/component-test/suites/01-life-cycle/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/01-install/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/01-install/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py b/test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py deleted file mode 100644 index b8d2c38b8..000000000 --- a/test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py +++ /dev/null @@ -1,94 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import sys -import time -import random -import logging -import json - -from framework.case_base import * -from framework.test_api import * -from harness.harness_api import * - -class CTestCase(CTestCaseBase): - def __init__(self, suite): - CTestCaseBase.__init__(self, suite) - - def get_case_name(self): - case_path = os.path.dirname(os.path.abspath( __file__ )) - return os.path.split(case_path)[1] - - def on_get_case_description(self): - return "startup the executables" - - def on_setup_case(self): - os.chdir(self.get_case_name()) - start_env() - api_log_error("on_setup_case OK") - return True, '' - - def on_cleanup_case(self): - stop_env() - api_log_error("on_cleanup_case OK") - return True, '' - - # called by the framework - def on_run_case(self): - time.sleep(0.5) - - #uninstall inexistent App1 - ret = uninstall_app("App1") - if (ret != 160): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps([]) - if (ret == False): - return False, '' - - #install App1 - ret = install_app("App1", "01_install.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1"]) - if (ret == False): - return False, '' - - #install App2 - ret = install_app("App2", "01_install.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1","App2"]) - if (ret == False): - return False, '' - - #uninstall App2 - ret = uninstall_app("App2") - if (ret != 66): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1"]) - if (ret == False): - return False, '' - - return True, '' diff --git a/test-tools/component-test/suites/01-life-cycle/cases/02-request/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/02-request/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py b/test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py deleted file mode 100644 index e2192d5fa..000000000 --- a/test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py +++ /dev/null @@ -1,73 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import sys -import time -import random -import logging -import json - -from framework.case_base import * -from framework.test_api import * -from harness.harness_api import * - -class CTestCase(CTestCaseBase): - def __init__(self, suite): - CTestCaseBase.__init__(self, suite) - - def get_case_name(self): - case_path = os.path.dirname(os.path.abspath( __file__ )) - return os.path.split(case_path)[1] - - def on_get_case_description(self): - return "startup the executables" - - def on_setup_case(self): - os.chdir(self.get_case_name()) - start_env() - api_log_error("on_setup_case OK") - return True, '' - - def on_cleanup_case(self): - stop_env() - api_log_error("on_cleanup_case OK") - return True, '' - - # called by the framework - def on_run_case(self): - time.sleep(0.5) - - #install App1 - ret = install_app("App1", "02_request.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1"]) - if (ret == False): - return False, '' - - #send request to App1 - ret = send_request("/res1", "GET", None) - if (ret != 69): - return False, '' - expect_response_payload = {"key1":"value1","key2":"value2"} - ret = check_response_payload(expect_response_payload) - if (ret == False): - return False, '' - - #send request to App1 - ret = send_request("/res2", "DELETE", None) - if (ret != 66): - return False, '' - expect_response_payload = {} - ret = check_response_payload(expect_response_payload) - if (ret == False): - return False, '' - - return True, '' diff --git a/test-tools/component-test/suites/01-life-cycle/cases/03-event/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/03-event/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py b/test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py deleted file mode 100644 index 3886cb820..000000000 --- a/test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py +++ /dev/null @@ -1,67 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -import sys -import time -import random -import logging -import json - -from framework.case_base import * -from framework.test_api import * -from harness.harness_api import * - -class CTestCase(CTestCaseBase): - def __init__(self, suite): - CTestCaseBase.__init__(self, suite) - - def get_case_name(self): - case_path = os.path.dirname(os.path.abspath( __file__ )) - return os.path.split(case_path)[1] - - def on_get_case_description(self): - return "startup the executables" - - def on_setup_case(self): - os.chdir(self.get_case_name()) - start_env() - api_log_error("on_setup_case OK") - return True, '' - - def on_cleanup_case(self): - stop_env() - api_log_error("on_cleanup_case OK") - return True, '' - - # called by the framework - def on_run_case(self): - time.sleep(0.5) - - #install App1 - ret = install_app("App1", "03_event.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1"]) - if (ret == False): - return False, '' - - #register event - ret = register("/alert/overheat", 2000, 5000) - if (ret != 69): - return False, '' - ret = check_get_event() - if (ret == False): - return False, '' - - #deregister event - ret = deregister("/alert/overheat") - if (ret != 69): - return False, '' - - return True, '' diff --git a/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py b/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py deleted file mode 100644 index bf395f58b..000000000 --- a/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py +++ /dev/null @@ -1,80 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import sys -import time -import random -import logging -import json - -from framework.case_base import * -from framework.test_api import * -from harness.harness_api import * - -class CTestCase(CTestCaseBase): - def __init__(self, suite): - CTestCaseBase.__init__(self, suite) - - def get_case_name(self): - case_path = os.path.dirname(os.path.abspath( __file__ )) - return os.path.split(case_path)[1] - - def on_get_case_description(self): - return "startup the executables" - - def on_setup_case(self): - os.chdir(self.get_case_name()) - start_env() - api_log_error("on_setup_case OK") - return True, '' - - def on_cleanup_case(self): - stop_env() - api_log_error("on_cleanup_case OK") - return True, '' - - # called by the framework - def on_run_case(self): - time.sleep(0.5) - - #install App1 - ret = install_app("App1", "04_request_internal_resp.wasm") - if (ret != 65): - return False, '' - - #install App2 - ret = install_app("App2", "04_request_internal_req.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1","App2"]) - if (ret == False): - return False, '' - - #send request to App2 - ret = send_request("/res1", "GET", None) - if (ret != 69): - return False, '' - time.sleep(2) - expect_response_payload = {"key1":"value1","key2":"value2"} - ret = check_response_payload(expect_response_payload) - if (ret == False): - return False, '' - - #send request to App2 - ret = send_request("/res2", "GET", None) - if (ret != 69): - return False, '' - time.sleep(2) - expect_response_payload = {"key1":"value1","key2":"value2"} - ret = check_response_payload(expect_response_payload) - if (ret == False): - return False, '' - - return True, '' diff --git a/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py b/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py deleted file mode 100644 index 79c328749..000000000 --- a/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py +++ /dev/null @@ -1,70 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import sys -import time -import random -import logging -import json - -from framework.case_base import * -from framework.test_api import * -from harness.harness_api import * - -class CTestCase(CTestCaseBase): - def __init__(self, suite): - CTestCaseBase.__init__(self, suite) - - def get_case_name(self): - case_path = os.path.dirname(os.path.abspath( __file__ )) - return os.path.split(case_path)[1] - - def on_get_case_description(self): - return "startup the executables" - - def on_setup_case(self): - os.chdir(self.get_case_name()) - start_env() - api_log_error("on_setup_case OK") - return True, '' - - def on_cleanup_case(self): - stop_env() - api_log_error("on_cleanup_case OK") - return True, '' - - # called by the framework - def on_run_case(self): - time.sleep(0.5) - - #install App1 - ret = install_app("App1", "05_event_internal_provider.wasm") - if (ret != 65): - return False, '' - - #install App2 - ret = install_app("App2", "05_event_internal_subscriber.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1","App2"]) - if (ret == False): - return False, '' - - #send request to App2 - ret = send_request("/res1", "GET", None) - if (ret != 69): - return False, '' - time.sleep(2) - expect_response_payload = {"key1":"value1","key2":"value2"} - ret = check_response_payload(expect_response_payload) - if (ret == False): - return False, '' - - return True, '' diff --git a/test-tools/component-test/suites/01-life-cycle/cases/06-timer/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/06-timer/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py b/test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py deleted file mode 100644 index 90af4d5d9..000000000 --- a/test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py +++ /dev/null @@ -1,70 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import sys -import time -import random -import logging -import json - -from framework.case_base import * -from framework.test_api import * -from harness.harness_api import * - -class CTestCase(CTestCaseBase): - def __init__(self, suite): - CTestCaseBase.__init__(self, suite) - - def get_case_name(self): - case_path = os.path.dirname(os.path.abspath( __file__ )) - return os.path.split(case_path)[1] - - def on_get_case_description(self): - return "startup the executables" - - def on_setup_case(self): - os.chdir(self.get_case_name()) - start_env() - api_log_error("on_setup_case OK") - return True, '' - - def on_cleanup_case(self): - stop_env() - api_log_error("on_cleanup_case OK") - return True, '' - - # called by the framework - def on_run_case(self): - time.sleep(0.5) - - #install App1 - ret = install_app("App1", "06_timer.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1"]) - if (ret == False): - return False, '' - - #send request to App1 - ret = send_request("/res1", "GET", None) - if (ret != 69): - return False, '' - - time.sleep(3) - - ret = send_request("/check_timer", "GET", None) - if (ret != 69): - return False, '' - expect_response_payload = {"num":2} - ret = check_response_payload(expect_response_payload) - if (ret == False): - return False, '' - - return True, '' diff --git a/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py b/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py deleted file mode 100644 index 2bb756203..000000000 --- a/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py +++ /dev/null @@ -1,65 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import sys -import time -import random -import logging -import json - -from framework.case_base import * -from framework.test_api import * -from harness.harness_api import * - -class CTestCase(CTestCaseBase): - def __init__(self, suite): - CTestCaseBase.__init__(self, suite) - - def get_case_name(self): - case_path = os.path.dirname(os.path.abspath( __file__ )) - return os.path.split(case_path)[1] - - def on_get_case_description(self): - return "startup the executables" - - def on_setup_case(self): - os.chdir(self.get_case_name()) - start_env() - api_log_error("on_setup_case OK") - return True, '' - - def on_cleanup_case(self): - stop_env() - api_log_error("on_cleanup_case OK") - return True, '' - - # called by the framework - def on_run_case(self): - time.sleep(0.5) - - #install App1 - ret = install_app("App1", "07_sensor.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1"]) - if (ret == False): - return False, '' - - #send request to App1 - ret = send_request("/res1", "GET", None) - if (ret != 69): - return False, '' - time.sleep(2) - expect_response_payload = {"key1":"value1","key2":"value2"} - ret = check_response_payload(expect_response_payload) - if (ret == False): - return False, '' - - return True, '' diff --git a/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py b/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py deleted file mode 100644 index 99a4512ee..000000000 --- a/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py +++ /dev/null @@ -1,78 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import sys -import time -import random -import logging -import json - -from framework.case_base import * -from framework.test_api import * -from harness.harness_api import * - -class CTestCase(CTestCaseBase): - def __init__(self, suite): - CTestCaseBase.__init__(self, suite) - - def get_case_name(self): - case_path = os.path.dirname(os.path.abspath( __file__ )) - return os.path.split(case_path)[1] - - def on_get_case_description(self): - return "startup the executables" - - def on_setup_case(self): - os.chdir(self.get_case_name()) - start_env() - api_log_error("on_setup_case OK") - return True, '' - - def on_cleanup_case(self): - stop_env() - api_log_error("on_cleanup_case OK") - return True, '' - - # called by the framework - def on_run_case(self): - time.sleep(0.5) - - #install App1 - ret = install_app("App1", "08_on_destroy.wasm") - if (ret != 65): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps(["App1"]) - if (ret == False): - return False, '' - - #send request to App1 - ret = send_request("/res1", "GET", None) - if (ret != 69): - return False, '' - time.sleep(2) - expect_response_payload = {"key1":"value1"} - ret = check_response_payload(expect_response_payload) - if (ret == False): - return False, '' - - #uninstall App1 - ret = uninstall_app("App1") - if (ret != 66): - return False, '' - - #query Apps - ret = query_app() - if (ret != 69): - return False, '' - ret = check_query_apps([]) - if (ret == False): - return False, '' - - return True, '' diff --git a/test-tools/component-test/suites/01-life-cycle/cases/__init__.py b/test-tools/component-test/suites/01-life-cycle/cases/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/01-life-cycle/suite_setup.py b/test-tools/component-test/suites/01-life-cycle/suite_setup.py deleted file mode 100644 index 2307186f7..000000000 --- a/test-tools/component-test/suites/01-life-cycle/suite_setup.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -import os -import shutil -import types -import time -import glob - -from framework.test_api import * -from framework.test_utils import * -from harness.harness_api import * -from framework.suite import * - -class CTestSuite(CTestSuiteBase): - setup_path = "" - def __init__(self, name, suite_path, run_path): - CTestSuiteBase.__init__(self, name, suite_path, run_path) - - def on_suite_setup(self): - global setup_path - setup_path = os.getcwd() - cases = os.listdir(self.suite_path + "/cases/") - cases.sort() - - if api_get_value("rebuild", False): - path_tmp = os.getcwd() - os.chdir(self.suite_path + "/test-app") - os.system(self.suite_path + "/test-app" + "/build.sh") - os.chdir(path_tmp) - - os.makedirs(self.run_path + "/test-app") - - for case in cases: - if case != "__init__.pyc" and case != "__init__.py": - os.makedirs(self.run_path + "/" + case) - #copy each case's host_tool, simple, wasm files, start/stop scripts to the run directory, - shutil.copy(setup_path + "/../../samples/simple/out/simple", self.run_path + "/" + case) - shutil.copy(setup_path + "/../../samples/simple/out/host_tool", self.run_path + "/" + case) - for file in glob.glob(self.suite_path + "/test-app/" + "/*.wasm"): - shutil.copy(file, self.run_path + "/test-app") - shutil.copy(self.suite_path + "/tools/product/start.sh", self.run_path + "/" + case) - shutil.copy(self.suite_path + "/tools/product/stop.sh", self.run_path + "/" + case) - - os.chdir(self.run_path) - - return True, 'OK' - - def on_suite_cleanup(self): - global setup_path - os.chdir(setup_path) - api_log("stopping env..") - - return True, 'OK' diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/01_install.c b/test-tools/component-test/suites/01-life-cycle/test-app/01_install.c deleted file mode 100644 index 5c7153588..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/01_install.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" - -void -on_init() -{ - printf("Hello, I was installed.\n"); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/02_request.c b/test-tools/component-test/suites/01-life-cycle/test-app/02_request.c deleted file mode 100644 index 251de6ff4..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/02_request.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" - -void -res1_handler(request_t *request) -{ - response_t response[1]; - attr_container_t *payload; - - printf("### user resource 1 handler called\n"); - - printf("###### dump request ######\n"); - printf("sender: %lu\n", request->sender); - printf("url: %s\n", request->url); - printf("action: %d\n", request->action); - printf("payload:\n"); - if (request->payload != NULL && request->payload_len > 0 - && request->fmt == FMT_ATTR_CONTAINER) - attr_container_dump((attr_container_t *)request->payload); - printf("#### dump request end ###\n"); - - payload = attr_container_create("wasm app response payload"); - if (payload == NULL) - return; - - attr_container_set_string(&payload, "key1", "value1"); - attr_container_set_string(&payload, "key2", "value2"); - - make_response_for_request(request, response); - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, - (const char *)payload, - attr_container_get_serialize_length(payload)); - printf("reciver: %lu, mid:%d\n", response->reciever, response->mid); - api_response_send(response); - - attr_container_destroy(payload); -} - -void -res2_handler(request_t *request) -{ - response_t response[1]; - make_response_for_request(request, response); - set_response(response, DELETED_2_02, 0, NULL, 0); - api_response_send(response); - - printf("### user resource 2 handler called\n"); -} - -void -on_init() -{ - /* register resource uri */ - api_register_resource_handler("/res1", res1_handler); - api_register_resource_handler("/res2", res2_handler); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/03_event.c b/test-tools/component-test/suites/01-life-cycle/test-app/03_event.c deleted file mode 100644 index 59cfd0097..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/03_event.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/timer_wasm_app.h" -#include "wa-inc/request.h" - -int num = 0; - -void -publish_overheat_event() -{ - attr_container_t *event; - - event = attr_container_create("event"); - attr_container_set_string(&event, "warning", "temperature is over high"); - - printf("###app publish event begin ###\n"); - - api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event, - attr_container_get_serialize_length(event)); - - printf("###app publish event end ###\n"); - - attr_container_destroy(event); -} - -/* Timer callback */ -void -timer1_update(user_timer_t timer) -{ - printf("Timer update %d\n", num++); - publish_overheat_event(); -} - -void -start_timer() -{ - user_timer_t timer; - - /* set up a timer */ - timer = api_timer_create(1000, true, false, timer1_update); - api_timer_restart(timer, 1000); -} - -void -on_init() -{ - start_timer(); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c b/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c deleted file mode 100644 index 99bab9704..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" - -uint32 mid; -unsigned long sender; - -void -my_response_handler(response_t *response, void *user_data) -{ - attr_container_t *payload; - printf("### user resource 1 handler called\n"); - - payload = attr_container_create("wasm app response payload"); - if (payload == NULL) - return; - - attr_container_set_string(&payload, "key1", "value1"); - attr_container_set_string(&payload, "key2", "value2"); - - response->mid = mid; - response->reciever = sender; - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, - (const char *)payload, - attr_container_get_serialize_length(payload)); - printf("reciver: %lu, mid:%d\n", response->reciever, response->mid); - api_response_send(response); - - attr_container_destroy(payload); -} - -static void -test_send_request(const char *url, const char *tag) -{ - request_t request[1]; - - init_request(request, (char *)url, COAP_PUT, 0, NULL, 0); - api_send_request(request, my_response_handler, (void *)tag); -} - -void -res1_handler(request_t *request) -{ - mid = request->mid; - sender = request->sender; - test_send_request("url1", "a general request"); -} - -void -res2_handler(request_t *request) -{ - mid = request->mid; - sender = request->sender; - test_send_request("/app/App1/url1", "a general request"); -} - -void -on_init() -{ - /* register resource uri */ - api_register_resource_handler("/res1", res1_handler); - api_register_resource_handler("/res2", res2_handler); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c b/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c deleted file mode 100644 index 13aecb43a..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" - -void -res1_handler(request_t *request) -{ - response_t response[1]; - attr_container_t *payload; - - printf("[resp] ### user resource 1 handler called\n"); - - printf("[resp] ###### dump request ######\n"); - printf("[resp] sender: %lu\n", request->sender); - printf("[resp] url: %s\n", request->url); - printf("[resp] action: %d\n", request->action); - printf("[resp] payload:\n"); - if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER) - attr_container_dump((attr_container_t *)request->payload); - printf("[resp] #### dump request end ###\n"); - - payload = attr_container_create("wasm app response payload"); - if (payload == NULL) - return; - - attr_container_set_string(&payload, "key1", "value1"); - attr_container_set_string(&payload, "key2", "value2"); - - make_response_for_request(request, response); - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, - (const char *)payload, - attr_container_get_serialize_length(payload)); - printf("[resp] response payload len %d\n", - attr_container_get_serialize_length(payload)); - printf("[resp] reciver: %lu, mid:%d\n", response->reciever, response->mid); - api_response_send(response); - - attr_container_destroy(payload); -} - -void -on_init() -{ - /* register resource uri */ - api_register_resource_handler("/url1", res1_handler); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c b/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c deleted file mode 100644 index 59cfd0097..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/timer_wasm_app.h" -#include "wa-inc/request.h" - -int num = 0; - -void -publish_overheat_event() -{ - attr_container_t *event; - - event = attr_container_create("event"); - attr_container_set_string(&event, "warning", "temperature is over high"); - - printf("###app publish event begin ###\n"); - - api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event, - attr_container_get_serialize_length(event)); - - printf("###app publish event end ###\n"); - - attr_container_destroy(event); -} - -/* Timer callback */ -void -timer1_update(user_timer_t timer) -{ - printf("Timer update %d\n", num++); - publish_overheat_event(); -} - -void -start_timer() -{ - user_timer_t timer; - - /* set up a timer */ - timer = api_timer_create(1000, true, false, timer1_update); - api_timer_restart(timer, 1000); -} - -void -on_init() -{ - start_timer(); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c b/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c deleted file mode 100644 index 00e451369..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" - -uint32 mid; -unsigned long sender; - -void -over_heat_event_handler(request_t *request) -{ - response_t response[1]; - attr_container_t *payload; - - payload = attr_container_create("wasm app response payload"); - if (payload == NULL) - return; - - attr_container_set_string(&payload, "key1", "value1"); - attr_container_set_string(&payload, "key2", "value2"); - - response->mid = mid; - response->reciever = sender; - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, - (const char *)payload, - attr_container_get_serialize_length(payload)); - printf("reciver: %lu, mid:%d\n", response->reciever, response->mid); - api_response_send(response); - - attr_container_destroy(payload); -} - -void -res1_handler(request_t *request) -{ - mid = request->mid; - sender = request->sender; - api_subscribe_event("alert/overheat", over_heat_event_handler); -} - -void -on_init() -{ - /* register resource uri */ - api_register_resource_handler("/res1", res1_handler); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c b/test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c deleted file mode 100644 index 6aa107d5c..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" -#include "wa-inc/timer_wasm_app.h" - -/* User global variable */ -int num = 0; - -/* Timer callback */ -void -timer1_update(user_timer_t timer) -{ - if (num < 2) - num++; -} - -void -res1_handler(request_t *request) -{ - user_timer_t timer; - - /* set up a timer */ - timer = api_timer_create(1000, true, false, timer1_update); - api_timer_restart(timer, 1000); - - response_t response[1]; - - make_response_for_request(request, response); - - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, NULL, 0); - - api_response_send(response); -} - -void -res2_handler(request_t *request) -{ - response_t response[1]; - attr_container_t *payload; - - if (num == 2) { - attr_container_t *payload; - printf("### user resource 1 handler called\n"); - - payload = attr_container_create("wasm app response payload"); - if (payload == NULL) - return; - - attr_container_set_int(&payload, "num", num); - - make_response_for_request(request, response); - - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, - (const char *)payload, - attr_container_get_serialize_length(payload)); - printf("reciver: %lu, mid:%d\n", response->reciever, response->mid); - api_response_send(response); - - attr_container_destroy(payload); - } -} - -void -on_init() -{ - /* register resource uri */ - api_register_resource_handler("/res1", res1_handler); - api_register_resource_handler("/check_timer", res2_handler); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c b/test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c deleted file mode 100644 index a6c24a8bc..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" -#include "wa-inc/sensor.h" - -uint32 mid; -unsigned long sender; - -/* Sensor event callback*/ -void -sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data) -{ - printf("### app get sensor event\n"); - - response_t response[1]; - attr_container_t *payload; - - payload = attr_container_create("wasm app response payload"); - if (payload == NULL) - return; - - attr_container_set_string(&payload, "key1", "value1"); - attr_container_set_string(&payload, "key2", "value2"); - - response->mid = mid; - response->reciever = sender; - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, - (const char *)payload, - attr_container_get_serialize_length(payload)); - printf("reciver: %lu, mid:%d\n", response->reciever, response->mid); - api_response_send(response); - - attr_container_destroy(payload); -} - -void -res1_handler(request_t *request) -{ - mid = request->mid; - sender = request->sender; - - sensor_t sensor; - char *user_data; - attr_container_t *config; - - printf("### app on_init 1\n"); - /* open a sensor */ - user_data = malloc(100); - printf("### app on_init 2\n"); - sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data); - printf("### app on_init 3\n"); - - /* config the sensor */ - sensor_config(sensor, 2000, 0, 0); - printf("### app on_init 4\n"); -} - -void -on_init() -{ - /* register resource uri */ - api_register_resource_handler("/res1", res1_handler); -} - -void -on_destroy() -{ - /* real destroy work including killing timer and closing sensor is - * accomplished in wasm app library version of on_destroy() */ -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c b/test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c deleted file mode 100644 index ac05a77da..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "wasm_app.h" -#include "wa-inc/request.h" -#include "wa-inc/sensor.h" - -uint32 mid; -unsigned long sender; -sensor_t sensor; - -/* Sensor event callback*/ -void -sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data) -{ - printf("### app get sensor event\n"); - - response_t response[1]; - attr_container_t *payload; - - payload = attr_container_create("wasm app response payload"); - if (payload == NULL) - return; - - attr_container_set_string(&payload, "key1", "value1"); - - response->mid = mid; - response->reciever = sender; - set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, - (const char *)payload, - attr_container_get_serialize_length(payload)); - printf("reciver: %lu, mid:%d\n", response->reciever, response->mid); - api_response_send(response); - - attr_container_destroy(payload); -} - -void -res1_handler(request_t *request) -{ - mid = request->mid; - sender = request->sender; - - char *user_data; - attr_container_t *config; - - printf("### app on_init 1\n"); - /* open a sensor */ - user_data = malloc(100); - printf("### app on_init 2\n"); - sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data); - printf("### app on_init 3\n"); -} - -void -on_init() -{ - /* register resource uri */ - api_register_resource_handler("/res1", res1_handler); -} - -void -on_destroy() -{ - if (NULL != sensor) { - sensor_close(sensor); - } -} diff --git a/test-tools/component-test/suites/01-life-cycle/test-app/build.sh b/test-tools/component-test/suites/01-life-cycle/test-app/build.sh deleted file mode 100755 index 4b5428051..000000000 --- a/test-tools/component-test/suites/01-life-cycle/test-app/build.sh +++ /dev/null @@ -1,39 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -. ../../../set_dev_env.sh - -CC=/opt/wasi-sdk/bin/clang -APP_DIR=$PWD -WAMR_DIR=${APP_DIR}/../../../../../ -SDK_DIR=${WAMR_DIR}/wamr-sdk/out/simple-host-interp -APP_FRAMEWORK_DIR=${SDK_DIR}/app-sdk/wamr-app-framework -DEPS_DIR=${WAMR_DIR}/core/deps - -for i in `ls *.c` -do -APP_SRC="$i" -OUT_FILE=${i%.*}.wasm -/opt/wasi-sdk/bin/clang -O3 \ - -Wno-int-conversion \ - -I${APP_FRAMEWORK_DIR}/include \ - -I${DEPS_DIR} \ - -O3 -z stack-size=4096 -Wl,--initial-memory=65536 \ - --sysroot=${SDK_DIR}/app-sdk/libc-builtin-sysroot \ - -L${APP_FRAMEWORK_DIR}/lib -lapp_framework \ - -Wl,--allow-undefined-file=${SDK_DIR}/app-sdk/libc-builtin-sysroot/share/defined-symbols.txt \ - -Wl,--strip-all,--no-entry -nostdlib \ - -Wl,--export=on_init -Wl,--export=on_destroy \ - -Wl,--export=on_request -Wl,--export=on_response \ - -Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \ - -Wl,--export=on_connection_data \ - -o ${OUT_FILE} \ - ${APP_SRC} -if [ -f ${OUT_FILE} ]; then - echo "build ${OUT_FILE} success" -else - echo "build ${OUT_FILE} fail" -fi -done diff --git a/test-tools/component-test/suites/01-life-cycle/tools/product/start.sh b/test-tools/component-test/suites/01-life-cycle/tools/product/start.sh deleted file mode 100755 index f83e39356..000000000 --- a/test-tools/component-test/suites/01-life-cycle/tools/product/start.sh +++ /dev/null @@ -1,10 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -#!/bin/bash - -cd $(dirname "$0") - -./simple -s > /dev/null 2>&1 & diff --git a/test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh b/test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh deleted file mode 100755 index b7bc2c8d2..000000000 --- a/test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh +++ /dev/null @@ -1,9 +0,0 @@ -# -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -#!/bin/bash - -ps aux | grep -ie host_tool | awk '{print $2}' | xargs kill -9 & -ps aux | grep -ie simple | awk '{print $2}' | xargs kill -9 & diff --git a/test-tools/component-test/suites/__init__.py b/test-tools/component-test/suites/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test-tools/component-test/suites/readme.txt b/test-tools/component-test/suites/readme.txt deleted file mode 100644 index 1e8792f5b..000000000 --- a/test-tools/component-test/suites/readme.txt +++ /dev/null @@ -1,19 +0,0 @@ -The description of each case in the test suites, should add descriptions in this file when new cases created in the future. - -suite 01-life-cycle: -case 01-install: - install or uninstall apps for times and query apps to see if the app list is expected. -case 02-request: - send request to an app, the app will respond specific attribute objects, host side should get them. -case 03-event: - register event to an app, the app will send event back periodically, host side should get some payload. -case 04-request_internal: - install 2 apps, host sends request to app2, then app2 sends request to app1, finally app1 respond specific payload to host, host side will check it. -case 05-event_internal: - install 2 apps, host sends request to app2, then app2 subscribe app1's event, finally app1 respond specific payload to host, host side will check it. -case 06-timer: - host send request to an app, the app then start a timer, when time goes by 2 seconds, app will respond specific payload to host, host side will check it. -case 07-sensor: - open sensor in app and then config the sensor in on_init, finally app will respond specific payload to host, host side will check it. -case 08-on_destroy: - open sensor in app in on_init, and close the sensor in on_destroy, host should install and uninstall the app successfully. diff --git a/test-tools/host-tool/CMakeLists.txt b/test-tools/host-tool/CMakeLists.txt deleted file mode 100644 index 932cf73bd..000000000 --- a/test-tools/host-tool/CMakeLists.txt +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -cmake_minimum_required (VERSION 2.9) -project (host-agent) - -if (NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE Debug) -endif (NOT CMAKE_BUILD_TYPE) - -if (NOT WAMR_BUILD_PLATFORM) - set (WAMR_BUILD_PLATFORM "linux") -endif (NOT WAMR_BUILD_PLATFORM) - -message ("WAMR_BUILD_PLATFORM = " ${WAMR_BUILD_PLATFORM}) - -add_definitions(-DWA_MALLOC=malloc) -add_definitions(-DWA_FREE=free) - -set (REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) -set (IWASM_DIR ${REPO_ROOT_DIR}/core/iwasm) -set (APP_MGR_DIR ${REPO_ROOT_DIR}/core/app-mgr) -set (SHARED_DIR ${REPO_ROOT_DIR}/core/shared) -set (APP_FRAMEWORK_DIR ${REPO_ROOT_DIR}/core/app-framework) -#TODO: use soft-plc/tools/iec-runtime/external/cJSON instead -set (CJSON_DIR ${CMAKE_CURRENT_LIST_DIR}/external/cJSON) - -include (${APP_FRAMEWORK_DIR}/app-native-shared/native_interface.cmake) -include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake) -include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake) -include (${SHARED_DIR}/utils/shared_utils.cmake) -include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake) -include (${CJSON_DIR}/cjson.cmake) -include (${SHARED_DIR}/coap/lib_coap.cmake) - -add_definitions(-Wall -Wno-pointer-sign) - -include_directories( - ${CMAKE_CURRENT_LIST_DIR}/src - ${IWASM_DIR}/include -) - -file (GLOB_RECURSE HOST_TOOL_SRC src/*.c) - -SET(SOURCES - ${HOST_TOOL_SRC} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${CJSON_SOURCE} - ${LIB_HOST_AGENT_SOURCE} - ) - -add_executable(host_tool ${SOURCES}) -target_link_libraries(host_tool pthread) diff --git a/test-tools/host-tool/external/cJSON/LICENSE b/test-tools/host-tool/external/cJSON/LICENSE deleted file mode 100644 index 78deb0406..000000000 --- a/test-tools/host-tool/external/cJSON/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2009-2017 Dave Gamble and cJSON contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - diff --git a/test-tools/host-tool/external/cJSON/cJSON.c b/test-tools/host-tool/external/cJSON/cJSON.c deleted file mode 100644 index 830d2a346..000000000 --- a/test-tools/host-tool/external/cJSON/cJSON.c +++ /dev/null @@ -1,2991 +0,0 @@ -/* - Copyright (c) 2009-2017 Dave Gamble and cJSON contributors - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ - -/* cJSON */ -/* JSON parser in C. */ - -/* disable warnings about old C89 functions in MSVC */ -#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) -#define _CRT_SECURE_NO_DEPRECATE -#endif - -#ifdef __GNUC__ -#pragma GCC visibility push(default) -#endif -#if defined(_MSC_VER) -#pragma warning(push) -/* disable warning about single line comments in system headers */ -#pragma warning(disable : 4001) -#endif - -#include -#include -#include -#include -#include -#include -#include - -#ifdef ENABLE_LOCALES -#include -#endif - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif -#ifdef __GNUC__ -#pragma GCC visibility pop -#endif - -#include "cJSON.h" - -/* define our own boolean type */ -#ifdef true -#undef true -#endif -#define true ((cJSON_bool)1) - -#ifdef false -#undef false -#endif -#define false ((cJSON_bool)0) - -/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has - * been defined in math.h */ -#ifndef isinf -#define isinf(d) (isnan((d - d)) && !isnan(d)) -#endif -#ifndef isnan -#define isnan(d) (d != d) -#endif - -#ifndef NAN -#ifdef _WIN32 -#define NAN sqrt(-1.0) -#else -#define NAN 0.0 / 0.0 -#endif -#endif - -typedef struct { - const unsigned char *json; - size_t position; -} error; -static error global_error = { NULL, 0 }; - -CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) -{ - return (const char *)(global_error.json + global_error.position); -} - -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item) -{ - if (!cJSON_IsString(item)) { - return NULL; - } - - return item->valuestring; -} - -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) -{ - if (!cJSON_IsNumber(item)) { - return (double)NAN; - } - - return item->valuedouble; -} - -/* This is a safeguard to prevent copy-pasters from using incompatible C and - * header files */ -#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) \ - || (CJSON_VERSION_PATCH != 16) -#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. -#endif - -CJSON_PUBLIC(const char *) cJSON_Version(void) -{ - static char version[15]; - sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, - CJSON_VERSION_PATCH); - - return version; -} - -/* Case insensitive string comparison, doesn't consider two NULL pointers equal - * though */ -static int -case_insensitive_strcmp(const unsigned char *string1, - const unsigned char *string2) -{ - if ((string1 == NULL) || (string2 == NULL)) { - return 1; - } - - if (string1 == string2) { - return 0; - } - - for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) { - if (*string1 == '\0') { - return 0; - } - } - - return tolower(*string1) - tolower(*string2); -} - -typedef struct internal_hooks { - void *(CJSON_CDECL *allocate)(size_t size); - void(CJSON_CDECL *deallocate)(void *pointer); - void *(CJSON_CDECL *reallocate)(void *pointer, size_t size); -} internal_hooks; - -#if defined(_MSC_VER) -/* work around MSVC error C2322: '...' address of dllimport '...' is not static - */ -static void *CJSON_CDECL -internal_malloc(size_t size) -{ - return malloc(size); -} -static void CJSON_CDECL -internal_free(void *pointer) -{ - free(pointer); -} -static void *CJSON_CDECL -internal_realloc(void *pointer, size_t size) -{ - return realloc(pointer, size); -} -#else -#define internal_malloc malloc -#define internal_free free -#define internal_realloc realloc -#endif - -/* strlen of character literals resolved at compile time */ -#define static_strlen(string_literal) (sizeof(string_literal) - sizeof("")) - -static internal_hooks global_hooks = { internal_malloc, internal_free, - internal_realloc }; - -static unsigned char * -cJSON_strdup(const unsigned char *string, const internal_hooks *const hooks) -{ - size_t length = 0; - unsigned char *copy = NULL; - - if (string == NULL) { - return NULL; - } - - length = strlen((const char *)string) + sizeof(""); - copy = (unsigned char *)hooks->allocate(length); - if (copy == NULL) { - return NULL; - } - memcpy(copy, string, length); - - return copy; -} - -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) -{ - if (hooks == NULL) { - /* Reset hooks */ - global_hooks.allocate = malloc; - global_hooks.deallocate = free; - global_hooks.reallocate = realloc; - return; - } - - global_hooks.allocate = malloc; - if (hooks->malloc_fn != NULL) { - global_hooks.allocate = hooks->malloc_fn; - } - - global_hooks.deallocate = free; - if (hooks->free_fn != NULL) { - global_hooks.deallocate = hooks->free_fn; - } - - /* use realloc only if both free and malloc are used */ - global_hooks.reallocate = NULL; - if ((global_hooks.allocate == malloc) - && (global_hooks.deallocate == free)) { - global_hooks.reallocate = realloc; - } -} - -/* Internal constructor. */ -static cJSON * -cJSON_New_Item(const internal_hooks *const hooks) -{ - cJSON *node = (cJSON *)hooks->allocate(sizeof(cJSON)); - if (node) { - memset(node, '\0', sizeof(cJSON)); - } - - return node; -} - -/* Delete a cJSON structure. */ -CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) -{ - cJSON *next = NULL; - while (item != NULL) { - next = item->next; - if (!(item->type & cJSON_IsReference) && (item->child != NULL)) { - cJSON_Delete(item->child); - } - if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) { - global_hooks.deallocate(item->valuestring); - } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { - global_hooks.deallocate(item->string); - } - global_hooks.deallocate(item); - item = next; - } -} - -/* get the decimal point character of the current locale */ -static unsigned char -get_decimal_point(void) -{ -#ifdef ENABLE_LOCALES - struct lconv *lconv = localeconv(); - return (unsigned char)lconv->decimal_point[0]; -#else - return '.'; -#endif -} - -typedef struct { - const unsigned char *content; - size_t length; - size_t offset; - size_t depth; /* How deeply nested (in arrays/objects) is the input at the - current offset. */ - internal_hooks hooks; -} parse_buffer; - -/* check if the given size is left to read in a given parse buffer (starting - * with 1) */ -#define can_read(buffer, size) \ - ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) -/* check if the buffer can be accessed at the given index (starting with 0) */ -#define can_access_at_index(buffer, index) \ - ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) -#define cannot_access_at_index(buffer, index) \ - (!can_access_at_index(buffer, index)) -/* get a pointer to the buffer at the position */ -#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) - -/* Parse the input text to generate a number, and populate the result into item. - */ -static cJSON_bool -parse_number(cJSON *const item, parse_buffer *const input_buffer) -{ - double number = 0; - unsigned char *after_end = NULL; - unsigned char number_c_string[64]; - unsigned char decimal_point = get_decimal_point(); - size_t i = 0; - - if ((input_buffer == NULL) || (input_buffer->content == NULL)) { - return false; - } - - /* copy the number into a temporary buffer and replace '.' with the decimal - * point of the current locale (for strtod) This also takes care of '\0' not - * necessarily being available for marking the end of the input */ - for (i = 0; (i < (sizeof(number_c_string) - 1)) - && can_access_at_index(input_buffer, i); - i++) { - switch (buffer_at_offset(input_buffer)[i]) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '+': - case '-': - case 'e': - case 'E': - number_c_string[i] = buffer_at_offset(input_buffer)[i]; - break; - - case '.': - number_c_string[i] = decimal_point; - break; - - default: - goto loop_end; - } - } -loop_end: - number_c_string[i] = '\0'; - - number = strtod((const char *)number_c_string, (char **)&after_end); - if (number_c_string == after_end) { - return false; /* parse_error */ - } - - item->valuedouble = number; - - /* use saturation in case of overflow */ - if (number >= INT_MAX) { - item->valueint = INT_MAX; - } - else if (number <= (double)INT_MIN) { - item->valueint = INT_MIN; - } - else { - item->valueint = (int)number; - } - - item->type = cJSON_Number; - - input_buffer->offset += (size_t)(after_end - number_c_string); - return true; -} - -/* don't ask me, but the original cJSON_SetNumberValue returns an integer or - * double */ -CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) -{ - if (number >= INT_MAX) { - object->valueint = INT_MAX; - } - else if (number <= (double)INT_MIN) { - object->valueint = INT_MIN; - } - else { - object->valueint = (int)number; - } - - return object->valuedouble = number; -} - -CJSON_PUBLIC(char *) -cJSON_SetValuestring(cJSON *object, const char *valuestring) -{ - char *copy = NULL; - /* if object's type is not cJSON_String or is cJSON_IsReference, it should - * not set valuestring */ - if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) { - return NULL; - } - if (strlen(valuestring) <= strlen(object->valuestring)) { - strcpy(object->valuestring, valuestring); - return object->valuestring; - } - copy = - (char *)cJSON_strdup((const unsigned char *)valuestring, &global_hooks); - if (copy == NULL) { - return NULL; - } - if (object->valuestring != NULL) { - cJSON_free(object->valuestring); - } - object->valuestring = copy; - - return copy; -} - -typedef struct { - unsigned char *buffer; - size_t length; - size_t offset; - size_t depth; /* current nesting depth (for formatted printing) */ - cJSON_bool noalloc; - cJSON_bool format; /* is this print a formatted print */ - internal_hooks hooks; -} printbuffer; - -/* realloc printbuffer if necessary to have at least "needed" bytes more */ -static unsigned char * -ensure(printbuffer *const p, size_t needed) -{ - unsigned char *newbuffer = NULL; - size_t newsize = 0; - - if ((p == NULL) || (p->buffer == NULL)) { - return NULL; - } - - if ((p->length > 0) && (p->offset >= p->length)) { - /* make sure that offset is valid */ - return NULL; - } - - if (needed > INT_MAX) { - /* sizes bigger than INT_MAX are currently not supported */ - return NULL; - } - - needed += p->offset + 1; - if (needed <= p->length) { - return p->buffer + p->offset; - } - - if (p->noalloc) { - return NULL; - } - - /* calculate new buffer size */ - if (needed > (INT_MAX / 2)) { - /* overflow of int, use INT_MAX if possible */ - if (needed <= INT_MAX) { - newsize = INT_MAX; - } - else { - return NULL; - } - } - else { - newsize = needed * 2; - } - - if (p->hooks.reallocate != NULL) { - /* reallocate with realloc if available */ - newbuffer = (unsigned char *)p->hooks.reallocate(p->buffer, newsize); - if (newbuffer == NULL) { - p->hooks.deallocate(p->buffer); - p->length = 0; - p->buffer = NULL; - - return NULL; - } - } - else { - /* otherwise reallocate manually */ - newbuffer = (unsigned char *)p->hooks.allocate(newsize); - if (!newbuffer) { - p->hooks.deallocate(p->buffer); - p->length = 0; - p->buffer = NULL; - - return NULL; - } - - memcpy(newbuffer, p->buffer, p->offset + 1); - p->hooks.deallocate(p->buffer); - } - p->length = newsize; - p->buffer = newbuffer; - - return newbuffer + p->offset; -} - -/* calculate the new length of the string in a printbuffer and update the offset - */ -static void -update_offset(printbuffer *const buffer) -{ - const unsigned char *buffer_pointer = NULL; - if ((buffer == NULL) || (buffer->buffer == NULL)) { - return; - } - buffer_pointer = buffer->buffer + buffer->offset; - - buffer->offset += strlen((const char *)buffer_pointer); -} - -/* securely comparison of floating-point variables */ -static cJSON_bool -compare_double(double a, double b) -{ - double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); - return (fabs(a - b) <= maxVal * DBL_EPSILON); -} - -/* Render the number nicely from the given item into a string. */ -static cJSON_bool -print_number(const cJSON *const item, printbuffer *const output_buffer) -{ - unsigned char *output_pointer = NULL; - double d = item->valuedouble; - int length = 0; - size_t i = 0; - unsigned char number_buffer[26] = { - 0 - }; /* temporary buffer to print the number into */ - unsigned char decimal_point = get_decimal_point(); - double test = 0.0; - - if (output_buffer == NULL) { - return false; - } - - /* This checks for NaN and Infinity */ - if (isnan(d) || isinf(d)) { - length = sprintf((char *)number_buffer, "null"); - } - else if (d == (double)item->valueint) { - length = sprintf((char *)number_buffer, "%d", item->valueint); - } - else { - /* Try 15 decimal places of precision to avoid nonsignificant nonzero - * digits */ - length = sprintf((char *)number_buffer, "%1.15g", d); - - /* Check whether the original double can be recovered */ - if ((sscanf((char *)number_buffer, "%lg", &test) != 1) - || !compare_double((double)test, d)) { - /* If not, print with 17 decimal places of precision */ - length = sprintf((char *)number_buffer, "%1.17g", d); - } - } - - /* sprintf failed or buffer overrun occurred */ - if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) { - return false; - } - - /* reserve appropriate space in the output */ - output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); - if (output_pointer == NULL) { - return false; - } - - /* copy the printed number to the output and replace locale - * dependent decimal point with '.' */ - for (i = 0; i < ((size_t)length); i++) { - if (number_buffer[i] == decimal_point) { - output_pointer[i] = '.'; - continue; - } - - output_pointer[i] = number_buffer[i]; - } - output_pointer[i] = '\0'; - - output_buffer->offset += (size_t)length; - - return true; -} - -/* parse 4 digit hexadecimal number */ -static unsigned -parse_hex4(const unsigned char *const input) -{ - unsigned int h = 0; - size_t i = 0; - - for (i = 0; i < 4; i++) { - /* parse digit */ - if ((input[i] >= '0') && (input[i] <= '9')) { - h += (unsigned int)input[i] - '0'; - } - else if ((input[i] >= 'A') && (input[i] <= 'F')) { - h += (unsigned int)10 + input[i] - 'A'; - } - else if ((input[i] >= 'a') && (input[i] <= 'f')) { - h += (unsigned int)10 + input[i] - 'a'; - } - else /* invalid */ - { - return 0; - } - - if (i < 3) { - /* shift left to make place for the next nibble */ - h = h << 4; - } - } - - return h; -} - -/* converts a UTF-16 literal to UTF-8 - * A literal can be one or two sequences of the form \uXXXX */ -static unsigned char -utf16_literal_to_utf8(const unsigned char *const input_pointer, - const unsigned char *const input_end, - unsigned char **output_pointer) -{ - long unsigned int codepoint = 0; - unsigned int first_code = 0; - const unsigned char *first_sequence = input_pointer; - unsigned char utf8_length = 0; - unsigned char utf8_position = 0; - unsigned char sequence_length = 0; - unsigned char first_byte_mark = 0; - - if ((input_end - first_sequence) < 6) { - /* input ends unexpectedly */ - goto fail; - } - - /* get the first utf16 sequence */ - first_code = parse_hex4(first_sequence + 2); - - /* check that the code is valid */ - if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) { - goto fail; - } - - /* UTF16 surrogate pair */ - if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) { - const unsigned char *second_sequence = first_sequence + 6; - unsigned int second_code = 0; - sequence_length = 12; /* \uXXXX\uXXXX */ - - if ((input_end - second_sequence) < 6) { - /* input ends unexpectedly */ - goto fail; - } - - if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) { - /* missing second half of the surrogate pair */ - goto fail; - } - - /* get the second utf16 sequence */ - second_code = parse_hex4(second_sequence + 2); - /* check that the code is valid */ - if ((second_code < 0xDC00) || (second_code > 0xDFFF)) { - /* invalid second half of the surrogate pair */ - goto fail; - } - - /* calculate the unicode codepoint from the surrogate pair */ - codepoint = - 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); - } - else { - sequence_length = 6; /* \uXXXX */ - codepoint = first_code; - } - - /* encode as UTF-8 - * takes at maximum 4 bytes to encode: - * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ - if (codepoint < 0x80) { - /* normal ascii, encoding 0xxxxxxx */ - utf8_length = 1; - } - else if (codepoint < 0x800) { - /* two bytes, encoding 110xxxxx 10xxxxxx */ - utf8_length = 2; - first_byte_mark = 0xC0; /* 11000000 */ - } - else if (codepoint < 0x10000) { - /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ - utf8_length = 3; - first_byte_mark = 0xE0; /* 11100000 */ - } - else if (codepoint <= 0x10FFFF) { - /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - utf8_length = 4; - first_byte_mark = 0xF0; /* 11110000 */ - } - else { - /* invalid unicode codepoint */ - goto fail; - } - - /* encode as utf8 */ - for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; - utf8_position--) { - /* 10xxxxxx */ - (*output_pointer)[utf8_position] = - (unsigned char)((codepoint | 0x80) & 0xBF); - codepoint >>= 6; - } - /* encode first byte */ - if (utf8_length > 1) { - (*output_pointer)[0] = - (unsigned char)((codepoint | first_byte_mark) & 0xFF); - } - else { - (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); - } - - *output_pointer += utf8_length; - - return sequence_length; - -fail: - return 0; -} - -/* Parse the input text into an unescaped cinput, and populate item. */ -static cJSON_bool -parse_string(cJSON *const item, parse_buffer *const input_buffer) -{ - const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; - const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; - unsigned char *output_pointer = NULL; - unsigned char *output = NULL; - - /* not a string */ - if (buffer_at_offset(input_buffer)[0] != '\"') { - goto fail; - } - - { - /* calculate approximate size of the output (overestimate) */ - size_t allocation_length = 0; - size_t skipped_bytes = 0; - while ( - ((size_t)(input_end - input_buffer->content) < input_buffer->length) - && (*input_end != '\"')) { - /* is escape sequence */ - if (input_end[0] == '\\') { - if ((size_t)(input_end + 1 - input_buffer->content) - >= input_buffer->length) { - /* prevent buffer overflow when last input character is a - * backslash */ - goto fail; - } - skipped_bytes++; - input_end++; - } - input_end++; - } - if (((size_t)(input_end - input_buffer->content) - >= input_buffer->length) - || (*input_end != '\"')) { - goto fail; /* string ended unexpectedly */ - } - - /* This is at most how much we need for the output */ - allocation_length = (size_t)(input_end - buffer_at_offset(input_buffer)) - - skipped_bytes; - output = (unsigned char *)input_buffer->hooks.allocate(allocation_length - + sizeof("")); - if (output == NULL) { - goto fail; /* allocation failure */ - } - } - - output_pointer = output; - /* loop through the string literal */ - while (input_pointer < input_end) { - if (*input_pointer != '\\') { - *output_pointer++ = *input_pointer++; - } - /* escape sequence */ - else { - unsigned char sequence_length = 2; - if ((input_end - input_pointer) < 1) { - goto fail; - } - - switch (input_pointer[1]) { - case 'b': - *output_pointer++ = '\b'; - break; - case 'f': - *output_pointer++ = '\f'; - break; - case 'n': - *output_pointer++ = '\n'; - break; - case 'r': - *output_pointer++ = '\r'; - break; - case 't': - *output_pointer++ = '\t'; - break; - case '\"': - case '\\': - case '/': - *output_pointer++ = input_pointer[1]; - break; - - /* UTF-16 literal */ - case 'u': - sequence_length = utf16_literal_to_utf8( - input_pointer, input_end, &output_pointer); - if (sequence_length == 0) { - /* failed to convert UTF16-literal to UTF-8 */ - goto fail; - } - break; - - default: - goto fail; - } - input_pointer += sequence_length; - } - } - - /* zero terminate the output */ - *output_pointer = '\0'; - - item->type = cJSON_String; - item->valuestring = (char *)output; - - input_buffer->offset = (size_t)(input_end - input_buffer->content); - input_buffer->offset++; - - return true; - -fail: - if (output != NULL) { - input_buffer->hooks.deallocate(output); - } - - if (input_pointer != NULL) { - input_buffer->offset = (size_t)(input_pointer - input_buffer->content); - } - - return false; -} - -/* Render the cstring provided to an escaped version that can be printed. */ -static cJSON_bool -print_string_ptr(const unsigned char *const input, - printbuffer *const output_buffer) -{ - const unsigned char *input_pointer = NULL; - unsigned char *output = NULL; - unsigned char *output_pointer = NULL; - size_t output_length = 0; - /* numbers of additional characters needed for escaping */ - size_t escape_characters = 0; - - if (output_buffer == NULL) { - return false; - } - - /* empty string */ - if (input == NULL) { - output = ensure(output_buffer, sizeof("\"\"")); - if (output == NULL) { - return false; - } - strcpy((char *)output, "\"\""); - - return true; - } - - /* set "flag" to 1 if something needs to be escaped */ - for (input_pointer = input; *input_pointer; input_pointer++) { - switch (*input_pointer) { - case '\"': - case '\\': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - /* one character escape sequence */ - escape_characters++; - break; - default: - if (*input_pointer < 32) { - /* UTF-16 escape sequence uXXXX */ - escape_characters += 5; - } - break; - } - } - output_length = (size_t)(input_pointer - input) + escape_characters; - - output = ensure(output_buffer, output_length + sizeof("\"\"")); - if (output == NULL) { - return false; - } - - /* no characters have to be escaped */ - if (escape_characters == 0) { - output[0] = '\"'; - memcpy(output + 1, input, output_length); - output[output_length + 1] = '\"'; - output[output_length + 2] = '\0'; - - return true; - } - - output[0] = '\"'; - output_pointer = output + 1; - /* copy the string */ - for (input_pointer = input; *input_pointer != '\0'; - (void)input_pointer++, output_pointer++) { - if ((*input_pointer > 31) && (*input_pointer != '\"') - && (*input_pointer != '\\')) { - /* normal character, copy */ - *output_pointer = *input_pointer; - } - else { - /* character needs to be escaped */ - *output_pointer++ = '\\'; - switch (*input_pointer) { - case '\\': - *output_pointer = '\\'; - break; - case '\"': - *output_pointer = '\"'; - break; - case '\b': - *output_pointer = 'b'; - break; - case '\f': - *output_pointer = 'f'; - break; - case '\n': - *output_pointer = 'n'; - break; - case '\r': - *output_pointer = 'r'; - break; - case '\t': - *output_pointer = 't'; - break; - default: - /* escape and print as unicode codepoint */ - sprintf((char *)output_pointer, "u%04x", *input_pointer); - output_pointer += 4; - break; - } - } - } - output[output_length + 1] = '\"'; - output[output_length + 2] = '\0'; - - return true; -} - -/* Invoke print_string_ptr (which is useful) on an item. */ -static cJSON_bool -print_string(const cJSON *const item, printbuffer *const p) -{ - return print_string_ptr((unsigned char *)item->valuestring, p); -} - -/* Predeclare these prototypes. */ -static cJSON_bool -parse_value(cJSON *const item, parse_buffer *const input_buffer); -static cJSON_bool -print_value(const cJSON *const item, printbuffer *const output_buffer); -static cJSON_bool -parse_array(cJSON *const item, parse_buffer *const input_buffer); -static cJSON_bool -print_array(const cJSON *const item, printbuffer *const output_buffer); -static cJSON_bool -parse_object(cJSON *const item, parse_buffer *const input_buffer); -static cJSON_bool -print_object(const cJSON *const item, printbuffer *const output_buffer); - -/* Utility to jump whitespace and cr/lf */ -static parse_buffer * -buffer_skip_whitespace(parse_buffer *const buffer) -{ - if ((buffer == NULL) || (buffer->content == NULL)) { - return NULL; - } - - if (cannot_access_at_index(buffer, 0)) { - return buffer; - } - - while (can_access_at_index(buffer, 0) - && (buffer_at_offset(buffer)[0] <= 32)) { - buffer->offset++; - } - - if (buffer->offset == buffer->length) { - buffer->offset--; - } - - return buffer; -} - -/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ -static parse_buffer * -skip_utf8_bom(parse_buffer *const buffer) -{ - if ((buffer == NULL) || (buffer->content == NULL) - || (buffer->offset != 0)) { - return NULL; - } - - if (can_access_at_index(buffer, 4) - && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) - == 0)) { - buffer->offset += 3; - } - - return buffer; -} - -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithOpts(const char *value, const char **return_parse_end, - cJSON_bool require_null_terminated) -{ - size_t buffer_length; - - if (NULL == value) { - return NULL; - } - - /* Adding null character size due to require_null_terminated. */ - buffer_length = strlen(value) + sizeof(""); - - return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, - require_null_terminated); -} - -/* Parse an object - create a new root, and populate. */ -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, - const char **return_parse_end, - cJSON_bool require_null_terminated) -{ - parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; - cJSON *item = NULL; - - /* reset error position */ - global_error.json = NULL; - global_error.position = 0; - - if (value == NULL || 0 == buffer_length) { - goto fail; - } - - buffer.content = (const unsigned char *)value; - buffer.length = buffer_length; - buffer.offset = 0; - buffer.hooks = global_hooks; - - item = cJSON_New_Item(&global_hooks); - if (item == NULL) /* memory fail */ - { - goto fail; - } - - if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) { - /* parse failure. ep is set. */ - goto fail; - } - - /* if we require null-terminated JSON without appended garbage, skip and - * then check for a null terminator */ - if (require_null_terminated) { - buffer_skip_whitespace(&buffer); - if ((buffer.offset >= buffer.length) - || buffer_at_offset(&buffer)[0] != '\0') { - goto fail; - } - } - if (return_parse_end) { - *return_parse_end = (const char *)buffer_at_offset(&buffer); - } - - return item; - -fail: - if (item != NULL) { - cJSON_Delete(item); - } - - if (value != NULL) { - error local_error; - local_error.json = (const unsigned char *)value; - local_error.position = 0; - - if (buffer.offset < buffer.length) { - local_error.position = buffer.offset; - } - else if (buffer.length > 0) { - local_error.position = buffer.length - 1; - } - - if (return_parse_end != NULL) { - *return_parse_end = - (const char *)local_error.json + local_error.position; - } - - global_error = local_error; - } - - return NULL; -} - -/* Default options for cJSON_Parse */ -CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) -{ - return cJSON_ParseWithOpts(value, 0, 0); -} - -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLength(const char *value, size_t buffer_length) -{ - return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); -} - -#define cjson_min(a, b) (((a) < (b)) ? (a) : (b)) - -static unsigned char * -print(const cJSON *const item, cJSON_bool format, - const internal_hooks *const hooks) -{ - static const size_t default_buffer_size = 256; - printbuffer buffer[1]; - unsigned char *printed = NULL; - - memset(buffer, 0, sizeof(buffer)); - - /* create buffer */ - buffer->buffer = (unsigned char *)hooks->allocate(default_buffer_size); - buffer->length = default_buffer_size; - buffer->format = format; - buffer->hooks = *hooks; - if (buffer->buffer == NULL) { - goto fail; - } - - /* print the value */ - if (!print_value(item, buffer)) { - goto fail; - } - update_offset(buffer); - - /* check if reallocate is available */ - if (hooks->reallocate != NULL) { - printed = (unsigned char *)hooks->reallocate(buffer->buffer, - buffer->offset + 1); - if (printed == NULL) { - goto fail; - } - buffer->buffer = NULL; - } - else /* otherwise copy the JSON over to a new buffer */ - { - printed = (unsigned char *)hooks->allocate(buffer->offset + 1); - if (printed == NULL) { - goto fail; - } - memcpy(printed, buffer->buffer, - cjson_min(buffer->length, buffer->offset + 1)); - printed[buffer->offset] = '\0'; /* just to be sure */ - - /* free the buffer */ - hooks->deallocate(buffer->buffer); - } - - return printed; - -fail: - if (buffer->buffer != NULL) { - hooks->deallocate(buffer->buffer); - } - - if (printed != NULL) { - hooks->deallocate(printed); - } - - return NULL; -} - -/* Render a cJSON item/entity/structure to text. */ -CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) -{ - return (char *)print(item, true, &global_hooks); -} - -CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) -{ - return (char *)print(item, false, &global_hooks); -} - -CJSON_PUBLIC(char *) -cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -{ - printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - - if (prebuffer < 0) { - return NULL; - } - - p.buffer = (unsigned char *)global_hooks.allocate((size_t)prebuffer); - if (!p.buffer) { - return NULL; - } - - p.length = (size_t)prebuffer; - p.offset = 0; - p.noalloc = false; - p.format = fmt; - p.hooks = global_hooks; - - if (!print_value(item, &p)) { - global_hooks.deallocate(p.buffer); - return NULL; - } - - return (char *)p.buffer; -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, - const cJSON_bool format) -{ - printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - - if ((length < 0) || (buffer == NULL)) { - return false; - } - - p.buffer = (unsigned char *)buffer; - p.length = (size_t)length; - p.offset = 0; - p.noalloc = true; - p.format = format; - p.hooks = global_hooks; - - return print_value(item, &p); -} - -/* Parser core - when encountering text, process appropriately. */ -static cJSON_bool -parse_value(cJSON *const item, parse_buffer *const input_buffer) -{ - if ((input_buffer == NULL) || (input_buffer->content == NULL)) { - return false; /* no input */ - } - - /* parse the different types of values */ - /* null */ - if (can_read(input_buffer, 4) - && (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) - == 0)) { - item->type = cJSON_NULL; - input_buffer->offset += 4; - return true; - } - /* false */ - if (can_read(input_buffer, 5) - && (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) - == 0)) { - item->type = cJSON_False; - input_buffer->offset += 5; - return true; - } - /* true */ - if (can_read(input_buffer, 4) - && (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) - == 0)) { - item->type = cJSON_True; - item->valueint = 1; - input_buffer->offset += 4; - return true; - } - /* string */ - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == '\"')) { - return parse_string(item, input_buffer); - } - /* number */ - if (can_access_at_index(input_buffer, 0) - && ((buffer_at_offset(input_buffer)[0] == '-') - || ((buffer_at_offset(input_buffer)[0] >= '0') - && (buffer_at_offset(input_buffer)[0] <= '9')))) { - return parse_number(item, input_buffer); - } - /* array */ - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == '[')) { - return parse_array(item, input_buffer); - } - /* object */ - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == '{')) { - return parse_object(item, input_buffer); - } - - return false; -} - -/* Render a value to text. */ -static cJSON_bool -print_value(const cJSON *const item, printbuffer *const output_buffer) -{ - unsigned char *output = NULL; - - if ((item == NULL) || (output_buffer == NULL)) { - return false; - } - - switch ((item->type) & 0xFF) { - case cJSON_NULL: - output = ensure(output_buffer, 5); - if (output == NULL) { - return false; - } - strcpy((char *)output, "null"); - return true; - - case cJSON_False: - output = ensure(output_buffer, 6); - if (output == NULL) { - return false; - } - strcpy((char *)output, "false"); - return true; - - case cJSON_True: - output = ensure(output_buffer, 5); - if (output == NULL) { - return false; - } - strcpy((char *)output, "true"); - return true; - - case cJSON_Number: - return print_number(item, output_buffer); - - case cJSON_Raw: - { - size_t raw_length = 0; - if (item->valuestring == NULL) { - return false; - } - - raw_length = strlen(item->valuestring) + sizeof(""); - output = ensure(output_buffer, raw_length); - if (output == NULL) { - return false; - } - memcpy(output, item->valuestring, raw_length); - return true; - } - - case cJSON_String: - return print_string(item, output_buffer); - - case cJSON_Array: - return print_array(item, output_buffer); - - case cJSON_Object: - return print_object(item, output_buffer); - - default: - return false; - } -} - -/* Build an array from input text. */ -static cJSON_bool -parse_array(cJSON *const item, parse_buffer *const input_buffer) -{ - cJSON *head = NULL; /* head of the linked list */ - cJSON *current_item = NULL; - - if (input_buffer->depth >= CJSON_NESTING_LIMIT) { - return false; /* to deeply nested */ - } - input_buffer->depth++; - - if (buffer_at_offset(input_buffer)[0] != '[') { - /* not an array */ - goto fail; - } - - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == ']')) { - /* empty array */ - goto success; - } - - /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) { - input_buffer->offset--; - goto fail; - } - - /* step back to character in front of the first element */ - input_buffer->offset--; - /* loop through the comma separated array elements */ - do { - /* allocate next item */ - cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) { - goto fail; /* allocation failure */ - } - - /* attach next item to list */ - if (head == NULL) { - /* start the linked list */ - current_item = head = new_item; - } - else { - /* add to the end and advance */ - current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; - } - - /* parse next value */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) { - goto fail; /* failed to parse value */ - } - buffer_skip_whitespace(input_buffer); - } while (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == ',')); - - if (cannot_access_at_index(input_buffer, 0) - || buffer_at_offset(input_buffer)[0] != ']') { - goto fail; /* expected end of array */ - } - -success: - input_buffer->depth--; - - if (head != NULL) { - head->prev = current_item; - } - - item->type = cJSON_Array; - item->child = head; - - input_buffer->offset++; - - return true; - -fail: - if (head != NULL) { - cJSON_Delete(head); - } - - return false; -} - -/* Render an array to text */ -static cJSON_bool -print_array(const cJSON *const item, printbuffer *const output_buffer) -{ - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_element = item->child; - - if (output_buffer == NULL) { - return false; - } - - /* Compose the output array. */ - /* opening square bracket */ - output_pointer = ensure(output_buffer, 1); - if (output_pointer == NULL) { - return false; - } - - *output_pointer = '['; - output_buffer->offset++; - output_buffer->depth++; - - while (current_element != NULL) { - if (!print_value(current_element, output_buffer)) { - return false; - } - update_offset(output_buffer); - if (current_element->next) { - length = (size_t)(output_buffer->format ? 2 : 1); - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { - return false; - } - *output_pointer++ = ','; - if (output_buffer->format) { - *output_pointer++ = ' '; - } - *output_pointer = '\0'; - output_buffer->offset += length; - } - current_element = current_element->next; - } - - output_pointer = ensure(output_buffer, 2); - if (output_pointer == NULL) { - return false; - } - *output_pointer++ = ']'; - *output_pointer = '\0'; - output_buffer->depth--; - - return true; -} - -/* Build an object from the text. */ -static cJSON_bool -parse_object(cJSON *const item, parse_buffer *const input_buffer) -{ - cJSON *head = NULL; /* linked list head */ - cJSON *current_item = NULL; - - if (input_buffer->depth >= CJSON_NESTING_LIMIT) { - return false; /* to deeply nested */ - } - input_buffer->depth++; - - if (cannot_access_at_index(input_buffer, 0) - || (buffer_at_offset(input_buffer)[0] != '{')) { - goto fail; /* not an object */ - } - - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == '}')) { - goto success; /* empty object */ - } - - /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) { - input_buffer->offset--; - goto fail; - } - - /* step back to character in front of the first element */ - input_buffer->offset--; - /* loop through the comma separated array elements */ - do { - /* allocate next item */ - cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) { - goto fail; /* allocation failure */ - } - - /* attach next item to list */ - if (head == NULL) { - /* start the linked list */ - current_item = head = new_item; - } - else { - /* add to the end and advance */ - current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; - } - - /* parse the name of the child */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_string(current_item, input_buffer)) { - goto fail; /* failed to parse name */ - } - buffer_skip_whitespace(input_buffer); - - /* swap valuestring and string, because we parsed the name */ - current_item->string = current_item->valuestring; - current_item->valuestring = NULL; - - if (cannot_access_at_index(input_buffer, 0) - || (buffer_at_offset(input_buffer)[0] != ':')) { - goto fail; /* invalid object */ - } - - /* parse the value */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) { - goto fail; /* failed to parse value */ - } - buffer_skip_whitespace(input_buffer); - } while (can_access_at_index(input_buffer, 0) - && (buffer_at_offset(input_buffer)[0] == ',')); - - if (cannot_access_at_index(input_buffer, 0) - || (buffer_at_offset(input_buffer)[0] != '}')) { - goto fail; /* expected end of object */ - } - -success: - input_buffer->depth--; - - if (head != NULL) { - head->prev = current_item; - } - - item->type = cJSON_Object; - item->child = head; - - input_buffer->offset++; - return true; - -fail: - if (head != NULL) { - cJSON_Delete(head); - } - - return false; -} - -/* Render an object to text. */ -static cJSON_bool -print_object(const cJSON *const item, printbuffer *const output_buffer) -{ - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_item = item->child; - - if (output_buffer == NULL) { - return false; - } - - /* Compose the output: */ - length = (size_t)(output_buffer->format ? 2 : 1); /* fmt: {\n */ - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { - return false; - } - - *output_pointer++ = '{'; - output_buffer->depth++; - if (output_buffer->format) { - *output_pointer++ = '\n'; - } - output_buffer->offset += length; - - while (current_item) { - if (output_buffer->format) { - size_t i; - output_pointer = ensure(output_buffer, output_buffer->depth); - if (output_pointer == NULL) { - return false; - } - for (i = 0; i < output_buffer->depth; i++) { - *output_pointer++ = '\t'; - } - output_buffer->offset += output_buffer->depth; - } - - /* print key */ - if (!print_string_ptr((unsigned char *)current_item->string, - output_buffer)) { - return false; - } - update_offset(output_buffer); - - length = (size_t)(output_buffer->format ? 2 : 1); - output_pointer = ensure(output_buffer, length); - if (output_pointer == NULL) { - return false; - } - *output_pointer++ = ':'; - if (output_buffer->format) { - *output_pointer++ = '\t'; - } - output_buffer->offset += length; - - /* print value */ - if (!print_value(current_item, output_buffer)) { - return false; - } - update_offset(output_buffer); - - /* print comma if not last */ - length = ((size_t)(output_buffer->format ? 1 : 0) - + (size_t)(current_item->next ? 1 : 0)); - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) { - return false; - } - if (current_item->next) { - *output_pointer++ = ','; - } - - if (output_buffer->format) { - *output_pointer++ = '\n'; - } - *output_pointer = '\0'; - output_buffer->offset += length; - - current_item = current_item->next; - } - - output_pointer = ensure( - output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); - if (output_pointer == NULL) { - return false; - } - if (output_buffer->format) { - size_t i; - for (i = 0; i < (output_buffer->depth - 1); i++) { - *output_pointer++ = '\t'; - } - } - *output_pointer++ = '}'; - *output_pointer = '\0'; - output_buffer->depth--; - - return true; -} - -/* Get Array size/item / object item. */ -CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) -{ - cJSON *child = NULL; - size_t size = 0; - - if (array == NULL) { - return 0; - } - - child = array->child; - - while (child != NULL) { - size++; - child = child->next; - } - - /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ - - return (int)size; -} - -static cJSON * -get_array_item(const cJSON *array, size_t index) -{ - cJSON *current_child = NULL; - - if (array == NULL) { - return NULL; - } - - current_child = array->child; - while ((current_child != NULL) && (index > 0)) { - index--; - current_child = current_child->next; - } - - return current_child; -} - -CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) -{ - if (index < 0) { - return NULL; - } - - return get_array_item(array, (size_t)index); -} - -static cJSON * -get_object_item(const cJSON *const object, const char *const name, - const cJSON_bool case_sensitive) -{ - cJSON *current_element = NULL; - - if ((object == NULL) || (name == NULL)) { - return NULL; - } - - current_element = object->child; - if (case_sensitive) { - while ((current_element != NULL) && (current_element->string != NULL) - && (strcmp(name, current_element->string) != 0)) { - current_element = current_element->next; - } - } - else { - while ((current_element != NULL) - && (case_insensitive_strcmp( - (const unsigned char *)name, - (const unsigned char *)(current_element->string)) - != 0)) { - current_element = current_element->next; - } - } - - if ((current_element == NULL) || (current_element->string == NULL)) { - return NULL; - } - - return current_element; -} - -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItem(const cJSON *const object, const char *const string) -{ - return get_object_item(object, string, false); -} - -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItemCaseSensitive(const cJSON *const object, - const char *const string) -{ - return get_object_item(object, string, true); -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_HasObjectItem(const cJSON *object, const char *string) -{ - return cJSON_GetObjectItem(object, string) ? 1 : 0; -} - -/* Utility for array list handling. */ -static void -suffix_object(cJSON *prev, cJSON *item) -{ - prev->next = item; - item->prev = prev; -} - -/* Utility for handling references. */ -static cJSON * -create_reference(const cJSON *item, const internal_hooks *const hooks) -{ - cJSON *reference = NULL; - if (item == NULL) { - return NULL; - } - - reference = cJSON_New_Item(hooks); - if (reference == NULL) { - return NULL; - } - - memcpy(reference, item, sizeof(cJSON)); - reference->string = NULL; - reference->type |= cJSON_IsReference; - reference->next = reference->prev = NULL; - return reference; -} - -static cJSON_bool -add_item_to_array(cJSON *array, cJSON *item) -{ - cJSON *child = NULL; - - if ((item == NULL) || (array == NULL) || (array == item)) { - return false; - } - - child = array->child; - /* - * To find the last item in array quickly, we use prev in array - */ - if (child == NULL) { - /* list is empty, start new one */ - array->child = item; - item->prev = item; - item->next = NULL; - } - else { - /* append to the end */ - if (child->prev) { - suffix_object(child->prev, item); - array->child->prev = item; - } - } - - return true; -} - -/* Add item to array/object. */ -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) -{ - return add_item_to_array(array, item); -} - -#if defined(__clang__) \ - || (defined(__GNUC__) \ - && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic push -#endif -#ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Wcast-qual" -#endif -/* helper function to cast away const */ -static void * -cast_away_const(const void *string) -{ - return (void *)string; -} -#if defined(__clang__) \ - || (defined(__GNUC__) \ - && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic pop -#endif - -static cJSON_bool -add_item_to_object(cJSON *const object, const char *const string, - cJSON *const item, const internal_hooks *const hooks, - const cJSON_bool constant_key) -{ - char *new_key = NULL; - int new_type = cJSON_Invalid; - - if ((object == NULL) || (string == NULL) || (item == NULL) - || (object == item)) { - return false; - } - - if (constant_key) { - new_key = (char *)cast_away_const(string); - new_type = item->type | cJSON_StringIsConst; - } - else { - new_key = (char *)cJSON_strdup((const unsigned char *)string, hooks); - if (new_key == NULL) { - return false; - } - - new_type = item->type & ~cJSON_StringIsConst; - } - - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { - hooks->deallocate(item->string); - } - - item->string = new_key; - item->type = new_type; - - return add_item_to_array(object, item); -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) -{ - return add_item_to_object(object, string, item, &global_hooks, false); -} - -/* Add an item to an object with constant string as key */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) -{ - return add_item_to_object(object, string, item, &global_hooks, true); -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) -{ - if (array == NULL) { - return false; - } - - return add_item_to_array(array, create_reference(item, &global_hooks)); -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -{ - if ((object == NULL) || (string == NULL)) { - return false; - } - - return add_item_to_object(object, string, - create_reference(item, &global_hooks), - &global_hooks, false); -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddNullToObject(cJSON *const object, const char *const name) -{ - cJSON *null = cJSON_CreateNull(); - if (add_item_to_object(object, name, null, &global_hooks, false)) { - return null; - } - - cJSON_Delete(null); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddTrueToObject(cJSON *const object, const char *const name) -{ - cJSON *true_item = cJSON_CreateTrue(); - if (add_item_to_object(object, name, true_item, &global_hooks, false)) { - return true_item; - } - - cJSON_Delete(true_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddFalseToObject(cJSON *const object, const char *const name) -{ - cJSON *false_item = cJSON_CreateFalse(); - if (add_item_to_object(object, name, false_item, &global_hooks, false)) { - return false_item; - } - - cJSON_Delete(false_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddBoolToObject(cJSON *const object, const char *const name, - const cJSON_bool boolean) -{ - cJSON *bool_item = cJSON_CreateBool(boolean); - if (add_item_to_object(object, name, bool_item, &global_hooks, false)) { - return bool_item; - } - - cJSON_Delete(bool_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddNumberToObject(cJSON *const object, const char *const name, - const double number) -{ - cJSON *number_item = cJSON_CreateNumber(number); - if (add_item_to_object(object, name, number_item, &global_hooks, false)) { - return number_item; - } - - cJSON_Delete(number_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddStringToObject(cJSON *const object, const char *const name, - const char *const string) -{ - cJSON *string_item = cJSON_CreateString(string); - if (add_item_to_object(object, name, string_item, &global_hooks, false)) { - return string_item; - } - - cJSON_Delete(string_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddRawToObject(cJSON *const object, const char *const name, - const char *const raw) -{ - cJSON *raw_item = cJSON_CreateRaw(raw); - if (add_item_to_object(object, name, raw_item, &global_hooks, false)) { - return raw_item; - } - - cJSON_Delete(raw_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddObjectToObject(cJSON *const object, const char *const name) -{ - cJSON *object_item = cJSON_CreateObject(); - if (add_item_to_object(object, name, object_item, &global_hooks, false)) { - return object_item; - } - - cJSON_Delete(object_item); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_AddArrayToObject(cJSON *const object, const char *const name) -{ - cJSON *array = cJSON_CreateArray(); - if (add_item_to_object(object, name, array, &global_hooks, false)) { - return array; - } - - cJSON_Delete(array); - return NULL; -} - -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) -{ - if ((parent == NULL) || (item == NULL)) { - return NULL; - } - - if (item != parent->child) { - /* not the first element */ - item->prev->next = item->next; - } - if (item->next != NULL) { - /* not the last element */ - item->next->prev = item->prev; - } - - if (item == parent->child) { - /* first element */ - parent->child = item->next; - } - else if (item->next == NULL) { - /* last element */ - parent->child->prev = item->prev; - } - - /* make sure the detached item doesn't point anywhere anymore */ - item->prev = NULL; - item->next = NULL; - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) -{ - if (which < 0) { - return NULL; - } - - return cJSON_DetachItemViaPointer(array, - get_array_item(array, (size_t)which)); -} - -CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) -{ - cJSON_Delete(cJSON_DetachItemFromArray(array, which)); -} - -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObject(cJSON *object, const char *string) -{ - cJSON *to_detach = cJSON_GetObjectItem(object, string); - - return cJSON_DetachItemViaPointer(object, to_detach); -} - -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) -{ - cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); - - return cJSON_DetachItemViaPointer(object, to_detach); -} - -CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) -{ - cJSON_Delete(cJSON_DetachItemFromObject(object, string)); -} - -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) -{ - cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); -} - -/* Replace array/object items with new ones. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -{ - cJSON *after_inserted = NULL; - - if (which < 0) { - return false; - } - - after_inserted = get_array_item(array, (size_t)which); - if (after_inserted == NULL) { - return add_item_to_array(array, newitem); - } - - newitem->next = after_inserted; - newitem->prev = after_inserted->prev; - after_inserted->prev = newitem; - if (after_inserted == array->child) { - array->child = newitem; - } - else { - newitem->prev->next = newitem; - } - return true; -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, - cJSON *replacement) -{ - if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) - || (item == NULL)) { - return false; - } - - if (replacement == item) { - return true; - } - - replacement->next = item->next; - replacement->prev = item->prev; - - if (replacement->next != NULL) { - replacement->next->prev = replacement; - } - if (parent->child == item) { - if (parent->child->prev == parent->child) { - replacement->prev = replacement; - } - parent->child = replacement; - } - else { /* - * To find the last item in array quickly, we use prev in array. - * We can't modify the last item's next pointer where this item was - * the parent's child - */ - if (replacement->prev != NULL) { - replacement->prev->next = replacement; - } - if (replacement->next == NULL) { - parent->child->prev = replacement; - } - } - - item->next = NULL; - item->prev = NULL; - cJSON_Delete(item); - - return true; -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) -{ - if (which < 0) { - return false; - } - - return cJSON_ReplaceItemViaPointer( - array, get_array_item(array, (size_t)which), newitem); -} - -static cJSON_bool -replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, - cJSON_bool case_sensitive) -{ - if ((replacement == NULL) || (string == NULL)) { - return false; - } - - /* replace the name in the replacement */ - if (!(replacement->type & cJSON_StringIsConst) - && (replacement->string != NULL)) { - cJSON_free(replacement->string); - } - replacement->string = - (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); - if (replacement->string == NULL) { - return false; - } - - replacement->type &= ~cJSON_StringIsConst; - - return cJSON_ReplaceItemViaPointer( - object, get_object_item(object, string, case_sensitive), replacement); -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) -{ - return replace_item_in_object(object, string, newitem, false); -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, - cJSON *newitem) -{ - return replace_item_in_object(object, string, newitem, true); -} - -/* Create basic types: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_NULL; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_True; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_False; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = boolean ? cJSON_True : cJSON_False; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Number; - item->valuedouble = num; - - /* use saturation in case of overflow */ - if (num >= INT_MAX) { - item->valueint = INT_MAX; - } - else if (num <= (double)INT_MIN) { - item->valueint = INT_MIN; - } - else { - item->valueint = (int)num; - } - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_String; - item->valuestring = - (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); - if (!item->valuestring) { - cJSON_Delete(item); - return NULL; - } - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_String | cJSON_IsReference; - item->valuestring = (char *)cast_away_const(string); - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_Object | cJSON_IsReference; - item->child = (cJSON *)cast_away_const(child); - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_Array | cJSON_IsReference; - item->child = (cJSON *)cast_away_const(child); - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Raw; - item->valuestring = - (char *)cJSON_strdup((const unsigned char *)raw, &global_hooks); - if (!item->valuestring) { - cJSON_Delete(item); - return NULL; - } - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Array; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) { - item->type = cJSON_Object; - } - - return item; -} - -/* Create Arrays: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) -{ - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; - - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber(numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; - } - if (!i) { - a->child = n; - } - else { - suffix_object(p, n); - } - p = n; - } - - if (a && a->child) { - a->child->prev = n; - } - - return a; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) -{ - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; - - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber((double)numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; - } - if (!i) { - a->child = n; - } - else { - suffix_object(p, n); - } - p = n; - } - - if (a && a->child) { - a->child->prev = n; - } - - return a; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) -{ - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; - - if ((count < 0) || (numbers == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateNumber(numbers[i]); - if (!n) { - cJSON_Delete(a); - return NULL; - } - if (!i) { - a->child = n; - } - else { - suffix_object(p, n); - } - p = n; - } - - if (a && a->child) { - a->child->prev = n; - } - - return a; -} - -CJSON_PUBLIC(cJSON *) -cJSON_CreateStringArray(const char *const *strings, int count) -{ - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; - - if ((count < 0) || (strings == NULL)) { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) { - n = cJSON_CreateString(strings[i]); - if (!n) { - cJSON_Delete(a); - return NULL; - } - if (!i) { - a->child = n; - } - else { - suffix_object(p, n); - } - p = n; - } - - if (a && a->child) { - a->child->prev = n; - } - - return a; -} - -/* Duplication */ -CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -{ - cJSON *newitem = NULL; - cJSON *child = NULL; - cJSON *next = NULL; - cJSON *newchild = NULL; - - /* Bail on bad ptr */ - if (!item) { - goto fail; - } - /* Create new item */ - newitem = cJSON_New_Item(&global_hooks); - if (!newitem) { - goto fail; - } - /* Copy over all vars */ - newitem->type = item->type & (~cJSON_IsReference); - newitem->valueint = item->valueint; - newitem->valuedouble = item->valuedouble; - if (item->valuestring) { - newitem->valuestring = (char *)cJSON_strdup( - (unsigned char *)item->valuestring, &global_hooks); - if (!newitem->valuestring) { - goto fail; - } - } - if (item->string) { - newitem->string = (item->type & cJSON_StringIsConst) - ? item->string - : (char *)cJSON_strdup( - (unsigned char *)item->string, &global_hooks); - if (!newitem->string) { - goto fail; - } - } - /* If non-recursive, then we're done! */ - if (!recurse) { - return newitem; - } - /* Walk the ->next chain for the child. */ - child = item->child; - while (child != NULL) { - newchild = cJSON_Duplicate( - child, - true); /* Duplicate (with recurse) each item in the ->next chain */ - if (!newchild) { - goto fail; - } - if (next != NULL) { - /* If newitem->child already set, then crosswire ->prev and ->next - * and move on */ - next->next = newchild; - newchild->prev = next; - next = newchild; - } - else { - /* Set newitem->child and move to it */ - newitem->child = newchild; - next = newchild; - } - child = child->next; - } - if (newitem && newitem->child) { - newitem->child->prev = newchild; - } - - return newitem; - -fail: - if (newitem != NULL) { - cJSON_Delete(newitem); - } - - return NULL; -} - -static void -skip_oneline_comment(char **input) -{ - *input += static_strlen("//"); - - for (; (*input)[0] != '\0'; ++(*input)) { - if ((*input)[0] == '\n') { - *input += static_strlen("\n"); - return; - } - } -} - -static void -skip_multiline_comment(char **input) -{ - *input += static_strlen("/*"); - - for (; (*input)[0] != '\0'; ++(*input)) { - if (((*input)[0] == '*') && ((*input)[1] == '/')) { - *input += static_strlen("*/"); - return; - } - } -} - -static void -minify_string(char **input, char **output) -{ - (*output)[0] = (*input)[0]; - *input += static_strlen("\""); - *output += static_strlen("\""); - - for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { - (*output)[0] = (*input)[0]; - - if ((*input)[0] == '\"') { - (*output)[0] = '\"'; - *input += static_strlen("\""); - *output += static_strlen("\""); - return; - } - else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { - (*output)[1] = (*input)[1]; - *input += static_strlen("\""); - *output += static_strlen("\""); - } - } -} - -CJSON_PUBLIC(void) cJSON_Minify(char *json) -{ - char *into = json; - - if (json == NULL) { - return; - } - - while (json[0] != '\0') { - switch (json[0]) { - case ' ': - case '\t': - case '\r': - case '\n': - json++; - break; - - case '/': - if (json[1] == '/') { - skip_oneline_comment(&json); - } - else if (json[1] == '*') { - skip_multiline_comment(&json); - } - else { - json++; - } - break; - - case '\"': - minify_string(&json, (char **)&into); - break; - - default: - into[0] = json[0]; - json++; - into++; - } - } - - /* and null-terminate. */ - *into = '\0'; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Invalid; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_False; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xff) == cJSON_True; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & (cJSON_True | cJSON_False)) != 0; -} -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_NULL; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Number; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_String; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Array; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Object; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item) -{ - if (item == NULL) { - return false; - } - - return (item->type & 0xFF) == cJSON_Raw; -} - -CJSON_PUBLIC(cJSON_bool) -cJSON_Compare(const cJSON *const a, const cJSON *const b, - const cJSON_bool case_sensitive) -{ - if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) { - return false; - } - - /* check if type is valid */ - switch (a->type & 0xFF) { - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - case cJSON_Number: - case cJSON_String: - case cJSON_Raw: - case cJSON_Array: - case cJSON_Object: - break; - - default: - return false; - } - - /* identical objects are equal */ - if (a == b) { - return true; - } - - switch (a->type & 0xFF) { - /* in these cases and equal type is enough */ - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - return true; - - case cJSON_Number: - if (compare_double(a->valuedouble, b->valuedouble)) { - return true; - } - return false; - - case cJSON_String: - case cJSON_Raw: - if ((a->valuestring == NULL) || (b->valuestring == NULL)) { - return false; - } - if (strcmp(a->valuestring, b->valuestring) == 0) { - return true; - } - - return false; - - case cJSON_Array: - { - cJSON *a_element = a->child; - cJSON *b_element = b->child; - - for (; (a_element != NULL) && (b_element != NULL);) { - if (!cJSON_Compare(a_element, b_element, case_sensitive)) { - return false; - } - - a_element = a_element->next; - b_element = b_element->next; - } - - /* one of the arrays is longer than the other */ - if (a_element != b_element) { - return false; - } - - return true; - } - - case cJSON_Object: - { - cJSON *a_element = NULL; - cJSON *b_element = NULL; - cJSON_ArrayForEach(a_element, a) - { - /* TODO This has O(n^2) runtime, which is horrible! */ - b_element = - get_object_item(b, a_element->string, case_sensitive); - if (b_element == NULL) { - return false; - } - - if (!cJSON_Compare(a_element, b_element, case_sensitive)) { - return false; - } - } - - /* doing this twice, once on a and b to prevent true comparison if a - * subset of b - * TODO: Do this the proper way, this is just a fix for now */ - cJSON_ArrayForEach(b_element, b) - { - a_element = - get_object_item(a, b_element->string, case_sensitive); - if (a_element == NULL) { - return false; - } - - if (!cJSON_Compare(b_element, a_element, case_sensitive)) { - return false; - } - } - - return true; - } - - default: - return false; - } -} - -CJSON_PUBLIC(void *) cJSON_malloc(size_t size) -{ - return global_hooks.allocate(size); -} - -CJSON_PUBLIC(void) cJSON_free(void *object) -{ - global_hooks.deallocate(object); -} diff --git a/test-tools/host-tool/external/cJSON/cJSON.h b/test-tools/host-tool/external/cJSON/cJSON.h deleted file mode 100644 index 2cafdcf59..000000000 --- a/test-tools/host-tool/external/cJSON/cJSON.h +++ /dev/null @@ -1,392 +0,0 @@ -/* - Copyright (c) 2009-2017 Dave Gamble and cJSON contributors - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ - -#ifndef cJSON__h -#define cJSON__h - -#ifdef __cplusplus -extern "C" { -#endif - -#if !defined(__WINDOWS__) \ - && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) \ - || defined(_WIN32)) -#define __WINDOWS__ -#endif - -#ifdef __WINDOWS__ - -/* When compiling for windows, we specify a specific calling convention to avoid -issues where we are being called from a project with a different default calling -convention. For windows you have 3 define options: - -CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever -dllexport symbols CJSON_EXPORT_SYMBOLS - Define this on library build when you -want to dllexport symbols (default) CJSON_IMPORT_SYMBOLS - Define this if you -want to dllimport symbol - -For *nix builds that support visibility attribute, you can define similar -behavior by - -setting default visibility to hidden by adding --fvisibility=hidden (for gcc) -or --xldscope=hidden (for sun cc) -to CFLAGS - -then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way -CJSON_EXPORT_SYMBOLS does - -*/ - -#define CJSON_CDECL __cdecl -#define CJSON_STDCALL __stdcall - -/* export symbols by default, this is necessary for copy pasting the C and - * header file */ -#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) \ - && !defined(CJSON_EXPORT_SYMBOLS) -#define CJSON_EXPORT_SYMBOLS -#endif - -#if defined(CJSON_HIDE_SYMBOLS) -#define CJSON_PUBLIC(type) type CJSON_STDCALL -#elif defined(CJSON_EXPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL -#elif defined(CJSON_IMPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL -#endif -#else /* !__WINDOWS__ */ -#define CJSON_CDECL -#define CJSON_STDCALL - -#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) \ - && defined(CJSON_API_VISIBILITY) -#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type -#else -#define CJSON_PUBLIC(type) type -#endif -#endif - -/* project version */ -#define CJSON_VERSION_MAJOR 1 -#define CJSON_VERSION_MINOR 7 -#define CJSON_VERSION_PATCH 16 - -#include - -/* cJSON Types: */ -#define cJSON_Invalid (0) -#define cJSON_False (1 << 0) -#define cJSON_True (1 << 1) -#define cJSON_NULL (1 << 2) -#define cJSON_Number (1 << 3) -#define cJSON_String (1 << 4) -#define cJSON_Array (1 << 5) -#define cJSON_Object (1 << 6) -#define cJSON_Raw (1 << 7) /* raw json */ - -#define cJSON_IsReference 256 -#define cJSON_StringIsConst 512 - -/* The cJSON structure: */ -typedef struct cJSON { - /* next/prev allow you to walk array/object chains. Alternatively, use - * GetArraySize/GetArrayItem/GetObjectItem */ - struct cJSON *next; - struct cJSON *prev; - /* An array or object item will have a child pointer pointing to a chain of - * the items in the array/object. */ - struct cJSON *child; - - /* The type of the item, as above. */ - int type; - - /* The item's string, if type==cJSON_String and type == cJSON_Raw */ - char *valuestring; - /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ - int valueint; - /* The item's number, if type==cJSON_Number */ - double valuedouble; - - /* The item's name string, if this item is the child of, or is in the list - * of subitems of an object. */ - char *string; -} cJSON; - -typedef struct cJSON_Hooks { - /* malloc/free are CDECL on Windows regardless of the default calling - * convention of the compiler, so ensure the hooks allow passing those - * functions directly. */ - void *(CJSON_CDECL *malloc_fn)(size_t sz); - void(CJSON_CDECL *free_fn)(void *ptr); -} cJSON_Hooks; - -typedef int cJSON_bool; - -/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse - * them. This is to prevent stack overflows. */ -#ifndef CJSON_NESTING_LIMIT -#define CJSON_NESTING_LIMIT 1000 -#endif - -/* returns the version of cJSON as a string */ -CJSON_PUBLIC(const char *) cJSON_Version(void); - -/* Supply malloc, realloc and free functions to cJSON */ -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks); - -/* Memory Management: the caller is always responsible to free the results from - * all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib - * free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is - * cJSON_PrintPreallocated, where the caller has full responsibility of the - * buffer. */ -/* Supply a block of JSON, and this returns a cJSON object you can interrogate. - */ -CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLength(const char *value, size_t buffer_length); -/* ParseWithOpts allows you to require (and check) that the JSON is null - * terminated, and to retrieve the pointer to the final byte parsed. */ -/* If you supply a ptr in return_parse_end and parsing fails, then - * return_parse_end will contain a pointer to the error so will match - * cJSON_GetErrorPtr(). */ -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithOpts(const char *value, const char **return_parse_end, - cJSON_bool require_null_terminated); -CJSON_PUBLIC(cJSON *) -cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, - const char **return_parse_end, - cJSON_bool require_null_terminated); - -/* Render a cJSON entity to text for transfer/storage. */ -CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); -/* Render a cJSON entity to text for transfer/storage without any formatting. */ -CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); -/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess - * at the final size. guessing well reduces reallocation. fmt=0 gives - * unformatted, =1 gives formatted */ -CJSON_PUBLIC(char *) -cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); -/* Render a cJSON entity to text using a buffer already allocated in memory with - * given length. Returns 1 on success and 0 on failure. */ -/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will - * use, so to be safe allocate 5 bytes more than you actually need */ -CJSON_PUBLIC(cJSON_bool) -cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, - const cJSON_bool format); -/* Delete a cJSON entity and all subentities. */ -CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); - -/* Returns the number of items in an array (or object). */ -CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); -/* Retrieve item number "index" from array "array". Returns NULL if - * unsuccessful. */ -CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); -/* Get item "string" from object. Case insensitive. */ -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItem(const cJSON *const object, const char *const string); -CJSON_PUBLIC(cJSON *) -cJSON_GetObjectItemCaseSensitive(const cJSON *const object, - const char *const string); -CJSON_PUBLIC(cJSON_bool) -cJSON_HasObjectItem(const cJSON *object, const char *string); -/* For analysing failed parses. This returns a pointer to the parse error. - * You'll probably need to look a few chars back to make sense of it. Defined - * when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ -CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); - -/* Check item type and return its value */ -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item); -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item); - -/* These functions check the type of an item */ -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item); - -/* These calls create a cJSON item of the appropriate type. */ -CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); -CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); -CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); -CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); -CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); -CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); -/* raw json */ -CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); -CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); -CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); - -/* Create a string where valuestring references a string so - * it will not be freed by cJSON_Delete */ -CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); -/* Create an object/array that only references it's elements so - * they will not be freed by cJSON_Delete */ -CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); -CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); - -/* These utilities create an Array of count items. - * The parameter count cannot be greater than the number of elements in the - * number array, otherwise array access will be out of bounds.*/ -CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); -CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); -CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); -CJSON_PUBLIC(cJSON *) -cJSON_CreateStringArray(const char *const *strings, int count); - -/* Append item to the specified array/object. */ -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item); -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); -/* Use this when string is definitely const (i.e. a literal, or as good as), and - * will definitely survive the cJSON object. WARNING: When this function was - * used, make sure to always check that (item->type & cJSON_StringIsConst) is - * zero before writing to `item->string` */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); -/* Append reference to item to the specified array/object. Use this when you - * want to add an existing cJSON to a new cJSON, but don't want to corrupt your - * existing cJSON. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); -CJSON_PUBLIC(cJSON_bool) -cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); - -/* Remove/Detach items from Arrays/Objects. */ -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item); -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); -CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObject(cJSON *object, const char *string); -CJSON_PUBLIC(cJSON *) -cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObject(cJSON *object, const char *string); -CJSON_PUBLIC(void) -cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); - -/* Update array items. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_InsertItemInArray( - cJSON *array, int which, - cJSON *newitem); /* Shifts pre-existing items to the right. */ -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, - cJSON *replacement); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem); -CJSON_PUBLIC(cJSON_bool) -cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, - cJSON *newitem); - -/* Duplicate a cJSON item */ -CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); -/* Duplicate will create a new, identical cJSON item to the one you pass, in new - * memory that will need to be released. With recurse!=0, it will duplicate any - * children connected to the item. The item->next and ->prev pointers are always - * zero on return from Duplicate. */ -/* Recursively compare two cJSON items for equality. If either a or b is NULL or - * invalid, they will be considered unequal. case_sensitive determines if object - * keys are treated case sensitive (1) or case insensitive (0) */ -CJSON_PUBLIC(cJSON_bool) -cJSON_Compare(const cJSON *const a, const cJSON *const b, - const cJSON_bool case_sensitive); - -/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from - * strings. The input pointer json cannot point to a read-only address area, - * such as a string constant, but should point to a readable and writable - * address area. */ -CJSON_PUBLIC(void) cJSON_Minify(char *json); - -/* Helper functions for creating and adding items to an object at the same time. - * They return the added item or NULL on failure. */ -CJSON_PUBLIC(cJSON *) -cJSON_AddNullToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddTrueToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddFalseToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddBoolToObject(cJSON *const object, const char *const name, - const cJSON_bool boolean); -CJSON_PUBLIC(cJSON *) -cJSON_AddNumberToObject(cJSON *const object, const char *const name, - const double number); -CJSON_PUBLIC(cJSON *) -cJSON_AddStringToObject(cJSON *const object, const char *const name, - const char *const string); -CJSON_PUBLIC(cJSON *) -cJSON_AddRawToObject(cJSON *const object, const char *const name, - const char *const raw); -CJSON_PUBLIC(cJSON *) -cJSON_AddObjectToObject(cJSON *const object, const char *const name); -CJSON_PUBLIC(cJSON *) -cJSON_AddArrayToObject(cJSON *const object, const char *const name); - -/* When assigning an integer value, it needs to be propagated to valuedouble - * too. */ -#define cJSON_SetIntValue(object, number) \ - ((object) ? (object)->valueint = (object)->valuedouble = (number) \ - : (number)) -/* helper for the cJSON_SetNumberValue macro */ -CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); -#define cJSON_SetNumberValue(object, number) \ - ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) \ - : (number)) -/* Change the valuestring of a cJSON_String object, only takes effect when type - * of object is cJSON_String */ -CJSON_PUBLIC(char *) -cJSON_SetValuestring(cJSON *object, const char *valuestring); - -/* If the object is not a boolean type this does nothing and returns - * cJSON_Invalid else it returns the new type*/ -#define cJSON_SetBoolValue(object, boolValue) \ - ((object != NULL && ((object)->type & (cJSON_False | cJSON_True))) \ - ? (object)->type = ((object)->type & (~(cJSON_False | cJSON_True))) \ - | ((boolValue) ? cJSON_True : cJSON_False) \ - : cJSON_Invalid) - -/* Macro for iterating over an array or object */ -#define cJSON_ArrayForEach(element, array) \ - for (element = (array != NULL) ? (array)->child : NULL; element != NULL; \ - element = element->next) - -/* malloc/free objects using the malloc/free functions that have been set with - * cJSON_InitHooks */ -CJSON_PUBLIC(void *) cJSON_malloc(size_t size); -CJSON_PUBLIC(void) cJSON_free(void *object); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test-tools/host-tool/external/cJSON/cjson.cmake b/test-tools/host-tool/external/cJSON/cjson.cmake deleted file mode 100644 index af1a9d8a1..000000000 --- a/test-tools/host-tool/external/cJSON/cjson.cmake +++ /dev/null @@ -1,10 +0,0 @@ - -set (CJSON_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${CJSON_DIR}) - - -file (GLOB_RECURSE source_all ${CJSON_DIR}/*.c) - -set (CJSON_SOURCE ${source_all}) - diff --git a/test-tools/host-tool/src/host_tool_utils.c b/test-tools/host-tool/src/host_tool_utils.c deleted file mode 100644 index 9ea3d6ca9..000000000 --- a/test-tools/host-tool/src/host_tool_utils.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "host_tool_utils.h" -#include "bi-inc/shared_utils.h" -#include "bh_platform.h" - -#include -#include -#include -#include -#include - -typedef union jvalue { - bool z; - int8_t i8; - uint8_t u8; - int16_t i16; - uint16_t u16; - int32_t i32; - uint32_t u32; - int64_t i64; - uint64_t u64; - float f; - double d; -} jvalue; - -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) -{ - return get_int16(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) -{ - return get_int32(buf); -} - -char * -attr_container_get_attr_begin(const attr_container_t *attr_cont, - uint32_t *p_total_length, uint16_t *p_attr_num); - -cJSON * -attr2json(const attr_container_t *attr_cont) -{ - uint32_t total_length; - uint16_t attr_num, i, j, type; - const char *p, *tag, *key; - jvalue value; - cJSON *root; - - if (!attr_cont) - return NULL; - - root = cJSON_CreateObject(); - if (!root) - return NULL; - - /* TODO: how to convert the tag? */ - tag = attr_container_get_tag(attr_cont); - if (!tag) - goto fail; - - p = attr_container_get_attr_begin(attr_cont, &total_length, &attr_num); - if (!p) - goto fail; - - for (i = 0; i < attr_num; i++) { - cJSON *obj; - - key = p + 2; - /* Skip key len and key */ - p += 2 + get_uint16(p); - type = *p++; - - switch (type) { - case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ - bh_memcpy_s(&value.i8, 1, p, 1); - if (NULL == (obj = cJSON_CreateNumber(value.i8))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p++; - break; - case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ - bh_memcpy_s(&value.i16, sizeof(int16_t), p, sizeof(int16_t)); - if (NULL == (obj = cJSON_CreateNumber(value.i16))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - /* another approach: cJSON_AddNumberToObject(root, key, value.s) - */ - p += 2; - break; - case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ - bh_memcpy_s(&value.i32, sizeof(int32_t), p, sizeof(int32_t)); - if (NULL == (obj = cJSON_CreateNumber(value.i32))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p += 4; - break; - case ATTR_TYPE_INT64: - bh_memcpy_s(&value.i64, sizeof(int64_t), p, sizeof(int64_t)); - if (NULL == (obj = cJSON_CreateNumber(value.i64))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p += 8; - break; - case ATTR_TYPE_UINT8: - bh_memcpy_s(&value.u8, 1, p, 1); - if (NULL == (obj = cJSON_CreateNumber(value.u8))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p++; - break; - case ATTR_TYPE_UINT16: - bh_memcpy_s(&value.u16, sizeof(uint16_t), p, sizeof(uint16_t)); - if (NULL == (obj = cJSON_CreateNumber(value.u16))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p += 2; - break; - case ATTR_TYPE_UINT32: - bh_memcpy_s(&value.u32, sizeof(uint32_t), p, sizeof(uint32_t)); - if (NULL == (obj = cJSON_CreateNumber(value.u32))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p += 4; - break; - case ATTR_TYPE_UINT64: - bh_memcpy_s(&value.u64, sizeof(uint64_t), p, sizeof(uint64_t)); - if (NULL == (obj = cJSON_CreateNumber(value.u64))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p += 8; - break; - case ATTR_TYPE_FLOAT: - bh_memcpy_s(&value.f, sizeof(float), p, sizeof(float)); - if (NULL == (obj = cJSON_CreateNumber(value.f))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p += 4; - break; - case ATTR_TYPE_DOUBLE: - bh_memcpy_s(&value.d, sizeof(double), p, sizeof(double)); - if (NULL == (obj = cJSON_CreateNumber(value.d))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p += 8; - break; - case ATTR_TYPE_BOOLEAN: - bh_memcpy_s(&value.z, 1, p, 1); - if (NULL == (obj = cJSON_CreateBool(value.z))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p++; - break; - case ATTR_TYPE_STRING: - if (NULL == (obj = cJSON_CreateString(p + sizeof(uint16_t)))) - goto fail; - cJSON_AddItemToObject(root, key, obj); - p += sizeof(uint16_t) + get_uint16(p); - break; - case ATTR_TYPE_BYTEARRAY: - if (NULL == (obj = cJSON_CreateArray())) - goto fail; - cJSON_AddItemToObject(root, key, obj); - for (j = 0; j < get_uint32(p); j++) { - cJSON *item = - cJSON_CreateNumber(*(p + sizeof(uint32_t) + j)); - if (item == NULL) - goto fail; - cJSON_AddItemToArray(obj, item); - } - p += sizeof(uint32_t) + get_uint32(p); - break; - } - } - - return root; - -fail: - cJSON_Delete(root); - return NULL; -} - -attr_container_t * -json2attr(const cJSON *json_obj) -{ - attr_container_t *attr_cont; - cJSON *item; - - if (NULL == (attr_cont = attr_container_create(""))) - return NULL; - - if (!cJSON_IsObject(json_obj)) - goto fail; - - cJSON_ArrayForEach(item, json_obj) - { - - if (cJSON_IsNumber(item)) { - attr_container_set_double(&attr_cont, item->string, - item->valuedouble); - } - else if (cJSON_IsTrue(item)) { - attr_container_set_bool(&attr_cont, item->string, true); - } - else if (cJSON_IsFalse(item)) { - attr_container_set_bool(&attr_cont, item->string, false); - } - else if (cJSON_IsString(item)) { - attr_container_set_string(&attr_cont, item->string, - item->valuestring); - } - else if (cJSON_IsArray(item)) { - int8_t *array; - int i = 0, len = sizeof(int8_t) * cJSON_GetArraySize(item); - cJSON *array_item; - - if (0 == len || NULL == (array = (int8_t *)malloc(len))) - goto fail; - memset(array, 0, len); - - cJSON_ArrayForEach(array_item, item) - { - /* must be number array */ - if (!cJSON_IsNumber(array_item)) - break; - /* TODO: if array_item->valuedouble > 127 or < -128 */ - array[i++] = (int8_t)array_item->valuedouble; - } - if (i > 0) - attr_container_set_bytearray(&attr_cont, item->string, array, - i); - free(array); - } - } - - return attr_cont; - -fail: - attr_container_destroy(attr_cont); - return NULL; -} - -int g_mid = 0; - -int -gen_random_id() -{ - static bool init = false; - int r; - - if (!init) { - srand(time(NULL)); - init = true; - } - - r = rand(); - g_mid = r; - - return r; -} - -char * -read_file_to_buffer(const char *filename, int *ret_size) -{ - char *buffer; - int file; - int file_size, read_size; - struct stat stat_buf; - - if (!filename || !ret_size) { - return NULL; - } - - if ((file = open(filename, O_RDONLY, 0)) == -1) { - return NULL; - } - - if (fstat(file, &stat_buf) != 0) { - close(file); - return NULL; - } - - file_size = stat_buf.st_size; - - if (!(buffer = malloc(file_size))) { - close(file); - return NULL; - } - - read_size = read(file, buffer, file_size); - close(file); - - if (read_size < file_size) { - free(buffer); - return NULL; - } - - *ret_size = file_size; - return buffer; -} - -int -wirte_buffer_to_file(const char *filename, const char *buffer, int size) -{ - int file, ret; - - if ((file = open(filename, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) - return -1; - - ret = write(file, buffer, size); - - close(file); - - return ret; -} diff --git a/test-tools/host-tool/src/host_tool_utils.h b/test-tools/host-tool/src/host_tool_utils.h deleted file mode 100644 index 9b30b41ab..000000000 --- a/test-tools/host-tool/src/host_tool_utils.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _HOST_TOOL_UTILS_H_ -#define _HOST_TOOL_UTILS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "bi-inc/attr_container.h" -#include "cJSON.h" - -/** - * @brief Convert attribute container object to cJSON object. - * - * @param attr the attribute container object to be converted - * - * @return the created cJSON object if not NULL, NULL means fail - * - * @warning the return object should be deleted with cJSON_Delete by caller - */ -cJSON * -attr2json(const attr_container_t *attr); - -/** - * @brief Convert cJSON object to attribute container object. - * - * @param json the cJSON object to be converted - * - * @return the created attribute container object if not NULL, NULL means fail - * - * @warning the return object should be deleted with attr_container_destroy - */ -attr_container_t * -json2attr(const cJSON *json); - -/** - * @brief Generate a random 32 bit integer. - * - * @return the generated random integer - */ -int -gen_random_id(); - -/** - * @brief Read file content to buffer. - * - * @param filename the file name to read - * @param ret_size pointer of integer to save file size once return success - * - * @return the created buffer which contains file content if not NULL, NULL - * means fail - * - * @warning the return buffer should be deleted with free by caller - */ -char * -read_file_to_buffer(const char *filename, int *ret_size); - -/** - * @brief Write buffer content to file. - * - * @param filename name the file name to be written - * @param buffer the buffer - * @param size size of the buffer to be written - * - * @return < 0 means fail, > 0 means the number of bytes actually written - */ -int -wirte_buffer_to_file(const char *filename, const char *buffer, int size); - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif diff --git a/test-tools/host-tool/src/main.c b/test-tools/host-tool/src/main.c deleted file mode 100644 index dbddbf81b..000000000 --- a/test-tools/host-tool/src/main.c +++ /dev/null @@ -1,887 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "host_tool_utils.h" -#include "bi-inc/shared_utils.h" -#include "bi-inc/attr_container.h" -#include "coap_ext.h" -#include "cJSON.h" -#include "app_manager_export.h" /* for Module_WASM_App */ -#include "host_link.h" /* for REQUEST_PACKET */ -#include "transport.h" - -#define BUF_SIZE 1024 -#define TIMEOUT_EXIT_CODE 2 -#define URL_MAX_LEN 256 -#define DEFAULT_TIMEOUT_MS 5000 -#define DEFAULT_ALIVE_TIME_MS 0 - -#define CONNECTION_MODE_TCP 1 -#define CONNECTION_MODE_UART 2 - -typedef enum { - INSTALL, - UNINSTALL, - QUERY, - REQUEST, - REGISTER, - UNREGISTER -} op_type; - -typedef struct { - const char *file; - const char *name; - const char *module_type; - int heap_size; - /* max timers number */ - int timers; - int watchdog_interval; -} inst_info; - -typedef struct { - const char *name; - const char *module_type; -} uninst_info; - -typedef struct { - const char *name; -} query_info; - -typedef struct { - const char *url; - int action; - const char *json_payload_file; -} req_info; - -typedef struct { - const char *urls; -} reg_info; - -typedef struct { - const char *urls; -} unreg_info; - -typedef union operation_info { - inst_info inst; - uninst_info uinst; - query_info query; - req_info req; - reg_info reg; - unreg_info unreg; -} operation_info; - -typedef struct { - op_type type; - operation_info info; -} operation; - -typedef enum REPLY_PACKET_TYPE { - REPLY_TYPE_EVENT = 0, - REPLY_TYPE_RESPONSE = 1 -} REPLY_PACKET_TYPE; - -static uint32_t g_timeout_ms = DEFAULT_TIMEOUT_MS; -static uint32_t g_alive_time_ms = DEFAULT_ALIVE_TIME_MS; -static char *g_redirect_file_name = NULL; -static int g_redirect_udp_port = -1; -static int g_conn_fd; /* may be tcp or uart */ -static char *g_server_addr = "127.0.0.1"; -static int g_server_port = 8888; -static char *g_uart_dev = "/dev/ttyS2"; -static int g_baudrate = B115200; -static int g_connection_mode = CONNECTION_MODE_TCP; - -extern int g_mid; -extern unsigned char leading[2]; - -/* -1 fail, 0 success */ -static int -send_request(request_t *request, uint16_t msg_type) -{ - char *req_p; - int req_size, req_size_n, ret = -1; - - if ((req_p = pack_request(request, &req_size)) == NULL) - return -1; - - /* leading bytes */ - if (!host_tool_send_data(g_conn_fd, leading, sizeof(leading))) - goto ret; - - /* message type */ - msg_type = htons(msg_type); - if (!host_tool_send_data(g_conn_fd, (char *)&msg_type, sizeof(msg_type))) - goto ret; - - /* payload length */ - req_size_n = htonl(req_size); - if (!host_tool_send_data(g_conn_fd, (char *)&req_size_n, - sizeof(req_size_n))) - goto ret; - - /* payload */ - if (!host_tool_send_data(g_conn_fd, req_p, req_size)) - goto ret; - - ret = 0; - -ret: - free_req_resp_packet(req_p); - return ret; -} - -#define url_remain_space (sizeof(url) - strlen(url)) - -/** - * return: 0: success, others: fail - */ -static int -install(inst_info *info) -{ - request_t request[1] = { 0 }; - char *app_file_buf; - char url[URL_MAX_LEN] = { 0 }; - int ret = -1, app_size; - - snprintf(url, sizeof(url) - 1, "/applet?name=%s", info->name); - - if (info->module_type != NULL && url_remain_space > 0) - snprintf(url + strlen(url), url_remain_space, "&type=%s", - info->module_type); - - if (info->heap_size > 0 && url_remain_space > 0) - snprintf(url + strlen(url), url_remain_space, "&heap=%d", - info->heap_size); - - if (info->timers > 0 && url_remain_space > 0) - snprintf(url + strlen(url), url_remain_space, "&timers=%d", - info->timers); - - if (info->watchdog_interval > 0 && url_remain_space > 0) - snprintf(url + strlen(url), url_remain_space, "&wd=%d", - info->watchdog_interval); - - if ((app_file_buf = read_file_to_buffer(info->file, &app_size)) == NULL) - return -1; - - init_request(request, url, COAP_PUT, FMT_APP_RAW_BINARY, app_file_buf, - app_size); - request->mid = gen_random_id(); - - if (info->module_type == NULL || strcmp(info->module_type, "wasm") == 0) - ret = send_request(request, INSTALL_WASM_APP); - else - ret = send_request(request, REQUEST_PACKET); - - free(app_file_buf); - - return ret; -} - -static int -uninstall(uninst_info *info) -{ - request_t request[1] = { 0 }; - char url[URL_MAX_LEN] = { 0 }; - - snprintf(url, sizeof(url) - 1, "/applet?name=%s", info->name); - - if (info->module_type != NULL && url_remain_space > 0) - snprintf(url + strlen(url), url_remain_space, "&type=%s", - info->module_type); - - init_request(request, url, COAP_DELETE, FMT_ATTR_CONTAINER, NULL, 0); - request->mid = gen_random_id(); - - return send_request(request, REQUEST_PACKET); -} - -static int -query(query_info *info) -{ - request_t request[1] = { 0 }; - char url[URL_MAX_LEN] = { 0 }; - - if (info->name != NULL) - snprintf(url, sizeof(url) - 1, "/applet?name=%s", info->name); - else - snprintf(url, sizeof(url) - 1, "/applet"); - - init_request(request, url, COAP_GET, FMT_ATTR_CONTAINER, NULL, 0); - request->mid = gen_random_id(); - - return send_request(request, REQUEST_PACKET); -} - -static int -request(req_info *info) -{ - request_t request[1] = { 0 }; - attr_container_t *payload = NULL; - int ret = -1, payload_len = 0; - - if (info->json_payload_file != NULL) { - char *payload_file; - cJSON *json; - int payload_file_size; - - if ((payload_file = read_file_to_buffer(info->json_payload_file, - &payload_file_size)) - == NULL) - return -1; - - if (NULL == (json = cJSON_Parse(payload_file))) { - free(payload_file); - goto fail; - } - - if (NULL == (payload = json2attr(json))) { - cJSON_Delete(json); - free(payload_file); - goto fail; - } - payload_len = attr_container_get_serialize_length(payload); - - cJSON_Delete(json); - free(payload_file); - } - - init_request(request, (char *)info->url, info->action, FMT_ATTR_CONTAINER, - payload, payload_len); - request->mid = gen_random_id(); - - ret = send_request(request, REQUEST_PACKET); - - if (info->json_payload_file != NULL && payload != NULL) - attr_container_destroy(payload); - -fail: - return ret; -} - -/** - * TODO: currently only support 1 url. - * how to handle multiple responses and set process's exit code? - */ -static int -subscribe(reg_info *info) -{ - request_t request[1] = { 0 }; - int ret = -1; -#if 0 - char *p; - - p = strtok(info->urls, ","); - while(p != NULL) { - char url[URL_MAX_LEN] = {0}; - snprintf(url, URL_MAX_LEN, "%s%s", "/event/", p); - init_request(request, - url, - COAP_PUT, - FMT_ATTR_CONTAINER, - NULL, - 0); - request->mid = gen_random_id(); - ret = send_request(request, false); - p = strtok (NULL, ","); - } -#else - char url[URL_MAX_LEN] = { 0 }; - char *prefix = info->urls[0] == '/' ? "/event" : "/event/"; - snprintf(url, URL_MAX_LEN, "%s%s", prefix, info->urls); - init_request(request, url, COAP_PUT, FMT_ATTR_CONTAINER, NULL, 0); - request->mid = gen_random_id(); - ret = send_request(request, REQUEST_PACKET); -#endif - return ret; -} - -static int -unsubscribe(unreg_info *info) -{ - request_t request[1] = { 0 }; - int ret = -1; -#if 0 - char *p; - - p = strtok(info->urls, ","); - while(p != NULL) { - char url[URL_MAX_LEN] = {0}; - snprintf(url, URL_MAX_LEN, "%s%s", "/event/", p); - init_request(request, - url, - COAP_DELETE, - FMT_ATTR_CONTAINER, - NULL, - 0); - request->mid = gen_random_id(); - ret = send_request(request, false); - p = strtok (NULL, ","); - } -#else - char url[URL_MAX_LEN] = { 0 }; - snprintf(url, URL_MAX_LEN, "%s%s", "/event/", info->urls); - init_request(request, url, COAP_DELETE, FMT_ATTR_CONTAINER, NULL, 0); - request->mid = gen_random_id(); - ret = send_request(request, REQUEST_PACKET); -#endif - return ret; -} - -static int -init() -{ - if (g_connection_mode == CONNECTION_MODE_TCP) { - int fd; - if (!tcp_init(g_server_addr, g_server_port, &fd)) - return -1; - g_conn_fd = fd; - return 0; - } - else if (g_connection_mode == CONNECTION_MODE_UART) { - int fd; - if (!uart_init(g_uart_dev, g_baudrate, &fd)) - return -1; - g_conn_fd = fd; - return 0; - } - - return -1; -} - -static void -deinit() -{ - close(g_conn_fd); -} - -static int -parse_action(const char *str) -{ - if (strcasecmp(str, "PUT") == 0) - return COAP_PUT; - if (strcasecmp(str, "GET") == 0) - return COAP_GET; - if (strcasecmp(str, "DELETE") == 0) - return COAP_DELETE; - if (strcasecmp(str, "POST") == 0) - return COAP_POST; - return -1; -} - -/* clang-format off */ -static void showUsage() -{ - printf("Usages:\n"); - printf(" host_tool -i|-u|-q|-r|-s|-d ...\n"); - printf(" host_tool -i -f \n" - " [--type=]\n" - " [--heap=]\n" - " [--timers=]\n" - " [--watchdog=]\n" - " [ ...] \n"); - printf(" host_tool -u [ ...]\n"); - printf(" host_tool -q[] [ ...]\n"); - printf(" host_tool -r -A [-p ] [ ...]\n"); - printf(" host_tool -s [ ...]\n"); - printf(" host_tool -d [ ...]\n"); - - printf("\nGeneral Options:\n"); - printf(" -i, --install Install an application\n"); - printf(" -u, --uninstall Uninstall an application\n"); - printf(" -q, --query Query all applications\n"); - printf(" -r, --request Send a request\n"); - printf(" -s, --register Register event(s)\n"); - printf(" -d, --deregister De-register event(s)\n"); - printf(" -f, --file Specify app binary file path\n"); - printf(" -A, --action Specify action of the request\n"); - printf(" -p, --payload Specify payload of the request\n"); - - printf("\nControl Options:\n"); - printf(" -S
|--address=
Set server address, default to 127.0.0.1\n"); - printf(" -P |--port= Set server port, default to 8888\n"); - printf(" -D |--uart= Set uart device, default to /dev/ttyS2\n"); - printf(" -B |--baudrate= Set uart device baudrate, default to 115200\n"); - printf(" -t |--timeout= Operation timeout in ms, default to 5000\n"); - printf(" -a |--alive= Alive time in ms after last operation done, default to 0\n"); - printf(" -o |--output= Redirect the output to output a file\n"); - printf(" -U |--udp= Redirect the output to an UDP port in local machine\n"); - - printf("\nNotes:\n"); - printf(" =name of the application\n"); - printf(" =path of the application binary file in wasm format\n"); - printf(" =resource descriptor, such as /app//res1 or /res1\n"); - printf(" =event url list separated by ',', such as /event1,/event2,/event3\n"); - printf(" =action of the request, can be PUT, GET, DELETE or POST (case insensitive)\n"); - printf(" =path of the payload file in json format\n"); - printf(" =Type of app. Can be 'wasm'(default) or 'jeff'\n"); - printf(" =Heap size of app.\n"); - printf(" =Max timers number app can use.\n"); - printf(" =Watchdog interval in ms.\n"); -} - -#define CHECK_DUPLICATE_OPERATION do { \ - if (operation_parsed) { \ - showUsage(); \ - return false; \ - } \ -} while(0) - -#define ERROR_RETURN do { \ - showUsage(); \ - return false; \ -} while(0) - -#define CHECK_ARGS_UNMATCH_OPERATION(op_type) do { \ - if (!operation_parsed || op->type != op_type) { \ - showUsage(); \ - return false; \ - } \ -} while(0) - -static bool parse_args(int argc, char *argv[], operation *op) -{ - int c; - bool operation_parsed = false; - bool conn_mode_parsed = false; - - while (1) { - int optIndex = 0; - static struct option longOpts[] = { - { "install", required_argument, NULL, 'i' }, - { "uninstall", required_argument, NULL, 'u' }, - { "query", optional_argument, NULL, 'q' }, - { "request", required_argument, NULL, 'r' }, - { "register", required_argument, NULL, 's' }, - { "deregister", required_argument, NULL, 'd' }, - { "timeout", required_argument, NULL, 't' }, - { "alive", required_argument, NULL, 'a' }, - { "output", required_argument, NULL, 'o' }, - { "udp", required_argument, NULL, 'U' }, - { "action", required_argument, NULL, 'A' }, - { "file", required_argument, NULL, 'f' }, - { "payload", required_argument, NULL, 'p' }, - { "type", required_argument, NULL, 0 }, - { "heap", required_argument, NULL, 1 }, - { "timers", required_argument, NULL, 2 }, - { "watchdog", required_argument, NULL, 3 }, - { "address", required_argument, NULL, 'S' }, - { "port", required_argument, NULL, 'P' }, - { "uart_device",required_argument, NULL, 'D' }, - { "baudrate", required_argument, NULL, 'B' }, - { "help", required_argument, NULL, 'h' }, - { 0, 0, 0, 0 } - }; - - c = getopt_long(argc, argv, "i:u:q::r:s:d:t:a:o:U:A:f:p:S:P:D:B:h", - longOpts, &optIndex); - if (c == -1) - break; - - switch (c) { - case 'i': - CHECK_DUPLICATE_OPERATION; - op->type = INSTALL; - op->info.inst.name = optarg; - operation_parsed = true; - break; - case 'u': - CHECK_DUPLICATE_OPERATION; - op->type = UNINSTALL; - op->info.uinst.name = optarg; - operation_parsed = true; - break; - case 'q': - CHECK_DUPLICATE_OPERATION; - op->type = QUERY; - op->info.query.name = optarg; - break; - case 'r': - CHECK_DUPLICATE_OPERATION; - op->type = REQUEST; - op->info.req.url = optarg; - operation_parsed = true; - break; - case 's': - CHECK_DUPLICATE_OPERATION; - op->type = REGISTER; - op->info.reg.urls = optarg; - operation_parsed = true; - break; - case 'd': - CHECK_DUPLICATE_OPERATION; - op->type = UNREGISTER; - op->info.unreg.urls = optarg; - operation_parsed = true; - break; - case 't': - g_timeout_ms = atoi(optarg); - break; - case 'a': - g_alive_time_ms = atoi(optarg); - break; - case 'o': - g_redirect_file_name = optarg; - break; - case 'U': - g_redirect_udp_port = atoi(optarg); - break; - case 'A': - CHECK_ARGS_UNMATCH_OPERATION(REQUEST); - op->info.req.action = parse_action(optarg); - break; - case 'f': - CHECK_ARGS_UNMATCH_OPERATION(INSTALL); - op->info.inst.file = optarg; - break; - case 'p': - CHECK_ARGS_UNMATCH_OPERATION(REQUEST); - op->info.req.json_payload_file = optarg; - break; - /* module type */ - case 0: - /* TODO: use bit mask */ - /* CHECK_ARGS_UNMATCH_OPERATION(INSTALL | UNINSTALL); */ - if (op->type == INSTALL) - op->info.inst.module_type = optarg; - else if (op->type == UNINSTALL) - op->info.uinst.module_type = optarg; - break; - /* heap */ - case 1: - CHECK_ARGS_UNMATCH_OPERATION(INSTALL); - op->info.inst.heap_size = atoi(optarg); - break; - /* timers */ - case 2: - CHECK_ARGS_UNMATCH_OPERATION(INSTALL); - op->info.inst.timers = atoi(optarg); - break; - /* watchdog */ - case 3: - CHECK_ARGS_UNMATCH_OPERATION(INSTALL); - op->info.inst.watchdog_interval = atoi(optarg); - break; - case 'S': - if (conn_mode_parsed) { - showUsage(); - return false; - } - g_connection_mode = CONNECTION_MODE_TCP; - g_server_addr = optarg; - conn_mode_parsed = true; - break; - case 'P': - g_server_port = atoi(optarg); - break; - case 'D': - if (conn_mode_parsed) { - showUsage(); - return false; - } - g_connection_mode = CONNECTION_MODE_UART; - g_uart_dev = optarg; - conn_mode_parsed = true; - break; - case 'B': - g_baudrate = parse_baudrate(atoi(optarg)); - break; - case 'h': - showUsage(); - return false; - default: - showUsage(); - return false; - } - } - - /* check mandatory options for the operation */ - switch (op->type) { - case INSTALL: - if (NULL == op->info.inst.file || NULL == op->info.inst.name) - ERROR_RETURN; - break; - case UNINSTALL: - if (NULL == op->info.uinst.name) - ERROR_RETURN; - break; - case QUERY: - break; - case REQUEST: - if (NULL == op->info.req.url || op->info.req.action <= 0) - ERROR_RETURN; - break; - case REGISTER: - if (NULL == op->info.reg.urls) - ERROR_RETURN; - break; - case UNREGISTER: - if (NULL == op->info.unreg.urls) - ERROR_RETURN; - break; - default: - return false; - } - - return true; -} - -/** - * return value: < 0: not complete message - * REPLY_TYPE_EVENT: event(request) - * REPLY_TYPE_RESPONSE: response - */ -static int process_reply_data(const char *buf, int len, - imrt_link_recv_context_t *ctx) -{ - int result = -1; - const char *pos = buf; - -#if DEBUG - int i = 0; - for (; i < len; i++) { - printf(" 0x%02x", buf[i]); - } - printf("\n"); -#endif - - while (len-- > 0) { - result = on_imrt_link_byte_arrive((unsigned char) *pos++, ctx); - switch (result) { - case 0: { - imrt_link_message_t *message = &ctx->message; - if (message->message_type == RESPONSE_PACKET) - return REPLY_TYPE_RESPONSE; - if (message->message_type == REQUEST_PACKET) - return REPLY_TYPE_EVENT; - break; - } - default: - break; - } - } - - return -1; -} - -static response_t * -parse_response_from_imrtlink(imrt_link_message_t *message, response_t *response) -{ - if (!unpack_response(message->payload, message->payload_size, response)) - return NULL; - - return response; -} - -static request_t * -parse_event_from_imrtlink(imrt_link_message_t *message, request_t *request) -{ - if (!unpack_request(message->payload, message->payload_size, request)) - return NULL; - - return request; -} - -static void output(const char *header, attr_container_t *payload, - int foramt, int payload_len) -{ - cJSON *json = NULL; - char *json_str = NULL; - - /* output the header */ - printf("%s", header); - if (g_redirect_file_name != NULL) - wirte_buffer_to_file(g_redirect_file_name, header, strlen(header)); - if (g_redirect_udp_port > 0 && g_redirect_udp_port < 65535) - udp_send("127.0.0.1", g_redirect_udp_port, header, strlen(header)); - - if (foramt != FMT_ATTR_CONTAINER || payload == NULL || payload_len <= 0) - return; - - if ((json = attr2json(payload)) == NULL) - return; - - if ((json_str = cJSON_Print(json)) == NULL) { - cJSON_Delete(json); - return; - } - - /* output the payload as json format */ - printf("%s", json_str); - if (g_redirect_file_name != NULL) - wirte_buffer_to_file(g_redirect_file_name, json_str, strlen(json_str)); - if (g_redirect_udp_port > 0 && g_redirect_udp_port < 65535) - udp_send("127.0.0.1", g_redirect_udp_port, json_str, strlen(json_str)); - - free(json_str); - cJSON_Delete(json); -} - -static void output_response(response_t *obj) -{ - char header[32] = { 0 }; - snprintf(header, sizeof(header), "\nresponse status %d\n", obj->status); - output(header, obj->payload, obj->fmt, obj->payload_len); -} - -static void output_event(request_t *obj) -{ - char header[256] = { 0 }; - snprintf(header, sizeof(header), "\nreceived an event %s\n", obj->url); - output(header, obj->payload, obj->fmt, obj->payload_len); -} - -int main(int argc, char *argv[]) -{ - int ret = -1; - imrt_link_recv_context_t recv_ctx = { 0 }; - char buffer[BUF_SIZE] = { 0 }; - uint32_t last_check = 0, total_elpased_ms = 0; - bool is_responsed = false; - operation op; - - memset(&op, 0, sizeof(op)); - - if (!parse_args(argc, argv, &op)) - return -1; - - /* TODO: reconnect 3 times */ - if (init() != 0) - return -1; - - switch (op.type) { - case INSTALL: - ret = install((inst_info *) &op.info.inst); - break; - case UNINSTALL: - ret = uninstall((uninst_info *) &op.info.uinst); - break; - case QUERY: - ret = query((query_info *) &op.info.query); - break; - case REQUEST: - ret = request((req_info *) &op.info.req); - break; - case REGISTER: - ret = subscribe((reg_info *) &op.info.reg); - break; - case UNREGISTER: - ret = unsubscribe((unreg_info *) &op.info.unreg); - break; - default: - goto ret; - } - - if (ret != 0) - goto ret; - - bh_get_elpased_ms(&last_check); - - while (1) { - int result = 0; - fd_set readfds; - struct timeval tv; - - total_elpased_ms += bh_get_elpased_ms(&last_check); - - if (!is_responsed) { - if (total_elpased_ms >= g_timeout_ms) { - output("operation timeout\n", NULL, 0, 0); - ret = TIMEOUT_EXIT_CODE; - goto ret; - } - } else { - if (total_elpased_ms >= g_alive_time_ms) { - /*ret = 0;*/ - goto ret; - } - } - - if (g_conn_fd == -1) { - if ((init() != 0) - || (g_conn_fd == -1)) { - sleep(1); - continue; - } - } - - FD_ZERO(&readfds); - FD_SET(g_conn_fd, &readfds); - - tv.tv_sec = 1; - tv.tv_usec = 0; - - result = select(FD_SETSIZE, &readfds, NULL, NULL, &tv); - - if (result < 0) { - if (errno != EINTR) { - printf("Error in select, errno: 0x%x\n", errno); - ret = -1; - goto ret; - } - } - else if (result == 0) { /* select timeout */ - } - else if (result > 0) { - int n; - if (FD_ISSET(g_conn_fd, &readfds)) { - int reply_type = -1; - - n = read(g_conn_fd, buffer, BUF_SIZE); - if (n <= 0) { - g_conn_fd = -1; - continue; - } - - reply_type = process_reply_data((char *) buffer, n, &recv_ctx); - - if (reply_type == REPLY_TYPE_RESPONSE) { - response_t response[1] = { 0 }; - - parse_response_from_imrtlink(&recv_ctx.message, response); - - if (response->mid != g_mid) { - /* ignore invalid response */ - continue; - } - - is_responsed = true; - ret = response->status; - output_response(response); - - if (op.type == REGISTER || op.type == UNREGISTER) { - /* alive time start */ - total_elpased_ms = 0; - bh_get_elpased_ms(&last_check); - } - } - else if (reply_type == REPLY_TYPE_EVENT) { - request_t event[1] = { 0 }; - - parse_event_from_imrtlink(&recv_ctx.message, event); - - if (op.type == REGISTER || op.type == UNREGISTER) { - output_event(event); - } - } - } - } - } /* end of while(1) */ - -ret: - if (recv_ctx.message.payload != NULL) - free(recv_ctx.message.payload); - - deinit(); - return ret; -} diff --git a/test-tools/host-tool/src/transport.c b/test-tools/host-tool/src/transport.c deleted file mode 100644 index d4edf4f1d..000000000 --- a/test-tools/host-tool/src/transport.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "transport.h" - -#define SA struct sockaddr - -unsigned char leading[2] = { 0x12, 0x34 }; - -bool -tcp_init(const char *address, uint16_t port, int *fd) -{ - int sock; - struct sockaddr_in servaddr; - - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) - return false; - - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = inet_addr(address); - servaddr.sin_port = htons(port); - - if (connect(sock, (SA *)&servaddr, sizeof(servaddr)) != 0) { - close(sock); - return false; - } - - *fd = sock; - return true; -} - -int -parse_baudrate(int baud) -{ - switch (baud) { - case 9600: - return B9600; - case 19200: - return B19200; - case 38400: - return B38400; - case 57600: - return B57600; - case 115200: - return B115200; - case 230400: - return B230400; - case 460800: - return B460800; - case 500000: - return B500000; - case 576000: - return B576000; - case 921600: - return B921600; - case 1000000: - return B1000000; - case 1152000: - return B1152000; - case 1500000: - return B1500000; - case 2000000: - return B2000000; - case 2500000: - return B2500000; - case 3000000: - return B3000000; - case 3500000: - return B3500000; - case 4000000: - return B4000000; - default: - return -1; - } -} - -bool -uart_init(const char *device, int baudrate, int *fd) -{ - int uart_fd; - struct termios uart_term; - - uart_fd = open(device, O_RDWR | O_NOCTTY); - - if (uart_fd < 0) - return false; - - memset(&uart_term, 0, sizeof(uart_term)); - uart_term.c_cflag = baudrate | CS8 | CLOCAL | CREAD; - uart_term.c_iflag = IGNPAR; - uart_term.c_oflag = 0; - - /* set noncanonical mode */ - uart_term.c_lflag = 0; - uart_term.c_cc[VTIME] = 30; - uart_term.c_cc[VMIN] = 1; - tcflush(uart_fd, TCIFLUSH); - - if (tcsetattr(uart_fd, TCSANOW, &uart_term) != 0) { - close(uart_fd); - return false; - } - - *fd = uart_fd; - return true; -} - -bool -udp_send(const char *address, int port, const char *buf, int len) -{ - int sockfd; - ssize_t size_sent; - struct sockaddr_in servaddr; - - if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - return false; - - memset(&servaddr, 0, sizeof(servaddr)); - - servaddr.sin_family = AF_INET; - servaddr.sin_port = htons(port); - servaddr.sin_addr.s_addr = INADDR_ANY; - - size_sent = sendto(sockfd, buf, len, MSG_CONFIRM, - (const struct sockaddr *)&servaddr, sizeof(servaddr)); - - close(sockfd); - return (size_sent != -1) ? true : false; -} - -bool -host_tool_send_data(int fd, const char *buf, unsigned int len) -{ - int cnt = 0; - ssize_t ret; - - if (fd == -1 || buf == NULL || len <= 0) { - return false; - } - -resend: - ret = write(fd, buf, len); - - if (ret == -1) { - if (errno == ECONNRESET) { - close(fd); - } - - // repeat sending if the outbuffer is full - if (errno == EAGAIN || errno == EWOULDBLOCK) { - if (++cnt > 10) { - close(fd); - return false; - } - sleep(1); - goto resend; - } - } - - return (ret == len); -} - -#define SET_RECV_PHASE(ctx, new_phase) \ - do { \ - ctx->phase = new_phase; \ - ctx->size_in_phase = 0; \ - } while (0) - -/* - * input: 1 byte from remote - * output: parse result - * return: -1 invalid sync byte - * 1 byte added to buffer, waiting more for complete packet - * 0 completed packet - * 2 in receiving payload - */ -int -on_imrt_link_byte_arrive(unsigned char ch, imrt_link_recv_context_t *ctx) -{ - if (ctx->phase == Phase_Non_Start) { - if (ctx->message.payload) { - free(ctx->message.payload); - ctx->message.payload = NULL; - ctx->message.payload_size = 0; - } - - if (leading[0] == ch) { - ctx->phase = Phase_Leading; - } - else { - return -1; - } - } - else if (ctx->phase == Phase_Leading) { - if (leading[1] == ch) { - SET_RECV_PHASE(ctx, Phase_Type); - } - else { - ctx->phase = Phase_Non_Start; - return -1; - } - } - else if (ctx->phase == Phase_Type) { - unsigned char *p = (unsigned char *)&ctx->message.message_type; - p[ctx->size_in_phase++] = ch; - - if (ctx->size_in_phase == sizeof(ctx->message.message_type)) { - ctx->message.message_type = ntohs(ctx->message.message_type); - SET_RECV_PHASE(ctx, Phase_Size); - } - } - else if (ctx->phase == Phase_Size) { - unsigned char *p = (unsigned char *)&ctx->message.payload_size; - p[ctx->size_in_phase++] = ch; - - if (ctx->size_in_phase == sizeof(ctx->message.payload_size)) { - ctx->message.payload_size = ntohl(ctx->message.payload_size); - SET_RECV_PHASE(ctx, Phase_Payload); - - if (ctx->message.payload) { - free(ctx->message.payload); - ctx->message.payload = NULL; - } - - /* no payload */ - if (ctx->message.payload_size == 0) { - SET_RECV_PHASE(ctx, Phase_Non_Start); - return 0; - } - - ctx->message.payload = (char *)malloc(ctx->message.payload_size); - SET_RECV_PHASE(ctx, Phase_Payload); - } - } - else if (ctx->phase == Phase_Payload) { - ctx->message.payload[ctx->size_in_phase++] = ch; - - if (ctx->size_in_phase == ctx->message.payload_size) { - SET_RECV_PHASE(ctx, Phase_Non_Start); - return 0; - } - - return 2; - } - - return 1; -} diff --git a/test-tools/host-tool/src/transport.h b/test-tools/host-tool/src/transport.h deleted file mode 100644 index 449f438f8..000000000 --- a/test-tools/host-tool/src/transport.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef DEPS_APP_MGR_HOST_TOOL_SRC_TRANSPORT_H_ -#define DEPS_APP_MGR_HOST_TOOL_SRC_TRANSPORT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* IMRT link message between host and WAMR */ -typedef struct { - unsigned short message_type; - unsigned int payload_size; - char *payload; -} imrt_link_message_t; - -/* The receive phase of IMRT link message */ -typedef enum { - Phase_Non_Start, - Phase_Leading, - Phase_Type, - Phase_Size, - Phase_Payload -} recv_phase_t; - -/* The receive context of IMRT link message */ -typedef struct { - recv_phase_t phase; - int size_in_phase; - imrt_link_message_t message; -} imrt_link_recv_context_t; - -/** - * @brief Send data to WAMR. - * - * @param fd the connection fd to WAMR - * @param buf the buffer that contains content to be sent - * @param len size of the buffer to be sent - * - * @return true if success, false if fail - */ -bool -host_tool_send_data(int fd, const char *buf, unsigned int len); - -/** - * @brief Handle one byte of IMRT link message - * - * @param ch the one byte from WAMR to be handled - * @param ctx the receive context - * - * @return -1 invalid sync byte - * 1 byte added to buffer, waiting more for complete packet - * 0 completed packet - * 2 in receiving payload - */ -int -on_imrt_link_byte_arrive(unsigned char ch, imrt_link_recv_context_t *ctx); - -/** - * @brief Initialize TCP connection with remote server. - * - * @param address the network address of peer - * @param port the network port of peer - * @param fd pointer of integer to save the socket fd once return success - * - * @return true if success, false if fail - */ -bool -tcp_init(const char *address, uint16_t port, int *fd); - -/** - * @brief Initialize UART connection with remote. - * - * @param device name of the UART device - * @param baudrate baudrate of the device - * @param fd pointer of integer to save the uart fd once return success - * - * @return true if success, false if fail - */ -bool -uart_init(const char *device, int baudrate, int *fd); - -/** - * @brief Parse UART baudrate from an integer - * - * @param the baudrate interger to be parsed - * - * @return true if success, false if fail - * - * @par - * @code - * int baudrate = parse_baudrate(9600); - * ... - * uart_term.c_cflag = baudrate; - * ... - * @endcode - */ -int -parse_baudrate(int baud); - -/** - * @brief Send data over UDP. - * - * @param address network address of the remote - * @param port network port of the remote - * @param buf the buffer that contains content to be sent - * @param len size of the buffer to be sent - * - * @return true if success, false if fail - */ -bool -udp_send(const char *address, int port, const char *buf, int len); - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif - -#endif /* DEPS_APP_MGR_HOST_TOOL_SRC_TRANSPORT_H_ */ diff --git a/tests/wamr-test-suites/spec-test-script/collect_coverage.sh b/tests/wamr-test-suites/spec-test-script/collect_coverage.sh index 09b1f465e..0091e7649 100755 --- a/tests/wamr-test-suites/spec-test-script/collect_coverage.sh +++ b/tests/wamr-test-suites/spec-test-script/collect_coverage.sh @@ -34,8 +34,7 @@ lcov -q -r ${SRC_TEMP_COV_FILE} -o ${SRC_TEMP_COV_FILE} \ -rc lcov_branch_coverage=1 \ "*/usr/*" "*/_deps/*" "*/deps/*" "*/tests/unit/*" \ "*/llvm/include/*" "*/include/llvm/*" "*/samples/*" \ - "*/app-framework/*" "*/app-mgr/*" "*/test-tools/*" \ - "*/tests/standalone/*" "*/tests/*" + "*/test-tools/*" "*/tests/standalone/*" "*/tests/*" if [[ -s ${SRC_TEMP_COV_FILE} ]]; then if [[ -s ${DST_COV_FILE} ]]; then diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index a11db40aa..6a3f97521 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -214,7 +214,6 @@ endif() set (SHARED_DIR ../core/shared) set (IWASM_DIR ../core/iwasm) -set (APP_FRAMEWORK_DIR ../core/app-framework) include_directories (${SHARED_DIR}/include ${IWASM_DIR}/include) diff --git a/wamr-sdk/Kconfig b/wamr-sdk/Kconfig deleted file mode 100644 index 96c23a83c..000000000 --- a/wamr-sdk/Kconfig +++ /dev/null @@ -1,84 +0,0 @@ -mainmenu "WebAssembly Micro Runtime Configuration" - -choice - prompt "select a build target" - - config TARGET_X86_64 - bool "X86_64" - - config TARGET_X86_32 - bool "X86_32" - -endchoice - -choice - prompt "select a target platform" - - config PLATFORM_LINUX - bool "Linux" - -endchoice - -menu "select execution mode" - comment "At least one execution mode must be selected" - config EXEC_AOT - bool "AOT" - depends on PLATFORM_LINUX - - config EXEC_JIT - bool "JIT" - depends on PLATFORM_LINUX - select BUILD_LLVM - - config BUILD_LLVM - bool "build llvm (this may take a long time)" - depends on EXEC_JIT - help - llvm library is required by JIT mode. - - config EXEC_INTERP - bool "INTERPRETER" - default y -endmenu - -choice - prompt "libc support" - - config LIBC_BUILTIN - bool "builtin libc" - help - use builtin libc, this is a minimal subset of libc. - - config LIBC_WASI - bool "WebAssembly System Interface [WASI]" - depends on PLATFORM_LINUX - help - enable WebAssembly System Interface - -endchoice - -choice - prompt "application framework" - config APP_FRAMEWORK_DISABLE - bool "Disable app framework" - help - Disable wamr app framework - - config APP_FRAMEWORK_DEFAULT - bool "Default components" - help - Default components - - config APP_FRAMEWORK_ALL - bool "All components" - - config APP_FRAMEWORK_CUSTOM - bool "customized module config" - - menu "modules:" - depends on APP_FRAMEWORK_CUSTOM - - source ".wamr_modules" - - endmenu -endchoice diff --git a/wamr-sdk/Makefile b/wamr-sdk/Makefile deleted file mode 100644 index a0824aeab..000000000 --- a/wamr-sdk/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# # This will generate SDK for both runtime and wasm application -config: - ./build_sdk.sh -i - -menuconfig: - ./menuconfig.sh - diff --git a/wamr-sdk/README.md b/wamr-sdk/README.md index fd926af86..ef0cfd2ff 100644 --- a/wamr-sdk/README.md +++ b/wamr-sdk/README.md @@ -1,133 +1,3 @@ -# WebAssembly Micro Runtime SDK - -Usually there are two tasks for integrating the WAMR into a particular project: - -- Select what WAMR components (vmcore, libc, app-mgr, app-framework components) to be integrated, and get the associated source files added into the project building configuration -- Generate the APP SDK for developing the WASM apps on the selected libc and framework components - -The **[WAMR SDK](./wamr-sdk)** tools is helpful to finish the two tasks quickly. It supports menu configuration for selecting WAMR components and builds the WAMR to a SDK package that includes **runtime SDK** and **APP SDK**. The runtime SDK is used for building the native application and the APP SDK should be shipped to WASM application developers. - - -**Note**: [WASI-SDK](https://github.com/WebAssembly/wasi-sdk/releases) version 7 and above should be installed before building the WAMR SDK. - - - -### SDK profile and configuration file - -A SDK profile presents a configuration of build parameters for the selection of CPU architecture, software platforms, execution mode, libc and application framework components. The profile configurations are saved in a cmake file that will be included by the WAMR SDK building tool `build_sdk.sh`. - -Here is the default configuration file [wamr-sdk/wamr_config_default.cmake](./wamr_config_default.cmake): - -``` -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET X86_64) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE) -``` - - - -Execute following command to build the WAMR SDK for a configuration profile: - -``` -cd wamr-sdk -./build_sdk.sh -n [profile name] -x [config file path] -``` - -The output directory structure of a SDK package with profile name "simple": - -``` -simple/ -├── app-sdk -│   ├── libc-builtin-sysroot -│   │   ├── include -│   │   └── share -│   └── wamr-app-framework -│   ├── include -│   │   ├── bi-inc -│   │   └── wa-inc -│   ├── lib -│   └── share -└── runtime-sdk - ├── include - │   └── bi-inc - └── lib -``` - - - -Like the WAMR samples, a project probably has its own pre-defined SDK configuration file. The project building script can call the `build_sdk.sh` by passing the configuration file name to the build_sdk.sh to generate its own WAMR SDK package. - - - -### Menu configuration for building SDK - -Menu configuration is supported for easy integration of runtime components and application libraries for the target architecture and platform. Run following command to start the menu config. - -``` -cd wamr-sdk -./build_sdk.sh -i -n [profile name] -``` - - The argument "-i" will make the command enter menu config mode as depicted below. - -wamr build menu configuration - -After the menu configuration is finished, the profile config file is saved and the building process is automatically started. When the building gets successful, the SDK package is generated under folder $wamr-sdk/out/{profile}, and the header files of configured components were copied into the SDK package. - - - -### Build WASM applications with APP-SDK - -The folder “**app-sdk**” under the profile output directory contains all the header files and WASM library for developing the WASM application. For C/C++ based WASM applications, the developers can use conventional cross-compilation procedure to build the WASM application. According to the profile selection of libc, following cmake toolchain files under folder [wamr-sdk/app](./app) are available for cross compiling WASM application: - -- ` wamr_toolchain.cmake` -- `wasi_toolchain.cmake` - - - -Refer to [build WASM applications](../doc/build_wasm_app.md) for the details. - - - -### Use Runtime SDK to build native application - -The output folder "**runtime-sdk**" contains all the header files and library files for integration with project native code. - -You can link the pre-built library: -``` cmake -link_directories(${SDK_DIR}/runtime-sdk/lib) -include_directories(${SDK_DIR}/runtime-sdk/include) -# ...... -target_link_libraries (your_target vmlib -lm -ldl -lpthread) -``` - -This method can also be used when you don't use cmake - -You can refer to this sample: [CMakeLists.txt](../samples/simple/CMakeLists.txt). - -> NOTE: If you are familiar with how to configure WAMR by cmake and don't want to build the SDK, you can set the related settings on the top of your `CMakeLists.txt`, then the `runtime_lib.cmake` will not load settings from the SDK. - - - -### Integrate WAMR without pre-built WAMR library - -Use the provided `runtime_lib.cmake` file: - -You can include `${WAMR_ROOT}/cmake/runtime_lib.cmake` in your project's `CMakeLists.txt` file: - -``` cmake -include (${WAMR_ROOT}/cmake/runtime_lib.cmake) -add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE}) -# ...... -target_link_libraries (your_target vmlib -lm -ldl -lpthread) -``` - -You can refer to to product-mini building for Linux: [`product-mini/platforms/linux/CMakeLists.txt`](../product-mini/platforms/linux/CMakeLists.txt). - -> +# Notice +`wamr-sdk` has been migrated to **[wamr-app-framework/wamr-sdk](https://github.com/bytecodealliance/wamr-app-framework/tree/main/wamr-sdk)**. +Only some necessary files that wasm app will use are retained here diff --git a/wamr-sdk/app/CMakeLists.txt b/wamr-sdk/app/CMakeLists.txt deleted file mode 100644 index 2e115cf4c..000000000 --- a/wamr-sdk/app/CMakeLists.txt +++ /dev/null @@ -1,98 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required(VERSION 2.8) -project(app-framework) - -SET (CMAKE_C_FLAGS "-O3") - -if (NOT DEFINED WAMR_BUILD_SDK_PROFILE) - set (WAMR_BUILD_SDK_PROFILE "default") -endif () - -if (NOT DEFINED CONFIG_PATH) - set (CONFIG_PATH ${CMAKE_CURRENT_LIST_DIR}/../wamr_config_default.cmake) - message(STATUS "CONFIG_PATH set to ${CONFIG_PATH} ") -endif () - -if (NOT EXISTS "${CONFIG_PATH}") - message (FATAL_ERROR "${CONFIG_PATH} not exist") -endif () - -include(${CONFIG_PATH}) - -if (NOT DEFINED OUT_DIR) - set (OUT_DIR "${CMAKE_CURRENT_LIST_DIR}/../out/${WAMR_BUILD_SDK_PROFILE}") -endif () -set (APP_SDK_DIR "${OUT_DIR}/app-sdk") - -if (DEFINED EXTRA_SDK_INCLUDE_PATH) - message(STATUS, "EXTRA_SDK_INCLUDE_PATH = ${EXTRA_SDK_INCLUDE_PATH} ") - include_directories ( - ${EXTRA_SDK_INCLUDE_PATH} - ) -endif () - -if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1) - set (SYSROOT_DIR "${APP_SDK_DIR}/libc-builtin-sysroot") - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${SYSROOT_DIR}/include) - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${SYSROOT_DIR}/share) - execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/libc-builtin-sysroot/share/defined-symbols.txt ${SYSROOT_DIR}/share) - execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/wamr_toolchain.cmake ${APP_SDK_DIR}) - execute_process( - COMMAND ${CMAKE_COMMAND} - -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/libc-builtin-sysroot/include ${SYSROOT_DIR}/include - ) -else() - if (WAMR_BUILD_LIBC_WASI EQUAL 1) - set (SYSROOT_DIR "${APP_SDK_DIR}/wasi-sysroot") - message("sysroot: ${SYSROOT_DIR}") - execute_process(COMMAND ln -s ${WASI_SDK_DIR}/share/wasi-sysroot ${SYSROOT_DIR}) - execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/wasi_toolchain.cmake ${APP_SDK_DIR}/wamr_toolchain.cmake) - endif () -endif() - -if (WAMR_BUILD_APP_FRAMEWORK EQUAL 1) - message(WAMR_BUILD_APP_FRAMEWORK) - set (APP_FRAMEWORK_INCLUDE_TYPE "APP") - set (WAMR_APP_OUT_DIR "${APP_SDK_DIR}/wamr-app-framework") - - include(${CMAKE_CURRENT_LIST_DIR}/../../core/app-framework/app_framework.cmake) - - add_library(app_framework - ${WASM_APP_SOURCE_ALL} - ) - - add_custom_command( - TARGET app_framework POST_BUILD - - COMMAND ${CMAKE_COMMAND} -E make_directory ${WAMR_APP_OUT_DIR}/lib - COMMAND ${CMAKE_COMMAND} -E make_directory ${WAMR_APP_OUT_DIR}/include/wa-inc - COMMAND ${CMAKE_COMMAND} -E make_directory ${WAMR_APP_OUT_DIR}/share - COMMAND ${CMAKE_COMMAND} -E copy_directory ${WASM_APP_BI_INC_DIR} ${WAMR_APP_OUT_DIR}/include/bi-inc - COMMAND ${CMAKE_COMMAND} -E copy ${WASM_APP_BASE_DIR}/bh_platform.h ${WAMR_APP_OUT_DIR}/include - COMMAND ${CMAKE_COMMAND} -E copy ${WASM_APP_BASE_DIR}/wasm_app.h ${WAMR_APP_OUT_DIR}/include - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/*.a ${WAMR_APP_OUT_DIR}/lib - - # bi-inc folder should also copy into runtime-sdk - COMMAND ${CMAKE_COMMAND} -E make_directory ${OUT_DIR}/runtime-sdk/include - COMMAND ${CMAKE_COMMAND} -E copy_directory ${WASM_APP_BI_INC_DIR} ${OUT_DIR}/runtime-sdk/include/bi-inc - ) - - # If app-framework is enabled, add the undefined-symbol list to the toolchain file - if (WAMR_BUILD_LIBC_WASI EQUAL 1) - file (APPEND - ${APP_SDK_DIR}/wamr_toolchain.cmake - "SET (CMAKE_EXE_LINKER_FLAGS \"\${CMAKE_EXE_LINKER_FLAGS},--allow-undefined-file=\${CMAKE_CURRENT_LIST_DIR}/wamr-app-framework/share/defined-symbols.txt\" CACHE INTERNAL \"\")" - ) - endif () - - FOREACH (dir IN LISTS WASM_APP_WA_INC_DIR_LIST) - file (COPY ${dir} DESTINATION ${WAMR_APP_OUT_DIR}/include/) - ENDFOREACH (dir) - - if (DEFINED EXTRA_SDK_INCLUDE_PATH) - execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${EXTRA_SDK_INCLUDE_PATH} ${WAMR_APP_OUT_DIR}/include) - endif () - -endif() diff --git a/wamr-sdk/build_sdk.sh b/wamr-sdk/build_sdk.sh deleted file mode 100755 index 954584f69..000000000 --- a/wamr-sdk/build_sdk.sh +++ /dev/null @@ -1,254 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -sdk_root=$(cd "$(dirname "$0")/" && pwd) -wamr_root_dir=${sdk_root}/.. -out_dir=${sdk_root}/out -profile_path=${out_dir}/profile.cmake -wamr_config_cmake_file="" -wasi_sdk_home="/opt/wasi-sdk" -# libc support, default builtin-libc -LIBC_SUPPORT="BUILTIN" -CM_DEXTRA_SDK_INCLUDE_PATH="" -CM_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Release" -CM_TOOLCHAIN="" - -# menuconfig will pass options to this script -MENUCONFIG="" - -usage () -{ - echo "build.sh [options]" - echo " -n [profile name]" - echo " -x [config file path name]" - echo " -t [cmake toolchain file]" - echo " -e [extra include path], files under this path will be copied into SDK package" - echo " -c, clean" - echo " -d, debug mode" - echo " -i, enter menu config settings" - echo " -w [wasi-sdk installation path] it will be '/opt/wasi-sdk' if not set" - exit 1 -} - - -while getopts "e:x:n:t:icdw:" opt -do - case $opt in - n) - PROFILE=$OPTARG - ;; - t) - CM_TOOLCHAIN="-DCMAKE_TOOLCHAIN_FILE=$OPTARG" - ;; - x) - wamr_config_cmake_file=$OPTARG - ;; - e) - CM_DEXTRA_SDK_INCLUDE_PATH="-DEXTRA_SDK_INCLUDE_PATH=${OPTARG}" - ;; - c) - CLEAN="TRUE" - ;; - d) - CM_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Debug" - ;; - i) - MENUCONFIG="TRUE" - ;; - w) - if [[ -n "${OPTARG}" ]]; then - wasi_sdk_home=$(realpath "${OPTARG}") - fi - ;; - ?) - echo "Unknown arg: $arg" - usage - exit 1 - ;; - esac -done - - -if [ ! -f "${wasi_sdk_home}/bin/clang" ]; then - echo "Can not find clang under \"${wasi_sdk_home}/bin\"." - exit 1 -else - echo "Found WASI_SDK HOME ${wasi_sdk_home}" -fi - - -echo "download dependent external repositories.." -${wamr_root_dir}/core/deps/download.sh -[ $? -eq 0 ] || exit $? - - - -if [ -z "$PROFILE" ]; then - PROFILE="default" - echo "PROFILE argument not set, using DEFAULT" - if [[ -z "$wamr_config_cmake_file" ]]; then - wamr_config_cmake_file=${sdk_root}/wamr_config_default.cmake - echo "use default config file: [$wamr_config_cmake_file]" - fi -fi - - -if [ ! -d "${out_dir}" ]; then - mkdir -p ${out_dir} -fi - -curr_profile_dir=${out_dir}/${PROFILE} -wamr_app_out_dir=${curr_profile_dir}/app-sdk/wamr-app-framework -sysroot_dir=${curr_profile_dir}/app-sdk/libc-builtin-sysroot - - -echo "CM_DEXTRA_SDK_INCLUDE_PATH=${CM_DEXTRA_SDK_INCLUDE_PATH}" - - -if [[ "$CLEAN" = "TRUE" ]]; then - rm -rf ${curr_profile_dir} -fi - - - -# cmake config file for wamr runtime: -# 1. use the users provided the config cmake file path. -# 2. if user set MENU CONFIG, enter menu config to generate -# menu_config.cmake in the profile output folder -# 3. If the menu_config.cmake is already in the profile folder, use it -# 4. Use the default config cmake file -# -if [[ -n "$wamr_config_cmake_file" ]]; then - if [[ ! -f $wamr_config_cmake_file ]]; then - echo "user given file not exist: ${wamr_config_cmake_file}" - exit 1 - fi - - echo "User config file: [${wamr_config_cmake_file}]" - -else - wamr_config_cmake_file=${out_dir}/wamr_config_${PROFILE}.cmake - # always rebuilt the sdk if user is not giving the config file - if [ -d ${curr_profile_dir} ]; then - rm -rf ${curr_profile_dir} - fi - - if [[ "$MENUCONFIG" = "TRUE" ]] || [[ ! -f $wamr_config_cmake_file ]]; then - echo "MENUCONFIG: [${wamr_config_cmake_file}]" - ./menuconfig.sh -x ${wamr_config_cmake_file} - [ $? -eq 0 ] || exit $? - else - echo "use existing config file: [$wamr_config_cmake_file]" - fi -fi - - -mkdir -p ${curr_profile_dir} -mkdir -p ${curr_profile_dir}/app-sdk -mkdir -p ${curr_profile_dir}/runtime-sdk - - -if [ "${BUILD_LLVM}" = "TRUE" ]; then - if [ ! -d "${wamr_root_dir}/core/deps/llvm" ]; then - echo -e "\n" - echo "###### build llvm (this will take a long time) #######" - echo "" - cd ${wamr_root_dir}/wamr-compiler - ./build_llvm.sh - fi -fi - -echo -e "\n\n" -echo "############## Start to build wasm app sdk ###############" - -# If wgl module is selected, check if the extra SDK include dir is passed by the args, prompt user to input if not. -app_all_selected=`cat ${wamr_config_cmake_file} | grep WAMR_APP_BUILD_ALL` -app_wgl_selected=`cat ${wamr_config_cmake_file} | grep WAMR_APP_BUILD_WGL` - -if [[ -n "${app_wgl_selected}" ]] || [[ -n "${app_all_selected}" ]]; then - if [ -z "${CM_DEXTRA_SDK_INCLUDE_PATH}" ]; then - echo -e "\033[31mWGL module require lvgl config files, please input the path to the lvgl SDK include path:\033[0m" - read -a extra_file_path - - if [[ -z "${extra_file_path}" ]] || [[ ! -d "${extra_file_path}" ]]; then - echo -e "\033[31mThe extra SDK path is empty\033[0m" - else - CM_DEXTRA_SDK_INCLUDE_PATH="-DEXTRA_SDK_INCLUDE_PATH=${extra_file_path}" - fi - fi - - cd ${wamr_root_dir}/core/app-framework/wgl/app - ./prepare_headers.sh -fi - -cd ${sdk_root}/app -rm -fr build && mkdir build -cd build - -out=`grep WAMR_BUILD_LIBC_WASI ${wamr_config_cmake_file} |grep 1` -if [ -n "$out" ]; then - LIBC_SUPPORT="WASI" -fi -if [ "${LIBC_SUPPORT}" = "WASI" ]; then - echo "using wasi toolchain" - cmake .. $CM_DEXTRA_SDK_INCLUDE_PATH \ - -DWAMR_BUILD_SDK_PROFILE=${PROFILE} \ - -DCONFIG_PATH=${wamr_config_cmake_file} \ - -DWASI_SDK_DIR="${wasi_sdk_home}" \ - -DCMAKE_TOOLCHAIN_FILE=../wasi_toolchain.cmake -else - echo "using builtin libc toolchain" - cmake .. $CM_DEXTRA_SDK_INCLUDE_PATH \ - -DWAMR_BUILD_SDK_PROFILE=${PROFILE} \ - -DCONFIG_PATH=${wamr_config_cmake_file} \ - -DWASI_SDK_DIR="${wasi_sdk_home}" \ - -DCMAKE_TOOLCHAIN_FILE=../wamr_toolchain.cmake -fi -[ $? -eq 0 ] || exit $? - -make -if (( $? == 0 )); then - echo -e "\033[32mSuccessfully built app-sdk under ${curr_profile_dir}/app-sdk\033[0m" -else - echo -e "\033[31mFailed to build app-sdk for wasm application\033[0m" - exit 1 -fi - -cd .. -rm -fr build -echo -e "\n\n" - - - -echo "############## Start to build runtime sdk ###############" -cd ${sdk_root}/runtime -rm -fr build-runtime-sdk && mkdir build-runtime-sdk -cd build-runtime-sdk -cmake .. $CM_DEXTRA_SDK_INCLUDE_PATH \ - -DWAMR_BUILD_SDK_PROFILE=${PROFILE} \ - -DCONFIG_PATH=${wamr_config_cmake_file} \ - $CM_TOOLCHAIN $CM_BUILD_TYPE -[ $? -eq 0 ] || exit $? -make - -if (( $? == 0 )); then - echo -e "\033[32mSuccessfully built runtime library under ${curr_profile_dir}/runtime-sdk/lib\033[0m" -else - echo -e "\033[31mFailed to build runtime sdk\033[0m" - exit 1 -fi - -APP=`grep WAMR_BUILD_APP_FRAMEWORK ${wamr_config_cmake_file} |grep 1` -if [ -n "$APP" ]; then - # Generate defined-symbol list for app-sdk - cd ${wamr_app_out_dir}/share - cat ${curr_profile_dir}/runtime-sdk/include/*.inl | egrep "^ *EXPORT_WASM_API *[(] *[a-zA-Z_][a-zA-Z0-9_]* *?[)]" | cut -d '(' -f2 | cut -d ')' -f1 > defined-symbols.txt -fi - - -cd .. -rm -fr build-runtime-sdk - -exit 0 diff --git a/wamr-sdk/menuconfig.sh b/wamr-sdk/menuconfig.sh deleted file mode 100755 index b2f6fa628..000000000 --- a/wamr-sdk/menuconfig.sh +++ /dev/null @@ -1,223 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - - -usage () -{ - echo "menuconfig.sh [options]" - echo " -x [config file path name]" - exit 1 -} - - -while getopts "x:" opt -do - case $opt in - x) - wamr_config_cmake_file=$OPTARG - ;; - ?) - echo "Unknown arg: $arg" - usage - exit 1 - ;; - esac -done - - -if [ -z $wamr_config_cmake_file ]; then - usage - exit -fi - - -function set_build_target () { - target=$1 - - if [[ "${target}" = "X86_64" ]]; then - echo -e "set (WAMR_BUILD_TARGET \"X86_64\")" >> ${wamr_config_cmake_file} - elif [[ "${target}" = "X86_32" ]]; then - echo -e "set (WAMR_BUILD_TARGET \"X86_32\")" >> ${wamr_config_cmake_file} - else - echo "unknown build target." - exit 1 - fi -} - -function set_build_platform () { - platform=$1 - - if [[ "${platform}" = "linux" ]]; then - echo -e "set (WAMR_BUILD_PLATFORM \"linux\")" >> ${wamr_config_cmake_file} - # TODO: add other platforms - else - echo "${platform} platform currently not supported" - exit 1 - fi -} - -# input: array of selected exec modes [aot jit interp] -function set_exec_mode () { - modes=($1) - - for mode in ${modes[@]} - do - if [[ "$mode" = "aot" ]]; then - echo "set (WAMR_BUILD_AOT 1)" >> ${wamr_config_cmake_file} - elif [[ "$mode" = "jit" ]]; then - echo "set (WAMR_BUILD_JIT 1)" >> ${wamr_config_cmake_file} - BUILD_LLVM="TRUE" - elif [[ "$mode" = "interp" ]]; then - echo "set (WAMR_BUILD_INTERP 1)" >> ${wamr_config_cmake_file} - else - echo "unknown execute mode." - exit 1 - fi - done -} - -function set_libc_support () { - libc=$1 - - if [ "$libc" = "WASI" ]; then - echo "set (WAMR_BUILD_LIBC_WASI 1)" >> ${wamr_config_cmake_file} - else - echo "set (WAMR_BUILD_LIBC_BUILTIN 1)" >> ${wamr_config_cmake_file} - fi -} - -function set_app_framework () { - app_support=$1 - - if [ "$app_support" = "TRUE" ]; then - echo "set (WAMR_BUILD_APP_FRAMEWORK 1)" >> ${wamr_config_cmake_file} - fi -} - -# input: array of selected app modules -function set_app_module () { - modules=($1) - - for module in ${modules[*]} - do - if [ "${module}" = "all" ]; then - cmake_app_list="WAMR_APP_BUILD_ALL" - break - fi - - cmake_app_list="${cmake_app_list} WAMR_APP_BUILD_${module^^}" - done - - # APP module list - if [ -n "${cmake_app_list}" ]; then - echo "set (WAMR_BUILD_APP_LIST ${cmake_app_list# })" >> ${wamr_config_cmake_file} - fi -} - - - - -sdk_root=$(cd "$(dirname "$0")/" && pwd) -wamr_root=${sdk_root}/.. - -if [ ! `command -v menuconfig` ]; then - echo "Can't find kconfiglib python lib on this computer" - echo "Downloading it through pip" - echo "If this fails, you can try `pip install kconfiglib` to install it manually" - echo "Or download the repo from https://github.com/ulfalizer/Kconfiglib" - - pip install kconfiglib -fi - -if [ -f ".wamr_modules" ]; then - rm -f .wamr_modules -fi - -# get all modules under core/app-framework -for module in `ls ${wamr_root}/core/app-framework -F | grep "/$" | grep -v "base" | grep -v "app-native-shared" | grep -v "template"` -do - module=${module%*/} - echo "config APP_BUILD_${module^^}" >> .wamr_modules - echo " bool \"enable ${module}\"" >> .wamr_modules -done - -menuconfig Kconfig -[ $? -eq 0 ] || exit $? - -if [ ! -e ".config" ]; then - exit 0 -fi - -# parse platform -platform=`cat .config | grep "^CONFIG_PLATFORM"` -platform=${platform%*=y} -platform=${platform,,} -platform=${platform#config_platform_} - -# parse target -target=`cat .config | grep "^CONFIG_TARGET"` -target=${target%*=y} -target=${target#CONFIG_TARGET_} - -# parse execution mode -modes=`cat .config | grep "^CONFIG_EXEC"` -mode_list="" -for mode in ${modes} -do - mode=${mode%*=y} - mode=${mode#CONFIG_EXEC_} - mode_list="${mode_list} ${mode,,}" -done -if [ -z "${mode_list}" ]; then - echo "execution mode are not selected" - exit 1 -fi - -# parse libc support -libc=`cat .config | grep "^CONFIG_LIBC"` -libc=${libc%*=y} -if [ "${libc}" = "CONFIG_LIBC_WASI" ]; then - libc_support="WASI" -else - libc_support="BUILTIN" -fi - -# parse application framework options -app_option=`cat .config | grep "^CONFIG_APP_FRAMEWORK"` -app_option=${app_option%*=y} -app_option=${app_option#CONFIG_APP_FRAMEWORK_} - -if [ "${app_option}" != "DISABLE" ]; then - app_enable="TRUE" - - # Default components - if [ "${app_option}" = "DEFAULT" ]; then - app_list="base connection sensor" - # All components - elif [ "${app_option}" = "ALL" ]; then - app_list="all" - # Customize - elif [ "${app_option}" = "CUSTOM" ]; then - app_option=`cat .config | grep "^CONFIG_APP_BUILD"` - app_list="base" - for app in ${app_option} - do - app=${app%*=y} - app=${app#CONFIG_APP_BUILD_} - app_list="${app_list} ${app,,}" - done - fi -fi - -if [[ -f $wamr_config_cmake_file ]]; then - rm $wamr_config_cmake_file -fi - -set_build_target ${target} -set_build_platform ${platform} -set_exec_mode "${mode_list[*]}" -set_libc_support ${libc_support} -set_app_module "${app_list[*]}" -set_app_framework ${app_enable} diff --git a/wamr-sdk/runtime/CMakeLists.txt b/wamr-sdk/runtime/CMakeLists.txt deleted file mode 100644 index e8e5c363d..000000000 --- a/wamr-sdk/runtime/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required(VERSION 2.8) -project(runtime-sdk) - -SET (CMAKE_C_FLAGS "-O3") -set (CMAKE_BUILD_TYPE Release) - -add_definitions(-DBH_MALLOC=wasm_runtime_malloc) -add_definitions(-DBH_FREE=wasm_runtime_free) - -if (NOT DEFINED WAMR_BUILD_SDK_PROFILE) - set (WAMR_BUILD_SDK_PROFILE "default") -endif () - -if (NOT DEFINED CONFIG_PATH) - set (CONFIG_PATH ${CMAKE_CURRENT_LIST_DIR}/../wamr_config_default.cmake) -endif () - -if (NOT EXISTS "${CONFIG_PATH}") - message (FATAL_ERROR "${CONFIG_PATH} not exist") -endif () - -include(${CONFIG_PATH}) - -if (NOT DEFINED OUT_DIR) - set (OUT_DIR "${CMAKE_CURRENT_LIST_DIR}/../out/${WAMR_BUILD_SDK_PROFILE}") -endif () -set (RUNTIME_SDK_DIR "${OUT_DIR}/runtime-sdk") - -include(${CMAKE_CURRENT_LIST_DIR}/../../build-scripts/runtime_lib.cmake) - -# build vmlib -add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) - -# copy vmlib.a to ${SDK_ROOT}/out/runtime-sdk/lib -add_custom_command( - TARGET vmlib POST_BUILD - - COMMAND ${CMAKE_COMMAND} -E make_directory ${RUNTIME_SDK_DIR}/lib - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/*.a ${RUNTIME_SDK_DIR}/lib -) - -# copy headers to ${SDK_ROOT}/out/runtime-sdk/include -FOREACH (header IN LISTS RUNTIME_LIB_HEADER_LIST) - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${RUNTIME_SDK_DIR}/include) - execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${header}" ${RUNTIME_SDK_DIR}/include) -ENDFOREACH (header) - - -if (DEFINED EXTRA_SDK_INCLUDE_PATH) - execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${EXTRA_SDK_INCLUDE_PATH} ${RUNTIME_SDK_DIR}/include) -endif () - -# config.h is not needed when building a runtime product with pre-built library -# erase the file to avoid compile error -file (WRITE ${RUNTIME_SDK_DIR}/include/config.h "") diff --git a/wamr-sdk/wamr_config_default.cmake b/wamr-sdk/wamr_config_default.cmake deleted file mode 100644 index 98cc6e9cf..000000000 --- a/wamr-sdk/wamr_config_default.cmake +++ /dev/null @@ -1,12 +0,0 @@ -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET X86_64) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_JIT 0) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE) - -# -# set (EXTRA_SDK_INCLUDE_PATH "") diff --git a/wamr-sdk/wamr_config_macos_release.cmake b/wamr-sdk/wamr_config_macos_release.cmake deleted file mode 100644 index cbcec2d6f..000000000 --- a/wamr-sdk/wamr_config_macos_release.cmake +++ /dev/null @@ -1,40 +0,0 @@ -set (WAMR_BUILD_PLATFORM "darwin") -set (WAMR_BUILD_TARGET X86_64) - -# Running mode -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_JIT 0) - -# Runtime SDK Features -set (WAMR_BUILD_CUSTOM_NAME_SECTION 0) -set (WAMR_BUILD_DEBUG_INTERP 0) -set (WAMR_BUILD_DEBUG_AOT 0) -set (WAMR_BUILD_DUMP_CALL_STACK 0) -set (WAMR_BUILD_LIBC_UVWASI 0) -set (WAMR_BUILD_LIBC_EMCC 0) -set (WAMR_BUILD_LIB_RATS 0) -set (WAMR_BUILD_LOAD_CUSTOM_SECTION 0) -set (WAMR_BUILD_MEMORY_PROFILING 0) -set (WAMR_BUILD_MINI_LOADER 0) -set (WAMR_BUILD_MULTI_MODULE 0) -set (WAMR_BUILD_PERF_PROFILING 0) -set (WAMR_BUILD_SPEC_TEST 0) -set (WAMR_BUILD_BULK_MEMORY 1) -set (WAMR_BUILD_LIB_PTHREAD 1) -set (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 1) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 1) -set (WAMR_BUILD_REF_TYPES 1) -set (WAMR_BUILD_SIMD 1) -set (WAMR_BUILD_SHARED_MEMORY 1) -set (WAMR_BUILD_TAIL_CALL 1) -set (WAMR_BUILD_THREAD_MGR 1) - -# APP SDK Features -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE) - -# -# set (EXTRA_SDK_INCLUDE_PATH "") - diff --git a/wamr-sdk/wamr_config_ubuntu_release.cmake b/wamr-sdk/wamr_config_ubuntu_release.cmake deleted file mode 100644 index 8919c4e41..000000000 --- a/wamr-sdk/wamr_config_ubuntu_release.cmake +++ /dev/null @@ -1,40 +0,0 @@ -set (WAMR_BUILD_PLATFORM "linux") -set (WAMR_BUILD_TARGET X86_64) - -# Running mode -set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_INTERP 1) -set (WAMR_BUILD_JIT 0) - -# Runtime SDK Features -set (WAMR_BUILD_CUSTOM_NAME_SECTION 0) -set (WAMR_BUILD_DEBUG_INTERP 0) -set (WAMR_BUILD_DEBUG_AOT 0) -set (WAMR_BUILD_DUMP_CALL_STACK 0) -set (WAMR_BUILD_LIBC_UVWASI 0) -set (WAMR_BUILD_LIBC_EMCC 0) -set (WAMR_BUILD_LIB_RATS 0) -set (WAMR_BUILD_LOAD_CUSTOM_SECTION 0) -set (WAMR_BUILD_MEMORY_PROFILING 0) -set (WAMR_BUILD_MINI_LOADER 0) -set (WAMR_BUILD_MULTI_MODULE 0) -set (WAMR_BUILD_PERF_PROFILING 0) -set (WAMR_BUILD_SPEC_TEST 0) -set (WAMR_BUILD_BULK_MEMORY 1) -set (WAMR_BUILD_LIB_PTHREAD 1) -set (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 1) -set (WAMR_BUILD_LIBC_BUILTIN 1) -set (WAMR_BUILD_LIBC_WASI 1) -set (WAMR_BUILD_REF_TYPES 1) -set (WAMR_BUILD_SIMD 1) -set (WAMR_BUILD_SHARED_MEMORY 1) -set (WAMR_BUILD_TAIL_CALL 1) -set (WAMR_BUILD_THREAD_MGR 1) - -# APP SDK Features -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE) - -# -# set (EXTRA_SDK_INCLUDE_PATH "") -