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

📄 gatestate.c

📁 dialogic voip 测试代码
💻 C
📖 第 1 页 / 共 4 页
字号:



/*****FUNCTION***************************************************
*        NAME : gateConnected
* DESCRIPTION : The function waits for disconnected from IP/PSTN.
*
*       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 gateConnected(unsigned int channel, COMP_KEY compKey, long event,void * EvtData)
{
	int            rBool;  

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


    /* Switch on event */
    switch(event) {
	         
		  /* Got call informationl */
    
	 
      case GCEV_EXTENSION:
         break; 
		 
	  case GCEV_ALERTING:
		  break;


       /* A drop from the IP/PSTN  or error*/
       case GCEV_DISCONNECTED:
	   case GCEV_TASKFAIL:

		   /* Unlisten to IP */
		   rBool = pstnUnListen(channel);
           if(rBool != FUNCSUCCESS) {
		      gateFATAL(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"PSTN unlisten failed.\n"));
              return(FUNCFAIL);
		   }else{

			  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Make PSTN Unlisten to IP on channel %d\n", channel));

		   }	

		   /* UnListen to pstn */
		   if (gc_UnListen(Session[channel].ipParams.linedev, EV_SYNC) == -1) {
			   gateFATAL(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tError in gc_UnListen on channel %d\n",channel));
			   return (FUNCFAIL);
		   }else{

			  gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"Make IP Unlisten to PSTN on channel %d\n", channel));

		   }
	       

		   if (gc_DropCall(Session[channel].ipParams.currentCRN, GC_NORMAL_CLEARING, 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 (gc_DropCall(Session[channel].pstnParams.currentCRN, GC_NORMAL_CLEARING, 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;
	  		  
	       gateUpdate(&(Session[channel]),GATE_DROP);
           break; 
   

      default:
           gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in gateConnected from %s\n",
                      gateEventStr(event),event,channel,gateKeyStr(compKey)));
           break;

    } /* end switch(event) */


   return (FUNCSUCCESS);
          
 } /* End of Function gateConnected */



/*****FUNCTION***************************************************
*        NAME : gateDrop
* DESCRIPTION : The function Waiting for GCEV_DROPCALL from IP & PSTN.
*
*       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 gateDrop(unsigned int channel, COMP_KEY compKey, long event,void * EvtData)
{
	GC_PARM_BLKP  gcParmBlk = NULL;
      
    gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"In GATE_DROP State on channel %d\n\t got event %s (0x%x) from %s\n", 
             channel,gateEventStr(event), event, gateKeyStr(compKey)));


   /* Switch on event */
   switch(event) {
		 
	
      case GCEV_EXTENSION:  /* Got call information  or taskFail*/ 
	  case GCEV_TASKFAIL:  /* The reason for the fail can be on gc_Extionsion, gc_DropCall, or other reson */


		  if (Session[channel].ipParams.currentCRN > 0){
			  if (gc_ReleaseCallEx(Session[channel].ipParams.currentCRN, EV_SYNC)<0){
			      printGCError("gc_ReleaseCallEx",channel,Session[channel].LogFile,_logLevel); 
	              return (FUNCFAIL); 
			  }else{

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

			  }
		  }

		  if (Session[channel].ipParams.glareCRN > 0){
			  if (gc_ReleaseCallEx(Session[channel].ipParams.glareCRN, EV_SYNC)<0){
			      printGCError("gc_ReleaseCallEx",channel,Session[channel].LogFile,_logLevel); 
	              return (FUNCFAIL); 
			  }else{

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

			  }
		  }

          if (Session[channel].pstnParams.currentCRN > 0){
			  if (gc_ReleaseCallEx(Session[channel].pstnParams.currentCRN , EV_SYNC)<0){
			      printGCError("gc_ReleaseCallEx",channel,Session[channel].LogFile,_logLevel); 
	              return (FUNCFAIL); 
			  }else{

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

			  }
		  }

		  if (Session[channel].pstnParams.glareCRN > 0){
			  if (gc_ReleaseCallEx(Session[channel].pstnParams.glareCRN, EV_SYNC)<0){
			      printGCError("gc_ReleaseCallEx",channel,Session[channel].LogFile,_logLevel); 
	              return (FUNCFAIL); 
			  }else{

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

			  }
		  }         

		  /* Reset session */
          IPTResetSession(channel,0);
		  gateUpdate(&(Session[channel]),GATE_NULL);
		  
		  if (Session[channel].ipParams.nextCRN > 0){
			  Session[channel].ipParams.currentCRN = Session[channel].ipParams.nextCRN;
			  Session[channel].ipParams.nextCRN = 0;
			  if((*(Session[channel].stateFxn))(channel,IP,GCEV_OFFERED,NULL) != FUNCSUCCESS) {
		         gateFATAL(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"State Machine Error on Channel %d, event GCEV_OFFERED\n", channel ));
	             return(FUNCFAIL);
			  }
		  }
		  else if (Session[channel].pstnParams.nextCRN > 0){
			  Session[channel].pstnParams.currentCRN = Session[channel].pstnParams.nextCRN;
			  Session[channel].pstnParams.nextCRN = 0;
			  if((*(Session[channel].stateFxn))(channel,PSTN,GCEV_OFFERED,NULL) != FUNCSUCCESS) {
		         gateFATAL(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"State Machine Error on Channel %d, event GCEV_OFFERED\n", channel ));
	             return(FUNCFAIL);
			  }
		  }
		  break; 

	  

		 

		  
	  case GCEV_DROPCALL:

		  Session[channel].NumOfDropEvt++;
		  
		  if (Session[channel].NumOfDropExpected == Session[channel].NumOfDropEvt){
			  chanInfoIP[channel].callsNull++;
              chanInfoPSTN[channel].callsNull++;
			  

			  /* Fill gcParmBlk structure */
		      if (gc_util_insert_parm_val(&gcParmBlk,IPSET_CALLINFO, IPPARM_RTCPINFO,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_CALLDURATION,sizeof(int),1) < 0){

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

			  } 


		      /* send a gc_Extension message instead of GatCallInfo */
			  if (Session[channel].ipParams.currentCRN > 0){
				  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,"send a gc_Extension message instead of GatCallInfo to IP on channel %d\n", channel));

				  }
			  }else{
				  if (gc_Extension(GCTGT_GCLIB_CRN,
					              Session[channel].ipParams.glareCRN,
								  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,"send a gc_Extension(glareCRN) message instead of GatCallInfo to IP on channel %d\n", channel));

				  }
			  }

		
		      gc_util_delete_parm_blk(gcParmBlk);

		  }
		  break;

		  
			  
	  case GCEV_OFFERED:

		  /* The nextCRN will be updated (for IP or PSTN) , so when finish relesing the call 

		     for the currentCRN , the application will hold the call relating to nextCRN  

			 (see the case GCEV_EXTENSION in this function ) */ 


	  case GCEV_ANSWERED:
	  case GCEV_DETECTED:
	  
		  break;
	  
	  case GCEV_DISCONNECTED:

		 /* received DISCONNECTED event from PSTN, after we got OFFERED from PSTN in DROP state and 

		       due to timeout we received the DISCONNECTED */

		  if (Session[channel].pstnParams.nextCRN > 0){

			  if (gc_DropCall(Session[channel].pstnParams.nextCRN, GC_REQ_CHANNEL_NOT_AVAIL, 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(nextCRN) to PSTN on channel %d\n", channel));

				  Session[channel].NumOfDropExpected ++;

			  }

		  }

             

			  /* received DISCONNECTED event from IP, after we got OFFERED from IP in DROP state and 

		        due to timeout we received the DISCONNECTED */

		  if (Session[channel].ipParams.nextCRN > 0){

			  if (gc_DropCall(Session[channel].ipParams.nextCRN, GC_REQ_CHANNEL_NOT_AVAIL, 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(nextCRN) to IP on channel %d\n", channel));

				  Session[channel].NumOfDropExpected ++;

			  }

		  }
	      
		  break;

      default:
          gateTRACE(channel,_logLevel,Session[channel].LogFile,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in DROP from %s\n",
                      gateEventStr(event),event,channel,gateKeyStr(compKey)));
          break;

   } /* end switch(event) */

   
   return (FUNCSUCCESS);
          
 } /* End of Function gateDrop */


/**** End of File: GateState.c *****/


⌨️ 快捷键说明

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