From: Sangwan Kwon Date: Thu, 28 Nov 2019 07:32:54 +0000 (+0900) Subject: Change rmi from klay to internal X-Git-Tag: submit/tizen/20200810.073515~145 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e1819e26181ba9677d97d8ebb7f88f854f083640;p=platform%2Fcore%2Fsecurity%2Fvist.git Change rmi from klay to internal Signed-off-by: Sangwan Kwon --- diff --git a/src/vist/archive.hpp b/src/vist/archive.hpp index f1f9d18..f2bd3dc 100644 --- a/src/vist/archive.hpp +++ b/src/vist/archive.hpp @@ -24,11 +24,12 @@ #include +#include +#include #include +#include #include #include -#include -#include namespace vist { @@ -59,6 +60,10 @@ public: template = 0> Archive& operator<<(const T& object); template + Archive& operator<<(const std::vector& values); + template + Archive& operator<<(const std::map& map); + template Archive& operator<<(const std::unique_ptr& pointer); template Archive& operator<<(const std::shared_ptr& pointer); @@ -71,6 +76,10 @@ public: template = 0> Archive& operator>>(T& object); template + Archive& operator>>(std::vector& values); + template + Archive& operator>>(std::map& map); + template Archive& operator>>(std::unique_ptr& pointer); template Archive& operator>>(std::shared_ptr& pointer); @@ -143,6 +152,28 @@ Archive& Archive::operator<<(const T& value) return *this; } +template +Archive& Archive::operator<<(const std::vector& values) +{ + *this << values.size(); + for (const T& value : values) + *this << value; + + return *this; +} + +template +Archive& Archive::operator<<(const std::map& map) +{ + *this << map.size(); + for (const auto& pair : map) { + *this << pair.first; + *this << pair.second; + } + + return *this; +} + template Archive& Archive::operator<<(const std::unique_ptr& pointer) { @@ -171,6 +202,38 @@ Archive& Archive::operator>>(T& value) return *this; } +template +Archive& Archive::operator>>(std::vector& values) +{ + std::size_t size; + *this >> size; + values.resize(size); + + for (T& value : values) + *this >> value; + + return *this; +} + +template +Archive& Archive::operator>>(std::map& map) +{ + std::size_t size; + *this >> size; + + while (size--) { + K key; + V value; + + *this >> key; + *this >> value; + + map[key] = value; + } + + return *this; +} + template Archive& Archive::operator>>(std::unique_ptr& pointer) { diff --git a/src/vist/client/CMakeLists.txt b/src/vist/client/CMakeLists.txt index cb38c21..279cf0d 100644 --- a/src/vist/client/CMakeLists.txt +++ b/src/vist/client/CMakeLists.txt @@ -26,4 +26,5 @@ ADD_VIST_TEST(${CLIENT_TESTS}) ADD_LIBRARY(${TARGET_VIST_CLIENT_LIB} STATIC ${${TARGET_VIST_CLIENT_LIB}_SRCS}) TARGET_LINK_LIBRARIES(${TARGET_VIST_CLIENT_LIB} ${VIST_CLIENT_DEPS_LIBRARIES} + ${TARGET_VIST_COMMON_LIB} pthread) diff --git a/src/vist/client/query.cpp b/src/vist/client/query.cpp index 5a8c6c3..dac1ab1 100644 --- a/src/vist/client/query.cpp +++ b/src/vist/client/query.cpp @@ -17,7 +17,7 @@ #include "query.hpp" #include -#include +#include namespace { const std::string SOCK_ADDR = "/tmp/.vist"; @@ -28,9 +28,9 @@ namespace vist { Rows Query::Execute(const std::string& statement) { INFO(VIST_CLIENT) << "Query execution: " << statement; - auto& client = ipc::Client::Instance(SOCK_ADDR); + rmi::Client client(SOCK_ADDR); - return client->methodCall("Vist::query", statement); + return client.invoke("Vist::query", statement); } } // namespace vist diff --git a/src/vist/klass/functor.hpp b/src/vist/klass/functor.hpp index 7a178ad..c9872fc 100644 --- a/src/vist/klass/functor.hpp +++ b/src/vist/klass/functor.hpp @@ -144,6 +144,17 @@ Functor make_functor(std::shared_ptr instance, R (K::* member)(P return Functor(instance, make_function(member)); } +template +std::shared_ptr> make_functor_ptr(K* instance, + R (K::* member)(Ps...)) +{ + if (instance == nullptr) + throw std::invalid_argument("Instance can't be nullptr."); + + std::shared_ptr smartPtr(instance); + return std::make_shared>(smartPtr, make_function(member)); +} + template std::shared_ptr> make_functor_ptr(std::shared_ptr instance, R (K::* member)(Ps...)) diff --git a/src/vist/rmi/server.hpp b/src/vist/rmi/server.hpp index d18fa92..46afa84 100644 --- a/src/vist/rmi/server.hpp +++ b/src/vist/rmi/server.hpp @@ -81,7 +81,7 @@ private: template void Server::expose(O&& object, const std::string& name, F&& func) { - auto functor = make_functor_ptr(std::forward(object), std::forward(func)); + auto functor = klass::make_functor_ptr(std::forward(object), std::forward(func)); this->functorMap[name] = functor; } diff --git a/src/vist/service/vist.cpp b/src/vist/service/vist.cpp index 860e227..c63c65c 100644 --- a/src/vist/service/vist.cpp +++ b/src/vist/service/vist.cpp @@ -16,15 +16,13 @@ #include "vist.hpp" -#include +#include #include #include #include #include -#define QUERY_RET_TYPE std::vector> - namespace { const std::string SOCK_ADDR = "/tmp/.vist"; } // anonymous namespace @@ -39,10 +37,11 @@ Vist::Vist() void Vist::start() { INFO(VIST) << "Vist daemon starts."; - auto& server = ipc::Server::Instance(SOCK_ADDR); + rmi::Server server; + server.listen(SOCK_ADDR); - server->expose(this, "", (QUERY_RET_TYPE)(Vist::query)(std::string)); - server->start(); + server.expose(this, "Vist::query", &Vist::query); + server.start(); } Rows Vist::query(const std::string& statement) diff --git a/src/vist/service/vist.hpp b/src/vist/service/vist.hpp index 03cf9e9..ab8b8df 100644 --- a/src/vist/service/vist.hpp +++ b/src/vist/service/vist.hpp @@ -27,6 +27,8 @@ using Rows = std::vector; class Vist final { public: + ~Vist() = default; + Vist(const Vist&) = delete; Vist& operator=(const Vist&) = delete; @@ -51,7 +53,6 @@ public: private: explicit Vist(); - ~Vist() = default; }; } // namespace vist