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

📄 voip_adapter_ready.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 2 页
字号:
				/* Update target connection context */
				pTargetConnectionContext->un32NbResponsesExpected--;
				if( pTargetConnectionContext->un32NbResponsesExpected == 0 )
				{
					/*
					 *	Allocate the connection context
					 */
					Result = VoipSendAdapterConnectionAlloc(
						in_pAdapterContext,
						pTargetConnectionContext);
					if( TBX_RESULT_FAILURE( Result ) )
					{
						TBX_EXIT_ERROR (Result, 0, "Failed to allocate connection");
					}
				}

			} break;

			/*
			 * Response from our "connection alloc" messages
			 */
			case TB640_MSG_ID_CONN_OP_CREATE:
			{
				/* Retrieve connection identifier */
				un32ConnectionId = (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );

				/* Retrieve target connection context */
				Result = TBXHashFind( in_pAdapterContext->pTargetConfig->hConnectionHash, (TBX_HASH_KEY)un32ConnectionId, (PTBX_VOID*)&pTargetConnectionContext );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR(TBX_RESULT_NOT_FOUND, 0, "Failed to found target connection context!" );
				}

				/* Update target connection context */
				pTargetConnectionContext->un32NbResponsesExpected--;

				/* Handle this response */
				Result = VoipHandleAdapterConnectionAllocResponse( in_pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR( Result, 0, "Failed to create connection!" );
				}

				/* Increment stress-test stats */
				if( in_pAdapterContext->StressTest.fActive == TBX_TRUE )
				{
					in_pAdapterContext->StressTest.Stats.un64NbConnectionsCompleted++;
				}

			} break;

			default:
				TBX_EXIT_ERROR( TBX_RESULT_NOT_FOUND, 0, "Failed to found connect message" );
				break;
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Increment stress-test stats */
		if( in_pAdapterContext->StressTest.fActive == TBX_TRUE )
		{
			in_pAdapterContext->StressTest.Stats.un64NbConnectionsFailed++;
		}

		VoipCliAdapterStatePrint(
			in_pAdapterContext,
			TRACE_LEVEL_ERROR,
			"VoipAdapterHandleConnectMessage: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);

		/*
		 *	Rollback operation
		 */
		if( un32ConnectionId != 0 )
		{
			/*
			 * Remove connection from target configuration
			 */
			{
				PVOIP_CONNECTION_CONTEXT pConnectionContext;

				/* Find the corresponding target connection context */
				Result = TBXHashFind( in_pAdapterContext->pTargetConfig->hConnectionHash, un32ConnectionId, (PTBX_VOID*)&pConnectionContext );
				if( TBX_RESULT_SUCCESS( Result) == TBX_TRUE )
				{
					/* Remove connection from target configuration */
					VoipAdapterRemoveConnectionFromTarget( in_pAdapterContext, un32ConnectionId );
				}
			}
		}
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipAdapterHandleDisconnectMessage	:	Handles message to destroy connection.
 |
 |	in_pAdapterContext					:	Adapter we are configuring
 |	in_hMsg								:	Message to handle
 |	
 |
 |  Note								:	~
 |
 |  Return								:	TBX_RESULT_OK if the function succeeded
 |											Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterHandleDisconnectMessage(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	TBX_RESULT					Result;
	PVOIP_CONNECTION_CONTEXT	pCurrentConnectionContext;
	PVOIP_CONNECTION_CONTEXT	pTargetConnectionContext;
	TBX_UINT32					un32ConnectionId;

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

		switch( TBX_MSG_ID_GET( in_hMsg ) )
		{
			case VOIP_MSG_ID_OP_CLEAR_CONNECTION:
			{
				PVOIP_EVT_OP_CLEAR_CONNECTION	pEvt = TBX_MSG_PAYLOAD_POINTER( in_hMsg );

				/* Increment stress-test stats */
				if( in_pAdapterContext->StressTest.fActive == TBX_TRUE )
				{
					in_pAdapterContext->StressTest.Stats.un64NbConnectionsClosed++;
				}

				if( pEvt->fAll == TBX_TRUE )
				{
					/*
					 *	Disconnect all resources (type 1 only)
					 */
					pCurrentConnectionContext = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfConnections );
					while( pCurrentConnectionContext )
					{
						/* Note: It is not necessary to send disconnect if connection is already disconnecting */
						if( (pCurrentConnectionContext->Params.Type == VOIP_CONNECTION_TYPE_1) &&
							(pCurrentConnectionContext->fAllocated == TBX_TRUE) )
						{
							/* Do we need to disconnect call with infinite duration? */
							if ((pEvt->fIncludeInfiniteDurCall) ||
								(pCurrentConnectionContext->Params.Type1.un32DurationMs != (TBX_UINT32)-1))
							{
								/*
								 *	Clear connection
								 */
								Result = VoipSendAdapterConnectionClear(
									in_pAdapterContext,
									pCurrentConnectionContext);
								if( TBX_RESULT_FAILURE( Result ) )
								{
									TBX_EXIT_ERROR (Result, 0, "Failed to clear current connection context");
								}
							}
						}

						pCurrentConnectionContext = TBXPoolOfBuffersNext( in_pAdapterContext->CurrentConfig.hPoolOfConnections, pCurrentConnectionContext );
					}
				}
				else
				{
					/*
					 *	Disconnect resources
					 */
					un32ConnectionId = pEvt->un32ConnectionId;

					/* Retrieve current connection context */
					Result = TBXHashFind( in_pAdapterContext->CurrentConfig.hConnectionHash, (TBX_HASH_KEY)un32ConnectionId, (PTBX_VOID*)&pCurrentConnectionContext );
					if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
					{
						TBX_EXIT_ERROR(TBX_RESULT_NOT_FOUND, 0, "Failed to found current connection context!" );
					}

					if( pCurrentConnectionContext->Params.Type == VOIP_CONNECTION_TYPE_0 )
					{
						TBX_EXIT_ERROR (TBX_RESULT_INVALID_OPERATION, 0, "Prompt playback connections are permanent... Ignoring request!");
					}

					/* Note: It is not necessary to send disconnect if connection is already disconnecting */
					if( pCurrentConnectionContext->fAllocated == TBX_TRUE )
					{
						/*
						 *	Clear connection
						 */
						Result = VoipSendAdapterConnectionClear(
							in_pAdapterContext,
							pCurrentConnectionContext);
						if( TBX_RESULT_FAILURE( Result ) )
						{
							TBX_EXIT_ERROR (Result, 0, "Failed to clear current connection context");
						}
					}
				}

			} break;

			/*
			 * Response from our "Stream free" messages
			 */
			case TB640_MSG_ID_STREAM_RES_FREE:
			{
				/* Retrieve connection identifier */
				un32ConnectionId = (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );

				/* Handle this response */
				Result = VoipHandleAdapterStreamResClearResponse( in_pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR( Result, 0, "Failed to clear stream resource!" );
				}

				/* Retrieve target connection context */
				Result = TBXHashFind( in_pAdapterContext->pTargetConfig->hConnectionHash, (TBX_HASH_KEY)un32ConnectionId, (PTBX_VOID*)&pTargetConnectionContext );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR(TBX_RESULT_NOT_FOUND, 0, "Failed to found target connection context!" );
				}

				/* Update responses counter */
				pTargetConnectionContext->un32NbResponsesExpected--;

				if( pTargetConnectionContext->un32NbResponsesExpected == 0)
				{
					/* Remove connection from target configuration */
					Result = VoipAdapterRemoveConnectionFromTarget( in_pAdapterContext, un32ConnectionId );
					if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
					{
						TBX_EXIT_ERROR(Result, 0, "Failed to remove connection from target configuration!" );
					}
				}

			} break;

			/*
			 * Response from our "voice processing free" messages
			 */
			case TB640_MSG_ID_VP_GROUP_FREE:
			{
				/* Retrieve connection identifier */
				un32ConnectionId = (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );

				/* Handle this response */
				Result = VoipHandleAdapterVpGroupClearResponse( in_pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR( Result, 0, "Failed to clear voice processing group!" );
				}

				/* Retrieve target connection context */
				Result = TBXHashFind( in_pAdapterContext->pTargetConfig->hConnectionHash, (TBX_HASH_KEY)un32ConnectionId, (PTBX_VOID*)&pTargetConnectionContext );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR(TBX_RESULT_NOT_FOUND, 0, "Failed to found target connection context!" );
				}

				/* Update responses counter */
				pTargetConnectionContext->un32NbResponsesExpected--;

				if( pTargetConnectionContext->un32NbResponsesExpected == 0)
				{
					/* Remove connection from target configuration */
					Result = VoipAdapterRemoveConnectionFromTarget( in_pAdapterContext, un32ConnectionId );
					if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
					{
						TBX_EXIT_ERROR(Result, 0, "Failed to remove connection from target configuration!" );
					}
				}

			} break;

			/*
			 * Response from our "connection free" messages
			 */
			case TB640_MSG_ID_CONN_OP_DESTROY:
			{
				/* Retrieve connection identifier */
				un32ConnectionId = (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );

				/* Handle this response */
				Result = VoipHandleAdapterConnectionClearResponse( in_pAdapterContext, in_hMsg );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR( Result, 0, "Failed to destroy connection!" );
				}

				/* Retrieve target connection context */
				Result = TBXHashFind( in_pAdapterContext->pTargetConfig->hConnectionHash, (TBX_HASH_KEY)un32ConnectionId, (PTBX_VOID*)&pTargetConnectionContext );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR(TBX_RESULT_NOT_FOUND, 0, "Failed to found target connection context!" );
				}

				/* Reset responses counter */
				pTargetConnectionContext->un32NbResponsesExpected = 0;

				if( pTargetConnectionContext->Params.Type1.SecondRes.Type != VOIP_RESOURCE_TYPE_STREAM_SOCKET )
				{
					/* Remove connection from target configuration */
					Result = VoipAdapterRemoveConnectionFromTarget( in_pAdapterContext, un32ConnectionId );
					if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
					{
						TBX_EXIT_ERROR(Result, 0, "Failed to remove connection from target configuration!" );
					}
				}
				else
				{
					/*
					 * Free stream resource
					 */
					{
						PVOIP_STREAM_RES pCurrentStreamRes;

						/* Find the corresponding current stream resource context */
						Result = TBXHashFind( in_pAdapterContext->CurrentConfig.hStreamResHash, un32ConnectionId, (PTBX_VOID*)&pCurrentStreamRes );
						if( TBX_RESULT_SUCCESS( Result ) == TBX_TRUE )
						{
							/*
							 *	Clear stream resource
							 */
							Result = VoipSendAdapterStreamResClear(
								in_pAdapterContext,
								pCurrentStreamRes);
							if( TBX_RESULT_FAILURE( Result ) )
							{
								TBX_EXIT_ERROR (Result, 0, "Failed to clear stream resource");
							}

							/* Update responses counter */
							pTargetConnectionContext->un32NbResponsesExpected++;
						}
					}

					/*
					 * Free voice processing group
					 */
					{
						PVOIP_VP_GROUP pCurrentVpGroup;

						/* Find the corresponding current voice processing group context */
						/* Remove the resource handle from our hash table of connection identifier */
						Result = TBXHashFind( in_pAdapterContext->CurrentConfig.hVpGroupHash, un32ConnectionId, (PTBX_VOID*)&pCurrentVpGroup );
						if( TBX_RESULT_SUCCESS( Result ) == TBX_TRUE )
						{
							/*
							 *	Clear voice processing group
							 */
							Result = VoipSendAdapterVpGroupClear(
								in_pAdapterContext,
								pCurrentVpGroup);
							if( TBX_RESULT_FAILURE( Result ) )
							{
								TBX_EXIT_ERROR (Result, 0, "Failed to clear voice processing group");
							}

							/* Update responses counter */
							pTargetConnectionContext->un32NbResponsesExpected++;
						}
					}
				}

			} break;

			default:
				TBX_EXIT_ERROR( TBX_RESULT_NOT_FOUND, 0, "Failed to found disconnect message" );
				break;
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		VoipCliAdapterStatePrint(
			in_pAdapterContext,
			TRACE_LEVEL_ERROR,
			"VoipAdapterHandleDisconnectMessage: %s (Result 0x%08X, %s, line %d)\n",
			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 + -