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

📄 gatestat.c

📁 ipt网关源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*         rBool = Dm3TscMakeCall(lpTsc,        //* pointer to DM3TSC structure 
                                destAddr,     //* destination IP address 
                                srcAddr,      //* source IP address 
                                FALSE,        //* set for call progress 
                                KV_Info,      //* array of KV-Set 
                                infoCount);   //* number of KV-Set elements 
								

         if(rBool==DM3FAIL) {
            gateFATAL(channel,(Session[channel].LogFile,"\tError making call on channel %d\n"));
            return(DM3FAIL);
         }
		 chanInfo[channel].callsMade++;
         gateTRACE(channel,(Session[channel].LogFile,"\tMaking call on channel %d\n",channel));
		 gateUpdate(lpCamelSession,GATE_WAIT_CONNECT);*/

		 gateUpdate(lpCamelSession,GATE_WAIT_OFFHOOK_CMPLT);
         break; /* End DE_RING case */
   
   default:

        gateTRACE(channel,(Session[channel].LogFile,"\tUnexpected event %s (0x%x) on channel %d in WaitForCall\n",
                  gateEventStr(event),event,channel));
        break;

   } /* end switch(event) */


   return (DM3SUCCESS);

} /* Function gateWaitForCall */


/*****FUNCTION***************************************************
*        NAME : gateWaitForConnect
* DESCRIPTION : Waiting for connect event from NetTSC:
*                    *  If we made call update state to 
*                       WAIT FOR DISCONNECT
*                    *  If we got offering from NetTSC, 
*                       we should dial to local extention
*                       and route.
*       INPUT : LPDM3NetTSC  lpNetTsc   -  pointer to NetTsc structure
*               LONG         event      -  the recieved event
*  				 void         *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
USHORT gateWaitForConnect(LPDM3NetTSC  lpNetTsc, 
                          LONG         event,
					           void         *pEvtData)

{
   
   BOOL            rBool;
   LPDM3TSC        lpTsc;
   CallParameters  *CFGParm;
   CallParameters  *lpCallParm;
   GateSession     *pCamelSession;
   USHORT          channel;


   pCamelSession = (GateSession *)(lpNetTsc->lpUserInfo);
   channel = pCamelSession->sessionNumber;
   lpTsc = NETTSC_GET_DM3TSC(lpNetTsc);
   lpCallParm = NETTSC_GET_CALLPARM(lpNetTsc);
   CFGParm = &(pCamelSession->ConfigFileParm);


   gateTRACE(channel,(Session[channel].LogFile,"In WAIT_FOR_CONNECT on channel %d\n\t got event %s (0x%x)\n", 
               channel,gateEventStr(event), event));
    	 
   switch(event) {

      case TSC_EvtCallState_Type_Connected:
   
		 chanInfo[channel].callsConnected++;

      	/* Update the active channel to send UII or NonStdCmd */
         activeChannel = channel;
   
         if(lpNetTsc->fIsInbound == TRUE) {
            /* Go off hook */
            if(pstnOffHook(channel) == DM3FAIL)  {
                 gateFATAL(channel,(Session[channel].LogFile,"\tError setting line on channel %d\n"));
            }
	 
			if((frontEnd == GATE_LEGACY_T1) || (frontEnd == GATE_LEGACY_E1) ) {
				if((pstnState(channel) == FALSE)) {
					gateUpdate(pCamelSession,PSTN_INIT);
			        return(DM3SUCCESS);
				}
			}
           //以下外拨电话过程移至GATE_WAIT_IPINBOUND_OFFHOOK_CMPLT
           /* Dialing the local phone number on Analog front end*/
           /*if (frontEnd == GATE_LEGACY_ANALOG) {
				  gateTRACE(channel,(Session[channel].LogFile,"\tDialing (%s) on channel %d\n",
							  lpCallParm->localPhoneNumber, channel));
				  rBool = pstnDial(channel, lpCallParm->localPhoneNumber);
				  if(rBool==DM3FAIL) {
					 gateFATAL(channel,(Session[channel].LogFile,"\tError dialing on channel %d\n", channel));
					 return(DM3FAIL);
				  } 
			  }*/

           /* Routing the channels */
           /*rBool = gateRoute(channel);
           if(rBool==DM3FAIL) {
              gateFATAL(channel,(Session[channel].LogFile,"\tError routing after dial on channel %d\n", channel));
           }*/ 
         gateUpdate(pCamelSession,GATE_WAIT_IPINBOUND_OFFHOOK_CMPLT);
         }  /* End of if(lpNetTsc->fIsInbound == TRUE) */
		 else {

         
	     gateUpdate(pCamelSession,GATE_WAIT_DISCONNECT);
		 }
   		  
         break;
   

      /* Case of MakeCallCmlt */
      case TSC_MsgMakeCallCmplt:
   
         gateTRACE(channel,(Session[channel].LogFile,"Got makeCallCmplt on channel %d.\n",channel));
         break;
   
      /* ...._Idle can happen if the h323 service could 
         not find matching coders to astablish the call (as a respond to answerCall) */
      case TSC_EvtCallState_Type_Idle:

		  chanInfo[channel].callsIdle++;
          if(lpNetTsc->fIsInbound != TRUE) {
			    gateUnRoute(channel);
		    }

          /* Releasing call */
          rBool = Dm3TscReleaseCall(lpTsc,     /* pointer to DM3TSC structure */
                                    /* reason for releasing call */
                                  TSC_MsgRejectCall_Reason_Busy);
          if(rBool==DM3FAIL) {
             gateFATAL(channel,(Session[channel].LogFile,"\tError releasing Call channel %d \n", channel));
             return(DM3FAIL);
         
          } 
          else {
             gateTRACE(channel,(Session[channel].LogFile,"Releasing call on channel %d.\n",channel));
		       gateUpdate(pCamelSession,GATE_WAIT_RELEASE);
          }
		    return(DM3SUCCESS);

		    break;

      /* ...._Failed can happen if the remote side decided to disconect 
		 , if h323 service didn't find matching coders(as a respond to makeCall) */
      case TSC_EvtCallState_Type_Failed:
   
   	   gateTRACE(channel,(Session[channel].LogFile,"Got Failed or Disconneted reason is %d\n",
                   ((TSC_EvtCallState_t *)(pEvtData))->Reason));
       chanInfo[channel].callsFailed++;

   	  
      /* Can happen if the user made call and hang up before connection */
      case DE_LCOFF:
      case DE_TONEON:
      case DIGITAL_ONHOOK:

		 if(event != TSC_EvtCallState_Type_Failed) {
             Session[channel].waitOnHook = FALSE;
   	         gateTRACE(channel,(Session[channel].LogFile,"PSTN Disconnect on channel %d\n",
                        channel));
		 }

         /* Unlisten both sides */
         if(lpNetTsc->fIsInbound != TRUE) {
			    gateUnRoute(channel);
         }


         /* Dropping call */
         Dm3TscDropCall(lpTsc,     /* pointer to DM3TSC structure */
                        /* reason for dropping call */
                       CallStateR_RemoteTermination);
		 chanInfo[channel].callsDropped++;
         gateUpdate(pCamelSession,GATE_WAIT_IDLE);
         break;
   
      /* Case of Exit Notification */
      case TSC_EvtChanState_Type_OutOfService:
   
         gateTRACE(channel,(Session[channel].LogFile,"Channel %d OutOfService.\n",channel));
         if(lpNetTsc->fIsInbound != TRUE) {
			   gateUnRoute(channel);
		   }
         gateExit(CHAN_OUT_OF_SERVICE,channel);
         break;
   
      default:
   
         gateTRACE(channel,(Session[channel].LogFile,"\tUnexpected event %s (0x%x)  on channel %d in WaitForConnect\n",
                   gateEventStr(event),event,channel));
         break;

   } /* end switch(event) */

   return (DM3SUCCESS);

} /* Function gateWaitForConnect */


/*****FUNCTION***************************************************
*        NAME : gatePstnInit
* DESCRIPTION : Waiting for off hook from PSTN:
*
*       INPUT : LPDM3NetTSC  lpNetTsc   -  pointer to NetTsc structure
*               LONG         event      -  the recieved event
*  				 void         *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
USHORT gatePstnInit(LPDM3NetTSC  lpNetTsc, 
                          LONG         event,
					           void         *pEvtData)

{
   
   BOOL            rBool;
   LPDM3TSC        lpTsc;
   GateSession     *pCamelSession;
   USHORT          channel;;


   pCamelSession = (GateSession *)(lpNetTsc->lpUserInfo);
   channel = pCamelSession->sessionNumber;
   lpTsc = NETTSC_GET_DM3TSC(lpNetTsc);


   gateTRACE(channel,(Session[channel].LogFile,"In PSTN_INIT on channel %d\n\t got event %s (0x%x)\n", 
               channel,gateEventStr(event), event));

   switch(event) {

      case DIGITAL_OFFHOOK:
   
         Session[channel].waitOnHook = TRUE;

		  /* Routing the channels */
		  rBool = gateRoute(channel);
		  if(rBool==DM3FAIL) {
			  gateFATAL(channel,(Session[channel].LogFile,"\tError routing after dial on channel %d\n", channel));
		  }

		 gateUpdate(pCamelSession,GATE_WAIT_DISCONNECT);

         break;
   
		/* A drop from the NetTSC */
      case TSC_EvtCallState_Type_Disconnected:
   
   	   gateTRACE(channel,(Session[channel].LogFile,"Got Call State Disconnected the reason is %d\n",
                    ((TSC_EvtCallState_t *)(pEvtData))->Reason));
   
         /* Dropping call */
         Dm3TscDropCall(lpTsc,        /* pointer to DM3TSC structure */
                        /* Reason for dropping call */
      					   CallStateR_RemoteTermination);
		   chanInfo[channel].callsDropped++;
		   gateUpdate(pCamelSession,GATE_WAIT_IDLE);
         break; 
   
      /* Case of Exit Notification */
      case TSC_EvtChanState_Type_OutOfService:
   
         gateTRACE(channel,(Session[channel].LogFile,"Channel %d OutOfService.\n",channel));
         gateExit(CHAN_OUT_OF_SERVICE,channel);
         break;
   
      default:
   
         gateTRACE(channel,(Session[channel].LogFile,"\tUnexpected event %s (0x%x)  on channel %d in PstnInit\n",
                   gateEventStr(event),event,channel));
         break;

   } /* end switch(event) */

   return (DM3SUCCESS);

} /* Function gatePstnInit */


/*****FUNCTION***************************************************
*        NAME : gateWaitForDisconnect
* DESCRIPTION : Gateway is in connected state.
*               May get UII or NonStdCmd.
*               Waiting for hang up or netTSC drop, 
*               then unroute the channel and send message drop call 
*       INPUT : LPDM3NetTSC  lpNetTsc   -  pointer to NetTsc structure
*               LONG         event      -  the recieved event
*  				 void         *pEvtData  -  the data recieved
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None.
****************************************************************/
USHORT gateWaitForDisconnect(LPDM3NetTSC  lpNetTsc, 
                             LONG         event,
					              void         *pEvtData)

{
   BOOL           rBool;
   LPDM3TSC       lpTsc;
   GateSession    *pCamelSession;
   USHORT         channel;
   char			  tmpbuf[10];


   pCamelSession = (GateSession *)(lpNetTsc->lpUserInfo);
   channel = pCamelSession->sessionNumber;
   lpTsc = NETTSC_GET_DM3TSC(lpNetTsc);


   gateTRACE(channel,(Session[channel].LogFile,"In WAIT_FOR_DISCONNECT on channel %d\n\t got event %s (0x%x)\n", 
               channel,gateEventStr(event), event));

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

   
      /* Case of Exit Notification */
      case TSC_EvtChanState_Type_OutOfService:
   
         gateUnRoute(channel);
         gateTRACE(channel,(Session[channel].LogFile,"Channel %d OutOfService.\n",channel));
         gateExit(CHAN_OUT_OF_SERVICE,channel);
   
         break;
   
      /* Got call information */
      case TSC_MsgGetCallInfoCmplt :
   	     gateTRACE(channel,(Session[channel].LogFile,"Got Call info cmplt on channel %d\n",
                    channel));
		 break;
	  case TM_EOD:			//播放完毕
	  case TM_MAXDTMF:      //用户按键
		  	/*if (play(channel,handle[channel])==-1) { 
					//播放文件出错
					gateTRACE(channel,(Session[channel].LogFile,"Error in openning VOX file in channel %d on Gate_wait_for_getusername_cmplt state\n",
                        channel));
					 gateExit(PLAY_VOXFILE_ERROR,channel);
	                 return(DM3FAIL);
				}*/
		  if (dx_fileclose(handle[channel]) == -1) {
                    
				     gateTRACE(channel,(Session[channel].LogFile,"Error in closing VOX file in channel %d on Gate_wait_for_welcome_cmplt state\n",
                        channel));
				}
 		  //使用同步停止通道
    	  if (dx_stopch(channel, EV_SYNC)==-1) {
        	  printf("Error in stop channel %d !\n",channel);
		  }
		   
           rBool = gateRoute(channel);
           if(rBool==DM3FAIL) {
              gateFATAL(channel,(Session[channel].LogFile,"\tError routing after dial on channel %d\n", channel));

⌨️ 快捷键说明

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