[Voyageurs] Add a basic ps/2 keyboard driver.
This commit is contained in:
parent
7151a509ee
commit
8365d47cbe
|
@ -15,4 +15,8 @@ glcr::ErrorCode PortClient::WriteString(glcr::String str, z_cap_t cap) {
|
||||||
ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap));
|
ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glcr::ErrorCode PortClient::WriteByte(uint8_t byte) {
|
||||||
|
return static_cast<glcr::ErrorCode>(
|
||||||
|
ZPortSend(port_cap_, 1, &byte, 0, nullptr));
|
||||||
|
}
|
||||||
} // namespace mmth
|
} // namespace mmth
|
||||||
|
|
|
@ -17,6 +17,8 @@ class PortClient {
|
||||||
|
|
||||||
glcr::ErrorCode WriteString(glcr::String str, z_cap_t cap);
|
glcr::ErrorCode WriteString(glcr::String str, z_cap_t cap);
|
||||||
|
|
||||||
|
glcr::ErrorCode WriteByte(uint8_t byte);
|
||||||
|
|
||||||
z_cap_t cap() { return port_cap_; }
|
z_cap_t cap() { return port_cap_; }
|
||||||
|
|
||||||
bool empty() { return port_cap_ == 0; }
|
bool empty() { return port_cap_ == 0; }
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace mmth {
|
||||||
|
|
||||||
class PortServer {
|
class PortServer {
|
||||||
public:
|
public:
|
||||||
|
PortServer() {}
|
||||||
static glcr::ErrorOr<PortServer> Create();
|
static glcr::ErrorOr<PortServer> Create();
|
||||||
static PortServer AdoptCap(z_cap_t cap);
|
static PortServer AdoptCap(z_cap_t cap);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
||||||
add_subdirectory(denali)
|
add_subdirectory(denali)
|
||||||
add_subdirectory(teton)
|
add_subdirectory(teton)
|
||||||
add_subdirectory(victoriafalls)
|
add_subdirectory(victoriafalls)
|
||||||
|
add_subdirectory(voyageurs)
|
||||||
add_subdirectory(yellowstone)
|
add_subdirectory(yellowstone)
|
||||||
|
|
||||||
set(SYS_BUNDLE
|
set(SYS_BUNDLE
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
add_executable(voyageurs
|
||||||
|
keyboard/keyboard_driver.cpp
|
||||||
|
voyageurs_server.cpp
|
||||||
|
voyageurs.cpp)
|
||||||
|
|
||||||
|
target_include_directories(voyageurs
|
||||||
|
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
target_link_libraries(voyageurs
|
||||||
|
glacier
|
||||||
|
mammoth
|
||||||
|
voyageurs_yunq
|
||||||
|
yellowstone_yunq
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(voyageurs PROPERTIES
|
||||||
|
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
||||||
|
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS voyageurs)
|
||||||
|
|
||||||
|
yunq_gen(lib/voyageurs lib voyageurs)
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include "keyboard/keyboard_driver.h"
|
||||||
|
|
||||||
|
#include <mammoth/util/debug.h>
|
||||||
|
|
||||||
|
void InterruptEnter(void* void_keyboard) {
|
||||||
|
KeyboardDriver* keyboard = static_cast<KeyboardDriver*>(void_keyboard);
|
||||||
|
|
||||||
|
keyboard->InterruptLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyboardDriver::KeyboardDriver() { check(ZIrqRegister(kZIrqKbd, &irq_cap_)); }
|
||||||
|
|
||||||
|
void KeyboardDriver::RegisterListener(uint64_t port_cap) {
|
||||||
|
listeners_.PushFront(mmth::PortClient::AdoptPort(port_cap));
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread KeyboardDriver::StartInterruptLoop() {
|
||||||
|
return Thread(InterruptEnter, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardDriver::InterruptLoop() {
|
||||||
|
dbgln("Interrupt");
|
||||||
|
while (true) {
|
||||||
|
uint8_t scancode;
|
||||||
|
uint64_t num_bytes = 1;
|
||||||
|
uint64_t num_caps = 0;
|
||||||
|
check(ZPortRecv(irq_cap_, &num_bytes, &scancode, &num_caps, nullptr));
|
||||||
|
dbgln("Scan {x}", scancode);
|
||||||
|
|
||||||
|
for (mmth::PortClient& client : listeners_) {
|
||||||
|
client.WriteByte(scancode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glacier/container/linked_list.h>
|
||||||
|
#include <mammoth/ipc/port_client.h>
|
||||||
|
#include <mammoth/ipc/port_server.h>
|
||||||
|
#include <mammoth/proc/thread.h>
|
||||||
|
|
||||||
|
class KeyboardDriver {
|
||||||
|
public:
|
||||||
|
KeyboardDriver();
|
||||||
|
KeyboardDriver(const KeyboardDriver&) = delete;
|
||||||
|
KeyboardDriver(KeyboardDriver&&) = delete;
|
||||||
|
|
||||||
|
void RegisterListener(uint64_t port_cap);
|
||||||
|
|
||||||
|
Thread StartInterruptLoop();
|
||||||
|
void InterruptLoop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
z_cap_t irq_cap_;
|
||||||
|
glcr::LinkedList<mmth::PortClient> listeners_;
|
||||||
|
};
|
|
@ -0,0 +1,12 @@
|
||||||
|
interface Voyageurs {
|
||||||
|
method RegisterKeyboardListener(KeyboardListener) -> (None);
|
||||||
|
}
|
||||||
|
|
||||||
|
message KeyboardListener {
|
||||||
|
capability port_capability;
|
||||||
|
}
|
||||||
|
|
||||||
|
message None {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Generated file - DO NOT MODIFY
|
||||||
|
#include "voyageurs.yunq.client.h"
|
||||||
|
|
||||||
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
|
#include <zcall.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener& request, None& response) {
|
||||||
|
uint64_t buffer_size = kBufferSize;
|
||||||
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
|
||||||
|
const uint32_t kSentinel = 0xBEEFDEAD;
|
||||||
|
buffer_.WriteAt<uint32_t>(0, kSentinel);
|
||||||
|
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;
|
||||||
|
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap));
|
||||||
|
|
||||||
|
// FIXME: Add a way to zero out the first buffer.
|
||||||
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
|
return glcr::INVALID_RESPONSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check Response Code.
|
||||||
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||||
|
|
||||||
|
return glcr::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Generated file - DO NOT MODIFY
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
|
#include <glacier/status/error.h>
|
||||||
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
#include "voyageurs.yunq.h"
|
||||||
|
|
||||||
|
class VoyageursClient {
|
||||||
|
public:
|
||||||
|
VoyageursClient(z_cap_t Voyageurs_cap) : endpoint_(Voyageurs_cap) {}
|
||||||
|
VoyageursClient(const VoyageursClient&) = delete;
|
||||||
|
VoyageursClient(VoyageursClient&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
|
||||||
|
|
||||||
|
z_cap_t Capability() { return endpoint_; }
|
||||||
|
|
||||||
|
|
||||||
|
[[nodiscard]] glcr::ErrorCode RegisterKeyboardListener(const KeyboardListener& request, None& response);
|
||||||
|
|
||||||
|
private:
|
||||||
|
z_cap_t endpoint_;
|
||||||
|
uint64_t kBufferSize = 0x1000;
|
||||||
|
glcr::ByteBuffer buffer_{kBufferSize};
|
||||||
|
uint64_t kCapBufferSize = 0x10;
|
||||||
|
glcr::CapBuffer cap_buffer_{kCapBufferSize};
|
||||||
|
};
|
|
@ -0,0 +1,110 @@
|
||||||
|
// Generated file -- DO NOT MODIFY.
|
||||||
|
#include "voyageurs.yunq.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const uint64_t header_size = 24; // 4x uint32, 1x uint64
|
||||||
|
|
||||||
|
struct ExtPointer {
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
void CheckHeader(const glcr::ByteBuffer& bytes) {
|
||||||
|
// TODO: Check ident.
|
||||||
|
// TODO: Parse core size.
|
||||||
|
// TODO: Parse extension size.
|
||||||
|
// TODO: Check CRC32
|
||||||
|
// TODO: Parse options.
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) {
|
||||||
|
bytes.WriteAt<uint32_t>(offset + 0, 0xDEADBEEF); // TODO: Chose a more unique ident sequence.
|
||||||
|
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
||||||
|
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
||||||
|
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
||||||
|
bytes.WriteAt<uint64_t>(offset + 16, 0); // TODO: Add options.
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
void KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
|
ParseFromBytesInternal(bytes, offset);
|
||||||
|
// Parse port_capability.
|
||||||
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
|
set_port_capability(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
|
ParseFromBytesInternal(bytes, offset);
|
||||||
|
// Parse port_capability.
|
||||||
|
uint64_t port_capability_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
|
set_port_capability(caps.At(port_capability_ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardListener::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
|
CheckHeader(bytes);
|
||||||
|
// Parse port_capability.
|
||||||
|
// Skip Cap.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
uint32_t next_extension = header_size + 8 * 1;
|
||||||
|
const uint32_t core_size = next_extension;
|
||||||
|
// Write port_capability.
|
||||||
|
// FIXME: Implement inbuffer capabilities.
|
||||||
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
||||||
|
|
||||||
|
// The next extension pointer is the length of the message.
|
||||||
|
WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
|
return next_extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||||
|
uint32_t next_extension = header_size + 8 * 1;
|
||||||
|
const uint32_t core_size = next_extension;
|
||||||
|
uint64_t next_cap = 0;
|
||||||
|
// Write port_capability.
|
||||||
|
caps.WriteAt(next_cap, port_capability());
|
||||||
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Generated file - DO NOT MODIFY
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
|
#include <glacier/container/vector.h>
|
||||||
|
#include <glacier/string/string.h>
|
||||||
|
#include <ztypes.h>
|
||||||
|
class KeyboardListener {
|
||||||
|
public:
|
||||||
|
KeyboardListener() {}
|
||||||
|
// Delete copy and move until implemented.
|
||||||
|
KeyboardListener(const KeyboardListener&) = delete;
|
||||||
|
KeyboardListener(KeyboardListener&&) = 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;
|
||||||
|
const z_cap_t& port_capability() const { return port_capability_; }
|
||||||
|
void set_port_capability(const z_cap_t& value) { port_capability_ = value; }
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
// Generated file -- DO NOT MODIFY.
|
||||||
|
#include "voyageurs.yunq.server.h"
|
||||||
|
|
||||||
|
#include <mammoth/util/debug.h>
|
||||||
|
#include <zcall.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const uint32_t kSentinel = 0xBEEFDEAD;
|
||||||
|
const uint32_t kHeaderSize = 0x10;
|
||||||
|
|
||||||
|
void WriteError(glcr::ByteBuffer& buffer, glcr::ErrorCode err) {
|
||||||
|
buffer.WriteAt<uint32_t>(0, kSentinel);
|
||||||
|
buffer.WriteAt<uint32_t>(4, kHeaderSize);
|
||||||
|
buffer.WriteAt<uint64_t>(8, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteHeader(glcr::ByteBuffer& buffer, uint64_t message_length) {
|
||||||
|
buffer.WriteAt<uint32_t>(0, kSentinel);
|
||||||
|
buffer.WriteAt<uint32_t>(4, kHeaderSize + message_length);
|
||||||
|
buffer.WriteAt<uint64_t>(8, glcr::OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void VoyageursServerBaseThreadBootstrap(void* server_base) {
|
||||||
|
((VoyageursServerBase*)server_base)->ServerThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
glcr::ErrorOr<VoyageursClient> VoyageursServerBase::CreateClient() {
|
||||||
|
uint64_t client_cap;
|
||||||
|
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||||
|
return VoyageursClient(client_cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread VoyageursServerBase::RunServer() {
|
||||||
|
return Thread(VoyageursServerBaseThreadBootstrap, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoyageursServerBase::ServerThread() {
|
||||||
|
glcr::ByteBuffer recv_buffer(0x1000);
|
||||||
|
glcr::CapBuffer recv_cap(0x10);
|
||||||
|
glcr::ByteBuffer resp_buffer(0x1000);
|
||||||
|
glcr::CapBuffer resp_cap(0x10);
|
||||||
|
z_cap_t reply_port_cap;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
uint64_t recv_cap_size = 0x10;
|
||||||
|
uint64_t recv_buf_size = 0x1000;
|
||||||
|
recv_cap.Reset();
|
||||||
|
glcr::ErrorCode recv_err = static_cast<glcr::ErrorCode>(ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap));
|
||||||
|
if (recv_err != glcr::OK) {
|
||||||
|
dbgln("Error in receive: {x}", recv_err);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t resp_length = 0;
|
||||||
|
|
||||||
|
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);
|
||||||
|
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
||||||
|
} else {
|
||||||
|
WriteHeader(resp_buffer, resp_length);
|
||||||
|
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr()));
|
||||||
|
}
|
||||||
|
if (reply_err != glcr::OK) {
|
||||||
|
dbgln("Error in reply: {x}", reply_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
glcr::ErrorCode VoyageursServerBase::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t method_select = request.At<uint64_t>(8);
|
||||||
|
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return glcr::UNIMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return glcr::OK;
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Generated File -- DO NOT MODIFY.
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glacier/status/error_or.h>
|
||||||
|
#include <mammoth/proc/thread.h>
|
||||||
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
#include "voyageurs.yunq.h"
|
||||||
|
#include "voyageurs.yunq.client.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class VoyageursServerBase {
|
||||||
|
public:
|
||||||
|
VoyageursServerBase(z_cap_t Voyageurs_cap) : endpoint_(Voyageurs_cap) {}
|
||||||
|
VoyageursServerBase(const VoyageursServerBase&) = delete;
|
||||||
|
VoyageursServerBase(VoyageursServerBase&&) = delete;
|
||||||
|
|
||||||
|
glcr::ErrorOr<VoyageursClient> CreateClient();
|
||||||
|
|
||||||
|
[[nodiscard]] Thread RunServer();
|
||||||
|
|
||||||
|
|
||||||
|
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterKeyboardListener(const KeyboardListener&, None&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
z_cap_t endpoint_;
|
||||||
|
|
||||||
|
friend void VoyageursServerBaseThreadBootstrap(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);
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
#include <mammoth/util/debug.h>
|
||||||
|
#include <mammoth/util/init.h>
|
||||||
|
|
||||||
|
#include "keyboard/keyboard_driver.h"
|
||||||
|
#include "voyageurs_server.h"
|
||||||
|
|
||||||
|
uint64_t main(uint64_t init_port) {
|
||||||
|
ParseInitPort(init_port);
|
||||||
|
|
||||||
|
dbgln("Initializing PS/2 Driver.");
|
||||||
|
KeyboardDriver driver;
|
||||||
|
|
||||||
|
dbgln("Starting PS/2 Thread.");
|
||||||
|
Thread keyboard_thread = driver.StartInterruptLoop();
|
||||||
|
|
||||||
|
dbgln("Starting voyaguers server.");
|
||||||
|
ASSIGN_OR_RETURN(glcr::UniquePtr<VoyageursServer> server,
|
||||||
|
VoyageursServer::Create(driver));
|
||||||
|
|
||||||
|
Thread server_thread = server->RunServer();
|
||||||
|
|
||||||
|
check(server_thread.Join());
|
||||||
|
check(keyboard_thread.Join());
|
||||||
|
|
||||||
|
return glcr::OK;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "voyageurs_server.h"
|
||||||
|
|
||||||
|
glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> VoyageursServer::Create(
|
||||||
|
KeyboardDriver& keyboard_driver) {
|
||||||
|
z_cap_t cap;
|
||||||
|
RET_ERR(ZEndpointCreate(&cap));
|
||||||
|
return glcr::UniquePtr<VoyageursServer>(
|
||||||
|
new VoyageursServer(cap, keyboard_driver));
|
||||||
|
}
|
||||||
|
|
||||||
|
glcr::ErrorCode VoyageursServer::HandleRegisterKeyboardListener(
|
||||||
|
const KeyboardListener& listener, None&) {
|
||||||
|
keyboard_driver_.RegisterListener(listener.port_capability());
|
||||||
|
return glcr::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
VoyageursServer::VoyageursServer(z_cap_t voyageurs_cap,
|
||||||
|
KeyboardDriver& keyboard_driver)
|
||||||
|
: VoyageursServerBase(voyageurs_cap), keyboard_driver_(keyboard_driver) {}
|
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glacier/memory/unique_ptr.h>
|
||||||
|
#include <glacier/status/error_or.h>
|
||||||
|
|
||||||
|
#include "keyboard/keyboard_driver.h"
|
||||||
|
#include "voyageurs/voyageurs.yunq.server.h"
|
||||||
|
|
||||||
|
class VoyageursServer : public VoyageursServerBase {
|
||||||
|
public:
|
||||||
|
static glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> Create(
|
||||||
|
KeyboardDriver& keyboard_driver);
|
||||||
|
|
||||||
|
virtual glcr::ErrorCode HandleRegisterKeyboardListener(
|
||||||
|
const KeyboardListener& listener, None&) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
KeyboardDriver& keyboard_driver_;
|
||||||
|
VoyageursServer(z_cap_t voyageurs_cap, KeyboardDriver& keyboard_driver);
|
||||||
|
};
|
|
@ -1,2 +1,3 @@
|
||||||
|
voyageurs
|
||||||
teton
|
teton
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue