[mammoth] Update EndpointServer to have move-only semantics.
This commit is contained in:
parent
16c30d12fb
commit
2e89aee5a3
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/unique_ptr.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
|
@ -7,8 +8,12 @@
|
|||
|
||||
class EndpointServer {
|
||||
public:
|
||||
static glcr::ErrorOr<EndpointServer> Create();
|
||||
static EndpointServer Adopt(z_cap_t endpoint_cap);
|
||||
EndpointServer() = delete;
|
||||
EndpointServer(const EndpointServer&) = delete;
|
||||
EndpointServer& operator=(const EndpointServer&) = delete;
|
||||
|
||||
static glcr::ErrorOr<glcr::UniquePtr<EndpointServer>> Create();
|
||||
static glcr::UniquePtr<EndpointServer> Adopt(z_cap_t endpoint_cap);
|
||||
|
||||
glcr::ErrorOr<EndpointClient> CreateClient();
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "mammoth/endpoint_server.h"
|
||||
|
||||
glcr::ErrorOr<EndpointServer> EndpointServer::Create() {
|
||||
glcr::ErrorOr<glcr::UniquePtr<EndpointServer>> EndpointServer::Create() {
|
||||
uint64_t cap;
|
||||
RET_ERR(ZEndpointCreate(&cap));
|
||||
return EndpointServer(cap);
|
||||
return glcr::UniquePtr<EndpointServer>(new EndpointServer(cap));
|
||||
}
|
||||
|
||||
EndpointServer EndpointServer::Adopt(z_cap_t endpoint_cap) {
|
||||
return EndpointServer(endpoint_cap);
|
||||
glcr::UniquePtr<EndpointServer> EndpointServer::Adopt(z_cap_t endpoint_cap) {
|
||||
return glcr::UniquePtr<EndpointServer>(new EndpointServer(endpoint_cap));
|
||||
}
|
||||
|
||||
glcr::ErrorOr<EndpointClient> EndpointServer::CreateClient() {
|
||||
|
|
|
@ -28,11 +28,12 @@ uint64_t main(uint64_t init_port_cap) {
|
|||
auto resp_cap = resp_cap_or.value();
|
||||
PortClient notify = PortClient::AdoptPort(resp_cap.second());
|
||||
|
||||
ASSIGN_OR_RETURN(EndpointServer endpoint, EndpointServer::Create());
|
||||
ASSIGN_OR_RETURN(EndpointClient client, endpoint.CreateClient());
|
||||
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointServer> endpoint,
|
||||
EndpointServer::Create());
|
||||
ASSIGN_OR_RETURN(EndpointClient client, endpoint->CreateClient());
|
||||
notify.WriteMessage("denali", client.GetCap());
|
||||
|
||||
DenaliServer server(endpoint, driver);
|
||||
DenaliServer server(glcr::Move(endpoint), driver);
|
||||
RET_ERR(server.RunServer());
|
||||
// FIXME: Add thread join.
|
||||
return 0;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "denali_server.h"
|
||||
|
||||
#include <glacier/memory/move.h>
|
||||
#include <glacier/status/error.h>
|
||||
#include <mammoth/debug.h>
|
||||
#include <zcall.h>
|
||||
|
@ -12,8 +13,9 @@ void HandleResponse(z_cap_t reply_port, uint64_t lba, uint64_t size,
|
|||
}
|
||||
} // namespace
|
||||
|
||||
DenaliServer::DenaliServer(EndpointServer server, AhciDriver& driver)
|
||||
: server_(server), driver_(driver) {
|
||||
DenaliServer::DenaliServer(glcr::UniquePtr<EndpointServer> server,
|
||||
AhciDriver& driver)
|
||||
: server_(glcr::Move(server)), driver_(driver) {
|
||||
gServer = this;
|
||||
}
|
||||
|
||||
|
@ -21,7 +23,7 @@ glcr::ErrorCode DenaliServer::RunServer() {
|
|||
while (true) {
|
||||
uint64_t buff_size = kBuffSize;
|
||||
z_cap_t reply_port;
|
||||
RET_ERR(server_.Recieve(&buff_size, read_buffer_, &reply_port));
|
||||
RET_ERR(server_->Recieve(&buff_size, read_buffer_, &reply_port));
|
||||
if (buff_size < sizeof(uint64_t)) {
|
||||
dbgln("Skipping invalid message");
|
||||
continue;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
class DenaliServer {
|
||||
public:
|
||||
DenaliServer(EndpointServer server, AhciDriver& driver);
|
||||
DenaliServer(glcr::UniquePtr<EndpointServer> server, AhciDriver& driver);
|
||||
|
||||
glcr::ErrorCode RunServer();
|
||||
|
||||
|
@ -17,7 +17,7 @@ class DenaliServer {
|
|||
|
||||
private:
|
||||
static const uint64_t kBuffSize = 1024;
|
||||
EndpointServer server_;
|
||||
glcr::UniquePtr<EndpointServer> server_;
|
||||
uint8_t read_buffer_[kBuffSize];
|
||||
|
||||
AhciDriver& driver_;
|
||||
|
|
|
@ -12,18 +12,18 @@ uint64_t main(uint64_t port_cap) {
|
|||
dbgln("Yellowstone Initializing.");
|
||||
check(ParseInitPort(port_cap));
|
||||
|
||||
ASSIGN_OR_RETURN(YellowstoneServer server, YellowstoneServer::Create());
|
||||
Thread server_thread = server.RunServer();
|
||||
Thread registration_thread = server.RunRegistration();
|
||||
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
|
||||
Thread server_thread = server->RunServer();
|
||||
Thread registration_thread = server->RunRegistration();
|
||||
DumpPciEDevices();
|
||||
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootDenaliVmmoCap, &vaddr));
|
||||
ASSIGN_OR_RETURN(EndpointClient client, server.GetServerClient());
|
||||
ASSIGN_OR_RETURN(EndpointClient client, server->GetServerClient());
|
||||
check(SpawnProcessFromElfRegion(vaddr, client));
|
||||
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
|
||||
ASSIGN_OR_RETURN(client, server.GetServerClient());
|
||||
ASSIGN_OR_RETURN(client, server->GetServerClient());
|
||||
check(SpawnProcessFromElfRegion(vaddr, client));
|
||||
|
||||
check(server_thread.Join());
|
||||
|
|
|
@ -30,14 +30,16 @@ glcr::ErrorCode HandleDenaliRegistration(z_cap_t endpoint_cap) {
|
|||
|
||||
} // namespace
|
||||
|
||||
glcr::ErrorOr<YellowstoneServer> YellowstoneServer::Create() {
|
||||
ASSIGN_OR_RETURN(EndpointServer server, EndpointServer::Create());
|
||||
glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
|
||||
ASSIGN_OR_RETURN(auto server, EndpointServer::Create());
|
||||
ASSIGN_OR_RETURN(PortServer port, PortServer::Create());
|
||||
return YellowstoneServer(server, port);
|
||||
return glcr::UniquePtr<YellowstoneServer>(
|
||||
new YellowstoneServer(glcr::Move(server), port));
|
||||
}
|
||||
|
||||
YellowstoneServer::YellowstoneServer(EndpointServer server, PortServer port)
|
||||
: server_(server), register_port_(port) {}
|
||||
YellowstoneServer::YellowstoneServer(glcr::UniquePtr<EndpointServer> server,
|
||||
PortServer port)
|
||||
: server_(glcr::Move(server)), register_port_(port) {}
|
||||
|
||||
Thread YellowstoneServer::RunServer() {
|
||||
return Thread(ServerThreadBootstrap, this);
|
||||
|
@ -52,7 +54,7 @@ void YellowstoneServer::ServerThread() {
|
|||
uint64_t num_bytes = kBufferSize;
|
||||
uint64_t reply_port_cap;
|
||||
// FIXME: Error handling.
|
||||
check(server_.Recieve(&num_bytes, server_buffer_, &reply_port_cap));
|
||||
check(server_->Recieve(&num_bytes, server_buffer_, &reply_port_cap));
|
||||
YellowstoneGetReq* req =
|
||||
reinterpret_cast<YellowstoneGetReq*>(server_buffer_);
|
||||
switch (req->type) {
|
||||
|
@ -102,5 +104,5 @@ void YellowstoneServer::RegistrationThread() {
|
|||
}
|
||||
|
||||
glcr::ErrorOr<EndpointClient> YellowstoneServer::GetServerClient() {
|
||||
return server_.CreateClient();
|
||||
return server_->CreateClient();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/unique_ptr.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <mammoth/endpoint_server.h>
|
||||
#include <mammoth/port_server.h>
|
||||
|
@ -7,7 +8,7 @@
|
|||
|
||||
class YellowstoneServer {
|
||||
public:
|
||||
static glcr::ErrorOr<YellowstoneServer> Create();
|
||||
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
|
||||
|
||||
Thread RunServer();
|
||||
Thread RunRegistration();
|
||||
|
@ -18,7 +19,7 @@ class YellowstoneServer {
|
|||
glcr::ErrorOr<EndpointClient> GetServerClient();
|
||||
|
||||
private:
|
||||
EndpointServer server_;
|
||||
glcr::UniquePtr<EndpointServer> server_;
|
||||
PortServer register_port_;
|
||||
|
||||
static const uint64_t kBufferSize = 128;
|
||||
|
@ -29,5 +30,5 @@ class YellowstoneServer {
|
|||
z_cap_t denali_cap_ = 0;
|
||||
z_cap_t victoria_falls_cap_ = 0;
|
||||
|
||||
YellowstoneServer(EndpointServer server, PortServer port);
|
||||
YellowstoneServer(glcr::UniquePtr<EndpointServer> server, PortServer port);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue