[mammoth] Move port server operations to their own class.
This commit is contained in:
parent
7989c9d616
commit
5fb9fa6ae6
8 changed files with 74 additions and 42 deletions
45
lib/mammoth/src/port_server.cpp
Normal file
45
lib/mammoth/src/port_server.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#include "mammoth/port_server.h"
|
||||
|
||||
#include <zcall.h>
|
||||
|
||||
glcr::ErrorOr<PortServer> PortServer::Create() {
|
||||
z_cap_t port;
|
||||
RET_ERR(ZPortCreate(&port));
|
||||
return PortServer(port);
|
||||
}
|
||||
|
||||
PortServer PortServer::AdoptCap(z_cap_t cap) { return PortServer(cap); }
|
||||
|
||||
PortServer::PortServer(z_cap_t port_cap) : port_cap_(port_cap) {}
|
||||
|
||||
glcr::ErrorCode PortServer::CreateClient(z_cap_t *new_port) {
|
||||
// FIXME: Restrict permissions.
|
||||
return ZCapDuplicate(port_cap_, new_port);
|
||||
}
|
||||
|
||||
glcr::ErrorCode PortServer::RecvCap(uint64_t *num_bytes, char *msg,
|
||||
uint64_t *cap) {
|
||||
uint64_t caps = 1;
|
||||
RET_ERR(ZPortRecv(port_cap_, num_bytes, reinterpret_cast<uint8_t *>(msg),
|
||||
&caps, cap));
|
||||
|
||||
if (caps != 1) {
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t PortServer::PollForIntCap(uint64_t *msg, uint64_t *cap) {
|
||||
uint64_t bytes = sizeof(uint64_t);
|
||||
uint64_t caps = 1;
|
||||
RET_ERR(ZPortPoll(port_cap_, &bytes, reinterpret_cast<uint8_t *>(msg), &caps,
|
||||
cap));
|
||||
|
||||
if (bytes != sizeof(uint64_t)) {
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
}
|
||||
if (caps != 1) {
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue