class timer_callback_t- {
- virtual void handle (timer_t &_timer, timer_callback_arg_t *_p_arg) = 0;
- };
- class timer_t
- {
- public:
- timer_t (msecond_t _duration, timer_callback_t *_p_callback,
- timer_callback_arg_t *_p_callback_arg);
- private:
- void fire ()
- {
- p_callback_.handle (this, p_callback_arg_);
- }
- timer_callback_t *p_callback_;
- timer_callback_arg_t *p_callback_arg_;
- };
- class connect_timeout_callback_t: public timer_callback_t
- {
- void handle (timer_t &_timer, timer_callback_arg_t *_p_arg)
- {
- // do something here
- }
- };
- void foo ()
- {
- static connect_timeout_callback_t callback;
- timer_t *p_timer = new timer_t (100, &callback, 0);
- }
- void bar ()
- {
- connect_timeout_callback_t *p_callback = new connect_timeout_callback_t ();
- timer_t *p_timer = new timer_t (100, p_callback, 0);
- }
- template <typename T_CALLBACK, typename T_CALLBACK_ARG>
- class timer_callback_t
- {
- virtual void handle (timer_t <T_CALLBACK, T_CALLBACK_ARG> &_timer,
- T_CALLBACK_ARG _arg) = 0;
- };
- template <typename T_CALLBACK, typename T_CALLBACK_ARG>
- class timer_t
- {
- public:
- timer_t (msecond_t _duration, T_CALLBACK_ARG _callback_arg);
- private:
- void fire ()
- {
- static T_CALLBACK callback;
- callback.handle (*this, callback_arg_);
- }
- T_CALLBACK_ARG callback_arg_;
- };
- class connect_timeout_callback_t:
- public timer_callback_t <connect_timeout_callback_t, void *>
- {
- void handle (timer_t <connect_timeout_callback_t, void *> &_timer, void *_arg)
- {
- // do something here
- }
- };
- void foo ()
- {
- timer_t <connect_timeout_callback_t, void *> *p_timer =
- new timer_t < connect_timeout_callback_t, void *> (100, 0);
- }