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

📄 voip_adapter_clear.c

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterTrunkMaintenance	:	Set a trunk in maintenance mode.
 |
 |	in_pAdapterContext				:	Adapter configuration we are configuring
 |	in_pCurrentTrunkConfig			:	Current trunk to clear
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterTrunkMaintenance(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_TRUNK_CONFIG		in_pCurrentTrunkConfig)
{
	VOIP_SEND_REQUEST_BODY_PART1( TRUNK_OP_MAINTENANCE, 0 )
	{
		if( in_pAdapterContext->fNewConfigPending && !in_pAdapterContext->fStopUsingPending )
		{
			/* Config has been changed. Don't loose too much time trying to clearing things that may 
			   remain valid in new config ... */
			TBX_EXIT_SUCCESS (Result);
		}

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Maintenance Trunk %d\n",
			in_pCurrentTrunkConfig->un32TrunkNumber
		);

		/* Store the trunk number we are configuring in the user context, to retrieve our context upon response reception */
		TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_pCurrentTrunkConfig->un32TrunkNumber );

		pMsg->Request.hTrunk = in_pCurrentTrunkConfig->hTrunk;

		/* Mark this trunk as not configured in our structures. If response indicates "fail", we will
		   resync from scratch anyways. */

		in_pCurrentTrunkConfig->fActivated	= TBX_FALSE;
	}
	/* Send request macro part 2: Send the request, return Result code */
	VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterTrunkMaintenance")
}

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterTrunkMaintenanceResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	TBX_RESULT						Result;
	PTB640_RSP_TRUNK_OP_MAINTENANCE	pResponse;
	TBX_UINT32						un32TrunkNb;

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

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

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_0,
			"Maintenance trunk %d result is 0x%08X\n",
			(int)un32TrunkNb,
			(int)pResponse->Result
		);

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

		/* Now that the trunk is in maintenance, we can clear it */
		Result = VoipSendAdapterTrunkClear
		( 
			in_pAdapterContext,
			&in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNb ]
		);
		if( Result == TBX_RESULT_OPERATION_INCOMPLETE )
		{
			/* Continue later... */
			TBX_EXIT_SUCCESS (Result);
		}
		else if( TBX_RESULT_FAILURE( Result ) )
		{
			/* Request failed. */
			TBX_EXIT_SUCCESS (Result);
		}

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterStreamResClear	:	Clear a stream resource on the adapter.
 |
 |	in_pAdapterContext				:	Adapter configuration we are configuring
 |	in_pCurrentStreamRes			:	Current stream resource to clear
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterStreamResClear(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_STREAM_RES		in_pCurrentStreamRes)
{
	VOIP_SEND_REQUEST_BODY_PART1( STREAM_RES_FREE, 0 )
	{
		if( in_pAdapterContext->fNewConfigPending && !in_pAdapterContext->fStopUsingPending )
		{
			/* Config has been changed. Don't loose too much time trying to clearing things that may 
			   remain valid in new config ... */
			TBX_EXIT_SUCCESS (Result);
		}

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Clearing Stream resource 0x%08X\n",
			(int)in_pCurrentStreamRes->Common.hRes
		);

		/* Store the resource handle we are configuring in the user context, to retrieve our context upon response reception */
		TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_pCurrentStreamRes->Common.un32ConnectionId );
		TBX_MSG_USER_CONTEXT2_SET( hMsg, (TBX_UINT64)in_pCurrentStreamRes->Common.hRes );

		pMsg->Request.hStreamRes = in_pCurrentStreamRes->Common.hRes;

		/* Mark this stream resource as not configured in our structures. If response indicates "fail", we will
		   resync from scratch anyways. */

		in_pCurrentStreamRes->Common.fAllocated = TBX_FALSE;
	}

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

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterStreamResClearResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	TBX_RESULT					Result;
	PTB640_RSP_TRUNK_RES_FREE	pResponse;
	PVOIP_STREAM_RES			pCurrentStreamRes;
	TB640_RESOURCE_HANDLE		hRes;

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

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

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_0,
			"Clear stream resource 0x%08X result is 0x%08X\n",
			(int)hRes,
			(int)pResponse->Result
		);

		if( TBX_RESULT_FAILURE( pResponse->Result ) )
		{
			/* Request failed. */
			TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to free stream resource!");
		}

		/* Find the corresponding current stream resource context */
		/* Remove the resource handle from our hash table of resource handles */
		TBXHashRemove
		(
			in_pAdapterContext->CurrentConfig.hResHandleHash,
			(TBX_HASH_KEY)hRes,
			(PTBX_VOID*)&pCurrentStreamRes
		);
		if( pCurrentStreamRes == NULL )
		{
			TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to remove current stream resource from resource handle hash table!");
		}

		if( VOIP_IS_VALID_CONNECTION_ID( pCurrentStreamRes->Common.un32ConnectionId ) == TBX_TRUE )
		{
			/* Find the corresponding current stream resource context */
			/* Remove the resource handle from our hash table of connection identifier */
			Result = TBXHashRemove( in_pAdapterContext->CurrentConfig.hStreamResHash, pCurrentStreamRes->Common.un32ConnectionId, (PTBX_VOID*)&pCurrentStreamRes );
			if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
			{
				TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to remove connection identifier from stream resource hash table!");
			}
		}

		if( in_pAdapterContext->StressTest.fActive == TBX_TRUE )
		{
			/* Release reserved IP port */
			VoipStressTestReleaseIpPort( in_pAdapterContext, pCurrentStreamRes->Params.un16FromNetworkIPPort, pCurrentStreamRes->Params.un16ToNetworkIPPort);
		}

		/* Free stream resource context */
		Result = TBXPoolOfBuffersFree
		(
			in_pAdapterContext->CurrentConfig.hPoolOfStreamRes,
			pCurrentStreamRes
		);
		if( TBX_RESULT_FAILURE(Result) == TBX_TRUE )
		{
			TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to remove stream resource from pool of stream resource buffers!");
		}

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterVpGroupClear	:	Clear a voice processing group on the adapter.
 |
 |	in_pAdapterContext			:	Adapter configuration we are configuring
 |	in_pCurrentVpGroup			:	Current voice processing group to clear
 |
 |  Note						:	~
 |
 |  Return						:	TBX_RESULT_OK if the function succeeded
 |									Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterVpGroupClear(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_VP_GROUP			in_pCurrentVpGroup)
{
	VOIP_SEND_REQUEST_BODY_PART1( VP_GROUP_FREE, 0 )
	{
		if( in_pAdapterContext->fNewConfigPending && !in_pAdapterContext->fStopUsingPending )
		{
			/* Config has been changed. Don't loose too much time trying to clearing things that may 
			   remain valid in new config ... */
			TBX_EXIT_SUCCESS (Result);
		}

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Clearing voice processing group 0x%08X\n",
			(int)in_pCurrentVpGroup->Common.hRes
		);

		/* Store the voice processing group handle we are configuring in the user context, to retrieve our context upon response reception */
		TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_pCurrentVpGroup->Common.un32ConnectionId );
		TBX_MSG_USER_CONTEXT2_SET( hMsg, (TBX_UINT64)in_pCurrentVpGroup->Common.hRes );

		pMsg->Request.hVPGroup = in_pCurrentVpGroup->Common.hRes;

		/* Mark this voice processing group as not configured in our structures. If response indicates "fail", we will
		   resync from scratch anyways. */

		in_pCurrentVpGroup->Common.fAllocated = TBX_FALSE;
	}

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

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterVpGroupClearResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	TBX_RESULT					Result;
	PTB640_RSP_VP_GROUP_FREE	pResponse;
	PVOIP_VP_GROUP				pCurrentVpGroup;
	PVOIP_VP_RES				pCurrentVpRes;
	TB640_VPGROUP_HANDLE		hVpGroup;
	TBX_UINT32					un32Index;

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

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

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_0,
			"Clear voice processing group 0x%08X result is 0x%08X\n",
			(int)hVpGroup,
			(int)pResponse->Result
		);

		if( TBX

⌨️ 快捷键说明

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