service/sm: improve service manager implementation

- Reorder error codes to match numerical order
- Rename RegisterClient to Initialize in service registration
  to match actual function name
- Update function declaration order in header to match implementation
- Improve QueryPointerBufferSize implementation:
  * Add proper documentation comment
  * Use constexpr for maximum transfer memory size
  * Use std::numeric_limits where appropriate
  * Improve debug logging message
  * Use meaningful constant name

These changes improve code organization and clarity while making
the service manager interface more consistent with Nintendo's
official naming conventions.
This commit is contained in:
Zephyron 2025-02-08 19:50:28 +10:00
parent b89a85e228
commit e3128c6e98
No known key found for this signature in database
3 changed files with 9 additions and 7 deletions

View file

@ -18,11 +18,11 @@
namespace Service::SM { namespace Service::SM {
[[maybe_unused]] constexpr Result ResultNotAllowed(ErrorModule::SM, 1);
constexpr Result ResultInvalidClient(ErrorModule::SM, 2); constexpr Result ResultInvalidClient(ErrorModule::SM, 2);
constexpr Result ResultAlreadyRegistered(ErrorModule::SM, 4); constexpr Result ResultAlreadyRegistered(ErrorModule::SM, 4);
constexpr Result ResultInvalidServiceName(ErrorModule::SM, 6); constexpr Result ResultInvalidServiceName(ErrorModule::SM, 6);
constexpr Result ResultNotRegistered(ErrorModule::SM, 7); constexpr Result ResultNotRegistered(ErrorModule::SM, 7);
[[maybe_unused]] constexpr Result ResultNotAllowed(ErrorModule::SM, 1);
ServiceManager::ServiceManager(Kernel::KernelCore& kernel_) : kernel{kernel_} { ServiceManager::ServiceManager(Kernel::KernelCore& kernel_) : kernel{kernel_} {
controller_interface = std::make_unique<Controller>(kernel.System()); controller_interface = std::make_unique<Controller>(kernel.System());
@ -282,14 +282,14 @@ SM::SM(ServiceManager& service_manager_, Core::System& system_)
: ServiceFramework{system_, "sm:", 4}, : ServiceFramework{system_, "sm:", 4},
service_manager{service_manager_}, kernel{system_.Kernel()} { service_manager{service_manager_}, kernel{system_.Kernel()} {
RegisterHandlers({ RegisterHandlers({
{0, &SM::RegisterClient, "RegisterClient"}, {0, &SM::Initialize, "Initialize"},
{1, &SM::GetServiceCmif, "GetService"}, {1, &SM::GetServiceCmif, "GetService"},
{2, &SM::RegisterServiceCmif, "RegisterService"}, {2, &SM::RegisterServiceCmif, "RegisterService"},
{3, &SM::UnregisterService, "UnregisterService"}, {3, &SM::UnregisterService, "UnregisterService"},
{4, &SM::DetachClient, "DetachClient"}, {4, &SM::DetachClient, "DetachClient"},
}); });
RegisterHandlersTipc({ RegisterHandlersTipc({
{0, &SM::RegisterClient, "RegisterClient"}, {0, &SM::Initialize, "Initialize"},
{1, &SM::GetServiceTipc, "GetService"}, {1, &SM::GetServiceTipc, "GetService"},
{2, &SM::RegisterServiceTipc, "RegisterService"}, {2, &SM::RegisterServiceTipc, "RegisterService"},
{3, &SM::UnregisterService, "UnregisterService"}, {3, &SM::UnregisterService, "UnregisterService"},

View file

@ -38,8 +38,8 @@ public:
~SM() override; ~SM() override;
private: private:
void RegisterClient(HLERequestContext& ctx);
void Initialize(HLERequestContext& ctx); void Initialize(HLERequestContext& ctx);
void RegisterClient(HLERequestContext& ctx);
void GetServiceCmif(HLERequestContext& ctx); void GetServiceCmif(HLERequestContext& ctx);
void GetServiceTipc(HLERequestContext& ctx); void GetServiceTipc(HLERequestContext& ctx);
void RegisterServiceCmif(HLERequestContext& ctx); void RegisterServiceCmif(HLERequestContext& ctx);

View file

@ -13,6 +13,8 @@
#include "core/hle/service/server_manager.h" #include "core/hle/service/server_manager.h"
#include "core/hle/service/sm/sm_controller.h" #include "core/hle/service/sm/sm_controller.h"
#include <limits>
namespace Service::SM { namespace Service::SM {
void Controller::ConvertCurrentObjectToDomain(HLERequestContext& ctx) { void Controller::ConvertCurrentObjectToDomain(HLERequestContext& ctx) {
@ -68,13 +70,13 @@ void Controller::CloneCurrentObjectEx(HLERequestContext& ctx) {
} }
void Controller::QueryPointerBufferSize(HLERequestContext& ctx) { void Controller::QueryPointerBufferSize(HLERequestContext& ctx) {
LOG_DEBUG(Service, "called"); LOG_DEBUG(Service, "Querying maximum pointer buffer size");
u16 pointer_buffer_size = 0x8000; // Replace with the actual size if known constexpr u16 MAX_TRANSFER_MEMORY_SIZE = 0xFFFF;
IPC::ResponseBuilder rb{ctx, 3}; IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
rb.Push<u16>(pointer_buffer_size); rb.Push<u16>(MAX_TRANSFER_MEMORY_SIZE);
} }
// https://switchbrew.org/wiki/IPC_Marshalling // https://switchbrew.org/wiki/IPC_Marshalling