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

📄 voip_adapter_clear.c

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

		/*
		 * Validate MBL port resources
		 */
		{
			TBX_UINT32				un32PortNb;
			TBX_UINT32				un32StreamNb;
			TBX_UINT32				un32TimeSlotNb;
			PVOIP_MBL_PORT_CONFIG	pCurrentMblPortConfig;
			PVOIP_MBL_PORT_CONFIG	pTargetMblPortConfig;
			PVOIP_MBL_RES			pCurrentMblPortRes;
			PVOIP_MBL_RES			pTargetMblPortRes;

			for( un32PortNb = 0; un32PortNb < VOIP_MAX_MBL_PORT_PER_ADAPTER; un32PortNb++ )
			{
				pCurrentMblPortConfig	= &in_pAdapterContext->CurrentConfig.aMblPort[ un32PortNb ];
				pTargetMblPortConfig	= &in_pAdapterContext->pTargetConfig->aMblPort[ un32PortNb ];

				fMustClear = TBX_FALSE;
				if (pCurrentMblPortConfig->fAllocated == TBX_TRUE)
				{
					/* Test if we must clear resources for this MBL port */
					if( in_fForceClear )
					{
						fMustClear = TBX_TRUE;
					}
					else
					{
						VoipAdapterMblPortConfigureCompare(
							in_pAdapterContext,
							pCurrentMblPortConfig,
							pTargetMblPortConfig,
							&fMustClear,
							&fMustSetConfigDummy);
					}

					pCurrentMblPortConfig->fMustClear = fMustClear;

					if( fMustClear == TBX_FALSE )
					{
						for( un32StreamNb = 0; un32StreamNb < VOIP_MAX_STREAM_PER_MBL_PORT; un32StreamNb++ )
						{
							for( un32TimeSlotNb = 0; un32TimeSlotNb < VOIP_MAX_TIMESLOT_PER_MBL_STREAM; un32TimeSlotNb++ )
							{
								pCurrentMblPortRes	= &pCurrentMblPortConfig->aRes[ un32StreamNb ] [ un32TimeSlotNb ];
								pTargetMblPortRes	= &pTargetMblPortConfig->aRes[ un32StreamNb ] [ un32TimeSlotNb ];

								if ( pCurrentMblPortRes->Common.fAllocated == TBX_TRUE )
								{
									if( fMustClear == TBX_FALSE )
									{
										/* Validate MBL port resource parameters */
										VoipCliAdapterStatePrint(
											in_pAdapterContext,
											TRACE_LEVEL_0,
											"Validating MBL port resource 0x%08X config\n",
											(int)pCurrentMblPortRes->Common.hRes );

										if( pCurrentMblPortRes->Params.ResType != TB640_RESOURCE_TYPE_FD )
										{
											fMustClear = TBX_TRUE;
										}

										if( (TBX_UINT32)pCurrentMblPortRes->Params.un8Stream != un32StreamNb )
										{
											fMustClear = TBX_TRUE;
										}

										if( (TBX_UINT32)pCurrentMblPortRes->Params.un8TimeSlot != un32TimeSlotNb )
										{
											fMustClear = TBX_TRUE;
										}
									}
								}
							}
						}
					}

					if( fMustClear == TBX_TRUE )
					{
						for( un32StreamNb = 0; un32StreamNb < VOIP_MAX_STREAM_PER_MBL_PORT; un32StreamNb++ )
						{
							for( un32TimeSlotNb = 0; un32TimeSlotNb < VOIP_MAX_TIMESLOT_PER_MBL_STREAM; un32TimeSlotNb++ )
							{
								pCurrentMblPortRes = &pCurrentMblPortConfig->aRes[ un32StreamNb ] [ un32TimeSlotNb ];

								if ( pCurrentMblPortRes->Common.fAllocated == TBX_TRUE )
								{
									pCurrentMblPortRes->Common.fMustClear = fMustClear;
								}
							}
						}
					}
				}
			}
		}

		/*
		 * Validate stream resources
		 */
		{
			PVOIP_STREAM_RES	pCurrentStreamRes;
			PVOIP_STREAM_RES	pTargetStreamRes;

			pCurrentStreamRes = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfStreamRes );
			while( pCurrentStreamRes )
			{
				fMustClear = TBX_FALSE;
				if( pCurrentStreamRes->Common.fAllocated == TBX_TRUE )
				{
					/* Test if we must clear connection */
					if( in_fForceClear )
					{
						fMustClear = TBX_TRUE;
					}
					else
					{
						/* Find the corresponding target stream resource context */
						Result = TBXHashFind
						(
							in_pAdapterContext->pTargetConfig->hStreamResHash,
							(TBX_HASH_KEY)pCurrentStreamRes->Common.un32ConnectionId,
							(PTBX_VOID*)&pTargetStreamRes
						);
						if( (TBX_RESULT_SUCCESS( Result ) == TBX_TRUE) && (pTargetStreamRes != NULL) )
						{
							/* Validate stream resource parameters */
							VoipCliAdapterStatePrint(
								in_pAdapterContext,
								TRACE_LEVEL_0,
								"Validating stream resource 0x%08X config\n",
								pCurrentStreamRes->Common.hRes );

							VoipAdapterStreamResConfigureCompare(
								in_pAdapterContext,
								pCurrentStreamRes,
								pTargetStreamRes,
								&fMustClear,
								&fMustSetConfigDummy);
						}
						else
						{
							fMustClear = TBX_TRUE;
						}
					}

					pCurrentStreamRes->Common.fMustClear = fMustClear;
				}

				pCurrentStreamRes = TBXPoolOfBuffersNext( in_pAdapterContext->CurrentConfig.hPoolOfStreamRes, pCurrentStreamRes );
			}
		}

		/*
		 * Validate voice processing group
		 */
		{
			PVOIP_VP_GROUP				pCurrentVpGroup;
			PVOIP_VP_GROUP				pTargetVpGroup;

			pCurrentVpGroup = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfVpGroups );
			while( pCurrentVpGroup )
			{
				fMustClear = TBX_FALSE;
				if( pCurrentVpGroup->Common.fAllocated == TBX_TRUE )
				{
					/* Test if we must clear connection */
					if( in_fForceClear )
					{
						fMustClear = TBX_TRUE;
					}
					else
					{
						/* Find the corresponding target voice processing group context */
						Result = TBXHashFind
						(
							in_pAdapterContext->pTargetConfig->hVpGroupHash,
							(TBX_HASH_KEY)pCurrentVpGroup->Common.un32ConnectionId,
							(PTBX_VOID*)&pTargetVpGroup
						);
						if( (TBX_RESULT_SUCCESS( Result ) == TBX_TRUE) && (pTargetVpGroup != NULL) )
						{
							/* Validate voice processing group parameters */
							VoipCliAdapterStatePrint(
								in_pAdapterContext,
								TRACE_LEVEL_0,
								"Validating voice processing group 0x%08X config\n",
								pCurrentVpGroup->Common.hRes );

							VoipAdapterVpGroupConfigureCompare(
								in_pAdapterContext,
								pCurrentVpGroup,
								pTargetVpGroup,
								&fMustClear,
								&fMustSetConfigDummy);
						}
						else
						{
							fMustClear = TBX_TRUE;
						}
					}

					/* Set "fMustClear" indication for VP group */
					pCurrentVpGroup->Common.fMustClear = fMustClear;

					/* Set "fMustClear" indication for VP resources */
					for( un32Index = 0; un32Index < pCurrentVpGroup->un32NbResources; un32Index++ )
					{
						pCurrentVpGroup->aRes[un32Index].Common.fMustClear = fMustClear;
					}
				}

				pCurrentVpGroup = TBXPoolOfBuffersNext( in_pAdapterContext->CurrentConfig.hPoolOfVpGroups, pCurrentVpGroup );
			}
		}

		/*
		 * Free connections
		 */
		{
			PVOIP_CONNECTION_CONTEXT	pTargetConnectionContext = NULL;
			PVOIP_CONNECTION_CONTEXT	pCurrentConnectionContext = NULL;
			PVOIP_CONNECTION_CONTEXT	pNextConnectionContext = NULL;

			pCurrentConnectionContext = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfConnections );
			while( pCurrentConnectionContext )
			{
				fMustClear = TBX_FALSE;
				if( pCurrentConnectionContext->fAllocated == TBX_TRUE )
				{
					/* Test if we must clear connection */
					if( in_fForceClear == TBX_TRUE)
					{
						fMustClear = TBX_TRUE;
					}
					else
					{
						/* Find the corresponding target connection context */
						Result = TBXHashFind
						(
							in_pAdapterContext->pTargetConfig->hConnectionHash,
							(TBX_HASH_KEY)pCurrentConnectionContext->un32ConnectionId,
							(PTBX_VOID*)&pTargetConnectionContext
						);
						if( (TBX_RESULT_SUCCESS( Result) != TBX_FALSE) && (pTargetConnectionContext != NULL) )
						{
							/* Validate connection parameters */
							VoipCliAdapterStatePrint(
								in_pAdapterContext,
								TRACE_LEVEL_0,
								"Validating connection 0x%08X config\n",
								pCurrentConnectionContext->hConn );

							VoipAdapterConnectionConfigureCompare(
								in_pAdapterContext,
								pCurrentConnectionContext,
								pTargetConnectionContext,
								&fMustClear,
								&fMustSetConfigDummy);
						}
						else
						{
							fMustClear = TBX_TRUE;
						}
					}
				}

				/* Get next connection context before clearing current connection context */
				pNextConnectionContext = TBXPoolOfBuffersNext( in_pAdapterContext->CurrentConfig.hPoolOfConnections, pCurrentConnectionContext );

				if( fMustClear == TBX_TRUE )
				{
					/*
					 *	Clear connection
					 */
					Result = VoipSendAdapterConnectionClear(
						in_pAdapterContext,
						pCurrentConnectionContext);
					if( TBX_RESULT_FAILURE( Result ) )
					{
						TBX_EXIT_ERROR (Result, 0, "Failed to clear connection context");
					}
				}
				else
				{
					if (pTargetConnectionContext != NULL)
					{
						/* Update connection context */
						pCurrentConnectionContext->un32ConnectionIdx = pTargetConnectionContext->un32ConnectionIdx;
						pCurrentConnectionContext->Params = pTargetConnectionContext->Params;
						if( (pCurrentConnectionContext->Params.Type == VOIP_CONNECTION_TYPE_1) &&
							(pCurrentConnectionContext->Params.Type1.un32DurationMs != (TBX_UINT32)-1) )
						{
							/* Connection duration is not infinite, need to set a valid allocation timestamp */
							pCurrentConnectionContext->un32AllocatedTimestamp = ( g_pContext->un32TimerCurrentTime - pCurrentConnectionContext->Params.Type1.un32DurationMs );
						}
					}
				}

				pCurrentConnectionContext = pNextConnectionContext;
			}
		}

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterClearSubState2	:	Compares the current configuration of the adapter with
 |									its target configuration, and clears all resources that
 |									don't match the target configuration (second steps).
 |
 |	in_pAdapterContext			:	Adapter we are configuring
 |	in_fForceClear				:	Force clear all resources on the adapter
 |
 |  Note						:	~
 |
 |  Return						:	TBX_RESULT_OK if the function succeeded
 |									Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterClearSubState2(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_BOOL				in_fForceClear)
{
	TBX_RESULT	Result;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		Result = TBX_RESULT_OK;

		(TBX_VOID)in_fForceClear;

		/*
		 * Free BERT resources
		 */
		{
			PVOIP_BERT_RES	pCurrentBertRes;

			pCurrentBertRes		= &in_pAdapterContext->CurrentConfig.aBertRes[ 0 ];

			if( pCurrentBertRes->Common.fMustClear == TBX_TRUE )
			{
				/* Clear BERT resource */
				Result = VoipSendAdapterBertResClear(
					in_pAdapterContext,
					pCurrentBertRes);
				if( TBX_RESULT_FAILURE( Result ) )
				{
					TBX_EXIT_ERROR (Result, 0, "Failed to clear BERT resource");
				}
			}
		}

		/*
		 * Free MBL port resources
		 */

⌨️ 快捷键说明

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