2020-12-28 19:15:37 +04:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "common/concepts.h"
|
2021-05-06 05:20:08 +04:00
|
|
|
#include "core/hle/kernel/client_port.h"
|
|
|
|
#include "core/hle/kernel/object.h"
|
|
|
|
#include "core/hle/kernel/server_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 05:20:08 +04:00
|
|
|
class ClientPort;
|
|
|
|
class ClientSession;
|
2020-12-28 19:15:37 +04:00
|
|
|
class KernelCore;
|
2021-05-06 05:20:08 +04:00
|
|
|
class ServerPort;
|
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:
|
|
|
|
explicit SM(std::shared_ptr<ServiceManager> service_manager_, Core::System& system_);
|
|
|
|
~SM() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Initialize(Kernel::HLERequestContext& ctx);
|
|
|
|
void GetService(Kernel::HLERequestContext& ctx);
|
|
|
|
void RegisterService(Kernel::HLERequestContext& ctx);
|
|
|
|
void UnregisterService(Kernel::HLERequestContext& ctx);
|
|
|
|
|
|
|
|
std::shared_ptr<ServiceManager> service_manager;
|
|
|
|
Kernel::KernelCore& kernel;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ServiceManager {
|
|
|
|
public:
|
|
|
|
static void InstallInterfaces(std::shared_ptr<ServiceManager> self, Core::System& system);
|
|
|
|
|
|
|
|
explicit ServiceManager(Kernel::KernelCore& kernel_);
|
|
|
|
~ServiceManager();
|
|
|
|
|
2021-05-06 05:20:08 +04:00
|
|
|
ResultVal<std::shared_ptr<Kernel::ServerPort>> RegisterService(std::string name,
|
|
|
|
u32 max_sessions);
|
2020-12-28 19:15:37 +04:00
|
|
|
ResultCode UnregisterService(const std::string& name);
|
2021-05-06 05:20:08 +04:00
|
|
|
ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name);
|
|
|
|
ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(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-05-06 05:20:08 +04:00
|
|
|
auto port = service->second->GetServerPort();
|
2020-12-28 19:15:37 +04:00
|
|
|
if (port == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-05-06 05:20:08 +04:00
|
|
|
return std::static_pointer_cast<T>(port->GetHLEHandler());
|
2020-12-28 19:15:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void InvokeControlRequest(Kernel::HLERequestContext& context);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::weak_ptr<SM> sm_interface;
|
|
|
|
std::unique_ptr<Controller> controller_interface;
|
|
|
|
|
2021-05-06 05:20:08 +04:00
|
|
|
/// Map of registered services, retrieved using GetServicePort or ConnectToService.
|
|
|
|
std::unordered_map<std::string, std::shared_ptr<Kernel::ClientPort>> registered_services;
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
/// Kernel context
|
|
|
|
Kernel::KernelCore& kernel;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Service::SM
|