6 changed files with 110 additions and 102 deletions
-
4src/core/CMakeLists.txt
-
71src/core/hle/service/am/lock_accessor.cpp
-
28src/core/hle/service/am/lock_accessor.h
-
2src/core/hle/service/am/service/common_state_getter.cpp
-
75src/core/hle/service/am/service/lock_accessor.cpp
-
32src/core/hle/service/am/service/lock_accessor.h
@ -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 |
|
||||
@ -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
|
||||
@ -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 |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue