Skip to content

Commit b524f41

Browse files
authored
Pass PluginHandle to stream contexts. (proxy-wasm#167)
Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent d65908e commit b524f41

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

include/proxy-wasm/context.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace proxy_wasm {
3232
#include "proxy_wasm_common.h"
3333
#include "proxy_wasm_enums.h"
3434

35+
class PluginHandleBase;
3536
class WasmBase;
3637
class WasmVm;
3738

@@ -143,7 +144,7 @@ class ContextBase : public RootInterface,
143144
ContextBase(WasmBase *wasm); // Vm Context.
144145
ContextBase(WasmBase *wasm, std::shared_ptr<PluginBase> plugin); // Root Context.
145146
ContextBase(WasmBase *wasm, uint32_t parent_context_id,
146-
std::shared_ptr<PluginBase> plugin); // Stream context.
147+
std::shared_ptr<PluginHandleBase> plugin_handle); // Stream context.
147148
virtual ~ContextBase();
148149

149150
WasmBase *wasm() const { return wasm_; }
@@ -394,12 +395,13 @@ class ContextBase : public RootInterface,
394395

395396
WasmBase *wasm_{nullptr};
396397
uint32_t id_{0};
397-
uint32_t parent_context_id_{0}; // 0 for roots and the general context.
398-
ContextBase *parent_context_{nullptr}; // set in all contexts.
399-
std::string root_id_; // set only in root context.
400-
std::string root_log_prefix_; // set only in root context.
401-
std::shared_ptr<PluginBase> plugin_; // set in root and stream contexts.
402-
std::shared_ptr<PluginBase> temp_plugin_; // Remove once ABI v0.1.0 is gone.
398+
uint32_t parent_context_id_{0}; // 0 for roots and the general context.
399+
ContextBase *parent_context_{nullptr}; // set in all contexts.
400+
std::string root_id_; // set only in root context.
401+
std::string root_log_prefix_; // set only in root context.
402+
std::shared_ptr<PluginBase> plugin_; // set in root and stream contexts.
403+
std::shared_ptr<PluginHandleBase> plugin_handle_; // set only in stream context.
404+
std::shared_ptr<PluginBase> temp_plugin_; // Remove once ABI v0.1.0 is gone.
403405
bool in_vm_context_created_ = false;
404406
bool destroyed_ = false;
405407
bool stream_failed_ = false; // Set true after failStream is called in case of VM failure.

include/proxy-wasm/wasm.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,19 @@ class PluginHandleBase : public std::enable_shared_from_this<PluginHandleBase> {
321321
public:
322322
explicit PluginHandleBase(std::shared_ptr<WasmHandleBase> wasm_handle,
323323
std::shared_ptr<PluginBase> plugin)
324-
: wasm_handle_(wasm_handle), plugin_key_(plugin->key()) {}
325-
~PluginHandleBase() { wasm_handle_->wasm()->startShutdown(plugin_key_); }
324+
: plugin_(plugin), wasm_handle_(wasm_handle) {}
325+
~PluginHandleBase() {
326+
if (wasm_handle_) {
327+
wasm_handle_->wasm()->startShutdown(plugin_->key());
328+
}
329+
}
326330

331+
std::shared_ptr<PluginBase> &plugin() { return plugin_; }
327332
std::shared_ptr<WasmBase> &wasm() { return wasm_handle_->wasm(); }
328333

329334
protected:
335+
std::shared_ptr<PluginBase> plugin_;
330336
std::shared_ptr<WasmHandleBase> wasm_handle_;
331-
std::string plugin_key_;
332337
};
333338

334339
using PluginHandleFactory = std::function<std::shared_ptr<PluginHandleBase>(

src/context.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ ContextBase::ContextBase(WasmBase *wasm, std::shared_ptr<PluginBase> plugin)
9898

9999
// NB: wasm can be nullptr if it failed to be created successfully.
100100
ContextBase::ContextBase(WasmBase *wasm, uint32_t parent_context_id,
101-
std::shared_ptr<PluginBase> plugin)
101+
std::shared_ptr<PluginHandleBase> plugin_handle)
102102
: wasm_(wasm), id_(wasm ? wasm->allocContextId() : 0), parent_context_id_(parent_context_id),
103-
plugin_(plugin) {
103+
plugin_(plugin_handle->plugin()), plugin_handle_(plugin_handle) {
104104
if (wasm_) {
105105
wasm_->contexts_[id_] = this;
106106
parent_context_ = wasm_->contexts_[parent_context_id_];

0 commit comments

Comments
 (0)