2022-04-23 01:59:50 -07:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-06-05 23:31:59 -07:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-08-01 19:40:00 -07:00
|
|
|
#include <memory>
|
2023-02-18 13:26:48 -08:00
|
|
|
#include <mutex>
|
2017-06-05 23:31:59 -07:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
2018-08-01 19:40:00 -07:00
|
|
|
|
2020-08-03 04:46:14 -07:00
|
|
|
#include "common/concepts.h"
|
2021-04-23 17:00:15 -07:00
|
|
|
#include "core/hle/kernel/k_port.h"
|
2017-06-05 23:31:59 -07:00
|
|
|
#include "core/hle/result.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
2020-11-26 12:19:08 -08:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2017-06-05 23:31:59 -07:00
|
|
|
namespace Kernel {
|
2021-04-21 21:43:25 -07:00
|
|
|
class KClientPort;
|
2021-04-13 17:48:37 -07:00
|
|
|
class KClientSession;
|
2019-11-25 15:28:48 -08:00
|
|
|
class KernelCore;
|
2021-04-23 17:00:15 -07:00
|
|
|
class KPort;
|
2017-06-05 23:31:59 -07:00
|
|
|
class SessionRequestHandler;
|
|
|
|
} // namespace Kernel
|
|
|
|
|
2018-04-19 18:41:44 -07:00
|
|
|
namespace Service::SM {
|
2017-06-05 23:31:59 -07:00
|
|
|
|
2018-08-01 19:40:00 -07:00
|
|
|
class Controller;
|
|
|
|
|
2017-10-14 19:18:42 -07:00
|
|
|
/// Interface to "sm:" service
|
|
|
|
class SM final : public ServiceFramework<SM> {
|
|
|
|
public:
|
2021-05-10 16:18:30 -07:00
|
|
|
explicit SM(ServiceManager& service_manager_, Core::System& system_);
|
2018-04-20 16:29:04 -07:00
|
|
|
~SM() override;
|
2017-10-14 19:18:42 -07:00
|
|
|
|
|
|
|
private:
|
2023-02-19 11:42:12 -08:00
|
|
|
void Initialize(HLERequestContext& ctx);
|
2023-12-09 19:16:35 -08:00
|
|
|
void GetServiceCmif(HLERequestContext& ctx);
|
2023-02-19 11:42:12 -08:00
|
|
|
void GetServiceTipc(HLERequestContext& ctx);
|
2023-12-09 19:16:35 -08:00
|
|
|
void RegisterServiceCmif(HLERequestContext& ctx);
|
|
|
|
void RegisterServiceTipc(HLERequestContext& ctx);
|
2023-02-19 11:42:12 -08:00
|
|
|
void UnregisterService(HLERequestContext& ctx);
|
2017-10-14 19:18:42 -07:00
|
|
|
|
2023-07-14 17:16:39 -07:00
|
|
|
Result GetServiceImpl(Kernel::KClientSession** out_client_session, HLERequestContext& ctx);
|
2023-12-09 19:16:35 -08:00
|
|
|
void RegisterServiceImpl(HLERequestContext& ctx, std::string name, u32 max_session_count,
|
|
|
|
bool is_light);
|
2021-05-10 16:18:30 -07:00
|
|
|
|
|
|
|
ServiceManager& service_manager;
|
2019-11-25 15:28:48 -08:00
|
|
|
Kernel::KernelCore& kernel;
|
2017-10-14 19:18:42 -07:00
|
|
|
};
|
|
|
|
|
2017-06-05 23:31:59 -07:00
|
|
|
class ServiceManager {
|
|
|
|
public:
|
2020-09-17 07:43:54 -07:00
|
|
|
explicit ServiceManager(Kernel::KernelCore& kernel_);
|
2018-04-20 16:29:04 -07:00
|
|
|
~ServiceManager();
|
|
|
|
|
2023-12-09 08:22:42 -08:00
|
|
|
Result RegisterService(std::string name, u32 max_sessions,
|
|
|
|
SessionRequestHandlerFactory handler_factory);
|
2022-06-25 20:44:19 -07:00
|
|
|
Result UnregisterService(const std::string& name);
|
2023-07-14 17:16:39 -07:00
|
|
|
Result GetServicePort(Kernel::KPort** out_port, const std::string& name);
|
2017-06-05 23:31:59 -07:00
|
|
|
|
2023-02-19 11:42:12 -08:00
|
|
|
template <Common::DerivedFrom<SessionRequestHandler> T>
|
2018-10-05 23:49:01 -07: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;
|
|
|
|
}
|
2023-12-09 08:22:42 -08:00
|
|
|
return std::static_pointer_cast<T>(service->second());
|
2018-10-05 23:49:01 -07:00
|
|
|
}
|
|
|
|
|
2023-02-19 11:42:12 -08:00
|
|
|
void InvokeControlRequest(HLERequestContext& context);
|
2017-10-14 19:18:42 -07:00
|
|
|
|
2023-02-19 05:44:54 -08:00
|
|
|
void SetDeferralEvent(Kernel::KEvent* deferral_event_) {
|
|
|
|
deferral_event = deferral_event_;
|
|
|
|
}
|
|
|
|
|
2017-06-05 23:31:59 -07:00
|
|
|
private:
|
2021-06-30 18:06:47 -07:00
|
|
|
std::shared_ptr<SM> sm_interface;
|
2017-10-14 19:18:42 -07:00
|
|
|
std::unique_ptr<Controller> controller_interface;
|
2017-06-06 21:25:28 -07:00
|
|
|
|
2021-04-13 17:48:37 -07:00
|
|
|
/// Map of registered services, retrieved using GetServicePort.
|
2023-02-18 13:26:48 -08:00
|
|
|
std::mutex lock;
|
2023-12-09 08:22:42 -08:00
|
|
|
std::unordered_map<std::string, SessionRequestHandlerFactory> registered_services;
|
2022-10-30 19:22:14 -07:00
|
|
|
std::unordered_map<std::string, Kernel::KPort*> service_ports;
|
2020-09-17 07:43:54 -07:00
|
|
|
|
|
|
|
/// Kernel context
|
|
|
|
Kernel::KernelCore& kernel;
|
2023-02-19 05:44:54 -08:00
|
|
|
Kernel::KEvent* deferral_event{};
|
2017-06-05 23:31:59 -07:00
|
|
|
};
|
|
|
|
|
2023-02-18 13:26:48 -08:00
|
|
|
/// Runs SM services.
|
|
|
|
void LoopProcess(Core::System& system);
|
|
|
|
|
2018-04-19 18:41:44 -07:00
|
|
|
} // namespace Service::SM
|