1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #include <stdint.h>
6 #include <k_api.h>
7 
8 /** @defgroup cpp_aos_queue
9  *  @ingroup cpp_aos_api
10  * @{
11  */
12 namespace AOS {
13 
14 #define Queue_WAIT_FOREVER 0xFFFFFFFFU
15 
16 /**
17  * @brief Queue Class.
18  *
19  */
20 
21     class Queue
22     {
23       public:
24         /**
25          * @brief This function will create a buf-queue
26          * @param[in]  name     name of the queue
27          * @param[in]  buf      pointer to the buf
28          * @param[in]  size     size of the buf
29          * @param[in]  max_msg  max size of one msg
30          * @return  the operation status, RHINO_SUCCESS is OK, others is error
31          */
32         kstat_t create(const name_t *name, void *buf, size_t size,
33                        size_t max_msg);
34 
35         /**
36          * @brief This function will delete a queue
37          * @param[in]  NULL
38          * @return  the operation status, RHINO_SUCCESS is OK, others is error
39          */
40         kstat_t destory(void);
41 
42         /**
43          * @brief This function will send a msg at the end of queue
44          * @param[in]  msg    pointer to msg to be send
45          * @param[in]  size   size of the msg
46          * @return  the operation status, RHINO_SUCCESS is OK, others is error
47          */
48         kstat_t send(void *msg, size_t size);
49 
50         /**
51          * @brief This function will receive msg form aqueue
52          * @param[out]  msg    pointer to the buf to save msg
53          * @param[out]  size   size of received msg
54          * @param[in]   millisec  millisec to wait before receiving msg
55          * @return  the operation status, RHINO_SUCCESS is OK, others is error
56          */
57         kstat_t receive(void *msg, size_t *size, uint32_t millisec);
58 
59         /**
60          * @brief This function will reset queue
61          * @param[in]  NULL
62          * @return  the operation status, RHINO_SUCCESS is OK, others is error
63          */
64         kstat_t flush(void);
65 
66         /**
67          * @brief This function will get information of a queue
68          * @param[out]  free   free size of the queue buf
69          * @param[out]  total  total size of the queue buf
70          * @return  the operation status, RHINO_SUCCESS is OK, others is error
71          */
72         kstat_t info_get(kbuf_queue_info_t *info);
73 
74         /**
75          * @brief This function will get a Queue struct pointer
76          * @param[in]  none
77          * @return  Queue struct pointer
78          */
79         kbuf_queue_t *self(void);
80 
81       private:
82         /**
83          * @brief a Queue buffer
84          */
85         kbuf_queue_t _buf_queue_def;
86     };
87 
88 }
89 /**
90  * @}
91  */
92