📄 cb.h
字号:
/****************************************************************************
*****************************************************************************
**
** File Name
** ---------
**
** CB.H
**
*****************************************************************************
*****************************************************************************
**
** Description
** -----------
**
** Communication buffer services definitions.
**
** Communications buffers (ComBufs) are a structure with an attached buffer
** that provides a way for headers to be prepended and stripped from a packet
** as it passes through the communications stack without data copies or
** moves.
**
*****************************************************************************
*****************************************************************************
**
** Source Change Indices
** ---------------------
**
** Porting: <none>0----<major> Customization: <none>0----<major>
**
*****************************************************************************
*****************************************************************************
**
** Services List
** -------------
**
** CB_AttachComBuf() - Increment ComBuf UseCount to "attach" user
** CB_ClearComBuf() - Clear out the contents of a ComBuf
** CB_ClearAndExpandComBuf() - Forcibly set the data size of a ComBuf
** CB_DeleteComBuf() - Delete a ComBuf
** CB_ExpandComBuf() - Expand the data size of a ComBuf
** CB_GetDataPtrComBuf() - Return the data pointer of the ComBuf
** CB_GetDataSizeComBuf() - Return the current data size of a ComBuf
** CB_NewComBuf() - Create a new ComBuf
** CB_PrependComBuf() - Expand and put new data into a ComBuf
** CB_ShrinkComBuf() - Reduce the data size of a ComBuf
** CB_ShrinkOffsetComBuf() - Remove the middle portion of a ComBuf
** CB_StripComBuf() - Take data from a combuf and shrink it
** CB_TradeForBigger() - Trade ComBuf (if needed) to ensure space
** CB_TradeForBiggerClear() - Trade ComBuf (if needed) to ensure space
** CB_WordAlignComBuf() - Ensure first data byte is word aligned
**
*****************************************************************************
*****************************************************************************
** **
** ETHERNET/IP EXAMPLE CODE **
** COPYRIGHT (c) 2000-2005 ODVA (Open DeviceNet Vendor Association) **
** & ControlNet International Ltd. **
** **
** All rights reserved, except as specifically licensed in writing. **
** Use of the Ethernet/IP Example Protocol Software is subject to **
** ODVA's and ControlNet International's Terms of Use Agreement. **
** The following work constitutes example program code and is intended **
** merely to illustrate useful programming techniques. The user is **
** responsible for applying the code correctly. The code is provided **
** AS IS without warranty and is in no way guaranteed to be error-free. **
** **
*****************************************************************************
*****************************************************************************
*/
/****************************************************************************
*****************************************************************************
**
** Change Log
** ----------
**
**
*****************************************************************************
*****************************************************************************
*/
#ifndef CB_H
#define CB_H
/****************************************************************************
**
** Typedefs
**
*****************************************************************************
*/
/*---------------------------------------------------------------------------
**
** CB_ComBufType
**
** Combuf control structure definition. It is assumed that the data buffer
** immediately follows this structure.
**
**---------------------------------------------------------------------------
*/
typedef struct CB_ComBufType
{
UINT8 *pData; /* pointer to start of active buffer data */
UINT16 iReqSize; /* requested allocation size */
UINT16 iBufSize; /* max size of the buffer (heap block size) */
UINT16 iDataSize; /* size of active data in buffer */
UINT8 bUseCount; /* use count for shared ComBufs */
UINT8 bPad; /* make sure things stay word aligned */
}
CB_ComBufType;
/****************************************************************************
**
** Public Services
**
*****************************************************************************
*/
/*---------------------------------------------------------------------------
**
** CB_AttachComBuf()
**
** Increment UseCount of ComBuf to indicate another user is "attached"
** and actively using the combuf. Call CB_DeleteComBuf to "detach" a user
** from a combuf. The last user to "detach" from the combuf causes the
** combuf to be freed back to the heap.
**
**---------------------------------------------------------------------------
**
** Inputs:
** pC - Pointer to Combuf
**
** Outputs:
** None
**
** Usage:
** CB_AttachComBuf( pComBuf );
**
**---------------------------------------------------------------------------
*/
#define CB_AttachComBuf( pComBuf ) \
{ \
(pComBuf)->bUseCount++; \
}
/*---------------------------------------------------------------------------
**
** CB_ClearComBuf()
**
** Reset a ComBuf to its initial empty state.
**
**---------------------------------------------------------------------------
**
** Inputs:
** pComBuf - Pointer to Combuf
**
** Outputs:
** None
**
** Usage:
** CB_ClearComBuf( pComBuf );
**
**---------------------------------------------------------------------------
*/
#define CB_ClearComBuf( pComBuf ) \
{ \
(pComBuf)->iDataSize = 0; \
(pComBuf)->pData = (UINT8*)(pComBuf) + \
sizeof( CB_ComBufType ) + \
(pComBuf)->iBufSize; \
}
/*---------------------------------------------------------------------------
**
** CB_ClearAndExpandComBuf()
**
** Set ComBuf data size to the specified value and adjust the ComBuf data
** pointer to correspond.
**
**---------------------------------------------------------------------------
**
** Inputs:
** pComBuf - Pointer to ComBuf
** iSize - New data size
**
** Outputs:
** None
**
** Usage:
** CB_ClearAndExpandComBuf( pComBuf, iSize );
**
**---------------------------------------------------------------------------
*/
#define CB_ClearAndExpandComBuf( pComBuf, iSize ) \
{ \
(pComBuf)->iDataSize = (iSize); \
(pComBuf)->pData = (UINT8*)(pComBuf) + \
sizeof( CB_ComBufType ) + \
(pComBuf)->iBufSize - \
(iSize); \
}
/*---------------------------------------------------------------------------
**
** CB_DeleteComBuf()
**
** Detach one user from a ComBuf.
** Delete and free its heap memory if this was the last user.
**
**---------------------------------------------------------------------------
**
** Inputs:
** pComBuf - Pointer to Combuf
**
** Outputs:
** Return - TRUE if combuf deleted
** FALSE if not deleted
**
** Usage:
** if( CB_DeleteCombuf( pComBuf ) )...
**
**---------------------------------------------------------------------------
*/
EXTFUNC BOOL CB_DeleteComBuf( CB_ComBufType *pComBuf );
/*---------------------------------------------------------------------------
**
** CB_ExpandComBuf()
**
** Make room in front of a packet in a ComBuf.
**
**---------------------------------------------------------------------------
**
** Inputs:
** pComBuf - Pointer to ComBuf
** iSize - Size of expansion area
**
** Outputs:
** None
**
** Usage:
** CB_ExpandComBuf( pComBuf, iSize );
**
**---------------------------------------------------------------------------
*/
#define CB_ExpandComBuf( pComBuf, iSize ) \
{ \
GS_LogEventIf( (pComBuf)->iDataSize + (iSize) > (pComBuf)->iBufSize, \
CB_OVERFLOW, \
((pComBuf)->iDataSize + (iSize) - (pComBuf)->iBufSize) /* jjw 9/26/99 added parenth for typedef on msvc */, \
(void*)(pComBuf), \
FATAL ); \
(pComBuf)->pData -= (iSize); \
(pComBuf)->iDataSize += (iSize); \
}
/*---------------------------------------------------------------------------
**
** CB_GetDataPtrComBuf()
**
** Reference the data ptr (to the packet currently resident) in the ComBuf.
**
**---------------------------------------------------------------------------
**
** Inputs:
** pComBuf - Pointer to ComBuf
**
** Outputs:
** Return - Pointer to the start of the data in ComBuf
**
** Usage:
** pData = CB_GetDataPtrComBuf( pComBuf );
**
**---------------------------------------------------------------------------
*/
#define CB_GetDataPtrComBuf( pComBuf ) ( (void*)(pComBuf)->pData )
/*---------------------------------------------------------------------------
**
** CB_GetDataSizeComBuf()
**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -