Experimental AuroraRuntime-based Remote Procedure Call library
Go to file
2024-09-07 09:33:46 +01:00
Include [+] Large packets 2023-12-16 22:59:44 +00:00
Source [*] Update send packet 2024-09-07 09:33:46 +01:00
.gitignore Initial Commit 2022-07-02 23:13:53 +01:00
Aurora.json Initial Commit 2022-07-02 23:13:53 +01:00
LICENSE Initial Commit 2022-07-02 23:13:53 +01:00
README.md [*] Updated Aurora Runtime 2022-12-28 12:09:07 +00:00

Experimental RPC library

Example

#include <AuRPCAPI.hpp>

static AuSPtr<AuIRPC> gRpcServer = AuRPCNewInstance();
static AuSPtr<AuIRPC> gRpcClient = AuRPCNewInstance();
static AuSPtr<AuIRPCClientChannel> gRpcClientChannel;

void Run()
{
    SysAssert(gRpcServer->StartServer(AuAsync::GetCurrentWorkerPId()));
    SysAssert(gRpcClient->StartClient(AuAsync::GetCurrentWorkerPId()));

    auto server = gRpcServer->ToServer();

    auto handle = server->ExportString();

    struct DummyService : AuIRPCService
    {
        AuUInt32 GetId() override
        {
            return 2;
        }

        void Dispatch(AuRPCResponse &response, AuUInt32 id, AuByteBuffer &buffer) override
        {
            AuLogDbg("ID = {}, bytes = {}", id, buffer.RemainingBytes());
            
            response.message->Write<AuString>("Hello World");
        }
    };

    server->RegisterService(AuMakeShared<DummyService>());

    gRpcClientChannel = gRpcClient->Connect(handle);
    SysAssert(gRpcClientChannel);

    auto callback = AuMakeShared<AuIRPCChannelCallbacksFunctional>();
    SysAssert(callback);

    callback->OnConnectFunctional = []()
    {
        auto request = AuRPCNewRequest(2, 3);
        SysAssert(request);

        auto callback = AuMakeShared<AuRPCRequestCallbackFunctional>();
        SysAssert(callback);

        callback->OnResponseFunctional = [](const AuRPCResponse &res)
        {
            AuLogDbg("Complete! Message = {}", res.message->Read<AuString>());
        };

        request->SetCallback(callback);
        gRpcClientChannel->SendRequest(request);
    };

    gRpcClientChannel->SetCallbacks(callback);
}