queue_ex.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Author: Sychov. A / 12/2020
  2. #ifndef QUEUE_EX_H
  3. #define QUEUE_EX_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include "app/queue/queue.h"
  8. ///
  9. /// \brief Initialize a queue linking the user buffer
  10. /// \param self Pointer to the queue.
  11. /// \param buffer Pointer to the user buffer to be used as storage
  12. /// \param capacity Capacity of the user buffer storage
  13. /// \return QUEUE_RC_NOERROR if no error or error code.
  14. ///
  15. static inline int queue_init(queue_t * self, void * buffer, int16_t capacity )
  16. {
  17. if( RINGBUF_RC_NO_ERROR == ringbuf_init( self, buffer, capacity ) )
  18. {
  19. return QUEUE_RC_NOERROR;
  20. }
  21. return QUEUE_RC_INIT_ERROR;
  22. }
  23. ///
  24. /// \brief Placing a dummy record to the end of the queue with specified size
  25. /// \param self Pointer to the queue.
  26. /// \param record Pointer to the record struct to place.
  27. /// \param payload Pointer to the trailing data payload following the record struct
  28. /// \details The record struct must specify the whole record size including the payload size
  29. /// in @record.size, while the @record.payload must specify only the payload size (@payload)
  30. /// \return QUEUE_RC_NOERROR if no error or error code.
  31. ///
  32. int queue_pushback_payload(queue_t * self, queue_record_t * record, const void * payload );
  33. ///
  34. /// \brief Getting a part of record with the payload from the queue without extracting.
  35. /// \param self Pointer to the record queue.
  36. /// \param record Pointer to the record to store.
  37. /// \param recordBufferSize Size of the struct to store a part of record (minimum is sizeof(record))
  38. /// \param payload Pointer to the payload to store.
  39. /// \param payloadBufferSize Size of the buffer to store a part of payload.
  40. /// \return Size of the peeked record on success, error code otherwise.
  41. ///
  42. int queue_peek_payload(const queue_t * self, queue_record_t * record, int16_t recordBufferSize, void * payload, int16_t payloadBufferSize );
  43. ///
  44. /// \brief Getting a part of record from the queue without extracting.
  45. /// \param self Pointer to the record queue.
  46. /// \param record Pointer to the record to store.
  47. /// \param size Size of the struct to store a part of record.
  48. /// \return Size of the peeked record on success, error code otherwise.
  49. ///
  50. int queue_peek_n(const queue_t * self, queue_record_t * record, int16_t partSize);
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif // QUEUE_EX_H