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

📄 thread3.cpp

📁 电信短信应用smgp1.3协议网关,中兴开发包
💻 CPP
字号:
// Thread3.cpp : implementation file
//

#include "stdafx.h"
#include "MyThread.h"
#include "Thread3.h"
#include "smgpapi.h"
#include "smgpdef.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Thread3

IMPLEMENT_DYNCREATE(Thread3, CWinThread)

Thread3::Thread3()
{
	m_stop_state=false;
	m_pDlg=NULL;
	m_active1=false;//true收到test
}

Thread3::~Thread3()
{
}

BOOL Thread3::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	return TRUE;
}

int Thread3::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(Thread3, CWinThread)
	//{{AFX_MSG_MAP(Thread3)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Thread3 message handlers
void Thread3::GetOwner(CMyThreadDlg *m_pOwner)
{
	m_pDlg=m_pOwner;
//	m_conn_status=false;
}


int Thread3::Run()
{
	int res=-1;
	int i=0;
	int j=0;
	int nErrorCode;
	res=InitSMGPAPI(NULL);
	if (res!=0)
	{
		m_pDlg->AddString("thread3连接失败");
		return 0;
	}
	//m_pDlg->g_cs.Lock();
	//m_pDlg->m_active=true;
	//m_pDlg->g_cs.Unlock();
    m_pDlg->AddString("Thread3 开始");
	//Sleep(2000);
	while(!m_stop_state)
	{
		m_pDlg->g_cs.Lock();
		m_active1=m_pDlg->m_active;
		m_pDlg->g_cs.Unlock();
		if((!m_active1)||(j==0))
		{
			j=1;i=0;
			while(i<3)
			{
	//			m_pDlg->AddString("active test!");
				res=SMGPActiveTest(&nErrorCode);
				if(res==0)
				{
					m_active1=true;
					m_pDlg->g_cs.Lock();
					m_pDlg->m_active=true;
					m_pDlg->g_cs.Unlock();
					break;
				} else  Sleep(500);
				i++;
				if(i==3) 
				{
					m_pDlg->g_cs.Lock();
					m_pDlg->m_active=false;
					m_pDlg->g_cs.Unlock();
					m_active1=false;
					CString result;
 					result.Format("Thread3 active test Err=%d,res=%d",nErrorCode,res);
 					m_pDlg->AddString((char*)result.GetBuffer(0));
					Sleep(3000);
				}
			}//while i
			while((!m_active1)&&(!m_stop_state))
			{
				res=InitSMGPAPI(NULL);
				if (res!=0)
				{
					m_active1=false;
					m_pDlg->AddString("thread3连接失败");
					//m_Operate->Smgp_exit();
					Sleep(3000);
				}
				else 
				{
					m_pDlg->AddString("thread3连接成功");
					/*m_pDlg->g_cs.Lock();
					m_pDlg->m_active=true;
					m_pDlg->g_cs.Unlock();*/
					Sleep(500);
					break;
				}
			}
			if(m_active1==false) j=0;
		}//((!m_active1)||(j==0))
		else
		{
			j=(j+1)%18;
			Sleep(10000);
		}
	}//m_stop_state
	m_pDlg->AddString("thread3退出");
	return 0;
}

⌨️ 快捷键说明

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