#include "StdAfx.h" #include "ServerImgDownloadDispatcher.h" #ifdef _DEBUG #define SERVERIMGDOWNLOADWORKERCOUNT 1 #else #define SERVERIMGDOWNLOADWORKERCOUNT 3 #endif CServerImgDownloadDispatcher::CServerImgDownloadDispatcher(void):CMutilTaskDispatcher(SERVERIMGDOWNLOADWORKERCOUNT) { } CServerImgDownloadDispatcher::~CServerImgDownloadDispatcher(void) { } void CServerImgDownloadDispatcher::setImageInfo( Json::Value* imginfos ) { m_imgInfos =imginfos; m_lastCreatedTaskIndex =-1; m_lastHandledIndex =-1; m_isError=false; if(imginfos->size()>0){ tasks.resize(imginfos->size(),0); tasks_excuted.resize(imginfos->size(),TS_NOCREATE); } } CServerImgDownloadTask * CServerImgDownloadDispatcher::GetNextTask() { if(m_isError)return 0;//已经发生错误,结束下载 int size =m_imgInfos->size(); if(m_lastCreatedTaskIndex+1=0;idx--) { if(tasks[idx]==task){ if(task->GetResult()){ tasks_excuted[idx] = TS_EXCUTED; }else{ m_isError=true; tasks_excuted[idx] = TS_FIALURE; } break; } } }