Skip to content

Commit acca269

Browse files
committed
Feat: Add additional virtual keywords to wasm base.
Signed-off-by: Rachel Green <[email protected]>
1 parent 74f8572 commit acca269

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

include/proxy-wasm/context.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,23 @@ class ContextBase : public RootInterface,
150150
const std::shared_ptr<PluginHandleBase> &plugin_handle); // Stream context.
151151
virtual ~ContextBase();
152152

153+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
154+
virtual WasmBase *wasm() const { return wasm_; }
155+
#else
153156
WasmBase *wasm() const { return wasm_; }
157+
#endif
154158
uint32_t id() const { return id_; }
155159
// The VM Context used for calling "malloc" has an id_ == 0.
156160
bool isVmContext() const { return id_ == 0; }
157161
// Root Contexts have the VM Context as a parent.
158162
bool isRootContext() const { return parent_context_id_ == 0; }
163+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
164+
virtual ContextBase *parent_context() const { return parent_context_; }
165+
virtual ContextBase *root_context() const {
166+
#else
159167
ContextBase *parent_context() const { return parent_context_; }
160168
ContextBase *root_context() const {
169+
#endif
161170
const ContextBase *previous = this;
162171
ContextBase *parent = parent_context_;
163172
while (parent != previous) {
@@ -170,7 +179,11 @@ class ContextBase : public RootInterface,
170179
std::string_view log_prefix() const {
171180
return isRootContext() ? root_log_prefix_ : plugin_->log_prefix();
172181
}
182+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
183+
virtual WasmVm *wasmVm() const;
184+
#else
173185
WasmVm *wasmVm() const;
186+
#endif
174187

175188
// Called before deleting the context.
176189
virtual void destroy();

include/proxy-wasm/wasm.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,34 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
5454
WasmBase(const std::shared_ptr<WasmHandleBase> &base_wasm_handle, const WasmVmFactory &factory);
5555
virtual ~WasmBase();
5656

57+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
58+
virtual bool load(const std::string &code, bool allow_precompiled = false);
59+
virtual bool initialize();
60+
virtual void startVm(ContextBase *root_context);
61+
virtual bool configure(ContextBase *root_context, std::shared_ptr<PluginBase> plugin);
62+
#else
5763
bool load(const std::string &code, bool allow_precompiled = false);
5864
bool initialize();
5965
void startVm(ContextBase *root_context);
6066
bool configure(ContextBase *root_context, std::shared_ptr<PluginBase> plugin);
67+
#endif
6168
// Returns the root ContextBase or nullptr if onStart returns false.
69+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
70+
virtual ContextBase *start(const std::shared_ptr<PluginBase> &plugin);
71+
#else
6272
ContextBase *start(const std::shared_ptr<PluginBase> &plugin);
73+
#endif
6374

6475
std::string_view vm_id() const { return vm_id_; }
6576
std::string_view vm_key() const { return vm_key_; }
6677
WasmVm *wasm_vm() const { return wasm_vm_.get(); }
78+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
79+
virtual ContextBase *vm_context() const { return vm_context_.get(); }
80+
virtual ContextBase *getRootContext(const std::shared_ptr<PluginBase> &plugin, bool allow_closed);
81+
#else
6782
ContextBase *vm_context() const { return vm_context_.get(); }
6883
ContextBase *getRootContext(const std::shared_ptr<PluginBase> &plugin, bool allow_closed);
84+
#endif
6985
ContextBase *getContext(uint32_t id) {
7086
auto it = contexts_.find(id);
7187
if (it != contexts_.end())
@@ -321,14 +337,23 @@ using WasmHandleCloneFactory =
321337
class WasmHandleBase : public std::enable_shared_from_this<WasmHandleBase> {
322338
public:
323339
explicit WasmHandleBase(std::shared_ptr<WasmBase> wasm_base) : wasm_base_(wasm_base) {}
340+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
341+
virtual ~WasmHandleBase() {
342+
#else
324343
~WasmHandleBase() {
344+
#endif
325345
if (wasm_base_) {
326346
wasm_base_->startShutdown();
327347
}
328348
}
329349

350+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
351+
virtual bool canary(const std::shared_ptr<PluginBase> &plugin,
352+
const WasmHandleCloneFactory &clone_factory);
353+
#else
330354
bool canary(const std::shared_ptr<PluginBase> &plugin,
331355
const WasmHandleCloneFactory &clone_factory);
356+
#endif
332357

333358
void kill() { wasm_base_ = nullptr; }
334359

@@ -356,7 +381,11 @@ class PluginHandleBase : public std::enable_shared_from_this<PluginHandleBase> {
356381
explicit PluginHandleBase(std::shared_ptr<WasmHandleBase> wasm_handle,
357382
std::shared_ptr<PluginBase> plugin)
358383
: plugin_(plugin), wasm_handle_(wasm_handle) {}
384+
#ifdef PROXY_WASM_CPP_HOST_MORE_VIRTUAL_METHODS
385+
virtual ~PluginHandleBase() {
386+
#else
359387
~PluginHandleBase() {
388+
#endif
360389
if (wasm_handle_) {
361390
wasm_handle_->wasm()->startShutdown(plugin_->key());
362391
}

0 commit comments

Comments
 (0)