From f857f1323f80db5237714a66c9042b77d8b8b333 Mon Sep 17 00:00:00 2001 From: Jakub Strzebonski Date: Sat, 14 Nov 2020 18:35:43 +0100 Subject: [PATCH] #973: implement default proxy --- examples/callback/callback_context.cc | 37 +++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/examples/callback/callback_context.cc b/examples/callback/callback_context.cc index e72915cf00..0153ef7e9b 100644 --- a/examples/callback/callback_context.cc +++ b/examples/callback/callback_context.cc @@ -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 * fn, typename... Args> + void send(Args&&... args) const { + vt::theMsg()->sendMsg( + node_, vt::makeMessage(std::forward(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); @@ -108,8 +140,9 @@ int main(int argc, char** argv) { auto cb = vt::theCB()->makeFunc( vt::pipe::LifetimeEnum::Once, &my_global_ctx, callbackFn ); - auto msg = vt::makeMessage(cb); - vt::theMsg()->sendMsg(1, msg); + + auto const& default_proxy = DefaultProxy::get(); + default_proxy[1].send(cb); } vt::finalize();