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

📄 voip_adapter_set.c

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterTrunkSet	:	Set a trunk on the adapter.
 |
 |	in_pAdapterContext		:	Adapter configuration we are configuring
 |	in_pTargetTrunkConfig	:	Target trunk to Set
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK if the function succeeded
 |								Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterTrunkSet(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_TRUNK_CONFIG		in_pTargetTrunkConfig)
{
	TBX_BOOL			fMustClear;
	TBX_BOOL			fMustSetConfig;
	PVOIP_TRUNK_CONFIG	pCurrentTrunkConfig;

	VOIP_SEND_REQUEST_BODY_PART1( TRUNK_OP_SET_PARAMS, 0 )
	{
		/* Initialize local variables */
		pCurrentTrunkConfig = NULL;

		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);
		}

		/* Retrieve the corresponding current trunk config */
		pCurrentTrunkConfig = &in_pAdapterContext->CurrentConfig.aTrunk[ in_pTargetTrunkConfig->un32TrunkNumber ];

		if( !pCurrentTrunkConfig->fAllocated )
		{
			/* Trunk not allocated. Allocate instead of set... */
			Result = VoipSendAdapterTrunkAlloc
			(
				in_pAdapterContext,
				in_pTargetTrunkConfig
			);
			TBX_EXIT_SUCCESS( Result );
		}
		else
		{
			/* Validate if this trunk need to be reconfigured or not */
			VoipAdapterTrunkConfigureCompare
			(
				in_pAdapterContext,
				pCurrentTrunkConfig,
				in_pTargetTrunkConfig,
				&fMustClear,
				&fMustSetConfig
			);
			if( fMustClear )
			{
				/* Not supposed to happen, we should already have cleared it... but just in case... */
				VoipSendAdapterTrunkMaintenance
				(
					in_pAdapterContext,
					pCurrentTrunkConfig
				);
				VoipCliAdapterStatePrint
				(
					in_pAdapterContext,
					TRACE_LEVEL_ERROR,
					"Trunk config for trunk '%d' should already have been freed. Will clear and resynchronize with adapter.",
					(int)pCurrentTrunkConfig->un32TrunkNumber
				);
				TBX_EXIT_ERROR (TBX_RESULT_INVALID_STATE, 0, "");
			}

			/* 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_pTargetTrunkConfig->un32TrunkNumber );

			if( fMustSetConfig )
			{
				/* Fill request parameters */
				pMsg->Request.hTrunk			= pCurrentTrunkConfig->hTrunk;
				pMsg->Request.un64UserContext1	= 0;	/* Don't care */
				pMsg->Request.un64UserContext2	= 0;	/* Don't care */
				memcpy
				(
					&pMsg->Request.TrunkCfg,
					&( in_pAdapterContext->pTargetConfig->aTrunk[ in_pTargetTrunkConfig->un32TrunkNumber ].TrunkCfg ),
					sizeof( pMsg->Request.TrunkCfg )
				);

				VoipCliAdapterStatePrint
				(
					in_pAdapterContext,
					TRACE_LEVEL_1,
					"Setting config for trunk %d\n",
					(int)in_pTargetTrunkConfig->un32TrunkNumber
				);

				/* Request will be sent in VOIP_SEND_REQUEST_BODY_PART2 */
			}
			else
			{
				VoipCliAdapterStatePrint
				(
					in_pAdapterContext,
					TRACE_LEVEL_1,
					"Keeping config for trunk 0x%08X\n",
					(int)in_pTargetTrunkConfig->hTrunk
				);

				/* 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 = VoipHandleAdapterTrunkSetResponse
				(
					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("VoipSendAdapterTrunkSet")
}

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterTrunkSetResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	PTB640_RSP_TRUNK_OP_SET_PARAMS	pResponse;
	PVOIP_TRUNK_CONFIG				pCurrentTrunkConfig;
	PVOIP_TRUNK_CONFIG				pTargetTrunkConfig;
	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 );
		pCurrentTrunkConfig = &in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNb ];
		pTargetTrunkConfig	= &in_pAdapterContext->pTargetConfig->aTrunk[ un32TrunkNb ];

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_0,
			"Set/alloc trunk %d result is 0x%08X\n",
			(int)pCurrentTrunkConfig->un32TrunkNumber,
			(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 trunk params!");
		}

		/* The current trunk configuration now matches the target. */
		pCurrentTrunkConfig->fAllocated			= TBX_TRUE;
		pCurrentTrunkConfig->un32TrunkNumber	= un32TrunkNb;
		strncpy( pCurrentTrunkConfig->szTrunkName, pTargetTrunkConfig->szTrunkName, sizeof(pCurrentTrunkConfig->szTrunkName) );
		pCurrentTrunkConfig->szTrunkName[ sizeof(pCurrentTrunkConfig->szTrunkName) - 1] = '\0';
		memcpy( &pCurrentTrunkConfig->TrunkCfg, &pTargetTrunkConfig->TrunkCfg, sizeof(pCurrentTrunkConfig->TrunkCfg) );
		pCurrentTrunkConfig->un32MaxTimeSlot	= pTargetTrunkConfig->un32MaxTimeSlot;

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

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

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

	RETURN;
}

⌨️ 快捷键说明

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