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

📄 gatemain.c

📁 dialogic voip 测试代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	   strcpy(Session[ch].ConfigFileParm.versionID,"\0");
       ZeroMemory(&(Session[ch].ConfigFileParm.Coder),sizeof(IP_CAPABILITY));
	   strcpy(Session[ch].ConfigFileParm.srcAddr,"\0");
       strcpy(Session[ch].ConfigFileParm.destAddr,"\0");
       Session[ch].ConfigFileParm.callDurationTime = 0;               
       ZeroMemory(&(Session[ch].ConfigFileParm.RTCPInfo),sizeof(IP_RTCPINFO));/* default */

	   ZeroMemory(&(Session[ch].ConfigFileParm.UII),sizeof(H245Data));

	   ZeroMemory(&(Session[ch].ConfigFileParm.NonStdCmd),sizeof(H245Data));

	   ZeroMemory(&(Session[ch].ConfigFileParm.Q931Facility),sizeof(Q931Data));

	   strcpy(Session[ch].ConfigFileParm.IPT_UUI,"\0");

	   

       /* Reset CHANInfo IP parameters */

	   chanInfoIP[ch].callsMake = 0;
	   chanInfoIP[ch].callsOffered = 0;
	   chanInfoIP[ch].callsConnected = 0;
	   chanInfoIP[ch].callsNull = 0;
	   chanInfoIP[ch].callsFailed = 0;
	   chanInfoIP[ch].callsRejected = 0;

	   chanInfoIP[ch].NonStdCmd_Msg = 0;

	   chanInfoIP[ch].NonStdCmd_Evt = 0;

	   chanInfoIP[ch].UII_Msg = 0;

	   chanInfoIP[ch].UII_Evt = 0;

	   chanInfoIP[ch].Q931Facility_Msg = 0;

	   chanInfoIP[ch].Q931Facility_Evt = 0;

	   
	   /* Reset CHANInfo PSTN parameters */

	   chanInfoPSTN[ch].callsMake = 0;
	   chanInfoPSTN[ch].callsOffered = 0;
	   chanInfoPSTN[ch].callsConnected = 0;
	   chanInfoPSTN[ch].callsNull = 0;
	   chanInfoPSTN[ch].callsFailed = 0;
	   chanInfoPSTN[ch].callsRejected = 0;

	   chanInfoPSTN[ch].NonStdCmd_Msg = 0;

	   chanInfoPSTN[ch].NonStdCmd_Evt = 0;

	   chanInfoPSTN[ch].UII_Msg = 0;

	   chanInfoPSTN[ch].UII_Evt = 0;

	   chanInfoPSTN[ch].Q931Facility_Msg = 0;

	   chanInfoPSTN[ch].Q931Facility_Evt = 0;

	   



	   
   }

} /* Function IPTResetSession */



/*****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(unsigned int pstnChannels, unsigned int iptChannels)  
{
	
   /* Set gateChannels to minimum available channels */
   gateChannels = (pstnChannels <= iptChannels) ? pstnChannels : iptChannels;
   if ((argChannels > 0 ) && (argChannels < gateChannels)){
	   gateChannels = argChannels;
   }
   printf("\n ==> %d channels were initialized\n\n",gateChannels);   
} /* Function getGateChannels */



/*****FUNCTION***************************************************
*        NAME : printConfiguration
* DESCRIPTION : Print information from confoguration file
*       INPUT : None
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void printConfiguration()     
{
	unsigned int index;
	unsigned short coderCount;
	

   /* Print out the configuration information */
   for(index = 1; index <= gateChannels; index++) {





	   /* check the UII string length , Max length is 99 bytes */

	   if(strlen(Session[index].ConfigFileParm.UII.Val) > 99) {

		   gateERROR(index,_logLevel,Session[index].LogFile, (Session[index].LogFile, "UII string is too long, can be max 99 bytes.\n"));

		   strncpy(Session[index].ConfigFileParm.UII.Val,Session[index].ConfigFileParm.UII.Val,99);

	   }



	   /* check the Nonstandard string length , Max length is 99 bytes */

	   if(strlen(Session[index].ConfigFileParm.NonStdCmd.Val) > 99) {

		   gateERROR(index,_logLevel,Session[index].LogFile, (Session[index].LogFile, "Non Std Cmd string is too long, can be max 99 bytes.\n"));

		   strncpy(Session[index].ConfigFileParm.NonStdCmd.Val,Session[index].ConfigFileParm.NonStdCmd.Val,99);

	   }

       printf("Session %d: Source %s\n\t Destination %s\n\t PhoneList %s\n\t LocalPhoneNumber %s\n\t",
                index,
                Session[index].ConfigFileParm.srcAddr,
                Session[index].ConfigFileParm.destAddr,
                Session[index].ConfigFileParm.phoneList,
                Session[index].ConfigFileParm.localPhoneNumber);

       for(coderCount = 0; coderCount < Session[index].ConfigFileParm.maxTxCoders; coderCount++) {
		   printf(" Coder[%d]\n\t\t Capability %d\n\t\t Payload_type %d\n\t\t FramesPerPacket %d\n\t\t VAD %d \n\t",
			       coderCount,
                Session[index].ConfigFileParm.Coder[coderCount].capability,
                Session[index].ConfigFileParm.Coder[coderCount].payload_type,
                Session[index].ConfigFileParm.Coder[coderCount].extra.audio.frames_per_pkt,
                Session[index].ConfigFileParm.Coder[coderCount].extra.audio.VAD);
	   }

       printf(" Display %s\n\t UII %s\n\t UUI %s\n\t NonStdCmd %s\n\t Q931Facility%s\n\t ObjectId %s\n\n",
                Session[index].ConfigFileParm.display,

				Session[index].ConfigFileParm.UII.Val,
                Session[index].ConfigFileParm.IPT_UUI,

				Session[index].ConfigFileParm.NonStdCmd.Val,

				Session[index].ConfigFileParm.Q931Facility.Data,

				Session[index].ConfigFileParm.Q931Facility.ObjId);

	   

	       
   }
}

/*****FUNCTION***************************************************
*        NAME : ApplicationExit
* DESCRIPTION : Closes PSTN and IP resources and log files
*       INPUT : None
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void ApplicationExit()
{
	unsigned int      channel;
 
	for ( channel = 1; channel <= gateChannels; channel++) {
			if (closeChannel(channel) == FUNCFAIL){
				gateERROR(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\t Failed to close channel %d\n",channel));
			}
			if((int)Session[channel].LogFile == 1){
			    PDLcloseLogFile(Session[channel].LogFile);
			}
		}
	        exit(0);
}

/*****FUNCTION***************************************************
*        NAME : fallback_hdlr
* DESCRIPTION : The fallback handler for all events
*       INPUT : parm
*      OUTPUT : return value
*     RETURNS : 
*    CAUTIONS : None
****************************************************************/
long fallback_hdlr()
{
	GateSession *lpSession;
	METAEVENT   metaevt;


	
	/* Find out the event received */
	if (gc_GetMetaEvent(&metaevt)<0) {
	      printf("%s"," ***** Error: gc_GetMetaEvent failed *****\n");
	      return(-1); 
	}
	
	if (metaevt.evttype == CTRL_CLOSE_EVENT){
		ApplicationExit();
	}

	if (gc_GetUsrAttr(metaevt.evtdev,&lpSession) < 0){
          printf("%s"," ***** Error: gc_GetUsrAttr failed *****\n");
	      return(-1); 
	} 

	
	if (metaevt.evtdev == lpSession->ipParams.linedev){

		/* Get the IP event */
		ipGetEvent(&metaevt,lpSession->sessionNumber);

	}

	else if ((metaevt.evtdev == lpSession->pstnParams.linedev) || (metaevt.evtdev == lpSession->pstnParams.VoiceH)
		    || (metaevt.evtdev == lpSession->pstnParams.NetwH)){
		
		/* Get the IP event */
        pstnGetEvent(&metaevt,lpSession->sessionNumber);
	}
	else
		gateERROR(lpSession->sessionNumber,_logLevel,lpSession->LogFile,(lpSession->LogFile,"\tGetting invalid handle %d \n",
				metaevt.evtdev));

	return(1);

}  /* Function fallback_hdlr */


/*****FUNCTION***************************************************
*        NAME : closeChannel
* DESCRIPTION : close channel
*       INPUT : channel   -  Channel to close
*      OUTPUT : return value
*     RETURNS : FAIL or SUCCESS
*    CAUTIONS : None
****************************************************************/
int closeChannel(unsigned int channel)
{

   gateTRACE(channel,_logLevel,Session[channel].LogFile, (Session[channel].LogFile,"\t   In closeChannel function on channel %d\n",channel));
	
	if((Session[channel].pstnParams.linedev != 0) && (gc_Close((Session[channel]).pstnParams.linedev) <0)) {
   	   printGCError("gc_Close pstn channels",channel,Session[channel].LogFile,_logLevel); 
	    return (FUNCFAIL); 
	}
	else{
		gateTRACE(channel,_logLevel,Session[channel].LogFile, (Session[channel].LogFile,"\t pstn Line Device was closed on channel %d.\n",channel));
    }
	if((Session[channel].ipParams.linedev != 0) && (gc_Close((Session[channel]).ipParams.linedev) <0)) {
   	    printGCError("gc_Close ip channels",channel,Session[channel].LogFile,_logLevel); 
	    return (FUNCFAIL); 
	}
	else{
		gateTRACE(channel,_logLevel,Session[channel].LogFile, (Session[channel].LogFile,"\t ip Line Device was closed on channel %d.\n",channel));
    }

	gateTRACE(channel,_logLevel,Session[channel].LogFile, (Session[channel].LogFile,"\t   End of closeChannel function on channel %d\n",channel));
   
    return(FUNCSUCCESS);
}

 

/*****FUNCTION***************************************************
*        NAME : gateInitialize
* DESCRIPTION : Initializes the Camel Gateway demo:
*               gets argument from command line,
*               opens NetTSC instances,
*               gets information from configuration file,
*               opens VOX channels.
*       INPUT : int argc 
*               char *argv[]
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void gateInitialize(int argc, 
			     char *argv[])     
{
	
	unsigned int    index;
    unsigned int VOXChannels = 0;
	unsigned int IPChannels = 0;
	
    /*  Checks list of arguments from command line */
    checkArg(argc,argv);

	if (gc_Start(NULL)<0){
	    printf("%s","***** Error: failed in gc_Start *****\n");
	    exit(0);	  
    }

    PDLsr_setparm();
    PDLcreateThread();
    /* Set-up the call-back handler  */
    PDLsr_enbhdlr(fallback_hdlr);

	/* Check number of avialable vox channels */
    if ((VOXChannels = pstnGetVOXChannels()) == 0){
		printf("%s","***** Unable to get number of pstn channels *****\n");
	    exit(0);

    }else{

		printf("\n<<Number of PSTN channels found: %d >>\n",VOXChannels);

    }

	/* Check number of avialable ip channels */
    if ((IPChannels = ipGetChannels()) == 0){
   		printf("%s","***** Unable to to get number of ip channels *****\n");
   	    exit(0);
    }else{

		printf("\n<<Number of IP channels found: %d >>\n",IPChannels);

    }	

	getGateChannels(VOXChannels,IPChannels);


    for(index=1;index<= gateChannels;index++) {
		IPTResetSession(index,1);
	}

    /* Configure the demo */
    if(gateConfiguration(cfgFile) != FUNCSUCCESS) {
		printf("%s","\nError in configuration file\n");
        exit(0);
	}
    
	printConfiguration();


   /* Initialize the front end */
   if( pstnOpenFrontEnd() == FUNCFAIL) {
	   printf("%s","***** Failed to open pstn channels.*****\n");
       exit(0);
   }

   /* Initialize the front end */
   if( ipOpenDevices() == FUNCFAIL) {
	   printf("%s","***** Failed to open ip channels.*****\n");
       exit(0);
   }


   
} /* Function gateInitialize */


/****FUNCTION***************************************************
*        NAME : main
* DESCRIPTION : Our main function 
*               The main loop waiting for events
*       INPUT : int argc      -  Number of arguments from command line
*               char *argv[]  -  Array of arguments from command line
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
int main(int argc, 
		  char *argv[])
{  
   ExitApp = ApplicationExit;
   PDLSetApplicationExitPath(ExitApp);
   /* Print banner titles */
   banner();

   /* General initialization  */
   gateInitialize(argc,argv); 
   
	
   printf ("%s","\n\nWaiting for key:\n\t 'Q' - to quit \n\t 'D' - to change debug level \n\t 'C' - to print channels statistics information \n\t 'U' - to send H.245 User Input Indication messgae\n\t 'N' - to send H.245 Non Standard Command message \n\t 'F' - to send Q931 Facility Information message\n");
   /* spin waiting for keyboard events  */
   while(1) {
	   waitForKey(); 
   } /* while 1 */
   return (0);
} /* Function main */

/*** End of File ***/







⌨️ 快捷键说明

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