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