📄 gatemain.c
字号:
(UCHAR)BoardId,
(UCHAR)SessionId,
NULL,
(DM3COMPCALLBACK) NETTSCClusterEvtHndlr,
NULL,
NULL,
0) != DM3SUCCESS) {
gateTRACE(SessionId,(Session[SessionId].LogFile,"ERROR:Getting cluster for TSC %d failed\n",
SessionId));
rBool = FALSE;
SessionId--;
continue;
}
if((pClusterDesc->lastEvent != NETTSCCLUSTEREVENT_INITCMPLT) ||
(pClusterDesc->dwErrorCode != NO_ERROR)) {
gateTRACE(SessionId,(Session[SessionId].LogFile,"ERROR:Getting cluster for TSC %d failed\n",
SessionId));
rBool = FALSE;
SessionId--;
continue;
}
/* Get cluster's components (NetTSC component instances) */
if (NETTSCClusterGetAllComps(pClusterDesc) != DM3SUCCESS) {
gateTRACE(SessionId,(Session[SessionId].LogFile,"ERROR:Getting cluster components for TSC %d failed\n",
SessionId));
rBool = FALSE;
SessionId--;
continue;
}
if((pClusterDesc->lastEvent != NETTSCCLUSTEREVENT_GETALLCOMPSCMPLT) ||
(pClusterDesc->dwErrorCode != NO_ERROR)) {
gateTRACE(SessionId,(Session[SessionId].LogFile,"ERROR:Getting cluster components for TSC %d failed\n",
SessionId));
rBool = FALSE;
SessionId--;
continue;
}
/* Get Cluster Transmit Time Slot
(which were terminated in the IPTSlot) */
if(NETTSCClusterGetXmitSlot(pClusterDesc) != DM3SUCCESS) {
gateTRACE(SessionId,(Session[SessionId].LogFile,"ERROR: Getting TxTimeSlot for TSC cluster %d\n", SessionId));
rBool = FALSE;
SessionId--;
continue;
}
if((pClusterDesc->lastEvent != NETTSCCLUSTEREVENT_GETXMITSLOTCMPLT) ||
(pClusterDesc->dwErrorCode != NO_ERROR)) {
gateTRACE(SessionId,(Session[SessionId].LogFile,"ERROR: Getting TxTimeSlot for TSC cluster %d\n", SessionId));
rBool = FALSE;
SessionId--;
continue;
}
} /* end of while */
*pNumNetTSC = SessionId; /* Number of IPT clusters */
return(DM3SUCCESS);
} /* Function ClusterInit */
/*****FUNCTION***************************************************
* NAME : NetTSCCompInit
* DESCRIPTION : Initialize IPT component, Set async parameters
* and enable list of events.
* INPUT : None
* OUTPUT : None
* RETURNS : Success or fail
* CAUTIONS : None
****************************************************************/
USHORT NetTSCCompInit()
{
USHORT index = 1;
UINT offset = 0;
LPDM3TSC lpDm3Tsc;
while(index <= gateChannels) {
lpDm3Tsc = NETTSC_GET_DM3TSC((&(Session[index].NetTscComp)));
/* Initialize the NetTSC framework component structure */
if ( Dm3NetTscInit(&(Session[index].NetTscComp),
Session[index].NetTscClust.qcdTsc,
Dm3NetTscEvtHndlr,
(LPVOID)(&Session[index])) == DM3FAIL ) {
gateFATAL(index,(Session[index].LogFile,"NetTSC component init failed for NetTSC #%d\n",index));
return(DM3FAIL);
}
/* Enable Async mode by giving an IOCP and completion key for each
NetTSC instance ( 1 per channel ) */
if ( Dm3CompSetAsyncParams(&(lpDm3Tsc->theComp),
hIOCP, DM3_IPT_KEY) == DM3FAIL ) {
gateFATAL(index,(Session[index].LogFile,"NetTSC component Set Async params failed for NetTSC #%d\n",index));
return(DM3FAIL);
}
/* Enable asynchronous mode of operation (NON_BLOCKING)
from now on all functions are async. function calls */
if ( Dm3CompEnableAsyncMode(&(lpDm3Tsc->theComp),
MNT_DEFAULT_TIMEOUT) == DM3FAIL ) {
gateFATAL(index,(Session[index].LogFile,"NetTSC comp enable async mode fail for NetTSC #%d\n",index));
return(DM3FAIL);
}
/* Enable list of events for each NetTsc instance */
if ( IPTEnableAllEvts(lpDm3Tsc) == DM3FAIL ) {
gateFATAL(index,(Session[index].LogFile,"Unable to detect all events for channel %d.\n", index));
return(DM3FAIL);
}
index++;
}
return(DM3SUCCESS);
} /* Function NetTSCCompInit */
/*****FUNCTION***************************************************
* NAME : IPTCloseNetTSC
* DESCRIPTION : Closes NetTSC instances
* INPUT : USHORT rc
* USHORT channels
* OUTPUT : None
* RETURNS : Success or fail
* CAUTIONS : None
****************************************************************/
BOOL IPTCloseNetTSC(USHORT rc,
USHORT channel)
{
USHORT ii;
/* Close all channels */
if(channel == ALL_CHANNELS) {
for(ii=1;ii <= gateChannels;ii++) {
if(Session[ii].NetTscComp.dm3tsc.fBusy == FALSE) {
if((closeDM3Channel(rc,ii)) == DM3FAIL) {
gateFATAL(ii,(Session[ii].LogFile,"Unable to close channel %d.\n",ii));
return(DM3FAIL);
}
}
}
}
else
{
/* Close specific channel */
if(Session[channel].NetTscComp.dm3tsc.fBusy == FALSE) {
if((closeDM3Channel(rc,channel)) == DM3FAIL) {
gateFATAL(channel,(Session[channel].LogFile,"Unable to close channel %d.\n",channel));
return(DM3FAIL);
}
}
fclose(Session[channel].LogFile);
}
return (DM3SUCCESS);
} /* Function IPTCloseNetTSC */
/*****FUNCTION***************************************************
* NAME : gateRoute
* DESCRIPTION : Routes DM3 to D/xx and D/xx to DM3
* INPUT : USHORT channel - Channel to route
* OUTPUT : None
* RETURNS : Success or fail
* CAUTIONS : None
****************************************************************/
BOOL gateRoute(USHORT channel)
{
UINT timeslot;
BOOL rBool;
/***
** Route D/xx to DM3
*/
/* Get DM3 transmit time slot for this channel */
timeslot = Session[channel].NetTscClust.unTxTimeSlot;
if( (timeslot < 0) || (timeslot > 1023) ) {
gateFATAL(channel,(Session[channel].LogFile,"Invalid DM3 timeslot number.\n"));
return(DM3FAIL);
}
/* Have D/xx channel listen to it */
rBool = pstnListen(channel,timeslot);
if(rBool != DM3SUCCESS) {
gateERROR(channel,(Session[channel].LogFile,"D/xx can't listen to DM3.\n"));
return(DM3FAIL);
}
/***
** Route DM3 to D/xx
*/
/* Get D/xx transmit time slot for this channel */
rBool = pstnGetXMitSlot(channel,×lot);
if(rBool != DM3SUCCESS) {
gateFATAL(channel,(Session[channel].LogFile,"Unable to get D/xx transmit TS.\n"));
return(DM3FAIL);
}
/* Have DM3 channel listen to it */
rBool = NETTSCClusterListen(&(Session[channel].NetTscClust),
(USHORT)timeslot);
if(rBool != DM3SUCCESS) {
gateFATAL(channel,(Session[channel].LogFile,"DM3 can't listen to D/xx.\n"));
return(DM3FAIL);
}
return(rBool);
} /* Function gateRoute */
/*****FUNCTION***************************************************
* NAME : gateUnRoute
* DESCRIPTION : Make DM3 Unlisten to D/xx (Deactivate and Unassign),
* D/xx Unlisten to DM3.
* INPUT : USHORT channel
* OUTPUT : None
* RETURNS : void
* CAUTIONS : None
****************************************************************/
void gateUnRoute(USHORT channel)
{
BOOL rBool;
/* Get DM3 unlisten */
if (NETTSCClusterUnlisten(&(Session[channel].NetTscClust)) == DM3FAIL) {
gateFATAL(channel,(Session[channel].LogFile,"\tIPT UN-Listen FAIL %s.\n",gateErrorString()));
}
/* Have D/xx channel unlisten to DM3
and relisten to original (frontEnd to voice) */
rBool = pstnUnListen(channel);
if(rBool!=DM3SUCCESS) {
gateFATAL(channel,(Session[channel].LogFile,"\tPSTN UnListen failed on channel %d\n",channel));
}
} /* Function Unlisten */
/*****FUNCTION***************************************************
* NAME : closeDM3Channel
* DESCRIPTION : Closes an active channel
* Disable events and free allocated cluster
* INPUT : USHORT rc
* USHORT channel
* OUTPUT : None
* RETURNS : Success or fail
* CAUTIONS : None
****************************************************************/
BOOL closeDM3Channel(USHORT rc,USHORT channel)
{
LPDM3TSC lpTsc;
LPDM3COMP lpNetTscComp;
USHORT count = NUM_EVENTS;
lpTsc = NETTSC_GET_DM3TSC((&(Session[channel].NetTscComp)));
lpNetTscComp = NETTSC_GET_DM3COMP((&(Session[channel].NetTscComp)));
/* Disable events on this channel */
if(rc != OPEN_ERROR) {
if( IPTDisableAllEvts(lpTsc) == DM3FAIL ) {
gateFATAL(channel,(Session[channel].LogFile,"\tDM3 NetTSCCancelEvts FAIL.\n"));
return(DM3FAIL);
}
}
/* Cleans component structure */
if ( Dm3CompCleanup(&(lpTsc->theComp)) == DM3FAIL ) {
gateFATAL(channel,(Session[channel].LogFile,"\tDM3 COMP CLEANUP FAIL for channel %d.\n",channel));
return(DM3FAIL);
}
/* Free the cluster */
if( NETTSCClusterRelease(&(Session[channel].NetTscClust)) == DM3FAIL ) {
gateFATAL(channel,(Session[channel].LogFile,"\tIPT Cluster Release FAIL %s.\n",gateErrorString()));
return(DM3FAIL);
}
Session[channel].NetTscComp.dm3tsc.fBusy = FALSE;
if(rc == CHAN_OUT_OF_SERVICE) {
Session[channel].NetTscComp.fIsInService = FALSE;
}
return(DM3SUCCESS);
} /* Function closeChannel */
/*****FUNCTION***************************************************
* NAME : allChannelsNotActive
* DESCRIPTION : Checks if all available channels in the system are
* not active
* INPUT : None
* OUTPUT : None
* RETURNS : DM3SUCCESS - all channels not active,
* DM3FAIL - at least one channel is active
* CAUTIONS : None
****************************************************************/
BOOL allChannelsNotActive()
{
USHORT channel=1;
while(channel <= gateChannels) {
if(Session[channel].NetTscComp.fIsInService == TRUE) {
return(DM3FAIL);
}
channel++;
}
return(DM3SUCCESS);
} /* Function allChannelsNotActive */
/*****FUNCTION***************************************************
* NAME : gateExit
* DESCRIPTION : Exit one or more channels
* INPUT : USHORT rc - Exit code
* USHORT channel - hannel number or ALL_CHANNELS
* OUTPUT : None
* RETURNS : void
* CAUTIONS : None
****************************************************************/
void gateExit(USHORT rc, USHORT channel)
{
USHORT index;
IPTCloseNetTSC(rc, channel);
if ( (rc == CHAN_OUT_OF_SERVICE) && (allChannelsNotActive() == DM3SUCCESS)) {
pstnCloseFrontEnd(gateChannels);
printf("\tIPTGate is exiting with exit code (0x%lx)!\n",rc);
for(index = 0; index <=gateChannels; index++) {
fclose(Session[index].LogFile);
}
exit(rc);
}
if (rc == NO_ERROR) {
pstnCloseFrontEnd(gateChannels);
}
if (channel == ALL_CHANNELS) {
for(index = 0; index <=gateChannels; index++) {
fclose(Session[index].LogFile);
}
exit(rc);
}
} /* Function gateExit */
/*****FUNCTION***************************************************
* NAME : getGateChannels
* DESCRIPTION : Gets the gateChannels number to be the minimum
* of PSTN channels and available IPT clusters
* INPUT : None
* OUTPUT : None
* RETURNS : void
* CAUTIONS : None
****************************************************************/
void getGateChannels()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -