diff options
Diffstat (limited to 'fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples')
6 files changed, 197 insertions, 0 deletions
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_publisher.ts b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_publisher.ts new file mode 100644 index 00000000..3ca133fd --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_publisher.ts @@ -0,0 +1,36 @@ +/* + * 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/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_subscriber.ts b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_subscriber.ts new file mode 100644 index 00000000..c9aa52a8 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_subscriber.ts @@ -0,0 +1,36 @@ +/* + * 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/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_handler.ts b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_handler.ts new file mode 100644 index 00000000..ef9f58c5 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_handler.ts @@ -0,0 +1,40 @@ +/* + * 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/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_sender.ts b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_sender.ts new file mode 100644 index 00000000..5648985e --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_sender.ts @@ -0,0 +1,43 @@ +/* + * 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/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/timer.ts b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/timer.ts new file mode 100644 index 00000000..2e3f69d2 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/timer.ts @@ -0,0 +1,36 @@ +/* + * 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/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/tsconfig.json b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/tsconfig.json new file mode 100644 index 00000000..c614e5c8 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../node_modules/assemblyscript/std/assembly.json", + "include": [ + "./**/*.ts" + ] +}
\ No newline at end of file |