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