SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
msgq.hpp
Go to the documentation of this file.
1/*
2 * SatNOGS-COMMS control library
3 *
4 * Copyright (C) 2024, Libre Space Foundation <http://libre.space>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GNU General Public License v3.0 or later
20 */
21
22#pragma once
23
24#include <cstdint>
25#include <cstdlib>
26
28{
41template <typename T> class imsgq
42{
43public:
49 imsgq(size_t len) : m_len(len) {}
50
51 imsgq(const imsgq &) = delete;
52
58 size_t
59 max_size() const
60 {
61 return m_len;
62 }
63
72 virtual size_t
73 size() = 0;
74
84 virtual int
85 put(const T &msg, size_t timeout_ms) = 0;
86
95 virtual int
96 put_isr(const T &msg) = 0;
97
106 virtual int
107 peek(T *msg) = 0;
108
118 virtual int
119 get(T *msg, size_t timeout_ms) = 0;
120
129 virtual int
130 get_isr(T *msg) = 0;
131
132protected:
133 const size_t m_len;
134};
135
151template <typename T, const size_t LEN> class msgq : public imsgq<T>
152{
153public:
154 msgq() : imsgq<T>(LEN) {}
155};
156} // namespace satnogs::comms::lib::bsp
virtual size_t size()=0
A virtual method that returns the current number of messages in the queue.
size_t max_size() const
A method that returns the maximum size of the message queue.
Definition msgq.hpp:59
imsgq(size_t len)
Constructs an imsgq object with a specified maximum size.
Definition msgq.hpp:49
virtual int peek(T *msg)=0
A virtual method that peeks at the next message in the queue without removing it.
virtual int put_isr(const T &msg)=0
A virtual method that enqueues a message into the queue from an interrupt context.
virtual int get_isr(T *msg)=0
A virtual method that retrieves a message from the queue from an interrupt context.
imsgq(const imsgq &)=delete
virtual int get(T *msg, size_t timeout_ms)=0
A virtual method that retrieves a message from the queue.
virtual int put(const T &msg, size_t timeout_ms)=0
A virtual method that enqueues a message into the queue.