Collage  1.0.1
Object-Oriented C++ Network Library
worker.h
1 
2 /* Copyright (c) 2011-2013, Stefan Eilemann <eile@eyescale.ch>
3  *
4  * This file is part of Collage <https://github.com/Eyescale/Collage>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef CO_WORKER_H
21 #define CO_WORKER_H
22 
23 #include <co/api.h> // CO_API definition
24 #include <co/types.h>
25 #include <lunchbox/thread.h> // base class
26 
27 #ifndef CO_WORKER_API
28 # define CO_WORKER_API CO_API
29 #endif
30 
31 namespace co
32 {
34 template< class Q > class WorkerThread : public lunchbox::Thread
35 {
36 public:
39 
41  virtual ~WorkerThread() {}
42 
44  Q* getWorkerQueue() { return &_commands; }
45 
46 protected:
48  virtual bool init()
49  {
50  setName( lunchbox::className( this ));
51  return true;
52  }
53 
55  CO_WORKER_API virtual void run();
56 
58  virtual bool stopRunning() { return false; }
59 
61  virtual bool notifyIdle() { return false; }
62 
63 private:
65  Q _commands;
66 };
67 
68 typedef WorkerThread< CommandQueue > Worker; // instantiated in worker.cpp
69 }
70 #endif //CO_WORKER_H
virtual bool notifyIdle()
Definition: worker.h:61
virtual bool stopRunning()
Definition: worker.h:58
Q * getWorkerQueue()
Definition: worker.h:44
virtual ~WorkerThread()
Destruct the worker.
Definition: worker.h:41
virtual bool init()
Definition: worker.h:48
WorkerThread()
Construct a new worker thread.
Definition: worker.h:38
virtual CO_WORKER_API void run()
Definition: worker.ipp:25