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

📄 voip_adapter_configure.c

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

			/* Get connection */
			pConnectionContext = TBXPoolOfBuffersAlloc
			(
				in_pAdapterContext->pTargetConfig->hPoolOfConnections,
				(TBX_HASH_KEY)un32ConnectionId
			);
			if( pConnectionContext == NULL )
			{
				TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Maximum number of connections reached." );
			}

			/* Initialize connection context */
			pConnectionContext->hConn							= (TB640_CONNECTION_HANDLE)NULL;
			pConnectionContext->un32ConnectionId				= un32ConnectionId;
			pConnectionContext->un32ConnectionIdx				= un32ConnectionIdx;
			pConnectionContext->fAllocated						= TBX_TRUE;
			pConnectionContext->Params							= *in_pConnectionParams;
			pConnectionContext->un32PathDescCount				= un32PathDescCount;
			pConnectionContext->aPathDesc[0].un32StructVersion	= 1;
			pConnectionContext->aPathDesc[0].fFullDuplex		= fFullDuplex;
			pConnectionContext->aPathDesc[0].hResSrc			= (TB640_RESOURCE_HANDLE)TBX_HANDLE_INVALID;
			pConnectionContext->aPathDesc[0].hResDst			= (TB640_RESOURCE_HANDLE)TBX_HANDLE_INVALID;
			pConnectionContext->aPathDesc[1].un32StructVersion	= 1;
			pConnectionContext->aPathDesc[1].fFullDuplex		= fFullDuplex;
			pConnectionContext->aPathDesc[1].hResSrc			= (TB640_RESOURCE_HANDLE)TBX_HANDLE_INVALID;
			pConnectionContext->aPathDesc[1].hResDst			= (TB640_RESOURCE_HANDLE)TBX_HANDLE_INVALID;
		}
		else
		{
			TBX_EXIT_ERROR( TBX_RESULT_FAIL, 0, "Unsupported connection type." );
		}

		if( pVpGroup != NULL )
		{
			/* Insert voice processing group in voice processing hash table */
			Result = TBXHashInsert
			(
				in_pAdapterContext->pTargetConfig->hVpGroupHash,
				(TBX_HASH_KEY)un32ConnectionId,
				pVpGroup
			);
			if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
			{
				TBX_EXIT_ERROR( Result, 0, "Maximum number of voice processing group reached." );
			}
		}

		if( pStreamRes != NULL )
		{
			/* Insert stream resource context in stream resource hash table */
			Result = TBXHashInsert
			(
				in_pAdapterContext->pTargetConfig->hStreamResHash,
				(TBX_HASH_KEY)un32ConnectionId,
				pStreamRes
			);
			if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
			{
				TBX_EXIT_ERROR( Result, 0, "Maximum number of stream resources reached." );
			}
		}

		/* Insert connection context in connection hash table */
		Result = TBXHashInsert
		(
			in_pAdapterContext->pTargetConfig->hConnectionHash,
			(TBX_HASH_KEY)un32ConnectionId,
			pConnectionContext
		);
		if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
		{
			TBX_EXIT_ERROR( Result, 0, "Maximum number of connection reached." );
		}

		/* Return connection context */
		*io_ppConnectionContext	= pConnectionContext;

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

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		if( TBX_RESULT_SUCCESS( TBX_ERROR_RESULT ) == TBX_TRUE )
		{
			/* Reserve connection index */
			in_pAdapterContext->pTargetConfig->aun32ConnectionIdxReserved[un32ConnectionIdx] = un32ConnectionId;
			in_pAdapterContext->pTargetConfig->un32ConnectionIdxReservedLast = un32ConnectionIdx;
		}
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterRemoveConnectionFromTarget	:	Remove connection from target configuration.
 |
 |	in_pAdapterContext						:	Adapter we are configuring
 |	in_un32ConnectionId						:	Connection identifier of the connection to remove.
 |
 |  Note									:	~
 |
 |  Return									:	TBX_RESULT_OK if the function succeeded
 |												Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterRemoveConnectionFromTarget(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_UINT32				in_un32ConnectionId)
{
	TBX_RESULT					Result;
	PVOIP_STREAM_RES			pTargetStreamRes;
	PVOIP_VP_GROUP				pTargetVpGroup;
	PVOIP_CONNECTION_CONTEXT	pTargetConnectionContext;

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

		/* Find the corresponding target connection context */
		/* Remove the connection context from our hash table of connection identifiers */
		Result = TBXHashRemove( in_pAdapterContext->pTargetConfig->hConnectionHash, (TBX_HASH_KEY)in_un32ConnectionId, (PTBX_VOID*)&pTargetConnectionContext );
		if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
		{
			TBX_EXIT_ERROR(TBX_RESULT_NOT_FOUND, 0, "Failed to found target connection context!" );
		}

		if( pTargetConnectionContext->un32ConnectionIdx >= VOIP_MAX_CONNECTION_IDX_PER_ADAPTER )
		{
			TBX_EXIT_ERROR( TBX_RESULT_INVALID_PARAM, 0, "Invalid connection index!" );
		}

		/* Release reserved connection index */
		in_pAdapterContext->pTargetConfig->aun32ConnectionIdxReserved[pTargetConnectionContext->un32ConnectionIdx] = 0;

		/* Free connection context */
		Result = TBXPoolOfBuffersFree
		(
			in_pAdapterContext->pTargetConfig->hPoolOfConnections,
			pTargetConnectionContext
		);
		if( TBX_RESULT_FAILURE(Result) == TBX_TRUE )
		{
			TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to free target connection context!");
		}

		if( (pTargetConnectionContext->Params.Type == VOIP_CONNECTION_TYPE_0) ||
			((pTargetConnectionContext->Params.Type == VOIP_CONNECTION_TYPE_1) &&
			 (pTargetConnectionContext->Params.Type1.SecondRes.Type == VOIP_RESOURCE_TYPE_STREAM_SOCKET)) )
		{
			/* Find the corresponding target stream resource context */
			/* Remove the stream resource context from our hash table of connection identifiers */
			TBXHashRemove
			(
				in_pAdapterContext->pTargetConfig->hStreamResHash,
				(TBX_HASH_KEY)in_un32ConnectionId,
				(PTBX_VOID*)&pTargetStreamRes
			);
			if( pTargetStreamRes == NULL )
			{
				TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to remove target stream resource context!");
			}

			/* Free stream resource context */
			Result = TBXPoolOfBuffersFree
			(
				in_pAdapterContext->pTargetConfig->hPoolOfStreamRes,
				pTargetStreamRes
			);
			if( TBX_RESULT_FAILURE(Result) == TBX_TRUE )
			{
				TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to free target stream resource!");
			}

			/* Find the corresponding target voice processing group context */
			/* Remove the voice processing group context from our hash table of connection identifiers */
			TBXHashRemove
			(
				in_pAdapterContext->pTargetConfig->hVpGroupHash,
				(TBX_HASH_KEY)in_un32ConnectionId,
				(PTBX_VOID*)&pTargetVpGroup
			);
			if( pTargetVpGroup == NULL )
			{
				TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to remove target voice processing group context!");
			}

			/* Free voice processing group context */
			Result = TBXPoolOfBuffersFree
			(
				in_pAdapterContext->pTargetConfig->hPoolOfVpGroups,
				pTargetVpGroup
			);
			if( TBX_RESULT_FAILURE(Result) == TBX_TRUE )
			{
				TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to free target voice processing group!");
			}
		}

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterAddPromptToTarget	:	Add new prompt to target configuration.
 |
 |	in_pAdapterContext				:	Adapter context.
 |	in_pPromptParams				:	Prompt parameters
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterAddPromptToTarget(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_PROMPT_PARAMS		in_pPromptParams)
{
	TBX_RESULT					Result;
	PVOIP_CLI_CONTEXT			pCliContext = &g_pContext->CliContext;
	PVOIP_PROMPT_CONTEXT		pPromptContext;
	VOIP_CONNECTION_PARAMS		ConnectionParams;
	PVOIP_CONNECTION_CONTEXT	pConnectionContext;
	TBX_UINT32					un32ConnectionId;

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

		/* Add new prompt connection to target configuration */
		memset( &ConnectionParams, 0, sizeof(ConnectionParams) );
		ConnectionParams.Type				= VOIP_CONNECTION_TYPE_0;
		ConnectionParams.Type0.un16RxIPPort	= in_pPromptParams->un16RxIPPort;
		ConnectionParams.Type0.fPlaybackEnabled = TBX_TRUE;
		ConnectionParams.Type0.fRecordEnabled = in_pPromptParams->fRecordEnabled;
		ConnectionParams.Type0.un16TxIPPort = in_pPromptParams->un16TxIPPort;
		strncpy( ConnectionParams.Type0.szStreamSocketIP, in_pPromptParams->szStreamSocketIP, sizeof(ConnectionParams.Type0.szStreamSocketIP) );
		ConnectionParams.Type0.szStreamSocketIP[sizeof(ConnectionParams.Type0.szStreamSocketIP) - 1] = '\0';
		strncpy( ConnectionParams.Type0.szPromptName, in_pPromptParams->szPromptName, sizeof(ConnectionParams.Type0.szPromptName) );
		ConnectionParams.Type0.szPromptName[sizeof(ConnectionParams.Type0.szPromptName) - 1] = '\0';
		Result = VoipAdapterAddConnectionToTarget( in_pAdapterContext, &ConnectionParams, &pConnectionContext );
		if( TBX_RESULT_FAILURE( Result ) 

⌨️ 快捷键说明

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