]> git.lyx.org Git - lyx.git/blob - src/support/FileMonitor.h
File monitoring is Go!
[lyx.git] / src / support / FileMonitor.h
1 // -*- C++ -*-
2 /*
3  * \file FileMonitor.h
4  * Copyright 2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author Angus Leeming <leeming@lyx.org>
8  *
9  * FileMonitor monitors a file and informs a listener when that file has
10  * changed.
11  */
12
13 #ifndef FILEMONITOR_H
14 #define FILEMONITOR_H
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "LString.h"
21
22 #include <boost/utility.hpp>
23 #include <boost/scoped_ptr.hpp>
24 #include <boost/signals/signal0.hpp>
25
26 class FileMonitor : boost::noncopyable {
27 public:
28         /** Once monitoring begins, the file will be monitored every
29          *  interval ms.
30          */
31         FileMonitor(string const & file_with_path, int interval);
32
33         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
34         ~FileMonitor();
35
36         ///
37         void reset(string const & file_with_path) const;
38
39         ///
40         string const & filename() const;
41
42         /// Begin monitoring the file
43         void start() const;
44         ///
45         void stop() const;
46         ///
47         bool monitoring() const;
48
49         /** The checksum is recomputed whenever the file is modified.
50          *  If the file is not being monitored, then the checksum will be
51          *  recomputed each time this function is called.
52          */
53         unsigned long checksum() const;
54
55         /// Connect and you'll be informed when the file has changed.
56         typedef boost::signal0<void>::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 #endif // FILEMONITOR_H