From 43d7bfa7adabade46bd7a7923d11ad4f9aff9141 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Mon, 27 Nov 2023 08:08:03 -0800 Subject: [PATCH] [Voyageurs] Use yunq native empty response for service. --- lib/mammoth/input/keyboard.cpp | 3 +- sys/voyageurs/lib/voyageurs/voyageurs.yunq | 6 +--- .../lib/voyageurs/voyageurs.yunq.client.cpp | 9 +++-- .../lib/voyageurs/voyageurs.yunq.client.h | 4 ++- .../lib/voyageurs/voyageurs.yunq.cpp | 33 ------------------- sys/voyageurs/lib/voyageurs/voyageurs.yunq.h | 17 ---------- .../lib/voyageurs/voyageurs.yunq.server.cpp | 15 ++++++--- .../lib/voyageurs/voyageurs.yunq.server.h | 4 ++- sys/voyageurs/voyageurs_server.cpp | 2 +- sys/voyageurs/voyageurs_server.h | 2 +- 10 files changed, 28 insertions(+), 67 deletions(-) diff --git a/lib/mammoth/input/keyboard.cpp b/lib/mammoth/input/keyboard.cpp index aa7303d..377cc22 100644 --- a/lib/mammoth/input/keyboard.cpp +++ b/lib/mammoth/input/keyboard.cpp @@ -40,8 +40,7 @@ void KeyboardListenerBase::Register() { crash("Failed to create client", client_or.error()); } listn.set_port_capability(client_or.value().cap()); - None n; - check(vclient.RegisterKeyboardListener(listn, n)); + check(vclient.RegisterKeyboardListener(listn)); } Thread KeyboardListenerBase::Listen() { diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq b/sys/voyageurs/lib/voyageurs/voyageurs.yunq index 4d59744..a0064b0 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq @@ -1,12 +1,8 @@ interface Voyageurs { - method RegisterKeyboardListener(KeyboardListener) -> (None); + method RegisterKeyboardListener(KeyboardListener) -> (); } message KeyboardListener { capability port_capability; } -message None { - -} - diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.client.cpp b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.client.cpp index 80703fd..65f4d26 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.client.cpp +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.client.cpp @@ -8,7 +8,9 @@ -glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener& request, None& response) { + +glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener& request) { + uint64_t buffer_size = kBufferSize; uint64_t cap_size = kCapBufferSize; @@ -17,7 +19,10 @@ glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener buffer_.WriteAt(8, 0); cap_buffer_.Reset(); + uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); + + buffer_.WriteAt(4, 16 + length); z_cap_t reply_port_cap; @@ -33,7 +38,7 @@ glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener // Check Response Code. RET_ERR(buffer_.At(8)); - response.ParseFromBytes(buffer_, 16, cap_buffer_); + return glcr::OK; } diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.client.h b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.client.h index 2fea9ba..ecf97fe 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.client.h +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.client.h @@ -17,7 +17,9 @@ class VoyageursClient { z_cap_t Capability() { return endpoint_; } - [[nodiscard]] glcr::ErrorCode RegisterKeyboardListener(const KeyboardListener& request, None& response); + + [[nodiscard]] glcr::ErrorCode RegisterKeyboardListener(const KeyboardListener& request); + private: z_cap_t endpoint_; diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp index 22394d7..050800a 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.cpp @@ -73,38 +73,5 @@ uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of // The next extension pointer is the length of the message. WriteHeader(bytes, offset, core_size, next_extension); - return next_extension; -} -void None::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { - ParseFromBytesInternal(bytes, offset); -} - -void None::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { - ParseFromBytesInternal(bytes, offset); -} - -void None::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { - CheckHeader(bytes); - -} - -uint64_t None::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { - uint32_t next_extension = header_size + 8 * 0; - const uint32_t core_size = next_extension; - - // The next extension pointer is the length of the message. - WriteHeader(bytes, offset, core_size, next_extension); - - return next_extension; -} - -uint64_t None::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { - uint32_t next_extension = header_size + 8 * 0; - const uint32_t core_size = next_extension; - uint64_t next_cap = 0; - - // The next extension pointer is the length of the message. - WriteHeader(bytes, offset, core_size, next_extension); - return next_extension; } \ No newline at end of file diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.h b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.h index 4961d5e..a182d8e 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.h +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.h @@ -23,23 +23,6 @@ class KeyboardListener { private: z_cap_t port_capability_; - // Parses everything except for caps. - void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); -}; -class None { - public: - None() {} - // Delete copy and move until implemented. - None(const None&) = delete; - None(None&&) = delete; - - void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset); - void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); - uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; - uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - - private: - // Parses everything except for caps. void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); }; \ No newline at end of file diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.server.cpp b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.server.cpp index f21e594..e0095c9 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.server.cpp +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.server.cpp @@ -87,14 +87,21 @@ glcr::ErrorCode VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& reque switch(method_select) { case 0: { + + KeyboardListener yunq_request; - None yunq_response; - yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); + - RET_ERR(HandleRegisterKeyboardListener(yunq_request, yunq_response)); + - resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps); + + RET_ERR(HandleRegisterKeyboardListener(yunq_request)); + + + + resp_length = 0; + break; } default: { diff --git a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.server.h b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.server.h index 7781c61..9921534 100644 --- a/sys/voyageurs/lib/voyageurs/voyageurs.yunq.server.h +++ b/sys/voyageurs/lib/voyageurs/voyageurs.yunq.server.h @@ -21,7 +21,9 @@ class VoyageursServerBase { [[nodiscard]] Thread RunServer(); - [[nodiscard]] virtual glcr::ErrorCode HandleRegisterKeyboardListener(const KeyboardListener&, None&) = 0; + + [[nodiscard]] virtual glcr::ErrorCode HandleRegisterKeyboardListener(const KeyboardListener&) = 0; + private: diff --git a/sys/voyageurs/voyageurs_server.cpp b/sys/voyageurs/voyageurs_server.cpp index 93f31d7..1404479 100644 --- a/sys/voyageurs/voyageurs_server.cpp +++ b/sys/voyageurs/voyageurs_server.cpp @@ -9,7 +9,7 @@ glcr::ErrorOr> VoyageursServer::Create( } glcr::ErrorCode VoyageursServer::HandleRegisterKeyboardListener( - const KeyboardListener& listener, None&) { + const KeyboardListener& listener) { keyboard_driver_.RegisterListener(listener.port_capability()); return glcr::OK; } diff --git a/sys/voyageurs/voyageurs_server.h b/sys/voyageurs/voyageurs_server.h index d95a272..d597093 100644 --- a/sys/voyageurs/voyageurs_server.h +++ b/sys/voyageurs/voyageurs_server.h @@ -12,7 +12,7 @@ class VoyageursServer : public VoyageursServerBase { KeyboardDriver& keyboard_driver); virtual glcr::ErrorCode HandleRegisterKeyboardListener( - const KeyboardListener& listener, None&) override; + const KeyboardListener& listener) override; private: KeyboardDriver& keyboard_driver_;