Beispiel #1
0
BOOL
ProgressUIThread::InitInstance ()
{
  try
    {
      ProgressUIDialog * pDlg = new ProgressUIDialog;
      m_pMainWnd = pDlg;
      MIKTEX_ASSERT (hParentWindow == 0 || IsWindow(hParentWindow));
      CWnd * pWnd = 0;
      if (hParentWindow != 0)
	{
	  pWnd = CWnd::FromHandle(hParentWindow);
	}
      BEGIN_USE_MY_RESOURCES()
	{
	  if (! pDlg->Create(IDD_PROGRESS, pWnd))
	    {
	      FATAL_WINDOWS_ERROR ("CDialog::Create", 0);
	    }
	}
      END_USE_MY_RESOURCES();
      hWindow = pDlg->GetSafeHwnd();
      MIKTEX_ASSERT (hWindow != 0);
      pReadyEvent->SetEvent ();
      return (TRUE);
    }
  catch (const exception &)
    {
      return (FALSE);
    }
}
Beispiel #2
0
UINT Cappacketlivethread(LPVOID pParam)//抓包线程函数
{
	//CMainFrame *p_frame=(CMainFrame*)AfxGetMainWnd();
	//int m_exsn=p_frame->m_myprosheet.m_page2.m_thread_num;
	//int m_stoptime=p_frame->m_myprosheet.m_page2.m_stoptime;
	//int m_thread_index=0;
	for(int i=0;i<m_mystruct.m_packetlimit;i++)//线程数目
	{	
		if (::WaitForSingleObject(m_stoptimeup,0)==WAIT_OBJECT_0)
		{
			//m_thread_index=i;
			m_mystruct.m_count=i;
			break;
		} 
        pcap_next_ex(m_mystruct.pcap_handle,&m_mystruct.protocol_header,&m_mystruct.pkt_data);//句柄,协议头,数据包
		if ((m_mystruct.protocol_header->len)>m_mystruct.m_pl)//判断是否在规定长度以内
		{	
			i--;
			continue;
		}  
		pcap_dump((u_char*)m_mystruct.dumpfile,m_mystruct.protocol_header,m_mystruct.pkt_data);
		m_mystruct.m_count=i;
	} 
	m_eventEnd.SetEvent();
	return 0;
}
Beispiel #3
0
void COscillDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
////////////////////////////// Close Serialport //////////////////////////////
	
	
//////////////////////////////////////////////////////////////////////////////

	m_bRecvThreadRunning = false;
	g_eventCommRecv.SetEvent();
	if(	WAIT_OBJECT_0 != WaitForSingleObject( m_pRecvThread->m_hThread, 100 ) )
	{
		if ( FALSE == TerminateThread( m_pRecvThread->m_hThread, -2 ) )
		{
			TRACE( "Terminate RecvThread Failure\r\n" );
//			ShowLastError( TEXT( "TerminateThread[RecvThread]" ) );
		}
		else
		{
			TRACE( "RecvThread has been terminated!(-2)\r\n" );
		}
	}
	
	g_COGL.m_bDspyThreadRunning = false;
	g_eventDspy.SetEvent();
	
	//glClear would cost 30-80ms
	if(	WAIT_OBJECT_0 !=							
		WaitForSingleObject( g_COGL.m_pDspyThread->m_hThread, 100 ) )	
	{
		if ( FALSE == TerminateThread( g_COGL.m_pDspyThread->m_hThread, -1 ) )
		{
			TRACE( "Terminate DspyThread Failure\r\n" );
//			ShowLastError( TEXT( "TerminateThread[DspyThread]" ) );
		}
		else
		{
			TRACE( "DspyThread has been terminated!(-1)\r\n" );
		}
	}
	
	delete g_psQueue;
	
	CDialog::OnClose();
}
	virtual void OnPacketReceived( CTCPPacket *pPacket )
	{
		if ( g_ClientPacket.Count() < pPacket->GetLen() )
			g_ClientPacket.SetSize( pPacket->GetLen() );
		
		memcpy( g_ClientPacket.Base(), pPacket->GetData(), pPacket->GetLen() );
		g_ClientPacketEvent.SetEvent();
		pPacket->Release();
	}
Beispiel #5
0
void VMPI_DeletePortalMCSocket()
{
	// Stop the thread if it exists.
	if ( g_hMCThread )
	{
		g_MCThreadExitEvent.SetEvent();
		WaitForSingleObject( g_hMCThread, INFINITE );
		CloseHandle( g_hMCThread );
		g_hMCThread = NULL;
	}

	if ( g_pPortalMCSocket )
	{
		g_pPortalMCSocket->Release();
		g_pPortalMCSocket = NULL;
	}
}
CDownloadTask::~CDownloadTask()
{
	BOOL bCOM = SUCCEEDED( OleInitialize( NULL ) );

	Transfers.m_pSection.Lock();

	if ( Downloads.Check( m_pDownload ) )
		m_pDownload->OnTaskComplete( this );

	CEvent* pEvent = m_pEvent;
	Transfers.m_pSection.Unlock();
	if ( pEvent )
		pEvent->SetEvent();

	delete m_pRequest;

	if ( bCOM )
		OleUninitialize();
}
Beispiel #7
0
void COscillDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	g_eventCommRecv.SetEvent();
//	WaitForSingleObject( m_pRecvThread->m_hThread, INFINITE );
/*
	static int m = 0;
	static int noldPos = 0;

	INSQueue( g_psQueue, g_nTest[m] - 100 );
	m = ( m + 1 ) % 200;
	
	// There are still a problem is that when  
	// m_nSampPerFrame is greater than MAX_SAMP_RECORD. 
	// Temporarily ignored.
	m_nXCnt++;
	if ( m_nXCnt >= m_nSampPerFrame )
	{
		m_nXCnt %= m_nSampPerFrame;
	}
	
	m_nNumOfDiv = ( g_psQueue->num - m_nXCnt ) / ( m_nSampPerFrame / 12 );
	m_ctrlSbDrawFrame.SetScrollRange( 0, m_nNumOfDiv );
	
	noldPos = m_ctrlSbDrawFrame.GetScrollPos();
	m_ctrlSbDrawFrame.SetScrollPos( m_nNumOfDiv, FALSE );

	if ( noldPos != m_nNumOfDiv )
	{
		m_nQueueRearOffset = 0;
		UpdateFrame( CLEAR );
	}
	else
	{
		UpdateFrame( BASIC );
	}
*/	
	CDialog::OnTimer(nIDEvent);

}
Beispiel #8
0
int CMMCApp::ExitInstance()
{
	

	try
	{

		if (GetSockStatus()==0)
		{
			TRACE("关闭");
			//SetSockCloseNei();
			EventExit.SetEvent();
		}


		//delete global_socket;

		TRACE("进程即将退出");
		LC_ConnectionOper(2);

	}
	catch (CMemoryException* e)
	{
		
	}
	catch (CFileException* e)
	{
	}
	catch (CException* e)
	{
	}
	catch(...)
	{

	}
	
	

	return CWinApp::ExitInstance();
}
/*
*********************************************************
* PROCESS THE DATA AND SHARE THEM WITH OTHER SOFTWARE.
*********************************************************
*/
void CDataProcess::DataProcess(){
	if(COMM_SHAREDMEM == g_CommunicationSel){
		//USING SHARED MEMERY.
		BOOL bTimeout = gEventRecv.Lock(INFINITE);
		UploadData();
		gEventRecv.Unlock();
		gEventSend.SetEvent();//SEND DATA.
	}
	else if(COMM_NETWORK == g_CommunicationSel){
		//USING TCP
		//UploadData();
		//gEventSend.SetEvent();

		//TELL THE SERVER TO SEND THE DATA
		SetEvent(h_eSingleSpectraSending);
	}
	else if(COMM_NONE == g_CommunicationSel){
		//SetEvent(h_eSingleSpectraSending);
		global.series_fifo.append(rq);
	    
	}
}
UINT CProcessPaste::MarkAsPastedThread(LPVOID pParam)
{
	DWORD startTick = GetTickCount();

	static CEvent UpdateTimeEvent(TRUE, TRUE, _T("Ditto_Update_Clip_Time"), NULL);
	UpdateTimeEvent.ResetEvent();

	Log(_T("Start of MarkAsPastedThread"));

	//If running from a U3 device then wait a little before updating the db
	//updating the db can take a second or two and it delays the act of pasting
	if(g_Opt.m_bU3)
	{
		Sleep(350);
	}

	BOOL bRet = FALSE;
	int clipId = 0;

	try
	{
		MarkAsPastedData* pData = (MarkAsPastedData*)pParam;
		if(pData)
		{
			clipId = pData->clipId;
			if(g_Opt.m_bUpdateTimeOnPaste)
			{
				try
				{
					if(pData->pastedFromGroup)
					{
						CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipGroupOrder FROM Main ORDER BY clipGroupOrder DESC LIMIT 1"));

						if(q.eof() == false)
						{
							double latestDate = q.getFloatField(_T("clipGroupOrder"));
							latestDate += 1;

							Log(StrF(_T("Setting clipId: %d, GroupOrder: %f"), pData->clipId, latestDate));

							theApp.m_db.execDMLEx(_T("UPDATE Main SET clipGroupOrder = %f where lID = %d;"), latestDate, pData->clipId);

							theApp.RefreshClipOrder(pData->clipId);
						}
					}
					else
					{
						CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipOrder FROM Main ORDER BY clipOrder DESC LIMIT 1"));

						if(q.eof() == false)
						{
							double latestDate = q.getFloatField(_T("clipOrder"));
							latestDate += 1;

							Log(StrF(_T("Setting clipId: %d, order: %f"), pData->clipId, latestDate));

							theApp.m_db.execDMLEx(_T("UPDATE Main SET clipOrder = %f where lID = %d;"), latestDate, pData->clipId);

							theApp.RefreshClipOrder(pData->clipId);
						}
					}
				}
				CATCH_SQLITE_EXCEPTION
			}

			try
			{
				theApp.m_db.execDMLEx(_T("UPDATE Main SET lastPasteDate = %d where lID = %d;"), (int)CTime::GetCurrentTime().GetTime(), pData->clipId);
			}
			CATCH_SQLITE_EXCEPTION

			delete pData;
			bRet = TRUE;
		}
	}
	CATCH_SQLITE_EXCEPTION

	Log(_T("End of MarkAsPastedThread"));

	DWORD endTick = GetTickCount();
	if((endTick-startTick) > 350)
		Log(StrF(_T("Paste Timing MarkAsPastedThread: %d, ClipId: %d"), endTick-startTick, clipId));

	UpdateTimeEvent.SetEvent();
	return bRet;
}
Beispiel #11
0
extern "C" _declspec(dllexport) int __stdcall SetSockClose()

{

	try
	{



		TRACE("调用SetSockClose1");

		if (GetSockStatus()!=0)
		{
			return 0;
		}




		if (g_socketServer != INVALID_SOCKET)   
		{
			//g_iClosesignal=1;////主动连接

			EventExitBack.ResetEvent();
			EventExit.SetEvent();


			//shutdown(g_socketServer,SD_SEND);
			TRACE("开始等待");
			TRACE("threadid %d",hThread);



			WaitForSingleObject(EventExitBack,THREADQUITTIME);//hThread

			CloseHandle(hThread);
			///////////////////////
			//Sleep(500);

			//_endthreadex((unsigned int)hThread);

			TRACE("等待结束");
			//Sleep(500);
			TRACE("WaitForSingleObject(hThread,INFINITE) return ...\n");   
			TRACE("子线程退出");
			delete pThreadParam;
			return 0;
		}



		return 0;



	}
	catch (CMemoryException* e)
	{
		return 30050;
		
	}
	catch (CFileException* e)
	{
		return 30051;
	}
	catch (CException* e)
	{
		return 30052;
	}
	catch(...)
	{
		return 30053;

	}




}
Beispiel #12
0
int Receive(SOCKET s)
{
	////////////////////////////////////
	//static int i=0;

	TRACE("获得一个OnReceive事件");
	//i++;
	/*BYTE * pRightEndTemp;*/

	BYTE buff[65536];
	memset(buff,0x00,65536);
	int nRead;
	nRead = recv(s,(char*)buff, 65536,0); 
	TRACE("已经接收数据 长度%d",nRead);
	switch (nRead)
	{
	case 0:
		//SetSockClose();
		//closesocket(g_socketServer);
		//UnInitSock();   

		TRACE("开始关闭连接");
		//shutdown(g_socketServer,SD_SEND);
		/*EventExit.SetEvent();*/
		THROW(1);

		return WSAGetLastError();
		//case -1:
		//	Close();
		//	break;
	case SOCKET_ERROR:
		if (GetLastError() != WSAEWOULDBLOCK) 
		{
			TRACE("收到WSAEWOULDBLOCK");
			//AfxMessageBox ("Error occurred");
			//SetSockClose();
			//UnInitSock();  
			//shutdown(g_socketServer,SD_SEND);
			/*EventExit.SetEvent();*/
			THROW(1);
			return WSAGetLastError();
		}
		else
		{
			return WSAEWOULDBLOCK;
		}

	default://接收到了数据
		TRACE("接收到了数据");

		if (global_socket->pDataEnd==&(global_socket->pRecvOriginal[0]))//缓冲区为空
		{

			memcpy(global_socket->pDataEnd,buff,nRead);
			global_socket->pDataEnd=global_socket->pDataEnd+nRead-1;
		}
		else
		{//缓冲区有数据
			memcpy(global_socket->pDataEnd+1,buff,nRead);
			global_socket->pDataEnd=global_socket->pDataEnd+1+nRead-1;//    +nRead-1;


		}

	    while(global_socket->pDataEnd-&(global_socket->pRecvOriginal[0]) > 21)
	    
		
	  {
			BYTE * pRightEndTemp;
		
		int i=global_socket->CheckWheaverHaveRightData(&pRightEndTemp);


		TRACE("调用CheckWheaverHaveRightData %d",i);
		if (i==1)//正确包

		{
			TRACE("正确数据包");

			DataReved * pDataReved=new DataReved(global_socket->pHead,pRightEndTemp);
			TRACE("组装接收对象 %d",pDataReved->routeType);
			if (pDataReved->routeType==0||pDataReved->routeType==1)//flex
			{

				/*LC_NSend("LCFlexClient","LCFlexRecvFromNetWork",4,pDataReved->byteDataRecvOrigianl,pDataReved->lengthofbyteDataRecvOrigianl);*/
				
				if (g_LCStatusFlag<=1 )
				{
					LC_NSend("_airToWeb","airToWebHandler",4,pDataReved->byteDataRecvOrigianl,pDataReved->lengthofbyteDataRecvOrigianl);
				}
				//to lC control
			}
			if (pDataReved->routeType==0||pDataReved->routeType==1)//flex
			{
				TRACE("to mm flag %d",pDataReved->flag);
				if (pDataReved->flag==1000)
				{
					TRACE("设置EventConnectFava");
					//::SetEvent(hEvent);
					if (strcmp("yes",((ConnectFava*)pDataReved->p_ToDelphiData)->status)==0)
					{ iError=0;
					TRACE("yes");

					Sleep(500);
					EventConnectFava.SetEvent();

					}
					else
					{
						TRACE("no");
						iError=30011;
						Sleep(500);

						EventConnectFava.SetEvent();

					}

				}
				if (pDataReved->flag==1012)
				{

					TRACE("设置EventConnectFava");
					//::SetEvent(hEvent);
					if (((PlayerFava*)pDataReved->p_ToDelphiData)->playerStatus==0||((PlayerFava*)pDataReved->p_ToDelphiData)->playerStatus==1)
					{ 
						//iError=((PlayerFava*)pDataReved->p_ToDelphiData)->playerStatus;
						iError=0;
						TRACE("yes");

						Sleep(500);
						EventPlayerFava1012.SetEvent();

					}
					else
					{
						TRACE("no");
						iError=30012;
						Sleep(500);

						EventPlayerFava1012.SetEvent();

					}
					//EventPlayerFava1012.SetEvent();

				}
				if (pDataReved->flag==1013)
				{

					TRACE("设置EventConnectFava");
					//::SetEvent(hEvent);
					if (((PlayerFava*)pDataReved->p_ToDelphiData)->playerSkill==0)
					{ 
						iError=((PlayerFava*)pDataReved->p_ToDelphiData)->playerSkill;
						TRACE("yes");

						Sleep(500);
						EventPlayerFava1013.SetEvent();

					}
					else
					{
						TRACE("no");
						iError=30013;
						Sleep(500);

						EventPlayerFava1013.SetEvent();

					}
					//EventPlayerFava1013.SetEvent();

				}
				if (pDataReved->flag==1014)
				{
					EventPlayerFava1014.SetEvent();

				}
				if ((pDataReved->flag!=1000)&&(pDataReved->flag!=1012)&&(pDataReved->flag!=1013)&&(pDataReved->flag!=1014))
				{//回调函数

					    TRACE("调用回调函数,%d",pDataReved->flag);
						TRACE("调用SetDataCallBack,%d",DataCallBackFunc);
						TRACE(",pDataReved->p_ToDelphiData ,%d",pDataReved->p_ToDelphiData);
					(*DataCallBackFunc)(pDataReved->flag,pDataReved->p_ToDelphiData);
					TRACE(",调用完成 pDataReved->p_ToDelphiData ,%d",pDataReved->p_ToDelphiData);


				}


			}
			delete pDataReved;

			TRACE("销毁 pDataReved");
			TRACE("调用ClearOneDataZone");
			global_socket->ClearOneDataZone(pRightEndTemp+1);

		}
		if (i==2)//找到结束符不过偏移量和长度不适合 返回最后结束符,部分清理 
		{
			global_socket->ClearOneDataZone(pRightEndTemp+1);
		}
		if (i==3)//3//超限,错误 全清
		{
			//memset(pRecvOriginal,0x00,65536);
			memset(global_socket->pRecvOriginal,0x00,65536);
			global_socket->pDataEnd=global_socket->pRecvOriginal;
			global_socket->pHead=global_socket->pRecvOriginal;
			global_socket->pRightEnd=global_socket->pRecvOriginal;
		}
		if (i==4)//4;//到有效数据结尾还没有发现结束符,数据保留
		{
           break;
		}
	  }

		
	}
}
Beispiel #13
0
/*
 * Starts data acquisition and acquires data until StopAcquisition is called (i.e., the _isRunning flag is set to false)
 * Then the data acquisition will be stopped.
 */
unsigned int DoAcquisition(LPVOID pArgs)
{
	int queueIndex = 0;
	int numChannels = NUMBER_OF_CHANNELS + (int) ENABLE_TRIGGER;
	int nPoints = NUMBER_OF_SCANS * numChannels;
	DWORD numValidBytes = nPoints * sizeof(float);
	DWORD bufferSizeBytes = (DWORD) ceil(numValidBytes / (double) MAX_USB_PACKET_SIZE) * MAX_USB_PACKET_SIZE;
	int timeOutMilliseconds = (int) ceil(2000 * (NUMBER_OF_SCANS / (double) SAMPLE_RATE_HZ));
	DWORD numBytesReceived = 0;

	//create the temporary data buffers (the device will write data into those)
	BYTE** buffers = new BYTE*[QUEUE_SIZE];
	OVERLAPPED* overlapped = new OVERLAPPED[QUEUE_SIZE];

	__try
	{
		//for each data buffer allocate a number of numValidBytes bytes
		for (queueIndex = 0; queueIndex < QUEUE_SIZE; queueIndex++)
		{
			buffers[queueIndex] = new BYTE[bufferSizeBytes];
			SecureZeroMemory(&(overlapped[queueIndex]), sizeof(OVERLAPPED));

			//create a windows event handle that will be signaled when new data from the device has been received for each data buffer
			overlapped[queueIndex].hEvent = CreateEvent(NULL, false, false, NULL);
		}

		queueIndex = 0;

		//start device
		if (!GT_Start(_hDevice))
		{
			cout << "\tError on GT_Start: Couldn't start data acquisition of device.\n";
			PrintDeviceErrorMessage();
			return 0;
		}

		//queue up the first batch of transfer requests to prevent overflow on the device
		for (queueIndex = 0; queueIndex < QUEUE_SIZE; queueIndex++)
		{
			if (!GT_GetData(_hDevice, buffers[queueIndex], bufferSizeBytes, &overlapped[queueIndex]))
			{
				cout << "\tError on GT_GetData.\n";
				PrintDeviceErrorMessage();
				return 0;
			}
		}

		queueIndex = 0;

		//continouos data acquisition
		while (_isRunning)
		{
			//wait for notification from the system telling that new data is available
			if (WaitForSingleObject(overlapped[queueIndex].hEvent, 5000) == WAIT_TIMEOUT)
			{
				cout << "\tError on data transfer: timeout occured.\n";
				PrintDeviceErrorMessage();
				return 0;
			}

			//get number of actually received bytes...
			if (!GT_GetOverlappedResult(_hDevice, &overlapped[queueIndex], &numBytesReceived, false))
			{
				cout << "\tError on data transfer: couldn't receive number of transferred bytes (GT_GetOverlappedResult() returned FALSE; Windows error code: " << GetLastError() << ")\n";
				return 0;
			}

			//...and check if we lost something (number of received bytes must be equal to the previously allocated buffer size)
			if (numBytesReceived != numValidBytes)
			{
				cout << "\tError on data transfer: samples lost.\n";
				return 0;
			}

			//to store the received data into the application data buffer at once, lock it
			_bufferLock.Lock();

			__try
			{
				//if we are going to overrun on writing the received data into the buffer, set the appropriate flag; the reading thread will handle the overrun
				_bufferOverrun = (_buffer.GetFreeSize() < nPoints);

				//store received data in the correct order (that is scan-wise, where one scan includes all channels)
				_buffer.Write((float*) buffers[queueIndex], nPoints);
			}
			__finally
			{
				//release the previously acquired lock
				_bufferLock.Unlock();
			}

			//add new GetData call to the queue replacing the currently received one
			if (!GT_GetData(_hDevice, buffers[queueIndex], bufferSizeBytes, &overlapped[queueIndex]))
			{
				cout << "\tError on GT_GetData.\n";
				PrintDeviceErrorMessage();
				return 0;
			}

			//signal processing (main) thread that new data is available
			_newDataAvailable.SetEvent();
			
			//increment circular queueIndex to process the next queue at the next loop repitition (on overrun start at index 0 again)
			queueIndex = (queueIndex + 1) % QUEUE_SIZE;
		}
	}
	__finally
	{
		cout << "Stopping device and cleaning up..." << "\n";

		//stop device
		if (!GT_Stop(_hDevice))
		{
			cout << "\tError on GT_Stop: couldn't stop device.\n";
			PrintDeviceErrorMessage();
		}

		//clean up allocated resources
		for (int i = 0; i < QUEUE_SIZE; i++)
		{
			if (WaitForSingleObject(overlapped[queueIndex].hEvent, timeOutMilliseconds) == WAIT_TIMEOUT)
				GT_ResetTransfer(_hDevice);

			CloseHandle(overlapped[queueIndex].hEvent);

			delete [] buffers[queueIndex];

			//increment queue index
			queueIndex = (queueIndex + 1) % QUEUE_SIZE;
		}

		delete [] buffers;
		delete [] overlapped;

		//reset _isRunning flag
		_isRunning = false;

		//signal event
		_dataAcquisitionStopped.SetEvent();

		//end thread
		AfxEndThread(0xdead);
	}

	return 0xdead;
}
Beispiel #14
0
void MCThreadCleanupFn()
{
	g_MCThreadExitEvent.SetEvent();
}
Beispiel #15
0
extern "C" _declspec(dllexport) int __stdcall SendSync(int flag,void * Pin)

{

	try
	{


		if (flag==1003)
		{
			if (strlen(((SingleFava*)Pin)->chatTxt)>MAXMESSAGELENGTH)
			{
				return 30030;
			}

		}

		if (GetSockStatus()!=0)
		{
			return GetSockStatus();
		}

		TRACE("调用SendSync flag:%d",flag);
		TRACE("调用SendSync flag:%d",flag);


		DWORD iErrorNo;
		DWORD iRetWait;



		g_objectCComAutoCriticalSection.Lock();
		TRACE("开始组织数据\n");
		CDataClass * pCDataClass=new CDataClass(flag,Pin);
		//global_socket->ListInPacket.push(pCDataClass);
		global_socket->ListInPacket_Push(pCDataClass);
		g_objectCComAutoCriticalSection.Unlock();
		EventSend.SetEvent();

		//global_socket.AsyncSelect(FD_WRITE);
		TRACE("数据完全生成");
		TRACE("数据完全生成 开始调用发送");
		//int i=SendPackge(g_socketServer);
		//	g_objectCComAutoCriticalSection.Unlock();
		if (flag==1000)
		{

			TRACE("1000节点 开始等待");
			TRACE("开始等待1000");
			BOOL i=EventConnectFava.ResetEvent();

			int dRet=WaitForSingleObject(EventConnectFava,RECVTIMEOUT);


			TRACE("WaitForSingleObject退出");

			if(dRet == WAIT_TIMEOUT)
			{
				TRACE("WaitForSingleObject超时");
				EventExit.SetEvent();
				return 1460;

			}
			else if(dRet == WAIT_OBJECT_0)
			{
				TRACE("WaitForSingleObject正常退出1000________________ iError: %d",iError);
				TRACE("正常退出1000________________");
				return iError;
			}






		}
		if (flag==1012)
		{

			EventPlayerFava1012.ResetEvent();

			int dRet=WaitForSingleObject(EventPlayerFava1012,RECVTIMEOUT);

			if(dRet == WAIT_TIMEOUT)
			{
				EventExit.SetEvent();
				return 1460;

			}
			else if(dRet == WAIT_OBJECT_0)
			{
				TRACE("正常退出1000________________");
				return iError;
			}



			/////////////////////////////////////////////////////////////


		}

		if (flag==1013)
		{

			EventPlayerFava1013.ResetEvent();

			int dRet=WaitForSingleObject(EventPlayerFava1013,RECVTIMEOUT);

			if(dRet == WAIT_TIMEOUT)
			{
				EventExit.SetEvent();
				return 1460;

			}
			else if(dRet == WAIT_OBJECT_0)
			{
				TRACE("正常退出1000________________");
				return iError;
			}



			/////////////////////////////////////////////////////////////


		}

		if (flag==1014)
		{
			EventPlayerFava1014.ResetEvent();

			int dRet=WaitForSingleObject(EventPlayerFava1014,RECVTIMEOUT);

			if(dRet == WAIT_TIMEOUT)
			{
				EventExit.SetEvent();
				return 1460;

			}
			else if(dRet == WAIT_OBJECT_0)
			{
				TRACE("正常退出1000________________");
				return iError;
			}



			/////////////////////////////////////////////////////////////

		}

		return 0;






	}
	catch (CMemoryException* e)
	{
		return 30050;
	}
	catch (CFileException* e)
	{
		return 30051;
	}
	catch (CException* e)
	{
		return 30052;
	}
	catch(...)
	{
		return 30053;

	}

}
Beispiel #16
0
void WINAPI ReceiveFromLC( int flag,char *lcName,char *methodName,void *ptrPara1,void *ptrPara2,void *ptrPara3)
{



	try
	{



		TRACE("ReceiveFromLC flag:%d,%s,%s",flag,lcName,methodName );

		if (strcmp(lcName,"_XSM_R3")==0)
		{

			if (DataCallBackFunc==NULL)
			{

				TRACE("DataCallBackFunc,NULL");
			}
			else
			{

				PLCControlFava* pPLCControlFava=new PLCControlFava();

				pPLCControlFava->szFlag=flag;
				pPLCControlFava->szMethodName=methodName;
				pPLCControlFava->szPara1=(char*)ptrPara1;
				pPLCControlFava->szPara2=(char*)ptrPara2;
				pPLCControlFava->szPara3=(char*)ptrPara3;

				TRACE("即将调用XSMtoR3 回调函数");
				g_objectCComAutoCriticalSection.Lock();
				(*DataCallBackFunc)(flag,(void*)pPLCControlFava);
				g_objectCComAutoCriticalSection.Unlock();
				TRACE(" 回调函数返回");

				delete pPLCControlFava;
			}


			return ;
		}

		if (strcmp(lcName,"_webToAir")==0)
		{
			TRACE("发现 _webToAir");

			if (strcmp(methodName,"webToAirHandler")==0)
			{

				TRACE("发现 webToAirHandler");
				TRACE("webToAirHandler");



				if (GetSockStatus()!=0)
				{
					TRACE("发现 不联网");
					return;
				}

				TRACE("发现 联网");
				g_objectCComAutoCriticalSection.Lock();

				CDataClass * pCDataClass=new CDataClass((BYTE*)ptrPara1);


				global_socket->ListInPacket.push(pCDataClass);
				g_objectCComAutoCriticalSection.Unlock();

				EventSendFromFlex.SetEvent();

				/*int i=SendPackge(g_socketServer);*/

				//global_socket.AsyncSelect(FD_WRITE);
				//return i;
				return;


			}




		}

		return;






	}
	catch (CMemoryException* e)
	{
			return;
	}
	catch (CFileException* e)
	{
			return;
	}
	catch (CException* e)
	{
			return;
	}
	catch(...)
	{
			return;

	}


}
Beispiel #17
0
BOOL CSampleGrabberCB::SaveBitmap(BYTE * pBuffer, long lBufferSize )
{
	HANDLE hf = CreateFile(m_szFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL,
		CREATE_ALWAYS, NULL, NULL);

	if( hf == INVALID_HANDLE_VALUE )
	{
		DWORD dwError = GetLastError();

		CString strMsg;

		strMsg.Format(_T("Create bitmap file failed ErrorCode:%d"),dwError);

//		OutputEx(LPCTSTR(strMsg));

		return 0;
	}

	//try
	//{

	// 写文件头 
	BITMAPFILEHEADER bfh;

	memset( &bfh, 0, sizeof( bfh ) );

	bfh.bfType ='MB';

	bfh.bfSize = sizeof( bfh ) + lBufferSize + sizeof( BITMAPINFOHEADER );

	bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );

	DWORD dwWritten = 0;

	WriteFile( hf, &bfh, sizeof( bfh ), &dwWritten, NULL );

	// 写位图格式
	BITMAPINFOHEADER bih;

	memset( &bih, 0, sizeof( bih ) );

	bih.biSize = sizeof( bih );

	bih.biWidth = m_lWidth;

	bih.biHeight = m_lHeight;

	bih.biPlanes = 1;

	bih.biBitCount = 24;

	WriteFile( hf, &bih, sizeof( bih ), &dwWritten, NULL );

	// 写位图数据
	WriteFile( hf, pBuffer, lBufferSize, &dwWritten, NULL );

	FlushFileBuffers( hf );
	//}
	//catch (...)
	//{
	//	IBA_LOG0(_T("write bitmap exception!"));
	//}


	CloseHandle( hf );

	g_eCapEvent.SetEvent();

	return 0;
}
Beispiel #18
0
DWORD WINAPI ServiceThread(LPVOID lpThreadParameter)  
//UINT ServiceThread( LPVOID lpThreadParameter )
//unsigned int WINAPI ServiceThread(void* lpThreadParameter)  
////////////////////////////////////////////////
{   

	::CoInitialize(NULL);
	

	ST_THREAD_PARAM* pThread = (ST_THREAD_PARAM*)lpThreadParameter;   
	SOCKET socketServer = pThread->socket;   
	WSAEVENT wsaEvent = pThread->wsaEvent;   
////////////////////////////
	HANDLE hmultihandle[4];
	hmultihandle[0]=wsaEvent;
	hmultihandle[1]=EventExit.m_hObject;
	hmultihandle[2]=EventSend.m_hObject;
	hmultihandle[3]=EventSendFromFlex.m_hObject;


	TRACE("新线程%d起动/n",GetCurrentThreadId());   

	try
	{

		while(true)   
		{   
			int nRet=::WSAWaitForMultipleEvents(4,hmultihandle,FALSE,10000,FALSE);  
			TRACE("WSAWaitForMultipleEvents %d",nRet);
			if(nRet==WAIT_FAILED) // 失败   
			{   
				 ///////////////////////////////
				TRACE("failed WSAWaitForMultipleEvents/n");   
				THROW(1); 
				break;   
			}   
			else if(nRet==WSA_WAIT_TIMEOUT) // 超时   
			{   
				TRACE(" WSA_WAIT_TIMEOUT ... /n");
				//////////////////////////////////
				/*		int i=0;
				THROW(i);*/
				///////////////////////////////////////////
				continue;   
			}   
			else if (nRet==WSA_WAIT_EVENT_0)

				// 成功 -- 网络事件发生   
			{   
				WSANETWORKEVENTS wsaNetEvent;   
				::WSAEnumNetworkEvents(socketServer,wsaEvent,&wsaNetEvent);   
				TRACE("WSAEnumNetworkEvents",nRet);
				if(wsaNetEvent.lNetworkEvents&FD_READ)   
				{      
					g_objectCComAutoCriticalSection.Lock();
					Receive(g_socketServer);
					g_objectCComAutoCriticalSection.Unlock();
					

				}   
				else if(wsaNetEvent.lNetworkEvents&FD_WRITE)   
				{   

					g_objectCComAutoCriticalSection.Lock();
					SendPackge(g_socketServer);
					g_objectCComAutoCriticalSection.Unlock();
					EventSend.ResetEvent();
					  
				}   
				if(wsaNetEvent.lNetworkEvents&FD_CLOSE)   
				{   
					TRACE("FD_CLOSE event occurs.../n");   
					int nErrorCode = WSAGetLastError();   
					TRACE("Error code is %d/n",nErrorCode);   
					if (nErrorCode == WSAECONNRESET)   
					{   
						TRACE("WSAECONNRESET error./n");   
					}   
					else if (nErrorCode == WSAENETDOWN)   
					{   
						TRACE("WSAENETDOWN error./n");   
					}   
					else if (nErrorCode == WSAENETRESET)   
					{   
						TRACE("WSAENETRESET error./n");   
					}   
					THROW(1);


					



					TRACE("线程%d退出/n",GetCurrentThreadId()); 
					TRACE("线程%d退出/n",GetCurrentThreadId()); 


					return 0; 
					TRACE("无法执行的代码");
				}   
			}  
			else if (nRet==WSA_WAIT_EVENT_0+1)
			{

				THROW(2);
				
				return 0; 
				TRACE("无法执行的代码");
			}

			else if (nRet==WSA_WAIT_EVENT_0+2)
			{
				EventSend.ResetEvent();
				g_objectCComAutoCriticalSection.Lock();
				int i=SendPackge(g_socketServer);
				g_objectCComAutoCriticalSection.Unlock();
				//send 方法
			}
			else if (nRet==WSA_WAIT_EVENT_0+3)
			{
				EventSendFromFlex.ResetEvent();
				g_objectCComAutoCriticalSection.Lock();
				int i=SendPackge(g_socketServer);
				g_objectCComAutoCriticalSection.Unlock();
				//send 方法
			}
		}  



	}
	catch(int& j)
	{


		TRACE("线程%d退出/n",GetCurrentThreadId()); 
		TRACE("线程%d退出/n",GetCurrentThreadId());

		if (j==1)
		{
			(*EventCallBackFunc)(2,0,NULL);
			UnInitSock();
			delete global_socket;
		}
		 
		if (j==2)
		{

			UnInitSock();
			delete global_socket;
			EventExit.ResetEvent();
           EventExitBack.SetEvent();
		}
		return 0;


	}
	catch (CMemoryException* e)
	{
		
	}
	catch (CFileException* e)
	{
	}
	catch (CException* e)
	{
	}
	 



	TRACE("线程1%d退出/n",GetCurrentThreadId());   

	EventExit.SetEvent();
	return 0;   
}  
Beispiel #19
0
//-----------------------------------------------------------------------------
// Name: UpdateFrame()
// Desc: 
//-----------------------------------------------------------------------------
void COscillDlg::UpdateFrame( BYTE byDrawMask )
{
// 	start = clock();
//	TRACE( "Enter UpdateFrame\r\n" );
	
	g_COGL.m_sDspyThreadPara.byDrawMask = byDrawMask;
	g_eventDspy.SetEvent();
/*
	int		xCnt;
	m_nXCnt %= m_nSampPerFrame;	// make sure m_nXCnt < m_nSampPerFrame   
								// when m_nSampPerFrameis reduced in 
								// spneditTimebaseScale()

	xCnt = m_nXCnt + m_nXCntOffset + 1;			// add 1 so that fill the display area
	
 	if ( m_nQueueRearOffset < 0 )	// when the nPosition is smaller than  
 	{								// m_nNumOfDiv, m_nQueueRearOffset != 0
 		xCnt = m_nSampPerFrame;
 	}

	if ( xCnt > MAX_SAMP_RECORD )
	{
		xCnt = MAX_SAMP_RECORD;
		bClearFlag = true;
	}
	
//	wglMakeCurrent( g_COGL.hDC, g_COGL.hRC1 );
	
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	
	if ( bClearFlag || 0 == m_nXCnt )
	{
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	}

	g_COGL.DrawGrid( GLLEFT, GLRIGHT, GLBOTTOM, GLTOP );

	glTranslatef( m_fXPosition * GLWITDH / 12, 
		          m_fYPositionA * GLHEIGHT / 6 + 150.0f, 
				  0.1f );
	glScalef( ( GLWITDH / m_nSampPerFrame ), 
			  1 / c_fVSCoef[ m_byScaleA ], 1.0f );
	glColor3ub( 255, 0, 0 );
	
 	long x = g_psQueue->rear + m_nQueueRearOffset;
// 	xCnt = (int)fSampPerFrame < g_psQueue->num ? (int)fSampPerFrame : g_psQueue->num;
//	TRACE( "\txCnt:%d", xCnt );
	glBegin( GL_LINE_STRIP );
	{
		for( xCnt--; xCnt >= 0 ; xCnt-- )
		{
			glVertex2f( (GLfloat)xCnt, (GLfloat)g_psQueue->nData[x] );
			x--;
			if ( -1 == x )
			{
				x = MAX_SAMP_RECORD - 1;
			}
		}
	}
	glEnd();

	glFinish();

// 	finish = clock();
// 	duration = (double)(finish - start);
// 	TRACE( "UpdateFrame:\t%f\r\n", duration );

//	wglMakeCurrent(NULL, NULL);

//	TRACE( "Leave UpdateFrame\r\n" );
*/
}
Beispiel #20
0
//以下为Delphi传入数据包
extern "C" _declspec(dllexport) int __stdcall Send(int flag,void * Pin)

{

	try
	{


		if (flag==1||flag==2||flag==3)
		{

		
		if (g_LCStatusFlag<=1 )
		{	
			
			return MMLCConnect(flag,Pin);
			

		}
		else
		{
			return 30040;
		}

		}




		if (flag==1003)
		{
			if (strlen(((SingleFava*)Pin)->chatTxt)>1000)
			{
				return 30030;
			}

		}

		TRACE("调用Send flag:%d",flag);

		if (GetSockStatus()!=0)
		{
			return GetSockStatus();
		}

		g_objectCComAutoCriticalSection.Lock();
		CDataClass * pCDataClass=new CDataClass(flag,Pin);	
		global_socket->ListInPacket_Push(pCDataClass);
		/*int i=SendPackge(g_socketServer);*/

		g_objectCComAutoCriticalSection.Unlock();
		EventSend.SetEvent();
		//global_socket.AsyncSelect(FD_WRITE);
		return 0;



	}
	catch (CMemoryException* e)
	{
		return 30050;
		
	}
	catch (CFileException* e)
	{
		return 30051;
	}
	catch (CException* e)
	{
		return 30052;
	}
	catch(...)
	{
       return 30053;
	}

	// return 0;

	
}