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

📄 gatemain.c

📁 ipt网关源码
💻 C
📖 第 1 页 / 共 4 页
字号:
			case 'c':
				strcpy(cfgFile,argv[ii]+2);
				break;

			/* Debug level printing */
			case 'd':
				_logLevel = atoi(argv[ii]+2);
				break;

			/* Enable write to different log file for each channel */
			case 'l':
				logFileFlag = TRUE;
				break;

			/* Encoding type */
			case 'E':                           
			case 'e':                           
			     switch(tolower((argv[ii]+2)[0])) {
						case 'm':
							encodingType = QSCBUS_ENCODING_MULAW;
							IdlePat = QSCBUS_IDLE_MULAW;
							break;

						case 'a':
							encodingType = QSCBUS_ENCODING_ALAW;
							IdlePat = QSCBUS_IDLE_ALAW;
						break;
						default:
							printf("Unknown encoding type('a' - A law, 'm' - Mu law).\n"); 
						}
					break;

			/* Help */
			case '?':
			case 'h':
			default:
				usage();
			break;

		}  /* end of switch. */

   } /* end of parse command line for */

} /* Function checkArg */


/*****FUNCTION***************************************************
*        NAME : attachSRLToIOCP
* DESCRIPTION : Attaches SRL to  IOCP
*       INPUT : Needed for SRL to IOCP 
*      OUTPUT : None
*     RETURNS : Success or fail
*    CAUTIONS : None
****************************************************************/
BOOL attachSRLToIOCP(HANDLE hPort, 
                     LPSRLWIN32INFO pSrlWin32Info,
                     LPOVERLAPPED pOverlapped)
{

   /* Build the SrlWin32 structure */
   pSrlWin32Info->dwTotalSize	= sizeof(SRLWIN32INFO);
   pSrlWin32Info->ObjectHandle  = hPort;
   pSrlWin32Info->dwHandleType  = SR_IOCOMPLETIONPORT;
   pSrlWin32Info->UserKey		= SRL_KEY;
   pSrlWin32Info->lpOverlapped  = pOverlapped;

   /* Set the SRL device to work with IO completion ports */
   if(sr_setparm(SRL_DEVICE, SR_WIN32INFO, (void *)pSrlWin32Info) == -1) {
      return DM3FAIL;
   }

   return DM3SUCCESS;

} /* Function attachSRLToIOCP */


/*****FUNCTION***************************************************
*        NAME : completionPorts
* DESCRIPTION : Create completion port 
*               and attach srl key to it.
*       INPUT : None
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void completionPorts()
{
   
  OVERLAPPED     srlOverlapped;  /* SRL attachment needs: */
  SRLWIN32INFO   iocpInfo;

   /* Create NULL IO completion port */
   if((hIOCP = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
                                      NULL,
                                      0,
                                      0 )) == NULL) {
      printf("\nCreate IOCP failed\n");
      gateExit(IOCP_ERROR,ALL_CHANNELS);
   }

   /* Zero out the overlapped structure for SRL */
   ZeroMemory(&srlOverlapped, sizeof(OVERLAPPED));
   
   /* Attach SRL to IOCP handling */
   if(attachSRLToIOCP(hIOCP, &iocpInfo, &srlOverlapped) == DM3FAIL) {
	   printf("\tAttaching SRL to IOCP FAILED\n");
   }

} /* Function CompletionPorts */


/*****FUNCTION***************************************************
*        NAME : IPTGetNumBoards
* DESCRIPTION : Gets the number of DM3 boards in the system
*       INPUT : ULONG * NumOfBoards - Number of DM3 boards
*      OUTPUT : ULONG * NumOfBoards - Number of DM3 boards
*     RETURNS : Success or fail
*    CAUTIONS : None
****************************************************************/
BOOL IPTGetNumBoards(ULONG * NumOfBoards)
{


   /* board attributes: 1 per each board found, */ 
   /* plus one for a NULL terminating attribute */
   QBoardAttr  boardAttr[MAX_BOARDS + 1];
   ULONG       maxBoardEntry = MAX_BOARDS + 1;
   ULONG       boardsFound = 0x0; 
   DWORD       ErrorCode;
   QValueAttr  valAttr[2];

   ZeroMemory(valAttr, 2*sizeof(QValueAttr));
   ZeroMemory(boardAttr,(MAX_BOARDS + 1)*sizeof(QBoardAttr));
   strcpy(valAttr[0].ValueName, "CurrentState");
   strcpy(valAttr[0].Value, "Running");
   valAttr[0].ValueType = REG_SZ;
   valAttr[0].ValueFlag = 0; /* match on 'Value' field */

   /* check registry to find boards with the matching attributes */
   if (mntGetBoardsByAttr(valAttr,
                           MAX_BOARDS + 1,
                           boardAttr,
                           &maxBoardEntry,
                           &boardsFound) == FALSE) {
      ErrorCode = GetLastError();
      printf("Can't get boards attributes (0x%x)\n", ErrorCode);
      return(DM3FAIL);
   } 

   if (boardsFound == 0) {
      return(DM3FAIL);
   } 
   
   *NumOfBoards = boardsFound;
   printf("Found %d boards.\n",boardsFound);

   return(DM3SUCCESS);

} /* Function IPTGetNumBoards */


///////////////////////////////////////////////////////////////////////
//        NAME : IPTEnableAllEvts()
// DESCRIPTION : Enable the reporting of multiple events for 
//               NetTsc component instance
//       INPUT : LPDM3TSC lpTsc - pointer to TSC structure 
//      OUTPUT : None.
//     RETURNS : success or fail
//    CAUTIONS : None.
///////////////////////////////////////////////////////////////////////
BOOL IPTEnableAllEvts(LPDM3TSC lpTsc)
{

   UINT  unMaxEvents;   // Number of Call State Events to be enabled


   /*
    * This array defines all the events that will be enabled and
    * should always correspond to the defines in TSCDEFS.H & NTSCDEFS.H
    */

   Std_MsgDetectxEvts_List_t NetTSCEvtList[] =
   { 
      TSC_EvtCallState_Type_Null,
	      TSC_LABEL_CALL_STATE,
      TSC_EvtCallState_Type_Connected,
	      TSC_LABEL_CALL_STATE,
	   TSC_EvtCallState_Type_Disconnected,
	      TSC_LABEL_CALL_STATE,
	   TSC_EvtCallState_Type_Failed,
	      TSC_LABEL_CALL_STATE,
	   TSC_EvtCallState_Type_Idle,
	      TSC_LABEL_CALL_STATE,
	   TSC_EvtCallState_Type_Offered,
	      TSC_LABEL_CALL_STATE,
	   TSC_EvtChanState_Type_OutOfService,
	      TSC_LABEL_CHAN_STATE,
      NetTSC_EvtH245Data_Type_NonStdCmd,
	      NTSC_LABEL_H245_DATA,
      NetTSC_EvtH245Data_Type_UsrInputIndication,
	      NTSC_LABEL_H245_DATA, 
   };
   
   if (!lpTsc) {
      SetLastError(ERROR_INVALID_PARAMETER);
      return (DM3FAIL);
   }

   unMaxEvents = sizeof(NetTSCEvtList)/sizeof(Std_MsgDetectxEvts_List_t);

   if (Dm3CompDetectxEvts(&( lpTsc->theComp), 
                          unMaxEvents,
                          NetTSCEvtList, 
                          lpTsc->theComp.qcdHostAddr) != DM3SUCCESS) {
      return(DM3FAIL);
   }
   
   return(DM3SUCCESS);
   
}  /* Function IPTEnableAllEvts */


///////////////////////////////////////////////////////////////////////
//        NAME : IPTDisableAllEvts()
// DESCRIPTION : Disable the reporting of multiple events for 
//               NetTsc component instance
//       INPUT : LPDM3TSC lpTsc - pointer to TSC structure 
//      OUTPUT : None.
//     RETURNS : success or fail
//    CAUTIONS : None.
///////////////////////////////////////////////////////////////////////
BOOL IPTDisableAllEvts(LPDM3TSC lpTsc)
{

   UINT  unMaxEvents;   // Number of Call State Events to be disabled


   /*
    * This array defines all events that will be disabled and
    * should always correspond to the defines in TSCDEFS.H & NTSCDEFS.H
    */

   Std_MsgCancelxEvts_List_t CancelEvtList[] =
   { 
      TSC_EvtCallState_Type_Null,
	   TSC_EvtCallState_Type_Connected,
	   TSC_EvtCallState_Type_Disconnected,
	   TSC_EvtCallState_Type_Failed,
	   TSC_EvtCallState_Type_Idle,
	   TSC_EvtCallState_Type_Offered,
	   TSC_EvtChanState_Type_OutOfService,
      NetTSC_EvtH245Data_Type_NonStdCmd,
      NetTSC_EvtH245Data_Type_UsrInputIndication
   };
   
   if (!lpTsc) {
      SetLastError(ERROR_INVALID_PARAMETER);
      return (DM3FAIL);
   }

   unMaxEvents = sizeof(CancelEvtList)/sizeof(Std_MsgCancelxEvts_List_t);

   if (Dm3CompCancelxEvts(&( lpTsc->theComp), 
                   unMaxEvents,
                   CancelEvtList ) != DM3SUCCESS) {
      return(DM3FAIL);
   }
   
   return(DM3SUCCESS);
   
} /* Function IPTDisableAllEvts */

/*****FUNCTION***************************************************
*        NAME : IPTResetSession
* DESCRIPTION : Resets session structure to default values
*       INPUT : int ch     -   Channel to reset
*               BOOL clear -   Boolean to know if reset totally
*                              TRUE - clear totaly
*                              FALSE - clear the related fields of this call
*      OUTPUT : None
*     RETURNS : void
*    CAUTIONS : None
****************************************************************/
void IPTResetSession(int ch, BOOL clear)
{
	char  fileName[20];
    
   gateUpdate(&(Session[ch]),GATE_WAIT_CALL);
	Session[ch].sessionNumber = ch;
	NetTSCResetSession(&(Session[ch].NetTscComp));
    Session[ch].resetNow = 0;
    Session[ch].waitOnHook = FALSE;



   if (clear==TRUE) {

	  if(logFileFlag) {
		  sprintf(fileName, "Chan%d.txt",ch);
		  if((Session[ch].LogFile = fopen(fileName, "w")) == NULL) {
			  printf("Unable to open log file for channel %d.\n",ch);
		  }
	  }
	  else {
		  Session[ch].LogFile = stdout;
	  }

     gateUpdate(&(Session[ch]),GATE_WAIT_DETECT_CMPLT);
     Session[ch].PstnInfo.phoneDevice = 0;                 
	  Session[ch].PstnInfo.pstnTxTSlot = 0;

     /* Set max Tx coders to Zero, the field will be updated while 
	     parsing from configuration file */      
     Session[ch].ConfigFileParm.maxTxCoders = 0;         

	  /* ConfigFileParm is a structure containing the information 
	     stored in the configuration file */
     strcpy(Session[ch].ConfigFileParm.display,"\0");
     strcpy(Session[ch].ConfigFileParm.phoneList,"\0"); 
     strcpy(Session[ch].ConfigFileParm.localPhoneNumber,"\0"); 
     ZeroMemory(&(Session[ch].ConfigFileParm.UII),sizeof(NetTSC_MsgSendUserInputIndication_t));
     ZeroMemory(&(Session[ch].ConfigFileParm.NonStdCmd),sizeof(NetTSC_MsgSendNonStandardCmd_t));
     ZeroMemory(&(Session[ch].ConfigFileParm.TxCoder),MAX_CODER_CAPABILITY*sizeof(NetTSC_Coder_t));/* default */
     ZeroMemory(&(Session[ch].ConfigFileParm.RxCoder),MAX_CODER_CAPABILITY*sizeof(NetTSC_Coder_t));/* default */
     strcpy(Session[ch].ConfigFileParm.srcAddr,"255.255.255.255");
     strcpy(Session[ch].ConfigFileParm.destAddr,"255.255.255.255");
     Session[ch].ConfigFileParm.callDurationTime = 0;               
     ZeroMemory(&(Session[ch].ConfigFileParm.RTCPInfo),sizeof(NetTSC_RTCPInfo_t));/* default */
	 chanInfo[ch].on_hook = 0;
	 chanInfo[ch].off_hook = 0;
	 chanInfo[ch].callsMade = 0;
	 chanInfo[ch].callsOffered = 0;
	 chanInfo[ch].callsConnected = 0;
	 chanInfo[ch].callsDropped = 0;
	 chanInfo[ch].callsIdle = 0;
	 chanInfo[ch].callsNull = 0;
	 chanInfo[ch].callsFailed = 0;
	 chanInfo[ch].callsRejected = 0;
   } 

} /* Function IPTResetSession */


/*****FUNCTION***************************************************
*        NAME : ClusterInit
* DESCRIPTION : Make all cluster initialization
*       INPUT : USHORT  *pNumTSC   Number of IPT channels
                USHORT VOXChannels  PSTN available channels
*      OUTPUT : USHORT  *pNumTSC   Number of IPT channels
*     RETURNS : Success or fail
*    CAUTIONS : None
****************************************************************/
USHORT ClusterInit(USHORT *pNumNetTSC,
                   USHORT VOXChannels)
{
   USHORT           BoardId = 0;
   USHORT           SessionId = 0;
   BOOL             rBool = TRUE;
   LPNETTSCCLUSTER  pClusterDesc;

   while((SessionId < VOXChannels) && (SessionId < gateChannels) && (BoardId < NumOfBoards) ) 
   {
	   if(rBool == FALSE) {
		   BoardId++;
		   rBool = TRUE;
           continue;
	   }

	   SessionId++;     /* Update counter */

      pClusterDesc = &(Session[SessionId].NetTscClust);

      /* Init Cluster Fields, allocate NetTSC cluster 
         and find SCBus component instance in the allocated cluster */
      (pClusterDesc->theCluster).ucEncodingType = encodingType;
      (pClusterDesc->theCluster).ucIdlePattern = IdlePat;
      if(NETTSCClusterInit(pClusterDesc,

⌨️ 快捷键说明

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