1 /* 2 * Copyright 2015, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef WORKER_H 6 #define WORKER_H 7 8 9 #include <Job.h> 10 #include <JobQueue.h> 11 12 13 using namespace BSupportKit; 14 using BSupportKit::BPrivate::JobQueue; 15 16 17 class Worker { 18 public: 19 Worker(JobQueue& queue); 20 virtual ~Worker(); 21 22 status_t Init(); 23 24 protected: 25 virtual status_t Process(); 26 virtual bigtime_t Timeout() const; 27 virtual const char* Name() const; 28 virtual status_t Run(BJob* job); 29 30 private: 31 static status_t _Process(void* self); 32 33 protected: 34 thread_id fThread; 35 JobQueue& fJobQueue; 36 }; 37 38 39 class MainWorker : public Worker { 40 public: 41 MainWorker(JobQueue& queue); 42 43 protected: 44 virtual bigtime_t Timeout() const; 45 virtual const char* Name() const; 46 virtual status_t Run(BJob* job); 47 48 private: 49 int32 fMaxWorkerCount; 50 }; 51 52 53 #endif // WORKER_H 54