FLTK 1.4.0
Loading...
Searching...
No Matches
Fl_Timeout.h
Go to the documentation of this file.
1//
2// Header for timeout support functions for the Fast Light Tool Kit (FLTK).
3//
4// Author: Albrecht Schlosser
5// Copyright 2021-2022 by Bill Spitzak and others.
6//
7// This library is free software. Distribution and use rights are outlined in
8// the file "COPYING" which should have been included with this file. If this
9// file is missing or damaged, see the license at:
10//
11// https://www.fltk.org/COPYING.php
12//
13// Please see the following page on how to report bugs and issues:
14//
15// https://www.fltk.org/bugs.php
16//
17
18#ifndef _src_Fl_Timeout_h_
19#define _src_Fl_Timeout_h_
20
21#include <FL/Fl.H>
22
23#define FL_TIMEOUT_DEBUG 0 // 1 = include debugging features, 0 = no
24
55
56protected:
57
58 Fl_Timeout *next; // ** Link to next timeout
59 Fl_Timeout_Handler callback; // the user's callback
60 void *data; // the user's callback data
61 double time; // delay until timeout
62 int skip; // skip "new" (inserted) timers (issue #450)
63
64 // constructor
65 Fl_Timeout() {
66 next = 0;
67 callback = 0;
68 data = 0;
69 time = 0;
70 skip = 0;
71 }
72
73 // destructor
74 ~Fl_Timeout() {}
75
76 // get a new timer entry from the pool or allocate a new one
77 static Fl_Timeout *get(double time, Fl_Timeout_Handler cb, void *data);
78
79 // insert this timer into the active timer queue, sorted by expiration time
80 void insert();
81
82 // remove this timer from the active timer queue and
83 // add it to the "current" timer stack
84 void make_current();
85
86 // remove this timer from the current timer stack and
87 // add it to the list of free timers
88 void release();
89
91 double delay() {
92 return time;
93 }
94
96 void delay(double t) {
97 time = t;
98 }
99
100public:
101 // Returns whether the given timeout is active.
102 static int has_timeout(Fl_Timeout_Handler cb, void *data);
103
104 // Add or remove timeouts
105
106 static void add_timeout(double time, Fl_Timeout_Handler cb, void *data);
107 static void repeat_timeout(double time, Fl_Timeout_Handler cb, void *data);
108 static void remove_timeout(Fl_Timeout_Handler cb, void *data);
109
110 // Elapse timeouts, i.e. calculate new delay time of all timers.
111 // This does not call the timer callbacks.
112 static void elapse_timeouts();
113
114 // Elapse timeouts and call timer callbacks.
115 static void do_timeouts();
116
117 // Return the delay in seconds until the next timer expires.
118 static double time_to_wait(double ttw);
119
120#if FL_TIMEOUT_DEBUG
121 // Write some statistics to stdout
122 static void debug(int level = 1);
123#endif
124
125protected:
126
127 static Fl_Timeout *current();
128
139
145
162 static Fl_Timeout *current_timeout; // list of "current" timeouts
163
164}; // class Fl_Timeout
165
166#endif // _src_Fl_Timeout_h_
Fl static class.
The internal class Fl_Timeout handles all timeout related functions.
Definition Fl_Timeout.h:54
static void repeat_timeout(double time, Fl_Timeout_Handler cb, void *data)
Repeats a timeout callback from the expiration of the previous timeout, allowing for more accurate ti...
Definition Fl_Timeout.cxx:252
static Fl_Timeout * free_timeout
List of free timeouts after use.
Definition Fl_Timeout.h:144
static int has_timeout(Fl_Timeout_Handler cb, void *data)
Returns true if the timeout exists and has not been called yet.
Definition Fl_Timeout.cxx:211
static void remove_timeout(Fl_Timeout_Handler cb, void *data)
Remove a timeout callback.
Definition Fl_Timeout.cxx:277
static void do_timeouts()
Elapse timers and call their callbacks if any timers are expired.
Definition Fl_Timeout.cxx:458
static Fl_Timeout * current()
Returns the first (top-most) timeout from the current timeout stack.
Definition Fl_Timeout.cxx:359
void make_current()
Remove the timeout from the active timer queue and push it onto the stack of currently running callba...
Definition Fl_Timeout.cxx:299
void insert()
Insert this timer entry into the active timer queue.
Definition Fl_Timeout.cxx:188
static Fl_Timeout * first_timeout
List of active timeouts.
Definition Fl_Timeout.h:138
static void elapse_timeouts()
Elapse all timers w/o calling their callbacks.
Definition Fl_Timeout.cxx:435
double delay()
Get the timer's delay in seconds.
Definition Fl_Timeout.h:91
static double time_to_wait(double ttw)
Returns the delay in seconds until the next timer expires, limited by ttw.
Definition Fl_Timeout.cxx:514
void release()
Remove the top-most timeout from the stack of currently running timeout callbacks and insert it into ...
Definition Fl_Timeout.cxx:328
static Fl_Timeout * current_timeout
The list of current timeouts is used to store the timeout whose callback is called while the callback...
Definition Fl_Timeout.h:162
void delay(double t)
Set the timer's delay in seconds.
Definition Fl_Timeout.h:96
static void add_timeout(double time, Fl_Timeout_Handler cb, void *data)
Adds a one-shot timeout callback.
Definition Fl_Timeout.cxx:233
static Fl_Timeout * get(double time, Fl_Timeout_Handler cb, void *data)
Get an Fl_Timeout instance for further handling.
Definition Fl_Timeout.cxx:403
void(* Fl_Timeout_Handler)(void *data)
Signature of timeout callback functions passed as parameters.
Definition Fl.H:94