123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #pragma once
- #include "TaskDispatcher.h"
- #include "MutilTaskExcute.h"
- #include "ServerImgDownloadTask.h"
- #include <vector>
- using namespace std;
- class CServerImgDownloadDispatcher:public CMutilTaskDispatcher<CServerImgDownloadTask>
- {
- public:
- CServerImgDownloadDispatcher(void);
- ~CServerImgDownloadDispatcher(void);
- void setImageInfo( Json::Value* m_imginfos );
- virtual CServerImgDownloadTask * GetNextTask();
- virtual void SaveTask( CServerImgDownloadTask * task);
- Json::Value *m_imgInfos;
- int m_lastCreatedTaskIndex;
- vector<CServerImgDownloadTask *> tasks;
- enum TASK_STATE{
- TS_NOCREATE,
- TS_EXCUTING,
- TS_EXCUTED,
- TS_FIALURE,
- };
- void setImageDownloadDir(CString dir){m_img_download_dir =dir;}
- vector<TASK_STATE> tasks_excuted;
- int m_lastHandledIndex;
- bool m_isError;
- CString m_img_download_dir;
- bool GetNext(CString & imgpath,int & img_index){
- int current_get_index =m_lastHandledIndex+1;
- if(current_get_index<m_imgInfos->size()){
- while(TRUE){
- switch(tasks_excuted[current_get_index]){
- case TS_EXCUTED :
- img_index = current_get_index;
- imgpath = tasks[current_get_index]->GetImgPath();
- m_lastHandledIndex=current_get_index;
- return true;
- break;
- case TS_FIALURE :
- return false;
- break;
- }
- Sleep(10);
- }
- }
- return false;
- }
- };
|