6 #ifndef RADEMBEDDEDKERNEL_RAD_CPP_H
7 #define RADEMBEDDEDKERNEL_RAD_CPP_H
38 constexpr
Span() =
default;
42 constexpr T *
data()
const {
return data_; }
44 constexpr
size_t size()
const {
return size_; }
46 constexpr
bool empty()
const {
return size_ == 0; }
48 constexpr T&
operator[](
size_t index)
const {
return data_[index]; }
50 constexpr T *
begin()
const {
return data_; }
52 constexpr T *
end()
const {
return data_ + size_; }
59 template <
typename Handle,
void (*CloseFn)(Handle)>
65 explicit constexpr
UniqueHandle(Handle handle) : handle_(handle) {}
74 if (
this != &other)
reset(other.release());
78 constexpr Handle
get()
const {
return handle_; }
80 constexpr
explicit operator bool()
const {
return handle_ !=
nullptr; }
83 Handle handle = handle_;
88 void reset(Handle handle =
nullptr) {
89 if (handle_) CloseFn(handle_);
93 Handle handle_ =
nullptr;
163 const char *name_ =
nullptr;
RAII wrapper for rad_event_t.
Definition: rad_cpp.h:128
Event(bool signaled=false)
Create a kernel event with an optional initial signal state.
Definition: rad_cpp.h:131
rad_status_t status() const
Return construction status.
Definition: rad_cpp.h:137
rad_status_t reset()
Reset the event to unsignaled.
Definition: rad_cpp.h:143
~Event()
Destroy the event when it was created successfully.
Definition: rad_cpp.h:133
rad_status_t signal()
Signal the event.
Definition: rad_cpp.h:141
rad_status_t wait(uint32_t timeout_ms)
Wait for the event or timeout.
Definition: rad_cpp.h:139
RAII registration wrapper for rad_module_descriptor_t.
Definition: rad_cpp.h:150
Module(const rad_module_descriptor_t &descriptor)
Register a module descriptor and unregister it on destruction.
Definition: rad_cpp.h:153
rad_status_t status() const
Return registration status.
Definition: rad_cpp.h:161
~Module()
Unregister the module when registration succeeded.
Definition: rad_cpp.h:157
RAII wrapper for rad_mutex_t.
Definition: rad_cpp.h:106
~Mutex()
Destroy the kernel mutex when it was created successfully.
Definition: rad_cpp.h:111
Mutex()
Create a kernel mutex.
Definition: rad_cpp.h:109
rad_mutex_t native() const
Return the raw mutex handle.
Definition: rad_cpp.h:121
rad_status_t lock()
Lock the mutex.
Definition: rad_cpp.h:117
rad_status_t status() const
Return construction status.
Definition: rad_cpp.h:115
rad_status_t unlock()
Unlock the mutex.
Definition: rad_cpp.h:119
Non-owning contiguous span used by lightweight C++ integrations.
Definition: rad_cpp.h:35
constexpr Span(T *data, size_t size)
Create a span over data and size elements.
Definition: rad_cpp.h:40
constexpr size_t size() const
Return the number of elements in the span.
Definition: rad_cpp.h:44
constexpr Span()=default
Create an empty span.
constexpr bool empty() const
Return true when the span has no elements.
Definition: rad_cpp.h:46
constexpr T & operator[](size_t index) const
Return the element at index without bounds checks.
Definition: rad_cpp.h:48
constexpr T * data() const
Return the first element pointer, or nullptr for an empty span.
Definition: rad_cpp.h:42
constexpr T * end() const
Return an iterator pointer one past the final element.
Definition: rad_cpp.h:52
constexpr T * begin() const
Return an iterator pointer to the first element.
Definition: rad_cpp.h:50
Move-only RAII owner for nullable RADPx-OS handles.
Definition: rad_cpp.h:60
void reset(Handle handle=nullptr)
Close any current handle and optionally take a replacement.
Definition: rad_cpp.h:88
constexpr Handle get() const
Return the raw handle without releasing ownership.
Definition: rad_cpp.h:78
Handle release()
Release ownership and return the raw handle.
Definition: rad_cpp.h:82
constexpr UniqueHandle()=default
Create an empty owner.
UniqueHandle(UniqueHandle &&other) noexcept
Move ownership from another handle owner.
Definition: rad_cpp.h:71
UniqueHandle & operator=(UniqueHandle &&other) noexcept
Replace this owner with another owner's handle.
Definition: rad_cpp.h:73
~UniqueHandle()
Close the owned handle if present.
Definition: rad_cpp.h:67
constexpr UniqueHandle(Handle handle)
Take ownership of handle.
Definition: rad_cpp.h:65
constexpr bool failed(rad_status_t status)
Return true when a C API status is not RAD_STATUS_OK.
Definition: rad_cpp.h:31
constexpr bool succeeded(rad_status_t status)
Return true when a C API status is RAD_STATUS_OK.
Definition: rad_cpp.h:29
Status
C++ status enum mirroring rad_status_t values.
Definition: rad_cpp.h:16
@ not_initialized
Kernel or handle is not initialized.
@ ok
Operation completed successfully.
@ not_found
Requested object was not found.
@ already_exists
Object already exists.
@ timeout
Operation timed out.
@ not_supported
Backend does not support the operation.
@ no_memory
Allocation failed.
@ invalid_argument
Caller supplied an invalid argument.
Portable RADPx-OS kernel service ABI for RADLib and RADPx-OS targets.
rad_status_t rad_module_unregister(const char *name)
Public RADPx-OS kernel API entry point.
rad_status_t rad_mutex_unlock(rad_mutex_t mutex)
Public RADPx-OS kernel API entry point.
struct rad_mutex_handle * rad_mutex_t
Opaque handle type rad_mutex_t backed by rad_mutex_handle.
Definition: radkernel.h:1349
rad_status_t rad_event_create(rad_event_t *event, int initially_signaled)
Public RADPx-OS kernel API entry point.
rad_status_t rad_mutex_create(rad_mutex_t *mutex)
Public RADPx-OS kernel API entry point.
rad_status_t rad_module_register(const rad_module_descriptor_t *descriptor)
Public RADPx-OS kernel API entry point.
rad_status_t rad_mutex_lock(rad_mutex_t mutex)
Public RADPx-OS kernel API entry point.
rad_status_t rad_event_wait(rad_event_t event, uint32_t timeout_ms)
Public RADPx-OS kernel API entry point.
@ RAD_STATUS_NOT_INITIALIZED
RAD_STATUS_NOT_INITIALIZED.
Definition: radkernel.h:151
@ RAD_STATUS_ERROR
RAD_STATUS_ERROR.
Definition: radkernel.h:144
@ RAD_STATUS_NO_MEMORY
RAD_STATUS_NO_MEMORY.
Definition: radkernel.h:147
@ RAD_STATUS_NOT_SUPPORTED
RAD_STATUS_NOT_SUPPORTED.
Definition: radkernel.h:149
@ RAD_STATUS_NOT_FOUND
RAD_STATUS_NOT_FOUND.
Definition: radkernel.h:146
@ RAD_STATUS_ALREADY_EXISTS
RAD_STATUS_ALREADY_EXISTS.
Definition: radkernel.h:150
@ RAD_STATUS_INVALID_ARGUMENT
RAD_STATUS_INVALID_ARGUMENT.
Definition: radkernel.h:145
@ RAD_STATUS_TIMEOUT
RAD_STATUS_TIMEOUT.
Definition: radkernel.h:148
@ RAD_STATUS_OK
RAD_STATUS_OK.
Definition: radkernel.h:143
rad_status_t rad_event_signal(rad_event_t event)
Public RADPx-OS kernel API entry point.
rad_status_t rad_event_reset(rad_event_t event)
Public RADPx-OS kernel API entry point.
void rad_event_destroy(rad_event_t event)
Public RADPx-OS kernel API entry point.
struct rad_event_handle * rad_event_t
Opaque handle type rad_event_t backed by rad_event_handle.
Definition: radkernel.h:1351
void rad_mutex_destroy(rad_mutex_t mutex)
Public RADPx-OS kernel API entry point.
enum rad_status rad_status_t
Public enumeration for rad_status.
Public data structure for rad_module_descriptor.
Definition: radkernel.h:1143