Line data Source code
1 : /** 2 : Copyright (c) 2024 Stappler LLC <admin@stappler.dev> 3 : 4 : Permission is hereby granted, free of charge, to any person obtaining a copy 5 : of this software and associated documentation files (the "Software"), to deal 6 : in the Software without restriction, including without limitation the rights 7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 : copies of the Software, and to permit persons to whom the Software is 9 : furnished to do so, subject to the following conditions: 10 : 11 : The above copyright notice and this permission notice shall be included in 12 : all copies or substantial portions of the Software. 13 : 14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 : THE SOFTWARE. 21 : **/ 22 : 23 : #include "SPWebWasmComponent.h" 24 : 25 : namespace STAPPLER_VERSIONIZED stappler::web { 26 : 27 0 : static uint32_t stappler_wasm_webserver_constructor_host_component(wasm_exec_env_t exec_env, uint32_t hostHandle, uint32_t infoHandle, 28 : uint32_t onChildInit, uint32_t onStorageInit, uint32_t onHeartbeat, uint32_t userdata) { 29 0 : auto env = wasm::ExecEnv::get(exec_env); 30 0 : auto inst = env->getInstance(); 31 0 : auto host = inst->getObject<Host>(hostHandle); 32 0 : if (!host) { 33 0 : log::error("wasm::Runtime", __FUNCTION__, ": invalid host handle"); 34 0 : return wasm::ModuleInstance::InvalidHandle; 35 : } 36 : 37 0 : auto info = inst->getObject<HostComponentInfo>(infoHandle); 38 0 : if (!host) { 39 0 : log::error("wasm::Runtime", __FUNCTION__, ": invalid host info handle"); 40 0 : return wasm::ModuleInstance::InvalidHandle; 41 : } 42 : 43 0 : auto c = new WasmComponent(*host, *info, env, WasmComponent::WasmData{onChildInit, onStorageInit, onHeartbeat, userdata}); 44 0 : return inst->addHandle(c); 45 : } 46 : 47 : static NativeSymbol stapper_wen_symbols[] = { 48 : NativeSymbol{"[constructor]host-component", (void *)&stappler_wasm_webserver_constructor_host_component, "(iiiiii)i", NULL}, 49 : }; 50 : 51 : static wasm::NativeModule s_wasmModule("stappler:wasm/webserver", stapper_wen_symbols, sizeof(stapper_wen_symbols) / sizeof(NativeSymbol)); 52 : 53 : }