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
690
  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
  using proxy_wasm::WasmVmIntegration::error;
30
  void error(std::string_view message) override;
31
  void trace(std::string_view message) override;
32
};
33

            
34
// Exceptions for issues with the WebAssembly code.
35
class WasmException : public EnvoyException {
36
public:
37
  using EnvoyException::EnvoyException;
38
};
39

            
40
using WasmVmPtr = std::unique_ptr<proxy_wasm::WasmVm>;
41

            
42
// Create a new low-level Wasm VM using runtime of the given type (e.g.
43
// "envoy.wasm.runtime.wasmtime").
44
WasmVmPtr createWasmVm(absl::string_view runtime);
45

            
46
/**
47
 * @return true if the provided Wasm Engine is compiled with Envoy
48
 */
49
bool isWasmEngineAvailable(absl::string_view runtime);
50

            
51
/**
52
 * @return the name of the first available Wasm Engine compiled with Envoy
53
 */
54
absl::string_view getFirstAvailableWasmEngineName();
55

            
56
} // namespace Wasm
57
} // namespace Common
58
} // namespace Extensions
59
} // namespace Envoy