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

📄 voip_adapter_alloc.c

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


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

#include "voip_includes.h"


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


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


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


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

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


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


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


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


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

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterAllocSubState1	:	Compares the Target configuration of the adapter with
 |									its Current configuration, and allocates all resources that
 |									don't match the Target configuration (first step).
 |
 |	in_pAdapterContext			:	Adapter we are configuring
 |
 |  Note						:	~
 |
 |  Return						:	TBX_RESULT_OK if the function succeeded
 |									Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterAllocSubState1(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext)
{
	TBX_RESULT	Result;

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

		/*
		 * Set clock configuration.
		 */
		{
			/* Set the clock configuration */
			Result = VoipSendAdapterSetClockConfig( in_pAdapterContext );
			if( TBX_RESULT_FAILURE( Result ) )
			{
				TBX_EXIT_ERROR (Result, 0, "Failed to set clock configuration");
			}
		}

		/*
		 * Allocate prompts
		 */
		{
			PVOIP_PROMPT_CONTEXT	pCurrentPromptContext;
			PVOIP_PROMPT_CONTEXT	pTargetPromptContext;

			pTargetPromptContext = TBXPoolOfBuffersFirst( in_pAdapterContext->pTargetConfig->hPoolOfPrompts );
			while( pTargetPromptContext )
			{
				if( pTargetPromptContext->fAllocated == TBX_TRUE )
				{
					/* Find the corresponding current prompt context */
					Result = TBXHashFind
					(
						in_pAdapterContext->CurrentConfig.hPromptNameHash,
						(TBX_HASH_KEY)pTargetPromptContext->Params.szPromptName,
						(PTBX_VOID*)&pCurrentPromptContext
					);

					if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
					{
						/* Allocate prompt */
						Result = VoipAdapterPromptAlloc(
							in_pAdapterContext,
							pTargetPromptContext);
						if( TBX_RESULT_FAILURE( Result ) )
						{
							TBX_EXIT_ERROR (Result, 0, "Failed to allocate prompt");
						}
					}
				}

				pTargetPromptContext = TBXPoolOfBuffersNext( in_pAdapterContext->pTargetConfig->hPoolOfPrompts, pTargetPromptContext );
			}
		}

		/*
		 * Allocate raw data files
		 */
		{
			PVOIP_RAW_DATA_FILE_CONTEXT	pCurrentRawDataFileContext;
			PVOIP_RAW_DATA_FILE_CONTEXT	pTargetRawDataFileContext;

			pTargetRawDataFileContext = TBXPoolOfBuffersFirst( in_pAdapterContext->pTargetConfig->hPoolOfRawDataFiles );
			while( pTargetRawDataFileContext )
			{
				if( pTargetRawDataFileContext->fAllocated == TBX_TRUE )
				{
					/* Find the corresponding current raw data file context */
					Result = TBXHashFind
					(
						in_pAdapterContext->CurrentConfig.hRawDataFileNameHash,
						(TBX_HASH_KEY)pTargetRawDataFileContext->Params.szRawDataFileResName,
						(PTBX_VOID*)&pCurrentRawDataFileContext
					);

					if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
					{
						/* Allocate raw data file */
						Result = VoipAdapterRawDataFileAlloc(
							in_pAdapterContext,
							pTargetRawDataFileContext);
						if( TBX_RESULT_FAILURE( Result ) )
						{
							TBX_EXIT_ERROR (Result, 0, "Failed to allocate raw data file");
						}
					}
				}

				pTargetRawDataFileContext = TBXPoolOfBuffersNext( in_pAdapterContext->pTargetConfig->hPoolOfRawDataFiles, pTargetRawDataFileContext );
			}
		}

		/*
		 * Allocate BERT resource
		 */
		{
			PVOIP_BERT_RES	pCurrentBertRes;
			PVOIP_BERT_RES	pTargetBertRes;

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

			if( (pCurrentBertRes->Common.fAllocated == TBX_FALSE) && (pTargetBertRes->Common.fAllocated == TBX_TRUE) )
			{
				/* Allocate the BERT resource */
				Result = VoipSendAdapterBertResAlloc(
					in_pAdapterContext,
					pTargetBertRes);
				if( TBX_RESULT_FAILURE( Result ) )
				{
					TBX_EXIT_ERROR (Result, 0, "Failed to allocate BERT resource");
				}
			}
		}

		/*
		 * Allocate/set every trunk configuration.
		 */
		{
			TBX_UINT32			un32TrunkNb;
			PVOIP_TRUNK_CONFIG	pTargetTrunkConfig;

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

				if( pTargetTrunkConfig->fAllocated == TBX_TRUE )
				{
					/* Set the configuration for this trunk (that function will allocate it if not already done) */
					Result = VoipSendAdapterTrunkSet(
						in_pAdapterContext,
						pTargetTrunkConfig);
					if( TBX_RESULT_FAILURE( Result ) )
					{
						TBX_EXIT_ERROR (Result, 0, "Failed to alloc/set trunk configuration");
					}
				}
			}
		}

		/*
		 * Allocate every MBL ports.
		 */
		{
			TBX_UINT32				un32PortNb;
			PVOIP_MBL_PORT_CONFIG	pCurrentMblPortConfig;
			PVOIP_MBL_PORT_CONFIG	pTargetMblPortConfig;

			for( un32PortNb = 0; un32PortNb < VOIP_MAX_MBL_PORT_PER_ADAPTER; un32PortNb++ )
			{
				pCurrentMblPortConfig = &in_pAdapterContext->CurrentConfig.aMblPort[ un32PortNb ];
				pTargetMblPortConfig = &in_pAdapterContext->pTargetConfig->aMblPort[ un32PortNb ];

				if( (pTargetMblPortConfig->fAllocated == TBX_TRUE) && (pCurrentMblPortConfig->fAllocated == TBX_FALSE) )
				{
					/* Set the configuration for this MBL port (that function will allocate it if not already done) */
					Result = VoipSendAdapterMblPortAlloc(
						in_pAdapterContext,
						pTargetMblPortConfig);
					if( TBX_RESULT_FAILURE( Result ) )
					{
						TBX_EXIT_ERROR (Result, 0, "Failed to alloc MBL port");
					}
				}
			}
		}

		/*
		 * Allocate stream resources
		 */
		{
			PVOIP_STREAM_RES			pCurrentStreamRes;
			PVOIP_STREAM_RES			pTargetStreamRes;

			pTargetStreamRes = TBXPoolOfBuffersFirst( in_pAdapterContext->pTargetConfig->hPoolOfStreamRes );
			while( pTargetStreamRes )
			{
				if( pTargetStreamRes->Common.fAllocated == TBX_TRUE )
				{
					/* Find the corresponding current stream resource context */
					Result = TBXHashFind
					(
						in_pAdapterContext->CurrentConfig.hStreamResHash,
						(TBX_HASH_KEY)pTargetStreamRes->Common.un32ConnectionId,
						(PTBX_VOID*)&pCurrentStreamRes
					);

					if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
					{
						/*
						 *	Allocate the stream resource
						 */
						Result = VoipSendAdapterStreamResAlloc(
							in_pAdapterContext,
							pTargetStreamRes);
						if( TBX_RESULT_FAILURE( Result ) )
						{
							TBX_EXIT_ERROR (Result, 0, "Failed to allocate stream resource");
						}
					}
				}

				pTargetStreamRes = TBXPoolOfBuffersNext( in_pAdapterContext->pTargetConfig->hPoolOfStreamRes, pTargetStreamRes );
			}
		}

		/*
		 * Allocate voice processing resources
		 */
		{
			PVOIP_VP_GROUP	pCurrentVpGroup;
			PVOIP_VP_GROUP	pTargetVpGroup;

			pTargetVpGroup = TBXPoolOfBuffersFirst( in_pAdapterContext->pTargetConfig->hPoolOfVpGroups );
			while( pTargetVpGroup )
			{
				if( pTargetVpGroup->Common.fAllocated == TBX_TRUE )
				{
					/* Find the corresponding current voice processing group context */
					Result = TBXHashFind
					(
						in_pAdapterContext->CurrentConfig.hVpGroupHash,
						(TBX_HASH_KEY)pTargetVpGroup->Common.un32ConnectionId,
						(PTBX_VOID*)&pCurrentVpGroup
					);

					if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
					{
						/*
						 *	Allocate the voice processing group
						 */
						Result = VoipSendAdapterVpGroupAlloc(
							in_pAdapterContext,
							pTargetVpGroup);
						if( TBX_RESULT_FAILURE( Result ) )
						{
							TBX_EXIT_ERROR (Result, 0, "Failed to allocate voice processing group");
						}
					}
				}

				pTargetVpGroup = TBXPoolOfBuffersNext( in_pAdapterContext->pTargetConfig->hPoolOfVpGroups, pTargetVpGroup );
			}
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		VoipCliAdapterStatePrint(
			in_pAdapterContext,
			TRACE_LEVEL_ERROR,
			"VoipAdapterAllocSubState1: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

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

	RETURN;

⌨️ 快捷键说明

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