2018-01-13 16:22:39 -05:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2017-06-06 02:31:59 -04:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-08-01 22:40:00 -04:00
|
|
|
#include <memory>
|
2017-06-06 02:31:59 -04:00
|
|
|
#include <string>
|
2018-10-06 02:49:01 -04:00
|
|
|
#include <type_traits>
|
2017-06-06 02:31:59 -04:00
|
|
|
#include <unordered_map>
|
2018-08-01 22:40:00 -04:00
|
|
|
|
2018-10-06 02:49:01 -04:00
|
|
|
#include "core/hle/kernel/client_port.h"
|
2018-08-01 22:40:00 -04:00
|
|
|
#include "core/hle/kernel/object.h"
|
2018-10-06 02:49:01 -04:00
|
|
|
#include "core/hle/kernel/server_port.h"
|
2017-06-06 02:31:59 -04:00
|
|
|
#include "core/hle/result.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
class ClientPort;
|
|
|
|
class ClientSession;
|
2019-11-25 18:28:48 -05:00
|
|
|
class KernelCore;
|
2017-06-06 02:31:59 -04:00
|
|
|
class ServerPort;
|
|
|
|
class SessionRequestHandler;
|
|
|
|
} // namespace Kernel
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::SM {
|
2017-06-06 02:31:59 -04:00
|
|
|
|
2018-08-01 22:40:00 -04:00
|
|
|
class Controller;
|
|
|
|
|
2017-10-14 22:18:42 -04:00
|
|
|
/// Interface to "sm:" service
|
|
|
|
class SM final : public ServiceFramework<SM> {
|
|
|
|
public:
|
2019-11-25 18:28:48 -05:00
|
|
|
explicit SM(std::shared_ptr<ServiceManager> service_manager, Kernel::KernelCore& kernel);
|
2018-04-20 19:29:04 -04:00
|
|
|
~SM() override;
|
2017-10-14 22:18:42 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void Initialize(Kernel::HLERequestContext& ctx);
|
|
|
|
void GetService(Kernel::HLERequestContext& ctx);
|
2018-11-03 20:02:18 -04:00
|
|
|
void RegisterService(Kernel::HLERequestContext& ctx);
|
|
|
|
void UnregisterService(Kernel::HLERequestContext& ctx);
|
2017-10-14 22:18:42 -04:00
|
|
|
|
|
|
|
std::shared_ptr<ServiceManager> service_manager;
|
2019-11-25 18:28:48 -05:00
|
|
|
Kernel::KernelCore& kernel;
|
2017-10-14 22:18:42 -04:00
|
|
|
};
|
|
|
|
|
2017-06-06 02:31:59 -04:00
|
|
|
class ServiceManager {
|
|
|
|
public:
|
2019-11-25 18:28:48 -05:00
|
|
|
static void InstallInterfaces(std::shared_ptr<ServiceManager> self, Kernel::KernelCore& kernel);
|
2017-06-07 00:25:28 -04:00
|
|
|
|
2018-09-06 14:32:25 -04:00
|
|
|
ServiceManager();
|
2018-04-20 19:29:04 -04:00
|
|
|
~ServiceManager();
|
|
|
|
|
2019-11-24 20:15:51 -05:00
|
|
|
ResultVal<std::shared_ptr<Kernel::ServerPort>> RegisterService(std::string name,
|
|
|
|
unsigned int max_sessions);
|
2018-11-24 00:04:07 -05:00
|
|
|
ResultCode UnregisterService(const std::string& name);
|
2019-11-24 20:15:51 -05:00
|
|
|
ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name);
|
|
|
|
ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(const std::string& name);
|
2017-06-06 02:31:59 -04:00
|
|
|
|
2018-10-06 02:49:01 -04:00
|
|
|
template <typename T>
|
|
|
|
std::shared_ptr<T> GetService(const std::string& service_name) const {
|
|
|
|
static_assert(std::is_base_of_v<Kernel::SessionRequestHandler, T>,
|
|
|
|
"Not a base of ServiceFrameworkBase");
|
|
|
|
auto service = registered_services.find(service_name);
|
|
|
|
if (service == registered_services.end()) {
|
|
|
|
LOG_DEBUG(Service, "Can't find service: {}", service_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto port = service->second->GetServerPort();
|
|
|
|
if (port == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-03-11 10:28:16 -04:00
|
|
|
return std::static_pointer_cast<T>(port->GetHLEHandler());
|
2018-10-06 02:49:01 -04:00
|
|
|
}
|
|
|
|
|
2017-10-14 22:18:42 -04:00
|
|
|
void InvokeControlRequest(Kernel::HLERequestContext& context);
|
|
|
|
|
2017-06-06 02:31:59 -04:00
|
|
|
private:
|
2017-10-14 22:18:42 -04:00
|
|
|
std::weak_ptr<SM> sm_interface;
|
|
|
|
std::unique_ptr<Controller> controller_interface;
|
2017-06-07 00:25:28 -04:00
|
|
|
|
|
|
|
/// Map of registered services, retrieved using GetServicePort or ConnectToService.
|
2019-11-24 20:15:51 -05:00
|
|
|
std::unordered_map<std::string, std::shared_ptr<Kernel::ClientPort>> registered_services;
|
2017-06-06 02:31:59 -04:00
|
|
|
};
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::SM
|