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 13using namespace BSupportKit; 14using BSupportKit::BPrivate::JobQueue; 15 16 17class Worker { 18public: 19 Worker(JobQueue& queue); 20 virtual ~Worker(); 21 22 status_t Init(); 23 24protected: 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 30private: 31 static status_t _Process(void* self); 32 33protected: 34 thread_id fThread; 35 JobQueue& fJobQueue; 36}; 37 38 39class MainWorker : public Worker { 40public: 41 MainWorker(JobQueue& queue); 42 43protected: 44 virtual bigtime_t Timeout() const; 45 virtual const char* Name() const; 46 virtual status_t Run(BJob* job); 47 48private: 49 int32 fMaxWorkerCount; 50}; 51 52 53#endif // WORKER_H 54