oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
queue.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
14#pragma once
15
16#include <ove/queue.h>
17#include <ove/types.hpp>
18
19#ifdef CONFIG_OVE_QUEUE
20
21namespace ove {
22
42template <typename T, size_t MaxItems = 0>
43class Queue {
44public:
51 Queue() requires (MaxItems > 0) {
52#ifdef CONFIG_OVE_ZERO_HEAP
53 static_assert(MaxItems > 0,
54 "MaxItems must be > 0 in zero-heap mode");
55 int err = ove_queue_init(&handle_, &storage_,
56 buffer_, sizeof(T), MaxItems);
57#else
58 int err = ove_queue_create(&handle_, sizeof(T), MaxItems);
59#endif
60 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
61 }
62
67 if (!handle_) return;
68#ifdef CONFIG_OVE_ZERO_HEAP
69 ove_queue_deinit(handle_);
70#else
71 ove_queue_destroy(handle_);
72#endif
73 }
74
75 Queue(const Queue &) = delete;
76 Queue &operator=(const Queue &) = delete;
77
78#ifdef CONFIG_OVE_ZERO_HEAP
79 Queue(Queue &&) = delete;
80 Queue &operator=(Queue &&) = delete;
81#else
86 Queue(Queue &&other) noexcept : handle_(other.handle_) {
87 other.handle_ = nullptr;
88 }
89
95 Queue &operator=(Queue &&other) noexcept {
96 if (this != &other) {
97 if (handle_) ove_queue_destroy(handle_);
98 handle_ = other.handle_;
99 other.handle_ = nullptr;
100 }
101 return *this;
102 }
103#endif
104
112 [[nodiscard]] int send(const T &item,
113 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
114 return ove_queue_send(handle_, &item, timeout_ms);
115 }
116
124 [[nodiscard]] int receive(T *item,
125 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
126 return ove_queue_receive(handle_, item, timeout_ms);
127 }
128
134 [[nodiscard]] int send_from_isr(const T &item) {
135 return ove_queue_send_from_isr(handle_, &item);
136 }
137
143 [[nodiscard]] int receive_from_isr(T *item) {
144 return ove_queue_receive_from_isr(handle_, item);
145 }
146
151 bool valid() const { return handle_ != nullptr; }
152
157 ove_queue_t handle() const { return handle_; }
158
159private:
160 ove_queue_t handle_ = nullptr;
161#ifdef CONFIG_OVE_ZERO_HEAP
162 ove_queue_storage_t storage_ = {};
163 T buffer_[MaxItems > 0 ? MaxItems : 1];
164#endif
165};
166
167} // namespace ove
168
169#endif /* CONFIG_OVE_QUEUE */
RAII wrapper around an oveRTOS typed message queue.
Definition queue.hpp:43
int send_from_isr(const T &item)
Sends an item to the queue from an ISR context (non-blocking).
Definition queue.hpp:134
ove_queue_t handle() const
Returns the raw oveRTOS queue handle.
Definition queue.hpp:157
int receive_from_isr(T *item)
Receives an item from the queue from an ISR context (non-blocking).
Definition queue.hpp:143
Queue()
Constructs and initialises the queue.
Definition queue.hpp:51
~Queue()
Destroys the queue, releasing the underlying kernel resource.
Definition queue.hpp:66
Queue & operator=(Queue &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition queue.hpp:95
Queue(Queue &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition queue.hpp:86
int receive(T *item, uint32_t timeout_ms=OVE_WAIT_FOREVER)
Receives an item from the front of the queue from task context.
Definition queue.hpp:124
int send(const T &item, uint32_t timeout_ms=OVE_WAIT_FOREVER)
Sends an item to the back of the queue from task context.
Definition queue.hpp:112
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition queue.hpp:151
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
Common type definitions and concepts for the C++ wrapper layer.