27#ifndef JUNO_BUFF_QUEUE_API_H
28#define JUNO_BUFF_QUEUE_API_H
58 ptQueueRoot->iStartIndex = 0;
59 ptQueueRoot->zLength = 0;
60 ptQueueRoot->zCapacity = zCapacity;
61 ptQueueRoot->_pfcnFailureHandler = pfcnFailureHdlr;
62 ptQueueRoot->_pvFailureUserData = pvFailureUserData;
77 if(ptQueueRoot->zLength < ptQueueRoot->zCapacity)
79 tResult.tOk = (ptQueueRoot->iStartIndex + ptQueueRoot->zLength) % ptQueueRoot->zCapacity;
80 ptQueueRoot->zLength += 1;
85 JUNO_FAIL(tResult.tStatus, ptQueueRoot->_pfcnFailureHandler, ptQueueRoot->_pvFailureUserData,
"Failed to enqueue data");
102 if(ptQueueRoot->zLength > 0)
104 tResult.tOk = ptQueueRoot->iStartIndex;
105 ptQueueRoot->iStartIndex = (ptQueueRoot->iStartIndex + 1) % ptQueueRoot->zCapacity;
106 ptQueueRoot->zLength -= 1;
110 JUNO_FAIL(tResult.tStatus, ptQueueRoot->_pfcnFailureHandler, ptQueueRoot->_pvFailureUserData,
"Queue is empty");
125 if(ptQueueRoot->zLength == 0)
128 JUNO_FAIL(tResult.tStatus, ptQueueRoot->_pfcnFailureHandler, ptQueueRoot->_pvFailureUserData,
"Failed to enqueue data");
131 tResult.tOk = ptQueueRoot->iStartIndex;
static JUNO_RESULT_SIZE_T JunoBuff_QueueDequeue(JUNO_BUFF_QUEUE_T *ptQueue)
Definition buff_queue_api.h:93
static JUNO_RESULT_SIZE_T JunoBuff_QueueEnqueue(JUNO_BUFF_QUEUE_T *ptQueue)
Definition buff_queue_api.h:68
static JUNO_RESULT_SIZE_T JunoBuff_QueuePeek(JUNO_BUFF_QUEUE_T *ptQueue)
Definition buff_queue_api.h:116
union JUNO_BUFF_QUEUE_T JUNO_BUFF_QUEUE_T
The Buffer queue module.
Definition buff_queue_api.h:41
struct JUNO_BUFF_QUEUE_ROOT_TAG JUNO_BUFF_QUEUE_ROOT_T
The Buffer queue root.
Definition buff_queue_api.h:39
static JUNO_STATUS_T JunoBuff_QueueInit(JUNO_BUFF_QUEUE_T *ptQueue, size_t zCapacity, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData)
Initialize a buffer queue with a capacity.
Definition buff_queue_api.h:54
#define JUNO_ASSERT_EXISTS(ptr)
Definition macros.h:28
#define JUNO_MODULE_ROOT(API_T,...)
Definition module.h:182
#define JUNO_STATUS_ERR
Definition status.h:25
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Definition status.h:43
int32_t JUNO_STATUS_T
Definition status.h:23
#define JUNO_FAIL(tStatus, pfcnFailureHandler, pvFailureUserData, pcMessage)
Definition status.h:48
#define JUNO_STATUS_NULLPTR_ERROR
Definition status.h:26
#define JUNO_STATUS_INVALID_SIZE_ERROR
Definition status.h:30
#define JUNO_STATUS_SUCCESS
Definition status.h:24
void JUNO_USER_DATA_T
Definition status.h:42