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

📄 gatestate.c

📁 dialogic voip 测试代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/**********************************************************************************************
* 
* $ProjectName: X:/SIPROJ/VOIP/HOST/WIN_NT/DEMOS/Samples.rel5/Dm3/Iplink/project.pj $
* $ProjectRevision: 1.5 $
* $Label$
* $Revision: 1.4 $ - $Date: 2001/10/07 16:02:29 $
* 
**********************************************************************************************/

#define  _GATESTATE_C


/* The DEMO H files are needed in this order: */
#include <libdbg.h>
#include "gatepstn.h"    
#include "main.h"            
#include "gatestrc.h"             
#include "gatevars.h"
#include "gateip.h"
#include  <pdl.h>
 

/*****FUNCTION **********************************************
*        NAME : gateUpdate 
* DESCRIPTION : Update Session state and state machine function
*       INPUT : GateSession * pSession   -  Channel to update information 
*               unsigned short newState  -  New state to update channel to
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None.
****************************************************************/
void gateUpdate(GateSession * pSession, 
                unsigned short newState)
{
	pSession->sessionState = newState;
    pSession->stateFxn = gateFunctionList[newState];

} /* Function gateUpdate */


/*****FUNCTION***************************************************
*        NAME : gateInit
* DESCRIPTION : Waiting for  GCEV_UNBLOCKED from both sides, 
*               so the application will be ready to take a call
*       INPUT : unsigned int           channel  -  channel which got the event
*               COMP_KEY       compKey  -  name of the component
*                                          that got the event
*               long         event      -  the recieved event
*  				 void        *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
unsigned short gateInit(unsigned int channel, COMP_KEY compKey, long event,void * EvtData)
{
      
   gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"In GATE_INIT State on channel %d\n\t got Event %s (0x%x) from %s\n", 
             channel,gateEventStr(event), event,gateKeyStr(compKey)));

   switch(event) {

	   /* If GCEV_UNBLOCKED  arrived to IP and PSTN, enuble a call */
	   case GCEV_UNBLOCKED:
		   unblockedFlage[channel]++;
		   if (unblockedFlage[channel] == 2){
			   if (gc_WaitCall((Session[channel]).pstnParams.linedev,NULL,NULL,0,EV_ASYNC) < 0){
				 /* process error  */
	             printGCError("gc_WaitCall",channel,Session[channel].LogFile,_logLevel);
	             return(FUNCFAIL);
			   }
			   if (gc_WaitCall((Session[channel]).ipParams.linedev,NULL,NULL,0,EV_ASYNC) < 0){
				 /* process error */
	             printGCError("gc_WaitCall",channel,Session[channel].LogFile,_logLevel);
	             return(FUNCFAIL);
			   }
			   gateUpdate(&(Session[channel]),GATE_NULL);
		   }

		   break;

	  case GCEV_TASKFAIL:
	  case GCEV_BLOCKED:
	    ApplicationExit();
		break;
      
	  default:
          gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in gateInit from %s\n",
                   gateEventStr(event), event,channel, gateKeyStr(compKey)));
          return(FUNCSUCCESS);
   
   } /* end switch(event) */

   return (FUNCSUCCESS);

} /* End gateInit function. */


/*****FUNCTION***************************************************
*        NAME : gateNull
* DESCRIPTION : The function waits for a call: 
*                    *  If it comes from the ip:
*                                Get call information.
*                    *  If it comes from the phone line:
*                                Send gc_AcceptCall and gc_MakeCall
*       INPUT : unsigned int         channel  -  channel which got the event
*               COMP_KEY       compKey  -  name of the component
*                                          that got the event
*               long         event      -  the recieved event
*  				void        *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
unsigned short gateNull(unsigned int channel, COMP_KEY compKey, long event,void * EvtData)
{
   
   CallParameters  CFGParm;
   GC_PARM_BLKP  gcParmBlk = NULL;
   unsigned short          infoCount;
      
   CFGParm = Session[channel].ConfigFileParm; 


   gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"In GATE_NULL State on channel (0x%x)\n\t got event %s (0x%x) from %s\n", 
             channel,gateEventStr(event), event, gateKeyStr(compKey)));


   /* Switch on event */
   switch(event) {

      case GCEV_DETECTED:
          if ((Session[channel].ipParams.currentCRN > 0) || (Session[channel].ipParams.nextCRN > 0)){
			  /* drop the calls */
			  if (gc_DropCall(Session[channel].pstnParams.currentCRN,
							                       GC_CALL_REJECTED,
												   EV_ASYNC)<0){
				  printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
	              return (FUNCFAIL);  
			  }else{

    		     gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call (currentCRN) to PSTN on channel %d\n", channel));

			  }



			  if (Session[channel].ipParams.nextCRN > 0){
				  Session[channel].ipParams.currentCRN = Session[channel].ipParams.nextCRN;
				  Session[channel].ipParams.nextCRN = 0;
			  }
			  

			  if (gc_DropCall(Session[channel].ipParams.currentCRN,
							                       GC_CALL_REJECTED,
												   EV_ASYNC)<0){
 			      printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
	              return (FUNCFAIL);  
			  }else{

    		     gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call(currentCRN) to IP on channel %d\n", channel));

			  }						  
							  						  						 
			  Session[channel].NumOfDropExpected = 2;
              chanInfoIP[channel].callsRejected++;
			  gateUpdate(&(Session[channel]),GATE_DROP);
		  }				  
          break;

	  case GCEV_TASKFAIL:
		  /* In this case the channel won't be able to make any further calls */ 
		  break;
		  
	  case GCEV_OFFERED:
		  switch (compKey){
			  case IP:
				  {
					  chanInfoIP[channel].callsOffered++;
                      if ((Session[channel].pstnParams.currentCRN > 0) || (Session[channel].pstnParams.nextCRN > 0)){
						  /* pstn have already gotten detected, drop the calls */
					      if (gc_DropCall(Session[channel].ipParams.currentCRN,
							                       GC_CALL_REJECTED,
												   EV_ASYNC)<0){
							  printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
	                          return (FUNCFAIL);  
						  }else{

							  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call(currentCRN) to IP on channel %d\n", channel));

						  }

						  if (Session[channel].pstnParams.nextCRN > 0){
							  Session[channel].pstnParams.currentCRN = Session[channel].pstnParams.nextCRN;
							  Session[channel].pstnParams.nextCRN = 0;
						  }

						  if (gc_DropCall(Session[channel].pstnParams.currentCRN,
							                       GC_CALL_REJECTED,
												   EV_ASYNC)<0){
							     printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
	                             return (FUNCFAIL);  
						  }else{

							  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call(currentCRN) to PSTN on channel %d\n", channel));

						  }						  
							  						  						 
						  Session[channel].NumOfDropExpected = 2;
                          chanInfoIP[channel].callsRejected++;
					      gateUpdate(&(Session[channel]),GATE_DROP);
					  }				  
				      else{

						  if (gc_util_insert_parm_val(&gcParmBlk,IPSET_CALLINFO, IPPARM_DISPLAY,
	                        	sizeof(int),1) < 0){
							  printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel); 
		
						  }



						  if (gc_util_insert_parm_val(&gcParmBlk,IPSET_CALLINFO, IPPARM_USERUSER_INFO,

	                            sizeof(int),1) < 0){

							  printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel); 

						  }

						  if (gc_util_insert_parm_val(&gcParmBlk,IPSET_CALLINFO, IPPARM_PHONELIST,
	                            sizeof(int),1) < 0){
							  printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel); 
						  }

						  if (gc_util_insert_parm_val(&gcParmBlk,IPSET_VENDORINFO, IPPARM_H221NONSTD,
	                        	sizeof(int),1) < 0){
							  printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel); 
						  }

						  if (gc_util_insert_parm_val(&gcParmBlk,IPSET_VENDORINFO, IPPARM_VENDOR_PRODUCT_ID,
	                            sizeof(int),1) < 0){

							  printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel); 
						  }

						  if (gc_util_insert_parm_val(&gcParmBlk,IPSET_VENDORINFO, IPPARM_VENDOR_VERSION_ID,
	                        	sizeof(int),1) < 0){
							  printGCError("gc_util_insert_parm_val",channel,Session[channel].LogFile,_logLevel); 
						  }

						

						  
							  
						  /* send a gc_Extension message instead of GetCallInfo */
						  if (gc_Extension(GCTGT_GCLIB_CRN,Session[channel].ipParams.currentCRN,
							                                   IPEXTID_GETINFO,
															   gcParmBlk,
															   NULL,
															   EV_ASYNC)<0){
							  printGCError("gc_Extention",channel,Session[channel].LogFile,_logLevel); 
	                          return (FUNCFAIL);  
						  }else{

							  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"gc_Extension was called instead of GetCallInfo on channel %d\n", channel));

						  }


						  gc_util_delete_parm_blk(gcParmBlk);
	
						  gateUpdate(&(Session[channel]),IP_OFFERED);
					  }
				  }
				  break;
    		  case PSTN:
				  {
					  if ((Session[channel].ipParams.currentCRN > 0) || (Session[channel].ipParams.nextCRN > 0)){
						  /* drop the calls */
					      if (gc_DropCall(Session[channel].pstnParams.currentCRN,
							                       GC_CALL_REJECTED,
												   EV_ASYNC)<0){
							  printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
	                          return (FUNCFAIL);  
						  }else{

							  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call(currentCRN) to PSTN on channel %d\n", channel));

						  }	

						  if (Session[channel].ipParams.nextCRN > 0){
							  Session[channel].ipParams.currentCRN = Session[channel].ipParams.nextCRN;
							  Session[channel].ipParams.nextCRN = 0;
						  }

						  if (gc_DropCall(Session[channel].ipParams.currentCRN,
							                       GC_CALL_REJECTED,
												   EV_ASYNC)<0){
							     printGCError("gc_DropCall",channel,Session[channel].LogFile,_logLevel); 
	                             return (FUNCFAIL);  
						  }else{

							  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Send Drop Call(currentCRN) to IP on channel %d\n", channel));

						  }							  
							  						  						 
						  Session[channel].NumOfDropExpected = 2;
                          chanInfoIP[channel].callsRejected++;
					      gateUpdate(&(Session[channel]),GATE_DROP);
					  }				  
				      else{

⌨️ 快捷键说明

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