66 lines
1.3 KiB
C++
66 lines
1.3 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;
|
|
}
|
|
|
|
AuSPtr<AuIRPC> AuRPCNewInstance()
|
|
{
|
|
return AuMakeShared<AuRPC>();
|
|
} |