]> git.lyx.org Git - lyx.git/blob - src/support/FileMonitor.h
* lyxfunctional.h: delete compare_memfun and helper classes
[lyx.git] / src / support / FileMonitor.h
1 // -*- C++ -*-
2 /**
3  * \file FileMonitor.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * FileMonitor monitors a file and informs a listener when that file has
12  * changed.
13  */
14
15 #ifndef FILEMONITOR_H
16 #define FILEMONITOR_H
17
18 #include <boost/utility.hpp>
19 #include <boost/scoped_ptr.hpp>
20 #include <boost/signal.hpp>
21
22 namespace lyx {
23 namespace support {
24
25 class FileMonitor : boost::noncopyable {
26 public:
27         /** Once monitoring begins, the file will be monitored every
28          *  interval ms.
29          */
30         FileMonitor(std::string const & file_with_path, int interval);
31
32         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
33         ~FileMonitor();
34
35         ///
36         void reset(std::string const & file_with_path) const;
37
38         ///
39         std::string const & filename() const;
40
41         /// Begin monitoring the file
42         void start() const;
43         ///
44         void stop() const;
45         ///
46         bool monitoring() const;
47
48         /** The checksum is recomputed whenever the file is modified.
49          *  If the file is not being monitored, then the checksum will be
50          *  recomputed each time this function is called.
51          */
52         unsigned long checksum() const;
53
54         /// Connect and you'll be informed when the file has changed.
55         typedef boost::signal<void()> FileChangedSig;
56         typedef FileChangedSig::slot_type slot_type;
57         ///
58         boost::signals::connection connect(slot_type const &) const;
59
60 private:
61         /// Use the Pimpl idiom to hide the internals.
62         class Impl;
63
64         /// The pointer never changes although *pimpl_'s contents may.
65         boost::scoped_ptr<Impl> const pimpl_;
66 };
67
68 } // namespace support
69 } // namespace lyx
70
71 #endif // FILEMONITOR_H