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

📄 sgipservicedemodlg.cpp

📁 **SgipSmg: 1、自己编写的遵循SGIP1.1的短信网关模拟程序。仅供测试、学习。 2、该程序只实现了SGIP1.1协议的一部分。 **声明: 1、用于商业目的之前必
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SgipServiceDemoDlg.cpp : implementation file
//
///////////////////////////
//由于本程序是在《sgip客户端测试》基础上修改而来,所以部分变量或函数的名称
//没有修改,特别是有关“MT”“MO”的名称。
///////////////////////////

#include "stdafx.h"
#include "SgipServiceDemo.h"
#include "SgipServiceDemoDlg.h"
#include "SgipProcThread.h"
#include "DlgConfig.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CSMSSubmitList CSgipServiceDemoDlg::m_SMSSubmitList;

CCriticalSection CSgipServiceDemoDlg::m_csSMSSubmit;

int CSgipServiceDemoDlg::m_iTestPhase = -1;

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSgipServiceDemoDlg dialog

CSgipServiceDemoDlg::CSgipServiceDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSgipServiceDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSgipServiceDemoDlg)
	m_strEditMOCTBeginTime = _T("");
	m_strEditMOCTEndTime = _T("");
	m_strEditMTCTBeginTime = _T("");
	m_strEditMTCTEndTime = _T("");
	m_bViewState = TRUE;
	m_bLogState = FALSE;
	m_iEditMTCTRPN = 0;
	m_iEditMOCTSPNMax = 10000;
	m_iEditMOCTSPNPerSecond = 600;
	m_bWaitResp = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_iniFile.SetFileName("SmgConfig.ini");
	m_logFile.InitLog("SmgStateLog.txt");

	m_bStartTest = FALSE;
	m_bStartMoctTest = FALSE;

	m_strOrgPhoneNo = "13005779990";
	m_iLocalLisPort = 9881;//8801;
	m_strLocalPwd = "jingan";//"opnet";
	m_strLocalUserName = "jingan";//"opnet";
	m_strMsgContent = "This is a test deliver sms.";
	m_iMsgFmt = MsgCode_ASCII;
	m_strServerIP = "127.0.0.1";
	m_iServerLisPort = 8801;//9881;
	m_strServerPwd = "opnet";
	m_strServerUserName = "opnet";
	m_iSPNumber = 449;

	ReadConfigInfo();

	m_hTMTAppExit = CreateEvent(NULL, FALSE, FALSE, NULL);// auto reset, initially reset;//系统退出信号量 for MT capacity test thread
	m_hTMTExit = CreateEvent(NULL, FALSE, FALSE, NULL);// auto reset, initially reset;//
	m_hTMOAppExit = CreateEvent(NULL, FALSE, FALSE, NULL);// auto reset, initially reset;//系统退出信号量 for MO capacity test thread
	m_hTMOExit = CreateEvent(NULL, FALSE, FALSE, NULL);// auto reset, initially reset;//
}

void CSgipServiceDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSgipServiceDemoDlg)
	DDX_Control(pDX, IDC_BTN_MTCTSTOP, m_BtnMTCTStop);
	DDX_Control(pDX, IDC_BTN_CONFIG, m_BtnConfig);
	DDX_Control(pDX, IDC_BTN_STOPTEST, m_BtnStopTest);
	DDX_Control(pDX, IDC_LST_RUNSTATE, m_lstrunstate);
	DDX_Control(pDX, IDC_BTN_STARTTEST, m_BtnStartTest);
	DDX_Control(pDX, IDC_BTN_MOCTSTOP, m_BtnMOCTStop);
	DDX_Control(pDX, IDC_BTN_MOCTSTART, m_BtnMOCTStart);
	DDX_Control(pDX, IDC_BTN_MTCTSTART, m_BtnMTCTStart);
	DDX_Text(pDX, IDC_EDIT_MOCTBEGINTIME, m_strEditMOCTBeginTime);
	DDX_Text(pDX, IDC_EDIT_MOCTENDTIME, m_strEditMOCTEndTime);
	DDX_Text(pDX, IDC_EDIT_MTCTBEGINTIME, m_strEditMTCTBeginTime);
	DDX_Text(pDX, IDC_EDIT_MTCTENDTIME, m_strEditMTCTEndTime);
	DDX_Check(pDX, IDC_CHECK_VIEWSTATE, m_bViewState);
	DDX_Check(pDX, IDC_CHECK_LOGSTATE, m_bLogState);
	DDX_Text(pDX, IDC_EDIT_MTCTRPN, m_iEditMTCTRPN);
	DDX_Text(pDX, IDC_EDIT_MOCTSPNMAX, m_iEditMOCTSPNMax);
	DDV_MinMaxUInt(pDX, m_iEditMOCTSPNMax, 10, 10000000);
	DDX_Text(pDX, IDC_EDIT_MOCTSPNPERSECOND, m_iEditMOCTSPNPerSecond);
	DDV_MinMaxUInt(pDX, m_iEditMOCTSPNPerSecond, 1, 1000);
	DDX_Check(pDX, IDC_CHECK_WAITRESP, m_bWaitResp);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSgipServiceDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CSgipServiceDemoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_MTCTSTART, OnBtnMtctstart)
	ON_BN_CLICKED(IDC_BTN_MOCTSTART, OnBtnMoctstart)
	ON_BN_CLICKED(IDC_BTN_MOCTSTOP, OnBtnMoctstop)
	ON_BN_CLICKED(IDC_BTN_STARTTEST, OnBtnStarttest)
	ON_BN_CLICKED(IDC_BTN_CONFIG, OnBtnConfig)
	ON_BN_CLICKED(IDC_BTN_STOPTEST, OnBtnStoptest)
	ON_BN_CLICKED(IDC_CHECK_VIEWSTATE, OnCheckViewstate)
	ON_BN_CLICKED(IDC_CHECK_LOGSTATE, OnCheckLogstate)
	ON_BN_CLICKED(IDC_BTN_MTCTSTOP, OnBtnMtctstop)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_CHECK_WAITRESP, OnCheckWaitresp)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_UPDATE_DLGDATA,Dlg_OnUpdateData) 
	ON_MESSAGE(WM_USER_REINITSOCKET,OnReInitSocket) 
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSgipServiceDemoDlg message handlers

BOOL CSgipServiceDemoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_lstrunstate.InsertColumn(0, "时间", LVCFMT_LEFT, 100);
	m_lstrunstate.InsertColumn(1, "状态信息", LVCFMT_LEFT, 360);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSgipServiceDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSgipServiceDemoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSgipServiceDemoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

LRESULT CSgipServiceDemoDlg::Dlg_OnUpdateData(WPARAM TrueOrFalse, LPARAM Len)//响应updatedata message
{
	switch(TrueOrFalse)
	{
	case 0:
		UpdateData(FALSE);
		break;
	case 1:
		UpdateData(TRUE);
		break;
	default:
		return -1L;
		break;
	}
	return 0L;
}

LRESULT CSgipServiceDemoDlg::OnReInitSocket(WPARAM wParam, LPARAM lParam)
{
	m_SocketRes.ReInitSocket();
	return 0L;
}
////////////////////////////////////////////////////////////////////////////
//function:Read the config info from the ini file.
//input:
//return: 0       ok 
//        other   error
////////////////////////////////////////////////////////////////////////////
int CSgipServiceDemoDlg::ReadConfigInfo()
{
	int iRet = 0;

	m_strOrgPhoneNo = m_iniFile.GetString("appconfig","strOrgPnoneNo",m_strOrgPhoneNo);
	m_iLocalLisPort = m_iniFile.GetInt("appconfig","iLocalLisPort",m_iLocalLisPort);
	m_strLocalUserName = m_iniFile.GetString("appconfig","strLocalUserName",m_strLocalUserName);
	m_strMsgContent = m_iniFile.GetString("appconfig","strMsgContent",m_strMsgContent);
	m_iMsgFmt = m_iniFile.GetInt("appconfig","iMsgFmt",m_iMsgFmt);
	m_strServerIP = m_iniFile.GetString("appconfig","strServerIP",m_strServerIP);
	m_strServerPwd = m_iniFile.GetString("appconfig","strServerPwd",m_strServerPwd);
	m_iServerLisPort = m_iniFile.GetInt("appconfig","iServerLisPort",m_iServerLisPort);
	m_strServerUserName = m_iniFile.GetString("appconfig","strServerUserName",m_strServerUserName);
	m_iSPNumber = m_iniFile.GetInt("appconfig","iSPNumber",m_iSPNumber);

	return iRet;
}

////////////////////////////////////////////////////////////////////////////
//function:Write the config info from the ini file.
//input:
//return: 0       ok 
//        other   error
////////////////////////////////////////////////////////////////////////////
int CSgipServiceDemoDlg::WriteConfigInfo()
{
	int iRet = 0;
	
	m_iniFile.SetString("appconfig","strOrgPnoneNo",m_strOrgPhoneNo);
	m_iniFile.SetInt("appconfig","iLocalLisPort",m_iLocalLisPort);
	m_iniFile.SetString("appconfig","strLocalUserName",m_strLocalUserName);
	m_iniFile.SetString("appconfig","strMsgContent",m_strMsgContent);
	m_iniFile.SetInt("appconfig","iMsgFmt",m_iMsgFmt);
	m_iniFile.SetString("appconfig","strServerIP",m_strServerIP);
	m_iniFile.SetString("appconfig","strServerPwd",m_strServerPwd);
	m_iniFile.SetInt("appconfig","iServerLisPort",m_iServerLisPort);
	m_iniFile.SetString("appconfig","strServerUserName",m_strServerUserName);
	m_iniFile.SetInt("appconfig","iSPNumber",m_iSPNumber);
	return iRet;
}

////////////////////////////////////////////////////////////////////////////
//function:show the app running state
//input: strContent--Msg Content  
//       iWhoCall  --0 in main thread , 1 in worker thread
//return:
//note:
//    iWhoCall: try to avoid making the main thread meet a lock!
////////////////////////////////////////////////////////////////////////////
void CSgipServiceDemoDlg::ShowRunState(CString strContent,int iWhoCall)
{
	if(m_bViewState)
	{
		CTime tCurTime = CTime::GetCurrentTime();
		CString strTime = tCurTime.Format("%m-%d  %H:%M:%S");
		if(1 == iWhoCall)
		{
			CSingleLock singleLock(&m_csShowRunstate);
			if(singleLock.Lock()&&singleLock.IsLocked())
			{

⌨️ 快捷键说明

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