2002-07-18 14:01:42 +00:00
|
|
|
// -*- C++ -*-
|
2002-09-25 10:03:41 +00:00
|
|
|
/**
|
2002-07-18 14:01:42 +00:00
|
|
|
* \file FileMonitor.h
|
2002-09-25 10:03:41 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-07-18 14:01:42 +00:00
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-07-18 14:01:42 +00:00
|
|
|
*
|
|
|
|
* FileMonitor monitors a file and informs a listener when that file has
|
|
|
|
* changed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FILEMONITOR_H
|
|
|
|
#define FILEMONITOR_H
|
|
|
|
|
2007-09-30 15:47:00 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
2002-07-18 14:01:42 +00:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2004-09-26 14:19:47 +00:00
|
|
|
#include <boost/signal.hpp>
|
2002-07-18 14:01:42 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
class FileName;
|
|
|
|
|
2002-07-18 14:01:42 +00:00
|
|
|
class FileMonitor : boost::noncopyable {
|
|
|
|
public:
|
|
|
|
/** Once monitoring begins, the file will be monitored every
|
|
|
|
* interval ms.
|
|
|
|
*/
|
2006-11-26 21:30:39 +00:00
|
|
|
FileMonitor(FileName const & file_with_path, int interval);
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
|
|
/// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
|
|
|
|
~FileMonitor();
|
|
|
|
|
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
void reset(FileName const & file_with_path) const;
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const & filename() const;
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
|
|
/// Begin monitoring the file
|
|
|
|
void start() const;
|
|
|
|
///
|
|
|
|
void stop() const;
|
|
|
|
///
|
|
|
|
bool monitoring() const;
|
|
|
|
|
|
|
|
/** The checksum is recomputed whenever the file is modified.
|
|
|
|
* If the file is not being monitored, then the checksum will be
|
|
|
|
* recomputed each time this function is called.
|
|
|
|
*/
|
|
|
|
unsigned long checksum() const;
|
|
|
|
|
|
|
|
/// Connect and you'll be informed when the file has changed.
|
2004-09-26 14:19:47 +00:00
|
|
|
typedef boost::signal<void()> FileChangedSig;
|
|
|
|
typedef FileChangedSig::slot_type slot_type;
|
2002-07-18 14:01:42 +00:00
|
|
|
///
|
|
|
|
boost::signals::connection connect(slot_type const &) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Use the Pimpl idiom to hide the internals.
|
|
|
|
class Impl;
|
|
|
|
|
|
|
|
/// The pointer never changes although *pimpl_'s contents may.
|
|
|
|
boost::scoped_ptr<Impl> const pimpl_;
|
|
|
|
};
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|
|
|
|
|
2002-07-18 14:01:42 +00:00
|
|
|
#endif // FILEMONITOR_H
|