#include #include #include #define ProcessingException 37 //----------------------------------------------------------------------- // C-style call to drive the QueueProcessor //----------------------------------------------------------------------- extern "C" void* driveQueue (void*); //----------------------------------------------------------------------- // Task //----------------------------------------------------------------------- class Task { public: Task () {}; virtual void execute () throw (int) = 0; virtual char* getDescription () { return "BaseTask"; }; friend ostream& operator<< (ostream& stream, Task* t) { stream << "Task[" << t->getDescription() << "]"; return stream; }; }; //----------------------------------------------------------------------- // QueueProcessor //----------------------------------------------------------------------- class QueueProcessor { private: bool _stopped; pthread_cond_t _condition; pthread_mutex_t _mutex; pthread_t _thread; list* _queue; public: QueueProcessor (); ~QueueProcessor (); void appendTask (Task*); void start (); void stop (); void processTasks (); };