Skip to content

Commit

Permalink
#973: implement default proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Strzebonski committed Nov 29, 2020
1 parent 65408f6 commit f857f13
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions examples/callback/callback_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,38 @@ static void handler(CallbackMsg* msg) {
// Some instance of the context
static MyContext my_global_ctx = {};

namespace {

struct DefaultProxyElem {
explicit DefaultProxyElem(vt::NodeType in_node) : node_(in_node) {}

template <typename MsgT, vt::ActiveTypedFnType<MsgT>* fn, typename... Args>
void send(Args&&... args) const {
vt::theMsg()->sendMsg<MsgT, fn>(
node_, vt::makeMessage<MsgT>(std::forward<Args>(args)...)
);
}

private:
vt::NodeType node_;
};

struct DefaultProxy {
DefaultProxyElem operator[](vt::NodeType node) const {
return DefaultProxyElem{node};
}

static const DefaultProxy& get() {
static DefaultProxy const default_proxy;
return default_proxy;
}

private:
DefaultProxy() = default;
};

}

int main(int argc, char** argv) {
vt::initialize(argc, argv);

Expand All @@ -108,8 +140,9 @@ int main(int argc, char** argv) {
auto cb = vt::theCB()->makeFunc<DataMsg,MyContext>(
vt::pipe::LifetimeEnum::Once, &my_global_ctx, callbackFn
);
auto msg = vt::makeMessage<CallbackMsg>(cb);
vt::theMsg()->sendMsg<CallbackMsg,handler>(1, msg);

auto const& default_proxy = DefaultProxy::get();
default_proxy[1].send<CallbackMsg, handler>(cb);
}

vt::finalize();
Expand Down

0 comments on commit f857f13

Please sign in to comment.