Modify licenses
[scp/ocu/5gnr.git] / Include / vos_que.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 ICT/CAS.
4 *
5 *   Licensed under the O-RAN Software License, Version 1.0 (the "Software License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       https://www.o-ran.org/software
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 *
17 *******************************************************************************/
18
19
20
21 #ifndef __VOS_QUE_H__
22 #define __VOS_QUE_H__
23
24 #ifdef    __cplusplus
25 extern "C"
26 {
27 #endif /* __cplusplus */
28
29 /** 队列中无消息 */
30 #define VOS_NO_MSG          0
31
32
33 #define VOS_QUEUE_MSG_SIZE   4
34
35 /** 队列中有消息 */
36 #define VOS_HAVE_MSG        (VOS_QUEUE_MSG_SIZE * sizeof(ULONG))
37
38 /** 队列类型,linux中只支持 VOS_MSG_Q_FIFO 和 VOS_MSG_Q_PRIORITY 类型 */
39 typedef enum {
40     VOS_MSG_Q_FIFO           = 0, ///< first in first out queue
41     VOS_MSG_Q_PRIORITY       = 1, ///< priority sorted queue
42     VOS_MSG_Q_PIPE           = 2, ///< pipe queue
43     VOS_MSG_Q_ISOCK                      = 3, ///< ISOCK queue
44 }VOS_msgq_type_t;
45
46 /** 消息优先级 */
47 typedef enum {
48     MSG_PRI_NORMAL      = 0,  ///< 普通优先级
49     MSG_PRI_URGENT      = 1,  ///< 高优先级
50 }VOS_msgq_pri_t;
51
52
53 /**
54  * 创建消息队列
55  * @param[in]   lMaxMsgs     消息队列中最大消息数目
56  * @param[in]   lOptions     选项,VOS_msgq_type_t 类型,linux中支持MSG_Q_FIFO和MSG_Q_PRIORITY
57  * @return      成功返回队列ID,失败则返回 0
58  */
59 ULONG VOS_QueCreate(LONG lMaxMsgs, LONG lOptions);
60
61
62 /**
63  * 删除队列
64  * @param[in]   msgQId     消息队列ID
65  * @return      成功返回队列ID,失败则返回 0
66  */
67 LONG VOS_QueDelete(ULONG msgQId);
68
69
70 /**
71  * 向消息队列发消息
72  * @param[in]   msgQId     消息队列ID
73  * @param[in]   aulMsg     发送的消息,含有VOS_QUEUE_MSG_SIZE个ULONG的数组
74  * @param[in]   lMsec      当队列满时,发送任务等待的时间,单位是毫秒。
75  *                         VOS_WAIT_FOREVER 表示永久等待。VOS_WAIT_NO_WAIT 表示不等待。
76  * @param[in]   lPriority  消息的优先级。分为MSG_PRI_NORMAL和MSG_PRI_URGENT两种。
77  * @return      VOS_OK - 成功,其他 - 失败
78  * @note WINDOWS中存在Bug,队列满了后,不能等待,只能返回失败
79  */
80 LONG VOS_QueSend(ULONG msgQId, ULONG aulMsg[VOS_QUEUE_MSG_SIZE], LONG lMsec, LONG lPriority);
81
82
83 /**
84  * 从消息队列接受
85  * @param[in]   msgQId     消息队列ID
86  * @param[in]   aulMsg     接收的消息,含有VOS_QUEUE_MSG_SIZE个ULONG的数组
87  * @param[in]   lMsec      当队列满时,发送任务等待的时间,单位是毫秒。
88  *                         VOS_WAIT_FOREVER 表示永久等待。VOS_WAIT_NO_WAIT 表示不等待。
89  * @return      失败为VOS_ERROR;成功时如果消息队列中消息数为0 则返回VOS_NO_MSG,
90  *              如果消息队列中消息数不为0 ,则返回VOS_HAVE_MSG。
91  * @note 一般任务的入口函数就阻塞在VOS_QueReceive。
92  */
93 LONG VOS_QueReceive(ULONG msgQId, ULONG aulMsg[VOS_QUEUE_MSG_SIZE], LONG lMsec);
94
95
96 /**
97  * 将队列和任务绑定,用于队列管理,一般创建完队列和任务后调用
98  * @param[in]   hTask     任务句柄
99  * @param[in]   ulQId     消息队列ID
100  */
101 VOID VOS_QueBindTask(VOS_HANDLE hTask, ULONG ulQId);
102
103
104 /**
105  * 获得队列中消息的数目
106  * @param[in]   msgQId    消息队列ID
107  * @return      成功则返回消息队列中消息的数目,失败则VOS_ERROR。
108  */
109 LONG VOS_QueNum(ULONG msgQId);
110
111 /**
112  * 删除所有创建的消息队列
113  * @return 成功VOS_OK
114  */
115 LONG VOS_QueClean();
116
117 #ifdef __cplusplus
118 }
119 #endif /* __cplusplus */
120
121 #endif /* __VOS_QUE_H__ */