📄 voip.c
字号:
{
TBXHashDestroy( g_pContext->hAdapterHandleHash );
g_pContext->hAdapterHandleHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Free all adapters' contexts */
if( g_pContext->hPoolOfAdapters != (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID )
{
/* Free all adapter configurations */
pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
while( pAdapterContextNode )
{
pAdapterContext = pAdapterContextNode->pAdapterContext;
VoipAdapterClearConfig( &pAdapterContext->TargetConfig1 );
VoipAdapterClearConfig( &pAdapterContext->TargetConfig2 );
free( pAdapterContextNode->pAdapterContext );
pAdapterContextNode->pAdapterContext = NULL;
TBXPoolOfBuffersFree( g_pContext->hPoolOfAdapters, pAdapterContextNode );
pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
}
/* Free the pool of adapter contexts */
TBXPoolOfBuffersDestroy( g_pContext->hPoolOfAdapters );
g_pContext->hPoolOfAdapters = (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID;
}
/* Terminate the command-line tool */
if( pCliContext->hCliTools )
{
TBX_CLI_TOOLS_HANDLE hCliToolsTmp;
/* Print last trace */
{
struct tm* pTime;
time_t Time = time( NULL );
TBX_CHAR szDate[ 256 ];
pTime = localtime( &Time );
strftime( szDate, sizeof(szDate) - 1, "%m/%d/%Y %H:%M:%S", pTime );
szDate[ sizeof( szDate ) - 1 ] = '\0';
TbxCliToolsLogPrint(pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, NULL, "******************************************************************************\n");
TbxCliToolsLogPrint(pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, NULL, "* Application stopped in a clean manner: %s\n", szDate);
TbxCliToolsLogPrint(pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, NULL, "******************************************************************************\n\n");
}
hCliToolsTmp = pCliContext->hCliTools;
TbxCliToolsStop( pCliContext->hCliTools );
/* Before destroying TBX CLI Tools, we must lock semaphore to avoid
a host lib callback to try to use it while we're destroying it */
TBX_SEM_GET( g_pContext->TbxCliLogSem, TBX_SEM_WAIT_FOREVER );
{
pCliContext->hCliTools = NULL;
}
TBX_SEM_GIV( g_pContext->TbxCliLogSem );
TbxCliToolsTerm( hCliToolsTmp );
}
fprintf( stdout, "Application done.\n");
/* Free the semaphores */
TBX_SEM_DESTROY (&g_pContext->hThreadSem);
TBX_SEM_DESTROY (&g_pContext->TbxCliLogSem);
free( g_pContext );
g_pContext = NULL;
}
/* Press RETURN to quit, if leaks detected */
if( sm_dump(0) || TBX_RESULT_FAILURE( g_AppResult ) )
{
/* if in test mode send the leaks in a file */
if( fTestMode )
{
FILE* pLeakFile = fopen ("leaks.txt", "w" );
if( pLeakFile )
{
sm_dump_to_file( pLeakFile, 0 );
fclose( pLeakFile );
}
}
else
{
fprintf( stdout, "Press RETURN to quit...\n" );
fflush( stdin );
getchar();
}
}
return;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterHashGetKey : Function to get hash key from pointer to adapter context.
| The Hash table hash key is the adapter handle.
|
|
| in_pAdapterContext : Pointer to adapter context structure
| (cast to PVOIP_ADAPTER_CONTEXT)
|
| Note : ~
|
| Return : Hash key associated to adapter context
|
*------------------------------------------------------------------------------------------------------------------------------*/
static TBX_HASH_KEY VoipAdapterHashGetKey
(
IN PTBX_VOID in_pUserContext,
IN PTBX_VOID in_pAdapterContext
)
{
(TBX_VOID)in_pUserContext;
return (TBX_HASH_KEY)( ( (PVOIP_ADAPTER_CONTEXT)in_pAdapterContext )->AdapterInfo.hAdapter );
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterNameGetKey : Function to get hash key from pointer to adapter context.
| The Hash table hash key is the adapter name.
|
|
| in_pAdapterContext : Pointer to adapter context structure
| (cast to PVOIP_ADAPTER_CONTEXT_NODE)
|
| Note : ~
|
| Return : Hash key associated to adapter name
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_HASH_KEY VoipAdapterNameGetKey
(
IN PTBX_VOID in_pUserContext,
IN PTBX_VOID in_pAdapterContext
)
{
(TBX_VOID)in_pUserContext;
return (TBX_HASH_KEY)( ( (PVOIP_ADAPTER_CONTEXT_NODE)in_pAdapterContext )->szAdapterName );
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipTbxLibErrorHandler : Tbx library error handler.
|
| in_pContext : Context for this callback.
| in_hTbxLib : Handle of the TBX library.
| in_hAdapter : Handle of the adapter the error is reported for (if appropriate).
| in_pErrorInfo : Information structure on the error.
| out_pActionToTake : Pointer to return the action to take following this error.
|
| Note : ~
|
| Return : ~.
|
*------------------------------------------------------------------------------------------------------------------------------*/
static TBX_VOID VoipTbxLibErrorHandler
(
IN PTBX_VOID in_pContext,
IN TBX_LIB_HANDLE in_hTbxLib,
IN TBX_ADAPTER_HANDLE in_hAdapter,
IN PTBX_LIB_ERROR_INFO in_pErrorInfo,
IN PTBX_LIB_ERROR_ACTION out_pActionToTake
)
{
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
(TBX_VOID)in_pContext;
(TBX_VOID)in_hTbxLib;
(TBX_VOID)in_hAdapter;
switch( in_pErrorInfo->Cause )
{
case TBX_LIB_ERROR_HANDLER_CAUSE_RX_FIFO_FULL:
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "WARNING: Host lib RX fifo FULL (%d messages), dropping adapter\n", (int)in_pErrorInfo->un32Extra0 );
*out_pActionToTake = TBX_LIB_ERROR_ACTION_DROP_ADAPTER_FLUSH_FILTERS;
} break;
case TBX_LIB_ERROR_HANDLER_CAUSE_TX_FIFO_FULL:
{
TbxCliToolsLogPrint
(
pCliContext->hCliTools,
TRACE_LEVEL_ERROR, NULL,
"WARNING: Host lib TX fifo FULL. Blocking state machine's thread...\n"
);
*out_pActionToTake = TBX_LIB_ERROR_ACTION_BLOCK;
} break;
case TBX_LIB_ERROR_HANDLER_CAUSE_FLOW_CONTROL:
{
*out_pActionToTake = TBX_LIB_ERROR_ACTION_BLOCK;
} break;
default:
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "WARNING: TBX Error handler called with unknown cause %d\n", (int)in_pErrorInfo->Cause );
*out_pActionToTake = TBX_LIB_ERROR_ACTION_IGNORE;
} break;
}
return;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipTbxLibErrorPrint : Error message print function for the host library.
|
| in_pContext : Context for this function.
| in_hLib : Handle of the TBX library.
| in_pszError : Error message to print.
|
| Note : ~
|
| Return : ~.
|
*------------------------------------------------------------------------------------------------------------------------------*/
static void VoipTbxLibErrorPrint
(
IN PTBX_VOID in_pContext,
IN TBX_LIB_HANDLE in_hLib,
IN PTBX_CHAR in_pszError
)
{
(void)in_pContext;
(void)in_hLib;
TBX_SEM_GET( g_pContext->TbxCliLogSem, TBX_SEM_WAIT_FOREVER );
{
if( g_pContext->CliContext.hCliTools )
{
PTBX_CHAR pszLine;
PTBX_CHAR pszEndLine;
/* Remove the endlines at beginning of trace */
while( *in_pszError && *in_pszError == '\n' )
{
in_pszError++;
}
/* Call the print function for every line of this log print, and insert "Hostlib" in front of each. */
pszLine = in_pszError;
while( (pszEndLine = strchr( pszLine, '\n' )) != NULL )
{
*pszEndLine = '\0';
TbxCliToolsLogPrint
(
g_pContext->CliContext.hCliTools,
TRACE_LEVEL_ALWAYS,
NULL,
FMAGEN "Hostlib: " DEFAULT_COLOR "%s\n",
pszLine
);
pszLine = pszEndLine + 1;
}
if( pszLine && *pszLine )
{
TbxCliToolsLogPrint
(
g_pContext->CliContext.hCliTools,
TRACE_LEVEL_ALWAYS,
NULL,
FMAGEN "Hostlib: " DEFAULT_COLOR "%s\n",
pszLine
);
}
}
}
TBX_SEM_GIV( g_pContext->TbxCliLogSem );
}
/*--------------------------------------------------------------------------------------------------------------------------------
|
| ControlC_Handler : Function called when the user press Control-C while the test is running.
| This function forces all file playbacks to stop.
|
| Note :
|
| Return :
|
*------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
BOOL WINAPI ControlC_Handler(DWORD CtrlType)
{
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
/* Process exit application command from windows */
if( CtrlType == 2 )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_3, NULL, "Window is being closed. Quitting...\n" );
}
else
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_3, NULL, "Received control-C. Quitting...\n" );
}
g_fContinue = TBX_FALSE;
return TBX_TRUE;
}
#else
void ControlC_Handler( int in_iSignal )
{
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
if( in_iSignal == SIGINT )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_3, NULL, "Received Control-C. Quitting...\n" );
}
else
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_3, NULL, "Received quit signal %d. Quitting...\n", in_iSignal );
}
/* Re-install this signal handler for the next time */
signal( in_iSignal, ControlC_Handler );
g_fContinue = TBX_FALSE;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -