You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <ipc/IpcChannel.h>
|
|
#include <rpc/RpcValue.h>
|
|
|
|
class ProxyMarshaller {
|
|
public:
|
|
explicit ProxyMarshaller(IpcChannel& ch) : channel(ch) {}
|
|
|
|
// Базовый type-erased вызов: принимает вектор RpcValue и возвращает RpcValue.
|
|
RpcValue call(const std::string& method, const RpcArgs& args) {
|
|
IpcMessage msg;
|
|
|
|
// имя метода
|
|
msg.add(method);
|
|
|
|
// аргументы (PoC: только int)
|
|
for (const auto& a : args) {
|
|
msg.add(a.asInt());
|
|
}
|
|
|
|
// отправить
|
|
channel.send(msg);
|
|
|
|
// получить ответ
|
|
IpcMessage resp = channel.receive();
|
|
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:
|
|
IpcChannel& channel;
|
|
};
|
|
|
|
|