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

📄 复件 (2) h323f.cpp

📁 基于h323协议的软phone
💻 CPP
📖 第 1 页 / 共 5 页
字号:
int h323_query_availability_state_call_forward_rcvd(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_query_availability_state_call_forward_rcvd\n");

	wp_msg = (WrapperMsg *)psEvent->pMsg;
	char forwardToNumber[40];
	
	//H323TRACE("Call forward message received\n");

	PreserveLcdMessage = TRUE;
	LcdShowMessage(H323_FORWARDING_TO);	
	strncpy(forwardToNumber, wp_msg->d.CallForwardInfo.ForwardToNumber, 39);
	forwardToNumber[39] = '\0';
	WriteLcd(forwardToNumber, 1, 0);

	/* Forward has a cycle, do nothing, goto dead_end_state */
	if (wp_msg->d.CallForwardInfo.hasCycle)
	{				
		taskDelay(TASKDELAY_ONE_SEC);
		AppTerminateAction( ST_H323_QUERY_AVAILABILITY_STATE );	
		PreserveLcdMessage = TRUE;
		LcdShowMessage(H323_CIRCULAR_TOO_MANY_FORWARD);
		PlayBusyTone(FIFTEEN_SEC);
		return to_dead_end_state;
	}

	if (wp_msg->d.CallForwardInfo.ForwardToAddrType == REROUTE_TYPE_IPADDR)
	{
		char ip[4];
		int i;
		for (i = 0; i < 4; i++)
		{
			ip[i] = (digit_set[4*i]-'0')*100+(digit_set[4*i+1]-'0')*10+(digit_set[4*i+2]-'0');
		}
		sprintf(digit_set, "*%u%u%u%u", ip[0], ip[1], ip[2], ip[3]);		
	}
	else
	{
		strncpy(digit_set, wp_msg->d.CallForwardInfo.ForwardToNumber,MAX_PHONE_NUMBER_LEN);
		digit_set[MAX_PHONE_NUMBER_LEN]='\0';
	}
	
	/* 通知菜单复位 */
	menu_event = reset_event;
	
	/*H323TRACE("Going to query_availability_state\n");*/
	/* 设置等待响应计时器 */
	DeleteTimer(&h323_timer);
	h323_timer = CreateTimer(TEN_SEC);
	return null_event;
}

/**
 * 对方无应答,终结呼叫;
 * 产生to_dead_end_state事件
 */
int h323_query_availability_state_timeout_event(s_event* psEvent, s_task*
    psTask)
{
	msg = (NonWrapperMsg *)psEvent->pMsg;
	if ((msg->digit != h323_timer) && (msg->digit != call_forward_timer))
		return null_event;

	H323TRACE("action: h323_query_availability_state_timeout_event\n");
	
	h323_timer = -1;
		
	if (!(*menu_inuse))
	{
		LcdShowMessage(H323_WAIT_FOR_REPLY_TIMEOUT);
	}

	/*H323TRACE("Doing terminate action\n");*/
	PreserveLcdMessage = TRUE;
	AppTerminateAction( ST_H323_QUERY_AVAILABILITY_STATE );	
	PlayBusyTone(FIFTEEN_SEC);
	return to_dead_end_state;
}

/**
 * 终结,回到初始状态
 */
int h323_query_availability_state_local_on_hook_event(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_query_availability_state_local_on_hook_event\n");
	
	/* 若为免提状态,状态不变 */
	if (on_speakerphone == TRUE)
		return to_query_availability_state;
	
	AppTerminateAction( ST_H323_QUERY_AVAILABILITY_STATE );
	
	menu_event = reset_event;
	return null_event;
}


/**
 * 播放回铃音;
 * 设置计时器
 */
int h323_query_availability_state_receive_available_event(s_event* psEvent,
    s_task* psTask)
{
	H323TRACE("action: h323_query_availability_state_receive_available_event\n");
	
	wp_msg = (WrapperMsg *) psEvent->pMsg;
	callIndex = wp_msg->baseInfo.callIndex;
	tone_playing = ringback_tone;
	PlayTone( ringback_tone );	
	//chenguoyin
	bufferPlayTone();
	
	/*H323TRACE("Going to wait_for_connect_state\n");*/
	/* 设置等待连接计时器 */
	DeleteTimer(&h323_timer);
	h323_timer = CreateTimer(CONNECT_TIME);
	return null_event;
}

/**
 * 返回忙或进行呼叫转移
 */
int h323_dead_end_state_receive_query_availability_event(s_event* psEvent,
    s_task* psTask)
{
	H323TRACE("action: h323_dead_end_state_receive_query_availability_event\n");

	wp_msg = (WrapperMsg *) psEvent->pMsg;
	
	AppReplyNotAvailOrFwd(wp_msg);
	return null_event;
}

/**
 * 终结terminate所指通道的通话
 */
int h323_dead_end_state_receive_terminate_event(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_dead_end_state_receive_terminate_event\n");
	return null_event;
}

/**
 * 播放催挂音
 */
int h323_dead_end_state_timeout_event(s_event* psEvent, s_task* psTask)
{
	msg = (NonWrapperMsg *)psEvent->pMsg;
	if ((msg->digit != h323_timer) && (msg->digit != call_forward_timer))
		return null_event;

	H323TRACE("action: h323_dead_end_state_timeout_event\n");
	
	/* 计时器清零 */
	h323_timer = -1;

	if (congestion_timeout == 0) /* 播放催挂音 */
	{
		if (!(*menu_inuse))
		{
			LcdShowMessage(H323_HANG_UP_MSG);
		}
		/* 播放催挂音 */
		tone_playing = congestion_tone;

		PlayTone( congestion_tone );
                //chenguoyin
		//bufferPlayTone();
		/* 设置催挂音的播放时间 */
		h323_timer = CreateTimer(ONE_SEC * 60);
		congestion_timeout = 1;
	}	
	else /* 停止播放催挂音 */
	{
		tone_playing = null_tone;
		StopTone();
		//chenguoyin
		bufferStopTone();
	}
	
	return null_event;
}

/**
 * 终结,回到初始状态
 */
int h323_dead_end_state_local_on_hook_event(s_event* psEvent, s_task* psTask)
{
	H323TRACE("action: h323_dead_end_state_local_on_hook_event\n");
	
	StopTone();
	//chenguoyin
	bufferStopTone();
	/* 若为免提状态,状态不变 */
	if (on_speakerphone == TRUE)
		return to_dead_end_state;
	
	AppTerminateAction( ST_H323_DEAD_END_STATE );
	
	menu_event = reset_event;
	return null_event;
}

/**
 * 终结一路通话后,回到另一路通话状态
 */
int h323_dead_end_state_to_bidir_voice_state(s_event* psEvent, s_task* psTask)
{
	H323TRACE("action: h323_dead_end_state_to_bidir_voice_state\n");
	PreserveLcdMessage = FALSE;
	return null_event;
}

/**
 * 返回忙或进行呼叫转移
 */
int h323_wait_for_connect_state_receive_query_availability_event(s_event*
    psEvent, s_task* psTask)
{
	H323TRACE("action: h323_wait_for_connect_state_receive_query_availability_event\n");

	wp_msg = (WrapperMsg *) psEvent->pMsg;
	AppReplyNotAvailOrFwd(wp_msg);
	return null_event;
}

/**
 * (收到CFU、CFB重定向消息);
 * 向“B”发送CallRerouting.ReturnResult、terminate消息;
 * 向"C"发送divertingLegInfo2消息,产生to_query_availability_state事件;
 * 出错则产生to_dead_end_state事件
 */
int h323_wait_for_connect_state_call_forward_rcvd(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_wait_for_connect_state_call_forward_rcvd\n");

	wp_msg = (WrapperMsg *)psEvent->pMsg;
	char forwardToNumber[40];
	
	//H323TRACE("Call forward message received\n");

	PreserveLcdMessage = TRUE;
	LcdShowMessage(H323_FORWARDING_TO);	
	strncpy(forwardToNumber, wp_msg->d.CallForwardInfo.ForwardToNumber, 39);
	forwardToNumber[39] = '\0';
	WriteLcd(forwardToNumber, 1, 0);

	/* Forward has a cycle, do nothing, goto dead_end_state */
	if (wp_msg->d.CallForwardInfo.hasCycle)
	{		
		taskDelay(TASKDELAY_ONE_SEC);
		AppTerminateAction( ST_H323_WAIT_FOR_CONNECT_STATE);	
		PreserveLcdMessage = TRUE;
		LcdShowMessage(H323_CIRCULAR_TOO_MANY_FORWARD);
		PlayBusyTone(FIFTEEN_SEC);
		return to_dead_end_state;
	}
	
	/* 通知菜单复位 */
	menu_event = reset_event;
	
	/*H323TRACE("Going to query_availability_state\n");*/
	/* 设置等待响应计时器 */
	DeleteTimer(&h323_timer);
	h323_timer = CreateTimer(TEN_SEC);
	return to_query_availability_state;
}


/**
 * 终结terminate所指通道的通话
 */
int h323_wait_for_connect_state_receive_terminate_event(s_event* psEvent,
    s_task* psTask)
{
	H323TRACE("action: h323_wait_for_connect_state_receive_terminate_event\n");

	wp_msg = (WrapperMsg *) psEvent->pMsg;

	if (callIndex != wp_msg->baseInfo.callIndex)
	{
		H323TRACE("Terminate on call index %d, not current call index %d, ignored\n",
			wp_msg->baseInfo.callIndex, callIndex);
		return null_event;
	}

	if (!(*menu_inuse))
	{
		PreserveLcdMessage = TRUE;
		if(wp_msg->reason == cmCallStateModeDisconnectedReject)
		{
			LcdShowMessage(H323_REMOTE_REJECT_THE_CALL);
		}
		else
		{
			LcdShowMessage(H323_UNKNOWN_ERROR);
		}	
	}		
	AppTerminateAction( ST_H323_WAIT_FOR_CONNECT_STATE );
	PlayBusyTone(FIFTEEN_SEC);
	return to_dead_end_state;
}

/**
 * 终结当前通话,产生to_dead_end_state事件
 */
int h323_wait_for_connect_state_timeout_event(s_event* psEvent, s_task* psTask)
{	
	msg = (NonWrapperMsg *)psEvent->pMsg;
	if ((msg->digit != h323_timer) && (msg->digit != call_forward_timer))
		return null_event;

	H323TRACE("action: h323_wait_for_connect_state_timeout_event\n");
	
	h323_timer = -1;
		
	StopTone();
       //chenguoyin
       bufferStopTone();

	if (!(*menu_inuse))
	{
		PreserveLcdMessage = TRUE;
		LcdShowMessage(H323_WAIT_FOR_ANSWER_TIMEOUT);
	}		
		
	AppTerminateAction( ST_H323_WAIT_FOR_CONNECT_STATE );		
	PlayBusyTone(FIFTEEN_SEC);
	return to_dead_end_state;
}

/**
 * 收到错误消息,取消等待连接
 */
int h323_wait_for_connect_state_receive_error_event(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_wait_for_connect_state_receive_error_event\n");
	
	wp_msg = (WrapperMsg *)psEvent->pMsg;
	DeleteTimer(&h323_timer);	
	StopTone();
       //chenguoyin
       bufferStopTone();
	if (!(*menu_inuse))
	{
		PreserveLcdMessage = TRUE;			
		LcdShowMessage(H323_UNKNOWN_ERROR);
	}		
	/*H323TRACE("Wait-for-connect error, disconnecting\n");*/
		
	AppTerminateAction( ST_H323_WAIT_FOR_CONNECT_STATE );		
	PlayBusyTone(FIFTEEN_SEC);
	return to_dead_end_state;
}

/**
 * 终结,回到初始状态
 */
int h323_wait_for_connect_state_local_on_hook_event(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_wait_for_connect_state_local_on_hook_event\n");

	/* 若为免提状态,状态不变 */
	if (on_speakerphone == TRUE)
		return to_wait_for_connect_state;
	
	AppTerminateAction( ST_H323_WAIT_FOR_CONNECT_STATE );
	
	menu_event = reset_event;
	return null_event;
}

int h323_wait_for_connect_state_to_dead_end_state(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_wait_for_connect_state_to_dead_end_state\n");
	return null_event;
}

int h323_wait_for_connect_state_to_bidir_voice_state(s_event* psEvent, s_task*
    psTask)
{

	H323TRACE("action: h323_wait_for_connect_state_to_bidir_voice_state\n");
	PreserveLcdMessage = FALSE;
	return null_event;
}

/**
 * 停止播放等待铃声;
 * 发送WP_SEND_CONN_ACK,接通voice开始通话;
 * 若出错则产生to_dead_end_state事件
 */
int h323_wait_for_connect_state_receive_connect_event(s_event* psEvent, s_task*
    psTask)
{	    	
	H323TRACE("action: h323_wait_for_connect_state_receive_connect_event\n");

      
	StopTone();
	//chenguoyin
	bufferStopTone();
	wp_msg = (WrapperMsg *) psEvent->pMsg;

	appCallInfo[callIndex].ipAddr[3] = wp_msg->d.codec.remoteRtpIpAddr>> 24;
	appCallInfo[callIndex].ipAddr[2] = (wp_msg->d.codec.remoteRtpIpAddr >> 16) & 0xFF;
	appCallInfo[callIndex].ipAddr[1] = (wp_msg->d.codec.remoteRtpIpAddr >> 8) & 0xFF;
	appCallInfo[callIndex].ipAddr[0] = wp_msg->d.codec.remoteRtpIpAddr & 0xFF;
	strncpy(appCallInfo[callIndex].display, 
		wp_msg->baseInfo.display, MAX_DISPLAY_LENGTH);
	appCallInfo[callIndex].display[MAX_DISPLAY_LENGTH] = '\0';
	appCallInfo[callIndex].codec.remoteRtpIpAddr = wp_msg->d.codec.remoteRtpIpAddr;
	appCallInfo[callIndex].codec.remoteRtpPort = wp_msg->d.codec.remoteRtpPort;
	appCallInfo[callIndex].codec.rx = wp_msg->d.codec.rx;
	appCallInfo[callIndex].codec.tx = wp_msg->d.codec.tx;
		
	if(transferred_flag)
	{
		aw

⌨️ 快捷键说明

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