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

📄 voip_adapter_set.c

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


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

#include "voip_includes.h"


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


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


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


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

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


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


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


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


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

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterSetClockConfig	:	Set the clock config on the adapter.
 |
 |	in_pAdapterContext				:	Adapter configuration we are configuring
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterSetClockConfig(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext)
{
	TBX_BOOL	fMustReallocate;
	TBX_BOOL	fMustSetParams;

	VOIP_SEND_REQUEST_BODY_PART1( CLK_SYNC_CFG_SET, 0 )
	{
		if( in_pAdapterContext->fStopUsingPending )
		{
			/* We must not use this adapter anymore (stop using). Don't send request. */
			TBX_EXIT_SUCCESS (Result);
		}
		if( in_pAdapterContext->fNewConfigPending )
		{
			/* Config has been changed. Don't loose too much time trying to set things that may 
			   remain valid in new config ... */
			TBX_EXIT_SUCCESS (Result);
		}

		/* Validate if clock need to be reconfigured or not */
		VoipAdapterClockConfigConfigureCompare( in_pAdapterContext, &fMustReallocate, &fMustSetParams );
		if ( fMustSetParams == TBX_TRUE )
		{
			/* Fill request parameters */
			pMsg->Request.LocalRef1.ClkSrc			= in_pAdapterContext->pTargetConfig->Clock.LocalRef1.ClkSrc;
			pMsg->Request.LocalRef1.un32Trunk		= in_pAdapterContext->pTargetConfig->Clock.LocalRef1.un32Trunk;
			pMsg->Request.LocalRef2.ClkSrc			= in_pAdapterContext->pTargetConfig->Clock.LocalRef2.ClkSrc;
			pMsg->Request.LocalRef2.un32Trunk		= in_pAdapterContext->pTargetConfig->Clock.LocalRef2.un32Trunk;
			pMsg->Request.fLocalRefAutoFallback		= in_pAdapterContext->pTargetConfig->Clock.fLocalRefAutoFallback;
			pMsg->Request.MasterClk					= in_pAdapterContext->pTargetConfig->Clock.MasterClk;
			pMsg->Request.InitialMasterRole			= in_pAdapterContext->pTargetConfig->Clock.InitialMasterRole;
			pMsg->Request.NetRef1.ClkSrc			= in_pAdapterContext->pTargetConfig->Clock.NetRef1.ClkSrc;
			pMsg->Request.NetRef1.un32Trunk			= in_pAdapterContext->pTargetConfig->Clock.NetRef1.un32Trunk;
			pMsg->Request.NetRef2.ClkSrc			= in_pAdapterContext->pTargetConfig->Clock.NetRef2.ClkSrc;
			pMsg->Request.NetRef2.un32Trunk			= in_pAdapterContext->pTargetConfig->Clock.NetRef2.un32Trunk;
			pMsg->Request.NetRef1Freq				= in_pAdapterContext->pTargetConfig->Clock.NetRef1Freq;
			pMsg->Request.NetRef2Freq				= in_pAdapterContext->pTargetConfig->Clock.NetRef2Freq;
			pMsg->Request.fMBLSystemClockingEnabled	= in_pAdapterContext->pTargetConfig->Clock.fMBLSystemClockingEnabled;

			VoipCliAdapterStatePrint
			(
				in_pAdapterContext,
				TRACE_LEVEL_3,
				"Setting clock configuration\n"
			);
		}
		else
		{
			VoipCliAdapterStatePrint
			(
				in_pAdapterContext,
				TRACE_LEVEL_1,
				"Keeping clock configuration\n"
			);

			/* Already properly configured. Simulate we received success response */
			pMsg->Response.un32MsgVersion	= 1;
			pMsg->Response.Result			= TBX_RESULT_OK;

			/* Trick the number of expected responses before calling "handle set response" */
			in_pAdapterContext->un32NbResponsesExpected++;
			Result = VoipHandleAdapterSetClockConfigResponse
			(
				in_pAdapterContext,
				hMsg
			);

			/* Skip message send. */
			TBX_EXIT_SUCCESS (Result);
		}
	}
	/* Send request macro part 2: Send the request, return Result code */
	VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterSetClockConfig")
}

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterSetClockConfigResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	PTB640_RSP_CLK_SYNC_CFG_SET	pResponse;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_0,
			"Set/alloc clock configuration result is 0x%08X\n",
			(int)pResponse->Result
		);

		/* Count this received response */
		if( in_pAdapterContext->un32NbResponsesExpected )
		{
			in_pAdapterContext->un32NbResponsesExpected--;
		}

		if( TBX_RESULT_FAILURE( pResponse->Result ) )
		{
			/* Request failed. */
			TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to set clock configuration!");
		}

		/* The current clock configuration now matches the target. */
		memcpy
		(
			&in_pAdapterContext->CurrentConfig.Clock,
			&in_pAdapterContext->pTargetConfig->Clock,
			sizeof(in_pAdapterContext->CurrentConfig.Clock)
		);

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

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP

⌨️ 快捷键说明

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