pion  5.0.6
timer.hpp
1 // ---------------------------------------------------------------------
2 // pion: a Boost C++ framework for building lightweight HTTP interfaces
3 // ---------------------------------------------------------------------
4 // Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
8 //
9 
10 #ifndef __PION_TCP_TIMER_HEADER__
11 #define __PION_TCP_TIMER_HEADER__
12 
13 #include <boost/asio.hpp>
14 #include <boost/bind.hpp>
15 #include <boost/shared_ptr.hpp>
16 #include <boost/enable_shared_from_this.hpp>
17 #include <boost/thread/mutex.hpp>
18 #include <pion/config.hpp>
19 #include <pion/tcp/connection.hpp>
20 
21 
22 namespace pion { // begin namespace pion
23 namespace tcp { // begin namespace tcp
24 
25 
29 class PION_API timer
30  : public boost::enable_shared_from_this<timer>
31 {
32 public:
33 
39  timer(tcp::connection_ptr& conn_ptr);
40 
46  void start(const boost::uint32_t seconds);
47 
49  void cancel(void);
50 
51 
52 private:
53 
59  void timer_callback(const boost::system::error_code& ec);
60 
62  tcp::connection_ptr m_conn_ptr;
63 
65  boost::asio::deadline_timer m_timer;
66 
68  boost::mutex m_mutex;
69 
71  bool m_timer_active;
72 
74  bool m_was_cancelled;
75 };
76 
77 
79 typedef boost::shared_ptr<timer> timer_ptr;
80 
81 
82 } // end namespace tcp
83 } // end namespace pion
84 
85 #endif