factor IPC out of server RPC

This commit is contained in:
Сергей Маринкевич
2025-12-03 18:27:08 +07:00
parent 00d359a064
commit 43f67275e2
6 changed files with 130 additions and 46 deletions
+5 -21
View File
@@ -1,7 +1,7 @@
#include "{{ cls.name }}.skeleton.h"
{{ cls.name }}Skeleton::{{ cls.name }}Skeleton({{ cls.name }}& obj)
{
{{ cls.name }}Skeleton::{{ cls.name }}Skeleton({{ cls.name }}& obj, RpcInvoker& inv)
: invoker(inv) {
{% for m in cls.methods %}
invoker.registerMethod(&obj,
"{{ cls.name }}.{{ m.name }}",
@@ -9,24 +9,8 @@
{% endfor %}
}
IpcMessage {{ cls.name }}Skeleton::dispatch(const IpcMessage& req) {
// Перепаковываем IpcMessage в RpcArgs и вызываем type-erased инвокер.
IpcMessage msg = req;
// имя метода
std::string method = msg.get<std::string>();
// аргументы (PoC: только int, читаем все до конца сообщения)
RpcArgs args;
while (!msg.empty()) {
int v = msg.get<int>();
args.emplace_back(RpcValue::fromInt(v));
}
RpcValue result = invoker.dispatch(method, args);
IpcMessage resp;
resp.add(result.asInt()); // PoC: только int
return resp;
RpcValue {{ cls.name }}Skeleton::dispatch(const std::string& method,
const RpcArgs& args) {
return invoker.dispatch(method, args);
}
+4 -4
View File
@@ -2,14 +2,14 @@
#include "{{ cls.name }}.h"
#include "rpc/RpcInvoker.h"
#include "ipc/IpcMessage.h"
class {{ cls.name }}Skeleton {
public:
explicit {{ cls.name }}Skeleton({{ cls.name }}& obj);
explicit {{ cls.name }}Skeleton({{ cls.name }}& obj, RpcInvoker& invoker);
IpcMessage dispatch(const IpcMessage& req);
// IPC-независимый диспетчер: принимает имя метода и RpcArgs.
RpcValue dispatch(const std::string& method, const RpcArgs& args);
private:
RpcInvoker invoker;
RpcInvoker& invoker;
};