refactor IPC-dependency out of Proxy

This commit is contained in:
Сергей Маринкевич
2025-12-02 20:54:41 +07:00
parent 6cc64fa6a3
commit f81ac5842c
5 changed files with 97 additions and 35 deletions
+20 -5
View File
@@ -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: