📄 voip_adapter_state.c
字号:
Result = VoipHandleAdapterBertResAllocResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
/*
* Response from our "trunk alloc/set" messages
*/
case TB640_MSG_ID_TRUNK_OP_ALLOC:
{
/* Handle this response */
Result = VoipHandleAdapterTrunkAllocResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
case TB640_MSG_ID_TRUNK_OP_SET_PARAMS:
{
/* Handle this response */
Result = VoipHandleAdapterTrunkSetResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
case TB640_MSG_ID_TRUNK_OP_ACTIVE:
{
/* Handle this response */
Result = VoipHandleAdapterTrunkActivateResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
case TB640_MSG_ID_TRUNK_RES_ALLOC:
{
/* Handle this response */
Result = VoipHandleAdapterTrunkResAllocResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
/*
* Response from our "MBL alloc" messages
*/
case TB640_MSG_ID_MBL_PORT_OP_ALLOC:
{
/* Handle this response */
Result = VoipHandleAdapterMblPortAllocResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
case TB640_MSG_ID_MBL_RES_ALLOC:
{
/* Handle this response */
Result = VoipHandleAdapterMblPortResAllocResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
/*
* Response from our "stream alloc" messages
*/
case TB640_MSG_ID_STREAM_RES_ALLOC:
{
/* Handle this response */
Result = VoipHandleAdapterStreamResAllocResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
/*
* Response from our "voice processing alloc" messages
*/
case TB640_MSG_ID_VP_GROUP_ALLOC:
{
/* Handle this response */
Result = VoipHandleAdapterVpGroupAllocResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
/*
* Response from our "connection alloc" messages
*/
case TB640_MSG_ID_CONN_OP_CREATE:
{
/* Handle this response */
Result = VoipHandleAdapterConnectionAllocResponse( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
/*
* Stream lib related events
*/
case VOIP_MSG_ID_OP_STREAM_GET_DATA_ADDR:
{
Result = VoipHandleStreamGetDataAddr( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
case VOIP_MSG_ID_OP_STREAM_STOP_CONFIRMED:
{
Result = VoipHandleStreamStopConfirmed( pAdapterContext, in_hMsg );
if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
} break;
default:
{
/* Not supposed to happen! */
if( TBX_MSG_TYPE_GET( in_hMsg ) == TBX_MSG_TYPE_RESPONSE )
{
if( pAdapterContext->un32NbResponsesExpected )
pAdapterContext->un32NbResponsesExpected--;
}
sprintf( szErrorMsg, "Unexpected message id 0x%X for this state\n", (int)TBX_MSG_ID_GET( in_hMsg ) );
TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, szErrorMsg);
} break;
}
if( TBX_RESULT_SUCCESS( pAdapterContext->StateResult ) )
{
if( pAdapterContext->un32NbResponsesExpected == 0 )
{
if( ((pAdapterContext->CurrentConfig.fVpGroup0Available == TBX_TRUE) && (pAdapterContext->Status.fVpGroup0Ready == TBX_FALSE)) ||
((pAdapterContext->CurrentConfig.fVpGroup1Available == TBX_TRUE) && (pAdapterContext->Status.fVpGroup1Ready == TBX_FALSE)) )
{
/* Get voice processing ready state */
VoipSendAdapterGetVpGroupReadyState( pAdapterContext );
}
}
}
if( TBX_RESULT_SUCCESS( pAdapterContext->StateResult ) )
{
/* Proceed next state machine sub-state, if appropriate */
while( pAdapterContext->un32NbResponsesExpected == 0 )
{
if( pAdapterContext->ConfigSubState == VOIP_ADAPTER_SUB_STATE_1 )
{
/* Send the "alloc" or "config set" messages for all trunks/clock that need to be configured for this adapter */
Result = VoipAdapterAllocSubState1( pAdapterContext );
if( TBX_RESULT_FAILURE( Result ) )
{
pAdapterContext->StateResult = Result;
TBX_EXIT_ERROR (Result, 0, "Failed to configure/allocate trunks/clock on the adapter.");
}
/* Continue configuring (state 2) */
pAdapterContext->ConfigSubState = VOIP_ADAPTER_SUB_STATE_2;
}
else if( pAdapterContext->ConfigSubState == VOIP_ADAPTER_SUB_STATE_2 )
{
/* Send the "config" messages for all resources that need to be allocated for this adapter */
Result = VoipAdapterAllocSubState2( pAdapterContext );
if( TBX_RESULT_FAILURE( Result ) )
{
pAdapterContext->StateResult = Result;
TBX_EXIT_ERROR (Result, 0, "Failed to allocate resources on the adapter.");
}
/* Continue configuring (state 3) */
pAdapterContext->ConfigSubState = VOIP_ADAPTER_SUB_STATE_3;
}
else if( pAdapterContext->ConfigSubState == VOIP_ADAPTER_SUB_STATE_3 )
{
/* Send the "config" messages for all connections that need to be allocated for this adapter */
Result = VoipAdapterAllocSubState3( pAdapterContext );
if( TBX_RESULT_FAILURE( Result ) )
{
pAdapterContext->StateResult = Result;
TBX_EXIT_ERROR (Result, 0, "Failed to allocate connections on the adapter.");
}
/* Continue configuring (state done) */
pAdapterContext->ConfigSubState = VOIP_ADAPTER_SUB_STATE_DONE;
}
else if( pAdapterContext->ConfigSubState == VOIP_ADAPTER_SUB_STATE_DONE )
{
/* Done configuring */
break;
}
}
}
/* Test if it's time to detach from adapter events */
if( pAdapterContext->fAttached )
{
if( pAdapterContext->un32NbResponsesExpected == 0 )
{
if( ( pAdapterContext->fStopUsingPending ) &&
!pAdapterContext->fDetachSent )
{
VoipSendAdapterDetach( pAdapterContext );
pAdapterContext->fDetachSent = TBX_TRUE;
}
}
}
/* Test is we received all expected responses */
if( pAdapterContext->un32NbResponsesExpected == 0 )
{
/* No more waiting for responses. Continue to next state */
if( pAdapterContext->fStopUsingPending )
{
VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_2, "Stop using adapter -> No more pending responses\n" );
/* We wish to stop using this adapter. Go to "clear" state instead of "Ready" state. */
VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_CLEAR );
}
else if( pAdapterContext->fNewConfigPending )
{
VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_2, "Apply new config -> No more pending responses\n" );
/* We must apply a new config. Go back to 'sync' state */
VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_SYNC );
}
else if( pAdapterContext->fStateTimedout )
{
/* Adapter is still ready... but configure timed-out. Maybe we can try sync/configure again... */
VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_SYNC );
}
else if( pAdapterContext->fReadyToConfigure == TBX_FALSE )
{
VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_2, "Not ready to configure anymore\n" );
/* Go back to sync state and wait till fReadyToConfigure flags goes back up */
VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_SYNC );
}
else
{
if( TBX_RESULT_SUCCESS( pAdapterContext->StateResult ) )
{
VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_2, "Configuration alloc/set done\n" );
/* Finished configuring. Continue to "ready" state */
VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_READY );
}
else
{
/* Synchronization failed. */
VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_ERROR, "Alloc/set failed. Waiting timeout for retry\n" );
}
}
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print the error to the user */
VoipCliAdapterStatePrint(
pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipAdapterStateConfiguringAlloc: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
return;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterStateReady : Handles adapter state: VOIP_ADAPTER_STATE_READY.
| This function is called when receiving response/event
| from an adapter while it is "ready" (being used).
|
| io_pAdapterContext : Context of the adapter
| in_hMsg : Message received for this adapter
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipAdapterStateReady(
IN PTBX_VOID io_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
TBX_RESULT Result;
PVOIP_ADAPTER_CONTEXT pAdapterContext = io_pAdapterContext;
PVOIP_CLI_CONTEXT pCliContext;
PVOIP_STREAM_RES pStreamRes;
TBX_STREAM_PACKET_TYPE PacketType;
TBX_CHAR szErrorMsg[ 256 ];
TBX_UINT32 un32Index;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
Result = TBX_RESULT_OK;
pCliContext = &g_pContext->CliContext;
switch( TBX_MSG_ID_GET( in_hMsg ) )
{
VOIP_HANDLE_COMMON_EVENTS( pAdapterContext, in_hMsg, TBX_FALSE )
case VOIP_MSG_ID_NOTIF_STATE_ENTER:
{
/* send a 'ReadyState' event to test controller if in test mode */
if( g_pContext->TestModeContext.fTestMode == TBX_TRUE )
{
TBTestLibSendConfirmEventMessage
(
g_pContext->hTbxLib,
g_pContext->TestModeContext.hHostHandle,
0,
g_pContext->TestModeContext.un32TestId,
TBX_RESULT_AUTOTEST_OK,
"ReadyState",
""
);
}
/* Sanity check */
if( pAdapterContext->un32NbResponsesExpected != 0 )
{
VoipCliAdapterStatePrint
(
pAdapterContext,
TRACE_LEVEL_ERROR,
"BUG: State entered while %d responses still awaited from previous state!\n",
(int)pAdapterContext->un32NbResponsesExpected
);
pAdapterContext->un32NbResponsesExpected = 0;
}
/* Set initial state result */
pAdapterContext->StateResult = TBX_RESULT_OK;
pAdapterContext->fStateTimedout = TBX_FALSE;
pAdapterContext->fDetachSent = TBX_FALSE;
/* This adapter has finished configuring its resources */
pAdapterContext->fConfigured = TBX_TRUE;
/* Restore stress test reservation tables */
if( pAdapterContext->StressTest.fActive == TBX_TRUE )
{
/* Reset stress test stats */
VoipStressTestResetStats( pAdapterContext );
/* Update the map of reserved IP ports and the packet type counters */
pStreamRes = TBXPoolOfBuffersFirst( pAdapterContext->CurrentConfig.hPoolOfStreamRes );
while( pStreamRes )
{
if( pStreamRes->Params.un16FromNetworkIPPort >= VOIP_STRESS_TEST_FIRST_IP_PORT )
{
un32Index = ((pStreamRes->Params.un16FromNetworkIPPort - VOIP_STRESS_TEST_FIRST_IP_PORT) % VOIP_STRESS_TEST_IP_PORT_COUNT);
pAdapterContext->StressTest.afIpPortReserved[un32Index] = TBX_TRUE;
}
PacketType = pStreamRes->Params.PacketType;
for( un32Index = 0; un32Index < pAdapterContext->StressTest.un32PacketTypeCount; un32Index++ )
{
if( pAdapterContext->StressTest.aPacketTypeInfo[un32Index].PacketType == PacketType )
{
pAdapterContext->StressTest.aPacketTypeInfo[un32Index].un32CurrentCount++;
break;
}
}
pStreamRes = TBXPoolOfBuffersNext( pAdapterContext->Curr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -