This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#pragma once
#include<ipc/IpcChannel.h>
#include<ipc/IpcCodec.h>
#include<rpc/RpcInvoker.h>
#include<string>
#include<iostream>
#include<unistd.h>
// Серверный диспетчер, который получает IpcMessage с канала,
// декодирует его в RPC-вызов, вызывает RpcInvoker и шлёт ответ.
classIpcDispatcher{
public:
IpcDispatcher(IpcChannel&ch,RpcInvoker&invoker)
:channel_(ch)
,invoker_(invoker){}
// Обработать один запрос. Возвращает false, если получили "пустое"
// сообщение и цикл стоит завершить.
boolhandleOnce(){
IpcMessagereq=channel_.receive();
if(req.empty()){
returnfalse;
}
std::stringmethod;
RpcArgsargs;
IpcCodec::decodeRequest(req,method,args);
RpcValueresult=invoker_.dispatch(method,args);
IpcMessageresp=IpcCodec::encodeResponse(result);
channel_.send(resp);
returntrue;
}
// Простой цикл обработки до тех пор, пока канал не вернёт пустое сообщение.