[mammoth] Finish separating PortServer and PortClient.
This commit is contained in:
parent
5fb9fa6ae6
commit
b7a962cc26
10 changed files with 66 additions and 60 deletions
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <glacier/string/string.h>
|
||||
#include <stdint.h>
|
||||
#include <zcall.h>
|
||||
|
||||
// FIXME: Split send and receive.
|
||||
class Port {
|
||||
public:
|
||||
static glcr::ErrorOr<Port> Create();
|
||||
Port(uint64_t port_cap);
|
||||
|
||||
template <typename T>
|
||||
z_err_t WriteMessage(const T& obj, uint64_t cap);
|
||||
|
||||
glcr::ErrorCode WriteString(glcr::String str, uint64_t cap);
|
||||
|
||||
private:
|
||||
uint64_t port_cap_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
z_err_t Port::WriteMessage(const T& obj, uint64_t cap) {
|
||||
return ZPortSend(port_cap_, sizeof(obj), &obj, 1, &cap);
|
||||
}
|
||||
28
lib/mammoth/include/mammoth/port_client.h
Normal file
28
lib/mammoth/include/mammoth/port_client.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <glacier/string/string.h>
|
||||
#include <stdint.h>
|
||||
#include <zcall.h>
|
||||
|
||||
class PortClient {
|
||||
public:
|
||||
static PortClient AdoptPort(z_cap_t port_cap);
|
||||
|
||||
template <typename T>
|
||||
z_err_t WriteMessage(const T& obj, z_cap_t cap);
|
||||
|
||||
glcr::ErrorCode WriteString(glcr::String str, z_cap_t cap);
|
||||
|
||||
z_cap_t cap() { return port_cap_; }
|
||||
|
||||
private:
|
||||
z_cap_t port_cap_;
|
||||
|
||||
PortClient(z_cap_t port_cap);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
z_err_t PortClient::WriteMessage(const T& obj, z_cap_t cap) {
|
||||
return ZPortSend(port_cap_, sizeof(obj), &obj, 1, &cap);
|
||||
}
|
||||
|
|
@ -3,16 +3,20 @@
|
|||
#include <glacier/status/error_or.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
#include "mammoth/port_client.h"
|
||||
|
||||
class PortServer {
|
||||
public:
|
||||
static glcr::ErrorOr<PortServer> Create();
|
||||
static PortServer AdoptCap(z_cap_t cap);
|
||||
|
||||
glcr::ErrorCode CreateClient(z_cap_t* new_port);
|
||||
glcr::ErrorOr<PortClient> CreateClient();
|
||||
|
||||
glcr::ErrorCode RecvCap(uint64_t* num_bytes, char* msg, uint64_t* cap);
|
||||
glcr::ErrorCode PollForIntCap(uint64_t* msg, uint64_t* cap);
|
||||
|
||||
z_cap_t cap() { return port_cap_; }
|
||||
|
||||
private:
|
||||
z_cap_t port_cap_;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue