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

📄 voip_demo.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VOIP sample
 |
 |	Filename:   	voip_demo.c
 |
 |	Copyright:  	TelcoBridges 2002-2004, All Rights Reserved
 |
 |	Description:	This file contains functions for demo operations.
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.12 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/

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

#include "voip_includes.h"


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

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


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


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


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

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipDemoCleanup		:	Demo cleanup function.
 |
 |	in_pAdapterContext	:	Context of the adapter to disconnect all resources.
 |
 |  Note				:	~
 |
 |  Return				:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipDemoCleanup(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext )
{
	PVOIP_CLI_CONTEXT				pCliContext;
	TBX_MSG_HANDLE					hMsg;
	PVOIP_EVT_OP_CLEAR_CONNECTION	pEvt;

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

		/* Disconnect all resources */
		hMsg = VoipFormatPrivateMsg
		(
			VOIP_MSG_ID_OP_CLEAR_CONNECTION,
			sizeof( VOIP_MSG_OP_CLEAR_CONNECTION ),
			in_pAdapterContext->AdapterInfo.hAdapter,
			0
		);

		/* Fill the request */
		pEvt = (PVOIP_EVT_OP_CLEAR_CONNECTION) TBX_MSG_PAYLOAD_POINTER (hMsg);
		pEvt->un32MsgVersion	= 1;
		pEvt->fAll	= TBX_TRUE;
		pEvt->fIncludeInfiniteDurCall	= TBX_TRUE;

		if( hMsg != (TBX_MSG_HANDLE)TBX_HANDLE_INVALID )
		{
			in_pAdapterContext->pFctStateHandler( in_pAdapterContext, hMsg );
			TBXReleaseMsg (g_pContext->hTbxLib, hMsg);
		}

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipDemoStart		:	Handles the start stress test message.
 |
 |	in_pAdapterContext	:	Context of the adapter to begin stress test.
 |	in_pEvt				:	Message to handle
 |
 |  Note				:	~
 |
 |  Return				:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipDemoStart(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		PVOIP_EVT_OP_START_DEMO	in_pEvt )
{
	PVOIP_CLI_CONTEXT	pCliContext;
	TBX_UINT32			un32Index;

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

		/* Enable demo */
		in_pAdapterContext->Demo.fActive			= TBX_TRUE;
		in_pAdapterContext->Demo.fCleanupPending	= TBX_FALSE;
		in_pAdapterContext->Demo.fSkipPauses		= in_pEvt->fSkipPauses;
		in_pAdapterContext->Demo.fAutoAbort			= in_pEvt->fAutoAbort;
		in_pAdapterContext->Demo.un32CurrentStep	= 0;
		in_pAdapterContext->Demo.fTitle				= TBX_FALSE;

		/* Reset demo step indications */
		for( un32Index = 0; un32Index < in_pAdapterContext->Demo.un32StepCount; un32Index++ )
		{
			in_pAdapterContext->Demo.aStep[un32Index].fWait = TBX_FALSE;
		}

		/* Demo is running on, at least, one adapter */
		g_pContext->fDemoRunning = TBX_TRUE;

		/* Start demo with first step */
		VoipDemoNextStep( in_pAdapterContext );

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

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipDemoStop		:	Handles the stop stress test message.
 |
 |	in_pAdapterContext	:	Context of the adapter to stop stress test
 |
 |  Note				:	~
 |
 |  Return				:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipDemoStop(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext )
{
	TBX_RESULT					Result;
	PVOIP_CLI_CONTEXT			pCliContext;
	PVOIP_ADAPTER_CONTEXT		pAdapterContext;
	PVOIP_ADAPTER_CONTEXT_NODE	pAdapterContextNode;

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

		if( g_pContext->fDemoCleanupPending == TBX_TRUE )
		{
			TBX_EXIT_ERROR(TBX_RESULT_ACCESS_DENIED, 0, "There is already a pending demo cleanup. Try later..." );
		}

		/* Disable demo */
		in_pAdapterContext->Demo.fActive				= TBX_FALSE;
		in_pAdapterContext->Demo.fCleanupPending		= TBX_TRUE;
		in_pAdapterContext->Demo.un32CleanupRetryCount	= 0;

		/* By default, there is no more demo running */
		g_pContext->fDemoRunning = TBX_FALSE;

		/* Check if there is a demo running on, at least, one adapter */
		pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
		while( pAdapterContextNode )
		{
			pAdapterContext = pAdapterContextNode->pAdapterContext;
			if( pAdapterContext->Demo.fActive == TBX_TRUE )
			{
				g_pContext->fDemoRunning = TBX_TRUE;
				break;
			}
			
			pAdapterContextNode = TBXPoolOfBuffersNext( g_pContext->hPoolOfAdapters, pAdapterContextNode );
		}

		/* Demo cleanup pending (wait for responses from previous request) */
		g_pContext->fDemoCleanupPending = TBX_TRUE;

		/* Clear all connections */
		Result = VoipDemoCleanup( in_pAdapterContext );
		if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
		{
			TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "Failed to clear all connections!\n" );
		}

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

⌨️ 快捷键说明

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