[Yunq] Return status in server code.

This commit is contained in:
Drew Galbraith 2023-12-01 10:23:54 -08:00
parent 3eba0bd9d8
commit 700f3f94cb
20 changed files with 166 additions and 178 deletions

View File

@ -72,6 +72,12 @@ void StrFormatValue(StringBuilder& builder, char const* const& value,
StrFormatInternal(builder, StringView(value)); StrFormatInternal(builder, StringView(value));
} }
template <>
void StrFormatValue(StringBuilder& builder, const String& value,
StringView opts) {
StrFormatInternal(builder, value);
}
template <> template <>
void StrFormatValue(StringBuilder& builder, const StringView& value, void StrFormatValue(StringBuilder& builder, const StringView& value,
StringView opts) { StringView opts) {

View File

@ -44,6 +44,9 @@ void StrFormatValue(StringBuilder& builder, char const* const& value,
StringView opts); StringView opts);
template <> template <>
void StrFormatValue(StringBuilder& builder, const String& value,
StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, const StringView& value, void StrFormatValue(StringBuilder& builder, const StringView& value,
StringView opts); StringView opts);

View File

@ -12,8 +12,8 @@ glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
return glcr::UniquePtr<DenaliServer>(new DenaliServer(cap, driver)); return glcr::UniquePtr<DenaliServer>(new DenaliServer(cap, driver));
} }
glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req, glcr::Status DenaliServer::HandleRead(const ReadRequest& req,
ReadResponse& resp) { ReadResponse& resp) {
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id())); ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
uint64_t paddr; uint64_t paddr;
@ -28,15 +28,15 @@ glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req,
resp.set_device_id(req.device_id()); resp.set_device_id(req.device_id());
resp.set_size(req.size()); resp.set_size(req.size());
resp.set_memory(region.DuplicateCap()); resp.set_memory(region.DuplicateCap());
return glcr::OK; return glcr::Status::Ok();
} }
glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req, glcr::Status DenaliServer::HandleReadMany(const ReadManyRequest& req,
ReadResponse& resp) { ReadResponse& resp) {
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id())); ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
if (req.lba().size() != req.sector_cnt().size()) { if (req.lba().size() != req.sector_cnt().size()) {
return glcr::INVALID_ARGUMENT; return glcr::InvalidArgument("LBA and Sector Cnt must be the same length.");
} }
uint64_t sector_cnt = 0; uint64_t sector_cnt = 0;
@ -60,5 +60,5 @@ glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
resp.set_device_id(req.device_id()); resp.set_device_id(req.device_id());
resp.set_size(sector_cnt); resp.set_size(sector_cnt);
resp.set_memory(region.DuplicateCap()); resp.set_memory(region.DuplicateCap());
return glcr::OK; return glcr::Status::Ok();
} }

View File

@ -10,10 +10,9 @@ class DenaliServer : public DenaliServerBase {
static glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> Create( static glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> Create(
AhciDriver& driver); AhciDriver& driver);
glcr::ErrorCode HandleRead(const ReadRequest& req, glcr::Status HandleRead(const ReadRequest& req, ReadResponse& resp) override;
ReadResponse& resp) override; glcr::Status HandleReadMany(const ReadManyRequest& req,
glcr::ErrorCode HandleReadMany(const ReadManyRequest& req, ReadResponse& resp) override;
ReadResponse& resp) override;
private: private:
static const uint64_t kBuffSize = 1024; static const uint64_t kBuffSize = 1024;

View File

@ -73,9 +73,10 @@ void DenaliServerBase::ServerThread() {
glcr::ErrorCode reply_err = glcr::OK; glcr::ErrorCode reply_err = glcr::OK;
resp_cap.Reset(); resp_cap.Reset();
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
if (err != glcr::OK) { if (!err) {
WriteError(resp_buffer, err); WriteError(resp_buffer, err.code());
dbgln("Responding Error {}", err.message());
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
} else { } else {
WriteHeader(resp_buffer, resp_length); WriteHeader(resp_buffer, resp_length);
@ -88,12 +89,12 @@ void DenaliServerBase::ServerThread() {
} }
glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request, glcr::Status DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
const glcr::CapBuffer& req_caps, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps) { glcr::CapBuffer& resp_caps) {
if (request.At<uint32_t>(0) != kSentinel) { 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); uint64_t method_select = request.At<uint64_t>(8);
@ -104,10 +105,7 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
ReadRequest yunq_request; ReadRequest yunq_request;
// TODO: Return status. // TODO: Return status.
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
if (!status) {
return status.code();
}
@ -115,7 +113,7 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
RET_ERR(HandleRead(yunq_request, yunq_response)); RETURN_ERROR(HandleRead(yunq_request, yunq_response));
@ -128,10 +126,7 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
ReadManyRequest yunq_request; ReadManyRequest yunq_request;
// TODO: Return status. // TODO: Return status.
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
if (!status) {
return status.code();
}
@ -139,7 +134,7 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
RET_ERR(HandleReadMany(yunq_request, yunq_response)); RETURN_ERROR(HandleReadMany(yunq_request, yunq_response));
@ -148,10 +143,10 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
break; break;
} }
default: { default: {
return glcr::UNIMPLEMENTED; return glcr::Unimplemented("Method unimplemented by server.");
} }
} }
return glcr::OK; return glcr::Status::Ok();
} }

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <glacier/status/status.h>
#include <mammoth/proc/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
@ -26,11 +27,11 @@ class DenaliServerBase {
[[nodiscard]] virtual glcr::ErrorCode HandleRead(const ReadRequest&, ReadResponse&) = 0; [[nodiscard]] virtual glcr::Status HandleRead(const ReadRequest&, ReadResponse&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleReadMany(const ReadManyRequest&, ReadResponse&) = 0; [[nodiscard]] virtual glcr::Status HandleReadMany(const ReadManyRequest&, ReadResponse&) = 0;
@ -40,9 +41,9 @@ class DenaliServerBase {
friend void DenaliServerBaseThreadBootstrap(void*); friend void DenaliServerBaseThreadBootstrap(void*);
void ServerThread(); void ServerThread();
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps, [[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps); glcr::CapBuffer& resp_caps);
}; };

View File

@ -73,9 +73,9 @@ void VFSServerBase::ServerThread() {
glcr::ErrorCode reply_err = glcr::OK; glcr::ErrorCode reply_err = glcr::OK;
resp_cap.Reset(); resp_cap.Reset();
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
if (err != glcr::OK) { if (!err) {
WriteError(resp_buffer, err); WriteError(resp_buffer, err.code());
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
} else { } else {
WriteHeader(resp_buffer, resp_length); WriteHeader(resp_buffer, resp_length);
@ -88,12 +88,12 @@ void VFSServerBase::ServerThread() {
} }
glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request, glcr::Status VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
const glcr::CapBuffer& req_caps, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps) { glcr::CapBuffer& resp_caps) {
if (request.At<uint32_t>(0) != kSentinel) { 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); uint64_t method_select = request.At<uint64_t>(8);
@ -104,10 +104,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
OpenFileRequest yunq_request; OpenFileRequest yunq_request;
// TODO: Return status. // TODO: Return status.
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
if (!status) {
return status.code();
}
@ -115,7 +112,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
RET_ERR(HandleOpenFile(yunq_request, yunq_response)); RETURN_ERROR(HandleOpenFile(yunq_request, yunq_response));
@ -128,10 +125,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
GetDirectoryRequest yunq_request; GetDirectoryRequest yunq_request;
// TODO: Return status. // TODO: Return status.
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
if (!status) {
return status.code();
}
@ -139,7 +133,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
RET_ERR(HandleGetDirectory(yunq_request, yunq_response)); RETURN_ERROR(HandleGetDirectory(yunq_request, yunq_response));
@ -148,10 +142,10 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
break; break;
} }
default: { default: {
return glcr::UNIMPLEMENTED; return glcr::Unimplemented("Method unimplemented by server.");
} }
} }
return glcr::OK; return glcr::Status::Ok();
} }

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <glacier/status/status.h>
#include <mammoth/proc/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
@ -26,11 +27,11 @@ class VFSServerBase {
[[nodiscard]] virtual glcr::ErrorCode HandleOpenFile(const OpenFileRequest&, OpenFileResponse&) = 0; [[nodiscard]] virtual glcr::Status HandleOpenFile(const OpenFileRequest&, OpenFileResponse&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetDirectory(const GetDirectoryRequest&, Directory&) = 0; [[nodiscard]] virtual glcr::Status HandleGetDirectory(const GetDirectoryRequest&, Directory&) = 0;
@ -40,9 +41,9 @@ class VFSServerBase {
friend void VFSServerBaseThreadBootstrap(void*); friend void VFSServerBaseThreadBootstrap(void*);
void ServerThread(); void ServerThread();
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps, [[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps); glcr::CapBuffer& resp_caps);
}; };

View File

@ -11,13 +11,13 @@ glcr::ErrorOr<glcr::UniquePtr<VFSServer>> VFSServer::Create(
return glcr::UniquePtr<VFSServer>(new VFSServer(endpoint_cap, driver)); return glcr::UniquePtr<VFSServer>(new VFSServer(endpoint_cap, driver));
} }
glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request, glcr::Status VFSServer::HandleOpenFile(const OpenFileRequest& request,
OpenFileResponse& response) { OpenFileResponse& response) {
auto path_tokens = glcr::StrSplit(request.path(), '/'); auto path_tokens = glcr::StrSplit(request.path(), '/');
// Require all paths to be absolute rather than relative. // Require all paths to be absolute rather than relative.
// If the path starts with '/' then the first token will be empty. // If the path starts with '/' then the first token will be empty.
if (path_tokens.at(0) != "") { if (path_tokens.at(0) != "") {
return glcr::INVALID_ARGUMENT; return glcr::InvalidArgument("Open file supports only absolute paths.");
} }
ASSIGN_OR_RETURN(auto files, driver_.ReadDirectory(2)); ASSIGN_OR_RETURN(auto files, driver_.ReadDirectory(2));
@ -31,9 +31,8 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
} }
} }
if (!found_token) { if (!found_token) {
dbgln("Directory '{}' not found.", return glcr::NotFound(glcr::StrFormat("Directory '{}' not found.",
glcr::String(path_tokens.at(i)).cstr()); glcr::String(path_tokens.at(i))));
return glcr::NOT_FOUND;
} }
} }
@ -48,8 +47,9 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
} }
} }
if (!region) { if (!region) {
dbgln("File '{}' not found.", return glcr::NotFound(
glcr::String(path_tokens.at(path_tokens.size() - 1)).cstr()); glcr::StrFormat("File '{}' not found.",
glcr::String(path_tokens.at(path_tokens.size() - 1))));
} }
response.set_path(request.path()); response.set_path(request.path());
@ -61,15 +61,15 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
ASSIGN_OR_RETURN(Inode * inode, driver_.GetInode(inode_num)); ASSIGN_OR_RETURN(Inode * inode, driver_.GetInode(inode_num));
// FIXME: This technically only sets the lower 32 bits. // FIXME: This technically only sets the lower 32 bits.
response.set_size(inode->size); response.set_size(inode->size);
return glcr::OK; return glcr::Status::Ok();
} }
glcr::ErrorCode VFSServer::HandleGetDirectory( glcr::Status VFSServer::HandleGetDirectory(const GetDirectoryRequest& request,
const GetDirectoryRequest& request, Directory& response) { Directory& response) {
auto path_tokens = glcr::StrSplit(request.path(), '/'); auto path_tokens = glcr::StrSplit(request.path(), '/');
if (path_tokens.at(0) != "") { if (path_tokens.at(0) != "") {
return glcr::INVALID_ARGUMENT; return glcr::InvalidArgument("Get Directory only supports absolute path.");
} }
// If there is a trailing slash we can get rid of the empty string. // If there is a trailing slash we can get rid of the empty string.
@ -88,9 +88,8 @@ glcr::ErrorCode VFSServer::HandleGetDirectory(
} }
} }
if (!found_token) { if (!found_token) {
dbgln("Directory '{}' not found.", return glcr::NotFound(glcr::StrFormat("Directory '{}' not found.",
glcr::String(path_tokens.at(i)).cstr()); glcr::String(path_tokens.at(i))));
return glcr::NOT_FOUND;
} }
} }
@ -106,5 +105,5 @@ glcr::ErrorCode VFSServer::HandleGetDirectory(
response.set_filenames(filelist.ToString()); response.set_filenames(filelist.ToString());
return glcr::OK; return glcr::Status::Ok();
} }

View File

@ -9,11 +9,11 @@ class VFSServer : public VFSServerBase {
public: public:
static glcr::ErrorOr<glcr::UniquePtr<VFSServer>> Create(Ext2Driver& driver); static glcr::ErrorOr<glcr::UniquePtr<VFSServer>> Create(Ext2Driver& driver);
glcr::ErrorCode HandleOpenFile(const OpenFileRequest&, glcr::Status HandleOpenFile(const OpenFileRequest&,
OpenFileResponse&) override; OpenFileResponse&) override;
glcr::ErrorCode HandleGetDirectory(const GetDirectoryRequest&, glcr::Status HandleGetDirectory(const GetDirectoryRequest&,
Directory&) override; Directory&) override;
private: private:
// FIXME: Don't store this as a reference. // FIXME: Don't store this as a reference.

View File

@ -73,9 +73,9 @@ void VoyageursServerBase::ServerThread() {
glcr::ErrorCode reply_err = glcr::OK; glcr::ErrorCode reply_err = glcr::OK;
resp_cap.Reset(); resp_cap.Reset();
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
if (err != glcr::OK) { if (!err) {
WriteError(resp_buffer, err); WriteError(resp_buffer, err.code());
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
} else { } else {
WriteHeader(resp_buffer, resp_length); WriteHeader(resp_buffer, resp_length);
@ -88,12 +88,12 @@ void VoyageursServerBase::ServerThread() {
} }
glcr::ErrorCode VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& request, glcr::Status VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& request,
const glcr::CapBuffer& req_caps, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps) { glcr::CapBuffer& resp_caps) {
if (request.At<uint32_t>(0) != kSentinel) { 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); uint64_t method_select = request.At<uint64_t>(8);
@ -104,16 +104,13 @@ glcr::ErrorCode VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& reque
KeyboardListener yunq_request; KeyboardListener yunq_request;
// TODO: Return status. // TODO: Return status.
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
if (!status) {
return status.code();
}
RET_ERR(HandleRegisterKeyboardListener(yunq_request)); RETURN_ERROR(HandleRegisterKeyboardListener(yunq_request));
@ -122,10 +119,10 @@ glcr::ErrorCode VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& reque
break; break;
} }
default: { default: {
return glcr::UNIMPLEMENTED; return glcr::Unimplemented("Method unimplemented by server.");
} }
} }
return glcr::OK; return glcr::Status::Ok();
} }

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <glacier/status/status.h>
#include <mammoth/proc/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
@ -26,7 +27,7 @@ class VoyageursServerBase {
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterKeyboardListener(const KeyboardListener&) = 0; [[nodiscard]] virtual glcr::Status HandleRegisterKeyboardListener(const KeyboardListener&) = 0;
@ -36,9 +37,9 @@ class VoyageursServerBase {
friend void VoyageursServerBaseThreadBootstrap(void*); friend void VoyageursServerBaseThreadBootstrap(void*);
void ServerThread(); void ServerThread();
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps, [[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps); glcr::CapBuffer& resp_caps);
}; };

View File

@ -8,10 +8,10 @@ glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> VoyageursServer::Create(
new VoyageursServer(cap, keyboard_driver)); new VoyageursServer(cap, keyboard_driver));
} }
glcr::ErrorCode VoyageursServer::HandleRegisterKeyboardListener( glcr::Status VoyageursServer::HandleRegisterKeyboardListener(
const KeyboardListener& listener) { const KeyboardListener& listener) {
keyboard_driver_.RegisterListener(listener.port_capability()); keyboard_driver_.RegisterListener(listener.port_capability());
return glcr::OK; return glcr::Status::Ok();
} }
VoyageursServer::VoyageursServer(z_cap_t voyageurs_cap, VoyageursServer::VoyageursServer(z_cap_t voyageurs_cap,

View File

@ -11,7 +11,7 @@ class VoyageursServer : public VoyageursServerBase {
static glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> Create( static glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> Create(
KeyboardDriver& keyboard_driver); KeyboardDriver& keyboard_driver);
virtual glcr::ErrorCode HandleRegisterKeyboardListener( virtual glcr::Status HandleRegisterKeyboardListener(
const KeyboardListener& listener) override; const KeyboardListener& listener) override;
private: private:

View File

@ -75,9 +75,9 @@ void YellowstoneServerBase::ServerThread() {
glcr::ErrorCode reply_err = glcr::OK; glcr::ErrorCode reply_err = glcr::OK;
resp_cap.Reset(); resp_cap.Reset();
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
if (err != glcr::OK) { if (!err) {
WriteError(resp_buffer, err); WriteError(resp_buffer, err.code());
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
} else { } else {
WriteHeader(resp_buffer, resp_length); WriteHeader(resp_buffer, resp_length);
@ -90,12 +90,12 @@ void YellowstoneServerBase::ServerThread() {
} }
glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request, glcr::Status YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request,
const glcr::CapBuffer& req_caps, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps) { glcr::CapBuffer& resp_caps) {
if (request.At<uint32_t>(0) != kSentinel) { 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); uint64_t method_select = request.At<uint64_t>(8);
@ -106,16 +106,13 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
RegisterEndpointRequest yunq_request; RegisterEndpointRequest yunq_request;
// TODO: Return status. // TODO: Return status.
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
if (!status) {
return status.code();
}
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; GetEndpointRequest yunq_request;
// TODO: Return status. // TODO: Return status.
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
if (!status) {
return status.code();
}
@ -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; break;
} }
default: { default: {
return glcr::UNIMPLEMENTED; return glcr::Unimplemented("Method unimplemented by server.");
} }
} }
return glcr::OK; return glcr::Status::Ok();
} }

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <glacier/status/status.h>
#include <mammoth/proc/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.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*); friend void YellowstoneServerBaseThreadBootstrap(void*);
void ServerThread(); void ServerThread();
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps, [[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps); glcr::CapBuffer& resp_caps);
}; };

View File

@ -42,13 +42,13 @@ glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap) YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
: YellowstoneServerBase(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_ahci_region(pci_reader_.GetAhciVmmo());
info.set_region_length(kPcieConfigurationSize); info.set_region_length(kPcieConfigurationSize);
return glcr::OK; return glcr::Status::Ok();
} }
glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo( glcr::Status YellowstoneServer::HandleGetFramebufferInfo(
FramebufferInfo& info) { FramebufferInfo& info) {
// FIXME: Don't do this for each request. // FIXME: Don't do this for each request.
mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion region =
@ -68,22 +68,22 @@ glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
info.set_blue_mask_size(fb->blue_mask_size); info.set_blue_mask_size(fb->blue_mask_size);
info.set_blue_mask_shift(fb->blue_mask_shift); 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")) { if (!endpoint_map_.Contains("denali")) {
return glcr::NOT_FOUND; return glcr::NotFound("Denali Capability Not registered");
} }
z_cap_t new_denali; z_cap_t new_denali;
check(ZCapDuplicate(endpoint_map_.at("denali"), kZionPerm_All, &new_denali)); check(ZCapDuplicate(endpoint_map_.at("denali"), kZionPerm_All, &new_denali));
info.set_denali_endpoint(new_denali); info.set_denali_endpoint(new_denali);
info.set_device_id(device_id_); info.set_device_id(device_id_);
info.set_lba_offset(lba_offset_); info.set_lba_offset(lba_offset_);
return glcr::OK; return glcr::Status::Ok();
} }
glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint( glcr::Status YellowstoneServer::HandleRegisterEndpoint(
const RegisterEndpointRequest& req) { const RegisterEndpointRequest& req) {
dbgln("Registering {}.", req.endpoint_name().view()); dbgln("Registering {}.", req.endpoint_name().view());
check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability())); check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability()));
@ -106,19 +106,20 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
} else { } else {
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr()); dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
} }
return glcr::OK; return glcr::Status::Ok();
} }
glcr::ErrorCode YellowstoneServer::HandleGetEndpoint( glcr::Status YellowstoneServer::HandleGetEndpoint(const GetEndpointRequest& req,
const GetEndpointRequest& req, Endpoint& resp) { Endpoint& resp) {
if (!endpoint_map_.Contains(req.endpoint_name())) { 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 cap = endpoint_map_.at(req.endpoint_name());
z_cap_t new_cap; z_cap_t new_cap;
check(ZCapDuplicate(cap, kZionPerm_All, &new_cap)); check(ZCapDuplicate(cap, kZionPerm_All, &new_cap));
resp.set_endpoint(new_cap); resp.set_endpoint(new_cap);
return glcr::OK; return glcr::Status::Ok();
} }
void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); } void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }

View File

@ -16,13 +16,11 @@ class YellowstoneServer : public YellowstoneServerBase {
public: public:
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create(); static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
glcr::ErrorCode HandleGetAhciInfo(AhciInfo&) override; glcr::Status HandleGetAhciInfo(AhciInfo&) override;
glcr::ErrorCode HandleGetFramebufferInfo(FramebufferInfo&) override; glcr::Status HandleGetFramebufferInfo(FramebufferInfo&) override;
glcr::ErrorCode HandleGetDenali(DenaliInfo&) override; glcr::Status HandleGetDenali(DenaliInfo&) override;
glcr::ErrorCode HandleRegisterEndpoint( glcr::Status HandleRegisterEndpoint(const RegisterEndpointRequest&) override;
const RegisterEndpointRequest&) override; glcr::Status HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) override;
glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&,
Endpoint&) override;
void WaitDenaliRegistered(); void WaitDenaliRegistered();
void WaitVictoriaFallsRegistered(); void WaitVictoriaFallsRegistered();

View File

@ -75,9 +75,10 @@ void {{interface.name}}ServerBase::ServerThread() {
glcr::ErrorCode reply_err = glcr::OK; glcr::ErrorCode reply_err = glcr::OK;
resp_cap.Reset(); resp_cap.Reset();
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
if (err != glcr::OK) { if (!err) {
WriteError(resp_buffer, err); WriteError(resp_buffer, err.code());
dbgln("Responding Error {}", err.message());
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
} else { } else {
WriteHeader(resp_buffer, resp_length); WriteHeader(resp_buffer, resp_length);
@ -90,12 +91,12 @@ void {{interface.name}}ServerBase::ServerThread() {
} }
glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuffer& request, glcr::Status {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuffer& request,
const glcr::CapBuffer& req_caps, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps) { glcr::CapBuffer& resp_caps) {
if (request.At<uint32_t>(0) != kSentinel) { 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); uint64_t method_select = request.At<uint64_t>(8);
@ -106,11 +107,7 @@ glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuff
{% if method.request != None %} {% if method.request != None %}
{{method.request}} yunq_request; {{method.request}} yunq_request;
// TODO: Return status. RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
auto status = yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
if (!status) {
return status.code();
}
{% endif %} {% endif %}
{% if method.response != None %} {% if method.response != None %}
@ -118,11 +115,11 @@ glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuff
{% endif %} {% endif %}
{% if method.request == None %} {% if method.request == None %}
RET_ERR(Handle{{method.name}}(yunq_response)); RETURN_ERROR(Handle{{method.name}}(yunq_response));
{% elif method.response == None %} {% elif method.response == None %}
RET_ERR(Handle{{method.name}}(yunq_request)); RETURN_ERROR(Handle{{method.name}}(yunq_request));
{% else %} {% else %}
RET_ERR(Handle{{method.name}}(yunq_request, yunq_response)); RETURN_ERROR(Handle{{method.name}}(yunq_request, yunq_response));
{% endif %} {% endif %}
{% if method.response != None %} {% if method.response != None %}
@ -134,10 +131,10 @@ glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuff
} }
{%- endfor %} {%- endfor %}
default: { default: {
return glcr::UNIMPLEMENTED; return glcr::Unimplemented("Method unimplemented by server.");
} }
} }
return glcr::OK; return glcr::Status::Ok();
} }
{% endfor %} {% endfor %}

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <glacier/status/status.h>
#include <mammoth/proc/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
@ -28,11 +29,11 @@ class {{interface.name}}ServerBase {
{% for method in interface.methods %} {% for method in interface.methods %}
{% if method.request == None %} {% if method.request == None %}
[[nodiscard]] virtual glcr::ErrorCode Handle{{method.name}}({{method.response}}&) = 0; [[nodiscard]] virtual glcr::Status Handle{{method.name}}({{method.response}}&) = 0;
{% elif method.response == None %} {% elif method.response == None %}
[[nodiscard]] virtual glcr::ErrorCode Handle{{method.name}}(const {{method.request}}&) = 0; [[nodiscard]] virtual glcr::Status Handle{{method.name}}(const {{method.request}}&) = 0;
{% else %} {% else %}
[[nodiscard]] virtual glcr::ErrorCode Handle{{method.name}}(const {{method.request}}&, {{method.response}}&) = 0; [[nodiscard]] virtual glcr::Status Handle{{method.name}}(const {{method.request}}&, {{method.response}}&) = 0;
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -42,9 +43,9 @@ class {{interface.name}}ServerBase {
friend void {{interface.name}}ServerBaseThreadBootstrap(void*); friend void {{interface.name}}ServerBaseThreadBootstrap(void*);
void ServerThread(); void ServerThread();
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps, [[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps); glcr::CapBuffer& resp_caps);
}; };
{% endfor %} {% endfor %}