2023-06-21 21:26:24 -07:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-26 11:38:17 -07:00
|
|
|
#include <glacier/memory/unique_ptr.h>
|
2023-06-21 21:26:24 -07:00
|
|
|
#include <glacier/status/error_or.h>
|
|
|
|
#include <ztypes.h>
|
|
|
|
|
2023-11-22 13:41:14 -08:00
|
|
|
#include "mammoth/ipc/endpoint_client.h"
|
2023-11-22 13:56:40 -08:00
|
|
|
#include "mammoth/ipc/request_context.h"
|
|
|
|
#include "mammoth/ipc/response_context.h"
|
2023-11-22 14:10:10 -08:00
|
|
|
#include "mammoth/proc/thread.h"
|
2023-06-21 21:26:24 -07:00
|
|
|
|
2023-11-22 14:59:41 -08:00
|
|
|
namespace mmth {
|
2023-06-21 21:26:24 -07:00
|
|
|
class EndpointServer {
|
|
|
|
public:
|
2023-06-26 11:38:17 -07:00
|
|
|
EndpointServer() = delete;
|
|
|
|
EndpointServer(const EndpointServer&) = delete;
|
|
|
|
EndpointServer& operator=(const EndpointServer&) = delete;
|
|
|
|
|
2023-06-26 11:54:36 -07:00
|
|
|
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> CreateClient();
|
2023-06-21 21:26:24 -07:00
|
|
|
|
2023-08-01 16:08:34 -07:00
|
|
|
Thread RunServer();
|
2023-08-01 15:52:08 -07:00
|
|
|
|
|
|
|
virtual glcr::ErrorCode HandleRequest(RequestContext& request,
|
|
|
|
ResponseContext& response) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EndpointServer(z_cap_t cap) : endpoint_cap_(cap) {}
|
|
|
|
|
2023-06-21 21:26:24 -07:00
|
|
|
private:
|
|
|
|
z_cap_t endpoint_cap_;
|
|
|
|
|
2023-08-01 15:52:08 -07:00
|
|
|
static const uint64_t kBufferSize = 1024;
|
|
|
|
uint8_t recieve_buffer_[kBufferSize];
|
2023-08-01 16:08:34 -07:00
|
|
|
|
|
|
|
friend void EndpointServerThreadBootstrap(void* endpoint_server);
|
|
|
|
void ServerThread();
|
2023-06-21 21:26:24 -07:00
|
|
|
};
|
2023-11-22 14:59:41 -08:00
|
|
|
|
|
|
|
} // namespace mmth
|