[Voyageurs] Use yunq native empty response for service.

This commit is contained in:
Drew Galbraith 2023-11-27 08:08:03 -08:00
parent b95c736825
commit 43d7bfa7ad
10 changed files with 28 additions and 67 deletions

View File

@ -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() {

View File

@ -1,12 +1,8 @@
interface Voyageurs {
method RegisterKeyboardListener(KeyboardListener) -> (None);
method RegisterKeyboardListener(KeyboardListener) -> ();
}
message KeyboardListener {
capability port_capability;
}
message None {
}

View File

@ -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<uint64_t>(8, 0);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
buffer_.WriteAt<uint32_t>(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<uint64_t>(8));
response.ParseFromBytes(buffer_, 16, cap_buffer_);
return glcr::OK;
}

View File

@ -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_;

View File

@ -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;
}

View File

@ -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);
};

View File

@ -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: {

View File

@ -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:

View File

@ -9,7 +9,7 @@ glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> VoyageursServer::Create(
}
glcr::ErrorCode VoyageursServer::HandleRegisterKeyboardListener(
const KeyboardListener& listener, None&) {
const KeyboardListener& listener) {
keyboard_driver_.RegisterListener(listener.port_capability());
return glcr::OK;
}

View File

@ -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_;