am: rewrite ILockAccessor
This commit is contained in:
parent
87b740df46
commit
927fa532e5
@ -431,8 +431,6 @@ add_library(core STATIC
|
|||||||
hle/service/am/idle.h
|
hle/service/am/idle.h
|
||||||
hle/service/am/library_applet_storage.cpp
|
hle/service/am/library_applet_storage.cpp
|
||||||
hle/service/am/library_applet_storage.h
|
hle/service/am/library_applet_storage.h
|
||||||
hle/service/am/lock_accessor.cpp
|
|
||||||
hle/service/am/lock_accessor.h
|
|
||||||
hle/service/am/managed_layer_holder.cpp
|
hle/service/am/managed_layer_holder.cpp
|
||||||
hle/service/am/managed_layer_holder.h
|
hle/service/am/managed_layer_holder.h
|
||||||
hle/service/am/omm.cpp
|
hle/service/am/omm.cpp
|
||||||
@ -471,6 +469,8 @@ add_library(core STATIC
|
|||||||
hle/service/am/service/library_applet_proxy.h
|
hle/service/am/service/library_applet_proxy.h
|
||||||
hle/service/am/service/library_applet_self_accessor.cpp
|
hle/service/am/service/library_applet_self_accessor.cpp
|
||||||
hle/service/am/service/library_applet_self_accessor.h
|
hle/service/am/service/library_applet_self_accessor.h
|
||||||
|
hle/service/am/service/lock_accessor.cpp
|
||||||
|
hle/service/am/service/lock_accessor.h
|
||||||
hle/service/am/service/process_winding_controller.cpp
|
hle/service/am/service/process_winding_controller.cpp
|
||||||
hle/service/am/service/process_winding_controller.h
|
hle/service/am/service/process_winding_controller.h
|
||||||
hle/service/am/service/self_controller.cpp
|
hle/service/am/service/self_controller.cpp
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#include "core/hle/service/am/lock_accessor.h"
|
|
||||||
#include "core/hle/service/ipc_helpers.h"
|
|
||||||
|
|
||||||
namespace Service::AM {
|
|
||||||
|
|
||||||
ILockAccessor::ILockAccessor(Core::System& system_)
|
|
||||||
: ServiceFramework{system_, "ILockAccessor"}, service_context{system_, "ILockAccessor"} {
|
|
||||||
// clang-format off
|
|
||||||
static const FunctionInfo functions[] = {
|
|
||||||
{1, &ILockAccessor::TryLock, "TryLock"},
|
|
||||||
{2, &ILockAccessor::Unlock, "Unlock"},
|
|
||||||
{3, &ILockAccessor::GetEvent, "GetEvent"},
|
|
||||||
{4,&ILockAccessor::IsLocked, "IsLocked"},
|
|
||||||
};
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
RegisterHandlers(functions);
|
|
||||||
|
|
||||||
lock_event = service_context.CreateEvent("ILockAccessor::LockEvent");
|
|
||||||
}
|
|
||||||
|
|
||||||
ILockAccessor::~ILockAccessor() {
|
|
||||||
service_context.CloseEvent(lock_event);
|
|
||||||
};
|
|
||||||
|
|
||||||
void ILockAccessor::TryLock(HLERequestContext& ctx) {
|
|
||||||
IPC::RequestParser rp{ctx};
|
|
||||||
const auto return_handle = rp.Pop<bool>();
|
|
||||||
|
|
||||||
LOG_WARNING(Service_AM, "(STUBBED) called, return_handle={}", return_handle);
|
|
||||||
|
|
||||||
// TODO: When return_handle is true this function should return the lock handle
|
|
||||||
|
|
||||||
is_locked = true;
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 3};
|
|
||||||
rb.Push(ResultSuccess);
|
|
||||||
rb.Push<u8>(is_locked);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ILockAccessor::Unlock(HLERequestContext& ctx) {
|
|
||||||
LOG_INFO(Service_AM, "called");
|
|
||||||
|
|
||||||
is_locked = false;
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
|
||||||
rb.Push(ResultSuccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ILockAccessor::GetEvent(HLERequestContext& ctx) {
|
|
||||||
LOG_INFO(Service_AM, "called");
|
|
||||||
|
|
||||||
lock_event->Signal();
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
|
||||||
rb.Push(ResultSuccess);
|
|
||||||
rb.PushCopyObjects(lock_event->GetReadableEvent());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ILockAccessor::IsLocked(HLERequestContext& ctx) {
|
|
||||||
LOG_INFO(Service_AM, "called");
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
|
||||||
rb.Push(ResultSuccess);
|
|
||||||
rb.Push<u8>(is_locked);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Service::AM
|
|
@ -1,28 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "core/hle/service/kernel_helpers.h"
|
|
||||||
#include "core/hle/service/service.h"
|
|
||||||
|
|
||||||
namespace Service::AM {
|
|
||||||
|
|
||||||
class ILockAccessor final : public ServiceFramework<ILockAccessor> {
|
|
||||||
public:
|
|
||||||
explicit ILockAccessor(Core::System& system_);
|
|
||||||
~ILockAccessor() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void TryLock(HLERequestContext& ctx);
|
|
||||||
void Unlock(HLERequestContext& ctx);
|
|
||||||
void GetEvent(HLERequestContext& ctx);
|
|
||||||
void IsLocked(HLERequestContext& ctx);
|
|
||||||
|
|
||||||
bool is_locked{};
|
|
||||||
|
|
||||||
Kernel::KEvent* lock_event;
|
|
||||||
KernelHelpers::ServiceContext service_context;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Service::AM
|
|
@ -4,8 +4,8 @@
|
|||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "core/hle/service/am/am_results.h"
|
#include "core/hle/service/am/am_results.h"
|
||||||
#include "core/hle/service/am/applet.h"
|
#include "core/hle/service/am/applet.h"
|
||||||
#include "core/hle/service/am/lock_accessor.h"
|
|
||||||
#include "core/hle/service/am/service/common_state_getter.h"
|
#include "core/hle/service/am/service/common_state_getter.h"
|
||||||
|
#include "core/hle/service/am/service/lock_accessor.h"
|
||||||
#include "core/hle/service/apm/apm_interface.h"
|
#include "core/hle/service/apm/apm_interface.h"
|
||||||
#include "core/hle/service/cmif_serialization.h"
|
#include "core/hle/service/cmif_serialization.h"
|
||||||
#include "core/hle/service/pm/pm.h"
|
#include "core/hle/service/pm/pm.h"
|
||||||
|
75
src/core/hle/service/am/service/lock_accessor.cpp
Normal file
75
src/core/hle/service/am/service/lock_accessor.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "core/hle/service/am/service/lock_accessor.h"
|
||||||
|
#include "core/hle/service/cmif_serialization.h"
|
||||||
|
|
||||||
|
namespace Service::AM {
|
||||||
|
|
||||||
|
ILockAccessor::ILockAccessor(Core::System& system_)
|
||||||
|
: ServiceFramework{system_, "ILockAccessor"}, m_context{system_, "ILockAccessor"},
|
||||||
|
m_event{m_context} {
|
||||||
|
// clang-format off
|
||||||
|
static const FunctionInfo functions[] = {
|
||||||
|
{1, D<&ILockAccessor::TryLock>, "TryLock"},
|
||||||
|
{2, D<&ILockAccessor::Unlock>, "Unlock"},
|
||||||
|
{3, D<&ILockAccessor::GetEvent>, "GetEvent"},
|
||||||
|
{4, D<&ILockAccessor::IsLocked>, "IsLocked"},
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
|
m_event.Signal();
|
||||||
|
}
|
||||||
|
|
||||||
|
ILockAccessor::~ILockAccessor() = default;
|
||||||
|
|
||||||
|
Result ILockAccessor::TryLock(Out<bool> out_is_locked,
|
||||||
|
OutCopyHandle<Kernel::KReadableEvent> out_handle,
|
||||||
|
bool return_handle) {
|
||||||
|
LOG_INFO(Service_AM, "called, return_handle={}", return_handle);
|
||||||
|
|
||||||
|
{
|
||||||
|
std::scoped_lock lk{m_mutex};
|
||||||
|
if (m_is_locked) {
|
||||||
|
*out_is_locked = false;
|
||||||
|
} else {
|
||||||
|
m_is_locked = true;
|
||||||
|
*out_is_locked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (return_handle) {
|
||||||
|
*out_handle = m_event.GetHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result ILockAccessor::Unlock() {
|
||||||
|
LOG_INFO(Service_AM, "called");
|
||||||
|
|
||||||
|
{
|
||||||
|
std::scoped_lock lk{m_mutex};
|
||||||
|
m_is_locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_event.Signal();
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result ILockAccessor::GetEvent(OutCopyHandle<Kernel::KReadableEvent> out_handle) {
|
||||||
|
LOG_INFO(Service_AM, "called");
|
||||||
|
*out_handle = m_event.GetHandle();
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result ILockAccessor::IsLocked(Out<bool> out_is_locked) {
|
||||||
|
LOG_INFO(Service_AM, "called");
|
||||||
|
std::scoped_lock lk{m_mutex};
|
||||||
|
*out_is_locked = m_is_locked;
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Service::AM
|
32
src/core/hle/service/am/service/lock_accessor.h
Normal file
32
src/core/hle/service/am/service/lock_accessor.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/hle/service/cmif_types.h"
|
||||||
|
#include "core/hle/service/kernel_helpers.h"
|
||||||
|
#include "core/hle/service/os/event.h"
|
||||||
|
#include "core/hle/service/service.h"
|
||||||
|
|
||||||
|
namespace Service::AM {
|
||||||
|
|
||||||
|
class ILockAccessor final : public ServiceFramework<ILockAccessor> {
|
||||||
|
public:
|
||||||
|
explicit ILockAccessor(Core::System& system_);
|
||||||
|
~ILockAccessor() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Result TryLock(Out<bool> out_is_locked, OutCopyHandle<Kernel::KReadableEvent> out_handle,
|
||||||
|
bool return_handle);
|
||||||
|
Result Unlock();
|
||||||
|
Result GetEvent(OutCopyHandle<Kernel::KReadableEvent> out_handle);
|
||||||
|
Result IsLocked(Out<bool> out_is_locked);
|
||||||
|
|
||||||
|
private:
|
||||||
|
KernelHelpers::ServiceContext m_context;
|
||||||
|
Event m_event;
|
||||||
|
std::mutex m_mutex{};
|
||||||
|
bool m_is_locked{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Service::AM
|
Loading…
Reference in New Issue
Block a user