Subversion Repositories HomeAutomation

Rev

Rev 1646 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  *
  3.  *    Copyright (C) 2010  Mattias Runge
  4.  *
  5.  *    This program is free software; you can redistribute it and/or modify
  6.  *    it under the terms of the GNU General Public License as published by
  7.  *    the Free Software Foundation; either version 2 of the License, or
  8.  *    (at your option) any later version.
  9.  *
  10.  *    This program is distributed in the hope that it will be useful,
  11.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *    GNU General Public License for more details.
  14.  *
  15.  *    You should have received a copy of the GNU General Public License along
  16.  *    with this program; if not, write to the Free Software Foundation, Inc.,
  17.  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  *
  19.  */
  20.  
  21. #ifndef TIMER_TIMER_H
  22. #define TIMER_TIMER_H
  23.  
  24. #include <boost/asio.hpp>
  25. #include <boost/signals2.hpp>
  26. #include <boost/shared_ptr.hpp>
  27.  
  28. #include "logging/Logger.h"
  29.  
  30. #include "types.h"
  31.  
  32. namespace atom {
  33. namespace timer {
  34.  
  35. class Timer
  36. {
  37. public:
  38.     typedef boost::shared_ptr<Timer> Pointer;
  39.    
  40.     typedef boost::signals2::signal<void(TimerId)> SignalOnTimeout;
  41.    
  42.     Timer(boost::asio::io_service& io_service, TimerId id, unsigned int timeout, bool repeat);
  43.     Timer(boost::asio::io_service& io_service, TimerId id, std::string time);
  44.     virtual ~Timer();
  45.  
  46.     void ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout);
  47.    
  48.     TimerId GetId();
  49.     bool GetRepeat();
  50.     void Start();
  51.     void Cancel();
  52.    
  53. private:
  54.     boost::asio::deadline_timer instance_;
  55.     TimerId id_;
  56.     std::string time_;
  57.     unsigned int timeout_;
  58.     bool repeat_;
  59.    
  60.     logging::Logger LOG;
  61.    
  62.     SignalOnTimeout signal_on_timeout_;
  63.    
  64.     void TimeoutHandler(const boost::system::error_code& error);
  65. };
  66.  
  67. }; // namespace timer
  68. }; // namespace atom
  69.  
  70. #endif // TIMER_TIMER_H
  71.