AuroraRPC/Source/AuRPC.cpp

71 lines
1.4 KiB
C++
Raw Normal View History

2022-07-02 22:08:52 +00:00
/***
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;
}
2022-07-02 22:08:52 +00:00
AuSPtr<AuIRPC> AuRPCNewInstance()
{
return AuMakeShared<AuRPC>();
}