[yellowstone] Add registration to yellowstone stub.
This commit is contained in:
parent
72483a3437
commit
c057da88ad
|
@ -20,7 +20,7 @@ class EndpointClient {
|
|||
template <typename Req, typename Resp>
|
||||
glcr::ErrorOr<Resp> CallEndpoint(const Req& req);
|
||||
|
||||
z_cap_t GetCap() { return cap_; }
|
||||
z_cap_t GetCap() const { return cap_; }
|
||||
|
||||
private:
|
||||
EndpointClient(uint64_t cap) : cap_(cap) {}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
class PortClient {
|
||||
public:
|
||||
PortClient() {}
|
||||
static PortClient AdoptPort(z_cap_t port_cap);
|
||||
|
||||
template <typename T>
|
||||
|
@ -16,8 +17,10 @@ class PortClient {
|
|||
|
||||
z_cap_t cap() { return port_cap_; }
|
||||
|
||||
bool empty() { return port_cap_ == 0; }
|
||||
|
||||
private:
|
||||
z_cap_t port_cap_;
|
||||
z_cap_t port_cap_ = 0;
|
||||
|
||||
PortClient(z_cap_t port_cap);
|
||||
};
|
||||
|
|
|
@ -19,24 +19,11 @@ uint64_t main(uint64_t init_port_cap) {
|
|||
ASSIGN_OR_RETURN(MappedMemoryRegion ahci_region, stub.GetAhciConfig());
|
||||
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(ahci_region));
|
||||
|
||||
YellowstoneGetReq req{
|
||||
.type = kYellowstoneGetRegistration,
|
||||
};
|
||||
auto resp_cap_or =
|
||||
yellowstone->CallEndpointGetCap<YellowstoneGetReq,
|
||||
YellowstoneGetRegistrationResp>(req);
|
||||
if (!resp_cap_or.ok()) {
|
||||
dbgln("Bad call");
|
||||
check(resp_cap_or.error());
|
||||
}
|
||||
auto resp_cap = resp_cap_or.value();
|
||||
PortClient notify = PortClient::AdoptPort(resp_cap.second());
|
||||
|
||||
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointServer> endpoint,
|
||||
EndpointServer::Create());
|
||||
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client,
|
||||
endpoint->CreateClient());
|
||||
notify.WriteMessage("denali", client->GetCap());
|
||||
check(stub.Register("denali", *client));
|
||||
|
||||
DenaliServer server(glcr::Move(endpoint), *driver);
|
||||
RET_ERR(server.RunServer());
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <mammoth/endpoint_client.h>
|
||||
#include <mammoth/memory_region.h>
|
||||
#include <mammoth/port_client.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
class YellowstoneStub {
|
||||
|
@ -10,6 +11,10 @@ class YellowstoneStub {
|
|||
|
||||
glcr::ErrorOr<MappedMemoryRegion> GetAhciConfig();
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode Register(glcr::String name,
|
||||
const EndpointClient& client);
|
||||
|
||||
private:
|
||||
glcr::UniquePtr<EndpointClient> yellowstone_stub_;
|
||||
PortClient register_port_;
|
||||
};
|
||||
|
|
|
@ -21,3 +21,19 @@ glcr::ErrorOr<MappedMemoryRegion> YellowstoneStub::GetAhciConfig() {
|
|||
->CallEndpoint<YellowstoneGetReq, YellowstoneGetAhciResp>(req)));
|
||||
return MappedMemoryRegion::DirectPhysical(resp.ahci_phys_offset, kPciSize);
|
||||
}
|
||||
|
||||
glcr::ErrorCode YellowstoneStub::Register(glcr::String name,
|
||||
const EndpointClient& client) {
|
||||
if (register_port_.empty()) {
|
||||
YellowstoneGetReq req{
|
||||
.type = kYellowstoneGetRegistration,
|
||||
};
|
||||
ASSIGN_OR_RETURN(
|
||||
auto resp_cap,
|
||||
(yellowstone_stub_->CallEndpointGetCap<
|
||||
YellowstoneGetReq, YellowstoneGetRegistrationResp>(req)));
|
||||
register_port_ = PortClient::AdoptPort(resp_cap.second());
|
||||
}
|
||||
|
||||
return register_port_.WriteString(name, client.GetCap());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue