瀏覽代碼

#IQRV #comment [Merge] PortableScanner

gifur 2 年之前
父節點
當前提交
bf774b791c

+ 56 - 146
Module/mod_PortableScanner/DocScannerCap.cpp

@@ -1,6 +1,7 @@
 #include "stdafx.h"
 #include "DocScannerCap.h"
 #include "math.h"
+#include "UserEventCode.h"
 //template<typename T>
 //struct  identity
 //{
@@ -144,12 +145,9 @@ int IsDeviceBusy(const char* lpcszDeviceName)
 				}
 				if (SUCCEEDED(hr)) {
 					hr = pPropBag->Read(L"FriendlyName", &varName, 0);
-					int count = 0;
-					char tmp[255] = {0};
-					while (varName.bstrVal[count] != 0x00 && count < 255) {
-						tmp[count] = (char)varName.bstrVal[count];
-						count++;
-					}
+					int count = 255;
+					char tmp[256] = {0};
+					WrapW2A(varName, tmp, count);
 					if(SUCCEEDED(hr)) {
 						if(!strcmp(lpcszDeviceName, tmp)) {
 							//Deal the specific device
@@ -219,7 +217,8 @@ int IsDeviceBusy(const char* lpcszDeviceName)
 												videoBusy = 0;
 											}
 											else {
-												Dbg("It works ? %d, %d", i, j);
+												LogWarn(Severity_Low, Error_DevCommFailed, LOG_ERROR_PORTABLESCANNER_BUSY_ONE,
+													CSimpleStringA::Format("%s stop failed: %d", lpcszDeviceName, innhr));
 											}
 											SAFE_RELEASE_IDEV(m_pVW);
 											SAFE_RELEASE_IDEV(m_pMC);
@@ -229,8 +228,7 @@ int IsDeviceBusy(const char* lpcszDeviceName)
 								}
 								if (videoBusy == 1)
 								{
-									Dbg("Test 1");
-									nRet = 1; //瑙嗛�璁惧�鍗犵敤
+									nRet = 1; //视频设备占用
 								}
 								SAFE_RELEASE_IDEV(pXBar1);
 							}
@@ -250,8 +248,9 @@ int IsDeviceBusy(const char* lpcszDeviceName)
 								HRESULT innhr = m_pMC->StopWhenReady();
 								if (FAILED(innhr))
 								{
-									Dbg("Test 2");
-									nRet = 1;  //瑙嗛�璁惧�鍗犵敤
+									LogWarn(Severity_Low, Error_DevCommFailed, LOG_ERROR_PORTABLESCANNER_BUSY_TWO,
+										CSimpleStringA::Format("%s stop failed: %d", lpcszDeviceName, innhr));
+									nRet = 1;  //视频设备占用
 								}
 								SAFE_RELEASE_IDEV(m_pVW);
 								SAFE_RELEASE_IDEV(m_pMC);
@@ -272,7 +271,6 @@ int IsDeviceBusy(const char* lpcszDeviceName)
 PEnd:
 	SAFE_RELEASE_IDEV(pDevEnum);
 	SAFE_RELEASE_IDEV(pEnum);
-	Dbg("IsDeviceBusy(%s) returned %d", lpcszDeviceName, nRet);
 	if(nRet != 1) {
 		nRet = 0;
 	}
@@ -373,7 +371,6 @@ int ExclusiveCameraBuckes(const CAMERA_BUCKET& lhs, const CAMERA_BUCKET& rhs, CA
 
 void DisplayCameraInfos(const CAMERA_BUCKET& vtCameraList)
 {
-	Dbg("Cameralist:(%d)", vtCameraList.size());
 	for(CAMERA_BUCKET_CITER it=vtCameraList.cbegin(); it!=vtCameraList.cend(); ++it) {
 		if(*it) {
 			(*it)->Display();
@@ -427,10 +424,7 @@ CDocScannerCap::~CDocScannerCap(void)
 	_cleanup(false);
 
 	RequestQueueCleanup();
-	//Would meet confict ?
-	Dbg("before destroyAllWindows...");
 	destroyAllWindows();
-	Dbg("after destroyAllWindows...");
 
 #endif
 
@@ -549,7 +543,7 @@ bool CDocScannerCap::Open(unsigned int idx)
 	//the method first call release to close alreay opened file or camera
 	m_cvCap.open(idx);
 	if(!m_cvCap.isOpened()) {
-		Dbg("open failed:");
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open failed:");
 		m_dwErrCode = ERROR_OPEN_FAILED;
 		winName.clear();
 		return false;
@@ -575,7 +569,7 @@ bool CDocScannerCap::Open(unsigned int idx)
 
 void CDocScannerCap::_setProperty()
 {
-	//璁剧疆涓轰笉涓€鏍风殑鍒嗚鲸鐜囷紝浼氬嚭鐜拌€楁椂锛�1.5s 闀垮煄
+	//设置为不一样的分辨率,会出现耗时,1.5s 长城
 	//SetResoultionRatio(1920, 1080);
 }
 
@@ -589,7 +583,7 @@ bool CDocScannerCap::OpenCamera(LPCTSTR lpcszDev)
 	const int camId = _getCamIDByDevName(lpcszDev);
 	if(camId < 0) {
 		m_dwErrCode = ERROR_FILE_NOT_FOUND;
-		Dbg("not found camera id.");
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("not found camera id.");
 		return false;
 	}
 
@@ -620,7 +614,7 @@ bool CDocScannerCap::OpenCamera(LPCTSTR lpcszDev)
 bool CDocScannerCap::ScanImage(const char* lpcszFilePath)
 {
 	if(!m_fPreviewing) {
-		Dbg("Request scaning without in previewing.");
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Request scaning without in previewing.");
 		m_dwErrCode = ERROR_INVALID_ENVIRONMENT;
 		return false;
 	}
@@ -648,13 +642,12 @@ bool CDocScannerCap::ScanImage(const char* lpcszFilePath)
 
 	RequestEventPtr item = CreateRequestEvent(EVTCODE_SCAN);
 	if(!item) {
-		Dbg("CreateRequestEvent failed");
 		m_dwErrCode = ERROR_RESOURCE_FAILED;
 		return false;
 	}
 	item->evtData = (CHAR*)malloc(sizeof(char)*(len+1));
 	if(item->evtData == NULL) {
-		Dbg("malloc failed");
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("malloc failed");
 		m_dwErrCode = ERROR_RESOURCE_FAILED;
 		delete item;
 		return false;
@@ -663,22 +656,13 @@ bool CDocScannerCap::ScanImage(const char* lpcszFilePath)
 	strcpy_s(item->evtData, sizeof(char)*(len+1), szFileName);
 	item->dwDataLen = len+1;
 	PostIntoRequestQueue(&item);
-	Dbg("WaitForResponse...");
 	int nRes = WaitForResponse(EVTCODE_SCAN, 30*1000);
-	Dbg("WaitForResponse returned: 0x%02x", nRes);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("WaitForResponse returned: 0x%02x", nRes);
 	if(nRes >= EVTSTATUS_ERROR_MASK) {
 
 	}
 	else if(nRes == EVTSTATUS_DONE_SUCC) {
-		Dbg("Scan succ: %d[%s]", ExistsFileA(szFileName), szFileName);
-		//Mat picture = imread(szFileName);
-		//if(!picture.empty()) {
-		//	namedWindow("show-img");
-		//	imshow("show-img", picture);
-		//}
-		//else {
-		//	Dbg("picture is empty!!");
-		//}
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Scan succ: %d[%s]", ExistsFileA(szFileName), szFileName);
 	}
 	return true;
 }
@@ -708,12 +692,10 @@ bool CDocScannerCap::StartPreview()
 	{
 		m_hPreviewPro = NULL;
 		m_dwErrCode = E_HANDLE;
-		Dbg("Create WndPreviewDlgProc thread failed");
 		return false;
 	}
 	m_fPreviewing = true;
 	if(ResumeThread(m_hPreviewPro) == (DWORD)-1) {
-		Dbg("ResumeThread failed, GLE=%u", GetLastError());
 		m_dwErrCode = E_UNEXPECTED;
 		m_fPreviewing = false;
 		CloseHandle(m_hPreviewPro);
@@ -731,17 +713,16 @@ bool CDocScannerCap::TerminatePreview()
 		m_dwErrCode = E_UNEXPECTED;
 		m_tpStopPreview = true;
 		//30 seconds to timeout?
-		Dbg("Set StopPreivew flag true, waitting...");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set StopPreivew flag true, waitting...");
 		DWORD dwResult = WaitForSingleObject(m_hPreviewPro, 30 * 1000);
 		if(dwResult == WAIT_OBJECT_0) {
-			Dbg("Wait succ.");
-			//assert(m_fPreviewing == false);
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Wait succ.");
 			CloseHandle(m_hPreviewPro);
 			m_hPreviewPro = NULL;
 			m_dwErrCode = ERROR_SUCCESS;
 			return true;
 		}else if(dwResult == WAIT_TIMEOUT) {
-			Dbg("Wait succ timeout: %d", m_fPreviewing);
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Wait succ timeout: %d", m_fPreviewing);
 			if(!m_fPreviewing) {
 				CloseHandle(m_hPreviewPro);
 				m_hPreviewPro = NULL;
@@ -751,7 +732,7 @@ bool CDocScannerCap::TerminatePreview()
 			m_dwErrCode = WAIT_TIMEOUT;
 		}
 		else {
-			Dbg("WaitForSingleObject failed returned: %u.", dwResult);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("WaitForSingleObject failed returned: %u.", dwResult);
 			m_dwErrCode = dwResult;
 		}
 	}
@@ -770,13 +751,12 @@ bool CDocScannerCap::_initWindow(bool fShown)
 	if(m_defWnd == NULL) {
 		destroyWindow(winName);
 		m_dwErrCode = ERROR_INVALID_WINDOW_HANDLE;
-		Dbg("Find %s window handle faiiled, GLE=%u", winName.c_str(), GetLastError());
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Find %s window handle faiiled, GLE=%u", winName.c_str(), GetLastError());
 		return false;
 	}
 	DWORD dwFlag = fShown ? SWP_SHOWWINDOW : SWP_HIDEWINDOW;
 	BOOL bRet = ::SetWindowPos(m_defWnd, HWND_TOPMOST, 
 		m_winSize.x, m_winSize.y, m_winSize.width, m_winSize.height, dwFlag);
-	Dbg("WinSize(%d): %d, %d, %d, %d", bRet, m_winSize.x, m_winSize.y, m_winSize.width, m_winSize.height);
 	if(bRet) { m_bHide = !fShown; }
 	m_dwErrCode = ERROR_SUCCESS;
 	rectStatus = NOT_SET;
@@ -790,12 +770,15 @@ void CDocScannerCap::_destroyWindow()
 		m_cmFrame.release();
 	}
 	if(m_defWnd) {
-		Dbg("before destroyWindow with %s", winName.c_str());
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before destroyWindow with %s", winName.c_str());
 		destroyWindow(winName);
-		Dbg("after destroyWindow with %s", winName.c_str());
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after destroyWindow with %s", winName.c_str());
 		m_defWnd = NULL;
 		m_bHide = FALSE;
 	}
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before destroyAllWindow");
+	destroyAllWindows();
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after destroyAllWindow");
 	return;
 }
 
@@ -816,7 +799,6 @@ UINT WINAPI CDocScannerCap::WndPreviewDlgProc(PVOID param)
 {
 	CDocScannerCap *pCap = reinterpret_cast<CDocScannerCap*>(param);
 	if(pCap == NULL) {
-		Dbg("WndPreviewDlgProc::praram is invalid(empty)");
 		return UINT(-1);
 	}
 	return (UINT)(pCap->_executePreview());
@@ -824,18 +806,17 @@ UINT WINAPI CDocScannerCap::WndPreviewDlgProc(PVOID param)
 
 void CDocScannerCap::EvtFinishedHandle(USHORT evtCode, UCHAR result, UINT checksum)
 {
-	Dbg("EvtCode:%d, result:%d, checksum:%d", evtCode, result, checksum);
+
 }
 
 void CDocScannerCap::SetResoultionRatio(int width, int height, int nframes /*= -1*/)
 {
-	Dbg("before: width=%d, height=%d , nframes=%d", (int)m_cvCap.get(CAP_PROP_FRAME_WIDTH), 
-		(int)m_cvCap.get(CAP_PROP_FRAME_HEIGHT), (int)m_cvCap.get(CAP_PROP_FRAME_COUNT));
+	// DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before: width=%d, height=%d , nframes=%d", (int)m_cvCap.get(CAP_PROP_FRAME_WIDTH), 
+	// 	(int)m_cvCap.get(CAP_PROP_FRAME_HEIGHT), (int)m_cvCap.get(CAP_PROP_FRAME_COUNT));
 	m_cvCap.set(CV_CAP_PROP_FRAME_WIDTH, width);
 	m_cvCap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
-	Dbg("after: width=%d, height=%d , nframes=%d", (int)m_cvCap.get(CAP_PROP_FRAME_WIDTH), 
-		(int)m_cvCap.get(CAP_PROP_FRAME_HEIGHT), (int)m_cvCap.get(CAP_PROP_FRAME_COUNT));
-	//m_cvCap.set(CAP_PROP_CONVERT_RGB, 0);
+	// DDbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)g("after: width=%d, height=%d , nframes=%d", (int)m_cvCap.get(CAP_PROP_FRAME_WIDTH), 
+	// 	(int)m_cvCap.get(CAP_PROP_FRAME_HEIGHT), (int)m_cvCap.get(CAP_PROP_FRAME_COUNT));
 }
 
 void CDocScannerCap::_setMouseCallback()
@@ -847,24 +828,13 @@ void CDocScannerCap::MouseClick(int event, int x, int y, int flags)
 {
 	//static Rect origin;
 	if(event == CV_EVENT_LBUTTONDOWN) {
-
-		//if(rectStatus == NOT_SET)
-		{
-			//Dbg("CV_EVENT_LBUTTONDOWN");
-			rectStatus = IN_PROCESS;
-			rect = Rect(x, y, 0, 0);
-			//origin = rect;
-		}
+		rectStatus = IN_PROCESS;
+		rect = Rect(x, y, 0, 0);
 
 	} else if(event == CV_EVENT_MOUSEMOVE) {
 
 		if(rectStatus == IN_PROCESS) {
 			rect = Rect(Point(rect.x, rect.y), Point(x,y));
-			//rect.x = MIN(origin.x, x);
-			//rect.y = MIN(origin.y, y);
-			//rect.width = abs(origin.x - x);
-			//rect.height = abs(origin.y - y);
-			//Dbg("CV_EVENT_MOUSEMOVE: %d,%d,%d,%d TID(%u)", rect.x, rect.y, rect.width, rect.height, GetCurrentThreadId());
 		}
 
 	}else if(event == CV_EVENT_LBUTTONUP) {
@@ -872,12 +842,10 @@ void CDocScannerCap::MouseClick(int event, int x, int y, int flags)
 		if(rectStatus == IN_PROCESS) {
 
 			if(rect.height == 0 || rect.width == 0) {
-				Dbg("CV_EVENT_LBUTTONUP::Zero Area");
 				rectStatus = NOT_SET;
 				return;
 			}
 			rect = Rect(Point(rect.x, rect.y), Point(x,y));
-			Dbg("CV_EVENT_LBUTTONUP");
 			rectStatus = SET;
 		}
 	}
@@ -885,36 +853,13 @@ void CDocScannerCap::MouseClick(int event, int x, int y, int flags)
 
 void CDocScannerCap::_setResizeArea(float ratio)
 {
-	//m_cmFrame.at<Vec3b>(m_cmFrame.cols / 2, m_cmFrame.rows / 2)[0] = 0;
-	//m_cmFrame.at<Vec3b>(m_cmFrame.cols / 2, m_cmFrame.rows / 2)[1] = 0;
-	//m_cmFrame.at<Vec3b>(m_cmFrame.cols / 2, m_cmFrame.rows / 2)[2] = 255;
-	//putText(m_cmFrame, "Hello", Point(m_cmFrame.cols/2, m_cmFrame.rows/2), 0, 0.7, Scalar(255, 0, 0));
 	Rect area((1-ratio)/2*m_cmFrame.cols, (1-ratio)/2*m_cmFrame.rows, ratio*m_cmFrame.cols, ratio*m_cmFrame.rows);
-
-	//Mat mask;
-	//mask.create(m_cmFrame.size(), CV_8UC1);
-	//mask.setTo( GC_BGD );
-	//(mask(area)).setTo( Scalar(GC_PR_FGD));
-
-	//Mat binMask;
-	//if( binMask.empty() || binMask.rows != mask.rows || binMask.cols != mask.cols )
-	//	binMask.create(mask.size(), CV_8UC1 );
-	//binMask = mask & 1;
-	//m_cmFrame.copyTo(res, binMask);
-	//WRITE_INFO_PARAM("w, h: %d, %d", m_cmFrame.cols, m_cmFrame.rows);
-	//WRITE_INFO_PARAM("x, y, w, h: %d, %d, %d, %d", area.x, area.y, area.width, area.height);
 	Mat roi = m_cmFrame(area);
 	Mat res;
 	res.create(roi.rows, roi.cols, m_cmFrame.type());
 	roi.copyTo(res);
-	//WRITE_INFO_PARAM("2 w, h: %d, %d", res.cols, res.rows);
 	m_cmFrame.release();
 	m_cmFrame = res;
-
-	//rectangle(m_cmFrame, Point(area.x, area.y), 
-	//	Point(area.x + area.width, area.y + area.height),
-	//	RED, rectangle_thickness);
-
 }
 
 void CDocScannerCap::_setInterestArea()
@@ -922,7 +867,6 @@ void CDocScannerCap::_setInterestArea()
 	if(rectStatus == IN_PROCESS || rectStatus == SET) {
 
 		Rect area(rect);
-		//Dbg("rect: %d, %d, %d, %d", rect.x, rect.y, rect.width, rect.height);
 		int suffix_x = rect.x - drawableRect.x;
 		int suffix_y = rect.y - drawableRect.y;
 
@@ -939,10 +883,8 @@ void CDocScannerCap::_setInterestArea()
 			Point(area.x + area.width, area.y + area.height),
 			GREEN, rectangle_thickness);
 		assert(m_cmFrame.data);
-		//Dbg("drawableRect: %d, %d, %d, %d", drawableRect.x, drawableRect.y, drawableRect.width, drawableRect.height);
 		const CvScalar colorMask = cvScalarAll(-52);
 		Mat res = Mat::ones(m_cmFrame.size(), CV_8UC1)*255;
-		//Dbg("area: %d, %d, %d, %d", area.x, area.y, area.width, area.height);
 		res(area).setTo(0);
 		cv::add(m_cmFrame, (const cv::Scalar&)colorMask, m_cmFrame, res, m_cmFrame.type());
 		rect = area;
@@ -979,14 +921,14 @@ bool CDocScannerCap::_executePreview()
 
 				if(eOccurTimes == 0) {
 					eOccurTimes++;
-					Dbg("Wow! the scanner has problem");
+					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Wow! the scanner has problem");
 					dwEStartTick = GetTickCount();
 				
 				}else if(eOccurTimes != -1) {
 					eOccurTimes++;
 					if(eOccurTimes >= ERROR_CONTINUE_TIMES
 						|| GetTickCount() > dwEStartTick + ERROR_CONTINUE_MILLSEC) {
-						Dbg("Send Reset Event !! %d", eOccurTimes);
+						DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Send Reset Event !! %d", eOccurTimes);
 						eOccurTimes = -1;
 						SetResetEvent();
 					}
@@ -999,12 +941,12 @@ bool CDocScannerCap::_executePreview()
 			if(B == G && G == R && B == 0) {
 
 				if(eClosedTimes == 0) {
-					Dbg("Eh, maybe forget to scratch the scanner");
+					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Eh, maybe forget to scratch the scanner");
 					eClosedTimes = 1;
 				}
 			
 			}else if(eClosedTimes != 0){
-				Dbg("Ok, you achieve it");
+				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Ok, you achieve it");
 				eClosedTimes = 0;
 			}
 		
@@ -1015,7 +957,7 @@ bool CDocScannerCap::_executePreview()
 			}
 
 			if(eClosedTimes != 0){
-				Dbg("Ok, you achieve it");
+				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Ok, you achieve it");
 				eClosedTimes = 0;
 			}
 		}
@@ -1031,7 +973,7 @@ bool CDocScannerCap::_executePreview()
 
 		Mat origin = m_cmFrame.clone();
 		int cols = 0, rows = 0;
-		{//濉�厖杈规�浠ラ€傚簲瀹藉害
+		{//填充边框以适应宽度
 			Size origin_size = m_cmFrame.size();
 			if(1.0*m_winSize.width / m_winSize.height > 1) {
 				int aimWidth = (int)(1.0*origin_size.height*(1.0*m_winSize.width / m_winSize.height));
@@ -1056,8 +998,6 @@ bool CDocScannerCap::_executePreview()
 		if(cols > 0 || rows > 0) {
 			copyMakeBorder(m_cmFrame, m_cmFrame, rows, rows, cols, cols, BORDER_CONSTANT, BLACK);
 		}
-		//Dbg("m_winSize: %d, %d", m_winSize.width, m_winSize.height);
-		//Dbg("m_cmFrame: %d, %d", m_cmFrame.cols, m_cmFrame.rows);
 		drawableRect.x = cols;
 		drawableRect.width = origin.cols;
 		drawableRect.y = rows;
@@ -1068,12 +1008,12 @@ bool CDocScannerCap::_executePreview()
 		imshow(winName, m_cmFrame);
 		char keyCode = cvWaitKey(WAITKEY_TIME);
 		//if(keyCode == 27) {
-		//	Dbg("ESC key press event recv.");
+		//	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ESC key press event recv.");
 		//	break;
 		//}
 		RequestEventPtr evtPtr = GetRequest();
 		if(evtPtr) {
-			Dbg("0x%02x event recv.", evtPtr->evtCode);
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("0x%02x event recv.", evtPtr->evtCode);
 			switch(evtPtr->evtCode)
 			{
 			case EVTCODE_SCAN:
@@ -1090,43 +1030,22 @@ bool CDocScannerCap::_executePreview()
 
 						if(rectStatus == SET && (rect.width != 0 && rect.height != 0)) {
 							Mat result(picture, rect);
-							//imwrite(szFileName, result);
-							Dbg("ScanImage@1: %s %d", szFileName, result.size());
+							DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ScanImage@1: %s %d", szFileName, result.size());
 							testMat = result.clone();
-						
 						} else {
-							//imwrite(szFileName, origin);
-							Dbg("ScanImage@2: %s %d", szFileName, origin.size());
+							DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ScanImage@2: %s %d", szFileName, origin.size());
 							testMat = origin.clone();
 						}
 
-
 						ImageWriteUntil(szFileName, testMat);
 
-						//cv::Mat destMat;
-						/*int compatRate = MatResize(testMat, destMat, 100);
-						compatRate = compatRate > 0 ? compatRate + 1: 100;*/
-						//const int compatRate = 90;
-						//Dbg("set compress rate: %d", compatRate);
-						//vector<int> comprressionParams;
-						//comprressionParams.push_back(CV_IMWRITE_JPEG_QUALITY);
-						//comprressionParams.push_back(compatRate); 
-						//default one
-						//comprressionParams.push_back(IMWRITE_JPEG_OPTIMIZE);
-						//comprressionParams.push_back(1);
-
-						//imwrite(szFileName, testMat, comprressionParams);
-						//Resize(szFileName, GetFileSize(szFileName), compatRate);
-
 						evtPtr->evtStatus = EVTSTATUS_DONE_SUCC;
 					}
 					catch(cv::Exception& ex)
 					{
-						Dbg("exception converting image to jpeg: %s", ex.what());
+						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("exception converting image to jpeg: %s", ex.what());
 						evtPtr->evtStatus = EVTSTATUS_DONE_FAIL;
-
 					}
-
 					evtPtr->OnAnswer();
 				}
 				break;
@@ -1138,7 +1057,7 @@ bool CDocScannerCap::_executePreview()
 			}
 		}
 		if(m_tpStopPreview) {
-			Dbg("Stop previewing event recv.");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Stop previewing event recv.");
 			break;
 		}
 	}
@@ -1154,7 +1073,6 @@ int CDocScannerCap::GetSpecificedCamInfor(const int camID, PCAMERA_INFOR_ITEM in
 		return -2;
 	}
 	info->Cleanup();
-	// Create the System Device Enumerator.
 	ICreateDevEnum *pSysDevEnum = NULL;
 	HRESULT hr = CoCreateInstance(
 		CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, 
@@ -1274,11 +1192,7 @@ int CDocScannerCap::_getCamIDByDevName(LPCTSTR lpcszDevName)
 					hr = pPropBag->Read(L"FriendlyName", &varName, 0);
 					char szDevName[MAX_PATH + 2] = {0};
 					int count = 0;
-					while( varName.bstrVal[count] != 0x00 && count < MAX_PATH) {
-						szDevName[count] = (char)varName.bstrVal[count];
-						count++;
-					}
-					szDevName[count] = 0;
+					WrapW2A(varName, szDevName, MAX_PATH);
 					if(strcmp(szDevName, lpcszDevName) == 0) {
 						done = true;
 						aimID = deviceCounter;
@@ -1333,14 +1247,14 @@ bool CDocScannerCap::IsColorAbnormal(IplImage* src)
 
 bool CDocScannerCap::IsFrameFuzzy(IplImage* data)
 {
-	//鍥剧墖姣忚�瀛楄妭鏁板強楂�
+	//图片每行字节数及高
 	int width=data->widthStep;
 	int height=data->height;
 	ushort* sobelTable = new ushort[width*height];
 	memset(sobelTable, 0, width*height*sizeof(ushort));
 
 	int i, j, mul;
-	//鎸囧悜鍥惧儚棣栧湴鍧€
+	//指向图像首地址
 	uchar* udata = (uchar*)data->imageData;
 	for(i = 1, mul = i*width; i < height - 1; i++, mul += width) {
 		for(j = 1; j < width - 1; j++) {
@@ -1361,7 +1275,7 @@ bool CDocScannerCap::IsFrameFuzzy(IplImage* data)
 
 	uchar suddenThre = 50;
 	uchar sameThre = 3;
-	//閬嶅巻鍥剧墖
+	//遍历图片
 	for(i = 1, mul = i*width; i < height - 1; i++, mul += width) {
 		for(j = 1; j < width - 1; j++) {
 			if(sobelTable[mul+j]) {
@@ -1464,7 +1378,7 @@ bool CDocScannerCap::IsFrameFuzzy(IplImage* data)
 			}
 		}
 	}
-	//妯$硦搴�
+	//模糊度
 	float result = (float)totLen/totCount;
 	delete[] sobelTable;
 	if(result > 5) {
@@ -1476,7 +1390,6 @@ bool CDocScannerCap::IsFrameFuzzy(IplImage* data)
 bool CDocScannerCap::ResetCamera()
 {
 	if(!_isVal() && m_videoID == -1) {
-		Dbg("Nothing to do with ResetCamera(%d)", m_videoID);
 		return true;
 	}
 	bool fPreview = m_fPreviewing;
@@ -1523,7 +1436,7 @@ bool CDocScannerCap::ResetCamera()
 	m_dwErrCode = ERROR_SUCCESS;
 	//SetWinShown(m_hideMode != 0 ? false : true);
 	if(fPreview && !StartPreview()) {
-		Dbg("StartPreview failed");
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("StartPreview failed");
 		return true;
 	}else if(fPreview && bHide) {
 		SetWinShown(false);
@@ -1539,7 +1452,7 @@ int CDocScannerCap::MatResize(const cv::Mat& src, cv::Mat& dest, int quantity)
 	params.push_back(quantity);
 	std::vector<unsigned char> buff;
 	cv::imencode(".jpg", src, buff, params);
-	Dbg("after buffer: size: %d, with quantity: %d", buff.size(), quantity);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after buffer: size: %d, with quantity: %d", buff.size(), quantity);
 	dest = cv::imdecode(buff, CV_LOAD_IMAGE_COLOR);
 	if(buff.size() > aim_size)
 		return (int)(aim_size * 1.2f / buff.size() * 100);
@@ -1553,7 +1466,7 @@ DWORD CDocScannerCap::GetFileSize(LPCTSTR srcFilePath)
 		return -1;
 	fseek(fHandle, 0, SEEK_END);
 	DWORD fileSize = ftell(fHandle);
-	Dbg("get the file size: %lu", fileSize);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get the file size: %lu", fileSize);
 	fclose(fHandle);
 	return fileSize;
 }
@@ -1565,7 +1478,7 @@ int CDocScannerCap::ImageWriteUntil(LPCTSTR srcFilePath, const cv::Mat& src)
 	for(int i=0; i<sizeof(compatRates)/sizeof(compatRates[0]); ++i)
 	{
 		const int compatRate = compatRates[i];
-		Dbg("set compress rate: %d", compatRate);
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("set compress rate: %d", compatRate);
 		vector<int> comprressionParams;
 		comprressionParams.push_back(CV_IMWRITE_JPEG_QUALITY);
 		comprressionParams.push_back(compatRate);
@@ -1575,7 +1488,7 @@ int CDocScannerCap::ImageWriteUntil(LPCTSTR srcFilePath, const cv::Mat& src)
 
 		} catch(cv::Exception& ex)
 		{
-			Dbg("exception converting image to jpeg: %s", ex.what());
+			DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("exception converting image to jpeg: %s", ex.what());
 			return -1;
 		}
 
@@ -1599,7 +1512,6 @@ int CDocScannerCap::Resize(LPCTSTR srcFilePath, DWORD dwSrcFileSize, int compres
 	if(src.empty())
 		return -1;
 	float rate = sqrt(aim_size * 1.0f / dwSrcFileSize);
-	Dbg("rate: %f", rate);
 	int width = static_cast<int>(src.cols*rate);
 	int height = static_cast<int>(src.rows*rate);
 
@@ -1616,7 +1528,6 @@ int CDocScannerCap::Resize(LPCTSTR srcFilePath, DWORD dwSrcFileSize, int compres
 	fseek(fHandle, 0, SEEK_END);
 	long fileSize = ftell(fHandle);
 	fclose(fHandle);
-	Dbg("get the resize file size: %ld", fileSize);
 	return 1;
 }
 
@@ -1649,7 +1560,6 @@ void OnMouseTrace(int event, int x, int y, int flags, void* param /*= NULL*/)
 {
 	CDocScannerCap* pCap = reinterpret_cast<CDocScannerCap*>(param);
 	if(pCap == NULL) {
-		Dbg("OnMouseTest::param is NULL!");
 		return;
 	}
 	pCap->MouseClick(event, x, y, flags);

+ 22 - 16
Module/mod_PortableScanner/DocScannerCap.h

@@ -53,24 +53,36 @@ typedef struct _CAMERA_INFOR_ITEM
 		}
 	}
 	void Display() {
-		Dbg("[%ld]%s(%s)",uWaveInID, szDevName, szDevPath);
-		Dbg("CLSID:%s", szCLSID);
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%ld]%s(%s)",uWaveInID, szDevName, szDevPath);
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CLSID:%s", szCLSID);
 	}
 
 } CAMERA_INFOR_ITEM, *PCAMERA_INFOR_ITEM;
 
 static int WrapW2A(VARIANT& varirant, char* szDst, const size_t maxLen) {
+
 	int count = 0;
-	while (varirant.bstrVal[count] != 0x00 && count < maxLen) {
-		szDst[count] = (char)varirant.bstrVal[count];
-		count++;
+	WCHAR tmp[256];
+	tmp[0] = 0;
+	memset(szDst, '\0', sizeof(char)*maxLen);
+	HRESULT hr = StringCchCopyW(tmp, 256, varirant.bstrVal);
+	if(hr == S_OK) {
+		count = WideCharToMultiByte(CP_ACP, 0, tmp, -1, szDst, maxLen, 0, NULL);
+	} else {
+		while (varirant.bstrVal[count] != 0x00 && count < maxLen) {
+			szDst[count] = (char)varirant.bstrVal[count];
+			count++;
+		}
 	}
+
+
 	return count;
 	/*
 	USES_CONVERSION;
 	lptstrValue = W2T(Value.bstrVal);
 	*/
 }
+
 typedef vector<PCAMERA_INFOR_ITEM> CAMERA_BUCKET;
 typedef CAMERA_BUCKET::const_iterator CAMERA_BUCKET_CITER;
 typedef CAMERA_BUCKET::iterator CAMERA_BUCKET_ITER;
@@ -269,7 +281,6 @@ public:
 			m_winSize.y = y;
 			m_winSize.width = width;
 			m_winSize.height = height;
-			Dbg("SetWinPosition(%d, %d, %d, %d)", m_winSize.x, m_winSize.y, m_winSize.width, m_winSize.height);
 			_resizeWindow();
 		}
 	}
@@ -331,20 +342,15 @@ private:
 	bool IsFrameFuzzy(IplImage* src);
 
 	void _cleanup(bool toReleaseVC = true) {
-
-		LOG_FUNCTION();
-
 		if(m_fPreviewing) {
 			TerminatePreview();
 			if(!toReleaseVC)
-				Sleep(1000); /* 鍑忓皯 m_cvCap 鏋愭瀯鏃惰皟鐢� release 鍗℃�鐨勫嚑鐜� */
+				Sleep(1000); /* 减少 m_cvCap 析构时调用 release 卡死的几率 */
 		}
-
 		_destroyWindow();
-
 		if(m_cvCap.isOpened()) {
 
-			Dbg("cvCap release...");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cvCap release...");
 			m_cvCap.release();
 			m_videoID = -1;
 			winName.clear();
@@ -352,6 +358,8 @@ private:
 		}
 		//_resetWinSize();
 		m_dwErrCode = ERROR_NOT_READY;
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cvCap release done");
+
 		return;
 	}
 
@@ -368,7 +376,6 @@ private:
 			}
 			devName = lpszName;
 		}
-		Dbg("_setDevName: %s", devName.c_str());
 		return devName.size();
 	}
 
@@ -536,7 +543,6 @@ private:
 				m_winSize.x, m_winSize.y, m_winSize.width, m_winSize.height, 
 				m_bHide ? SWP_HIDEWINDOW : SWP_SHOWWINDOW);
 			Area area = _getWindowRect();
-			Dbg("(%d) %d, %d vs %d, %d", bRet, m_winSize.width, m_winSize.height, area.x, area.y);
 		}
 	}
 	void _resetWinSize() {
@@ -567,7 +573,7 @@ private:
 	Rect rect;
 	Rect drawableRect;
 
-	// 鍚庣疆鎽勫儚澶村�浜庣敾骞呰�缃�棤鏁� -Josephus@2017126 14:51:14
+	// 后置摄像头对于画幅设置无效 -Josephus@2017126 14:51:14
 	bool m_bHSPSType;
 	CPortableScannerFSM* m_pFSM;
 	void SetResetEvent() {

文件差異過大導致無法顯示
+ 223 - 172
Module/mod_PortableScanner/PortableScannerFSM.cpp


+ 32 - 27
Module/mod_PortableScanner/PortableScannerFSM.h

@@ -23,7 +23,7 @@ enum DevStateEnum
 #endif
 
 #include "PortableScanner_server_g.h"
-//#include "DocScannerCap.h"
+#include "UserEventCode.h"
 
 using namespace PortableScanner;
 
@@ -114,7 +114,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("BindDeviceEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -130,7 +131,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("StartPreviewEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -146,7 +148,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("StopPreviewEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -162,7 +165,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ScanImageEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -178,7 +182,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ScanImageExEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -194,7 +199,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ShowPropertyEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -210,7 +216,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("SetPropertyEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -226,7 +233,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("SetWinPosEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -242,7 +250,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetDevStatusEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -258,7 +267,8 @@ public:
 	{
 		if(m_ctx != NULL)
 		{
-			m_ctx->Answer(Error_InvalidState);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetDevInfoEvent return InvalidState!");
+			m_ctx->Answer(Error_InvalidState, LOG_ERROR_PORTABLESCANNER_INVALIDSTATE);
 		}
 	}
 };
@@ -276,7 +286,7 @@ public:
 
 	void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
 
-	enum {s0, s1, /*s2,*/ s3, s4, s5, s6, s7, s8};
+	enum {s0, s1, /*s2,*/ s3, s4, s5, s6, s7};
 
 	BEGIN_FSM_STATE(CPortableScannerFSM)
 		FSM_STATE_ENTRY(s0, "Idle", s0_on_entry, s0_on_exit, s0_on_event)
@@ -286,7 +296,6 @@ public:
 		FSM_STATE_ENTRY(s5, "NotHold", s5_on_entry, s5_on_exit, s5_on_event)
 		FSM_STATE_ENTRY(s6, "HidPreviewing", s6_on_entry, s6_on_exit, s6_on_event)
 		FSM_STATE_ENTRY(s7, "Exit", s7_on_entry, s7_on_exit, s7_on_event)
-		FSM_STATE_ENTRY(s8, "Idiot", s8_on_entry, s8_on_exit, s8_on_event)
 	END_FSM_STATE()
 
 	BEGIN_FSM_RULE(CPortableScannerFSM, s0)
@@ -303,8 +312,6 @@ public:
 
 
 		FSM_RULE_ENTRY(s3, s1, USER_EVT_STARTPREVIEW_FINISHED, 0)
-		//FSM_RULE_ENTRY(s3, s0, USER_EVT_RESET, 0)
-		//FSM_RULE_ENTRY(s3, s3, USER_EVT_RESET, 1)
 		FSM_RULE_ENTRY(s3, s1, USER_EVT_RESET, 2)
 		FSM_RULE_ENTRY(s3, s5, USER_EVT_DROP_OFF_DEVICE, 1)
 		FSM_RULE_ENTRY(s3, s5, USER_EVT_BIND_DEVICE_FINISHED, 0)
@@ -411,16 +418,6 @@ public:
 	virtual void s7_on_exit();
 	virtual unsigned int s7_on_event(FSMEvent* e);
 
-	virtual void s8_on_entry() {
-		Dbg("Enter Idiot status");
-		m_eDevStatus = DEVICE_STATUS_NOCFG;
-	}
-	virtual void s8_on_exit() {
-		Dbg("Leave Idiot status");
-		m_eDevStatus = DEVICE_STATUS_NORMAL;
-	}
-	virtual unsigned int s8_on_event(FSMEvent* e);
-
 	virtual void OnStateTrans(int iSrcState, int iDstState);
 
 	int BindDevice(SpReqAnsContext<PortableScannerService_BindCameraDevice_Req,
@@ -429,6 +426,7 @@ public:
 	int StartPreview(SpReqAnsContext<PortableScannerService_StartPreview_Req,
 		PortableScannerService_StartPreview_Ans>::Pointer ctx);
 
+	/** Alaways return Error_Succeed Gifur@2022715]*/
 	ErrorCodeEnum SetPreview(SpReqAnsContext<PortableScannerService_StartPreview_Req,
 		PortableScannerService_StartPreview_Ans>::Pointer ctx);
 
@@ -496,6 +494,11 @@ private:
 	CapTypeEnum m_capCurrentType;
 
 	DWORD m_dwEntDevelID;
+	DWORD m_dwMaxImageSize;
+
+	BOOL m_fNotCloseCamereAtMainPage;
+
+	CRITICAL_SECTION m_csOpenCamera;
 
 public:
 
@@ -507,6 +510,7 @@ public:
 
 	DWORD GetCustLastErrorCode() { return m_dwErroCode; }
 	void SetCustLastErrorCode(DWORD dwVal = 0) { m_dwErroCode = dwVal; }
+	bool ResizeImage(CSimpleStringA fileName);
 
 private:
 	BOOL GetCurImageName(CSimpleStringA& csImagName, bool bExt = false);
@@ -530,6 +534,8 @@ private:
 
 	DWORD GetPortableDevID(LPCTSTR lpcszDevName);
 	void FireLogEventMsg(DWORD dwUserPlainCode, LPCTSTR lpcszMessage);
+	void InitialMaxResizeValue();
+
 };
 
 struct BindDeviceTask : public ITaskSp
@@ -585,7 +591,6 @@ struct SetPropertyInPreviewTask : public ITaskSp
 	{
 		FSMEvent* pEvt = new FSMEvent(USER_EVT_SETPROPERTYINVIEW_FINISHED);
 		ErrorCodeEnum eRet = m_fsm->SetPreview(m_ctx);
-		Dbg("SetPreview returned: %d, testCode: %d.", eRet, m_ctx->Ans.reserved1);
 		m_ctx->Answer(eRet);
 		if(ISSUCCEEDED(eRet))
 			pEvt->param1 = 0;
@@ -742,7 +747,7 @@ struct GetDevStatusTask : public ITaskSp
 	{
 		m_fsm->GetDevStatus(m_ctx);
 		if(m_ctx->Ans.connected == 0 && m_fsm->GetCurrState()->id != CPortableScannerFSM::s5) {
-			Dbg("Detect that not have device attached and not stay in NotHold situation");
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Detect that not have device attached and not stay in NotHold situation");
 			m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_NO_CONTAINS_DEVICE));
 		}
 		return;

+ 15 - 1
Module/mod_PortableScanner/PortableScanner_def_g.h

@@ -19,7 +19,7 @@ namespace PortableScanner {
 
 enum CapTypeEnum {
 	CAMTYPE_UNKNOWN = 0,
-	CAMTYPE_ENV, /*PAD锛屽墠缃�憚鍍忓ご*/
+	CAMTYPE_ENV, /*PAD,前置摄像头*/
 	CAMTYPE_OPT,
 	CAMTYPE_EWS,
 	CAMTYPE_HSPS,
@@ -27,6 +27,7 @@ enum CapTypeEnum {
 	CAMTYPE_MAX
 };
 
+
 #define PortableScannerService_Method_BindCameraDevice 0
 #define PortableScannerService_Method_DropOffDevice 1
 #define PortableScannerService_Method_StartPreview 2
@@ -53,6 +54,19 @@ enum CapTypeEnum {
 #define PortableScannerService_MethodSignature_GetDevInfo 296205965
 #define PortableScannerService_MethodSignature_Exit -1158854104
 
+#define PortableScannerService_LogCode_BindCameraDevice "QLR040221C00"
+#define PortableScannerService_LogCode_DropOffDevice "QLR040221C01"
+#define PortableScannerService_LogCode_StartPreview "QLR040221C02"
+#define PortableScannerService_LogCode_CancelPreview "QLR040221C03"
+#define PortableScannerService_LogCode_ScanImage "QLR040221C04"
+#define PortableScannerService_LogCode_ScanImageEx "QLR040221C05"
+#define PortableScannerService_LogCode_SetProperty "QLR040221C06"
+#define PortableScannerService_LogCode_SetWinPos "QLR040221C07"
+#define PortableScannerService_LogCode_ShowProperty "QLR040221C08"
+#define PortableScannerService_LogCode_GetDevStatus "QLR040221C09"
+#define PortableScannerService_LogCode_GetDevInfo "QLR040221C99"
+#define PortableScannerService_LogCode_Exit "QLR040221C10"
+
 struct PortableScannerService_BindCameraDevice_Req
 {
 	CSimpleStringA devName;

+ 0 - 12
Module/mod_PortableScanner/PortableScanner_server_g.h

@@ -274,7 +274,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_BindCameraDevice_Req,PortableScannerService_BindCameraDevice_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_BindCameraDevice(ctx);
 					}
 					break;
@@ -284,7 +283,6 @@ public:
 						ctx.Attach(new SpOnewayCallContext<PortableScannerService_DropOffDevice_Info>());
 						SpBuffer2Object(Buf, ctx->Info);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_DropOffDevice(ctx);
 					}
 					break;
@@ -294,7 +292,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_StartPreview_Req,PortableScannerService_StartPreview_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_StartPreview(ctx);
 					}
 					break;
@@ -304,7 +301,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_CancelPreview_Req,PortableScannerService_CancelPreview_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_CancelPreview(ctx);
 					}
 					break;
@@ -314,7 +310,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_ScanImage_Req,PortableScannerService_ScanImage_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_ScanImage(ctx);
 					}
 					break;
@@ -324,7 +319,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_ScanImageEx_Req,PortableScannerService_ScanImageEx_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_ScanImageEx(ctx);
 					}
 					break;
@@ -334,7 +328,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_SetProperty_Req,PortableScannerService_SetProperty_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_SetProperty(ctx);
 					}
 					break;
@@ -344,7 +337,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_SetWinPos_Req,PortableScannerService_SetWinPos_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_SetWinPos(ctx);
 					}
 					break;
@@ -354,7 +346,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_ShowProperty_Req,PortableScannerService_ShowProperty_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_ShowProperty(ctx);
 					}
 					break;
@@ -364,7 +355,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_GetDevStatus_Req,PortableScannerService_GetDevStatus_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_GetDevStatus(ctx);
 					}
 					break;
@@ -374,7 +364,6 @@ public:
 						ctx.Attach(new SpReqAnsContext<PortableScannerService_GetDevInfo_Req,PortableScannerService_GetDevInfo_Ans>(pTransactionContext));
 						SpBuffer2Object(Buf, ctx->Req);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_GetDevInfo(ctx);
 					}
 					break;
@@ -384,7 +373,6 @@ public:
 						ctx.Attach(new SpOnewayCallContext<PortableScannerService_Exit_Info>());
 						SpBuffer2Object(Buf, ctx->Info);
 						pTransactionContext->GetLinkContext(ctx->link);
-						EntityResource::setLink(ctx->link);
 						Handle_Exit(ctx);
 					}
 					break;

+ 33 - 0
Module/mod_PortableScanner/UserEventCode.h

@@ -14,6 +14,39 @@
 #define SCAN_IMAGE_EX_FAILED			6
 #define RESET_CAMERE_FAILED				7
 
+#define LOG_ERROR_PORTABLESCANNER_OPEN_CAMERA_FAILED 0x21C00001
+#define LOG_ERROR_PORTABLESCANNER_START_PREVIEW_FAILED 0x21C00002
+#define LOG_ERROR_PORTABLESCANNER_STOP_PREVIEW_FAILED 0x21C00003
+#define LOG_ERROR_PORTABLESCANNER_PREVIEWING_OCCURS_EXCEPTION 0x21C00004
+#define LOG_ERROR_PORTABLESCANNER_SCAN_IMAGE_FAILED 0x21C00005
+#define LOG_ERROR_PORTABLESCANNER_SCAN_IMAGE_EX_FAILED 0x21C00006
+#define LOG_ERROR_PORTABLESCANNER_RESET_CAMERE_FAILED 0x21C00007
+#define LOG_ERROR_PORTABLESCANNER_GET_IMAGE_NAME_PATH_FAILED 0x21C00008
+#define LOG_ERROR_PORTABLESCANNER_GET_OPEN_IMAGE_FAILED 0x21C00009
+#define LOG_ERROR_PORTABLESCANNER_GET_IMAGE_INVALID 0x21C0000A
+
+#define LOG_EVT_PORTABLESCANNER_NO_AVAILABLE 0x21C00201
+#define LOG_ERROR_PORTABLESCANNER_BUSY_ONE 0x21C00204
+#define LOG_ERROR_PORTABLESCANNER_BUSY_TWO 0x21C00205
+#define LOG_ERROR_PORTABLESCANNER_CREATE_OBJECT_FAILED 0x21C00206
+#define LOG_DEBUG_PORTABLESCANNER_ATTACH_CAMERE 0x21C00207
+#define LOG_DEBUG_PORTABLESCANNER_INVALID_CAMERA_NAME 0x21C00208
+#define LOG_ERROR_PORTABLESCANNER_INVALIDSTATE 0x21C00209
+#define LOG_ERROR_PORTABLESCANNER_UNBIND 0x21C0020A
+#define LOG_ERROR_PORTABLESCANNER_OPEN_CAMERA_WITH_NAME_FAILED 0x21C0020B
+#define LOG_ERROR_PORTABLESCANNER_OPEN_CAMERA_WITH_ID_FAILED 0x21C0020C
+#define LOG_WARN_PORTABLESCANNER_OPEN_DUPLICATE 0x21C0020D
+
+#define LOG_ERROR_PORTABLESCANNER_GET_CONFIGURED_SIZEVALUE 0x21C0020D
+#define LOG_EVT_PORTABLESCANNER_READ_IMAGE_FILE_FAILED 0x21C0020E
+#define LOG_WARN_PORTABLESCANNER_OPENCV_READ_FAILED 0x21C0020F
+#define LOG_WARN_PORTABLESCANNER_OPENCV_WRITE_FAILED 0x21C00210
+#define LOG_WARN_PORTABLESCANNER_RESIZE_FUNCTION_SUCCEED 0x21C00211
+#define LOG_EVT_PORTABLESCANNER_SCANIMAGE_FUNCTION_SUCCEED 0x21C00212
+#define LOG_WARN_PORTABLESCANNER_RESIZE_IMAGE_FILE_FAILED 0x21C00213
+#define LOG_ERROR_PORTABLESCANNER_SCANIMAGE_FUNCTION_FAILED 0x21C00214
+#define LOG_EVT_PORTABLESCANNER_SCANIMAGEEX_FUNCTION_SUCCEED 0x21C00215
+#define LOG_ERROR_PORTABLESCANNER_SCANIMAGEEX_FUNCTION_FAILED 0x21C00216
 
 
 

+ 13 - 1
Module/mod_PortableScanner/mod_PortableScanner.cpp

@@ -1,4 +1,4 @@
-// mod_PortableScanner.cpp : 瀹氫箟 DLL 搴旂敤绋嬪簭鐨勫�鍑哄嚱鏁般€�
+// mod_PortableScanner.cpp : 定义 DLL 应用程序的导出函数。
 //
 
 #include "stdafx.h"
@@ -9,6 +9,7 @@ void CPortableScannerServerSession::Handle_BindCameraDevice(
 	PortableScannerService_BindCameraDevice_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->BindDevice(ctx);
 }
 
@@ -16,6 +17,7 @@ void CPortableScannerServerSession::Handle_StartPreview(SpReqAnsContext<Portable
 	PortableScannerService_StartPreview_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->Preview(ctx);
 }
 
@@ -23,6 +25,7 @@ void CPortableScannerServerSession::Handle_CancelPreview(SpReqAnsContext<Portabl
 	PortableScannerService_CancelPreview_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->CancelPreview(ctx);
 }
 
@@ -30,6 +33,7 @@ void CPortableScannerServerSession::Handle_ScanImage(SpReqAnsContext<PortableSca
 	PortableScannerService_ScanImage_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->ScanImage(ctx);
 }
 
@@ -37,6 +41,7 @@ void CPortableScannerServerSession::Handle_ScanImageEx(SpReqAnsContext<PortableS
 	PortableScannerService_ScanImageEx_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->ScanImageEx(ctx);
 }
 
@@ -44,6 +49,7 @@ void CPortableScannerServerSession::Handle_SetProperty(SpReqAnsContext<PortableS
 	PortableScannerService_SetProperty_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->SetProperty(ctx);
 }
 
@@ -51,12 +57,14 @@ void CPortableScannerServerSession::Handle_SetWinPos(SpReqAnsContext<PortableSca
 	PortableScannerService_SetWinPos_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->SetWinPos(ctx);
 }
 
 void CPortableScannerServerSession::Handle_ShowProperty(SpReqAnsContext<PortableScannerService_ShowProperty_Req, PortableScannerService_ShowProperty_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->ShowProperty(ctx);
 }
 
@@ -64,6 +72,7 @@ void CPortableScannerServerSession::Handle_GetDevStatus(SpReqAnsContext<Portable
 	PortableScannerService_GetDevStatus_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->GetDevStatus(ctx);
 }
 
@@ -71,12 +80,14 @@ void CPortableScannerServerSession::Handle_GetDevInfo(SpReqAnsContext<PortableSc
 	PortableScannerService_GetDevInfo_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->GetDevInfo(ctx);
 }
 
 void CPortableScannerServerSession::Handle_Exit(SpOnewayCallContext<PortableScannerService_Exit_Info>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->Exit(ctx);
 }
 
@@ -84,6 +95,7 @@ void CPortableScannerServerSession::Handle_DropOffDevice(
 	SpOnewayCallContext<PortableScannerService_DropOffDevice_Info>::Pointer ctx)
 {
 	LOG_FUNCTION();
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->DropOffDevice(ctx);
 }
 

+ 2 - 1
Module/mod_PortableScanner/mod_PortableScanner.vcxproj

@@ -56,7 +56,7 @@
     <Link>
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>$(FrameworkLib)\SpBase.lib;$(ThirdPartyLib)\opencv_highgui310d.lib;$(ThirdPartyLib)\opencv_video310d.lib;$(ThirdPartyLib)\opencv_core310d.lib;$(ThirdPartyLib)\opencv_imgproc310d.lib;$(ThirdPartyLib)\opencv_videoio310d.lib;$(ThirdPartyLib)\opencv_imgcodecs310d.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>$(FrameworkLib)\SpBase.lib;$(FrameworkLib)\libtoolkit.lib;$(ThirdPartyLib)\opencv_highgui310d.lib;$(ThirdPartyLib)\opencv_video310d.lib;$(ThirdPartyLib)\opencv_core310d.lib;$(ThirdPartyLib)\opencv_imgproc310d.lib;$(ThirdPartyLib)\opencv_videoio310d.lib;$(ThirdPartyLib)\opencv_imgcodecs310d.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -86,6 +86,7 @@
     <ClInclude Include="PortableScanner_msg_g.h" />
     <ClInclude Include="PortableScanner_server_g.h" />
     <ClInclude Include="targetver.h" />
+    <ClInclude Include="UserEventCode.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="DocScannerCap.cpp" />

+ 3 - 0
Module/mod_PortableScanner/mod_PortableScanner.vcxproj.filters

@@ -39,6 +39,9 @@
     <ClInclude Include="DocScannerCap.h">
       <Filter>头文件</Filter>
     </ClInclude>
+    <ClInclude Include="UserEventCode.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="mod_PortableScanner.cpp">

部分文件因文件數量過多而無法顯示