2022-07-02 22:08:52 +00:00
|
|
|
/***
|
|
|
|
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();
|
2022-07-05 20:16:22 +00:00
|
|
|
data.Resize(view.length + this->HeaderLength());
|
2022-07-02 22:08:52 +00:00
|
|
|
if (!this->data)
|
|
|
|
{
|
|
|
|
SysPushErrorMem();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->WriteRPCHeader();
|
|
|
|
this->data.Write(view.ptr, view.length);
|
|
|
|
return bool(data);
|
|
|
|
}
|
|
|
|
|
2023-12-16 18:16:32 +00:00
|
|
|
void AuRPCRequest::SetCallback(const AuSPtr<AuRPCRequestCallback> &callback)
|
2022-07-02 22:08:52 +00:00
|
|
|
{
|
|
|
|
this->callback = callback;
|
|
|
|
}
|
|
|
|
|
2022-07-07 04:16:27 +00:00
|
|
|
bool AuRPCRequest::EmptyRequest()
|
|
|
|
{
|
|
|
|
return SetData(AuMemoryViewRead {});
|
|
|
|
}
|
|
|
|
|
2022-07-02 22:08:52 +00:00
|
|
|
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);
|
2023-12-16 18:16:32 +00:00
|
|
|
this->data.Write<AuUInt8>(this->dataType);
|
2022-07-02 22:08:52 +00:00
|
|
|
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;
|
|
|
|
}
|