71 lines
1.4 KiB
C++
71 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"
|
|
|
|
static thread_local AuSPtr<AuIO::IIOProcessor> tlsIOProcessor;
|
|
|
|
AuSPtr<AuIO::IIOProcessor> GetRPCProcessor()
|
|
{
|
|
return tlsIOProcessor ?
|
|
tlsIOProcessor :
|
|
tlsIOProcessor = AuIO::NewIOProcessorOnThread(false, AuAsync::GetCurrentWorkerPId());
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
AuSPtr<AuIRPC> AuRPCNewInstance()
|
|
{
|
|
return AuMakeShared<AuRPC>();
|
|
} |