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

📄 megacomgc.c

📁 h.248协议源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	RvMegacoSignal			   signal;
	int 					   x;
	RvMegacoContextIdType	   type;
	RvMegacoEventsDescriptor   eventsDescriptor; 
	RvMegacoRequestedEvent	   requestedEvent;
	
	sprintf(dispBuf, "In applDoCleanup(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf);
	
	if (applInfo[termInd].callInProgress == rvFalse)
		return E_ON_HOOK_DISC_IND;							 
	
	for (x = 0; x < 2; x++) 					  
	{
		if (applInfo[termInd].inService == rvFalse)    
			return NO_EVENT;
		type = rvMegacoContextIdGetType(&applInfo[termInd].contextId);
		/* Allocate and construct action  */
		applInfo[termInd].modifyCommandPtr =	  /* It will be constructed in		*/
		  rvAllocAllocate(&rvDefaultAlloc,	 /* send_request()				   */
		  sizeof(RvMegacoModifyCommand)); 
		rvMegacoModifyCommandConstruct(applInfo[termInd].modifyCommandPtr, 
		  &applInfo[termInd].terminationId);
		/* Setup events 				  */
		if (x == 0) 							  /* If originator of disconnect	*/
		{
			applInfo[termInd].callInProgress = rvFalse;
			applInfo[termInd].discInitiatorInd = termInd;
		}
		else									  /* If responder					*/
		{ 
			if (applInfo[termInd].markedAction == A_RING_SIGNAL_REQ) /* clash		*/
			{			 
				rvMegacoPackageItemConstruct(&packageItem1,/* Construct PackageItem*/
				  "al",  /* Analog Line Supervisory Pack*/
				  "on");/* On_hook eventId			 */
				rvMegacoRequestedEventConstruct(&requestedEvent, &packageItem1);
				rvMegacoEventsDescriptorConstruct(&eventsDescriptor, applInfo[termInd].requestId); 
				rvMegacoEventsDescriptorAddEvent(&eventsDescriptor, &requestedEvent);
				rvMegacoModifyCommandSetEvents(applInfo[termInd].modifyCommandPtr,
				  &eventsDescriptor);
				rvMegacoPackageItemDestruct(&packageItem1); 
				rvMegacoRequestedEventDestruct(&requestedEvent);
				rvMegacoEventsDescriptorDestruct(&eventsDescriptor); 
			}
		} 
		/* Set up signals				  */
		if (x == 0) 							  /* If originator of disconnect	*/ 
		{
			if (applInfo[termInd].markedAction == A_RING_SIGNAL_REQ) /* clash		*/
			{
				rvMegacoPackageItemConstruct(&packageItem2,/* Construct PackageItem*/
				  "cg",	/* Call Progress Tones Package*/
				  "wt"); /* Warning tone signal		 */ 
			}
			else
			{
				rvMegacoPackageItemConstruct(&packageItem2,/* Construct PackageItem*/
				  "", 		  /* Stop the ring		  */
				  "");  
			}
		}
		else									  /* If responder of disconnect 	*/
		{
			/* If connect originator		  */
			if (applInfo[termInd].connectInitiatorInd == termInd)
			{
				rvMegacoPackageItemConstruct(&packageItem2,/*Construct PackageItem	*/
				  "cg",  /* Call Progress Tones Pack*/
				  "wt");/* Warning tone signal	 */
			}
			else								   /* If connection responder		 */
			{
				if (applInfo[termInd].markedAction == A_STOP_RING_SIGNAL_REQ)
				{
					rvMegacoPackageItemConstruct(&packageItem2, 
					  "cg",  /* Call Progress Tones Pack*/
					  "wt");/* Warning tone signal	 */
				}
				else
					rvMegacoPackageItemConstruct(&packageItem2, 
					  "", 		  /* Stop the ring		  */
					  "");   
			}
		}
		rvMegacoSignalConstruct(&signal, &packageItem2);
		rvMegacoSignalsDescriptorConstruct(&signalsDescriptor);
		rvMegacoSignalsDescriptorAddSignal(&signalsDescriptor, &signal);
		rvMegacoModifyCommandSetSignals(applInfo[termInd].modifyCommandPtr,
		  &signalsDescriptor);
		
		if (type != RV_MEGACOCONTEXTID_NORMAL)
		{
			if (type == RV_MEGACOCONTEXTID_NULL)
			{
				if (applInfo[termInd].remoteTermInd != (-1))
				{
					rvMegacoContextIdDestruct(&applInfo[termInd].contextId);
					rvMegacoContextIdConstructSpecial(&applInfo[termInd].contextId,
					  RV_MEGACOCONTEXTID_ALL); 
				}
			}
			else	/* Context might change */
			{
				rvMegacoContextIdDestruct(&applInfo[termInd].contextId);
				rvMegacoContextIdConstructSpecial(&applInfo[termInd].contextId,
				  RV_MEGACOCONTEXTID_ALL); 
			}
		}
		applInfo[termInd].commandType = RV_MEGACOCOMMANDTYPE_MODIFY;	
		sendRequest(SEND_COMMAND);
		
		if (x == 0)	/* If originator of disconnect	*/
			applInfo[termInd].nextEvent = E_ON_HOOK_DISC_IND; 
		else
			applInfo[termInd].nextEvent = NO_EVENT;  
		
		rvMegacoPackageItemDestruct(&packageItem2);
		rvMegacoSignalDestruct(&signal);
		rvMegacoSignalsDescriptorDestruct(&signalsDescriptor);
		
		if (applInfo[termInd].timer.id != 0)
		{
			/* Clear timer */
			rvTimerStop(&applInfo[termInd].timer);
			applInfo[termInd].timer.id = 0;
			applInfo[termInd].timerEvent = NO_EVENT;
			sprintf(dispBuf, "Timer cleared, termInd %d", termInd);
			rvLogInfo3(&rvLog, dispBuf);
		}
		
		if (applInfo[termInd].remoteTermInd == (-1))
			return NO_EVENT;
		else
			termInd = applInfo[termInd].remoteTermInd;
	}
	return NO_EVENT;
}

/********************************************************************************/
/* We received some error in responce to our command. Clean up this termination */
/* or both terminations in case there was an association established between 2  */
/* terminations at this time.                                                   */
/********************************************************************************/
int  applErrorMsgResp(void)    
{
	applInfo[termInd].error = 0;
	return E_GO_OUT_OF_SERVICE;
}

/********************************************************************************/
/*  We come here in State 1 when MG sends a ServiceChange request telling MGC   */  
/* that a specific termination is back in service. Prepare to listen for the    */
/* off-hook signal on this termination                                          */
/********************************************************************************/
int  applGoInService(void)
{
	sprintf(dispBuf, "In applGoInService(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf);
	applInfo[termInd].inService = rvTrue;
	applInfo[termInd].timer.id = 0;
	return E_OFF_HOOK_LISTEN_REQ;
}
                                    
/********************************************************************************/
/*   We can get here any time when the serviceChange command is delivered from  */
/* MG announcing that the termination is taken out of service (for whatever     */
/* reason)                                                                      */ 
/********************************************************************************/
int  applGoOutOfService(void) 
{
	sprintf(dispBuf, "In applGoOutOfService, termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf);

	applInfo[termInd].timer.id = 0;
	applInfo[termInd].inService = rvFalse;
	applInfo[termInd].inUse = rvFalse;

	applInfo[termInd].callInProgress = rvFalse;
	applInfo[termInd].remoteTermInd = -1;    /* I know nothing about remote    */
											 /* Remote knows nothing about me  */
	applInfo[applInfo[termInd].remoteTermInd].remoteTermInd = -1; 
	applInfo[termInd].connectInitiatorInd = -1;
	applInfo[termInd].markedAction = NO_EVENT;   
	return NO_EVENT;
}

/********************************************************************************/
/*   We can come here in any state when the remote MG sends us something        */
/* unexpected. Do nothing for now, just log a message                           */
/********************************************************************************/
int  applIllegal(void)
{
	sprintf(dispBuf, "Illegal event in state %d, termInd %d",
	  applInfo[termInd].currentState, termInd);
	rvLogInfo3(&rvLog, dispBuf);

	if (rootRequest)
		return NO_EVENT;

	sendReply(CREATE_COMMAND_REPLY);       /* Send default reply              */
	return NO_EVENT;
}

/********************************************************************************/
/*   We can come here in state 1. This means that mg sends us some              */ 
/* notifications before service change is delivered. Drop it.                   */
/********************************************************************************/
int applIllegal1(void)
{
	sprintf(dispBuf, "Illegal event in state %d, termInd %d",
	  applInfo[termInd].currentState, termInd);
	rvLogInfo3(&rvLog, dispBuf);
	return NO_EVENT;
}

/********************************************************************************/
/*   If we come here it means there is a problem with the internal logic.       */
/* Use this action to block impossible combinations of events/states and detect */
/* a bug as early as possible                                                   */
/********************************************************************************/
int applImpossible(void)
{
	sprintf(dispBuf, "Impossible action in state %d, termInd %d", 
	  applInfo[termInd].currentState, termInd);
	rvLogInfo3(&rvLog, dispBuf);
	RVMGC_PRINT_ERROR("Bad state in applImpossible\n");
	return NO_EVENT;
}

/********************************************************************************/
/*  We come here in state 2 when the calling MG sends us the dialed number and  */
/* we now can add the calling termination for TDM phone as well as the RTP      */
/* stream into a new context.                                                   */
/*                                                                              */
/*  It's possible to use a function call                                        */
/*        rvMegacoTransactionConstructParse(RvMegacoTransaction *x,            */
/*                                           const char *text,                  */
/*                                           RvParseError *error)              */
/*                                                                              */     
/*  and a prefabricated "canned" message text instead of constructing this      */
/*  command from separate elements.                                             */
/*  The text for the applLocalConnect() command will be as follows:             */
/*                                                                              */ 
/*       "T=4{C=${A=terma,A=${M{L{\n \                                          */
/*        v=0\n \                                                               */
/*        c=IN IP4 $\n \                                                        */
/*        m=audio $ RTP/AVP 0\n \                                               */
/*        },O{MO=RC,nt/jit=40}}}}}\n"                                           */
/*                                                                              */
/********************************************************************************/
int applLocalConnect(void)         
{
	RvMegacoMediaDescriptor      media;
	RvMegacoStreamDescriptor     stream;
	RvMegacoAddCommand           addCommand1, addCommand2;
	RvMegacoStreamMode           mode = RV_MEGACOSTREAMMODE_RECVONLY;
	RvSdpMsg                     sdpMsg;
	RvSdpMediaDescr              *sdpMediaDescr;
	const char                   version = 0x30;
	RvMegacoParameterValue       paramValue1;
	RvMegacoPackageItem          packageItem1;
	RvMegacoTerminationId        terminationId;
	int                          i = 0;

	sprintf(dispBuf, "In applLocalConnect(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf); 
	
	/* 1st add command requests to add    */
	/* TDM term. to a new context         */      

⌨️ 快捷键说明

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