📄 isdn.c
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
|
| Project: VoiceLink TB640 sample (ISDN)
|
| Filename: isdn.c
|
| Copyright: TelcoBridges 2002-2003, All Rights Reserved
|
| Description: This file contains the main entry point of the application
|
| Notes: Tabs = 4
|
*-------------------------------------------------------------------------------------------------------------------------------
|
| Revision: $Revision: 1.16 $
|
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| 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_isdnmgr.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 "isdn.h"
#include "prototypes.h"
#include "macros.h"
/*--------------------------------------------------------------------------------------------------------------------------------
| Forward declarations
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Defines
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Types
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Versioning
*------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.16 $";
#endif
/*--------------------------------------------------------------------------------------------------------------------------------
| Global variables
*------------------------------------------------------------------------------------------------------------------------------*/
PTB640_ISDN_CONTEXT g_AppContext;
extern volatile TBX_BOOL g_fExit;
TBX_BOOL g_fControlc = TBX_FALSE;
/*--------------------------------------------------------------------------------------------------------------------------------
| 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_RESULT result;
/*---------------------------------------------------------------------------------------------------------------------------
| 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_ISDN_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 */
result = TB640IsdnParseAndLoadConfiguration (in_argv[1]);
}
else
{
/* Use default filename */
result = TB640IsdnParseAndLoadConfiguration (TB640_ISDN_DEFAULT_CONFIGURATION_FILENAME);
}
if (TBX_RESULT_FAILURE(result))
{
TBX_EXIT_ERROR(result, 0, "Unable to parse configuration file");
}
/* Configure trunk, stacks, CTBus resources and operation libraries */
result = TB640IsdnConfigureSystem ();
if (TBX_RESULT_FAILURE(result))
{
TBX_EXIT_ERROR(result, 0, "Unable to configure trunks and/or stacks");
}
/* Start the client interface (CLI) */
result = TB640IsdnCli ();
if (TBX_RESULT_FAILURE(result))
{
TBX_EXIT_ERROR(result, 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_ISDN_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 */
if( !g_fControlc )
TB640IsdnCleanSystem ();
/* 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;
}
/* Press RETURN to quit, if leaks detected */
if( sm_dump(0) || TBX_RESULT_FAILURE( TBX_ERROR_RESULT ) )
{
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;
g_fControlc = TBX_TRUE;
return TBX_TRUE;
}
#else
void ControlC_Handler( int in_iSignal )
{
g_fExit = TBX_TRUE;
g_fControlc = 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 + -