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

📄 voip_adapter_clear.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VOIP sample
 |
 |	Filename:   	voip_adapter_clear.c
 |
 |	Copyright:  	TelcoBridges 2002-2004, All Rights Reserved
 |
 |	Description:	This file contains functions used to clear adapter configurations
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.31 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Includes
 *------------------------------------------------------------------------------------------------------------------------------*/

#include "voip_includes.h"


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Forward declarations
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Types
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/

#ifdef WIN32
/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.31 $";
#endif


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Macros
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Function Prototypes
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Implementation
 *------------------------------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterClearSubState1	:	Compares the current configuration of the adapter with
 |									its target configuration, and clears all resources that
 |									don't match the target configuration (first step).
 |
 |	in_pAdapterContext			:	Adapter we are configuring
 |	in_fForceClear				:	Force clear all connections on the adapter
 |
 |  Note						:	~
 |
 |  Return						:	TBX_RESULT_OK if the function succeeded
 |									Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterClearSubState1(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_BOOL				in_fForceClear)
{
	TBX_RESULT	Result;
	TBX_BOOL	fMustClear;
	TBX_BOOL	fMustSetConfigDummy;
	TBX_UINT32	un32Index;

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

		/*
		 * Free prompts
		 */
		{
			PVOIP_PROMPT_CONTEXT	pCurrentPromptContext;
			PVOIP_PROMPT_CONTEXT	pNextPromptContext;
			PVOIP_PROMPT_CONTEXT	pTargetPromptContext;

			pCurrentPromptContext = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfPrompts );
			while( pCurrentPromptContext )
			{
				fMustClear = TBX_FALSE;
				if( pCurrentPromptContext->fAllocated == TBX_TRUE )
				{
					/* Test if we must clear connection */
					if( in_fForceClear )
					{
						fMustClear = TBX_TRUE;
					}
					else
					{
						/* Find the corresponding target stream resource context */
						Result = TBXHashFind
						(
							in_pAdapterContext->pTargetConfig->hPromptNameHash,
							(TBX_HASH_KEY)pCurrentPromptContext->Params.szPromptName,
							(PTBX_VOID*)&pTargetPromptContext
						);
						if( (TBX_RESULT_SUCCESS( Result ) == TBX_TRUE) && (pTargetPromptContext != NULL) )
						{
							/* Validate stream resource parameters */
							VoipCliAdapterStatePrint(
								in_pAdapterContext,
								TRACE_LEVEL_0,
								"Stop playing prompt %s config\n",
								pCurrentPromptContext->Params.szPromptName);

							VoipAdapterPromptConfigureCompare(
								in_pAdapterContext,
								pCurrentPromptContext,
								pTargetPromptContext,
								&fMustClear,
								&fMustSetConfigDummy);
						}
						else
						{
							fMustClear = TBX_TRUE;
						}
					}

				}

				/* Get next prompt context before clearing current prompt context */
				pNextPromptContext = TBXPoolOfBuffersNext( in_pAdapterContext->CurrentConfig.hPoolOfPrompts, pCurrentPromptContext );

				if( fMustClear == TBX_TRUE )
				{
					/*
					 *	Clear prompt
					 */
					Result = VoipAdapterPromptClear(
						in_pAdapterContext,
						pCurrentPromptContext);
					if( TBX_RESULT_FAILURE( Result ) )
					{
						TBX_EXIT_ERROR (Result, 0, "Failed to clear prompt context");
					}
				}

				pCurrentPromptContext = pNextPromptContext;
			}
		}

		/*
		 * Free raw data files
		 */
		{
			PVOIP_RAW_DATA_FILE_CONTEXT	pCurrentRawDataFileContext;
			PVOIP_RAW_DATA_FILE_CONTEXT	pNextRawDataFileContext;
			PVOIP_RAW_DATA_FILE_CONTEXT	pTargetRawDataFileContext;

			in_pAdapterContext->fRawDataFileClearInProgress = TBX_FALSE;
			
			pCurrentRawDataFileContext = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfRawDataFiles );
			while( pCurrentRawDataFileContext )
			{
				if( pCurrentRawDataFileContext->fAllocated == TBX_TRUE )
				{
					/* Test if we must clear connection */
					if( in_fForceClear )
					{
						fMustClear = TBX_TRUE;
					}
					else
					{
						/* Find the corresponding target stream resource context */
						Result = TBXHashFind
						(
							in_pAdapterContext->pTargetConfig->hRawDataFileNameHash,
							(TBX_HASH_KEY)pCurrentRawDataFileContext->Params.szRawDataFileResName,
							(PTBX_VOID*)&pTargetRawDataFileContext
						);
						if( (TBX_RESULT_SUCCESS( Result ) == TBX_TRUE) && (pTargetRawDataFileContext != NULL) )
						{
							/* Validate stream resource parameters */
							VoipCliAdapterStatePrint(
								in_pAdapterContext,
								TRACE_LEVEL_0,
								"Stop playing raw data file %s config\n",
								pCurrentRawDataFileContext->Params.szRawDataFileResName);

							VoipAdapterRawDataFileConfigureCompare(
								in_pAdapterContext,
								pCurrentRawDataFileContext,
								pTargetRawDataFileContext,
								&fMustClear,
								&fMustSetConfigDummy);
						}
						else
						{
							fMustClear = TBX_TRUE;
						}
					}

					/* Keep pointer to next prompt context before possibly freeing the current one */
					pNextRawDataFileContext = TBXPoolOfBuffersNext( in_pAdapterContext->CurrentConfig.hPoolOfRawDataFiles, pCurrentRawDataFileContext );

					if( fMustClear == TBX_TRUE )
					{
						/*
						 *	Clear raw data file
						 */
						VoipCliAdapterStatePrint(
							in_pAdapterContext,
							TRACE_LEVEL_2,
							"Calling VoipAdapterRawDataFileClear on raw data file %s\n",
							pCurrentRawDataFileContext->Params.szRawDataFileResName);

						Result = VoipAdapterRawDataFileClear(
							in_pAdapterContext,
							pCurrentRawDataFileContext);
						if( Result == TBX_RESULT_OPERATION_INCOMPLETE )
						{
							VoipCliAdapterStatePrint(
								in_pAdapterContext,
								TRACE_LEVEL_2,
								"Setting fRawDataFileClearInProgress\n",
								pCurrentRawDataFileContext->Params.szRawDataFileResName);

							in_pAdapterContext->fRawDataFileClearInProgress = TBX_TRUE;
						}
						else if( TBX_RESULT_FAILURE( Result ) )
						{
							TBX_EXIT_ERROR (Result, 0, "Failed to clear raw data file context");
						}
					}
				}

				pCurrentRawDataFileContext = pNextRawDataFileContext;
			}
		}

		/*
		 * Validate BERT resources
		 */
		{
			PVOIP_BERT_RES	pCurrentBertRes;
			PVOIP_BERT_RES	pTargetBertRes;

			pCurrentBertRes		= &in_pAdapterContext->CurrentConfig.aBertRes[ 0 ];
			pTargetBertRes		= &in_pAdapterContext->pTargetConfig->aBertRes[ 0 ];

			fMustClear = TBX_FALSE;
			if( pCurrentBertRes->Common.fAllocated == TBX_TRUE )
			{
				/* Test if we must clear BERT resources */
				if( in_fForceClear )
				{
					fMustClear = TBX_TRUE;
				}
				else
				{
					/* Validate BERT resource parameters */
					VoipCliAdapterStatePrint(
						in_pAdapterContext,
						TRACE_LEVEL_0,
						"Validating BERT resource 0x%08X config\n",
						pCurrentBertRes->Common.hRes );

					VoipAdapterBertResConfigureCompare(
						in_pAdapterContext,
						pCurrentBertRes,
						pTargetBertRes,
						&fMustClear,
						&fMustSetConfigDummy);
				}

				pCurrentBertRes->Common.fMustClear = fMustClear;
			}
		}

		/*
		 * Validate trunk resources
		 */
		{
			TBX_UINT32			un32TrunkNb;
			TBX_UINT32			un32TimeSlotNb;
			PVOIP_TRUNK_CONFIG	pCurrentTrunkConfig;
			PVOIP_TRUNK_CONFIG	pTargetTrunkConfig;
			PVOIP_TRUNK_RES		pCurrentTrunkRes;
			PVOIP_TRUNK_RES		pTargetTrunkRes;

			for( un32TrunkNb = 0; un32TrunkNb < VOIP_MAX_TRUNK_PER_ADAPTER; un32TrunkNb++ )
			{
				pCurrentTrunkConfig	= &in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNb ];
				pTargetTrunkConfig	= &in_pAdapterContext->pTargetConfig->aTrunk[ un32TrunkNb ];

				fMustClear = TBX_FALSE;
				if (pCurrentTrunkConfig->fAllocated == TBX_TRUE)
				{
					/* Test if we must clear resources for this trunk */
					if( in_fForceClear )
					{
						fMustClear = TBX_TRUE;
					}
					else
					{
						VoipAdapterTrunkConfigureCompare(
							in_pAdapterContext,
							pCurrentTrunkConfig,
							pTargetTrunkConfig,
							&fMustClear,
							&fMustSetConfigDummy);
					}

					pCurrentTrunkConfig->fMustClear = fMustClear;

					if( fMustClear == TBX_FALSE )
					{
						for( un32TimeSlotNb = 0; un32TimeSlotNb < VOIP_MAX_RES_PER_TRUNK; un32TimeSlotNb++ )
						{
							pCurrentTrunkRes	= &pCurrentTrunkConfig->aRes[ un32TimeSlotNb ];
							pTargetTrunkRes		= &pTargetTrunkConfig->aRes[ un32TimeSlotNb ];

							if ( pCurrentTrunkRes->Common.fAllocated == TBX_TRUE )
							{
								if( fMustClear == TBX_FALSE )
								{
									/* Validate trunk resource parameters */
									VoipCliAdapterStatePrint(
										in_pAdapterContext,
										TRACE_LEVEL_0,
										"Validating trunk resource 0x%08X config\n",
										(int)pCurrentTrunkRes->Common.hRes );

									if( pCurrentTrunkRes->ResType != TB640_RESOURCE_TYPE_FD )
									{
										fMustClear = TBX_TRUE;
									}

									if( pCurrentTrunkRes->un32TimeSlot != un32TimeSlotNb )
									{
										fMustClear = TBX_TRUE;
									}

									if( pCurrentTrunkRes->ChannelRate != TB640_RESOURCE_CHANNEL_RATE_64KBPS )
									{
										fMustClear = TBX_TRUE;
									}

									if( pCurrentTrunkRes->un32Channel != 0 )
									{
										fMustClear = TBX_TRUE;
									}
								}
							}
						}
					}

					if( fMustClear == TBX_TRUE )
					{
						for( un32TimeSlotNb = 0; un32TimeSlotNb < VOIP_MAX_RES_PER_TRUNK; un32TimeSlotNb++ )
						{
							pCurrentTrunkRes = &pCurrentTrunkConfig->aRes[ un32TimeSlotNb ];

							if ( pCurrentTrunkRes->Common.fAllocated == TBX_TRUE )
							{
								pCurrentTrunkRes->Common.fMustClear = fMustClear;
							}
						}

⌨️ 快捷键说明

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