INFO(VIST_CLIENT) << "Query execution: " << statement;
rmi::Remote remote(SOCK_ADDR);
- return remote.invoke<Rows>("Vist::query", statement);
+ auto query = REMOTE_METHOD(remote, &Vist::query);
+ return query.invoke<Rows>(statement);
}
} // namespace vist
#pragma once
+#define EXPOSE(gateway, object, function) gateway.expose(object, #function, function)
+
#include <vist/klass/functor.hpp>
#include <memory>
#include <string>
#include <memory>
+#define REMOTE_METHOD(remote, method) vist::rmi::Remote::Method {remote, #method}
+
namespace vist {
namespace rmi {
template<typename R, typename... Args>
R invoke(const std::string& name, Args&&... args);
+ struct Method {
+ Remote& remote;
+ std::string name;
+
+ template<typename R, typename... Args>
+ R invoke(Args&&... args)
+ {
+ return remote.invoke<R>(name, std::forward<Args>(args)...);
+ }
+ };
+
private:
Message request(Message& message);
gateway.expose(foo, "Foo::setName", &Foo::setName);
gateway.expose(foo, "Foo::getName", &Foo::getName);
+ // convenience macro
auto bar = std::make_shared<Bar>();
- gateway.expose(bar, "Bar::plusTwo", &Bar::plusTwo);
+ EXPOSE(gateway, bar, &Bar::plusTwo);
auto client = std::thread([&]() {
// caller-side
std::string name = remote.invoke<std::string>("Foo::getName");
EXPECT_EQ(name, param);
- int num = remote.invoke<int>("Bar::plusTwo", 3);
+ // convenience macro
+ auto plusTwo = REMOTE_METHOD(remote, &Bar::plusTwo);
+ int num = plusTwo.invoke<int>(3);
EXPECT_EQ(num, 5);
gateway.stop();
INFO(VIST) << "Vist daemon starts.";
rmi::Gateway gateway(SOCK_ADDR);
- gateway.expose(this, "Vist::query", &Vist::query);
+ EXPOSE(gateway, this, &Vist::query);
gateway.start();
}