f88bb3bbd94f3f9c78d69952c4cdfcc0297d9b68
[senf.git] / Utils / Logger / TimeSource.hh
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief TimeSource public header */
25
26 #ifndef HH_TimeSource_
27 #define HH_TimeSource_ 1
28
29 // Custom includes
30 #include <boost/cstdint.hpp>
31 #include <memory>
32
33 //#include "TimeSource.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37 namespace log {
38
39     typedef boost::int_fast64_t time_type;
40
41     /** \brief Log message time source abstract base class
42
43         Instances derived from TimeSource provide the Logging library with the current date/time
44         value. The \c operator() member must be implemented to return the current universal time
45         (UTC).
46
47         A new TimeSource may be installed using \ref senf::log::timeSource().
48
49         \ingroup config
50      */
51     struct TimeSource
52     {
53         virtual ~TimeSource();
54         virtual time_type operator()() const = 0;
55
56         static time_type now();
57     };
58
59     /** \brief Default %log message time source
60
61         This time source is installed by default and uses gettimeofday() (via the Boost.DateTime
62         library) to get the current universal time.
63         
64         \ingroup config
65      */
66     struct SystemTimeSource : public TimeSource
67     {
68         virtual time_type operator()() const;
69     };
70
71     /** \brief Change %log message time source
72
73         Set the %log message time source to \a source. The logging library will take ownership of \e
74         source and will take care to free it, if necessary.
75
76         Since the time source class will in almost all cases be default constructible, see the
77         template overload for a simpler interface.
78
79         \ingroup config
80      */
81     void timeSource(std::auto_ptr<TimeSource> source);
82
83     /** \brief Change %log message time source
84
85         Set the %log message time source to (an instance of) \a Source.  \a Source must be default
86         constructible, otherwise use the non-template senf::log::timeSource() overload.
87
88         \ingroup config
89      */
90     template <class Source> void timeSource();
91
92 }}
93
94 ///////////////////////////////hh.e////////////////////////////////////////
95 #include "TimeSource.cci"
96 //#include "TimeSource.ct"
97 #include "TimeSource.cti"
98 #endif
99
100 \f
101 // Local Variables:
102 // mode: c++
103 // fill-column: 100
104 // comment-column: 40
105 // c-file-style: "senf"
106 // indent-tabs-mode: nil
107 // ispell-local-dictionary: "american"
108 // compile-command: "scons -u test"
109 // End: