2022-04-23 22:49:07 +04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "common/concepts.h"
|
2021-05-06 06:45:54 +04:00
|
|
|
#include "core/hle/kernel/k_port.h"
|
2020-12-28 19:15:37 +04:00
|
|
|
#include "core/hle/result.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Kernel {
|
2021-05-06 06:45:54 +04:00
|
|
|
class KClientPort;
|
|
|
|
class KClientSession;
|
2020-12-28 19:15:37 +04:00
|
|
|
class KernelCore;
|
2021-05-06 06:45:54 +04:00
|
|
|
class KPort;
|
2020-12-28 19:15:37 +04:00
|
|
|
class SessionRequestHandler;
|
|
|
|
} // namespace Kernel
|
|
|
|
|
|
|
|
namespace Service::SM {
|
|
|
|
|
|
|
|
class Controller;
|
|
|
|
|
|
|
|
/// Interface to "sm:" service
|
|
|
|
class SM final : public ServiceFramework<SM> {
|
|
|
|
public:
|
2021-05-11 04:22:43 +04:00
|
|
|
explicit SM(ServiceManager& service_manager_, Core::System& system_);
|
2020-12-28 19:15:37 +04:00
|
|
|
~SM() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Initialize(Kernel::HLERequestContext& ctx);
|
|
|
|
void GetService(Kernel::HLERequestContext& ctx);
|
2021-05-11 04:22:43 +04:00
|
|
|
void GetServiceTipc(Kernel::HLERequestContext& ctx);
|
2020-12-28 19:15:37 +04:00
|
|
|
void RegisterService(Kernel::HLERequestContext& ctx);
|
|
|
|
void UnregisterService(Kernel::HLERequestContext& ctx);
|
|
|
|
|
2021-05-11 04:22:43 +04:00
|
|
|
ResultVal<Kernel::KClientSession*> GetServiceImpl(Kernel::HLERequestContext& ctx);
|
|
|
|
|
|
|
|
ServiceManager& service_manager;
|
|
|
|
bool is_initialized{};
|
2020-12-28 19:15:37 +04:00
|
|
|
Kernel::KernelCore& kernel;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ServiceManager {
|
|
|
|
public:
|
2021-05-11 04:22:43 +04:00
|
|
|
static Kernel::KClientPort& InterfaceFactory(ServiceManager& self, Core::System& system);
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
explicit ServiceManager(Kernel::KernelCore& kernel_);
|
|
|
|
~ServiceManager();
|
|
|
|
|
2022-06-30 05:24:05 +04:00
|
|
|
Result RegisterService(std::string name, u32 max_sessions,
|
|
|
|
Kernel::SessionRequestHandlerPtr handler);
|
|
|
|
Result UnregisterService(const std::string& name);
|
2021-05-06 06:45:54 +04:00
|
|
|
ResultVal<Kernel::KPort*> GetServicePort(const std::string& name);
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
template <Common::DerivedFrom<Kernel::SessionRequestHandler> T>
|
|
|
|
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-03 13:00:06 +04:00
|
|
|
return std::static_pointer_cast<T>(service->second);
|
2020-12-28 19:15:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void InvokeControlRequest(Kernel::HLERequestContext& context);
|
|
|
|
|
|
|
|
private:
|
2021-07-03 13:00:06 +04:00
|
|
|
std::shared_ptr<SM> sm_interface;
|
2020-12-28 19:15:37 +04:00
|
|
|
std::unique_ptr<Controller> controller_interface;
|
|
|
|
|
2021-05-06 06:45:54 +04:00
|
|
|
/// Map of registered services, retrieved using GetServicePort.
|
2021-07-03 13:00:06 +04:00
|
|
|
std::unordered_map<std::string, Kernel::SessionRequestHandlerPtr> registered_services;
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
/// Kernel context
|
|
|
|
Kernel::KernelCore& kernel;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Service::SM
|