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

📄 sgipservicedemodlg.cpp

📁 1、自己编写的遵循SGIP1.1协议的短信客户端程序。仅供测试、学习。 2、该程序只实现了SGIP1.1协议的一部分。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SgipServiceDemoDlg.cpp : implementation file
//

#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


//CSMSSubmitRespList CSgipServiceDemoDlg::m_SMSSubmitRespList;
CSMSDeliverList CSgipServiceDemoDlg::m_SMSDeliverList;
CSMSReportList CSgipServiceDemoDlg::m_SMSReportList;

//CCriticalSection CSgipServiceDemoDlg::m_csSMSSubmitResp;
CCriticalSection CSgipServiceDemoDlg::m_csSMSDeliver;
CCriticalSection CSgipServiceDemoDlg::m_csSMSReport;

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_strEditMTMOBeginTime = _T("");
	m_strEditMTMOEndTime = _T("");
	m_bViewState = TRUE;
	m_bLogState = FALSE;
	m_iEditMTCTSPNMax = 10000;
	m_iEditMTCTSPNPerSecond = 600;
	m_iEditMOCTRPN = 0;
	m_iEditMTMORPN = 0;
	m_iEditMTMOSPN = 0;
	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("ClientConfig.ini");
	m_logFile.InitLog("ClientStateLog.txt");

	m_bStartTest = FALSE;
	m_bStartMtctTest = FALSE;

	m_iCorpID = 30012;
	m_strDestPnoneNo = "13005779990";
	m_strFeePhoneNo = "13005777777";
	m_iFeeType = 0;
	m_iFeeValue = 10;
	m_iLocalLisPort = 8801;
	m_strLocalPwd = "opnet";
	m_strLocalUserName = "opnet";
	m_strMsgContent = "This is a test sms.";
	m_iMsgFmt = MsgCode_ASCII;
	m_iMsgLevel = 0;
	m_iRepFlag = 1;
	m_strServerIP = "127.0.0.1";
	m_strServerPwd = "jingan";
	m_iServerLisPort = 9881;
	m_strServerUserName = "jingan";
	m_lSourceID = 330012;
	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;//
	m_hTMOMTAppExit = CreateEvent(NULL, FALSE, FALSE, NULL);// auto reset, initially reset;//系统退出信号量 for MOMT capacity test thread
	m_hTMOMTExit = 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_MTMOSTOP, m_BtnMTMOStop);
	DDX_Control(pDX, IDC_BTN_MTMOSTART, m_BtnMTMOStart);
	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_Text(pDX, IDC_EDIT_MTMOBEGINTIME, m_strEditMTMOBeginTime);
	DDX_Text(pDX, IDC_EDIT_MTMOENDTIME, m_strEditMTMOEndTime);
	DDX_Check(pDX, IDC_CHECK_VIEWSTATE, m_bViewState);
	DDX_Check(pDX, IDC_CHECK_LOGSTATE, m_bLogState);
	DDX_Text(pDX, IDC_EDIT_MTCTSPNMAX, m_iEditMTCTSPNMax);
	DDV_MinMaxUInt(pDX, m_iEditMTCTSPNMax, 10, 10000000);
	DDX_Text(pDX, IDC_EDIT_MTCTSPNPERSECOND, m_iEditMTCTSPNPerSecond);
	DDV_MinMaxUInt(pDX, m_iEditMTCTSPNPerSecond, 1, 1000);
	DDX_Text(pDX, IDC_EDIT_MOCTRPN, m_iEditMOCTRPN);
	DDX_Text(pDX, IDC_EDIT_MTMORPN, m_iEditMTMORPN);
	DDX_Text(pDX, IDC_EDIT_MTMOSPN, m_iEditMTMOSPN);
	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_MTMOSTART, OnBtnMtmostart)
	ON_BN_CLICKED(IDC_BTN_MTMOSTOP, OnBtnMtmostop)
	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_iCorpID = m_iniFile.GetInt("appconfig","iCorpID",m_iCorpID);
	m_strDestPnoneNo = m_iniFile.GetString("appconfig","strDestPnoneNo",m_strDestPnoneNo);
	m_strFeePhoneNo = m_iniFile.GetString("appconfig","strFeePhoneNo",m_strFeePhoneNo);
	m_iFeeType = m_iniFile.GetInt("appconfig","iFeeType",m_iFeeType);
	m_iLocalLisPort = m_iniFile.GetInt("appconfig","iLocalLisPort",m_iLocalLisPort);
	m_strFeePhoneNo = m_iniFile.GetString("appconfig","strFeePhoneNo",m_strFeePhoneNo);
	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_iMsgLevel = m_iniFile.GetInt("appconfig","iMsgLevel",m_iMsgLevel);
	m_iRepFlag = m_iniFile.GetInt("appconfig","iRepFlag",m_iRepFlag);
	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_lSourceID = (long) m_iniFile.GetInt("appconfig","lSourceID",m_lSourceID);
	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.SetInt("appconfig","iCorpID",m_iCorpID);
	m_iniFile.SetString("appconfig","strDestPnoneNo",m_strDestPnoneNo);
	m_iniFile.SetString("appconfig","strFeePhoneNo",m_strFeePhoneNo);
	m_iniFile.SetInt("appconfig","iFeeType",m_iFeeType);
	m_iniFile.SetInt("appconfig","iLocalLisPort",m_iLocalLisPort);
	m_iniFile.SetString("appconfig","strFeePhoneNo",m_strFeePhoneNo);
	m_iniFile.SetString("appconfig","strLocalUserName",m_strLocalUserName);
	m_iniFile.SetString("appconfig","strMsgContent",m_strMsgContent);
	m_iniFile.SetInt("appconfig","iMsgFmt",m_iMsgFmt);
	m_iniFile.SetInt("appconfig","iMsgLevel",m_iMsgLevel);
	m_iniFile.SetInt("appconfig","iRepFlag",m_iRepFlag);
	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","lSourceID",m_lSourceID);
	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())
			{

				m_lstrunstate.InsertItem(0, strTime);
				m_lstrunstate.SetItemText(0, 1, strContent);

				int iCount = m_lstrunstate.GetItemCount();
				if (iCount > 200)
					m_lstrunstate.DeleteItem(iCount-1);

				singleLock.Unlock();
			}
		}
		else
		{//called by main thread
			m_lstrunstate.InsertItem(0, strTime);
			m_lstrunstate.SetItemText(0, 1, strContent);

			int iCount = m_lstrunstate.GetItemCount();
			if (iCount > 200)
			m_lstrunstate.DeleteItem(iCount-1);
		}
	}

	if(m_bLogState)
		m_logFile.WriteLog(strContent);
}

void CSgipServiceDemoDlg::OnBtnStarttest() 
{
	// TODO: Add your control notification handler code here
	m_bStartTest = TRUE;
	m_BtnStartTest.EnableWindow(FALSE);
	m_BtnConfig.EnableWindow(FALSE);

	t_INIT_DEF  ini_def;
	ini_def.iLocalLisPort = m_iLocalLisPort;
	ini_def.strLocalPwd = m_strLocalPwd;
	ini_def.strLocalUserName = m_strLocalUserName;
	ini_def.iCorpID = m_iCorpID;
	ini_def.strServerIP = m_strServerIP;
	ini_def.strServerPwd = m_strServerPwd;
	ini_def.iServerLisPort = m_iServerLisPort;
	ini_def.strServerUserName = m_strServerUserName;
	ini_def.lSourceID = m_lSourceID;
	ini_def.iSPNumber = m_iSPNumber;
//	ini_def.OnSMSSubmitResp = Callback_OnSMSSubmitResp;
	ini_def.OnSMSDeliver = Callback_OnSMSDeliver;
	ini_def.OnSMSReport = Callback_OnSMSReport;

	m_SocketRes.InitSocket(ini_def);
	//////////////////

	ResetEvent(m_hTMTAppExit);
	ResetEvent(m_hTMTExit);
	ResetEvent(m_hTMOAppExit);
	ResetEvent(m_hTMOExit);
	ResetEvent(m_hTMOMTAppExit);
	ResetEvent(m_hTMOMTExit);

	ShowRunState("程序启动", 0);

	AfxBeginThread(TMtct,this);
	AfxBeginThread(TMoct,this);
	AfxBeginThread(TMomtct,this);

	m_iTestPhase = 0;

⌨️ 快捷键说明

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