implement object registry

This commit is contained in:
Сергей Маринкевич
2025-12-04 20:03:00 +07:00
parent e7aa646a80
commit 47092fc6f1
10 changed files with 183 additions and 68 deletions
+15 -2
View File
@@ -1,6 +1,7 @@
#pragma once
#include <ipc/IpcConfig.h>
#include <rpc/RpcRegistry.h>
#include <rpc/RpcValue.h>
#include <string>
@@ -10,11 +11,18 @@
// (RpcValue/RpcArgs).
namespace IpcCodec {
// Запрос: имя метода + вектор аргументов.
inline IpcMessage encodeRequest(const std::string& method,
// Используем ObjectId из специализированного RPC-реестра.
using ObjectId = RpcRegistry::ObjectId;
// Запрос: ObjectId + имя метода + вектор аргументов.
inline IpcMessage encodeRequest(ObjectId objectId,
const std::string& method,
const RpcArgs& args) {
IpcMessage msg;
// ObjectId (PoC: приводим к int)
msg.add(static_cast<int>(objectId));
// имя метода
msg.add(method);
@@ -27,10 +35,15 @@ inline IpcMessage encodeRequest(const std::string& method,
}
inline void decodeRequest(const IpcMessage& msg,
ObjectId& objectId,
std::string& method,
RpcArgs& args) {
IpcMessage copy = msg;
// ObjectId (PoC: читаем как int и приводим к ObjectId)
int rawId = copy.get<int>();
objectId = static_cast<ObjectId>(rawId);
// имя метода
method = copy.get<std::string>();
+3 -2
View File
@@ -24,11 +24,12 @@ public:
return false;
}
IpcCodec::ObjectId objectId;
std::string method;
RpcArgs args;
IpcCodec::decodeRequest(req, method, args);
IpcCodec::decodeRequest(req, objectId, method, args);
RpcValue result = invoker_.dispatch(method, args);
RpcValue result = invoker_.dispatch(objectId, method, args);
IpcMessage resp = IpcCodec::encodeResponse(result);
channel_.send(resp);
return true;
+5 -3
View File
@@ -9,13 +9,14 @@
// и IpcCodec, но снаружи предъявляет только callTyped<T>(...).
class IpcMarshaller {
public:
explicit IpcMarshaller(IpcChannel& ch)
: channel(ch) {}
explicit IpcMarshaller(IpcChannel& ch, IpcCodec::ObjectId objectId = 0)
: channel(ch)
, objectId_(objectId) {}
// Базовый type-erased вызов: принимает вектор RpcValue и возвращает RpcValue.
RpcValue call(const std::string& method, const RpcArgs& args) {
// упаковать запрос в IpcMessage
IpcMessage msg = IpcCodec::encodeRequest(method, args);
IpcMessage msg = IpcCodec::encodeRequest(objectId_, method, args);
// отправить
channel.send(msg);
@@ -39,6 +40,7 @@ public:
private:
IpcChannel& channel;
IpcCodec::ObjectId objectId_;
};