LibJuno 1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
queue_api.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17
51#ifndef JUNO_DS_QUEUE_API_H
52#define JUNO_DS_QUEUE_API_H
53#include "juno/ds/array_api.h"
54#include "juno/macros.h"
56#include "juno/status.h"
57#include "juno/module.h"
58#include <stddef.h>
59#ifdef __cplusplus
60extern "C"
61{
62#endif
63
65typedef struct JUNO_DS_QUEUE_ROOT_TAG JUNO_DS_QUEUE_ROOT_T;
67
69
73struct JUNO_DS_QUEUE_ROOT_TAG JUNO_MODULE_ROOT(JUNO_DS_QUEUE_API_T,
74 JUNO_DS_ARRAY_ROOT_T *ptQueueArray;
75 size_t iStartIndex;
76 size_t zLength;
77);
78
100
105{
107 ptQueueApi &&
108 ptQueueApi->Enqueue &&
109 ptQueueApi->Dequeue &&
110 ptQueueApi->Peek
111 );
112 return JUNO_STATUS_SUCCESS;
113}
114
116// @{"req": ["REQ-QUEUE-001"]}
118{
119 JUNO_ASSERT_EXISTS(ptQueue);
120 JUNO_STATUS_T tStatus = JunoDs_ArrayVerify(ptQueue->ptQueueArray);
121 JUNO_ASSERT_SUCCESS(tStatus, return tStatus);
122 return JunoDs_QueueApiVerify(ptQueue->ptApi);
123}
124
130JUNO_RESULT_POINTER_T JunoDs_QueuePeek(JUNO_DS_QUEUE_ROOT_T *ptQueue);
131
138JUNO_STATUS_T JunoDs_QueueInit(JUNO_DS_QUEUE_ROOT_T *ptQueue, JUNO_DS_ARRAY_ROOT_T *ptQueueArray, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData);
139
140#ifdef __cplusplus
141}
142#endif
143#endif // JUNO_DS_QUEUE_API_H
Abstract fixed-capacity array interface for DS modules.
struct JUNO_DS_ARRAY_ROOT_TAG JUNO_DS_ARRAY_ROOT_T
Opaque array root carrying capacity and API pointer.
Definition array_api.h:58
static JUNO_STATUS_T JunoDs_ArrayVerify(const JUNO_DS_ARRAY_ROOT_T *ptArray)
Verify an array instance's capacity and API.
Definition array_api.h:121
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:51
#define JUNO_ASSERT_SUCCESS(tStatus,...)
Execute the provided failure operation(s) if status is not success.
Definition macros.h:89
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:129
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:59
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Failure handler callback signature.
Definition status.h:110
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:51
void JUNO_USER_DATA_T
Opaque user data type for failure callbacks.
Definition status.h:101
Common assertion and helper macros for LibJuno modules.
Module system and dependency injection primitives for LibJuno.
Pointer trait and helpers for memory operations.
struct JUNO_POINTER_TAG JUNO_POINTER_T
Definition pointer_api.h:49
JUNO_STATUS_T JunoDs_QueueInit(JUNO_DS_QUEUE_ROOT_T *ptQueue, JUNO_DS_ARRAY_ROOT_T *ptQueueArray, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData)
Initialize a queue over a backing array with a given capacity.
Definition juno_buff_queue.c:107
static JUNO_STATUS_T JunoDs_QueueApiVerify(const JUNO_DS_QUEUE_API_T *ptQueueApi)
Verify that the queue API provides all required functions.
Definition queue_api.h:104
JUNO_STATUS_T JunoDs_QueuePop(JUNO_DS_QUEUE_ROOT_T *ptQueue, JUNO_POINTER_T tReturn)
Dequeue the item at the front of the queue into tReturn (O(1)).
Definition juno_buff_queue.c:51
struct JUNO_DS_QUEUE_ROOT_TAG JUNO_DS_QUEUE_ROOT_T
The queue root module.
Definition queue_api.h:65
static JUNO_STATUS_T JunoDs_QueueVerify(const JUNO_DS_QUEUE_ROOT_T *ptQueue)
Verify a queue instance and its API table.
Definition queue_api.h:117
JUNO_RESULT_POINTER_T JunoDs_QueuePeek(JUNO_DS_QUEUE_ROOT_T *ptQueue)
Peek at the item at the front without removing it (O(1)).
Definition juno_buff_queue.c:79
JUNO_STATUS_T JunoDs_QueuePush(JUNO_DS_QUEUE_ROOT_T *ptQueue, JUNO_POINTER_T tItem)
Enqueue an item to the back of the queue (O(1)).
Definition juno_buff_queue.c:25
Status codes and failure-handling helpers for LibJuno.
Queue API vtable.
Definition queue_api.h:84
JUNO_STATUS_T(* Enqueue)(JUNO_DS_QUEUE_ROOT_T *ptQueue, JUNO_POINTER_T tItem)
Enqueue an item to the back of the queue.
Definition queue_api.h:89
JUNO_RESULT_POINTER_T(* Peek)(JUNO_DS_QUEUE_ROOT_T *ptQueue)
Peek at the item at the front without removing it.
Definition queue_api.h:98
JUNO_STATUS_T(* Dequeue)(JUNO_DS_QUEUE_ROOT_T *ptQueue, JUNO_POINTER_T tReturn)
Dequeue the item at the front of the queue.
Definition queue_api.h:94