Modify licenses
[scp/ocu/5gnr.git] / Include / msgb.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 #ifndef MSGB_H
21 #define MSGB_H
22
23 #include "vos_lib.h"
24 #include "vos_types.h"
25 #include "vos_string.h"
26
27 extern ULONG gMsgbFreeCount;
28
29 typedef struct
30 {
31         UINT16  maxHeadLen;                     /* Head域预留的长度 */
32         UINT16  maxDataLen;                     /* Data域预留的长度 */
33         UINT16  headSpareLen;           /* Head域空闲的长度 */
34         UINT16  tailOffset;                     /* 数据尾端到dataBuff[]起始位置的距离,包括1.整个Head域 2.Data域的使用部分 */
35 }MsgbInfo_t;
36
37 typedef struct
38 {
39         MsgbInfo_t      msgbInfo;
40         UINT8           dataBuff[0];    /* DataBuff域的起始地址,指向msgbInfo变量后面的地址,该成员不占用内存 */
41 }MsgbBuff_t;
42
43
44 INT32 msgbCheck(MsgbBuff_t *pMsgBuff);
45 MsgbBuff_t *msgbAllocWithDebug(UINT16 dataLen, UINT16 maxHeadLen, ULONG moduleId,unsigned char *file, unsigned long line);
46 UINT8 *msgbDataWithDebug(MsgbBuff_t *pMsgBuff,unsigned char *fun, unsigned long line);
47 UINT8 *msgbTailWithDebug(MsgbBuff_t *pMsgBuff,unsigned char *fun, unsigned long line);
48 UINT16 msgbDataUsedLenWithDebug(MsgbBuff_t *pMsgBuff,unsigned char *fun, unsigned long line);
49 UINT16 msgbDataAllocLenWithDebug(MsgbBuff_t *pMsgBuff,unsigned char *fun, unsigned long line);
50 UINT8 *msgbHeadPushWithDebug(MsgbBuff_t *pMsgBuff, UINT32 len,unsigned char *fun, unsigned long line);
51 UINT8 *msgbHeadPullWithDebug(MsgbBuff_t *pMsgBuff, UINT32 len,unsigned char *fun, unsigned long line);
52 UINT8 *msgbTailPushWithDebug(MsgbBuff_t *pMsgBuff, UINT32 len,unsigned char *fun, unsigned long line);
53 UINT8 *msgbTailPullWithDebug(MsgbBuff_t *pMsgBuff, UINT32 len,unsigned char *fun, unsigned long line);
54
55
56 #define msgbAlloc( dataLen,  maxHeadLen,  moduleId) msgbAllocWithDebug( dataLen,  maxHeadLen,  moduleId,(UCHAR *)__func__,__LINE__)
57
58
59
60 #define msgbData(pMsgBuff) msgbDataWithDebug(pMsgBuff,(UCHAR *)__func__,__LINE__)
61
62 #define msgbTail(pMsgBuff) msgbTailWithDebug(pMsgBuff,(UCHAR *)__func__,__LINE__)
63
64 #define msgbDataUsedLen(pMsgBuff) msgbDataUsedLenWithDebug(pMsgBuff,(UCHAR *)__func__,__LINE__)
65
66 #define msgbDataAllocLen(pMsgBuff) msgbDataAllocLenWithDebug(pMsgBuff,(UCHAR *)__func__,__LINE__)
67
68 extern UINT16 msgbHeadLeftRoom(MsgbBuff_t *pMsgBuff);
69
70 extern UINT16 msgbTailLeftRoom(MsgbBuff_t *pMsgBuff);
71
72
73 #define msgbFree(pMsgBuff)\
74 ({\
75         if(NULL == pMsgBuff)\
76         {\
77         vos_err_print("input is NULL!\n");\
78         }\
79         VOS_Free(pMsgBuff);\
80         gMsgbFreeCount++;\
81 })
82
83
84 #define msgbHeadPush(pMsgBuff,  len) msgbHeadPushWithDebug(pMsgBuff,  len,(UCHAR *)__func__,__LINE__)
85
86 #define msgbHeadPull(pMsgBuff,  len) msgbHeadPullWithDebug(pMsgBuff,  len,(UCHAR *)__func__,__LINE__)
87
88 #define msgbTailPush(pMsgBuff,  len) msgbTailPushWithDebug(pMsgBuff,  len,(UCHAR *)__func__,__LINE__)
89
90 #define msgbTailPull(pMsgBuff,  len) msgbTailPullWithDebug(pMsgBuff,  len,(UCHAR *)__func__,__LINE__)
91
92 #endif  /* MSGB_H */