Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "../api/ana.hpp"
00034 #include <boost/bind.hpp>
00035 #include <boost/thread.hpp>
00036
00037 namespace ana
00038 {
00039 namespace detail
00040 {
00041
00042 time_t_traits::time_type time_t_traits::now()
00043 {
00044 return std::time(0);
00045 }
00046
00047
00048 time_t_traits::time_type time_t_traits::add(const time_type& t, const duration_type& d)
00049 {
00050 return t + d.value;
00051 }
00052
00053
00054 time_t_traits::duration_type time_t_traits::subtract(const time_type& t1,
00055 const time_type& t2)
00056 {
00057 return duration_type(t1 - t2);
00058 }
00059
00060
00061 bool time_t_traits::less_than(const time_t_traits::time_type& t1,
00062 const time_t_traits::time_type& t2)
00063 {
00064 return t1 < t2;
00065 }
00066
00067
00068 boost::posix_time::time_duration time_t_traits::to_posix_duration(const duration_type& d)
00069 {
00070 return boost::posix_time::seconds(d.value);
00071 }
00072 }
00073
00074
00075 timer::timer() :
00076 holds_fresh_io_service_( true ),
00077 io_service_(new boost::asio::io_service() ),
00078 timer_thread_( NULL ),
00079 timer_(*io_service_)
00080 {
00081 }
00082
00083 timer::timer( boost::asio::io_service& io ) :
00084 holds_fresh_io_service_( false ),
00085 io_service_( &io ),
00086 timer_thread_( NULL ),
00087 timer_(*io_service_)
00088 {
00089 }
00090
00091 timer::~timer()
00092 {
00093 if ( holds_fresh_io_service_ )
00094 {
00095 io_service_->stop();
00096 timer_thread_->join();
00097 delete timer_thread_;
00098 }
00099 }
00100
00101 void timer::run()
00102 {
00103 if ( holds_fresh_io_service_ )
00104 io_service_->run_one();
00105 }
00106
00107 namespace detail
00108 {
00109 void timed_sender::set_timeouts(timeout_policy type, size_t ms)
00110 {
00111 timeout_milliseconds_ = ms;
00112 if (ms > 0)
00113 timeout_type_ = type;
00114 else
00115 timeout_type_ = NoTimeouts;
00116 }
00117
00118 bool timed_sender::timeouts_enabled() const
00119 {
00120 return (timeout_milliseconds_ != 0) && (timeout_type_ != NoTimeouts);
00121 }
00122
00123 timed_sender::timed_sender() :
00124 timeout_type_( NoTimeouts ),
00125 timeout_milliseconds_( 0 )
00126 {
00127 }
00128 }
00129 }
00130