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

📄 voip_adapter_sync.c

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterDetach	:	Detach to receive events fromt this adapter
 |
 |  in_pAdapterContext		:	Adapter to send the message to.
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK if the function succeeded
 |								Other error code if the function could not complete properly.
 |
 *-------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterDetach(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext)
{
	/* Send request macro part 1: Allocate and prepare message buffer */
	VOIP_SEND_REQUEST_BODY_PART1( ADAPTER_OP_DETACH, 0 )
	{
		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_2,
			"Detaching from adapter\n"
		);
		/* No specific parameters to set in this message type */
	}
	/* Send request macro part 2: Send the request, return result code */
	VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterDetach")
}

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

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

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

		in_pAdapterContext->fAttached = TBX_FALSE;

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Detached from adapter\n"
		);

		if( TBX_RESULT_FAILURE( pResponse->Result ) )
		{
			/* Request failed. */
			TBX_EXIT_ERROR (pResponse->Result, 0, "ERROR: Failed to detach events!");
		}

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterConfigGet	:	Get adapter configuration for this adapter
 |
 |  in_pAdapterContext			:	Adapter to send the message to.
 |
 |  Note						:	~
 |
 |  Return						:	TBX_RESULT_OK if the function succeeded
 |									Other error code if the function could not complete properly.
 |
 *-------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterConfigGet(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext)
{
	/* Send request macro part 1: Allocate and prepare message buffer */
	VOIP_SEND_REQUEST_BODY_PART1( ADAPTER_CFG_GET, 0 )
	{
		if( in_pAdapterContext->fStopUsingPending )
		{
			/* We must not use this adapter anymore (stop using). Don't send request. */
			TBX_EXIT_SUCCESS (Result);
		}

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_2,
			"Get adapter configuration\n"
		);
	}

	/* Send request macro part 2: Send the request, return result code */
	VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterConfigGet")
}

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

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

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

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Retrieved adapter configuration\n"
		);

		if( TBX_RESULT_FAILURE( pResponse->Result ) )
		{
			/* Request failed. */
			TBX_EXIT_ERROR (pResponse->Result, 0, "ERROR: Failed to get adapter configuration! Adapter may not work properly.");
		}

		Result = FeaturesListToFeaturesLookupTable(
			NULL,
			pResponse->un32FeatureCount,
			pResponse->aFeatures,
			TBX_FEATURE_TYPE_LAST,
			in_pAdapterContext->CurrentConfig.aun32FeatureEnabled,
			in_pAdapterContext->CurrentConfig.aun32FeatureLicensed,
			in_pAdapterContext->CurrentConfig.aun32FeatureMax);
		if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
		{
			TBX_EXIT_ERROR( Result, 0, "Failed to build features loopup table!" );
		}

		/* Check for trunk availability */
		if( in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_MAX_TRUNK] )
		{
			in_pAdapterContext->CurrentConfig.fTrunkAvailable = TBX_TRUE;
		}
		else
		{
			/* No trunk available */
			VoipCliAdapterStatePrint
			(
				in_pAdapterContext,
				TRACE_LEVEL_ALWAYS,
				"There is no trunk available\n"
			);
		}

		/* Check for voice processing group 0 availability */
		if( (in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_RECORD])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_PLAYBACK]) )
		{
			in_pAdapterContext->CurrentConfig.fVpGroup0Available = TBX_TRUE;
		}
		else
		{
			/* Voice processing group 0 is not available */
			VoipCliAdapterStatePrint
			(
				in_pAdapterContext,
				TRACE_LEVEL_ALWAYS,
				"Voice processing group 0 is not available\n"
			);
		}

		/* Check for voice processing group 1 availability */
		if( (in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_G711])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_G723])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_G726])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_G728])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_G729E])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_AMR])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_EFR])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_SMV])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_EVRC])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_QCELP8])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_QCELP13]) ||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_FR])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_ILBC13])	||
			(in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_VOIP_CODEC_ILBC15]))
		{
			in_pAdapterContext->CurrentConfig.fVpGroup1Available = TBX_TRUE;
		}
		else
		{
			/* Voice processing group 1 is not available */
			VoipCliAdapterStatePrint
			(
				in_pAdapterContext,
				TRACE_LEVEL_ALWAYS,
				"Voice processing group 1 is not available\n"
			);
		}

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterGetClockConfig	:	Send message of type TB640_MSG_ID_CLK_SYNC_CFG_GET
 |
 |  in_pAdapterContext				:	Adapter to send the message to.
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterGetClockConfig(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext)
{
	/* Send request macro part 1: Allocate and prepare message buffer */
	VOIP_SEND_REQUEST_BODY_PART1( CLK_SYNC_CFG_GET, 0 )
	{
		if( in_pAdapterContext->fStopUsingPending )
		{
			/* We must not use this adapter anymore (stop using). Don't send request. */
			TBX_EXIT_SUCCESS (Result);
		}

		VoipCliAdapterStatePrint(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Getting clock configuration\n");

		/* No specific parameters to set in this message type */
	}
	/* Send request macro part 2: Send the request, return result code */
	VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterGetClockConfig")
}

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterGetClockConfigResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	PTB640_RSP_CLK_SYNC_CFG_GET		pResponse;
	PVOIP_CLOCK_CONFIG				pClockConfig;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
		/* 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 get clock configuration!");
		}

		/* Store the current clock configuration */
		pClockConfig = &in_pAdapterContext->CurrentConfig.Clock;
		pClockConfig->fAllocated				= TBX_TRUE;
		pClockConfig->LocalRef1					= pResponse->LocalRef1;
		pClockConfig->LocalRef2					= pResponse->LocalRef2;
		pClockConfig->fLocalRefAutoFallback		= pResponse->fLocalRefAutoFallback;
		pClockConfig->MasterClk					= pResponse->MasterClk;
		pClockConfig->InitialMasterRole			= pResponse->InitialMasterRole;
		pClockConfig->NetRef1					= pResponse->NetRef1;
		pClockConfig->NetRef2					= pResponse->NetRef2;
		pClockConfig->NetRef1Freq				= pResponse->NetRef1Freq;
		pClockConfig->NetRef2Freq				= pResponse->NetRef2Freq;
		pClockConfig->fMBLSystemClockingEnabled	= pResponse->fMBLSystemClockingEnabled;

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

	/*---------------------------------------------------------------------------------------------------------------------------

⌨️ 快捷键说明

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