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

📄 thread2.cpp.bak

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

#include "stdafx.h"
#include "MyThread.h"
#include "Thread2.h"
#include <afxmt.h>
#include "smgpapi.h"
#include "smgpdef.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define RECV_MSG_TIME_OUT						1 /* Seconds */	
/////////////////////////////////////////////////////////////////////////////
// Thread2

IMPLEMENT_DYNCREATE(Thread2, CWinThread)

Thread2::Thread2()
{
		m_stop_state=false;//线程停止标志
		m_active1=false;
		m_pDlg=NULL;
		m_thread3=NULL;
		m_thread1=NULL;
		m_connection=NULL;
}

Thread2::~Thread2()
{
}

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

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

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

/////////////////////////////////////////////////////////////////////////////
// Thread2 message handlers

void Thread2::GetOwner(CMyThreadDlg *m_pOwner,Thread3* pThread3,Thread1*pThread1)
{
	m_pDlg=m_pOwner;
	m_thread3=pThread3;
	m_thread1=pThread1;
}

int Thread2::Run()
{
	int res=-1;
	CTime t;
	char time1[17];
	int 	nRetCode;
	DeliverResp m_del;
	CString phone,content,srcPhone, buffer;
	CString command;
	FILE*file;
	char f_name[30],spid[18];
	//while(!m_stop_state)//
	while(!m_active1)
	{
	m_pDlg->g_cs.Lock();
	m_active1=m_pDlg->m_active;
	m_pDlg->g_cs.Unlock();
	if(!m_stop_state) Sleep(1000);
	else break;
	}
	m_pDlg->AddString("开始Thread2");
	try
	{
			m_recordset.CreateInstance("ADODB.Recordset");
	}
	catch(_com_error e)
 	{
		m_pDlg->AddString("Thread2创建数据集失败!");
 		return FALSE;
 	}

	while(!m_stop_state)
	{
		memset(&m_del,0,sizeof(SMGP_Deliver));	
		nRetCode = SMGPDeliver((int)RECV_MSG_TIME_OUT,&m_del);
		if(nRetCode)
		{
			/* You Can Process Error Here */
			Sleep(50);
			continue;
		}
		/* Post Message To Application Thread */
		else 
		{
				t = CTime::GetCurrentTime();
				res=1;
				if(m_del.nIsReport==1)  res=4;
				//Sleep(10);
				if(res==1)
				{
				sprintf(time1,"%d%02d%02d%02d%02d%02d",t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond());
				srcPhone.Empty();
				srcPhone=srcPhone+m_del.sSrcTermID;
				phone.Empty();
				phone=phone+m_del.sDestTermID;
				content.Empty();
				content=content+m_del.sMsgContent;
				content.Replace("'","''");
					try
					{		
							memset(spid,0,18);
							memcpy(spid,phone.GetBuffer(0),phone.GetLength());
							int isTrue=0,i=0;
						    if(spid[0]=='1'&&spid[1]=='1'&&spid[2]=='8')i=3;
							if(spid[i]=='6'&&spid[i+1]=='1'&&spid[i+2]=='6'&&(spid[i+3]=='5'||spid[i+3]=='6'));
							else isTrue=-1;
							if(isTrue==-1)
							{
								command.Format("insert into db160..Sms_GW values('%s','gwdx','%s','%s','%s','2')",phone,srcPhone,content,time1);
								//hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)m_pDlg->m_connection,true),adOpenStatic,adLockOptimistic,adCmdText);
							}
							else
							{
								command.Format("insert into T_xlt_gw values('%s','%s','%s','%s')",phone,srcPhone,content,time1);
								//hr=m_recordset->Open(command.GetBuffer(0), _variant_t((IDispatch*)m_pDlg->m_connection,true),adOpenStatic,adLockOptimistic,adCmdText);
							}
							m_pDlg->m_connection->Execute(command.GetBuffer(0),&RecordsAffected,adCmdText);
					
							sprintf(f_name,"log/2Thread%d%02d%02dok.txt",t.GetYear(),t.GetMonth(),t.GetDay());
							buffer.Format("%s,%s,%s,%s,%d\n",srcPhone,phone,time1,content,res);
							if((file=fopen(f_name,"a"))==NULL) continue;
							fwrite(buffer.GetBuffer(0),sizeof(char),buffer.GetLength(),file);
							fclose(file);
					}//try
					catch(_com_error e)
 					{
					m_pDlg->AddString("Thread2操作数据库失败");	
					sprintf(f_name,"log/2Thread%d%02d%02dfail.txt",t.GetYear(),t.GetMonth(),t.GetDay());
					if((file=fopen(f_name,"a"))==NULL) continue;
					buffer.Empty();
					buffer.Format("%s,%s,%s,%s,%d\n",srcPhone,phone,time1,content,res);
					fwrite(buffer.GetBuffer(0),sizeof(char),buffer.GetLength(),file);
					fclose(file);
 					}
				}//res=1;
				else
				{
				sprintf(f_name,"log/2Thread%d%02d%02dreport.txt",t.GetYear(),t.GetMonth(),t.GetDay());
				buffer.Format("%s,%s,%s,%s,%d\n",srcPhone,phone,time1,content,res);
				if((file=fopen(f_name,"a"))==NULL) continue;
				fwrite(buffer.GetBuffer(0),sizeof(char),buffer.GetLength(),file);
				fclose(file);
				}
		}
	}//while
if(m_recordset->State)m_recordset->Close();
m_recordset=NULL;
m_pDlg->AddString("thread2退出");
//m_thread1->m_stop_state=true;
return 0;
}

⌨️ 快捷键说明

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