AuroraRPC/Source/AuRPCRequest.cpp
Jamie Reece Wilson aa7591967a [+] Broadcasts and client/server messages
[+] Async responses
[+] AuRPC::SetRecommendedPipeLength
2023-12-16 18:16:32 +00:00

92 lines
1.9 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuRPCRequest.cpp
Date: 2022-6-29
Author: Reece
***/
#include <AuroraRuntime.hpp>
#include "AuRPC.hpp"
#include "AuRPCRequest.hpp"
bool AuRPCRequest::SetData(const AuByteBuffer& toRead)
{
return this->SetData(AuMemoryViewRead(toRead));
}
bool AuRPCRequest::SetData(const AuMemoryViewRead& view)
{
data.Reset();
this->packetLength = view.length + this->HeaderLength();
data.Resize(view.length + this->HeaderLength());
if (!this->data)
{
SysPushErrorMem();
return false;
}
this->WriteRPCHeader();
this->data.Write(view.ptr, view.length);
return bool(data);
}
void AuRPCRequest::SetCallback(const AuSPtr<AuRPCRequestCallback> &callback)
{
this->callback = callback;
}
bool AuRPCRequest::EmptyRequest()
{
return SetData(AuMemoryViewRead {});
}
AuMemoryViewRead AuRPCRequest::GetData()
{
return this->data;
}
void AuRPCRequest::WriteDummy()
{
WriteRPCHeader();
}
void AuRPCRequest::WriteHeaderConnect()
{
this->data.Write<AuUInt32>(5);
this->data.Write<AuUInt8>(kRequestConnect);
}
void AuRPCRequest::WriteRPCHeader()
{
this->data.Write<AuUInt32>(this->packetLength);
this->data.Write<AuUInt8>(this->dataType);
this->data.Write<AuUInt32>(this->serviceId);
this->data.Write<AuUInt32>(this->methodId);
this->data.Write<AuUInt64>(AuUInt64(AuUInt(this)));
}
AuUInt32 AuRPCRequest::HeaderLength()
{
return 4 + 1 + 4 /*service id*/ + 4 /*method*/ + 8 /*uid*/;
}
ERPCRequestState AuRPCRequest::GetState()
{
return this->state;
}
AuSPtr<AuIRPCRequest> AuRPCNewRequest(AuUInt32 serviceId, AuUInt32 methodId)
{
auto req = AuMakeShared<AuRPCRequest>();
if (!req)
{
return {};
}
req->serviceId = serviceId;
req->methodId = methodId;
req->WriteRPCHeader();
return req;
}