Changeset 116 in pacpusframework for trunk/include/Pacpus/PacpusTools/PeriodicWorker.h
- Timestamp:
- 06/25/13 13:44:25 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Pacpus/PacpusTools/PeriodicWorker.h
r115 r116 23 23 namespace pacpus 24 24 { 25 /// @brief A simple base class for periodic worker. 26 /// 27 /// @example 28 /// To use the PeriodicWorker, simply inherit from this class when creating your worker. 29 /// ~~~ 30 /// class MyWorker 31 /// : public PeriodicWorkder 32 /// { 33 /// public: 34 /// void doWork() { std::cout << "Hey, I'm working!" << std::endl; } 35 /// }; 36 /// 37 /// // Do its work every second. 38 /// MyWorker worker; 39 /// worker.startWork(1000); 40 /// ~~~ 41 class PACPUSTOOLS_API PeriodicWorker 42 : public AsyncWorkerBase 43 { 25 26 /// @brief A simple base class for periodic worker. 27 /// 28 /// @example 29 /// To use the PeriodicWorker, simply inherit from this class when creating your worker. 30 /// ~~~ 31 /// class MyWorker 32 /// : public PeriodicWorkder 33 /// { 34 /// public: 35 /// void doWork() { std::cout << "Hey, I'm working!" << std::endl; } 36 /// }; 37 /// 38 /// // Do its work every second. 39 /// MyWorker worker; 40 /// worker.startWork(1000); 41 /// ~~~ 42 class PACPUSTOOLS_API PeriodicWorker 43 : public AsyncWorkerBase 44 { 44 45 Q_OBJECT 45 public: 46 /// Ctor of PeriodicWorker. 47 PeriodicWorker(); 48 49 /// Dtor of PeriodicWorker. 50 virtual ~PeriodicWorker(); 51 52 /** Start the periodic worker. 53 * @param msec Period in mseconds. 54 */ 55 void startWork(int msec); 56 57 /** Stop the periodic worker, but do not delete it. */ 58 void stopWork(); 59 60 public slots: 61 /** Do the work. 62 * This method need to be implemented in the subclasses, it will be called 63 * each time the timer has reached its period. 64 */ 65 virtual void doWork() = 0; 66 67 private: 68 QTimer* mHeartbeat; 69 }; 70 } 46 public: 47 /// Ctor of PeriodicWorker. 48 PeriodicWorker(); 49 50 /// Dtor of PeriodicWorker. 51 virtual ~PeriodicWorker(); 52 53 /// Start the periodic worker. 54 /// @param msec Period in mseconds. 55 void startWork(int msec); 56 57 /// Stop the periodic worker, but do not delete it. 58 void stopWork(); 59 60 public Q_SLOTS: 61 /// Do the work. 62 /// This method need to be implemented in the subclasses, it will be called 63 /// each time the timer has reached its period. 64 virtual void doWork() = 0; 65 66 private: 67 QTimer * mHeartbeat; 68 }; 69 70 } // namespace pacpus 71 71 72 72 #endif // DEF_PACPUS_PERIODIC_WORKER_H
Note:
See TracChangeset
for help on using the changeset viewer.