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

📄 cas.c

📁 telcobridges cas develop
💻 C
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VoiceLink TB640 sample (CAS)
 |
 |	Filename:   	cas.c
 |
 |	Copyright:  	TelcoBridges 2002-2005, All Rights Reserved
 |
 |	Description:	This file contains the main entry point of the application
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.9 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/


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

/* System includes */
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>

/* Local includes */
#include "tbx_ostypes.h"
#include "tbx_id.h"
#include "tbx_result.h"
#include "tbx_msg.h"
#include "tbx_std.h"
#include "tbx_api.h"
#include "tbx_featmgr.h"
#include "tb640_id.h"
#include "tb640_handle.h"
#include "tb640_adpmgr.h"
#include "tb640_trkmgr.h"
#include "tb640_casmgr.h"
#include "tbx_os_wrapper.h"

#include "tbx_hash.h"
#include "tbx_pool_of_buffers.h"
#include "tbx_timer.h"
#include "tbxasync.h"
#include "tbx_cli.h"
#include "cas.h"
#include "prototypes.h"
#include "macros.h"
#include "tbx_auto_test.h"

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


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


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


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
	/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.9 $";
#endif

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/
PTB640_CAS_CONTEXT				g_AppContext;
extern volatile TBX_BOOL		g_fExit;


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


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

#ifdef WIN32
	static BOOL WINAPI ControlC_Handler(DWORD CtrlType);
#else
	void ControlC_Handler( int in_iSignal );
#endif

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


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  main        	:	This function is the main entry point of the application
 |
 |  in_argc         :	Number of arguments passed to this application (including the application's name)
 |  in_argv			:	Array of strings containing every arguments
 |
 |  Note			:	~
 |
 |  Return          :	Not used
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
int 
main (
  IN	int			in_argc,
  IN	char *		in_argv [])
{	
	TBX_BOOL		fTestMode = TBX_FALSE;
	TBX_RESULT		result;
	PTBX_CHAR		pszConfigName;
	TBX_CHAR		szArguments[128];

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		g_AppContext = NULL;

		#ifdef WIN32
		{
			/* Install control-C handler function */
			/* SetConsoleCtrlHandler( ControlC_Handler, TBX_TRUE ); */
		}
		#else
		{
			TBX_UINT32	l_un32SigCount;
			int			l_pSignalsToTrap[] 	= { SIGINT, SIGHUP, SIGALRM, SIGQUIT, SIGTERM, SIGUSR1 };
			/* Trap normal exit signals */
			for( l_un32SigCount = 0; l_un32SigCount < sizeof( l_pSignalsToTrap ) / sizeof( int ); l_un32SigCount++ )
			{
				signal( l_pSignalsToTrap[ l_un32SigCount ], ControlC_Handler );
			}
			/* Ignore sig pipe (broken pipe that occurs when a socket closes) */
			signal( SIGPIPE, SIG_IGN );
		}
		#endif

		/* Allocate application context */
		g_AppContext = (PTB640_CAS_CONTEXT)calloc (1, sizeof(*g_AppContext));

		/* Create display output semaphore */
		TBX_SEM_CREATE (&g_AppContext->DisplaySem, 1, 1);

		/* Parse the configuration file and load it into our context structure */
		if (in_argc == 2)
		{
			/* Use filename passed in arguments */
			pszConfigName = in_argv[1];
		}
		else if( in_argc > 2 )
		{
			strcpy( szArguments, in_argv[1] );
			TB640CasToUpper( szArguments );
			/* Test mode or not ? */
			if (strcmp(TB640_CAS_TEST_ARG1_NAME, szArguments) == 0)
			{
				/* Test mode activated */
				g_AppContext->fTestModeActivated = TBX_TRUE;
				fTestMode = TBX_TRUE;

				/* Display is inhibited under unix system for test controller */
				#ifndef WIN32
				g_AppContext->fDisplayInhibited = TBX_TRUE;
				#endif

				/* Make sure we have enough arguments */
				if (in_argc != 5)
				{
					TBX_EXIT_ERROR(TBX_RESULT_ID_INVALID_PARAM, 0, "Missing argument(s)");
				}

				strcpy( szArguments, in_argv[2] );
				TB640CasToUpper( szArguments );
				/* Retrieve the application ID */
				if (strcmp(TB640_CAS_TEST_ARG2_NAME, szArguments) != 0)
				{
					TBX_EXIT_ERROR(TBX_RESULT_ID_INVALID_PARAM, 0, "Expecting '-ID [#]' as second argument");
				}
				g_AppContext->un32ApplicationId = atoi (in_argv[3]);

				/* Get the configuration filename */
				pszConfigName = in_argv[4];
			}
			else
			{
				/* missing '-test' parameter */
				TBX_CHAR		szErr[128];

				sprintf( szErr, "Expecting '%s' as first argument", TB640_CAS_TEST_ARG1_NAME );
				TBX_EXIT_ERROR(TBX_RESULT_ID_INVALID_PARAM, 0, szErr );

			}
		}
		else
		{
			/* Use default filename */
			pszConfigName = TB640_CAS_DEFAULT_CONFIGURATION_FILENAME;
		}

		result = TB640CasParseAndLoadConfiguration ( pszConfigName );
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to parse configuration file");
		}

		/* Configure trunk, stacks, CTBus resources and operation libraries */
		result = TB640CasConfigureSystem ();
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to configure trunks and/or stacks");
		}		

		/* Start the client interface (CLI) */
		result = TB640CasCli ();
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Error while executing client interface");
		}
		
		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_CAS_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		/* Free the application context */
		if (NULL != g_AppContext)
		{	
			/* Configure allocated trunk, stacks, CTBus resources and operation libraries */
			TB640CasCleanSystem ();
		
			/* Close the log file if it was opened */
			if (NULL != g_AppContext->pLogFile)
			{
				fclose (g_AppContext->pLogFile);
				g_AppContext->pLogFile = NULL;
			}

			/* Destroy display output semaphore */
			TBX_SEM_DESTROY (&g_AppContext->DisplaySem);

			/* Free global context */
			free (g_AppContext);
			g_AppContext = NULL;
		}
	}

	if( sm_dump(0) || TBX_RESULT_FAILURE( TBX_ERROR_RESULT ) )
	{
		/* if in test mode send the leaks in a file */
		if( fTestMode )
		{
			FILE*	pLeakFile = fopen ("leaks.txt", "w" );
			if( pLeakFile )
			{
				sm_dump_to_file( pLeakFile, 0 );
				fclose( pLeakFile );
			}

		}
		else
		{
			fprintf( stdout, "Done. Press RETURN to quit...\n" );
			fflush( stdin );
			getchar();
		}
	}
	RETURN_WITH_TYPE (int);
}



/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |  ControlC_Handler		:	Function called when the user press Control-C while the test is running.
 |								This function forces all file playbacks to stop.
 |
 |  Note					:	
 |						
 |  Return					:	
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
BOOL WINAPI ControlC_Handler(DWORD CtrlType)
{
	/* Process exit application command from windows */
	if( CtrlType == 2 )
	{
		printf( "Window is being closed. Quitting...\n" );
	}
	else
	{
		printf( "Received control-C. Quitting...\n" );
	}

	g_fExit = TBX_TRUE;

	return TBX_TRUE;
}
#else
void ControlC_Handler( int in_iSignal )
{
	g_fExit = TBX_TRUE;

	/* Re-install this signal handler for the next time */
	if( in_iSignal == SIGINT )
	{
		printf( "Received Control-C. Quitting...\n" );
	}
	else
	{
		printf( "Received quit signal %d. Quitting...\n", in_iSignal );
	}
	signal( in_iSignal, ControlC_Handler );
}
#endif

⌨️ 快捷键说明

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