dataQueue.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * This file is part of the PikaPython project.
  3. * http://github.com/pikastech/pikapython
  4. *
  5. * MIT License
  6. *
  7. * Copyright (c) 2021 lyon liang6516@outlook.com
  8. * Copyright (c) 2023 Gorgon Meducer embedded_zhuroan@hotmail.comByte
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a
  11. * copy of this software and associated documentation files (the "Software"),
  12. * to deal in the Software without restriction, including without limitation
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14. * and/or sell copies of the Software, and to permit persons to whom the
  15. * Software is furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  26. * DEALINGS IN THE SOFTWARE.
  27. */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #ifndef __DATA_QUEUE__H
  32. #define __DATA_QUEUE__H
  33. #include "dataArgs.h"
  34. /*! \NOTE: Make sure #include "__pika_ooc.h" is close to the class definition
  35. */
  36. #if defined(__DATA_QUEUE_CLASS_IMPLEMENT__)
  37. #define __PLOOC_CLASS_IMPLEMENT__
  38. #undef __DATA_QUEUE_CLASS_IMPLEMENT__
  39. #endif
  40. #include "__pika_ooc.h"
  41. typedef struct ByteQueue ByteQueue;
  42. struct ByteQueue {
  43. private_member(uint8_t* buffer; uint16_t buffer_size;
  44. uint16_t head;
  45. uint16_t tail;
  46. uint16_t peek;
  47. uint16_t count;
  48. uint16_t peek_count;)
  49. };
  50. typedef Args Queue;
  51. Queue* New_queue(void);
  52. int32_t queue_deinit(Queue* queue);
  53. int32_t queue_pushInt(Queue* queue, int val);
  54. int32_t queue_pushFloat(Queue* queue, pika_float val);
  55. int32_t queue_pushStr(Queue* queue, char* str);
  56. int32_t queue_pushArg(Queue* queue, Arg* arg);
  57. char* fast_itoa(char* buf, uint32_t val);
  58. int64_t queue_popInt(Queue* queue);
  59. pika_float queue_popFloat(Queue* queue);
  60. char* queue_popStr(Queue* queue);
  61. Arg* queue_popArg(Queue* queue);
  62. Arg* queue_popArg_notDeinitArg(Queue* queue);
  63. int32_t queue_deinit_stack(Queue* queue);
  64. void queue_init(Queue* queue);
  65. ByteQueue* byteQueue_init(ByteQueue* queue,
  66. void* buffer,
  67. uint_fast16_t size,
  68. pika_bool is_queue_full);
  69. pika_bool byteQueue_readOne(ByteQueue* queue, uint8_t* byte_ptr);
  70. pika_bool byteQueue_peekOne(ByteQueue* queue, uint8_t* byte_ptr);
  71. void byteQueue_resetPeek(ByteQueue* queue);
  72. void byteQueue_dropAllPeeked(ByteQueue* queue);
  73. uint_fast16_t byteQueue_getPeekedNumber(ByteQueue* queue);
  74. uint_fast16_t byteQueue_peekAvailableCount(ByteQueue* queue);
  75. pika_bool byteQueue_writeOne(ByteQueue* queue, uint8_t byte);
  76. #endif
  77. #ifdef __cplusplus
  78. }
  79. #endif