[Yellowstone][Mammoth] Delete unused cpp code.
This commit is contained in:
parent
d58cbed0df
commit
c1db6cb11f
24 changed files with 0 additions and 1590 deletions
|
|
@ -1,60 +0,0 @@
|
|||
#include "ipc/channel.h"
|
||||
|
||||
#include <zcall.h>
|
||||
|
||||
#include "util/debug.h"
|
||||
|
||||
namespace mmth {
|
||||
namespace {
|
||||
|
||||
uint64_t strlen(const char* ptr) {
|
||||
uint64_t len = 0;
|
||||
while (*ptr != '\0') {
|
||||
len++;
|
||||
ptr++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Channel::adopt_cap(uint64_t id) {
|
||||
if (chan_cap_ != 0) {
|
||||
crash("Adopting over channel.", glcr::ALREADY_EXISTS);
|
||||
}
|
||||
chan_cap_ = id;
|
||||
}
|
||||
z_cap_t Channel::release_cap() {
|
||||
z_cap_t cap = chan_cap_;
|
||||
chan_cap_ = 0;
|
||||
return cap;
|
||||
}
|
||||
|
||||
z_cap_t Channel::cap() { return chan_cap_; }
|
||||
|
||||
z_err_t Channel::WriteStr(const char* msg) {
|
||||
if (!chan_cap_) {
|
||||
return glcr::NULL_PTR;
|
||||
}
|
||||
return ZChannelSend(chan_cap_, strlen(msg), msg, 0, nullptr);
|
||||
}
|
||||
|
||||
z_err_t Channel::ReadStr(char* buffer, uint64_t* size) {
|
||||
if (!chan_cap_) {
|
||||
return glcr::NULL_PTR;
|
||||
}
|
||||
uint64_t num_caps = 0;
|
||||
return ZChannelRecv(chan_cap_, size, reinterpret_cast<uint8_t*>(buffer),
|
||||
&num_caps, nullptr);
|
||||
}
|
||||
|
||||
z_err_t CreateChannels(Channel& c1, Channel& c2) {
|
||||
z_cap_t chan1, chan2;
|
||||
RET_ERR(ZChannelCreate(&chan1, &chan2));
|
||||
|
||||
c1.adopt_cap(chan1);
|
||||
c2.adopt_cap(chan2);
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
} // namespace mmth
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
#include <stdint.h>
|
||||
#include <zcall.h>
|
||||
|
||||
namespace mmth {
|
||||
|
||||
class Channel {
|
||||
public:
|
||||
Channel() {}
|
||||
void adopt_cap(uint64_t id);
|
||||
z_cap_t release_cap();
|
||||
z_cap_t cap();
|
||||
|
||||
z_err_t WriteStr(const char* msg);
|
||||
z_err_t ReadStr(char* buffer, uint64_t* size);
|
||||
|
||||
template <typename T>
|
||||
z_err_t WriteStruct(T*);
|
||||
|
||||
template <typename T>
|
||||
z_err_t ReadStructAndCap(T*, uint64_t*);
|
||||
|
||||
// FIXME: Close channel here.
|
||||
~Channel() {}
|
||||
|
||||
private:
|
||||
z_cap_t chan_cap_ = 0;
|
||||
};
|
||||
|
||||
uint64_t CreateChannels(Channel& c1, Channel& c2);
|
||||
|
||||
template <typename T>
|
||||
z_err_t Channel::WriteStruct(T* obj) {
|
||||
return ZChannelSend(chan_cap_, sizeof(T), obj, 0, nullptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
z_err_t Channel::ReadStructAndCap(T* obj, uint64_t* cap) {
|
||||
uint64_t num_bytes = sizeof(T);
|
||||
uint64_t num_caps = 1;
|
||||
RET_ERR(ZChannelRecv(chan_cap_, &num_bytes, obj, &num_caps, cap));
|
||||
|
||||
if (num_caps != 1 || num_bytes != sizeof(T)) {
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
} // namespace mmth
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#include "ipc/endpoint_server.h"
|
||||
|
||||
namespace mmth {
|
||||
|
||||
glcr::UniquePtr<EndpointClient> EndpointClient::AdoptEndpoint(z_cap_t cap) {
|
||||
return glcr::UniquePtr<EndpointClient>(new EndpointClient(cap));
|
||||
}
|
||||
|
||||
} // namespace mmth
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/container/pair.h>
|
||||
#include <glacier/memory/unique_ptr.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <zcall.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
namespace mmth {
|
||||
|
||||
class EndpointClient {
|
||||
public:
|
||||
EndpointClient() = delete;
|
||||
EndpointClient(const EndpointClient&) = delete;
|
||||
EndpointClient& operator=(const EndpointClient&) = delete;
|
||||
|
||||
static glcr::UniquePtr<EndpointClient> AdoptEndpoint(z_cap_t cap);
|
||||
|
||||
template <typename Req, typename Resp>
|
||||
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> CallEndpointGetCap(const Req& req);
|
||||
|
||||
template <typename Req, typename Resp>
|
||||
glcr::ErrorOr<Resp> CallEndpoint(const Req& req);
|
||||
|
||||
z_cap_t GetCap() const { return cap_; }
|
||||
|
||||
private:
|
||||
EndpointClient(uint64_t cap) : cap_(cap) {}
|
||||
z_cap_t cap_;
|
||||
};
|
||||
|
||||
template <typename Req, typename Resp>
|
||||
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> EndpointClient::CallEndpointGetCap(
|
||||
const Req& req) {
|
||||
uint64_t reply_port_cap;
|
||||
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, 0, nullptr, &reply_port_cap));
|
||||
|
||||
Resp resp;
|
||||
z_cap_t cap = 0;
|
||||
uint64_t num_caps = 1;
|
||||
uint64_t num_bytes = sizeof(Resp);
|
||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &num_bytes, &resp, &num_caps, &cap));
|
||||
|
||||
if (num_bytes != sizeof(resp) || num_caps != 1) {
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
}
|
||||
|
||||
return glcr::Pair{resp, cap};
|
||||
}
|
||||
|
||||
template <typename Req, typename Resp>
|
||||
glcr::ErrorOr<Resp> EndpointClient::CallEndpoint(const Req& req) {
|
||||
uint64_t reply_port_cap;
|
||||
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, 0, nullptr, &reply_port_cap));
|
||||
|
||||
Resp resp;
|
||||
uint64_t num_bytes = sizeof(Resp);
|
||||
uint64_t num_caps = 0;
|
||||
RET_ERR(
|
||||
ZReplyPortRecv(reply_port_cap, &num_bytes, &resp, &num_caps, nullptr));
|
||||
|
||||
if (num_bytes != sizeof(resp)) {
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
} // namespace mmth
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
#include "ipc/endpoint_server.h"
|
||||
|
||||
#include "util/debug.h"
|
||||
|
||||
namespace mmth {
|
||||
// Declared as friend in EndpointServer.
|
||||
void EndpointServerThreadBootstrap(void* endpoint_server) {
|
||||
reinterpret_cast<EndpointServer*>(endpoint_server)->ServerThread();
|
||||
}
|
||||
|
||||
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> EndpointServer::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_cap_, ~(kZionPerm_Read), &client_cap));
|
||||
return EndpointClient::AdoptEndpoint(client_cap);
|
||||
}
|
||||
|
||||
Thread EndpointServer::RunServer() {
|
||||
return Thread(EndpointServerThreadBootstrap, this);
|
||||
}
|
||||
|
||||
void EndpointServer::ServerThread() {
|
||||
while (true) {
|
||||
uint64_t message_size = kBufferSize;
|
||||
uint64_t reply_port_cap = 0;
|
||||
uint64_t num_caps = 0;
|
||||
glcr::ErrorCode err = static_cast<glcr::ErrorCode>(
|
||||
ZEndpointRecv(endpoint_cap_, &message_size, recieve_buffer_, &num_caps,
|
||||
nullptr, &reply_port_cap));
|
||||
if (err != glcr::OK) {
|
||||
dbgln("Error in receive: {x}", err);
|
||||
continue;
|
||||
}
|
||||
|
||||
RequestContext request(recieve_buffer_, message_size);
|
||||
ResponseContext response(reply_port_cap);
|
||||
// FIXME: Consider pumping these errors into the response as well.
|
||||
check(HandleRequest(request, response));
|
||||
if (!response.HasWritten()) {
|
||||
dbgln("Returning without having written a response. Req type {x}",
|
||||
request.request_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mmth
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/unique_ptr.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
#include "mammoth/ipc/endpoint_client.h"
|
||||
#include "mammoth/ipc/request_context.h"
|
||||
#include "mammoth/ipc/response_context.h"
|
||||
#include "mammoth/proc/thread.h"
|
||||
|
||||
namespace mmth {
|
||||
class EndpointServer {
|
||||
public:
|
||||
EndpointServer() = delete;
|
||||
EndpointServer(const EndpointServer&) = delete;
|
||||
EndpointServer& operator=(const EndpointServer&) = delete;
|
||||
|
||||
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> CreateClient();
|
||||
|
||||
Thread RunServer();
|
||||
|
||||
virtual glcr::ErrorCode HandleRequest(RequestContext& request,
|
||||
ResponseContext& response) = 0;
|
||||
|
||||
protected:
|
||||
EndpointServer(z_cap_t cap) : endpoint_cap_(cap) {}
|
||||
|
||||
private:
|
||||
z_cap_t endpoint_cap_;
|
||||
|
||||
static const uint64_t kBufferSize = 1024;
|
||||
uint8_t recieve_buffer_[kBufferSize];
|
||||
|
||||
friend void EndpointServerThreadBootstrap(void* endpoint_server);
|
||||
void ServerThread();
|
||||
};
|
||||
|
||||
} // namespace mmth
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
#include <stdint.h>
|
||||
|
||||
class RequestContext {
|
||||
public:
|
||||
RequestContext(void* buffer, uint64_t buffer_length)
|
||||
: buffer_(buffer), buffer_length_(buffer_length) {
|
||||
if (buffer_length_ < sizeof(uint64_t)) {
|
||||
request_id_ = -1;
|
||||
} else {
|
||||
request_id_ = *reinterpret_cast<uint64_t*>(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t request_id() { return request_id_; }
|
||||
|
||||
template <typename T>
|
||||
glcr::ErrorCode As(T** arg) {
|
||||
if (buffer_length_ < sizeof(T)) {
|
||||
return glcr::INVALID_ARGUMENT;
|
||||
}
|
||||
*arg = reinterpret_cast<T*>(buffer_);
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t request_id_;
|
||||
void* buffer_;
|
||||
uint64_t buffer_length_;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue