refactor IPC-dependency out of Proxy
This commit is contained in:
@@ -1,27 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <ipc/IpcChannel.h>
|
||||
#include <rpc/RpcValue.h>
|
||||
|
||||
class ProxyMarshaller {
|
||||
public:
|
||||
explicit ProxyMarshaller(IpcChannel& ch) : channel(ch) {}
|
||||
|
||||
template<typename Ret, typename... Args>
|
||||
Ret call(const std::string& method, const Args&... args) {
|
||||
// Базовый type-erased вызов: принимает вектор RpcValue и возвращает RpcValue.
|
||||
RpcValue call(const std::string& method, const RpcArgs& args) {
|
||||
IpcMessage msg;
|
||||
|
||||
// имя метода
|
||||
msg.add(method);
|
||||
|
||||
// аргументы
|
||||
(msg.add(args), ...);
|
||||
// аргументы (PoC: только int)
|
||||
for (const auto& a : args) {
|
||||
msg.add(a.asInt());
|
||||
}
|
||||
|
||||
// отправить
|
||||
channel.send(msg);
|
||||
|
||||
// получить ответ
|
||||
IpcMessage resp = channel.receive();
|
||||
return resp.template get<Ret>();
|
||||
return RpcValue::fromInt(resp.get<int>());
|
||||
}
|
||||
|
||||
// Удобный шаблонный хелпер для сгенерированных прокси.
|
||||
template<typename Ret, typename... Args>
|
||||
Ret callTyped(const std::string& method, const Args&... args) {
|
||||
RpcArgs packed;
|
||||
packed.reserve(sizeof...(Args));
|
||||
(packed.emplace_back(RpcValue::fromInt(args)), ...); // PoC: только int
|
||||
|
||||
RpcValue r = call(method, packed);
|
||||
// PoC: Ret == int
|
||||
return static_cast<Ret>(r.asInt());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user