📄 voip_state.c
字号:
if( TBX_RESULT_FAILURE( LocalResult ) )
{
TbxCliToolsLogPrint
(
g_pContext->CliContext.hCliTools,
TRACE_LEVEL_ERROR, NULL,
"Could not get stream lib stats!\n"
);
}
else
{
/* Subtract the "reset values" from the stats */
g_pContext->Stats.StreamLibStats.un64NbSentPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbSentPackets;
g_pContext->Stats.StreamLibStats.un64NbSentRedundantPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbSentRedundantPackets;
g_pContext->Stats.StreamLibStats.un64NbSentManualPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbSentManualPackets;
g_pContext->Stats.StreamLibStats.un64NbSentManualRedundantPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbSentManualRedundantPackets;
g_pContext->Stats.StreamLibStats.un64NbSentKeepAlivePackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbSentKeepAlivePackets;
g_pContext->Stats.StreamLibStats.un64NbSentPollPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbSentPollPackets;
g_pContext->Stats.StreamLibStats.un64NbSentFlowControlPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbSentFlowControlPackets;
g_pContext->Stats.StreamLibStats.un64NbSentSkippedPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbSentSkippedPackets;
g_pContext->Stats.StreamLibStats.un64NbLateLoops -= g_pContext->Stats.StreamLibStatsResetVal.un64NbLateLoops;
g_pContext->Stats.StreamLibStats.un64NbPlayBuffersProcessed -= g_pContext->Stats.StreamLibStatsResetVal.un64NbPlayBuffersProcessed;
g_pContext->Stats.StreamLibStats.un32NbAllocatedRecords -= g_pContext->Stats.StreamLibStatsResetVal.un32NbAllocatedRecords;
g_pContext->Stats.StreamLibStats.un32NbActiveRecords -= g_pContext->Stats.StreamLibStatsResetVal.un32NbActiveRecords;
g_pContext->Stats.StreamLibStats.un64NbReceivedPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedPackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedRedundantPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedRedundantPackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedSilencePackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedSilencePackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedKeepAlivePackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedKeepAlivePackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedPollReplyPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedPollReplyPackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedFlowControlPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedFlowControlPackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedSkippedPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedSkippedPackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedIgnoredPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedIgnoredPackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedInvalidPackets -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedInvalidPackets;
g_pContext->Stats.StreamLibStats.un64NbReceivedSeqNbErrors -= g_pContext->Stats.StreamLibStatsResetVal.un64NbReceivedSeqNbErrors;
g_pContext->Stats.StreamLibStats.un64NbRecordBuffersProcessed -= g_pContext->Stats.StreamLibStatsResetVal.un64NbRecordBuffersProcessed;
g_pContext->Stats.StreamLibStats.un64TotalBytesSent -= g_pContext->Stats.StreamLibStatsResetVal.un64TotalBytesSent;
g_pContext->Stats.StreamLibStats.un64PayloadBytesSent -= g_pContext->Stats.StreamLibStatsResetVal.un64PayloadBytesSent;
g_pContext->Stats.StreamLibStats.un64TotalBytesReceived -= g_pContext->Stats.StreamLibStatsResetVal.un64TotalBytesReceived;
g_pContext->Stats.StreamLibStats.un64PayloadBytesReceived -= g_pContext->Stats.StreamLibStatsResetVal.un64PayloadBytesReceived;
/* Compute byte rates */
g_pContext->Stats.un32TxByteRate = (TBX_UINT32)
(g_pContext->Stats.StreamLibStats.un64PayloadBytesSent - g_pContext->Stats.un64PrevBytesTransmitted)
/ VOIP_STATS_UPDATE_DELAY_SECOND;
g_pContext->Stats.un32RxByteRate = (TBX_UINT32)
(g_pContext->Stats.StreamLibStats.un64PayloadBytesReceived - g_pContext->Stats.un64PrevBytesReceived)
/ VOIP_STATS_UPDATE_DELAY_SECOND;
g_pContext->Stats.un64PrevBytesTransmitted = g_pContext->Stats.StreamLibStats.un64PayloadBytesSent;
g_pContext->Stats.un64PrevBytesReceived = g_pContext->Stats.StreamLibStats.un64PayloadBytesReceived;
}
}
}
/* Send states update to all adapter's states machines */
{
TBX_UINT32 un32ElapsedMs;
un32ElapsedMs = (g_pContext->un32TimerCurrentTime - un32LastStatesUpdateTicks) * TBX_MSEC_PER_TICKS;
if( un32ElapsedMs >= VOIP_STATES_UPDATE_DELAY_MS )
{
un32LastStatesUpdateTicks = g_pContext->un32TimerCurrentTime;
VoipUpdateAllAdaptersStates();
}
}
/* Proceed with stress test operations */
if( g_pContext->fStressTestRunning )
{
TBX_UINT32 un32ElapsedMs;
un32ElapsedMs = (g_pContext->un32TimerCurrentTime - g_pContext->un32LastLoopTimestamp) * TBX_MSEC_PER_TICKS;
if( un32ElapsedMs > VOIP_STRESS_TEST_LOOP_DELAY_MS/2 )
{
/* Process stress test */
VoipStressTestProcess();
}
}
/* Proceed with pending demo operations */
else if( g_pContext->fDemoRunning )
{
TBX_UINT32 un32ElapsedMs;
un32ElapsedMs = (g_pContext->un32TimerCurrentTime - g_pContext->un32LastLoopTimestamp) * VOIP_DEMO_LOOP_DELAY_MS;
if( un32ElapsedMs > VOIP_DEMO_LOOP_DELAY_MS/2 )
{
/* Process demo */
VoipDemoProcess();
}
}
/* Proceed with pending demo clean up */
else if( g_pContext->fDemoCleanupPending )
{
TBX_UINT32 un32ElapsedMs;
un32ElapsedMs = (g_pContext->un32TimerCurrentTime - g_pContext->un32LastLoopTimestamp) * TBX_MSEC_PER_TICKS;
if( un32ElapsedMs > VOIP_DEMO_CLEANUP_DELAY_MS )
{
g_pContext->un32LastLoopTimestamp = g_pContext->un32TimerCurrentTime;
pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
while( pAdapterContextNode )
{
pAdapterContext = pAdapterContextNode->pAdapterContext;
if( pAdapterContext->Demo.fCleanupPending == TBX_TRUE )
{
pAdapterContext->Demo.un32CleanupRetryCount++;
if( (pAdapterContext->un32NbResponsesExpected == 0) ||
(pAdapterContext->Demo.un32CleanupRetryCount >= VOIP_DEMO_CLEANUP_RETRY_COUNT) )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Demo cleanup...\n" );
/* Demo cleanup */
VoipDemoCleanup( pAdapterContext );
/* Demo cleanup done */
g_pContext->fDemoCleanupPending = TBX_FALSE;
/* There is always one pending demo cleanup at a time */
break;
}
else
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Demo cleanup pending...\n" );
}
}
pAdapterContextNode = TBXPoolOfBuffersNext( g_pContext->hPoolOfAdapters, pAdapterContextNode );
}
}
}
if( Result == TBX_RESULT_API_TIMEOUT || Result == TBX_RESULT_API_FILTER_AWAKENED )
{
/* Continue to wait... */
}
else if( TBX_RESULT_FAILURE( Result ) )
{
/* Failed to read from filter! Not supposed to happen! */
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "VoipStateMachineMain: Failed to read from filter (0x%08X)\n", (int)Result );
TBX_SEM_GIV (g_pContext->hThreadSem);
TBX_SLEEP_MS( 100 );
TBX_SEM_GET (g_pContext->hThreadSem, TBX_SEM_WAIT_FOREVER);
}
else
{
/* Handle the message according to its type */
switch( TBX_MSG_ID_GET( hMsg ) )
{
case TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED:
{
/* Handling of this message for the adapters state machine */
VoipHandleAdapterAdded( hMsg );
/* Force command-line redraw */
TbxCliToolsNeedRedraw( pCliContext->hCliTools );
} break;
case TBX_MSG_ID_API_NOTIF_ADAPTER_REMOVED:
{
VoipHandleAdapterRemoved(
(PTBX_EVT_API_NOTIF_ADAPTER_REMOVED)TBX_MSG_PAYLOAD_POINTER( hMsg ));
/* Force command-line redraw */
TbxCliToolsNeedRedraw( pCliContext->hCliTools );
} break;
case TBX_MSG_ID_API_NOTIF_REMOTE_HOST_ADDED:
{
VoipHandleHostAdded( hMsg );
} break;
case VOIP_MSG_ID_OP_QUIT:
{
/* Stop stress test on all adapters */
pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
while( pAdapterContextNode )
{
pAdapterContext = pAdapterContextNode->pAdapterContext;
if( pAdapterContext->StressTest.fActive == TBX_TRUE )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Stop stress test...\n" );
VoipStressTestStop( pAdapterContext );
}
pAdapterContextNode = TBXPoolOfBuffersNext( g_pContext->hPoolOfAdapters, pAdapterContextNode );
}
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Quitting...\n" );
g_fContinue = TBX_FALSE;
} break;
case VOIP_MSG_ID_OP_RELOAD_CONFIG:
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Reloading configuration file...\n" );
/* Load new configuration file */
VoipLoadInitialConfig();
/* Restart with new configuration */
VoipStartInitialConfig();
} break;
case VOIP_MSG_ID_OP_RESET_BERT_STATS:
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Reseting bert stats...\n" );
/* Reset Bert Stats */
pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
while( pAdapterContextNode )
{
pAdapterContext = pAdapterContextNode->pAdapterContext;
pAdapterContext->Stats.fBertResetStats = TBX_TRUE;
pAdapterContextNode = TBXPoolOfBuffersNext( g_pContext->hPoolOfAdapters, pAdapterContextNode );
}
} break;
case VOIP_MSG_ID_OP_SET_TRACE_LEVEL:
{
PVOIP_EVT_OP_SET_TRACE_LEVEL pEvt =
(PVOIP_EVT_OP_SET_TRACE_LEVEL)TBX_MSG_PAYLOAD_POINTER( hMsg );
g_pContext->CurrentConfig.TraceLevelStdout = (TRACE_LEVEL)pEvt->un32DisplayTraceLevel;
g_pContext->CurrentConfig.TraceLevelLogFile = (TRACE_LEVEL)pEvt->un32LogFileTraceLevel;
/* Pass new trace level to TBX CLI Tools */
VoipCliUpdateTraceLevel();
TbxCliToolsLogPrint(
pCliContext->hCliTools,
TRACE_LEVEL_ALWAYS,
FCYAN,
"Changed trace level to %d-%d...!\n",
pEvt->un32DisplayTraceLevel,
pEvt->un32LogFileTraceLevel );
} break;
/*
* Any other message/event/response is handled by current state's function handler
* for the sender adapter or host.
*/
default:
{
TBX_ADAPTER_HANDLE hAdapter;
TBX_UINT32 un32Group;
un32Group = TBX_MSG_ID_GET_GROUP( TBX_MSG_ID_GET(hMsg) );
if( un32Group == TBX_TESTLIB_MSG_GROUP )
{
TbxCliToolsLogPrint(
g_pContext->CliContext.hCliTools,
TRACE_LEVEL_ALWAYS,
FCYAN,
"TestLib message received\n" );
if( g_pContext->TestModeContext.fTestMode == TBX_TRUE )
{
switch( TBX_MSG_ID_GET( hMsg ) )
{
case TB_TESTLIB_MSG_ID_NOTIF_SHUTDOWN_REQ:
{
PTB_TESTLIB_REQ_HOST_SHUTDOWN pShutdownParam;
TbxCliToolsLogPrint(
g_pContext->CliContext.hCliTools,
TRACE_LEVEL_ALWAYS,
FCYAN,
"shutdown test request received\n");
pShutdownParam = TBX_MSG_PAYLOAD_POINTER( hMsg );
/* send shutdown confirmation */
TBTestLibSendConfirmShutdownMessage
(
g_pContext->hTbxLib,
TBX_MSG_ADAPTER_HANDLE_GET(hMsg),
0,
g_pContext->TestModeContext.un32TestId,
TBX_RESULT_AUTOTEST_OK
);
g_fContinue = TBX_FALSE;
}break;
case TB_TESTLIB_MSG_ID_NOTIF_START_TEST_REQ:
{
PTB_TESTLIB_REQ_START_TEST pStartParam;
PVOIP_AUTO_TEST_DELEGATE pAutoTest;
TbxCliToolsLogPrint(
g_pContext->CliContext.hCliTools,
TRACE_LEVEL_ALWAYS,
FCYAN,
"Start test request received\n");
pStartParam = TBX_MSG_PAYLOAD_POINTER( hMsg );
if( pStartParam->StartTestParameter.un32ApplicationID == g_pContext->TestModeContext.un32TestId )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -