Skip to content
31 changes: 15 additions & 16 deletions include/proxy-wasm/wasm_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,25 @@ enum class AbiVersion { ProxyWasm_0_1_0, ProxyWasm_0_2_0, ProxyWasm_0_2_1, Unkno

class NullPlugin;

enum class FailState : int {
Ok = 0,
UnableToCreateVm = 1,
UnableToCloneVm = 2,
MissingFunction = 3,
UnableToInitializeCode = 4,
StartFailed = 5,
ConfigureFailed = 6,
RuntimeError = 7,
};

// Integrator specific WasmVm operations.
struct WasmVmIntegration {
virtual ~WasmVmIntegration() {}
virtual WasmVmIntegration *clone() = 0;
virtual proxy_wasm::LogLevel getLogLevel() = 0;
virtual void error(std::string_view message) = 0;
// Allow integrations to handle specific FailStates differently.
virtual void error(FailState fail_state, std::string_view message) { error(message); }
virtual void trace(std::string_view message) = 0;
// Get a NullVm implementation of a function.
// @param function_name is the name of the function with the implementation specific prefix.
Expand All @@ -165,17 +178,6 @@ struct WasmVmIntegration {
void *ptr_to_function_return) = 0;
};

enum class FailState : int {
Ok = 0,
UnableToCreateVm = 1,
UnableToCloneVm = 2,
MissingFunction = 3,
UnableToInitializeCode = 4,
StartFailed = 5,
ConfigureFailed = 6,
RuntimeError = 7,
};

// Wasm VM instance. Provides the low level WASM interface.
class WasmVm {
public:
Expand Down Expand Up @@ -308,14 +310,11 @@ class WasmVm {
*/
virtual bool usesWasmByteOrder() = 0;

/**
* Warm the VM such as engine and runtime.
*/
virtual void warm() = 0;
virtual void warm() {}

bool isFailed() { return failed_ != FailState::Ok; }
void fail(FailState fail_state, std::string_view message) {
integration()->error(message);
integration()->error(fail_state, message);
failed_ = fail_state;
for (auto &callback : fail_callbacks_) {
callback(fail_state);
Expand Down
Loading