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