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

📄 gatemain.c

📁 ipt网关源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/**********************************************************************************************
* 
* $ProjectName: X:\SIPROJ\VOIP\HOST\WIN_NT\DEMOS\VOIPGATE\PROJECT.PJ $
* $ProjectRevision: 1.1 $
* $Label$
* $Revision: 1.5 $ - $Date: 1997/07/14 14:53:35 $
* 
**********************************************************************************************/

#define  _GATEMAIN_C     
        
#include <conio.h>

#include <Dm3Tsc.h>
#include <NTSCClst.h>
#include "NTSCClsH.h"	
#include "Dm3NTscH.h"
#include "GateStrc.h"             
#include "gateDefs.h"		
#include "gateVars.h"
#include "GateDbg.h"
#include "PstnFP.h"             
#include "main.h"             
#include "parsFP.h"
#include "statFP.h"
#include "time.h"

//数据库头文件
#include "database.h"

char     cfgFile[80];      /* file name for configuration file */
HANDLE   hIOCP;            /* handle for IO Completion port */
FILE    *ChanInfoFile;     /* file for printing all channels information */


/*****FUNCTION***************************************************
*        NAME : getChannel
* DESCRIPTION : Gets the active channel to send message to
*       INPUT : None  
*      OUTPUT : None
*     RETURNS : int - Channel number
*    CAUTIONS : None
****************************************************************/
int getChannel()
{
   char  ch;
   char  channel[80];
   int   count = 0;
   BOOL  bCorrectInput = TRUE;
   char  temp[80];

   printf("activeChannel = %d.\n",activeChannel);
   printf("Would you like to change the active channel?(y-YES,n-NO)\n");
   scanf("%c",&ch);
   fflush(stdin);

    switch(ch) {
      
      /* The user would like to change the active channel */
		case 'y':         
		case 'Y':
			printf("Enter the active channel you want.\n");
			scanf("%s",channel);
			fflush(stdin);
			while(bCorrectInput) {
				if( (channel[count] < '0') || (channel[count] > '9') ) {	
				   bCorrectInput = FALSE;
				}
				else {
				   count++;
				}
			}

			if(count > 0) {
				strncpy(temp,channel, count);
				return(atoi(temp));
			}
			break;
		
      /* The user wouldn't like to change the active channel, 
         default is activeChannel = the last channel which entered connected state  */
      case'n':
	   case'N':
	   default:
			break;
	}

	return(activeChannel);

} /* Function getChannel */


/*****FUNCTION***************************************************
*        NAME : waitForKey
* DESCRIPTION : Thread waiting for key: q , ctrl+c to end application
*                                       u - to send user input indication
*                                       n - to send non standard command
*                                       c - get channel information
*                                       f - send Q931 Facility information
*       INPUT : None
*      OUTPUT : None
*     RETURNS : DWORD '0' - success
*    CAUTIONS : getch() func disable detection of 
*               interrupts from the keyboard
****************************************************************/
DWORD waitForKey()			// Separate Thread function.
{                 

   char        ch;
   USHORT      channel = 0;
   OVERLAPPED  Overlapped;

   while(!quitFlag) {	 /* quitFlag is a global variable which indicates that 
                            the user wants to end the application */
      ch = getch();
      
      switch(ch) {
         case 'u':
         case 'U':
            channel = getChannel();
            /* Check if valid channel value */ 
   			if( (channel <= 0)  || (channel > gateChannels) ) {
   				break;
			   }

            /* Sends UII only in GATE_WAIT_DISCONNECT state */
            if(Session[channel].sessionState == GATE_WAIT_DISCONNECT) {
				    activeChannel = channel;
                if(Dm3NTscUII( &(Session[channel].NetTscComp),
                                Session[channel].ConfigFileParm.UII.Val,
            	                (UInt16)(strlen(Session[channel].ConfigFileParm.UII.Val) +1)) == DM3FAIL ) {
                   gateFATAL(channel,(Session[channel].LogFile,"Unable to send User Input Indication on channel %d.\n", channel));
                }
            }
            else {
                gateERROR(channel,(Session[channel].LogFile,"Unable to send user input indication, channel is not in connected state.\n"));
            }
            break;
   
         case 'n':
         case 'N':
            channel = getChannel();
            /* Check if valid channel value */ 
   			if( (channel <= 0)  || (channel > gateChannels) ) {
   				break;
			   }

            /* Sends NonStdCmd only in GATE_WAIT_DISCONNECT state */
            if(Session[channel].sessionState == GATE_WAIT_DISCONNECT) {
				    activeChannel = channel;
                if(Dm3NTscNonStdCmd(&(Session[channel].NetTscComp),
                                    Session[channel].ConfigFileParm.NonStdCmd.CmdVal,
      		                        (UInt16)(strlen(Session[channel].ConfigFileParm.NonStdCmd.CmdVal)+1)) == DM3FAIL ) {
                   gateFATAL(channel,(Session[channel].LogFile,"Unable to send Non Standard Cmd on channel %d.\n", channel));
                }
            }
            else {
               gateERROR(channel,(Session[channel].LogFile,"Unable to send non standard cmd, channel is not in connected state.\n"));
            }
            break;

         case 'c':
         case 'C':
			 printChanInfo();
            break;

			
		   case 3:                /* The ascii code of Ctrl+c */
         case 'q':
         case 'Q':
            quitFlag = TRUE;

			/*close the connection to Sybase SQL server*/
		     dbexit();

             /* Post END_KEY to IO completion port to end application */
   		    if(PostQueuedCompletionStatus(hIOCP,
                                           1,
                                           END_KEY,
                                           &Overlapped) == FALSE) {
   			   printf("Last error in PostQueuedCompletionStatus %s.\n", gateErrorString());
			      exit(0);
   		    }
            break;
      }

   }

   /* Exit thread */
   return(0);

} /* Function waitForKey */


/*****FUNCTION***************************************************
*        NAME : printChanInfo
* DESCRIPTION : Prints channel information
*       INPUT : void
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void printChanInfo()
{
	USHORT  index;
	char    fileName[10];
    char  tmpbuf[128];
	CHANInfo  total;

    strcpy(fileName,"ChanInfo.txt");
    if((ChanInfoFile = fopen(fileName, "a")) == NULL) {
	  printf("%s","Unable to open log file to print information.\n");
	  return;
    }
    
    fprintf(ChanInfoFile,"\n\n");
    _strdate(tmpbuf);
    fprintf(ChanInfoFile,"DATE: %s ",tmpbuf);
    _strtime(tmpbuf);
    fprintf( ChanInfoFile,"TIME: %s\n", tmpbuf );

	fprintf(ChanInfoFile,"%s","SessId SessSt InstId OnH OffH Made Offer Connect Drop Idle Null Fail Reject.\n");
	fflush(ChanInfoFile);
	for(index = 1; index <=gateChannels; index++) {
	     fprintf(ChanInfoFile,"%4d %6d %6d %4d %4d %4d %4d %6d %5d %4d %4d %4d %5d.\n",
			      index,
				  Session[index].sessionState,
				  Session[index].NetTscComp.dm3tsc.theComp.qcdFwAddr.instance,
				  chanInfo[index].on_hook,
				  chanInfo[index].off_hook,
				  chanInfo[index].callsMade,
				  chanInfo[index].callsOffered,
				  chanInfo[index].callsConnected,
				  chanInfo[index].callsDropped,
		          chanInfo[index].callsIdle,
				  chanInfo[index].callsNull,
				  chanInfo[index].callsFailed,
				  chanInfo[index].callsRejected);
		fflush(ChanInfoFile);
	}

	ZeroMemory(&total, sizeof(CHANInfo));

	for(index = 1; index <= gateChannels; index++) {
		  total.on_hook += chanInfo[index].on_hook;
		  total.off_hook += chanInfo[index].off_hook;
		  total.callsMade += chanInfo[index].callsMade;
		  total.callsOffered += chanInfo[index].callsOffered;
		  total.callsConnected += chanInfo[index].callsConnected;
		  total.callsDropped += chanInfo[index].callsDropped;
		  total.callsIdle += chanInfo[index].callsIdle;
		  total.callsNull += chanInfo[index].callsNull;
		  total.callsFailed += chanInfo[index].callsFailed;
		  total.callsRejected += chanInfo[index].callsRejected;
	}

	fprintf(ChanInfoFile,"TOTAL %16d %4d %4d %4d %6d %5d %4d %4d %4d %5d.\n",
				  total.on_hook,
				  total.off_hook,
				  total.callsMade,
				  total.callsOffered,
				  total.callsConnected,
				  total.callsDropped,
		          total.callsIdle,
				  total.callsNull,
				  total.callsFailed,
				  total.callsRejected);
	fflush(ChanInfoFile);

	fclose(ChanInfoFile);
}


/*****FUNCTION***************************************************
*        NAME : banner
* DESCRIPTION : Prints program banner
*       INPUT : void
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void banner(void)
{
   printf("%s %s %s %s %s",
	         "----------------------------------------------------------\n",
            "     CamelDemo --- Voice over IP Gateway Demo Program\n",
            "              Version 1.00 Release 2.04\n",
            "            Copyright (c) 1998, Dialogic Corp\n",
            "----------------------------------------------------------\n");

} /* Function banner */


/*****FUNCTION***************************************************
*        NAME : usage
* DESCRIPTION : Command line option ? for help
*       INPUT : None
*      OUTPUT : Prints help text
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void usage()
{

   banner();
   printf("Usage:\n\tIPTGATE [-f<Front End>] [-b<IPTBoard>] [-e<Encoding type>][-l] \n");
   printf("\t\t [-r<[NumRings>] [-n<gateChannels>] [-c<cfgFile>] [-d<Debug Level>]\n\n");
   printf("Front End : 0 (ANALOG), 1 (DIGITAL - T1), 2 (DIGITAL - E1) ; (default = ANALOG) \n");
   printf("IPTBoard  : 0,1,2..etc. (default = 0) \n");
   printf("-l enables log file printing for each channel: ChanXX.txt.\n");
   printf("NumRings  : 1,2,3..etc. (ONLY IF FRONT END IS ANALOG, default = %d)\n",GATE_RINGS);
   printf("Debug level : 0 - no printings ... 6 - all printings (default = 6)\n");
   printf("gateChannels : (default minimum of NetTSC instances and pstn channels)\n");
   printf("Encoding type 'm'(Mu-law) or 'a'(A-law) (default = Mu-law).\n");
   printf("cfgFile : File containing info. about codecs, # to call, etc (default %s).\n\n", GATE_CONFIG_FILE);
   _exit(0);

} /* Function usage */


/*****FUNCTION***************************************************
*        NAME : checkArg
* DESCRIPTION : Checks arguments from command line
*       INPUT : int argc
*               char *argv[]
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void checkArg(int argc, char *argv[])

{
   
   int   ii;

   /* Defaults */
   frontEnd		= GATE_LEGACY_ANALOG;		 
   gateChannels = 0;
   strcpy(cfgFile, GATE_CONFIG_FILE);
   IPTBoardNumber = 0;

   /* parse command line  */
  	for (ii = 1; ii < argc; ii++) {
		if (*argv[ii] != '-') {
			continue;
		}

		switch(tolower(*(argv[ii]+1))) {

			/* Front End */
			case 'f':
				frontEnd = atoi(argv[ii]+2);
				if(frontEnd == 1) {
					numtslots = 24;
				}
				if(frontEnd == 2) {
					numtslots = 30;
				}

				break;

			/* board number of IPT */
			case 'b':
				IPTBoardNumber = atoi(argv[ii]+2);
				break;

			/* Number of rings */
			case 'r':
				numRings = atoi(argv[ii]+2);
				break;

			/* Max Channels to use */
			case 'n':
				gateChannels = atoi(argv[ii]+2);
				break;

			/* Configuration filename */

⌨️ 快捷键说明

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