factor IPC out of server RPC
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user