📄 main.c
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
|
| Project: VoiceLink TB640 sample (tone)
|
| Filename: main.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.14 $
|
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Includes
*------------------------------------------------------------------------------------------------------------------------------*/
/* local includes */
#include "structures.h"
/*--------------------------------------------------------------------------------------------------------------------------------
| Forward declarations
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Defines
*------------------------------------------------------------------------------------------------------------------------------*/
#define TB640_TONE_AUTODETECT_DELAY_MIN_MSEC 500
#define TB640_TONE_WATCHDOG_TIMEOUT_SEC 4
#define TB640_TONE_MAX_ERROR_DESCRIPTION_STRING 256
/*--------------------------------------------------------------------------------------------------------------------------------
| Types
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Versioning
*------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
static char g_szFileVersion [] = "$Revision: 1.14 $";
#endif
/*--------------------------------------------------------------------------------------------------------------------------------
| Global variables
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Macros
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Function Prototypes
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| 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 : 0 if everything was successful
| != 0, error code that occured
|
*------------------------------------------------------------------------------------------------------------------------------*/
int
main (
IN int in_argc,
IN char * in_argv [])
{
int nResult;
TBX_ADAPTER_HANDLE hAdapter;
TBX_LIB_HANDLE hLib;
TBX_LIB_PARAMS LibParam;
TBX_RESULT_API result;
/* Initialize local variables */
nResult = 0;
hLib = (TBX_LIB_HANDLE)TBX_HANDLE_INVALID;
hAdapter = (TBX_ADAPTER_HANDLE)TBX_HANDLE_INVALID;
result = TBX_RESULT_OK;
memset (&LibParam, 0, sizeof(LibParam));
/* Ignore sig pipe (broken pipe that occurs when a socket closes) */
#ifndef WIN32
signal( SIGPIPE, SIG_IGN );
#endif
/* Validate input parameters */
/* Initialize the library access parameters */
memset (&LibParam, 0, sizeof (LibParam));
LibParam.un32StructVersion = 1;
LibParam.un32AutoDetectionDelayMin = TB640_TONE_AUTODETECT_DELAY_MIN_MSEC;
LibParam.un32WatchdogTimeoutSec = TB640_TONE_WATCHDOG_TIMEOUT_SEC;
LibParam.TransportType = TBX_TRANSPORT_TYPE_ETHERNET;
LibParam.MsgRxThreadPrio = TBX_MSG_RX_THREAD_PRIO_HIGHER;
LibParam.un32SendFifoSize = TBX_SEND_FIFO_SIZE_DEFAULT;
LibParam.NetworkRedundancyParams.un32StructVersion = 1;
LibParam.NetworkRedundancyParams.un32PollDelayMs = TBX_NETWORK_REDUNDANCY_DEFAULT_POLL_DELAY_MS;
LibParam.NetworkRedundancyParams.un32NetworkDownDelayMs = TBX_NETWORK_REDUNDANCY_DEFAULT_NETWORK_DOWN_DELAY_MS;
LibParam.NetworkRedundancyParams.un32AdapterDownDelayMs = TBX_NETWORK_REDUNDANCY_DEFAULT_ADAPTER_DOWN_DELAY_MS;
LibParam.NetworkRedundancyParams.fUseNetworkGw0 = TBX_TRUE;
LibParam.NetworkRedundancyParams.fUseNetworkGw1 = TBX_TRUE;
LibParam.NetworkRedundancyParams.un32PreferredGateway = 0;
{
PTBX_CHAR pszArgv0 = in_argv[0];
PTBX_CHAR pszFound;
PTBX_CHAR pszAppName;
if( (pszFound = strrchr( pszArgv0, '/')) != NULL )
{
pszAppName = pszFound + 1;
}
else if( (pszFound = strrchr( pszArgv0, '\\')) != NULL )
{
pszAppName = pszFound + 1;
}
else
{
pszAppName = pszArgv0;
}
strncpy( LibParam.szApplicationName, pszAppName, sizeof(LibParam.szApplicationName) );
LibParam.szApplicationName[ sizeof(LibParam.szApplicationName) - 1 ] = '\0';
}
/* Opening the TBX library */
result = TBXOpenLib (&LibParam, &hLib);
printf ("*****************************************\n");
printf ("* TBX Library %s (0x%08X)\n", LibParam.szBuildTag, LibParam.un32BuildNumber);
printf ("*****************************************\n");
if (TBX_RESULT_SUCCESS (result))
{
/* Select which adapter we want to talk to */
result = AutoSelectAdapter (hLib, &hAdapter);
}
/* Was there a adapter selected ? */
if (hAdapter != (TBX_ADAPTER_HANDLE)TBX_HANDLE_INVALID)
{
TBX_BOOL fTrunkAllocated = TBX_FALSE;
TBX_UINT32 un32TrunkNo = 0;
if (TBX_RESULT_SUCCESS (result))
{
/* Retrieve the maximum allowed E1 trunks */
result = GetMaxAllowedTrunks( hLib, hAdapter, TBX_TRUE );
}
if (TBX_RESULT_SUCCESS (result))
{
/* Retrieve the maximum allowed T1 trunks */
result = GetMaxAllowedTrunks( hLib, hAdapter, TBX_FALSE );
}
if (TBX_RESULT_SUCCESS (result))
{
/* Retrieve allocated trunk list */
result = BuildAllocatedTrunkList( hLib, hAdapter, TBX_FALSE );
}
if (TBX_RESULT_SUCCESS (result))
{
un32TrunkNo = PromptUserWithDefault_TBX_INT32( "Trunk number to configure?", 0 );
/* Configure the trunks */
result = ConfigureAdapterTrunk
(
hLib,
hAdapter,
un32TrunkNo,
&fTrunkAllocated
);
}
/* Was there a trunk found ? */
if (TBX_RESULT_SUCCESS (result))
{
/* Main menu */
result = ToneMainMenu (hLib, hAdapter, un32TrunkNo );
}
if( fTrunkAllocated )
{
TBX_BOOL fTrunkFreed = TBX_FALSE;
FreeAdapterTrunk (hLib, hAdapter, un32TrunkNo, &fTrunkFreed);
}
/* Close the previously selected adapter */
CloseAdapter (hLib, hAdapter);
}
if (hLib != (TBX_LIB_HANDLE)TBX_HANDLE_INVALID)
{
/* Close the library */
TBXCloseLib (hLib);
}
/* Was there an error along in the process ? */
if (TBX_RESULT_FAILURE (result))
{
ValidateErrorCode (result, hAdapter, hLib);
nResult = (int)result;
}
return nResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -