TQInterface.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // TQInterface.h
  3. // LibDriveRating-CXX
  4. //
  5. // Created by Melo Yao on 6/9/14.
  6. // Copyright (c) 2014 AutoNavi. All rights reserved.
  7. //
  8. #ifndef __LibDriveRating_CXX__TQInterface__
  9. #define __LibDriveRating_CXX__TQInterface__
  10. namespace tq {
  11. typedef unsigned long TaskCategory;
  12. const TaskCategory NoCategory = 0;
  13. class ITask
  14. {
  15. public:
  16. virtual void Run() = 0;
  17. virtual void Cancel() = 0;
  18. virtual bool IsCancelled() const = 0;
  19. virtual TaskCategory GetCategory() const = 0;
  20. virtual ~ITask(){}
  21. };
  22. typedef void (*TaskRecycler)(ITask* task,void* context);
  23. class IQueue
  24. {
  25. public:
  26. virtual void Start(unsigned int nThreads = 1) = 0;
  27. virtual void Stop() = 0;
  28. virtual void AddTask(ITask* task) = 0;
  29. virtual void GetTasks(ITask** tasksBuf, unsigned int taskBufSize) const= 0;
  30. virtual unsigned int TaskCount() const = 0;
  31. virtual void CancelAll() = 0;
  32. virtual void WaitForFinish() = 0;
  33. virtual void Suspend() = 0;
  34. virtual void Resume() = 0;
  35. virtual void SetTaskRecycler(TaskCategory cat, TaskRecycler recycler,void *context){}
  36. virtual void ClearTaskRecycler(TaskCategory cat){}
  37. virtual ~IQueue() {}
  38. };
  39. }
  40. #endif /* defined(__LibDriveRating_CXX__TQInterface__) */