📄 voip_demo.c
字号:
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
TbxCliToolsLogPrint(
pCliContext->hCliTools,
TRACE_LEVEL_ERROR, NULL,
"VoipDemoStop: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipDemoNextStep : Handles the next demo step message.
|
| in_pAdapterContext : Context of the adapter to change current demo step
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipDemoNextStep(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext )
{
TBX_RESULT Result;
PVOIP_CLI_CONTEXT pCliContext;
PVOIP_DEMO_STEP pDemoStep;
TBX_UINT32 un32Step;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pCliContext = &g_pContext->CliContext;
while(1)
{
if( in_pAdapterContext->Demo.un32CurrentStep >= in_pAdapterContext->Demo.un32StepCount )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "Reached last demo step, restart...\n" );
/* Reset current step value */
in_pAdapterContext->Demo.un32CurrentStep = 0;
}
un32Step = in_pAdapterContext->Demo.un32CurrentStep;
pDemoStep = &in_pAdapterContext->Demo.aStep[un32Step];
if( pDemoStep->fWait == TBX_TRUE )
{
/* Waiting for responses, */
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "Waiting for responses... Current demo step in progress\n" );
break;
}
if( pDemoStep->Type == VOIP_DEMO_STEP_TYPE_PAUSE )
{
pDemoStep->fWait = TBX_TRUE;
}
else if( pDemoStep->Type == VOIP_DEMO_STEP_TYPE_TITLE )
{
/* Change demo title */
in_pAdapterContext->Demo.fTitle = TBX_TRUE;
strncpy( in_pAdapterContext->Demo.szTitle, pDemoStep->szTitle, sizeof(in_pAdapterContext->Demo.szTitle) );
in_pAdapterContext->Demo.szTitle[sizeof(in_pAdapterContext->Demo.szTitle) - 1] = '\0';
}
else if( pDemoStep->Type == VOIP_DEMO_STEP_TYPE_CONNECT )
{
TBX_MSG_HANDLE hMsg;
PVOIP_EVT_OP_ALLOCATE_CONNECTION pEvt;
/* Create new connection */
hMsg = VoipFormatPrivateMsg
(
VOIP_MSG_ID_OP_ALLOCATE_CONNECTION,
sizeof( VOIP_MSG_OP_ALLOCATE_CONNECTION ),
in_pAdapterContext->AdapterInfo.hAdapter,
0
);
if( hMsg == (TBX_MSG_HANDLE)TBX_HANDLE_INVALID )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "Failed to create new connections!\n" );
break;
}
/* Fill the request */
pEvt = (PVOIP_EVT_OP_ALLOCATE_CONNECTION) TBX_MSG_PAYLOAD_POINTER (hMsg);
pEvt->un32MsgVersion = 1;
pEvt->Params = pDemoStep->ConnectionParams;
pEvt->un32NbConnections = pDemoStep->un32NbConnections;
pEvt->un16IPPortIncrement = pDemoStep->un16IPPortIncrement;
in_pAdapterContext->pFctStateHandler( in_pAdapterContext, hMsg );
TBXReleaseMsg (g_pContext->hTbxLib, hMsg);
/* Implicit pause */
pDemoStep->fWait = TBX_TRUE;
}
else if( pDemoStep->Type == VOIP_DEMO_STEP_TYPE_DISCONNECT )
{
/* Clear all connections */
Result = VoipDemoCleanup( in_pAdapterContext );
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "Failed to clear all connections!\n" );
break;
}
/* Implicit pause */
pDemoStep->fWait = TBX_TRUE;
}
if( pDemoStep->fWait == TBX_TRUE )
{
/* Wait completion before continuing */
break;
}
else
{
/* Update current step value */
in_pAdapterContext->Demo.un32CurrentStep += 1;
}
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
TbxCliToolsLogPrint(
pCliContext->hCliTools,
TRACE_LEVEL_ERROR, NULL,
"VoipDemoStop: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipDemoProcess : Process the demo
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipDemoProcess()
{
TBX_RESULT Result;
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
PVOIP_ADAPTER_CONTEXT pAdapterContext;
PVOIP_ADAPTER_CONTEXT_NODE pAdapterContextNode;
PVOIP_DEMO_STEP pDemoStep;
TBX_UINT32 un32Step;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
Result = TBX_RESULT_OK;
pCliContext = &g_pContext->CliContext;
g_pContext->un32LastLoopTimestamp = g_pContext->un32TimerCurrentTime;
pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
while( pAdapterContextNode )
{
pAdapterContext = pAdapterContextNode->pAdapterContext;
if( (pAdapterContext->State == VOIP_ADAPTER_STATE_READY) && (pAdapterContext->Demo.fActive == TBX_TRUE) )
{
un32Step = pAdapterContext->Demo.un32CurrentStep;
if( un32Step < pAdapterContext->Demo.un32StepCount )
{
pDemoStep = &pAdapterContext->Demo.aStep[un32Step];
if( pDemoStep->fWait == TBX_TRUE )
{
if( pAdapterContext->un32NbResponsesExpected == 0 )
{
/* Current demo step done */
pDemoStep->fWait = TBX_FALSE;
if( (pDemoStep->Type != VOIP_DEMO_STEP_TYPE_PAUSE) || (pAdapterContext->Demo.fSkipPauses == TBX_TRUE) )
{
/* Update current step value */
pAdapterContext->Demo.un32CurrentStep += 1;
/* Continue with next demo step */
VoipDemoNextStep( pAdapterContext );
}
}
}
}
}
pAdapterContextNode = TBXPoolOfBuffersNext( g_pContext->hPoolOfAdapters, pAdapterContextNode );
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS ( TBX_RESULT_OK );
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
TbxCliToolsLogPrint(
pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
"VoipDemoProcess: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -