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

📄 voip_adapter_configure.c

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


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

#include "voip_includes.h"


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


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

/*#define VOIP_PROMPT_USE_GROUP1*/	/* Use group 1 for prompts playback (not supported) */


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


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

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


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


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


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


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

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterAdd			:	Add and fill a new adapter context
 |
 |	in_hPoolOfAdapters		:	Pool of adapters to allocate from
 |  in_pszAdapterName		:	Name of the adapter
 |	out_ppAdapterContext	:	Returns the allocated adapter context
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK if the list of hosts has been properly loaded
 |								Other error code if the list of hosts could not be loaded.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipAdapterAdd(
	IN		TBX_POOL_OF_BUFFERS_HANDLE	in_hPoolOfAdapters,
	IN		PTBX_CHAR					in_pszAdapterName,
	OUT		PVOIP_ADAPTER_CONTEXT*		out_ppAdapterContext)
{
	TBX_RESULT				Result;
	PVOIP_CLI_CONTEXT		pCliContext = &g_pContext->CliContext;
	PVOIP_ADAPTER_CONTEXT	pAdapterContext;
	PVOIP_ADAPTER_CONTEXT_NODE	pAdapterContextNode;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pAdapterContext = NULL;
		pAdapterContextNode = NULL;

		/* Make sure adapter name is unique */
		pAdapterContextNode = TBXPoolOfBuffersFind
		(
			in_hPoolOfAdapters,
			(TBX_HASH_KEY)in_pszAdapterName
		);
		if( pAdapterContextNode )
		{
			if( pAdapterContext->State != VOIP_ADAPTER_STATE_NOT_USED )
			{
				TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Adapter already defined.");
			}
		}
		else
		{
			pAdapterContextNode = TBXPoolOfBuffersAlloc
			(
				in_hPoolOfAdapters,
				(TBX_HASH_KEY)in_pszAdapterName
			);
			if( !pAdapterContextNode )
			{
				TBX_EXIT_ERROR (TBX_RESULT_NOT_ENOUGH_MEMORY, 0, "Failed to allocate context of adapter.");
			}
			memset( pAdapterContextNode, 0, sizeof(*pAdapterContextNode) );
			strcpy( pAdapterContextNode->szAdapterName, in_pszAdapterName );
			pAdapterContextNode->pAdapterContext = (PVOIP_ADAPTER_CONTEXT)calloc( 1, sizeof(*pAdapterContextNode->pAdapterContext) );
			if( !pAdapterContextNode->pAdapterContext )
			{
				TBXPoolOfBuffersFree( in_hPoolOfAdapters, pAdapterContextNode );
				pAdapterContextNode = NULL;

				TBX_EXIT_ERROR (TBX_RESULT_NOT_ENOUGH_MEMORY, 0, "Maximum number of adapters reached.");
			}

			/* Initialize the adapter context */
			strcpy( pAdapterContextNode->pAdapterContext->szAdapterName, in_pszAdapterName );
			pAdapterContextNode->pAdapterContext->pTargetConfig	= &pAdapterContextNode->pAdapterContext->TargetConfig1;
		}
		pAdapterContext = pAdapterContextNode->pAdapterContext;

		/* Set adapter initial state */
		pAdapterContext->State = VOIP_ADAPTER_STATE_NOT_READY;

		/* If we are allocating an actual adapter config (not just a temp adapter config while reading the
		   config file), then we may want to force "adapter added" event... */
		if( in_hPoolOfAdapters == g_pContext->hPoolOfAdapters )
		{
			if( !pAdapterContext->fPresent )
			{
				TBX_ADAPTER_HANDLE	ahAdapters[ VOIP_MAX_ADAPTERS ];
				TBX_UINT			un32NbAdapters = 0;

				/* Adapter not present. List adapters discovered by host lib, in case it was discovered
				   earlier and ignored because we were not interested in that adapter at that time */
				Result = TBXGetAdaptersList
				(
					g_pContext->hTbxLib,
					VOIP_MAX_ADAPTERS,
					&un32NbAdapters,
					ahAdapters
				);
				if( TBX_RESULT_SUCCESS( Result ) )
				{
					TBX_UINT	un32Index;
					for( un32Index = 0; un32Index < un32NbAdapters; un32Index++ )
					{
						TBX_ADAPTER_INFO	AdapterInfo;
						Result = TBXGetAdapterInfo
						(
							g_pContext->hTbxLib,
							ahAdapters[ un32Index ],
							&AdapterInfo
						);
						if( TBX_RESULT_SUCCESS( Result ) )
						{
							if( strcmp( AdapterInfo.szAdapterName, pAdapterContext->AdapterInfo.szAdapterName ) == 0 )
							{
								/* Found it! Simulate the "adapter added" event for this adapter */
								TBX_MSG_HANDLE		hMsg;

								TBXGetMsg (g_pContext->hTbxLib, sizeof( TBX_EVT_API_NOTIF_ADAPTER_ADDED ), &hMsg);
								if( hMsg != (TBX_MSG_HANDLE)TBX_HANDLE_INVALID )
								{
									PTBX_EVT_API_NOTIF_ADAPTER_ADDED	pMsg =
										(PTBX_EVT_API_NOTIF_ADAPTER_ADDED) TBX_MSG_PAYLOAD_POINTER( hMsg );

									TBX_FORMAT_MSG_HEADER
									(
										hMsg,
										TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED,
										TBX_MSG_TYPE_EVENT,
										sizeof( TBX_EVT_API_NOTIF_ADAPTER_ADDED ),
										ahAdapters[ un32Index ],
										0,
										0
									);

									pMsg->Info = AdapterInfo;

									VoipHandleAdapterAdded( hMsg );

									TBXReleaseMsg (g_pContext->hTbxLib, hMsg);
									break;
								}
							}
						}
					}
				}

				if( pAdapterContext->AdapterInfo.hAdapter != (TBX_ADAPTER_HANDLE)TBX_HANDLE_INVALID )
				{
					/* Enable networking with this adapter */
					VoipConfigureNetworkRedundancy
					(
						pAdapterContext->AdapterInfo.hAdapter,
						TBX_TRUE
					);
				}
			}
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print the error to the user */
		TbxCliToolsLogPrint(
			pCliContext->hCliTools,
			TRACE_LEVEL_ERROR, NULL,
			"VoipAdapterAdd: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		if( out_ppAdapterContext )
		{
			*out_ppAdapterContext = pAdapterContext;
		}
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterAddConnectionToTarget	:	Add new connection to target configuration.
 |
 |	in_pAdapterContext					:	Adapter we are configuring
 |	in_pConnectionParams				:	Connection parameters
 |	io_pun32ConnectionId				:	Connection identifier of the new created connection.
 |	io_ppConnectionContext				:	Context of the newly created connection.
 |
 |  Note								:	~
 |
 |  Return								:	TBX_RESULT_OK if the function succeeded
 |											Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterAddConnectionToTarget(
	IN		PVOIP_ADAPTER_CONTEXT		in_pAdapterContext,
	IN		PVOIP_CONNECTION_PARAMS		in_pConnectionParams,
	IN OUT	PVOIP_CONNECTION_CONTEXT *	io_ppConnectionContext)
{
	TBX_RESULT					Result;
	PVOIP_TRUNK_CONFIG			pTrunkConfig;
	PVOIP_MBL_PORT_CONFIG		pMblPortConfig;
	PVOIP_STREAM_RES			pStreamRes;
	PVOIP_RAW_DATA_FILE_CONTEXT	pRawDataFileContext;
	PVOIP_VP_GROUP				pVpGroup;
	PVOIP_VP_GRP0_PARAMS		pVpGrp0Params;
	PVOIP_VP_GRP1_PARAMS		pVpGrp1Params;
	PVOIP_CONNECTION_CONTEXT	pConnectionContext;
	TBX_UINT32					un32ConnectionIdx;
	TBX_UINT32					un32ConnectionId;
	TBX_UINT32					un32Index;
	TBX_UINT32					un32Index2;
	TBX_UINT32					un32Count;
	TBX_UINT32					un32SrcTrunkNb;
	TBX_UINT32					un32SrcMblPortNb;
	TBX_UINT32					un32SrcMblStreamNb;
	TBX_UINT32					un32SrcTimeSlot;

⌨️ 快捷键说明

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