[Yunq] Return status in server code.
This commit is contained in:
parent
3eba0bd9d8
commit
700f3f94cb
20 changed files with 166 additions and 178 deletions
|
|
@ -75,9 +75,9 @@ void YellowstoneServerBase::ServerThread() {
|
|||
|
||||
glcr::ErrorCode reply_err = glcr::OK;
|
||||
resp_cap.Reset();
|
||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||
if (err != glcr::OK) {
|
||||
WriteError(resp_buffer, err);
|
||||
glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||
if (!err) {
|
||||
WriteError(resp_buffer, err.code());
|
||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
||||
} else {
|
||||
WriteHeader(resp_buffer, resp_length);
|
||||
|
|
@ -90,12 +90,12 @@ void YellowstoneServerBase::ServerThread() {
|
|||
|
||||
}
|
||||
|
||||
glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||
const glcr::CapBuffer& req_caps,
|
||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||
glcr::CapBuffer& resp_caps) {
|
||||
glcr::Status YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||
const glcr::CapBuffer& req_caps,
|
||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||
glcr::CapBuffer& resp_caps) {
|
||||
if (request.At<uint32_t>(0) != kSentinel) {
|
||||
return glcr::INVALID_ARGUMENT;
|
||||
return glcr::InvalidArgument("Request Not Valid");
|
||||
}
|
||||
|
||||
uint64_t method_select = request.At<uint64_t>(8);
|
||||
|
|
@ -106,16 +106,13 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
|
||||
RegisterEndpointRequest yunq_request;
|
||||
// TODO: Return status.
|
||||
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
if (!status) {
|
||||
return status.code();
|
||||
}
|
||||
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RET_ERR(HandleRegisterEndpoint(yunq_request));
|
||||
RETURN_ERROR(HandleRegisterEndpoint(yunq_request));
|
||||
|
||||
|
||||
|
||||
|
|
@ -128,10 +125,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
|
||||
GetEndpointRequest yunq_request;
|
||||
// TODO: Return status.
|
||||
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
if (!status) {
|
||||
return status.code();
|
||||
}
|
||||
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||
|
||||
|
||||
|
||||
|
|
@ -139,7 +133,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
|
||||
|
||||
|
||||
RET_ERR(HandleGetEndpoint(yunq_request, yunq_response));
|
||||
RETURN_ERROR(HandleGetEndpoint(yunq_request, yunq_response));
|
||||
|
||||
|
||||
|
||||
|
|
@ -156,7 +150,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
|
||||
|
||||
|
||||
RET_ERR(HandleGetAhciInfo(yunq_response));
|
||||
RETURN_ERROR(HandleGetAhciInfo(yunq_response));
|
||||
|
||||
|
||||
|
||||
|
|
@ -173,7 +167,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
|
||||
|
||||
|
||||
RET_ERR(HandleGetFramebufferInfo(yunq_response));
|
||||
RETURN_ERROR(HandleGetFramebufferInfo(yunq_response));
|
||||
|
||||
|
||||
|
||||
|
|
@ -190,7 +184,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
|
||||
|
||||
|
||||
RET_ERR(HandleGetDenali(yunq_response));
|
||||
RETURN_ERROR(HandleGetDenali(yunq_response));
|
||||
|
||||
|
||||
|
||||
|
|
@ -199,10 +193,10 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
break;
|
||||
}
|
||||
default: {
|
||||
return glcr::UNIMPLEMENTED;
|
||||
return glcr::Unimplemented("Method unimplemented by server.");
|
||||
}
|
||||
}
|
||||
return glcr::OK;
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <glacier/status/status.h>
|
||||
#include <mammoth/proc/thread.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
|
|
@ -28,23 +29,23 @@ class YellowstoneServerBase {
|
|||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&) = 0;
|
||||
[[nodiscard]] virtual glcr::Status HandleRegisterEndpoint(const RegisterEndpointRequest&) = 0;
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) = 0;
|
||||
[[nodiscard]] virtual glcr::Status HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) = 0;
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetAhciInfo(AhciInfo&) = 0;
|
||||
[[nodiscard]] virtual glcr::Status HandleGetAhciInfo(AhciInfo&) = 0;
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetFramebufferInfo(FramebufferInfo&) = 0;
|
||||
[[nodiscard]] virtual glcr::Status HandleGetFramebufferInfo(FramebufferInfo&) = 0;
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetDenali(DenaliInfo&) = 0;
|
||||
[[nodiscard]] virtual glcr::Status HandleGetDenali(DenaliInfo&) = 0;
|
||||
|
||||
|
||||
|
||||
|
|
@ -54,9 +55,9 @@ class YellowstoneServerBase {
|
|||
friend void YellowstoneServerBaseThreadBootstrap(void*);
|
||||
void ServerThread();
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||
glcr::CapBuffer& resp_caps);
|
||||
[[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||
glcr::CapBuffer& resp_caps);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@ glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
|
|||
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
|
||||
: YellowstoneServerBase(endpoint_cap) {}
|
||||
|
||||
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(AhciInfo& info) {
|
||||
glcr::Status YellowstoneServer::HandleGetAhciInfo(AhciInfo& info) {
|
||||
info.set_ahci_region(pci_reader_.GetAhciVmmo());
|
||||
info.set_region_length(kPcieConfigurationSize);
|
||||
return glcr::OK;
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
|
||||
glcr::Status YellowstoneServer::HandleGetFramebufferInfo(
|
||||
FramebufferInfo& info) {
|
||||
// FIXME: Don't do this for each request.
|
||||
mmth::OwnedMemoryRegion region =
|
||||
|
|
@ -68,22 +68,22 @@ glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
|
|||
info.set_blue_mask_size(fb->blue_mask_size);
|
||||
info.set_blue_mask_shift(fb->blue_mask_shift);
|
||||
|
||||
return glcr::OK;
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::ErrorCode YellowstoneServer::HandleGetDenali(DenaliInfo& info) {
|
||||
glcr::Status YellowstoneServer::HandleGetDenali(DenaliInfo& info) {
|
||||
if (!endpoint_map_.Contains("denali")) {
|
||||
return glcr::NOT_FOUND;
|
||||
return glcr::NotFound("Denali Capability Not registered");
|
||||
}
|
||||
z_cap_t new_denali;
|
||||
check(ZCapDuplicate(endpoint_map_.at("denali"), kZionPerm_All, &new_denali));
|
||||
info.set_denali_endpoint(new_denali);
|
||||
info.set_device_id(device_id_);
|
||||
info.set_lba_offset(lba_offset_);
|
||||
return glcr::OK;
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
|
||||
glcr::Status YellowstoneServer::HandleRegisterEndpoint(
|
||||
const RegisterEndpointRequest& req) {
|
||||
dbgln("Registering {}.", req.endpoint_name().view());
|
||||
check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability()));
|
||||
|
|
@ -106,19 +106,20 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
|
|||
} else {
|
||||
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
|
||||
}
|
||||
return glcr::OK;
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
glcr::ErrorCode YellowstoneServer::HandleGetEndpoint(
|
||||
const GetEndpointRequest& req, Endpoint& resp) {
|
||||
glcr::Status YellowstoneServer::HandleGetEndpoint(const GetEndpointRequest& req,
|
||||
Endpoint& resp) {
|
||||
if (!endpoint_map_.Contains(req.endpoint_name())) {
|
||||
return glcr::NOT_FOUND;
|
||||
return glcr::NotFound(
|
||||
glcr::StrFormat("Endpoint '{}' not found.", req.endpoint_name()));
|
||||
}
|
||||
z_cap_t cap = endpoint_map_.at(req.endpoint_name());
|
||||
z_cap_t new_cap;
|
||||
check(ZCapDuplicate(cap, kZionPerm_All, &new_cap));
|
||||
resp.set_endpoint(new_cap);
|
||||
return glcr::OK;
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
||||
void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
|
||||
|
|
|
|||
|
|
@ -16,13 +16,11 @@ class YellowstoneServer : public YellowstoneServerBase {
|
|||
public:
|
||||
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
|
||||
|
||||
glcr::ErrorCode HandleGetAhciInfo(AhciInfo&) override;
|
||||
glcr::ErrorCode HandleGetFramebufferInfo(FramebufferInfo&) override;
|
||||
glcr::ErrorCode HandleGetDenali(DenaliInfo&) override;
|
||||
glcr::ErrorCode HandleRegisterEndpoint(
|
||||
const RegisterEndpointRequest&) override;
|
||||
glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&,
|
||||
Endpoint&) override;
|
||||
glcr::Status HandleGetAhciInfo(AhciInfo&) override;
|
||||
glcr::Status HandleGetFramebufferInfo(FramebufferInfo&) override;
|
||||
glcr::Status HandleGetDenali(DenaliInfo&) override;
|
||||
glcr::Status HandleRegisterEndpoint(const RegisterEndpointRequest&) override;
|
||||
glcr::Status HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) override;
|
||||
|
||||
void WaitDenaliRegistered();
|
||||
void WaitVictoriaFallsRegistered();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue