ServerImgDownloadDispatcher.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include "TaskDispatcher.h"
  3. #include "MutilTaskExcute.h"
  4. #include "ServerImgDownloadTask.h"
  5. #include <vector>
  6. using namespace std;
  7. class CServerImgDownloadDispatcher:public CMutilTaskDispatcher<CServerImgDownloadTask>
  8. {
  9. public:
  10. CServerImgDownloadDispatcher(void);
  11. ~CServerImgDownloadDispatcher(void);
  12. void setImageInfo( Json::Value* m_imginfos );
  13. virtual CServerImgDownloadTask * GetNextTask();
  14. virtual void SaveTask( CServerImgDownloadTask * task);
  15. Json::Value *m_imgInfos;
  16. int m_lastCreatedTaskIndex;
  17. vector<CServerImgDownloadTask *> tasks;
  18. enum TASK_STATE{
  19. TS_NOCREATE,
  20. TS_EXCUTING,
  21. TS_EXCUTED,
  22. TS_FIALURE,
  23. };
  24. void setImageDownloadDir(CString dir){m_img_download_dir =dir;}
  25. vector<TASK_STATE> tasks_excuted;
  26. int m_lastHandledIndex;
  27. bool m_isError;
  28. CString m_img_download_dir;
  29. bool GetNext(CString & imgpath,int & img_index){
  30. int current_get_index =m_lastHandledIndex+1;
  31. if(current_get_index<m_imgInfos->size()){
  32. while(TRUE){
  33. switch(tasks_excuted[current_get_index]){
  34. case TS_EXCUTED :
  35. img_index = current_get_index;
  36. imgpath = tasks[current_get_index]->GetImgPath();
  37. m_lastHandledIndex=current_get_index;
  38. return true;
  39. break;
  40. case TS_FIALURE :
  41. return false;
  42. break;
  43. }
  44. Sleep(10);
  45. }
  46. }
  47. return false;
  48. }
  49. };