Atmosphere/libraries/libstratosphere/include/stratosphere/os/os_message_queue.hpp

102 lines
3.3 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 09:21:35 +00:00
#include <stratosphere/os/os_message_queue_common.hpp>
#include <stratosphere/os/os_message_queue_types.hpp>
#include <stratosphere/os/os_message_queue_api.hpp>
namespace ams::os {
class MessageQueue {
NON_COPYABLE(MessageQueue);
NON_MOVEABLE(MessageQueue);
private:
2021-10-10 07:14:06 +00:00
MessageQueueType m_mq;
2020-04-08 09:21:35 +00:00
public:
explicit MessageQueue(uintptr_t *buf, size_t count) {
2021-10-10 07:14:06 +00:00
InitializeMessageQueue(std::addressof(m_mq), buf, count);
}
2021-10-10 07:14:06 +00:00
~MessageQueue() { FinalizeMessageQueue(std::addressof(m_mq)); }
2020-04-08 09:21:35 +00:00
/* Sending (FIFO functionality) */
void Send(uintptr_t data) {
2021-10-10 07:14:06 +00:00
return SendMessageQueue(std::addressof(m_mq), data);
2020-04-08 09:21:35 +00:00
}
2020-04-08 09:21:35 +00:00
bool TrySend(uintptr_t data) {
2021-10-10 07:14:06 +00:00
return TrySendMessageQueue(std::addressof(m_mq), data);
2020-04-08 09:21:35 +00:00
}
2020-04-08 09:21:35 +00:00
bool TimedSend(uintptr_t data, TimeSpan timeout) {
2021-10-10 07:14:06 +00:00
return TimedSendMessageQueue(std::addressof(m_mq), data, timeout);
2020-04-08 09:21:35 +00:00
}
/* Jamming (LIFO functionality) */
void Jam(uintptr_t data) {
2021-10-10 07:14:06 +00:00
return JamMessageQueue(std::addressof(m_mq), data);
2020-04-08 09:21:35 +00:00
}
bool TryJam(uintptr_t data) {
2021-10-10 07:14:06 +00:00
return TryJamMessageQueue(std::addressof(m_mq), data);
2020-04-08 09:21:35 +00:00
}
bool TimedJam(uintptr_t data, TimeSpan timeout) {
2021-10-10 07:14:06 +00:00
return TimedJamMessageQueue(std::addressof(m_mq), data, timeout);
2020-04-08 09:21:35 +00:00
}
/* Receive functionality */
2020-04-08 09:21:35 +00:00
void Receive(uintptr_t *out) {
2021-10-10 07:14:06 +00:00
return ReceiveMessageQueue(out, std::addressof(m_mq));
2020-04-08 09:21:35 +00:00
}
bool TryReceive(uintptr_t *out) {
2021-10-10 07:14:06 +00:00
return TryReceiveMessageQueue(out, std::addressof(m_mq));
2020-04-08 09:21:35 +00:00
}
bool TimedReceive(uintptr_t *out, TimeSpan timeout) {
2021-10-10 07:14:06 +00:00
return TimedReceiveMessageQueue(out, std::addressof(m_mq), timeout);
2020-04-08 09:21:35 +00:00
}
/* Peek functionality */
2020-04-08 09:21:35 +00:00
void Peek(uintptr_t *out) const {
2021-10-10 07:14:06 +00:00
return PeekMessageQueue(out, std::addressof(m_mq));
2020-04-08 09:21:35 +00:00
}
bool TryPeek(uintptr_t *out) const {
2021-10-10 07:14:06 +00:00
return TryPeekMessageQueue(out, std::addressof(m_mq));
2020-04-08 09:21:35 +00:00
}
bool TimedPeek(uintptr_t *out, TimeSpan timeout) const {
2021-10-10 07:14:06 +00:00
return TimedPeekMessageQueue(out, std::addressof(m_mq), timeout);
2020-04-08 09:21:35 +00:00
}
operator MessageQueueType &() {
2021-10-10 07:14:06 +00:00
return m_mq;
2020-04-08 09:21:35 +00:00
}
operator const MessageQueueType &() const {
2021-10-10 07:14:06 +00:00
return m_mq;
2020-04-08 09:21:35 +00:00
}
MessageQueueType *GetBase() {
2021-10-10 07:14:06 +00:00
return std::addressof(m_mq);
2020-04-08 09:21:35 +00:00
}
};
}