73 lines
1.4 KiB
C++
73 lines
1.4 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuRPC.cpp
|
|
Date: 2022-6-29
|
|
Author: Reece
|
|
***/
|
|
#include <AuroraRuntime.hpp>
|
|
#include "AuRPC.hpp"
|
|
#include "AuRPCClientChannel.hpp"
|
|
|
|
AuSPtr<AuIO::IIOProcessor> GetRPCProcessor()
|
|
{
|
|
return AuAsync::GetSelfIOProcessor();
|
|
}
|
|
|
|
bool AuRPC::StartClient(AuAsync::WorkerPId_t worker)
|
|
{
|
|
if (worker.second == AuAsync::kThreadIdAny)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
this->pinnedClientThread = worker;
|
|
return true;
|
|
}
|
|
|
|
bool AuRPC::StartServer(AuAsync::WorkerPId_t worker)
|
|
{
|
|
return this->server.Init(this, worker);
|
|
}
|
|
|
|
AuSPtr<AuIRPCServer> AuRPC::ToServer()
|
|
{
|
|
return AuSPtr<AuRPCServer>(AuSharedFromThis(), &this->server);
|
|
}
|
|
|
|
AuSPtr<AuIRPCClientChannel> AuRPC::Connect(const AuString& str)
|
|
{
|
|
auto eh = AuMakeShared<AuRPCClientChannel>(this->SharedFromThis());
|
|
if (!eh)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
//if (!AuTryInsert(this->clientChannels, eh))
|
|
//{
|
|
// return {};
|
|
//}
|
|
|
|
if (!eh->Init(str))
|
|
{
|
|
return {};
|
|
}
|
|
|
|
return eh;
|
|
}
|
|
|
|
void AuRPC::SetRecommendedPipeLength(AuUInt32 uLength)
|
|
{
|
|
this->optPipeLength = uLength;
|
|
}
|
|
|
|
AuUInt32 AuRPC::GetLargePacketLength()
|
|
{
|
|
auto uLength = this->optPipeLength.value_or(AuHwInfo::GetPageSize() * 16);
|
|
return uLength / 3;
|
|
}
|
|
|
|
AuSPtr<AuIRPC> AuRPCNewInstance()
|
|
{
|
|
return AuMakeShared<AuRPC>();
|
|
} |