Generalize the EndpointServer to require less boilerplate.
Classes can now inherit from the EndpointServer and just implement the HandleRequest function.
This commit is contained in:
parent
847d37addc
commit
caccb08e16
14 changed files with 215 additions and 147 deletions
|
|
@ -12,11 +12,6 @@
|
|||
|
||||
namespace {
|
||||
|
||||
void ServerThreadBootstrap(void* yellowstone) {
|
||||
dbgln("Yellowstone server starting");
|
||||
static_cast<YellowstoneServer*>(yellowstone)->ServerThread();
|
||||
}
|
||||
|
||||
void RegistrationThreadBootstrap(void* yellowstone) {
|
||||
dbgln("Yellowstone registration starting");
|
||||
static_cast<YellowstoneServer*>(yellowstone)->RegistrationThread();
|
||||
|
|
@ -40,71 +35,60 @@ glcr::ErrorOr<PartitionInfo> HandleDenaliRegistration(z_cap_t endpoint_cap) {
|
|||
} // namespace
|
||||
|
||||
glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
|
||||
ASSIGN_OR_RETURN(auto server, EndpointServer::Create());
|
||||
z_cap_t cap;
|
||||
RET_ERR(ZEndpointCreate(&cap));
|
||||
ASSIGN_OR_RETURN(PortServer port, PortServer::Create());
|
||||
return glcr::UniquePtr<YellowstoneServer>(
|
||||
new YellowstoneServer(glcr::Move(server), port));
|
||||
return glcr::UniquePtr<YellowstoneServer>(new YellowstoneServer(cap, port));
|
||||
}
|
||||
|
||||
YellowstoneServer::YellowstoneServer(glcr::UniquePtr<EndpointServer> server,
|
||||
PortServer port)
|
||||
: server_(glcr::Move(server)), register_port_(port) {}
|
||||
|
||||
Thread YellowstoneServer::RunServer() {
|
||||
return Thread(ServerThreadBootstrap, this);
|
||||
}
|
||||
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap, PortServer port)
|
||||
: EndpointServer(endpoint_cap), register_port_(port) {}
|
||||
|
||||
Thread YellowstoneServer::RunRegistration() {
|
||||
return Thread(RegistrationThreadBootstrap, this);
|
||||
}
|
||||
|
||||
void YellowstoneServer::ServerThread() {
|
||||
while (true) {
|
||||
uint64_t num_bytes = kBufferSize;
|
||||
uint64_t reply_port_cap;
|
||||
// FIXME: Error handling.
|
||||
check(server_->Recieve(&num_bytes, server_buffer_, &reply_port_cap));
|
||||
YellowstoneGetReq* req =
|
||||
reinterpret_cast<YellowstoneGetReq*>(server_buffer_);
|
||||
switch (req->type) {
|
||||
case kYellowstoneGetAhci: {
|
||||
dbgln("Yellowstone::GetAHCI");
|
||||
YellowstoneGetAhciResp resp{
|
||||
.type = kYellowstoneGetAhci,
|
||||
.ahci_phys_offset = pci_reader_.GetAhciPhysical(),
|
||||
};
|
||||
check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 0, nullptr));
|
||||
break;
|
||||
}
|
||||
case kYellowstoneGetRegistration: {
|
||||
dbgln("Yellowstone::GetRegistration");
|
||||
auto client_or = register_port_.CreateClient();
|
||||
if (!client_or.ok()) {
|
||||
check(client_or.error());
|
||||
}
|
||||
YellowstoneGetRegistrationResp resp;
|
||||
uint64_t reg_cap = client_or.value().cap();
|
||||
check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 1, ®_cap));
|
||||
break;
|
||||
}
|
||||
case kYellowstoneGetDenali: {
|
||||
dbgln("Yellowstone::GetDenali");
|
||||
z_cap_t new_denali;
|
||||
check(ZCapDuplicate(denali_cap_, &new_denali));
|
||||
YellowstoneGetDenaliResp resp{
|
||||
.type = kYellowstoneGetDenali,
|
||||
.device_id = device_id_,
|
||||
.lba_offset = lba_offset_,
|
||||
};
|
||||
check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 1,
|
||||
&new_denali));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dbgln("Unknown request type: %x", req->type);
|
||||
break;
|
||||
glcr::ErrorCode YellowstoneServer::HandleRequest(RequestContext& request,
|
||||
ResponseContext& response) {
|
||||
switch (request.request_id()) {
|
||||
case kYellowstoneGetAhci: {
|
||||
dbgln("Yellowstone::GetAHCI");
|
||||
YellowstoneGetAhciResp resp{
|
||||
.type = kYellowstoneGetAhci,
|
||||
.ahci_phys_offset = pci_reader_.GetAhciPhysical(),
|
||||
};
|
||||
RET_ERR(response.WriteStruct<YellowstoneGetAhciResp>(resp));
|
||||
break;
|
||||
}
|
||||
case kYellowstoneGetRegistration: {
|
||||
dbgln("Yellowstone::GetRegistration");
|
||||
auto client_or = register_port_.CreateClient();
|
||||
if (!client_or.ok()) {
|
||||
check(client_or.error());
|
||||
}
|
||||
YellowstoneGetRegistrationResp resp;
|
||||
uint64_t reg_cap = client_or.value().cap();
|
||||
RET_ERR(response.WriteStructWithCap(resp, reg_cap));
|
||||
break;
|
||||
}
|
||||
case kYellowstoneGetDenali: {
|
||||
dbgln("Yellowstone::GetDenali");
|
||||
z_cap_t new_denali;
|
||||
check(ZCapDuplicate(denali_cap_, &new_denali));
|
||||
YellowstoneGetDenaliResp resp{
|
||||
.type = kYellowstoneGetDenali,
|
||||
.device_id = device_id_,
|
||||
.lba_offset = lba_offset_,
|
||||
};
|
||||
RET_ERR(response.WriteStructWithCap(resp, new_denali));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dbgln("Unknown request type: %x", request.request_id());
|
||||
return glcr::UNIMPLEMENTED;
|
||||
break;
|
||||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
void YellowstoneServer::RegistrationThread() {
|
||||
|
|
@ -127,7 +111,7 @@ void YellowstoneServer::RegistrationThread() {
|
|||
uint64_t vaddr;
|
||||
check(
|
||||
ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
|
||||
auto client_or = GetServerClient();
|
||||
auto client_or = CreateClient();
|
||||
if (!client_or.ok()) {
|
||||
check(client_or.error());
|
||||
}
|
||||
|
|
@ -144,8 +128,3 @@ void YellowstoneServer::RegistrationThread() {
|
|||
dbgln(name.cstr());
|
||||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>>
|
||||
YellowstoneServer::GetServerClient() {
|
||||
return server_->CreateClient();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue