Change rmi from klay to internal
authorSangwan Kwon <sangwan.kwon@samsung.com>
Thu, 28 Nov 2019 07:32:54 +0000 (16:32 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Mon, 2 Dec 2019 06:36:38 +0000 (15:36 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
src/vist/archive.hpp
src/vist/client/CMakeLists.txt
src/vist/client/query.cpp
src/vist/klass/functor.hpp
src/vist/rmi/server.hpp
src/vist/service/vist.cpp
src/vist/service/vist.hpp

index f1f9d18344d008882f340eec427ae4decaf7450c..f2bd3dc63c57a4723e1b6fcb15e01bd1cad83d57 100644 (file)
 
 #include <vist/index-sequence.hpp>
 
+#include <map>
+#include <memory>
 #include <string>
+#include <tuple>
 #include <type_traits>
 #include <vector>
-#include <memory>
-#include <tuple>
 
 namespace vist {
 
@@ -59,6 +60,10 @@ public:
        template<typename T, IsArchival<T> = 0>
        Archive& operator<<(const T& object);
        template<typename T>
+       Archive& operator<<(const std::vector<T>& values);
+       template<typename K, typename V>
+       Archive& operator<<(const std::map<K, V>& map);
+       template<typename T>
        Archive& operator<<(const std::unique_ptr<T>& pointer);
        template<typename T>
        Archive& operator<<(const std::shared_ptr<T>& pointer);
@@ -71,6 +76,10 @@ public:
        template<typename T, IsArchival<T> = 0>
        Archive& operator>>(T& object);
        template<typename T>
+       Archive& operator>>(std::vector<T>& values);
+       template<typename K, typename V>
+       Archive& operator>>(std::map<K, V>& map);
+       template<typename T>
        Archive& operator>>(std::unique_ptr<T>& pointer);
        template<typename T>
        Archive& operator>>(std::shared_ptr<T>& pointer);
@@ -143,6 +152,28 @@ Archive& Archive::operator<<(const T& value)
        return *this;
 }
 
+template<typename T>
+Archive& Archive::operator<<(const std::vector<T>& values)
+{
+       *this << values.size();
+       for (const T& value : values)
+               *this << value;
+
+       return *this;
+}
+
+template<typename K, typename V>
+Archive& Archive::operator<<(const std::map<K, V>& map)
+{
+       *this << map.size();
+       for (const auto& pair : map) {
+               *this << pair.first;
+               *this << pair.second;
+       }
+
+       return *this;
+}
+
 template<typename T>
 Archive& Archive::operator<<(const std::unique_ptr<T>& pointer)
 {
@@ -171,6 +202,38 @@ Archive& Archive::operator>>(T& value)
        return *this;
 }
 
+template<typename T>
+Archive& Archive::operator>>(std::vector<T>& values)
+{
+       std::size_t size;
+       *this >> size;
+       values.resize(size);
+
+       for (T& value : values)
+               *this >> value;
+
+       return *this;
+}
+
+template<typename K, typename V>
+Archive& Archive::operator>>(std::map<K, V>& map)
+{
+       std::size_t size;
+       *this >> size;
+
+       while (size--) {
+               K key;
+               V value;
+
+               *this >> key;
+               *this >> value;
+
+               map[key] = value;
+       }
+
+       return *this;
+}
+
 template<typename T>
 Archive& Archive::operator>>(std::unique_ptr<T>& pointer)
 {
index cb38c21dbed6a12a84eb186e451fe5c2e9f894e0..279cf0da4107b6497122eab2362e3ff96ab7350a 100644 (file)
@@ -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)
index 5a8c6c3c55424903fe30049a866b02c8bde958ba..dac1ab137825e588ec3992561bcda575dba68b2e 100644 (file)
@@ -17,7 +17,7 @@
 #include "query.hpp"
 
 #include <vist/logger.hpp>
-#include <vist/ipc/client.hpp>
+#include <vist/rmi/client.hpp>
 
 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<Rows>("Vist::query", statement);
+       return client.invoke<Rows>("Vist::query", statement);
 }
 
 } // namespace vist
index 7a178ad98a862b8d8b0983e677fe0061d0343f17..c9872fc4bd6883a6cfcda76f2903c20e4d08a159 100644 (file)
@@ -144,6 +144,17 @@ Functor<R, K, Ps...> make_functor(std::shared_ptr<K> instance, R (K::* member)(P
        return Functor<R, K, Ps...>(instance, make_function(member));
 }
 
+template<typename R, typename K, typename... Ps>
+std::shared_ptr<Functor<R, K, Ps...>> make_functor_ptr(K* instance,
+                                                                                                          R (K::* member)(Ps...))
+{
+       if (instance == nullptr)
+               throw std::invalid_argument("Instance can't be nullptr.");
+
+       std::shared_ptr<K> smartPtr(instance);
+       return std::make_shared<Functor<R, K, Ps...>>(smartPtr, make_function(member));
+}
+
 template<typename R, typename K, typename... Ps>
 std::shared_ptr<Functor<R, K, Ps...>> make_functor_ptr(std::shared_ptr<K> instance,
                                                                                                           R (K::* member)(Ps...))
index d18fa923992b2c488fcbaf63acf3d53c3f70660b..46afa847145e9c0644145f073f340506b70a91c3 100644 (file)
@@ -81,7 +81,7 @@ private:
 template<typename O, typename F>
 void Server::expose(O&& object, const std::string& name, F&& func)
 {
-       auto functor = make_functor_ptr(std::forward<O>(object), std::forward<F>(func));
+       auto functor = klass::make_functor_ptr(std::forward<O>(object), std::forward<F>(func));
        this->functorMap[name] = functor;
 }
 
index 860e227f84f7883f9f96c2c28d1ee480c56e38ac..c63c65cdd8b05862eab894fb88e088fed00300b9 100644 (file)
 
 #include "vist.hpp"
 
-#include <vist/ipc/server.hpp>
+#include <vist/rmi/server.hpp>
 #include <vist/logger.hpp>
 #include <vist/exception.hpp>
 
 #include <osquery/registry_interface.h>
 #include <osquery/sql.h>
 
-#define QUERY_RET_TYPE std::vector<std::map<std::string, std::string>>
-
 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)
index 03cf9e93d2867be1fdfba131349a3493b8ddd4ad..ab8b8dfd98859da816a2b14c5dc5ea045d2ccb0d 100644 (file)
@@ -27,6 +27,8 @@ using Rows = std::vector<Row>;
 
 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