📄 config.c
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
|
| Project: VoiceLink TB640 sample (CAS)
|
| Filename: config.c
|
| Copyright: TelcoBridges 2002-2005, All Rights Reserved
|
| Description: This file contains the functions to dynamically configure a set of trunks and stacks asynchronously
|
| Notes: Tabs = 4
|
*-------------------------------------------------------------------------------------------------------------------------------
|
| Revision: $Revision: 1.48 $
|
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| 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_ctbusmgr.h"
#include "tb640_casmgr.h"
#include "tb640_connmgr.h"
#include "tbx_os_wrapper.h"
#include "tbxfeatures.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
*------------------------------------------------------------------------------------------------------------------------------*/
/* Timeout in msec to wait in the TBXReceiveMsg() function while waiting for adapters to register */
#define TB640_CAS_ADAPTER_LOOP_MSG_RECEIVE_TIMEOUT_MSEC 0
/* Timeout value for TbxReceiveMsg() used by the operation library */
#define TB640_CAS_OPERATION_RECEIVE_MSG_TIMEOUT_MSEC 250
/* Maximum number of operation active in one library at the same time */
#define TB640_CAS_MAX_OPERATION_PER_LIBRARY (TB640_CAS_MAX_TRUNK_PER_OPERATION_LIBRARY * TB640_CAS_MAX_TIMESLOT_IN_TRUNK * 4)
/* Allocation granularity for the operation library */
#define TB640_CAS_ALLOCATION_GRANULARITY 512
/* Max concurrent request per operation library */
#define TB640_CAS_MAX_CONCURRENT_REQUEST_PER_LIBRARY (TB640_CAS_MAX_OPERATION_PER_LIBRARY * 10)
/* Defines a interval at which the adapter sends an heartbeat to the library */
#define TB640_CAS_ADAPTER_KEEPALIVE_TIMER_SEC 1
/* Maximum timeout waiting for adapters attach/detach */
#define TB640_CAS_ADAPTER_ATTACH_TIMEOUT_MSEC (10*1000)
/* Maximum timeout waiting for adapters Ctbus alloc/free */
#define TB640_CAS_ADAPTER_CTBUS_ALLOC_TIMEOUT_MSEC (10*1000)
/* Maximum timeout waiting for adapters Trunk alloc/free */
#define TB640_CAS_ADAPTER_TRUNK_ALLOC_TIMEOUT_MSEC (10*1000)
/* Maximum timeout waiting for adapters Trunk activation/maintenance */
#define TB640_CAS_ADAPTER_TRUNK_ACTIVATION_TIMEOUT_MSEC (10*1000)
/* Maximum timeout waiting for adapters trunk resources alloc/free */
#define TB640_CAS_ADAPTER_TRUNK_RESOURCE_ALLOC_TIMEOUT_MSEC (10*1000)
/* Maximum timeout waiting for connection destruction */
#define TB640_CAS_ADAPTER_CONNECTION_DESTRUCTION_TIMEOUT_MSEC (10*1000)
/* Maximum timeout waiting for adapters stack alloc/free */
#define TB640_CAS_ADAPTER_STACK_ALLOC_TIMEOUT_MSEC (45*1000)
/*--------------------------------------------------------------------------------------------------------------------------------
| Types
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Versioning
*------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.48 $";
#endif
/*--------------------------------------------------------------------------------------------------------------------------------
| Global variables
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Macros
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Function Prototypes
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640CasOpenAdapters (void);
TBX_RESULT TB640CasCloseAdapters (void);
TBX_RESULT TB640CasAllocateCtBusResources (void);
TBX_RESULT TB640CasFreeCtBusResources (void);
TBX_RESULT TB640CasAllocateTrunks (void);
TBX_RESULT TB640CasFreeTrunks (void);
TBX_RESULT TB640CasAllocateTrunkResources (void);
TBX_RESULT TB640CasFreeTrunkResources (void);
TBX_RESULT TB640CasDestroyConnections (void);
TBX_RESULT TB640CasAllocateStacks (void);
TBX_RESULT TB640CasFreeStacks (void);
TBX_RESULT TB640CasActivateTrunks (void);
TBX_RESULT TB640CasMaintenanceTrunks (void);
/*--------------------------------------------------------------------------------------------------------------------------------
| Implementation
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640CasConfigureSystem: This function allocates and configure the trunks, stacks, CTBus resources and operation librairies
| required to run this application
|
| ~ : No arguments used
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasConfigureSystem (void)
{
TBX_LIB_PARAMS LibParam;
TBX_RESULT result;
TBX_UINT32 un32Count;
TBX_UINT32 un32Count2;
PTB640_CAS_ADAPTER_INFO pAdapterInfo;
TBX_ASYNC_LIB_PARAMS OperationLibParams;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
/* Initializes the TBX library */
memset (&LibParam, 0, sizeof (LibParam));
LibParam.un32StructVersion = 1;
LibParam.un32WatchdogTimeoutSec = TB640_CAS_ADAPTER_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.pMsgTrace = NULL;
LibParam.pStderr = g_AppContext->pLogFile;
if( g_AppContext->un32GatewayPortNumber > 0 )
{
/* get the first gateway port and put it in the default gateway parameter */
LibParam.un16TbxGwPort = (TBX_UINT16)g_AppContext->aun32GatewayPort[0];
/* get all the other gateway port */
if( g_AppContext->un32GatewayPortNumber > 1 )
{
TBX_UINT32 un32GwCount;
for( un32GwCount = 1; un32GwCount < g_AppContext->un32GatewayPortNumber; un32GwCount++ )
{
LibParam.aun16ExtraTbxGwPort[un32GwCount-1] = (TBX_UINT16)g_AppContext->aun32GatewayPort[un32GwCount];
}
}
}
else
{
/* set default gateway */
LibParam.un16TbxGwPort = 0;
}
strcpy( LibParam.szApplicationName, "cas" );
/* Initialize stress-test statistics semaphore */
TBX_SEM_CREATE (&g_StressStatsSem, 1, 1);
/* Initialize the transiant calls semaphore */
TBX_SEM_CREATE (&(g_AppContext->TransientCallsSem), 1, 1);
g_AppContext->un32TransientCalls = 0;
/* Opening the TBX library */
result = TBXOpenLib (&LibParam, &(g_AppContext->hTbxLib));
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to open TBX library");
}
TB640_CAS_LOG (TRACE_LEVEL_4, "+--------------------------------------------------------------\n");
TB640_CAS_LOG (TRACE_LEVEL_4, "| TBX Library %s (0x%08X)\n", LibParam.szBuildTag, LibParam.un32BuildNumber);
TB640_CAS_LOG (TRACE_LEVEL_4, "+--------------------------------------------------------------\n\n");
/* Create the op context semaphores */
for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
{
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Count]);
for (un32Count2=0; un32Count2<TB640_CAS_NB_OPERATION_LIBRARY_REQUIRED; un32Count2++)
{
TBX_SEM_CREATE (&(pAdapterInfo->Lock.aOperationLibSem[un32Count2]), 1, 1);
pAdapterInfo->Lock.apszOperationLibSemFile[un32Count2] = "";
}
}
/* Open adapters specified in configuration file */
result = TB640CasOpenAdapters ();
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to open requested adapters");
}
/* Open the operation libraries */
for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
{
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Count]);
for (un32Count2=0; un32Count2<(((pAdapterInfo->un32NbTrunk-1)/TB640_CAS_MAX_TRUNK_PER_OPERATION_LIBRARY)+1); un32Count2++)
{
TBX_FILTER_PARAMS AsyncLibCustomFilter[3];
memset( AsyncLibCustomFilter, 0, sizeof(AsyncLibCustomFilter) );
/* One more operation library */
pAdapterInfo->un32NbOperationLib++;
/* Configure the library parameters */
memset( &OperationLibParams, 0, sizeof(OperationLibParams) );
OperationLibParams.un32ReceiveTimeoutMSec = TB640_CAS_OPERATION_RECEIVE_MSG_TIMEOUT_MSEC;
OperationLibParams.un32OpContextMaxCount = TB640_CAS_MAX_OPERATION_PER_LIBRARY;
OperationLibParams.un32OpContextAllocGranularity = TB640_CAS_ALLOCATION_GRANULARITY;
OperationLibParams.un32OpContextUserContextSize = sizeof (TB640_CAS_CALL_CONTEXT);
OperationLibParams.un32RequestContextMaxCount = TB640_CAS_MAX_CONCURRENT_REQUEST_PER_LIBRARY;
OperationLibParams.un32RequestContextAllocGranularity = TB640_CAS_ALLOCATION_GRANULARITY;
OperationLibParams.pfnUnknowMsgHandler = TB640CasEventMessageHandler;
OperationLibParams.pfnAdapterRemovedHandler = NULL;
OperationLibParams.pvAppContext = TB640_CAS_CREATE_APP_CONTEXT (un32Count, un32Count2);
OperationLibParams.pfnErrorPrint = TB640CasAsyncLibErrorPrint;
/* Add one custom filter to async lib */
if (un32Count2 == 0)
{
if (g_AppContext->fTestModeActivated)
{
/* Add one custom filter to async lib */
OperationLibParams.un32NbCustomFilters = 3;
OperationLibParams.paCustomFilters = AsyncLibCustomFilter;
AsyncLibCustomFilter[0].un32StructVersion = 1;
AsyncLibCustomFilter[0].FilterMask = TBX_FILTER_MSG_ID | TBX_FILTER_ADAPTER_HANDLE;
AsyncLibCustomFilter[0].MsgId = TB640_MSG_ID_ADAPTER_NOTIF_CPU_REPORT;
AsyncLibCustomFilter[0].hAdapter = pAdapterInfo->hAdapter;
AsyncLibCustomFilter[1].un32StructVersion = 1;
AsyncLibCustomFilter[1].FilterMask = (TBX_FILTER_MSG_TYPE | TBX_FILTER_MSG_GROUP);
AsyncLibCustomFilter[1].MsgGroup = TBX_TESTLIB_MSG_GROUP;
AsyncLibCustomFilter[1].MsgTypeMask = (TBX_MSG_TYPE_REQUEST | TBX_MSG_TYPE_EVENT);
AsyncLibCustomFilter[2].un32StructVersion = 1;
AsyncLibCustomFilter[2].FilterMask = TBX_FILTER_MSG_GROUP;
AsyncLibCustomFilter[2].MsgGroup = TBX_ID_CLASS_TBX_API;
}
else
{
/* Add one custom filter to async lib */
OperationLibParams.un32NbCustomFilters = 1;
OperationLibParams.paCustomFilters = AsyncLibCustomFilter;
AsyncLibCustomFilter[0].un32StructVersion = 1;
AsyncLibCustomFilter[0].FilterMask = TBX_FILTER_MSG_ID | TBX_FILTER_ADAPTER_HANDLE;
AsyncLibCustomFilter[0].MsgId = TB640_MSG_ID_ADAPTER_NOTIF_CPU_REPORT;
AsyncLibCustomFilter[0].hAdapter = pAdapterInfo->hAdapter;
}
}
/* Configure the unique ID (taken from the configuration file */
// pAdapterInfo->aun64UniqueId [un32Count2] = g_AppContext->un64AppUniqueId + (TBX_UINT64)un32Count2;
/* Open the library */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -