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

📄 voip_adapter_alloc.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK if the function succeeded
 |								Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipAdapterRawDataFileAlloc(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_RAW_DATA_FILE_CONTEXT	in_pTargetRawDataFileContext)
{
	TBX_RESULT					Result;
	PVOIP_RAW_DATA_FILE_CONTEXT	pCurrentRawDataFileContext;
	TBX_UINT64					un64Id;
	TBX_UINT32					un32Index;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		pCurrentRawDataFileContext = NULL;
		
		if( in_pAdapterContext->fStopUsingPending )
		{
			/* We must not use this adapter anymore (stop using). Don't send request. */
			TBX_EXIT_SUCCESS (TBX_RESULT_OK);
		}
		if( in_pAdapterContext->fNewConfigPending )
		{
			/* Config has been changed. Don't loose too much time trying to allocate things that may not be
			   required in the new config... */
			TBX_EXIT_SUCCESS (TBX_RESULT_OK);
		}

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Allocating raw data file %s\n",
			in_pTargetRawDataFileContext->Params.szRawDataFileResName
		);

		/* Get free raw data file context */
		pCurrentRawDataFileContext = TBXPoolOfBuffersAlloc
		(
			in_pAdapterContext->CurrentConfig.hPoolOfRawDataFiles,
			(TBX_HASH_KEY)in_pTargetRawDataFileContext->un32ConnectionId
		);
		if( pCurrentRawDataFileContext == NULL )
		{
			TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to allocate element from pool of raw data file buffers.");
		}
		memset( pCurrentRawDataFileContext, 0, sizeof( *pCurrentRawDataFileContext ) );

		/* Insert raw data file context in hash table of raw data file names */
		Result = TBXHashInsert
		(
			in_pAdapterContext->CurrentConfig.hRawDataFileNameHash,
			(TBX_HASH_KEY)in_pTargetRawDataFileContext->Params.szRawDataFileResName,
			pCurrentRawDataFileContext
		);
		if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
		{
			TBX_EXIT_ERROR (Result, 0, "Failed to insert element in raw data file name hash table.");
		}

		/* Insert raw data file context in hash table of raw data file id */
		Result = TBXPoolOfBuffersGetBufferIndex
		(
			in_pAdapterContext->CurrentConfig.hPoolOfRawDataFiles,
			pCurrentRawDataFileContext,
			&un32Index
		);
		if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
		{
			TBX_EXIT_ERROR (Result, 0, "Failed to get index in pool of buffers for raw data file.");
		}

		un64Id = ( ( (TBX_UINT64) in_pAdapterContext->AdapterInfo.hAdapter ) << 32 ) | un32Index;

		Result = TBXHash64Insert
		(
			in_pAdapterContext->CurrentConfig.hRawDataFileIdHash64,
			(TBX_HASH_64_KEY)un64Id,
			pCurrentRawDataFileContext
		);
		if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
		{
			TBX_EXIT_ERROR (Result, 0, "Failed to insert element in raw data file id hash table.");
		}

		/* Allocate and initialize our "current" context. (config will be copied later in file "voip_adapter_set.c") */
		pCurrentRawDataFileContext->fAllocated			= TBX_TRUE;
		pCurrentRawDataFileContext->un64Id				= un64Id;
		pCurrentRawDataFileContext->un32ConnectionId	= in_pTargetRawDataFileContext->un32ConnectionId;
		pCurrentRawDataFileContext->Params				= in_pTargetRawDataFileContext->Params;

		/* Allocate stream server raw data file context */
		if( pCurrentRawDataFileContext->Params.Direction == VOIP_RAW_DATAFILE_DIRECTION_REC_PLAY ||
			pCurrentRawDataFileContext->Params.Direction == VOIP_RAW_DATAFILE_DIRECTION_PLAY )
		{
			Result = VoipRawDataFilePlayAlloc(
				pCurrentRawDataFileContext,
				pCurrentRawDataFileContext->Params.un16RxIPPort,
				in_pAdapterContext->AdapterInfo.szIpAddress0,
				pCurrentRawDataFileContext->Params.szPathName,
				pCurrentRawDataFileContext->Params.un32NbRepeat);
			if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
			{
				TBX_EXIT_ERROR (Result, 0, "Failed to allocate runtime context for raw data file playing.");
			}

			/* Start playing raw data file */
			Result = VoipRawDataFileStartPlay( &pCurrentRawDataFileContext->PlayContext );
			if( TBX_RESULT_FAILURE( Result ) )
			{
				TBX_EXIT_ERROR (Result, 0, "Failed to start playing raw data file");
			}
		}
		if( pCurrentRawDataFileContext->Params.Direction == VOIP_RAW_DATAFILE_DIRECTION_REC_PLAY ||
			pCurrentRawDataFileContext->Params.Direction == VOIP_RAW_DATAFILE_DIRECTION_REC )
		{
			TBX_CHAR		szRecordFilename[256];

			sprintf( szRecordFilename, "%s.log", pCurrentRawDataFileContext->Params.szPathName );
			Result = VoipRawDataFileRecordAlloc(
				pCurrentRawDataFileContext,
				pCurrentRawDataFileContext->Params.un16TxIPPort,
				in_pAdapterContext->AdapterInfo.szIpAddress0,
				szRecordFilename);
			if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
			{
				TBX_EXIT_ERROR (Result, 0, "Failed to allocate runtime context for raw data file recording.");
			}

			/* Start recording raw data */
			Result = VoipRawDataFileStartRecord( &pCurrentRawDataFileContext->RecordContext );
			if( TBX_RESULT_FAILURE( Result ) )
			{
				TBX_EXIT_ERROR (Result, 0, "Failed to start recording raw data file");
			}
		}

		pCurrentRawDataFileContext->fActive = 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,
			"VoipAdapterRawDataFileAlloc: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
		if( pCurrentRawDataFileContext )
		{
			VoipRawDataFileClearContext( in_pAdapterContext, pCurrentRawDataFileContext );
		}
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterBertResAlloc	:	Allocates a BERT resource on the adapter.
 |
 |	in_pAdapterContext			:	Adapter configuration we are configuring
 |	in_pTargetBertRes			:	Target BERT resource to allocate
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterBertResAlloc(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_BERT_RES			in_pTargetBertRes)
{
	PVOIP_BERT_RES	pCurrentBertRes;

	VOIP_SEND_REQUEST_BODY_PART1( BERT_RES_ALLOC, 0 )
	{
		pCurrentBertRes = &in_pAdapterContext->CurrentConfig.aBertRes[ VOIP_MAX_BERT_RES ];

		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 allocate things that may not be
			   required in the new config... */
			TBX_EXIT_SUCCESS (Result);
		}

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Allocating BERT resource\n"
		);

		/* Fill request parameters */
		pMsg->Request.Params.PatternType		= in_pTargetBertRes->Params.PatternType;
		pMsg->Request.Params.un8FixedPattern	= in_pTargetBertRes->Params.un8FixedPattern;
	}
	/* Send request macro part 2: Send the request, return Result code */
	VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterBertResAlloc")
}

/* Function to handle the response of the message above */
TBX_RESULT	VoipHandleAdapterBertResAllocResponse(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	TBX_RESULT					Result;
	PTB640_RSP_BERT_RES_ALLOC	pResponse;
	PVOIP_BERT_RES				pCurrentBertRes;
	PVOIP_BERT_RES				pTargetBertRes;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pResponse			= TBX_MSG_PAYLOAD_POINTER( in_hMsg );
		pCurrentBertRes		= &in_pAdapterContext->CurrentConfig.aBertRes[ 0 ];
		pTargetBertRes		= &in_pAdapterContext->pTargetConfig->aBertRes[ 0 ];

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

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Allocate BERT resource result is 0x%08X\n",
			(int)pResponse->Result
		);

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

		/* Insert BERT resource handle in resources handle hash table */
		Result = TBXHashInsert
		(
			in_pAdapterContext->CurrentConfig.hResHandleHash,
			(TBX_HASH_KEY)pResponse->hResource,
			pCurrentBertRes
		);
		if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
		{
			TBX_EXIT_ERROR (Result, 0, "Failed to insert element in resource handle hash table.");
		}

		/* Allocate and initialize our "current" context. (config will be copied later in file "voip_adapter_set.c") */
		pCurrentBertRes->Common.hRes				= pResponse->hResource;
		pCurrentBertRes->Common.fAllocated			= TBX_TRUE;
		pCurrentBertRes->Common.fMustClear			= TBX_FALSE;
		pCurrentBertRes->Common.fUsed				= TBX_FALSE;
		pCurrentBertRes->Common.un32ConnectionId	= 0;
		pCurrentBertRes->Params						= pTargetBertRes->Params;

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

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

	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipSendAdapterTrunkResAlloc	:	Allocates a trunk resource on the adapter.
 |
 |	in_pAdapterContext				:	Adapter configuration we are configuring
 |	in_pTargetTrunk					:	Target trunk to allocate resource
 |	in_un32TimeSlot					:	TimeSlot number of the resource to allocate
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipSendAdapterTrunkResAlloc(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_TRUNK_CONFIG		in_pTargetTrunkConfig,
	IN		TBX_UINT32				in_un32TimeSlot)
{
	PVOIP_TRUNK_CONFIG	pCurrentTrunkConfig;

	VOIP_SEND_REQUEST_BODY_PART1( TRUNK_RES_ALLOC, 0 )
	{
		pCurrentTrunkConfig = &in_pAdapterContext->CurrentConfig.aTrunk[ in_pTargetTrunkConfig->un32TrunkNumber ];

		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 allocate things that may not be
			   required in the new config... */
			TBX_EXIT_SUCCESS (Result);
		}

		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_1,
			"Allocating trunk %d timeslot %d\n",
			pCurrentTrunkConfig->un32TrunkNumber,

⌨️ 快捷键说明

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