• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef C_QUEUE_H
16 #define C_QUEUE_H 1
17 
18 #if defined(__cplusplus)
19 extern "C" {
20 #endif
21 
22 enum {
23     CQ_OK = 0,
24     CQ_ERR,
25 };
26 
27 typedef unsigned char CQItemType;
28 
29 typedef struct __CQueue
30 {
31     int read;
32     int write;
33     int size;
34     int len;
35     CQItemType *base;
36 } CQueue;
37 
38 typedef uint16_t (*FRAME_LEN_GETTER_T)(CQueue* q);
39 
40 /* Init Queue */
41 int InitCQueue(CQueue *Q, unsigned int size, CQItemType *buf);
42 /* Is Queue Empty */
43 int IsEmptyCQueue(CQueue *Q);
44 /* Filled Length Of Queue */
45 int LengthOfCQueue(CQueue *Q);
46 /* Empty Length Of Queue */
47 int AvailableOfCQueue(CQueue *Q);
48 /* Push Data Into Queue (Tail) */
49 int EnCQueue(CQueue *Q, CQItemType *e, unsigned int len);
50 /* Push Data Into Queue (Tail) */
51 int EnCQueue_AI(CQueue *Q, CQItemType *e, unsigned int len, FRAME_LEN_GETTER_T getter);
52 /* Push Data Into Front Of Queue */
53 int EnCQueueFront(CQueue *Q, CQItemType *e, unsigned int len);
54 /* Pop Data Data From Queue (Front) */
55 int DeCQueue(CQueue *Q, CQItemType *e, unsigned int len);
56 /* Peek But Not Pop Data From Queue (Front) */
57 int PeekCQueue(CQueue *Q, unsigned int len_want, CQItemType **e1, unsigned int *len1, CQItemType **e2, unsigned int *len2);
58 /* Peek data to buf e, But Not Pop Data From Queue (Front) */
59 int PeekCQueueToBuf(CQueue *Q, CQItemType *e, unsigned int len);
60 int PullCQueue(CQueue *Q, CQItemType *e, unsigned int len);
61 /* Dump Queue */
62 int DumpCQueue(CQueue *Q);
63 
64 void ResetCQueue(CQueue *Q);
65 
66 unsigned int GetCQueueReadOffset(CQueue *Q);
67 unsigned int GetCQueueWriteOffset(CQueue *Q);
68 int PeekCQueueToBufWithOffset(CQueue *Q, CQItemType *e, unsigned int len_want, unsigned int offset);
69 
70 #if defined(__cplusplus)
71 }
72 #endif
73 
74 #endif /* C_QUEUE_H */
75