2023-06-26 08:59:28 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <glacier/status/error_or.h>
|
|
|
|
#include <glacier/string/string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <zcall.h>
|
|
|
|
|
2023-11-22 14:59:41 -08:00
|
|
|
namespace mmth {
|
|
|
|
|
2023-06-26 08:59:28 -07:00
|
|
|
class PortClient {
|
|
|
|
public:
|
2023-07-05 15:01:29 -07:00
|
|
|
PortClient() {}
|
2023-06-26 08:59:28 -07:00
|
|
|
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_; }
|
|
|
|
|
2023-07-05 15:01:29 -07:00
|
|
|
bool empty() { return port_cap_ == 0; }
|
|
|
|
|
2023-06-26 08:59:28 -07:00
|
|
|
private:
|
2023-07-05 15:01:29 -07:00
|
|
|
z_cap_t port_cap_ = 0;
|
2023-06-26 08:59:28 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2023-11-22 14:59:41 -08:00
|
|
|
|
|
|
|
} // namespace mmth
|