pion  5.0.6
include/pion/tcp/timer.hpp
00001 // ---------------------------------------------------------------------
00002 // pion:  a Boost C++ framework for building lightweight HTTP interfaces
00003 // ---------------------------------------------------------------------
00004 // Copyright (C) 2007-2014 Splunk Inc.  (https://github.com/splunk/pion)
00005 //
00006 // Distributed under the Boost Software License, Version 1.0.
00007 // See http://www.boost.org/LICENSE_1_0.txt
00008 //
00009 
00010 #ifndef __PION_TCP_TIMER_HEADER__
00011 #define __PION_TCP_TIMER_HEADER__
00012 
00013 #include <boost/asio.hpp>
00014 #include <boost/bind.hpp>
00015 #include <boost/shared_ptr.hpp>
00016 #include <boost/enable_shared_from_this.hpp>
00017 #include <boost/thread/mutex.hpp>
00018 #include <pion/config.hpp>
00019 #include <pion/tcp/connection.hpp>
00020 
00021 
00022 namespace pion {    // begin namespace pion
00023 namespace tcp {     // begin namespace tcp
00024 
00025 
00029 class PION_API timer
00030     : public boost::enable_shared_from_this<timer>
00031 {
00032 public:
00033 
00039     timer(tcp::connection_ptr& conn_ptr);
00040 
00046     void start(const boost::uint32_t seconds);
00047 
00049     void cancel(void);
00050 
00051 
00052 private:
00053 
00059     void timer_callback(const boost::system::error_code& ec);
00060 
00062     tcp::connection_ptr                     m_conn_ptr;
00063 
00065     boost::asio::deadline_timer             m_timer;
00066     
00068     boost::mutex                            m_mutex;
00069 
00071     bool                                    m_timer_active; 
00072 
00074     bool                                    m_was_cancelled;    
00075 };
00076 
00077 
00079 typedef boost::shared_ptr<timer>     timer_ptr;
00080 
00081 
00082 }   // end namespace tcp
00083 }   // end namespace pion
00084 
00085 #endif