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

📄 voip_adapter_state.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
	{
	}

	return;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterStateSync	:	Handles adapter state: VOIP_ADAPTER_STATE_SYNC.
 |								This function is called when receiving response/event
 |								from an adapter while trying to synchronize with adapter's
 |								current state.
 |
 |  io_pAdapterContext		:	Context of the adapter
 |	in_hMsg					:	Message received for this adapter
 |
 |  Note					:	~
 |
 |  Return					:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipAdapterStateSync(
  IN		PTBX_VOID		io_pAdapterContext,
  IN		TBX_MSG_HANDLE	in_hMsg)
{
	TBX_RESULT				Result;
	PVOIP_ADAPTER_CONTEXT	pAdapterContext = io_pAdapterContext;
	TBX_CHAR				szErrorMsg[ 256 ];
	TBX_UINT32				un32Index;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		Result = TBX_RESULT_OK;

		switch( TBX_MSG_ID_GET( in_hMsg ) )
		{
			VOIP_HANDLE_COMMON_EVENTS( pAdapterContext, in_hMsg, TBX_FALSE )

			case VOIP_MSG_ID_NOTIF_STATE_ENTER:
			{
				/* 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;
				pAdapterContext->fSyncCompleted		= TBX_FALSE;
				pAdapterContext->fReadyToClear		= TBX_FALSE;
				pAdapterContext->fReadyToConfigure	= TBX_FALSE;
				pAdapterContext->SyncSubState		= VOIP_ADAPTER_SUB_STATE_2;

				/* Reset the map of reserved IP port */
				for( un32Index = 0; un32Index < VOIP_STRESS_TEST_IP_PORT_COUNT; un32Index++ )
				{
					pAdapterContext->StressTest.afIpPortReserved[un32Index]	= TBX_FALSE;
					pAdapterContext->StressTest.un32IpPortReservedLast		= 0;
				}

				/* Reset the packet type counters */
				for( un32Index = 0; un32Index < pAdapterContext->StressTest.un32PacketTypeCount; un32Index++ )
				{
					pAdapterContext->StressTest.aPacketTypeInfo[un32Index].un32CurrentCount = 0;
				}

				if( !pAdapterContext->fAttached )
				{
					/* Attach to events from this adapter */
					VoipSendAdapterAttach( pAdapterContext );
				}

				/* Stop playing prompts and clear stream server prompts */
				VoipStreamServerPromptCleanup();

				/* Clear all our contexts related to this adapter before re-synchronizing with it. */
				VoipAdapterClearConfig( &pAdapterContext->CurrentConfig );

				/* Clear this adapter's current status */
				memset( &pAdapterContext->Status, 0, sizeof(pAdapterContext->Status) );

				/* Reallocate empty tables and lists to fill while we are synchronizing */
				VoipAdapterAllocConfig( &pAdapterContext->CurrentConfig );

				Result = VoipSendAdapterConfigGet( pAdapterContext );
				if( TBX_RESULT_FAILURE( Result ) )
				{
					pAdapterContext->StateResult = Result;
					TBX_EXIT_ERROR (Result, 0, "Failed to get adapter configuration.");
				}

				Result = VoipSendAdapterGetClockConfig( pAdapterContext );
				if( TBX_RESULT_FAILURE( Result ) )
				{
					pAdapterContext->StateResult = Result;
					TBX_EXIT_ERROR (Result, 0, "Failed to synchronize with clock config on the adapter.");
				}

				Result = VoipSendAdapterGetClockStates( pAdapterContext );
				if( TBX_RESULT_FAILURE( Result ) )
				{
					pAdapterContext->StateResult = Result;
					TBX_EXIT_ERROR (Result, 0, "Failed to synchronize with clock config on the adapter.");
				}

				Result = VoipSendAdapterGetBertResList( pAdapterContext );
				if( TBX_RESULT_FAILURE( Result ) )
				{
					pAdapterContext->StateResult = Result;
					TBX_EXIT_ERROR (Result, 0, "Failed to synchronize with BERT resources on the adapter.");
				}

			} break;

			case VOIP_MSG_ID_NOTIF_ADAPTER_ACTIVATED_CHANGED:
			{
				/* Nothing to do here */
			} break;

			case VOIP_MSG_ID_NOTIF_STOP_USING:
			{
				VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_3, "Stop using adapter -> waiting for pending responses\n" );

				/* We are actually synchronizing the adapter. Stop configuring, wait for missing responses,
				   and continue to "not used" state. */
				pAdapterContext->fStopUsingPending	= TBX_TRUE;
			} break;

			case VOIP_MSG_ID_NOTIF_APPLY_NEW_CONFIG:
			{
				pAdapterContext->fNewConfigPending = TBX_TRUE;
			} break;

			case VOIP_MSG_ID_NOTIF_RECHECK_STATES:
			{
				/* Nothing to do. Only to wake up state machine so it will check the fReadyToConfigure flag */
			} break;

			case VOIP_MSG_ID_NOTIF_UPDATE_ALL_STATES:
			{
				/* Nothing to do */
			} break;

			case VOIP_MSG_ID_NOTIF_STATE_TIMEOUT:
			{
				/* Sync timeout */
				VoipCliAdapterStatePrint(  pAdapterContext, TRACE_LEVEL_ERROR, "Timeout\n");

				pAdapterContext->fStateTimedout				= TBX_TRUE;
				pAdapterContext->un32NbResponsesExpected	= 0;	/* Assume we will not receive the missing responses. */
			} break;

			/*
			 * Response from adapter attach
			 */
			case TB640_MSG_ID_ADAPTER_OP_ATTACH:
			{
				/* Handle this response */
				Result = VoipHandleAdapterAttachResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			/*
			 * Response from adapter detach
			 */
			case TB640_MSG_ID_ADAPTER_OP_DETACH:
			{
				/* Handle this response */
				Result = VoipHandleAdapterDetachResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			/*
			 * Response from our "adapter config get" query messages
			 */
			case TB640_MSG_ID_ADAPTER_CFG_GET:
			{
				/* Handle this response */
				Result = VoipHandleAdapterConfigGetResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) 
				{
					pAdapterContext->StateResult = Result;
				}
				else
				{
					if( pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_MAX_TRUNK] )
					{
						/* Start adapter synchronization state */
						Result = VoipSendAdapterGetTrunkList( pAdapterContext );
						if( TBX_RESULT_FAILURE( Result ) )
						{
							pAdapterContext->StateResult = Result;
							TBX_EXIT_ERROR (Result, 0, "Failed to synchronize with trunks on the adapter.");
						}
					}

					if( pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_MBL_MAX_PORT] )
					{
						Result = VoipSendAdapterGetMblPortList( pAdapterContext );
						if( TBX_RESULT_FAILURE( Result ) )
						{
							pAdapterContext->StateResult = Result;
							TBX_EXIT_ERROR (Result, 0, "Failed to synchronize with MBL ports on the adapter.");
						}
					}

					if( (pAdapterContext->CurrentConfig.fVpGroup0Available == TBX_TRUE) ||
						(pAdapterContext->CurrentConfig.fVpGroup1Available == TBX_TRUE) )
					{
						Result = VoipSendAdapterGetStreamResList( pAdapterContext );
						if( TBX_RESULT_FAILURE( Result ) )
						{
							pAdapterContext->StateResult = Result;
							TBX_EXIT_ERROR (Result, 0, "Failed to synchronize with stream resources on the adapter.");
						}

						Result = VoipSendAdapterGetVpGroupList( pAdapterContext );
						if( TBX_RESULT_FAILURE( Result ) )
						{
							pAdapterContext->StateResult = Result;
							TBX_EXIT_ERROR (Result, 0, "Failed to synchronize with voice processing groups on the adapter.");
						}
					}
				}

			} break;

			/*
			 * Response from our "clock" query messages
			 */
			case TB640_MSG_ID_CLK_SYNC_CFG_GET:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetClockConfigResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_CLK_SYNC_STATES_GET:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetClockStatesResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			/*
			 * Response from our "BERT" query messages
			 */
			case TB640_MSG_ID_BERT_RES_GET_LIST:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetBertResListResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_BERT_RES_GET_PARAMS:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetBertResParamsResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_BERT_RES_GET_STATES:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetBertResStatesResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			/*
			 * Response from our "trunk" list/query messages
			 */
			case TB640_MSG_ID_TRUNK_OP_GET_LIST:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetTrunkListResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_TRUNK_OP_GET_PARAMS:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetTrunkParamsResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_TRUNK_STATES_GET:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetTrunkStatesResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_TRUNK_RES_GET_LIST:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetTrunkResListResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_TRUNK_RES_GET_PARAMS:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetTrunkResParamsResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_PMALARMMGR_OP_GET_ALL_COUNTERS:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetPmCountersResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			/*
			 * Response from our "MBL port" list/query messages
			 */
			case TB640_MSG_ID_MBL_PORT_OP_GET_LIST:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetMblPortListResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_MBL_PORT_OP_GET_PARAMS:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetMblPortParamsResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_MBL_RES_GET_LIST:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetMblPortResListResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_MBL_RES_GET_PARAMS:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetMblPortResParamsResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			/*
			 * Response from our "Stream" query messages
			 */
			case TB640_MSG_ID_STREAM_RES_GET_LIST:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetStreamResListResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

			case TB640_MSG_ID_STREAM_RES_GET_PARAMS:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetStreamResParamsResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

⌨️ 快捷键说明

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