Generalize the EndpointServer to require less boilerplate.
Classes can now inherit from the EndpointServer and just implement the HandleRequest function.
This commit is contained in:
parent
847d37addc
commit
caccb08e16
14 changed files with 215 additions and 147 deletions
|
|
@ -1,14 +1,6 @@
|
|||
#include "mammoth/endpoint_server.h"
|
||||
|
||||
glcr::ErrorOr<glcr::UniquePtr<EndpointServer>> EndpointServer::Create() {
|
||||
uint64_t cap;
|
||||
RET_ERR(ZEndpointCreate(&cap));
|
||||
return glcr::UniquePtr<EndpointServer>(new EndpointServer(cap));
|
||||
}
|
||||
|
||||
glcr::UniquePtr<EndpointServer> EndpointServer::Adopt(z_cap_t endpoint_cap) {
|
||||
return glcr::UniquePtr<EndpointServer>(new EndpointServer(endpoint_cap));
|
||||
}
|
||||
#include "mammoth/debug.h"
|
||||
|
||||
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> EndpointServer::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
|
|
@ -17,7 +9,24 @@ glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> EndpointServer::CreateClient() {
|
|||
return EndpointClient::AdoptEndpoint(client_cap);
|
||||
}
|
||||
|
||||
glcr::ErrorCode EndpointServer::Recieve(uint64_t* num_bytes, void* data,
|
||||
glcr::ErrorCode EndpointServer::Receive(uint64_t* num_bytes, void* data,
|
||||
z_cap_t* reply_port_cap) {
|
||||
return ZEndpointRecv(endpoint_cap_, num_bytes, data, reply_port_cap);
|
||||
}
|
||||
|
||||
glcr::ErrorCode EndpointServer::RunServer() {
|
||||
while (true) {
|
||||
uint64_t message_size = kBufferSize;
|
||||
uint64_t reply_port_cap = 0;
|
||||
RET_ERR(Receive(&message_size, recieve_buffer_, &reply_port_cap));
|
||||
|
||||
RequestContext request(recieve_buffer_, message_size);
|
||||
ResponseContext response(reply_port_cap);
|
||||
// FIXME: Consider pumping these errors into the response as well.
|
||||
RET_ERR(HandleRequest(request, response));
|
||||
if (!response.HasWritten()) {
|
||||
dbgln("Returning without having written a response. Req type %x",
|
||||
request.request_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue