| 1 | /* |
| 2 | The software in this package is distributed under the GNU General |
| 3 | Public License version 2 (with a special exception described below). |
| 4 | |
| 5 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 6 | in the file COPYING.GPL. |
| 7 | |
| 8 | As a special exception, if other files instantiate templates or use macros |
| 9 | or inline functions from this file, or you compile this file and link it |
| 10 | with other works to produce a work based on this file, this file |
| 11 | does not by itself cause the resulting work to be covered |
| 12 | by the GNU General Public License. |
| 13 | |
| 14 | However the source code for this file must still be made available |
| 15 | in accordance with section (3) of the GNU General Public License. |
| 16 | |
| 17 | This exception does not invalidate any other reasons why a work based |
| 18 | on this file might be covered by the GNU General Public License. |
| 19 | */ |
| 20 | /** @file |
| 21 | * |
| 22 | * provides timer objects based on the TimerBase class |
| 23 | * |
| 24 | * (c) Copyright 2007 by Intra2net AG |
| 25 | */ |
| 26 | |
| 27 | #ifndef __ASYNC_TIMER_HPP__ |
| 28 | #define __ASYNC_TIMER_HPP__ |
| 29 | |
| 30 | #include "async_io.hpp" |
| 31 | |
| 32 | #include <boost/signals2.hpp> |
| 33 | |
| 34 | namespace AsyncIo |
| 35 | { |
| 36 | |
| 37 | |
| 38 | class SimpleTimer : public TimerBase |
| 39 | { |
| 40 | public: |
| 41 | |
| 42 | typedef boost::signals2::signal<void()> TimerSignal; |
| 43 | typedef boost::signals2::signal<void(SimpleTimer*)> TimerSignalP; |
| 44 | |
| 45 | public: |
| 46 | |
| 47 | SimpleTimer(); |
| 48 | |
| 49 | // convenience constructors for simple timeouts: |
| 50 | SimpleTimer(const MilliTime& delta, const TimerSignal::slot_function_type& action); |
| 51 | SimpleTimer(long milli_seonds_delta, const TimerSignal::slot_function_type& action); |
| 52 | |
| 53 | // add actions: |
| 54 | void addAction( const TimerSignal::slot_function_type& action ); |
| 55 | void addActionP( const TimerSignalP::slot_function_type& action ); |
| 56 | |
| 57 | // start the timer: |
| 58 | void startTimer( const MilliTime& delta ); |
| 59 | void startTimerMS( long milli_seconds ); |
| 60 | |
| 61 | // stop the timer: |
| 62 | void stopTimer(); |
| 63 | |
| 64 | protected: |
| 65 | MilliTime m_delta; |
| 66 | |
| 67 | TimerSignal m_timer_signal; |
| 68 | TimerSignalP m_timer_signal_p; |
| 69 | |
| 70 | virtual void execute(); |
| 71 | }; // eo class SimpleTimer |
| 72 | |
| 73 | |
| 74 | } // eo namespace AsyncIo |
| 75 | |
| 76 | #endif |