#include <vist/index-sequence.hpp>
+#include <map>
+#include <memory>
#include <string>
+#include <tuple>
#include <type_traits>
#include <vector>
-#include <memory>
-#include <tuple>
namespace vist {
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);
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);
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)
{
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)
{
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)
#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";
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
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...))
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;
}
#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
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)
class Vist final {
public:
+ ~Vist() = default;
+
Vist(const Vist&) = delete;
Vist& operator=(const Vist&) = delete;
private:
explicit Vist();
- ~Vist() = default;
};
} // namespace vist