2020-04-19 23:04:05 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 20:36:02 +01:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2019-09-24 22:54:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-13 10:04:47 +02:00
|
|
|
#include <kernel/types/KSession.h>
|
2020-02-16 18:53:33 +01:00
|
|
|
#include <nce.h>
|
2019-09-24 22:54:27 +02:00
|
|
|
#include "base_service.h"
|
|
|
|
|
2019-11-16 21:20:08 +01:00
|
|
|
namespace skyline::service {
|
2019-09-24 22:54:27 +02:00
|
|
|
/**
|
|
|
|
* @brief The ServiceManager class manages passing IPC requests to the right Service and running event loops of Services
|
|
|
|
*/
|
|
|
|
class ServiceManager {
|
|
|
|
private:
|
|
|
|
const DeviceState &state; //!< The state of the device
|
2019-11-16 21:20:08 +01:00
|
|
|
std::unordered_map<Service, std::shared_ptr<BaseService>> serviceMap; //!< A mapping from a Service to the underlying object
|
2020-04-18 23:40:18 +02:00
|
|
|
Mutex mutex; //!< This mutex is used to ensure concurrent access to services doesn't cause crashes
|
2019-09-24 22:54:27 +02:00
|
|
|
|
2019-10-16 14:41:30 +02:00
|
|
|
/**
|
2020-03-24 21:17:31 +01:00
|
|
|
* @brief Creates an instance of the service if it doesn't already exist, otherwise returns an existing instance
|
2019-10-16 14:41:30 +02:00
|
|
|
* @param serviceType The type of service requested
|
|
|
|
* @return A shared pointer to an instance of the service
|
|
|
|
*/
|
2020-04-22 19:02:27 +02:00
|
|
|
std::shared_ptr<BaseService> CreateService(Service serviceType);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @param state The state of the device
|
|
|
|
*/
|
|
|
|
ServiceManager(const DeviceState &state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Creates a new service and returns it's handle
|
|
|
|
* @param serviceType The type of the service
|
|
|
|
* @return Handle to KService object of the service
|
|
|
|
*/
|
2020-04-22 19:02:27 +02:00
|
|
|
KHandle NewSession(Service serviceType);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
2019-10-16 22:23:35 +02:00
|
|
|
* @brief Creates a new service using it's type enum and writes it's handle or virtual handle (If it's a domain request) to IpcResponse
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
* @param serviceName The name of the service
|
2019-09-24 22:54:27 +02:00
|
|
|
* @param session The session object of the command
|
|
|
|
* @param response The response object to write the handle or virtual handle to
|
|
|
|
*/
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
std::shared_ptr<BaseService> NewService(const std::string &serviceName, type::KSession &session, ipc::IpcResponse &response);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
2019-10-16 22:23:35 +02:00
|
|
|
/**
|
|
|
|
* @brief Registers a service object in the manager and writes it's handle or virtual handle (If it's a domain request) to IpcResponse
|
|
|
|
* @param serviceObject An instance of the service
|
|
|
|
* @param session The session object of the command
|
|
|
|
* @param response The response object to write the handle or virtual handle to
|
2020-03-24 21:17:31 +01:00
|
|
|
* @param submodule If the registered service is a submodule or not
|
2019-10-16 22:23:35 +02:00
|
|
|
*/
|
2020-03-24 21:17:31 +01:00
|
|
|
void RegisterService(std::shared_ptr<BaseService> serviceObject, type::KSession &session, ipc::IpcResponse &response, bool submodule = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param serviceType The type of the service
|
|
|
|
* @tparam The class of the service
|
|
|
|
* @return A shared pointer to an instance of the service
|
|
|
|
* @note This only works for services created with `NewService` as sub-interfaces used with `RegisterService` can have multiple instances
|
|
|
|
*/
|
|
|
|
template<typename Type>
|
2020-04-22 19:02:27 +02:00
|
|
|
inline std::shared_ptr<Type> GetService(Service serviceType) {
|
2020-03-24 21:17:31 +01:00
|
|
|
return std::static_pointer_cast<Type>(serviceMap.at(serviceType));
|
|
|
|
}
|
2019-10-16 22:23:35 +02:00
|
|
|
|
2019-09-24 22:54:27 +02:00
|
|
|
/**
|
|
|
|
* @brief Closes an existing session to a service
|
|
|
|
* @param service The handle of the KService object
|
|
|
|
*/
|
2020-04-22 19:02:27 +02:00
|
|
|
void CloseSession(KHandle handle);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Handles a Synchronous IPC Request
|
|
|
|
* @param handle The handle of the object
|
|
|
|
*/
|
2020-04-22 19:02:27 +02:00
|
|
|
void SyncRequestHandler(KHandle handle);
|
2019-09-24 22:54:27 +02:00
|
|
|
};
|
|
|
|
}
|