mirror of
https://git.uzuy-edge.org/Uzuy-Edge/Uzuy
synced 2024-11-23 11:09:47 +00:00
refactor: Improve MM_U service code structure and reduce redundancy
- Modularized repeated patterns for request parsing and response building: - Created helper functions `ParseAndRespond`, `ParseSetAndRespond`, and `ParseGetAndRespond` for consistency and readability. - Introduced `LogStubCall` for logging stubbed functions to reduce redundancy. - Cleaned up `mm_u.h` by removing redundant enum assignments and replacing `typedef` with `using`. - Simplified and improved readability in `mm_u.cpp` by reducing duplicate code and centralizing response logic. - Ensured consistency and streamlined logic across all functions handling IPC requests.
This commit is contained in:
parent
d183dcf2b7
commit
04d4d59596
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 uzuy Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2024 Uzuy
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/logging/log.h"
|
||||
@ -11,8 +11,8 @@ namespace Service::MM {
|
||||
|
||||
class MM_U final : public ServiceFramework<MM_U> {
|
||||
public:
|
||||
explicit MM_U(Core::System& system_) : ServiceFramework{system_, "mm:u"} {
|
||||
// clang-format off
|
||||
explicit MM_U(Core::System& system_)
|
||||
: ServiceFramework{system_, "mm:u"} {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &MM_U::InitializeOld, "InitializeOld"},
|
||||
{1, &MM_U::FinalizeOld, "FinalizeOld"},
|
||||
@ -23,90 +23,96 @@ public:
|
||||
{6, &MM_U::SetAndWait, "SetAndWait"},
|
||||
{7, &MM_U::Get, "Get"},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
RegisterHandlers(functions);
|
||||
}
|
||||
|
||||
private:
|
||||
void InitializeOld(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_MM, "(STUBBED) called");
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
LogStubCall("InitializeOld");
|
||||
ParseAndRespond(ctx, ResultSuccess);
|
||||
}
|
||||
|
||||
void FinalizeOld(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_MM, "(STUBBED) called");
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
LogStubCall("FinalizeOld");
|
||||
ParseAndRespond(ctx, ResultSuccess);
|
||||
}
|
||||
|
||||
void SetAndWaitOld(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
min = rp.Pop<u32>();
|
||||
max = rp.Pop<u32>();
|
||||
LOG_DEBUG(Service_MM, "(STUBBED) called, min=0x{:X}, max=0x{:X}", min, max);
|
||||
|
||||
current = min;
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
LogStubCall("SetAndWaitOld");
|
||||
ParseSetAndRespond(ctx, ResultSuccess);
|
||||
}
|
||||
|
||||
void GetOld(HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_MM, "(STUBBED) called");
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(current);
|
||||
LogStubCall("GetOld");
|
||||
ParseGetAndRespond(ctx, ResultSuccess);
|
||||
}
|
||||
|
||||
void Initialize(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_MM, "(STUBBED) called");
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push<u32>(id); // Any non zero value
|
||||
LogStubCall("Initialize");
|
||||
ParseAndRespond(ctx, ResultSuccess, request_id);
|
||||
}
|
||||
|
||||
void Finalize(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_MM, "(STUBBED) called");
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
LogStubCall("Finalize");
|
||||
ParseAndRespond(ctx, ResultSuccess);
|
||||
}
|
||||
|
||||
void SetAndWait(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
u32 input_id = rp.Pop<u32>();
|
||||
min = rp.Pop<u32>();
|
||||
max = rp.Pop<u32>();
|
||||
LOG_DEBUG(Service_MM, "(STUBBED) called, input_id=0x{:X}, min=0x{:X}, max=0x{:X}", input_id,
|
||||
min, max);
|
||||
|
||||
current = min;
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
ParseSetAndRespond(ctx, ResultSuccess);
|
||||
}
|
||||
|
||||
void Get(HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_MM, "(STUBBED) called");
|
||||
LogStubCall("Get");
|
||||
ParseGetAndRespond(ctx, ResultSuccess);
|
||||
}
|
||||
|
||||
void LogStubCall(const char* function_name) const {
|
||||
LOG_WARNING(Service_MM, "(STUBBED) %s called", function_name);
|
||||
}
|
||||
|
||||
void ParseAndRespond(HLERequestContext& ctx, Result result, u32 extra_data = 0) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
module = rp.PopEnum<Module>();
|
||||
if (extra_data != 0) {
|
||||
request_id = rp.Pop<u32>();
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, extra_data ? 3 : 2};
|
||||
rb.Push(result);
|
||||
if (extra_data != 0) {
|
||||
rb.Push(extra_data);
|
||||
}
|
||||
}
|
||||
|
||||
void ParseSetAndRespond(HLERequestContext& ctx, Result result) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
request_id = rp.Pop<u32>();
|
||||
min = rp.Pop<Setting>();
|
||||
max = rp.Pop<Setting>();
|
||||
current = min;
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void ParseGetAndRespond(HLERequestContext& ctx, Result result) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
request_id = rp.Pop<u32>();
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
rb.Push(current);
|
||||
}
|
||||
|
||||
u32 min{0};
|
||||
u32 max{0};
|
||||
u32 current{0};
|
||||
u32 id{1};
|
||||
Module module{Module::TEST};
|
||||
Priority priority{0};
|
||||
Setting min{0}, max{0}, current{0};
|
||||
u32 request_id{0}, event_clear_mode{0};
|
||||
};
|
||||
|
||||
void LoopProcess(Core::System& system) {
|
||||
auto server_manager = std::make_unique<ServerManager>(system);
|
||||
|
||||
server_manager->RegisterNamedService("mm:u", std::make_shared<MM_U>(system));
|
||||
ServerManager::RunServer(std::move(server_manager));
|
||||
}
|
||||
|
@ -1,14 +1,31 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 uzuy Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2024 Uzuy
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Service::MM {
|
||||
|
||||
enum class Module : u32 {
|
||||
CPU = 0,
|
||||
GPU,
|
||||
EMC,
|
||||
SYS_BUS,
|
||||
M_SELECT,
|
||||
NVDEC,
|
||||
NVENC,
|
||||
NVJPG,
|
||||
TEST
|
||||
};
|
||||
|
||||
using Priority = u32;
|
||||
using Setting = u32;
|
||||
|
||||
void LoopProcess(Core::System& system);
|
||||
|
||||
} // namespace Service::MM
|
||||
|
Loading…
Reference in New Issue
Block a user