2019-12-09 11:57:37 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-12-09 11:57:37 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
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);
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 07:14:06 +00:00
|
|
|
~MessageQueue() { FinalizeMessageQueue(std::addressof(m_mq)); }
|
2019-12-09 11:57:37 +00:00
|
|
|
|
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
|
|
|
}
|
2019-12-09 11:57:37 +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
|
|
|
}
|
2019-12-09 11:57:37 +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
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2021-09-29 19:24:18 +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
|
|
|
}
|
|
|
|
|
2021-09-29 19:24:18 +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
|
|
|
}
|
|
|
|
|
2021-09-29 19:24:18 +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
|
|
|
}
|
2019-12-09 11:57:37 +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
|
|
|
}
|
2019-12-09 11:57:37 +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
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|