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

📄 mosmgpthread.cpp

📁 小灵通网关服务程序.运行稳定.效果好.大家都可以来下载.
💻 CPP
字号:
// MOSmgpThread.cpp : 实现文件
//

#include "stdafx.h"
#include "MOSmgpService.h"
#include "MOSmgpThread.h"
using namespace SMS;
static UINT_PTR		lpTimerID=0;
static int iCount=0;
// MOSmgpThread

IMPLEMENT_DYNCREATE(CMOSmgpThread, CWinThread)

CMOSmgpThread::CMOSmgpThread()
{
}

CMOSmgpThread::~CMOSmgpThread()
{
	SMGP_Exit_MO();
}
void SocketTraceMO1(CString str){
	str+= "\r\n";
	CString strFilename = "c:\\mosmgp.txt";	
	CFileStatus status;
	CTime time = CTime::GetCurrentTime();
	CString strTime;
	strTime.Format("*******%04d-%02d-%02d %02d:%02d:%02d ****",
		time.GetYear(),time.GetMonth(),time.GetDay(),
		time.GetHour(),time.GetMinute(),time.GetSecond());

	if(CFile::GetStatus(strFilename,status)){
		try{
			CFile f(strFilename,CFile::modeReadWrite|CFile::modeNoTruncate);
			f.SeekToEnd();
			f.Write(strTime.GetBuffer(0),strTime.GetLength());
			f.Write(str.GetBuffer(0),str.GetLength());
			f.Close();
		}
		catch(...){
			CFile::Remove(strFilename);
		}
	}
	else{
		CFile f(strFilename,CFile::modeCreate|CFile::modeWrite);
		f.Write(strTime.GetBuffer(0),strTime.GetLength());
		f.Write(str.GetBuffer(0),str.GetLength());
		f.Close();
	}	
	//#endif
}
static void CALLBACK myTimerFunction(HWND hWnd,UINT uID,UINT_PTR pID,DWORD dwPar)
{
	CString m_strServiceName="TELEMOService";
	//	SocketTraceMO1("IN PUT TELEMOSERVIEC TIMEER>>>>>>>>>>>>>>>>>>>>>");
	KillTimer(NULL,lpTimerID);
	//CMPP_ActiveTest_MO();

	if(!SMGP_ActiveTest_MO())
	{   
		SocketTraceMO1("SMGP_ACTIVETEST_MO ERROR<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<,");
		SocketTraceMO1("no connect");
		iCount++;
		CString strMyMsg;			
		ServiceStatus enStatus;		
		/*if(::ServiceStart(m_strServiceName)!=ERROR_OK)AfxMessageBox("启动失败");*/
		int iStatus = ::GetServiceStatus(m_strServiceName,enStatus);		
		strMyMsg.Format("This service errcode is %d",enStatus);
		SocketTraceMO1(strMyMsg);
		//CMPP_Send(MyReg::GetYidongUsername(),MyReg::GetYidongPassword(),MyReg::GetYidongIP(),MyReg::GetYidongPort(),"13873162100",strMyMsg,MyReg::GetPayTypeYidong());
		if(iCount>5){
			SocketTraceMO1("stop service telemoservice");
			::ServiceStop(m_strServiceName);
		}
		else{
			lpTimerID = SetTimer(hWnd,118,1000,myTimerFunction);//重新定时
		}
	}
	else
	{
	 SocketTraceMO1("SMGP_ACTIVETEST_MO SUCCESS!!!!>>>>>>>>>>>>>>>");
		iCount=0;
	
		lpTimerID = SetTimer(hWnd,118,10*1000,myTimerFunction);//重新定时
	}
}
BOOL CMOSmgpThread::InitInstance()
{
    //SocketTraceMO1("IN PUT INITINSTANCE MOSMGP<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
	CString strClientID,strPassword,strServerIP,strLocalIP;
	UINT uServerPort=MyReg::GetPHSMtPort();
	strClientID="xiaofang";
	strPassword="1234";
	strServerIP=MyReg::GetPHSServerIP();
	//AfxMessageBox(strServerIP);
	strLocalIP=MyReg::GetClientPath();
	///////////////////
	CString strMsg;
	CTime time = CTime::GetCurrentTime();
	strMsg.Format("************ %04d-%02d-%02d %02d:%02d:%02d ***",
		time.GetYear(),time.GetMonth(),time.GetDay(),
		time.GetHour(),time.GetMinute(),time.GetSecond());
	SocketTraceMO1(strMsg);
	/////////////////////////////////////////////////////////////////////???????????????????????????
	BOOL bOK = this->m_wndListen.Create();
	strMsg.Format("Listen Window Create %s",bOK?"Success":"Failed");
	//////////////////////////////////////////////////////////////////////////????????????????????
	SocketTraceMO1(strMsg);
	// int iCode=SMGP_Login_MO(MyReg::GetPHSIcpID(),MyReg::GetPHSIcpPwd(),MyReg::GetPHSServerIP(),MyReg::GetPHSMoPort(),this->m_wndListen.GetSafeHwnd());
	//int iCode=SMGP_Login_MO(strClientID,strPassword,strServerIP,uServerPort,this->m_wndListen.GetSafeHwnd(),strLocalIP);
	int iCode=SMGP_Login_MO(MyReg::GetPHSIcpID(),MyReg::GetPHSIcpPwd(),MyReg::GetPHSServerIP(),MyReg::GetPHSMoPort(),this->m_wndListen.GetSafeHwnd(),MyReg::GetClientPath());
	//SocketTraceMO1("InitInstance");
	//MyReg::GetPHSIcpID(),MyReg::GetPHSIcpPwd(),MyReg::GetPHSServerIP(),MyReg::GetPHSMtPort(),MyReg::GetClientPath()
	strMsg.Format("SMGP_Login_MO Result: %s",::GetSmgpError(iCode));
	SocketTraceMO1(strMsg);	
	lpTimerID=SetTimer(NULL,118,1000,myTimerFunction);
	return TRUE;
}




int CMOSmgpThread::ExitInstance()
{
	// TODO: 在此执行任意逐线程清理
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CMOSmgpThread, CWinThread)
END_MESSAGE_MAP()


// MOSmgpThread 消息处理程序

⌨️ 快捷键说明

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