Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : 5 : #include "envoy/common/exception.h" 6 : #include "envoy/stats/scope.h" 7 : #include "envoy/stats/stats.h" 8 : 9 : #include "source/common/common/logger.h" 10 : 11 : #include "absl/strings/str_cat.h" 12 : #include "include/proxy-wasm/wasm_vm.h" 13 : #include "include/proxy-wasm/word.h" 14 : 15 : namespace Envoy { 16 : namespace Extensions { 17 : namespace Common { 18 : namespace Wasm { 19 : 20 : // providing logger and NullVm function getter to Wasm VM. 21 : class EnvoyWasmVmIntegration : public proxy_wasm::WasmVmIntegration, 22 : Logger::Loggable<Logger::Id::wasm> { 23 : public: 24 : // proxy_wasm::WasmVmIntegration 25 0 : proxy_wasm::WasmVmIntegration* clone() override { return new EnvoyWasmVmIntegration(); } 26 : bool getNullVmFunction(std::string_view function_name, bool returns_word, int number_of_arguments, 27 : proxy_wasm::NullPlugin* plugin, void* ptr_to_function_return) override; 28 : proxy_wasm::LogLevel getLogLevel() override; 29 : void error(std::string_view message) override; 30 : void trace(std::string_view message) override; 31 : }; 32 : 33 : // Exceptions for issues with the WebAssembly code. 34 : class WasmException : public EnvoyException { 35 : public: 36 : using EnvoyException::EnvoyException; 37 : }; 38 : 39 : using WasmVmPtr = std::unique_ptr<proxy_wasm::WasmVm>; 40 : 41 : // Create a new low-level Wasm VM using runtime of the given type (e.g. "envoy.wasm.runtime.wavm"). 42 : WasmVmPtr createWasmVm(absl::string_view runtime); 43 : 44 : /** 45 : * @return true if the provided Wasm Engine is compiled with Envoy 46 : */ 47 : bool isWasmEngineAvailable(absl::string_view runtime); 48 : 49 : /** 50 : * @return the name of the first available Wasm Engine compiled with Envoy 51 : */ 52 : absl::string_view getFirstAvailableWasmEngineName(); 53 : 54 : } // namespace Wasm 55 : } // namespace Common 56 : } // namespace Extensions 57 : } // namespace Envoy