Kernel: pass ref to port

This commit is contained in:
Weiyi Wang 2018-10-12 19:00:16 -04:00
parent c141657d83
commit 1213a298df
12 changed files with 37 additions and 25 deletions

View file

@ -22,11 +22,13 @@ static ResultCode ValidateServiceName(const std::string& name) {
return RESULT_SUCCESS;
}
ServiceManager::ServiceManager(Core::System& system) : system(system) {}
void ServiceManager::InstallInterfaces(Core::System& system) {
ASSERT(system.ServiceManager().srv_interface.expired());
auto srv = std::make_shared<SRV>(system);
srv->InstallAsNamedPort();
srv->InstallAsNamedPort(system.Kernel());
system.ServiceManager().srv_interface = srv;
}
@ -40,7 +42,7 @@ ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> ServiceManager::RegisterService
Kernel::SharedPtr<Kernel::ServerPort> server_port;
Kernel::SharedPtr<Kernel::ClientPort> client_port;
std::tie(server_port, client_port) = Kernel::ServerPort::CreatePortPair(max_sessions, name);
std::tie(server_port, client_port) = system.Kernel().CreatePortPair(max_sessions, name);
registered_services.emplace(std::move(name), std::move(client_port));
return MakeResult<Kernel::SharedPtr<Kernel::ServerPort>>(std::move(server_port));

View file

@ -45,6 +45,8 @@ class ServiceManager {
public:
static void InstallInterfaces(Core::System& system);
explicit ServiceManager(Core::System& system);
ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> RegisterService(std::string name,
unsigned int max_sessions);
ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> GetServicePort(const std::string& name);
@ -67,6 +69,7 @@ public:
}
private:
Core::System& system;
std::weak_ptr<SRV> srv_interface;
/// Map of registered services, retrieved using GetServicePort or ConnectToService.