2018-01-13 21:22:39 +00:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2017-06-06 06:31:59 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-08-02 02:40:00 +00:00
|
|
|
#include <memory>
|
2017-06-06 06:31:59 +00:00
|
|
|
#include <string>
|
2018-10-06 06:49:01 +00:00
|
|
|
#include <type_traits>
|
2017-06-06 06:31:59 +00:00
|
|
|
#include <unordered_map>
|
2018-08-02 02:40:00 +00:00
|
|
|
|
2020-08-03 11:46:14 +00:00
|
|
|
#include "common/concepts.h"
|
2021-04-22 04:43:25 +00:00
|
|
|
#include "core/hle/kernel/k_client_port.h"
|
2018-08-02 02:40:00 +00:00
|
|
|
#include "core/hle/kernel/object.h"
|
2018-10-06 06:49:01 +00:00
|
|
|
#include "core/hle/kernel/server_port.h"
|
2017-06-06 06:31:59 +00:00
|
|
|
#include "core/hle/result.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
2020-11-26 20:19:08 +00:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:31:59 +00:00
|
|
|
namespace Kernel {
|
2021-04-22 04:43:25 +00:00
|
|
|
class KClientPort;
|
2021-04-14 00:48:37 +00:00
|
|
|
class KClientSession;
|
2019-11-25 23:28:48 +00:00
|
|
|
class KernelCore;
|
2017-06-06 06:31:59 +00:00
|
|
|
class ServerPort;
|
|
|
|
class SessionRequestHandler;
|
|
|
|
} // namespace Kernel
|
|
|
|
|
2018-04-20 01:41:44 +00:00
|
|
|
namespace Service::SM {
|
2017-06-06 06:31:59 +00:00
|
|
|
|
2018-08-02 02:40:00 +00:00
|
|
|
class Controller;
|
|
|
|
|
2017-10-15 02:18:42 +00:00
|
|
|
/// Interface to "sm:" service
|
|
|
|
class SM final : public ServiceFramework<SM> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit SM(std::shared_ptr<ServiceManager> service_manager_, Core::System& system_);
|
2018-04-20 23:29:04 +00:00
|
|
|
~SM() override;
|
2017-10-15 02:18:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void Initialize(Kernel::HLERequestContext& ctx);
|
|
|
|
void GetService(Kernel::HLERequestContext& ctx);
|
2018-11-04 00:02:18 +00:00
|
|
|
void RegisterService(Kernel::HLERequestContext& ctx);
|
|
|
|
void UnregisterService(Kernel::HLERequestContext& ctx);
|
2017-10-15 02:18:42 +00:00
|
|
|
|
|
|
|
std::shared_ptr<ServiceManager> service_manager;
|
2019-11-25 23:28:48 +00:00
|
|
|
Kernel::KernelCore& kernel;
|
2017-10-15 02:18:42 +00:00
|
|
|
};
|
|
|
|
|
2017-06-06 06:31:59 +00:00
|
|
|
class ServiceManager {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
static void InstallInterfaces(std::shared_ptr<ServiceManager> self, Core::System& system);
|
2017-06-07 04:25:28 +00:00
|
|
|
|
2020-09-17 14:43:54 +00:00
|
|
|
explicit ServiceManager(Kernel::KernelCore& kernel_);
|
2018-04-20 23:29:04 +00:00
|
|
|
~ServiceManager();
|
|
|
|
|
2019-11-25 01:15:51 +00:00
|
|
|
ResultVal<std::shared_ptr<Kernel::ServerPort>> RegisterService(std::string name,
|
2020-09-17 14:43:54 +00:00
|
|
|
u32 max_sessions);
|
2018-11-24 05:04:07 +00:00
|
|
|
ResultCode UnregisterService(const std::string& name);
|
2021-04-22 04:43:25 +00:00
|
|
|
ResultVal<Kernel::KClientPort*> GetServicePort(const std::string& name);
|
2017-06-06 06:31:59 +00:00
|
|
|
|
2020-08-07 11:55:50 +00:00
|
|
|
template <Common::DerivedFrom<Kernel::SessionRequestHandler> T>
|
2018-10-06 06:49:01 +00:00
|
|
|
std::shared_ptr<T> GetService(const std::string& service_name) const {
|
|
|
|
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 14:28:16 +00:00
|
|
|
return std::static_pointer_cast<T>(port->GetHLEHandler());
|
2018-10-06 06:49:01 +00:00
|
|
|
}
|
|
|
|
|
2017-10-15 02:18:42 +00:00
|
|
|
void InvokeControlRequest(Kernel::HLERequestContext& context);
|
|
|
|
|
2017-06-06 06:31:59 +00:00
|
|
|
private:
|
2017-10-15 02:18:42 +00:00
|
|
|
std::weak_ptr<SM> sm_interface;
|
|
|
|
std::unique_ptr<Controller> controller_interface;
|
2017-06-07 04:25:28 +00:00
|
|
|
|
2021-04-14 00:48:37 +00:00
|
|
|
/// Map of registered services, retrieved using GetServicePort.
|
2021-04-22 04:43:25 +00:00
|
|
|
std::unordered_map<std::string, Kernel::KClientPort*> registered_services;
|
2020-09-17 14:43:54 +00:00
|
|
|
|
|
|
|
/// Kernel context
|
|
|
|
Kernel::KernelCore& kernel;
|
2017-06-06 06:31:59 +00:00
|
|
|
};
|
|
|
|
|
2018-04-20 01:41:44 +00:00
|
|
|
} // namespace Service::SM
|