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

📄 voip_adapter_sync.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		VoipCliAdapterStatePrint(
			in_pAdapterContext,
			TRACE_LEVEL_ERROR,
			"VoipHandleAdapterGetClockConfigResponse: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterGetClockStates	:	Send message of type TB640_MSG_ID_CLK_SYNC_STATES_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	VoipSendAdapterGetClockStates(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext)
{
	VOIP_SEND_REQUEST_BODY_PART1( CLK_SYNC_STATES_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 states\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("VoipSendAdapterGetClockStates")
}

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterGetClockStatesResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	PTB640_RSP_CLK_SYNC_STATES_GET		pResponse;
	PVOIP_CLOCK_STATUS					pClockStatus;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  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 states!");
		}

		/* Store the clock state context for this adapter */
		pClockStatus = &in_pAdapterContext->Status.Clock;
		pClockStatus->ClockRef					= pResponse->ClockRef;
		pClockStatus->fNetref1					= pResponse->fNetref1;
		pClockStatus->fNetref2					= pResponse->fNetref2;
		pClockStatus->fRequireHostIntervention	= pResponse->fRequireHostIntervention;

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipHandleAdapterClockStateChange	:	Handle event type TB640_MSG_ID_CLK_SYNC_NOTIF_STATE_CHANGE
 |
 |  in_pAdapterContext					:	Adapter to send the message to.
 |	in_hMsg								:	Event message received
 |
 |  Note								:	~
 |
 |  Return								:	TBX_RESULT_OK if the function succeeded
 |											Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipHandleAdapterClockStateChange(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	PTB640_EVT_CLK_SYNC_NOTIF_STATE_CHANGE		pEvent;

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

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_2,
			"Adapter clock state has changed\n"
		);

		/* Update the clock state context for this adapter */
		in_pAdapterContext->Status.Clock.ClockRef					= pEvent->ClockRef;
		in_pAdapterContext->Status.Clock.fNetref1					= pEvent->fNetref1;
		in_pAdapterContext->Status.Clock.fNetref2					= pEvent->fNetref2;
		in_pAdapterContext->Status.Clock.fRequireHostIntervention	= pEvent->fRequireHostIntervention;

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterGetBertResList	:	Send message of type TB640_MSG_ID_BERT_RES_GET_LIST
 |
 |  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	VoipSendAdapterGetBertResList(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext)
{
	/* Send request macro part 1: Allocate and prepare message buffer */
	VOIP_SEND_REQUEST_BODY_PART1( BERT_RES_GET_LIST, 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 BERT resources list\n");
	}

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

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterGetBertResListResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	TBX_RESULT						Result;
	PTB640_RSP_BERT_RES_GET_LIST	pResponse;
	TBX_CHAR						szErrorString[ 256 ];

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  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 BERT resources list!");
		}

		/* Validate response content */
		if( pResponse->un32BertResCount > VOIP_MAX_BERT_RES )
		{
			sprintf( szErrorString, "Unexpected BERT resources count (%d, max supported is %d)\n", (int)pResponse->un32BertResCount, (int)(VOIP_MAX_BERT_RES-1) );
			TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_RESOURCE, 0, szErrorString);
		}

		if( pResponse->un32BertResCount > 0 )
		{
			/* Query parameters for every listed BERT resources */
			Result = VoipSendAdapterGetBertResParams( in_pAdapterContext, pResponse->ahBertRes[ 0 ] );
			if( TBX_RESULT_FAILURE( Result ) )
			{
				TBX_EXIT_SUCCESS (Result);	/* Return error code, but don't display error in this function */
			}

			Result = VoipSendAdapterGetBertResStates( in_pAdapterContext, pResponse->ahBertRes[ 0 ], TBX_FALSE );
			if( TBX_RESULT_FAILURE( Result ) )
			{
				TBX_EXIT_SUCCESS (Result);	/* Return error code, but don't display error in this function */
			}
		}

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterGetBertResParams	:	Send message of type TB640_MSG_ID_BERT_RES_GET_PARAMS
 |
 |  in_pAdapterContext					:	Adapter to send the message to.
 |	in_hBertRes							:	Handle of the BERT resource to query parameters for
 |
 |  Note								:	~
 |
 |  Return								:	TBX_RESULT_OK if the function succeeded
 |											Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterGetBertResParams(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TB640_RESOURCE_HANDLE	in_hBertRes)
{
	/* Send request macro part 1: Allocate and prepare message buffer */
	VOIP_SEND_REQUEST_BODY_PART1( BERT_RES_GET_PARAMS, 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 parameters for BERT resource 0x%X\n",
			(int)in_hBertRes);

		/* Fill request parameters */
		pMsg->Request.hResource = in_hBertRes;

		/* Store the BERT resource handle we are querying in the user context, to retrieve our context upon response reception */
		TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_hBertRes );
	}
	/* Send request macro part 2: Send the request, return result code */
	VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterGetBertResParams")
}

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterGetBertResParamsResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	TBX_RESULT						Result;
	PTB640_RSP_BERT_RES_GET_PARAMS	pResponse;
	TB640_RESOURCE_HANDLE			hBertRes;
	PVOIP_BERT_RES					pCurrentBertRes;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE

⌨️ 快捷键说明

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