2001-06-14 08:20:41 +00:00
|
|
|
// -*- C++ -*-
|
2001-02-07 16:44:49 +00:00
|
|
|
/**
|
2007-11-12 20:18:19 +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 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
|
|
|
|
|
2017-05-28 11:25:53 +00:00
|
|
|
#include "support/signals.h"
|
2001-02-07 16:44:49 +00:00
|
|
|
|
2003-02-22 18:01:16 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
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
|
2017-05-28 11:25:53 +00:00
|
|
|
signals2::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);
|
|
|
|
|
|
|
|
private:
|
2007-11-12 20:18:19 +00:00
|
|
|
/// noncopyable
|
|
|
|
Timeout(Timeout const &);
|
|
|
|
void operator=(Timeout const &);
|
|
|
|
///
|
|
|
|
class Impl;
|
2002-03-11 22:47:41 +00:00
|
|
|
///
|
2007-11-12 20:18:19 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-12-18 18:40:21 +00:00
|
|
|
// Small Timer class useful for debugging and performance investigation.
|
|
|
|
class Timer
|
|
|
|
{
|
|
|
|
public:
|
2015-02-20 14:39:45 +00:00
|
|
|
///
|
2010-12-18 18:40:21 +00:00
|
|
|
Timer();
|
|
|
|
///
|
2015-02-20 14:39:45 +00:00
|
|
|
~Timer();
|
|
|
|
///
|
2010-12-18 18:40:21 +00:00
|
|
|
void restart();
|
|
|
|
///
|
|
|
|
int elapsed() const;
|
|
|
|
///
|
|
|
|
std::string dateStr(char separator = 0) const;
|
|
|
|
///
|
|
|
|
std::string timeStr(char separator = 0) const;
|
|
|
|
///
|
|
|
|
std::string toStr() const;
|
|
|
|
///
|
|
|
|
static std::string currentToStr();
|
|
|
|
private:
|
|
|
|
struct Private;
|
|
|
|
Private * d;
|
|
|
|
};
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2001-02-07 16:44:49 +00:00
|
|
|
#endif
|