⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macros.h

📁 telcobridges pri develop,30b+d
💻 H
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VoiceLink TB640 sample (ISDN)
 |
 |	Filename:   	macros.h
 |
 |	Copyright:  	TelcoBridges 2002-2003, All Rights Reserved
 |
 |	Description:	This file contains definition of utility macros
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.28 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Define header file
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifndef __MACROS_H__
#define __MACROS_H__

#ifndef WIN32
#include <pthread.h>
#endif

/*--------------------------------------------------------------------------------------------------------------------------------
 |  C++ support
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Forward declarations
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/

/* The following defines create the apppropriate function inlining according to the selected OS */
#define	INLINE						__inline

/* Define the max length of an error line displayed by the CLI */
#define TB640_ISDN_CLI_MAX_ERROR_LINE_SIZE				120

/* Define the number of "error log" lines that are remembered by the CLI */
#define TB640_ISDN_CLI_MAX_NB_ERROR_LINES				512

/* Define the number of "error log" lines that are displayer by the CLI */
#define TB640_ISDN_CLI_MAX_NB_ERROR_LINES_VIEWED		8

/* vsnprintf is defined differently under windows than other operating system */
#ifdef WIN32
#define		VSNPRINTF					_vsnprintf
#else
#define		VSNPRINTF					vsnprintf
#endif

/* Bit value to instruct the GUI to refresh the display */
#define TB640_ISDN_CLI_REFRESH_DISPLAY					(1<<0)

/* Bit value to instruct the GUI to do a force refresh */
#define TB640_ISDN_CLI_FORCE_REFRESH					(1<<30)

/* Bit value to instruct the GUI to clear the screen before refreshing */
#define TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH				(1<<31)

typedef enum _TRACE_LEVEL
{
	TRACE_LEVEL_0		= 0,
	TRACE_LEVEL_1		= 1,
	TRACE_LEVEL_2		= 2,
	TRACE_LEVEL_3		= 3,
	TRACE_LEVEL_4		= 4,
	TRACE_LEVEL_MAX		= 4,
	TRACE_LEVEL_ALWAYS	= 0xFFFFFFFE,
	TRACE_LEVEL_ERROR	= 0xFFFFFFFF
} TRACE_LEVEL, *PTRACE_LEVEL;

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Types
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/
extern volatile TBX_BOOL			g_fPrintInErrorBuffer;
extern volatile TBX_UINT32			g_un32ErrorLineId;
extern volatile TBX_UINT32			g_un32ErrorLineWriteIndex;
extern volatile TBX_UINT32			g_un32ErrorLineReadIndex;
extern volatile TBX_CHAR			g_aszErrorLines [TB640_ISDN_CLI_MAX_NB_ERROR_LINES+1] [TB640_ISDN_CLI_MAX_ERROR_LINE_SIZE];


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Macros
 *------------------------------------------------------------------------------------------------------------------------------*/

/* Inline function to output an error trace onto the display */
static INLINE void TB640_ISDN_DISPLAY_OUTPUT (PTBX_CHAR __pString__, va_list __var__)
{
	TBXCli_vfprintf (stdout, __pString__, __var__);
}

/* Inline function to output a trace into the logfile */
static INLINE void TB640_ISDN_FILE_OUTPUT(PTBX_CHAR __pString__, va_list __var__)
{
	if ((g_AppContext != NULL) && (g_AppContext->pLogFile != NULL))
	{
		vfprintf (g_AppContext->pLogFile, __pString__, __var__);
	}
}

/* Inline to output a  trace into the logfile and/or to the display */
static INLINE void TB640_ISDN_LOG(TBX_UINT32 __level__,PTBX_CHAR __pString__, ...)
{
	if (g_AppContext != NULL)
	{
		unsigned char *	pChar;
		int				length;
		va_list		 	marker;
		va_start (marker, __pString__);

		if (g_AppContext->un32DisplayLogLevel <= __level__)
		{
			/* Print into a memory buffer instead of output display ? */
			if (g_fPrintInErrorBuffer)
			{
				TBX_SEM_GET (g_AppContext->DisplaySem, TBX_SEM_WAIT_FOREVER);
				g_un32ErrorLineId++;

				/* Write the string at the "write index" location */
				sprintf ((PTBX_CHAR)&(g_aszErrorLines[g_un32ErrorLineWriteIndex][0]), "%d- ", g_un32ErrorLineId);
				length = strlen((PTBX_CHAR)&(g_aszErrorLines[g_un32ErrorLineWriteIndex][0]));
				VSNPRINTF ((PTBX_CHAR)&(g_aszErrorLines[g_un32ErrorLineWriteIndex][length]), (TB640_ISDN_CLI_MAX_ERROR_LINE_SIZE - length - 1),__pString__, marker);

				/* Remove trailing '\n' */
				length = strlen ((PTBX_CHAR)&(g_aszErrorLines[g_un32ErrorLineWriteIndex][0]));
				pChar = (unsigned char *)&(g_aszErrorLines[g_un32ErrorLineWriteIndex][length-1]);
				if ((*pChar == 0x0A) || (*pChar == 0x0D))
					*pChar = 0x00;
				pChar--;
				if ((*pChar == 0x0A) || (*pChar == 0x0D))
					*pChar = 0x00;

				/* Increment the write pointer */
				if (++g_un32ErrorLineWriteIndex >= TB640_ISDN_CLI_MAX_NB_ERROR_LINES)
				{
					g_un32ErrorLineWriteIndex = 0;
				}

				/* Check for collision with read pointer */
				if (g_un32ErrorLineWriteIndex == g_un32ErrorLineReadIndex)
				{
					/* Increment the read pointer */
					if (++g_un32ErrorLineReadIndex >= TB640_ISDN_CLI_MAX_NB_ERROR_LINES)
					{
						g_un32ErrorLineReadIndex = 0;
					}
				}
				TBX_SEM_GIV (g_AppContext->DisplaySem);
			}
			else
			{
				TB640_ISDN_DISPLAY_OUTPUT(__pString__,marker);
			}
		}
		if (g_AppContext->un32FileLogLevel <= __level__)
		{
			TB640_ISDN_FILE_OUTPUT(__pString__,marker);
		}
		va_end (marker);
	}
}

/* Inline to output a  trace into the logfile (no level checking) */
static INLINE void TB640_ISDN_FILE_PRINT(PTBX_CHAR __pString__, ...)
{
	va_list 	marker;
	va_start (marker, __pString__);
	TB640_ISDN_FILE_OUTPUT(__pString__,marker);
	va_end (marker);
}


/* Inline to output a  trace onto the display (no level checking) */
static INLINE void TB640_ISDN_DISPLAY_PRINT(PTBX_CHAR __pString__, ...)
{
	va_list 	marker;
	va_start (marker, __pString__);
	TB640_ISDN_DISPLAY_OUTPUT(__pString__,marker);
	va_end (marker);
}


/* Create a "application context" to be used with operation library */
#define TB640_ISDN_CREATE_APP_CONTEXT(__AdapterIdx__,__OpLibIdx__)							\
	((PTBX_VOID)(TBX_ADDR)((((__AdapterIdx__) << 16) & 0xFFFF0000) | (((__OpLibIdx__)) & 0x0000FFFF)))


/* Retrieve the "application context" to be used with operation library */
#define TB640_ISDN_RETRIEVE_APP_CONTEXT(__OpLibContext__, __AdapterIdx__, __OpLibIdx__)		\
{																							\
	(__AdapterIdx__) = (((TBX_UINT32)(TBX_ADDR)(__OpLibContext__)) & 0xFFFF0000) >> 16;				\
	(__OpLibIdx__) = (((TBX_UINT32)(TBX_ADDR)(__OpLibContext__)) & 0x0000FFFF);						\
}


#define TB640_ISDN_UPDATE_STATS(__StatsEntry__,__Value__)		\
	TBX_SEM_GET (g_StressStatsSem, TBX_SEM_WAIT_FOREVER);		\
	if (g_StressStats.fStatsActivated == TBX_TRUE)				\
		g_StressStats.__StatsEntry__ = __Value__;				\
	TBX_SEM_GIV (g_StressStatsSem)


#define TB640_ISDN_INCREMENT_STATS(__StatsEntry__,__Value__)	\
	TBX_SEM_GET (g_StressStatsSem, TBX_SEM_WAIT_FOREVER);		\
	if (g_StressStats.fStatsActivated == TBX_TRUE)				\
		g_StressStats.__StatsEntry__ += __Value__;				\
	TBX_SEM_GIV (g_StressStatsSem)


#define TB640_ISDN_INCREMENT_TRANSIANT_CALL(__Value__)						\
	TBX_SEM_GET (pAdapterInfo->TransientCallsSem, TBX_SEM_WAIT_FOREVER);	\
	pAdapterInfo->un32TransientCalls += (__Value__);						\
	TBX_SEM_GIV (pAdapterInfo->TransientCallsSem)


#define TB640_ISDN_DECREMENT_TRANSIANT_CALL(__Value__)						\
	TBX_SEM_GET (pAdapterInfo->TransientCallsSem, TBX_SEM_WAIT_FOREVER);	\
	pAdapterInfo->un32TransientCalls -= (__Value__);						\
	TBX_SEM_GIV (pAdapterInfo->TransientCallsSem)




/*
 *	Lock / unlock functions
*/
#ifdef WIN32
	#define CurrentThreadId		GetCurrentThreadId
#else
	#define CurrentThreadId		pthread_self
#endif

/* Macro that locks the lock for the specified adapter / trunk */
#define TB640IsdnLock( _un32AdapterIdx, _un32TrunkIdx )																\
{																													\
	PTB640_ISDN_ADAPTER_INFO						pAdapterInfo;													\
	PTB640_ISDN_TRUNK_INFO							pTrunkInfo;														\
																													\
	/* Validation */																								\

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -