]> git.lyx.org Git - lyx.git/blob - src/frontends/Timeout.h
fix crash due to invalidated iterator
[lyx.git] / src / frontends / Timeout.h
1 // -*- C++ -*-
2 /**
3  * \file Timeout.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef TIMEOUT_H
14 #define TIMEOUT_H
15
16 #include <boost/signal.hpp>
17
18
19 /**
20  * This class executes the callback when the timeout expires.
21  */
22 class Timeout {
23 public:
24         /// the timeout type
25         enum Type {
26                 ONETIME, //< one-shot timer
27                 CONTINUOUS //< repeating
28         };
29         /// Note that the c-tor is implemented in the GUI-specific frontends
30         Timeout(unsigned int msec, Type = ONETIME);
31         ///
32         ~Timeout();
33         /// Is the timer running?
34         bool running() const;
35         /// start the timer
36         void start();
37         /// stop the timer
38         void stop();
39         /// restart the timer
40         void restart();
41         /// signal emitted on timer expiry
42         boost::signal<void()> timeout;
43         /// emit the signal
44         void emit();
45         /// set the timer type
46         Timeout & setType(Type t);
47         /// set the timeout value
48         Timeout & setTimeout(unsigned int msec);
49
50         /** Base class for the GUI implementation.
51             It must be public so that C callback functions can access its
52             daughter classes.
53          */
54         class Impl
55         {
56         public:
57                 ///
58                 Impl(Timeout & owner) : owner_(owner) {}
59                 ///
60                 virtual ~Impl() {}
61                 /// Is the timer running?
62                 virtual bool running() const = 0;
63                 /// start the timer
64                 virtual void start() = 0;
65                 /// stop the timer
66                 virtual void stop() = 0;
67                 /// reset
68                 virtual void reset() = 0;
69
70         protected:
71                 ///
72                 void emit() { owner_.emit(); }
73                 ///
74                 unsigned int timeout_ms() const { return owner_.timeout_ms; }
75
76         private:
77                 ///
78                 Timeout & owner_;
79         };
80
81 private:
82         ///
83         friend class Impl;
84         ///
85         boost::scoped_ptr<Impl> const pimpl_;
86         /// one-shot or repeating
87         Type type;
88         /// timeout value in milliseconds
89         unsigned int timeout_ms;
90 };
91
92 #endif