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

📄 voip_adapter_sync.c

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


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

#include "voip_includes.h"


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


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


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


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

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


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


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


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


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

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipUpdateAllAdaptersStates	:	Tell all adapter's state machines to update their states.
 |
 |	~							:	No parameters
 |
 |  Note						:	~
 |
 |  Return						:	TBX_RESULT_OK if the function succeeded
 |									Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipUpdateAllAdaptersStates( TBX_VOID )
{
	PVOIP_ADAPTER_CONTEXT		pAdapterContext;
	PVOIP_ADAPTER_CONTEXT_NODE	pAdapterContextNode;
	PVOIP_CLI_CONTEXT			pCliContext;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pCliContext = &g_pContext->CliContext;

		pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
		while( pAdapterContextNode )
		{
			pAdapterContext = pAdapterContextNode->pAdapterContext;
			if( pAdapterContext->fPresent == TBX_TRUE )
			{
				/* Ask this adapter to update all its states */
				TBX_MSG_HANDLE		hMsg;

				/* Force the "standby" mode timeout, which make the state machine go out of standby */
				hMsg = VoipFormatPrivateMsg(
					VOIP_MSG_ID_NOTIF_UPDATE_ALL_STATES,
					sizeof( TBX_MSG_HEADER ),
					pAdapterContext->AdapterInfo.hAdapter,
					0 );
				if( hMsg != (TBX_MSG_HANDLE)TBX_HANDLE_INVALID )
				{
					pAdapterContext->pFctStateHandler( pAdapterContext, hMsg );
					TBXReleaseMsg (g_pContext->hTbxLib, hMsg);
				}
			}
			pAdapterContextNode = TBXPoolOfBuffersNext( g_pContext->hPoolOfAdapters, pAdapterContextNode );
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TbxCliToolsLogPrint(
			pCliContext->hCliTools,
			TRACE_LEVEL_ERROR, NULL,
			"VoipUpdateAllAdaptersStates: %s (Result = 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION, 
			TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterUpdateStates		:	Update all adapter states
 |
 |  in_pAdapterContext			:	Adapter to update states for.
 |
 |  Note						:	~
 |
 |  Return						:	TBX_RESULT_OK if the function succeeded
 |									Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterUpdateStates(
	IN		PVOIP_ADAPTER_CONTEXT		in_pAdapterContext)
{
	PVOIP_BERT_RES		pBertRes;
	TBX_BOOL			fResetStats;
	PVOIP_STREAM_RES	pStreamRes;
#if 0
	TBX_UINT32			un32TrunkNb;
#endif

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		if( in_pAdapterContext->CurrentConfig.aun32FeatureEnabled[TBX_FEATURE_TYPE_MAX_TRUNK] )
		{
#if 0
		/* Update states for all allocated trunks */
		for( un32TrunkNb = 0; un32TrunkNb < VOIP_MAX_TRUNK_PER_ADAPTER; un32TrunkNb++ )
		{
			PVOIP_TRUNK_CONFIG	pTrunkConfig = 
				&( in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNb ] );

			if( pTrunkConfig->fActivated )
			{
				/* Query states for this trunk */
				VoipSendAdapterGetTrunkStates
				(
					in_pAdapterContext,
					pTrunkConfig->hTrunk
				);
			}		
		}
#endif

			/* Update PM (performance monitoring) counters for all trunks */
			VoipSendAdapterGetPmCounters( in_pAdapterContext );
		}

		if( (in_pAdapterContext->CurrentConfig.fVpGroup0Available == TBX_TRUE) ||
			(in_pAdapterContext->CurrentConfig.fVpGroup1Available == TBX_TRUE) )
		{
			if( in_pAdapterContext->Stats.fGlobalStats == TBX_TRUE )
			{
				if( in_pAdapterContext->Stats.fResetStats == TBX_TRUE )
				{
					/* Reset global accumulated stream statistics */
					VoipSendAdapterResetStreamResStats( in_pAdapterContext, 0, in_pAdapterContext->Stats.Interface );

					/* Do not reset stats on next polling cycle */
					in_pAdapterContext->Stats.fResetStats = TBX_FALSE;
				}
				else
				{
					/* Get global accumulated stream statistics */
					VoipSendAdapterGetStreamResStats( in_pAdapterContext, 0, in_pAdapterContext->Stats.Interface );
				}
			}
			else
			{
				/* Get statistics for stream resource */
				pStreamRes = in_pAdapterContext->Stats.pStreamRes;
				if( (pStreamRes) && (pStreamRes->Common.fAllocated == TBX_TRUE) )
				{
					if( in_pAdapterContext->Stats.fResetStats == TBX_TRUE )
					{
						/* Reset statistics for stream resource */
						VoipSendAdapterResetStreamResStats( in_pAdapterContext, pStreamRes->Common.hRes, pStreamRes->Params.Interface );

						/* Do not reset stats on next polling cycle */
						in_pAdapterContext->Stats.fResetStats = TBX_FALSE;
					}
					else
					{
						/* Update statistics for stream resource */
						VoipSendAdapterGetStreamResStats( in_pAdapterContext, pStreamRes->Common.hRes, pStreamRes->Params.Interface );
					}
				}
			}
		}

		/* Update states for BERT resource */
		pBertRes	= &in_pAdapterContext->CurrentConfig.aBertRes[0];
		fResetStats	= in_pAdapterContext->Stats.fBertResetStats;
		in_pAdapterContext->Stats.fBertResetStats = TBX_FALSE;
		if( pBertRes->Common.fAllocated == TBX_TRUE )
		{
			VoipSendAdapterGetBertResStates( in_pAdapterContext, pBertRes->Common.hRes, fResetStats );
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterAttach	:	Attach to receive events from 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	VoipSendAdapterAttach(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext)
{
	/* Send request macro part 1: Allocate and prepare message buffer */
	VOIP_SEND_REQUEST_BODY_PART1( ADAPTER_OP_ATTACH, 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,
			"Attaching to adapter\n"
		);

		pMsg->Request.fEnableAutoReattach = TBX_TRUE;
	}
	/* Send request macro part 2: Send the request, return result code */
	VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterAttach")
}

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterAttachResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	PTB640_RSP_ADAPTER_OP_ATTACH	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,
			"Attached to adapter\n"
		);

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

		in_pAdapterContext->fAttached = TBX_TRUE;

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

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

⌨️ 快捷键说明

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