📄 cms_wapbox.c
字号:
/******************************************************************************
C M O D U L E F I L E
(c) Copyright MobileSoft Technology (NanJing) Co., LTD. 2001-2002
ALL RIGHTS RESERVED
*******************************************************************************
Project Name: WAP STACK Ver1.20
Written By : MobileSoft Technology
File Name : Cms_Malloc.c
Last Modify : 06/22/2002
******************************************************************************/
#include "string.h"
#include "Cms_WAPMain.h"
#include "Cms_WTPGLOBALVARIABLE.h"
#include "Cms_WAPGWLIB.h"
#include "Cms_WTP.h"
#include "Cms_WSP.h"
#include "Cms_WSP2WTP.h"
#include "Cms_WAPBox.h"
#include "Cms_WTPTimer.h"
#include "Cms_WAPStatus.h"
static enum
{
initializing,
running,
aborting,
aborting_with_prejudice
} run_status = initializing;
void timer_thread();
void wtp_timer_init();
CMS_VOID put_msg_in_queue(Msg *msg)
{
if (!msg)
{
return;
}
if (msg->wdp_datagram.user_data)
{
Cms_WAPSendUDP(octstr_get_cstr(msg->wdp_datagram.user_data),
(CMS_S32)octstr_len(msg->wdp_datagram.user_data));
}
msg_destroy(msg);
msg = NULL;
}
/* don't not free the space of the msg */
CMS_VOID put_msg_in_queue_2(Msg *msg)
{
if (!msg)
return;
if (msg->wdp_datagram.user_data)
{
Cms_WAPSendUDP(octstr_get_cstr(msg->wdp_datagram.user_data),
(CMS_S32)octstr_len(msg->wdp_datagram.user_data));
}
}
CMS_VOID Cms_WAPStackInit(int target)
{
if (WTPGlobalMachine)
{
wtp_machine_destroy(WTPGlobalMachine);
WTPGlobalMachine = NULL;
}
WTPGlobalMachine = wtp_machine_create(NULL, 1234L, NULL, 9201L, 0L, 2L);
if(WSPGlobalMachine)
{
wsp_machine_destroy(WSPGlobalMachine);
WSPGlobalMachine = NULL;
}
WSPGlobalMachine = wsp_machine_create();
if (NULL != WSPGlobalMachine)
{
WSPGlobalMachine->state = WSP_NULL;
}
if (NULL != WTPGlobalMachine)
{
WTPGlobalMachine->state = WTP_NULL;
}
/* 初始化时钟 */
wtp_timer_init();
WSPWorking = 0;
WTPWorking = 0;
run_status = running;
WTPGlobalMachine->up_target = target;
mms_StartTimer(10,1000); /* 修改定时器 */
return;
}
CMS_VOID Cms_UDPToWAP(P_CMS_U8 buf, CMS_S32 bytes)
{
WTPEvent *wtp_event = NULL;
Msg s_msg;
Octstr s_os;
memset(&s_msg,0,sizeof(Msg));
memset(&s_os,0,sizeof(Octstr));
if (bytes == 0)
{
return;
}
s_os.len = bytes;
s_os.data = buf;
s_msg.type = wdp_datagram;
s_msg.wdp_datagram.user_data = &s_os;
wtp_event = wtp_unpack_wdp_datagram(&s_msg);
if (wtp_event != NULL)
{
wtp_handle_event(WTPGlobalMachine, wtp_event);
}
}
CMS_S32 Cms_ConnectGateway(CMS_VOID)
{
WSPEvent * wsp_event = NULL;
wsp_event = WSPCreateSConnectRequest();
wsp_event->SConnectRequest.connect_type = 0;
wsp_handle_event(WSPGlobalMachine, wsp_event);
return 1;
}
void timer_thread()
{
int i;
if (run_status == running)
{
for ( i = 0; i < WTP_TIMER_NUMBER; i++ )
{
if( wtp_timer_check( (WTPTimer*)&WTPGlobalTimer[i] ) )
{
/* 发送相应的事件(如果超时) */
if( (WTPGlobalTimer[i].machine != NULL) && (WTPGlobalTimer[i].event != NULL) )
{
wtp_handle_event(WTPGlobalTimer[i].machine , WTPGlobalTimer[i].event );
}
}
}
}
return;
}
/* 时钟初始化 */
void wtp_timer_init(void)
{
int i;
static WTPEvent TO_Aevent;
static WTPEvent TO_Revent;
static WTPEvent TO_Wevent;
static WTPEvent TO_Nevent;
memset(&TO_Aevent,0,sizeof(WTPEvent));
memset(&TO_Revent,0,sizeof(WTPEvent));
memset(&TO_Wevent,0,sizeof(WTPEvent));
memset(&TO_Nevent,0,sizeof(WTPEvent));
for( i = 0; i < WTP_TIMER_NUMBER; i++ )
{
WTPGlobalTimer[i].machine = WTPGlobalMachine;
WTPGlobalTimer[i].interval = -1;
WTPGlobalTimer[i].start_time=0;
WTPGlobalTimer[i].event=0;
}
WTPGlobalTimer[0].event = &TO_Aevent;
WTPGlobalTimer[1].event = &TO_Revent;
WTPGlobalTimer[2].event = &TO_Wevent;
WTPGlobalTimer[3].event = &TO_Nevent;
TO_Aevent.type = TimerTO_A;
TO_Revent.type = TimerTO_R;
TO_Wevent.type = TimerTO_W;
TO_Nevent.type = TimerTO_N;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -