1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-26 04:06:03 +00:00
Atmosphere/libraries/libstratosphere/include/stratosphere/os/os_system_event.hpp

114 lines
4.5 KiB
C++
Raw Normal View History

/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
2020-04-08 10:21:35 +01:00
#include <stratosphere/os/os_event_common.hpp>
#include <stratosphere/os/os_system_event_types.hpp>
#include <stratosphere/os/os_system_event_api.hpp>
namespace ams::os {
class SystemEvent {
NON_COPYABLE(SystemEvent);
NON_MOVEABLE(SystemEvent);
private:
2021-10-10 08:14:06 +01:00
SystemEventType m_system_event;
public:
2020-04-08 10:21:35 +01:00
SystemEvent() {
2021-10-10 08:14:06 +01:00
m_system_event.state = SystemEventType::State_NotInitialized;
2020-04-08 10:21:35 +01:00
}
explicit SystemEvent(EventClearMode clear_mode, bool inter_process) {
2021-10-10 08:14:06 +01:00
R_ABORT_UNLESS(CreateSystemEvent(std::addressof(m_system_event), clear_mode, inter_process));
2020-04-08 10:21:35 +01:00
}
explicit SystemEvent(NativeHandle read_handle, bool manage_read_handle, NativeHandle write_handle, bool manage_write_handle, EventClearMode clear_mode) {
2021-10-10 08:14:06 +01:00
AttachSystemEvent(std::addressof(m_system_event), read_handle, manage_read_handle, write_handle, manage_write_handle, clear_mode);
2020-04-08 10:21:35 +01:00
}
~SystemEvent() {
2021-10-10 08:14:06 +01:00
if (m_system_event.state == SystemEventType::State_NotInitialized) {
2020-04-08 10:21:35 +01:00
return;
}
2021-10-10 08:14:06 +01:00
DestroySystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
void Attach(NativeHandle read_handle, bool manage_read_handle, NativeHandle write_handle, bool manage_write_handle, EventClearMode clear_mode) {
2021-10-10 08:14:06 +01:00
AMS_ABORT_UNLESS(m_system_event.state == SystemEventType::State_NotInitialized);
return AttachSystemEvent(std::addressof(m_system_event), read_handle, manage_read_handle, write_handle, manage_write_handle, clear_mode);
2020-04-08 10:21:35 +01:00
}
void AttachReadableHandle(NativeHandle read_handle, bool manage_read_handle, EventClearMode clear_mode) {
2021-10-10 08:14:06 +01:00
AMS_ABORT_UNLESS(m_system_event.state == SystemEventType::State_NotInitialized);
return AttachReadableHandleToSystemEvent(std::addressof(m_system_event), read_handle, manage_read_handle, clear_mode);
2020-04-08 10:21:35 +01:00
}
void AttachWritableHandle(NativeHandle write_handle, bool manage_write_handle, EventClearMode clear_mode) {
2021-10-10 08:14:06 +01:00
AMS_ABORT_UNLESS(m_system_event.state == SystemEventType::State_NotInitialized);
return AttachWritableHandleToSystemEvent(std::addressof(m_system_event), write_handle, manage_write_handle, clear_mode);
2020-04-08 10:21:35 +01:00
}
NativeHandle DetachReadableHandle() {
2021-10-10 08:14:06 +01:00
return DetachReadableHandleOfSystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
NativeHandle DetachWritableHandle() {
2021-10-10 08:14:06 +01:00
return DetachWritableHandleOfSystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
void Wait() {
2021-10-10 08:14:06 +01:00
return WaitSystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
bool TryWait() {
2021-10-10 08:14:06 +01:00
return TryWaitSystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
bool TimedWait(TimeSpan timeout) {
2021-10-10 08:14:06 +01:00
return TimedWaitSystemEvent(std::addressof(m_system_event), timeout);
2020-04-08 10:21:35 +01:00
}
void Signal() {
2021-10-10 08:14:06 +01:00
return SignalSystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
void Clear() {
2021-10-10 08:14:06 +01:00
return ClearSystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
NativeHandle GetReadableHandle() const {
2021-10-10 08:14:06 +01:00
return GetReadableHandleOfSystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
NativeHandle GetWritableHandle() const {
2021-10-10 08:14:06 +01:00
return GetWritableHandleOfSystemEvent(std::addressof(m_system_event));
2020-04-08 10:21:35 +01:00
}
operator SystemEventType &() {
2021-10-10 08:14:06 +01:00
return m_system_event;
2020-04-08 10:21:35 +01:00
}
operator const SystemEventType &() const {
2021-10-10 08:14:06 +01:00
return m_system_event;
2020-04-08 10:21:35 +01:00
}
SystemEventType *GetBase() {
2021-10-10 08:14:06 +01:00
return std::addressof(m_system_event);
2020-04-08 10:21:35 +01:00
}
};
}