#include "StdAfx.h" #include "RescanFromServerFeeder.h" #include "..\EvaluationUtil\HttpClient.h" #include "ServerConfig.h" CRescanFromServerFeeder::CRescanFromServerFeeder(void) { m_img =NULL; InitializeCriticalSection(&m_img_lock); } CRescanFromServerFeeder::~CRescanFromServerFeeder(void) { DeleteCriticalSection(&m_img_lock); } ServiceState CRescanFromServerFeeder::OnStarting( void ) { m_img = NULL; m_count =0; CHttpClient httpClient; string response; CString url_str; url_str.Format(_T("%s/%s"),CServerConfig::server_address_type==SAT_LOCAL_IN?CServerConfig::server_url_local_in:CServerConfig::server_address_type==SAT_LOCAL_OUT?CServerConfig::server_url_local_out:CServerConfig::server_url,_T("scan/findPaperImages")); CString postData; if(m_mode==MODE_EXAMINNE)postData.Format(_T("examId=%ld&examCourseId=%ld&batch=%s&examineeId=%s"),examId,examCourseId,m_batch,m_examineeId); else postData.Format(_T("examId=%ld&examCourseId=%ld&batch=%s"),examId,examCourseId,m_batch); httpClient.HttpPost(url_str,postData,response); Json::Features features; Json::Reader re(features); Json::Value root; re.parse(response,root); if(!(root["success"].isInt()&&root["success"].asInt())){ return stoping; } Json::Value rows =root["object"]; if(!(rows.isArray()&&rows.size()>0)){ return stoping; } m_imginfos =rows; sidd.setImageInfo(&m_imginfos); sidd.setImageDownloadDir(m_imgDownloadDir); sidd.Start(); return ServiceState::running; } ServiceState CRescanFromServerFeeder::OnRunning( void ) { ServiceState nextState = IService::OnRunning(); if(nextState != running) return nextState; if(m_img==NULL){ CString img_path;int img_index; bool success =sidd.GetNext(img_path,img_index); if(success){ char img_path1[512]; int len = WideCharToMultiByte(CP_ACP,0,img_path,-1,NULL,0,NULL,NULL); len=WideCharToMultiByte(CP_ACP,0,img_path,-1,img_path1,len,NULL,NULL); img_path1[len]=0; m_img =cvLoadImage(img_path1,1); m_param.type = identyfi_type_normal; m_param.srcimg_type = SRC_IMG_HANDLE_TYPE_COPY; m_param.img_path =img_path1; m_count++; return running; }else { return stoping; } }else{ Sleep(10); return running; } } ServiceState CRescanFromServerFeeder::OnStoping( void ) { m_imginfos=Json::Value(); return stoped; } bool CRescanFromServerFeeder::GetNext( BOOL wait,IplImage* & img, feeder_param& param ) { do { BOOL isStoped = m_serviceState == stoped; if(m_img!=NULL){ EnterCriticalSection(&m_img_lock); if(m_img!=NULL){ img = m_img; param=m_param; m_img=NULL; LeaveCriticalSection(&m_img_lock); return true; } LeaveCriticalSection(&m_img_lock); } if(isStoped)return false; if(wait)Sleep(10); } while (wait); return false; }