From: Sangwan Kwon Date: Fri, 20 Dec 2019 06:56:28 +0000 (+0900) Subject: Add convenience macro to RMI X-Git-Tag: submit/tizen/20200810.073515~128 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=93a9e0114a73014aa1fd731a13196b42140c0b9b;p=platform%2Fcore%2Fsecurity%2Fvist.git Add convenience macro to RMI The purpose of these macros(EXPOSE, REMOTE_METHOD) is to allow users to use RMI only with member function type. - server side - EXPOSE(gateway, this, &Vist::query); - client side - auto query = REMOTE_METHOD(remote, &Vist::query); auto rows = query.invoke(statement); Signed-off-by: Sangwan Kwon --- diff --git a/src/vist/client/query.cpp b/src/vist/client/query.cpp index 6c8ebc6..5b1cbed 100644 --- a/src/vist/client/query.cpp +++ b/src/vist/client/query.cpp @@ -30,7 +30,8 @@ Rows Query::Execute(const std::string& statement) INFO(VIST_CLIENT) << "Query execution: " << statement; rmi::Remote remote(SOCK_ADDR); - return remote.invoke("Vist::query", statement); + auto query = REMOTE_METHOD(remote, &Vist::query); + return query.invoke(statement); } } // namespace vist diff --git a/src/vist/rmi/gateway.hpp b/src/vist/rmi/gateway.hpp index b8a347b..69a6676 100644 --- a/src/vist/rmi/gateway.hpp +++ b/src/vist/rmi/gateway.hpp @@ -22,6 +22,8 @@ #pragma once +#define EXPOSE(gateway, object, function) gateway.expose(object, #function, function) + #include #include diff --git a/src/vist/rmi/remote.hpp b/src/vist/rmi/remote.hpp index 9a1206a..4dd64f4 100644 --- a/src/vist/rmi/remote.hpp +++ b/src/vist/rmi/remote.hpp @@ -28,6 +28,8 @@ #include #include +#define REMOTE_METHOD(remote, method) vist::rmi::Remote::Method {remote, #method} + namespace vist { namespace rmi { @@ -47,6 +49,17 @@ public: template R invoke(const std::string& name, Args&&... args); + struct Method { + Remote& remote; + std::string name; + + template + R invoke(Args&&... args) + { + return remote.invoke(name, std::forward(args)...); + } + }; + private: Message request(Message& message); diff --git a/src/vist/rmi/tests/rmi.cpp b/src/vist/rmi/tests/rmi.cpp index 250bed5..da5beb5 100644 --- a/src/vist/rmi/tests/rmi.cpp +++ b/src/vist/rmi/tests/rmi.cpp @@ -66,8 +66,9 @@ TEST(RmiTests, positive) gateway.expose(foo, "Foo::setName", &Foo::setName); gateway.expose(foo, "Foo::getName", &Foo::getName); + // convenience macro auto bar = std::make_shared(); - gateway.expose(bar, "Bar::plusTwo", &Bar::plusTwo); + EXPOSE(gateway, bar, &Bar::plusTwo); auto client = std::thread([&]() { // caller-side @@ -80,7 +81,9 @@ TEST(RmiTests, positive) std::string name = remote.invoke("Foo::getName"); EXPECT_EQ(name, param); - int num = remote.invoke("Bar::plusTwo", 3); + // convenience macro + auto plusTwo = REMOTE_METHOD(remote, &Bar::plusTwo); + int num = plusTwo.invoke(3); EXPECT_EQ(num, 5); gateway.stop(); diff --git a/src/vist/service/vist.cpp b/src/vist/service/vist.cpp index 8978d04..be4b68c 100644 --- a/src/vist/service/vist.cpp +++ b/src/vist/service/vist.cpp @@ -39,7 +39,7 @@ void Vist::start() INFO(VIST) << "Vist daemon starts."; rmi::Gateway gateway(SOCK_ADDR); - gateway.expose(this, "Vist::query", &Vist::query); + EXPOSE(gateway, this, &Vist::query); gateway.start(); }