2001-06-14 08:20:41 +00:00
|
|
|
|
// -*- C++ -*-
|
2001-02-07 16:44:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file Timeout.h
|
2002-09-05 15:14:23 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-02-07 16:44:49 +00:00
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author John Levon
|
2002-09-05 14:10:50 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-02-07 16:44:49 +00:00
|
|
|
|
*/
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2001-02-07 16:44:49 +00:00
|
|
|
|
#ifndef TIMEOUT_H
|
|
|
|
|
#define TIMEOUT_H
|
|
|
|
|
|
2004-09-26 14:19:47 +00:00
|
|
|
|
#include <boost/signal.hpp>
|
2001-02-07 16:44:49 +00:00
|
|
|
|
|
2003-02-22 18:01:16 +00:00
|
|
|
|
|
2001-02-07 16:44:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* This class executes the callback when the timeout expires.
|
|
|
|
|
*/
|
|
|
|
|
class Timeout {
|
|
|
|
|
public:
|
2002-06-12 02:54:19 +00:00
|
|
|
|
/// the timeout type
|
2001-02-07 16:44:49 +00:00
|
|
|
|
enum Type {
|
2002-06-12 02:54:19 +00:00
|
|
|
|
ONETIME, //< one-shot timer
|
|
|
|
|
CONTINUOUS //< repeating
|
2001-02-07 16:44:49 +00:00
|
|
|
|
};
|
2003-02-22 18:01:16 +00:00
|
|
|
|
/// Note that the c-tor is implemented in the GUI-specific frontends
|
2001-02-07 16:44:49 +00:00
|
|
|
|
Timeout(unsigned int msec, Type = ONETIME);
|
|
|
|
|
///
|
|
|
|
|
~Timeout();
|
2002-02-18 19:13:48 +00:00
|
|
|
|
/// Is the timer running?
|
|
|
|
|
bool running() const;
|
2001-02-07 16:44:49 +00:00
|
|
|
|
/// start the timer
|
|
|
|
|
void start();
|
|
|
|
|
/// stop the timer
|
|
|
|
|
void stop();
|
|
|
|
|
/// restart the timer
|
|
|
|
|
void restart();
|
|
|
|
|
/// signal emitted on timer expiry
|
2004-09-26 14:19:47 +00:00
|
|
|
|
boost::signal<void()> timeout;
|
2001-02-07 16:44:49 +00:00
|
|
|
|
/// emit the signal
|
|
|
|
|
void emit();
|
|
|
|
|
/// set the timer type
|
|
|
|
|
Timeout & setType(Type t);
|
|
|
|
|
/// set the timeout value
|
|
|
|
|
Timeout & setTimeout(unsigned int msec);
|
|
|
|
|
|
2003-02-22 18:01:16 +00:00
|
|
|
|
/** Base class for the GUI implementation.
|
|
|
|
|
It must be public so that C callback functions can access its
|
|
|
|
|
daughter classes.
|
|
|
|
|
*/
|
|
|
|
|
class Impl
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
Impl(Timeout & owner) : owner_(owner) {}
|
|
|
|
|
///
|
|
|
|
|
virtual ~Impl() {}
|
|
|
|
|
/// Is the timer running?
|
|
|
|
|
virtual bool running() const = 0;
|
|
|
|
|
/// start the timer
|
|
|
|
|
virtual void start() = 0;
|
|
|
|
|
/// stop the timer
|
|
|
|
|
virtual void stop() = 0;
|
|
|
|
|
/// reset
|
|
|
|
|
virtual void reset() = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
///
|
|
|
|
|
void emit() { owner_.emit(); }
|
|
|
|
|
///
|
|
|
|
|
unsigned int timeout_ms() const { return owner_.timeout_ms; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
///
|
|
|
|
|
Timeout & owner_;
|
|
|
|
|
};
|
2003-02-25 13:17:01 +00:00
|
|
|
|
|
2001-02-07 16:44:49 +00:00
|
|
|
|
private:
|
2002-03-11 22:47:41 +00:00
|
|
|
|
///
|
2003-02-22 18:01:16 +00:00
|
|
|
|
friend class Impl;
|
2002-03-11 22:47:41 +00:00
|
|
|
|
///
|
2003-02-22 18:01:16 +00:00
|
|
|
|
boost::scoped_ptr<Impl> const pimpl_;
|
2001-02-07 16:44:49 +00:00
|
|
|
|
/// one-shot or repeating
|
|
|
|
|
Type type;
|
|
|
|
|
/// timeout value in milliseconds
|
|
|
|
|
unsigned int timeout_ms;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|