]> git.lyx.org Git - lyx.git/blob - src/support/FileMonitor.h
de9e9068e1febee240a000f6c376f21f09055ea4
[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 "LString.h"
19
20 #include <boost/utility.hpp>
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/signal0.hpp>
23
24 class FileMonitor : boost::noncopyable {
25 public:
26         /** Once monitoring begins, the file will be monitored every
27          *  interval ms.
28          */
29         FileMonitor(string const & file_with_path, int interval);
30
31         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
32         ~FileMonitor();
33
34         ///
35         void reset(string const & file_with_path) const;
36
37         ///
38         string const & filename() const;
39
40         /// Begin monitoring the file
41         void start() const;
42         ///
43         void stop() const;
44         ///
45         bool monitoring() const;
46
47         /** The checksum is recomputed whenever the file is modified.
48          *  If the file is not being monitored, then the checksum will be
49          *  recomputed each time this function is called.
50          */
51         unsigned long checksum() const;
52
53         /// Connect and you'll be informed when the file has changed.
54         typedef boost::signal0<void>::slot_type slot_type;
55         ///
56         boost::signals::connection connect(slot_type const &) const;
57
58 private:
59         /// Use the Pimpl idiom to hide the internals.
60         class Impl;
61
62         /// The pointer never changes although *pimpl_'s contents may.
63         boost::scoped_ptr<Impl> const pimpl_;
64 };
65
66 #endif // FILEMONITOR_H