Exemplo n.º 1
0
bool CIBACaptureImage::CaptureImage(LPCTSTR lpszName)
{
	if (!m_bInitOK || !m_pCap->IsOpened())
	{
		IBA_LOG0(_T("CIBACaptureImage::CaptureImage(采集图片失败-未初始化)"));
		return false;
	}

	g_eCapEvent.ResetEvent();
	m_pCap->GrabOneFrame(TRUE);
	if( WaitForSingleObject( g_eCapEvent, 5 * 1000 ) != WAIT_OBJECT_0 )
	{
		IBA_LOG0(_T("设备超时"));
		return false;
	}


	bool bFlag = false;
	try
	{
		GdiplusStartupInput gdiplusStartupInput; 
		ULONG_PTR gdiplusToken = NULL;
		GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 

		BMPScale( m_strBmpFilePath2, m_strBmpFilePath1, 320, 240 );

		BMP2JPG( m_strBmpFilePath2, m_strPath + lpszName + _T(".jpg"));

		// 2014-7-7 - qsc
		DeleteFile(m_strBmpFilePath1);
		DeleteFile(m_strBmpFilePath2);

		GdiplusShutdown(gdiplusToken);

		Sleep( 50 );
		bFlag = true;
	}
	catch (...)
	{
		bFlag = false;
		IBA_LOG0(_T("照片转换成jpg出现错误!"));
	}
	return bFlag;
}
Exemplo n.º 2
0
//Starts the thread that does the data acquisition.
void StartAcquisition()
{
	int numChannels = NUMBER_OF_CHANNELS + (int) ENABLE_TRIGGER;

	_isRunning = true;
	_bufferOverrun = false;

	//give main process (the data processing thread) high priority
	HANDLE hProcess = GetCurrentProcess();
	SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);

	//initialize application data buffer to the specified number of seconds
	_buffer.Initialize(BUFFER_SIZE_SECONDS * SAMPLE_RATE_HZ * numChannels);

	//reset event
	_dataAcquisitionStopped.ResetEvent();

	//create data acquisition thread with high priority
	_dataAcquisitionThread = AfxBeginThread(DoAcquisition, NULL, THREAD_PRIORITY_TIME_CRITICAL,0, CREATE_SUSPENDED);
	_dataAcquisitionThread->ResumeThread();
}
Exemplo n.º 3
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;

	}




}
Exemplo n.º 4
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;   
}  
Exemplo n.º 5
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;

	}

}
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;
}