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

📄 voip_adapter_state.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
			/*
			 * Response from our "voice processing" query messages
			 */
			case TB640_MSG_ID_VP_GROUP_GET_LIST:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetVpGroupListResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

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

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

			case TB640_MSG_ID_CONN_OP_GET_PARAMS:
			{
				/* Handle this response */
				Result = VoipHandleAdapterGetConnectionParamsResponse( 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 ) )
		{
			/* Proceed next state machine sub-state, if appropriate */
			while( pAdapterContext->un32NbResponsesExpected == 0 )
			{
				if( pAdapterContext->SyncSubState == VOIP_ADAPTER_SUB_STATE_2 )
				{
					/* Send the "get connection list" messages for this adapter */
					Result = VoipSendAdapterGetConnectionList( pAdapterContext );
					if( TBX_RESULT_FAILURE( Result ) )
					{
						pAdapterContext->StateResult = Result;
						TBX_EXIT_ERROR (Result, 0, "Failed to synchronize with connection on the adapter.");
					}

					pAdapterContext->SyncSubState = VOIP_ADAPTER_SUB_STATE_DONE;
				}
				else if( pAdapterContext->SyncSubState == VOIP_ADAPTER_SUB_STATE_DONE )
				{
					/* Done clearing */
					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 )
		{
			if( !pAdapterContext->fSyncCompleted )
			{
				/* This adapter has finished its sync state */
				pAdapterContext->fSyncCompleted = TBX_TRUE;
			}

			/* This adapter has finished its sync state */
			pAdapterContext->fSyncCompleted = TBX_TRUE;

			/* This adapter is ready to clear configuration */
			pAdapterContext->fReadyToClear = TBX_TRUE;

			/* 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->fStateTimedout )
			{
				/* Adapter is still ready... but sync timed-out. Maybe we can try sync again... */
				VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_SYNC );
			}
			else if( pAdapterContext->fReadyToClear == TBX_TRUE )
			{
				if( TBX_RESULT_SUCCESS( pAdapterContext->StateResult ) )
				{
					VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_2, "Sync done\n" );

					/* Finished synchronizing. Continue to "configuring clear" state */
					VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_CONFIGURING_CLEAR );
				}
				else
				{
					/* Synchronization failed. */
					VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_ERROR, "Sync 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,
			"VoipAdapterStateSync: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	return;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterStateConfiguringClear	:	Handles adapter state: VOIP_ADAPTER_STATE_CONFIGURING_CLEAR.
 |											This function is called when receiving response/event
 |											from an adapter while configuring that adapter.
 |
 |  io_pAdapterContext					:	Context of the adapter
 |	in_hMsg								:	Message received for this adapter
 |
 |  Note								:	~
 |
 |  Return								:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipAdapterStateConfiguringClear(
  IN		PTBX_VOID		io_pAdapterContext,
  IN		TBX_MSG_HANDLE	in_hMsg)
{
	TBX_RESULT				Result;
	PVOIP_ADAPTER_CONTEXT	pAdapterContext = io_pAdapterContext;
	TBX_CHAR				szErrorMsg[ 256 ];

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  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->fClearComplete				= TBX_FALSE;
				pAdapterContext->fConfigured				= TBX_FALSE;
				pAdapterContext->ClearSubState				= VOIP_ADAPTER_SUB_STATE_2;

				pAdapterContext->un32ConfiguringClearCount++;

				/* Check for new config */
				if( pAdapterContext->fNewConfigPending )
				{
					/* Switch the target config to the new target config (if valid) */
					if( pAdapterContext->pTargetConfig == &pAdapterContext->TargetConfig1 )
					{
						if( pAdapterContext->TargetConfig2.fLoaded )
						{
							pAdapterContext->pTargetConfig = &pAdapterContext->TargetConfig2;
						}
					}
					else
					{
						if( pAdapterContext->TargetConfig1.fLoaded )
						{
							pAdapterContext->pTargetConfig = &pAdapterContext->TargetConfig1;
						}
					}
				}

				/* Make sure to use the only valid config (if only one valid config exist) */
				if( !pAdapterContext->pTargetConfig->fLoaded )
				{
					TBX_EXIT_ERROR( TBX_RESULT_FAIL, 0 , "No valid configuration loaded." );
				}

				/* We start applying the new adapter config here */
				pAdapterContext->fNewConfigPending = TBX_FALSE;

				/* Mark the 'old' config as no more loaded */
				if( pAdapterContext->pTargetConfig == &pAdapterContext->TargetConfig1 )
				{
					pAdapterContext->TargetConfig2.fLoaded = TBX_FALSE;
				}
				else
				{
					pAdapterContext->TargetConfig1.fLoaded = TBX_FALSE;
				}

				/* Send the "clear" messages for all resources that need to be freed for this adapter */
				Result = VoipAdapterClearSubState1( pAdapterContext, TBX_FALSE );
				if( TBX_RESULT_FAILURE( Result ) )
				{
					pAdapterContext->StateResult = Result;
					TBX_EXIT_ERROR (Result, 0, "Failed to clear connections 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 configuring 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:
			{
				VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_2, "Applying new config -> waiting for pending responses\n" );

				/* We were clearing things, but now we have a new config to apply. We will go back to
				   the beginning of the 'clear' state as soon as we received pending responses for current state. */
				pAdapterContext->fNewConfigPending = TBX_TRUE;
			} break;

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

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

			case VOIP_MSG_ID_NOTIF_STATE_TIMEOUT:
			{
				/* Clear 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 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 "BERT free" messages
			 */
			case TB640_MSG_ID_BERT_RES_FREE:
			{
				/* Handle this response */
				Result = VoipHandleAdapterBertResClearResponse( pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) ) pAdapterContext->StateResult = Result;
			} break;

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

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

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

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

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

			/*

⌨️ 快捷键说明

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