FLTK 1.4.4

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-2024 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
38
56 class Fl_Timeout {
57
58 protected:
59
60 Fl_Timeout *next; // ** Link to next timeout
61 Fl_Timeout_Handler callback; // the user's callback
62 void *data; // the user's callback data
63 double time; // delay until timeout
64 int skip; // skip "new" (inserted) timers (issue #450)
65
66 // constructor
67 Fl_Timeout() {
68 next = 0;
69 callback = 0;
70 data = 0;
71 time = 0;
72 skip = 0;
73 }
74
75 // destructor
76 ~Fl_Timeout() {}
77
78 // get a new timer entry from the pool or allocate a new one
79 static Fl_Timeout *get(double time, Fl_Timeout_Handler cb, void *data);
80
81 // insert this timer into the active timer queue, sorted by expiration time
82 void insert();
83
84 // remove this timer from the active timer queue and
85 // add it to the "current" timer stack
86 void make_current();
87
88 // remove this timer from the current timer stack and
89 // add it to the list of free timers
90 void release();
91
93 double delay() {
94 return time;
95 }
96
98 void delay(double t) {
99 time = t;
100 }
101
102 public:
103 // Returns whether the given timeout is active.
104 static int has_timeout(Fl_Timeout_Handler cb, void *data);
105
106 // Add or remove timeouts
107
108 static void add_timeout(double time, Fl_Timeout_Handler cb, void *data);
109 static void repeat_timeout(double time, Fl_Timeout_Handler cb, void *data);
110 static void remove_timeout(Fl_Timeout_Handler cb, void *data);
111 static int remove_next_timeout(Fl_Timeout_Handler cb, void *data = NULL, void **data_return = NULL);
112
113 // Elapse timeouts, i.e. calculate new delay time of all timers.
114 // This does not call the timer callbacks.
115 static void elapse_timeouts();
116
117 // Elapse timeouts and call timer callbacks.
118 static void do_timeouts();
119
120 // Return the delay in seconds until the next timer expires.
121 static double time_to_wait(double ttw);
122
123#if FL_TIMEOUT_DEBUG
124 // Write some statistics to stdout
125 static void debug(int level = 1);
126#endif
127
128 protected:
129
130 static Fl_Timeout *current();
131
141 static Fl_Timeout *first_timeout;
142
147 static Fl_Timeout *free_timeout;
148
165 static Fl_Timeout *current_timeout; // list of "current" timeouts
166
167}; // class Fl_Timeout
168
169#endif // _src_Fl_Timeout_h_
Fl.H
Fl static class.
Fl_Timeout
The internal class Fl_Timeout handles all timeout related functions.
Definition Fl_Timeout.h:56
Fl_Timeout::repeat_timeout
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:264
Fl_Timeout::free_timeout
static Fl_Timeout * free_timeout
List of free timeouts after use.
Definition Fl_Timeout.h:147
Fl_Timeout::has_timeout
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:219
Fl_Timeout::remove_timeout
static void remove_timeout(Fl_Timeout_Handler cb, void *data)
Remove a timeout callback.
Definition Fl_Timeout.cxx:291
Fl_Timeout::do_timeouts
static void do_timeouts()
Elapse timers and call their callbacks if any timers are expired.
Definition Fl_Timeout.cxx:515
Fl_Timeout::current
static Fl_Timeout * current()
Returns the first (top-most) timeout from the current timeout stack.
Definition Fl_Timeout.cxx:416
Fl_Timeout::make_current
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:356
Fl_Timeout::insert
void insert()
Insert this timer entry into the active timer queue.
Definition Fl_Timeout.cxx:194
Fl_Timeout::first_timeout
static Fl_Timeout * first_timeout
List of active timeouts.
Definition Fl_Timeout.h:141
Fl_Timeout::elapse_timeouts
static void elapse_timeouts()
Elapse all timers w/o calling their callbacks.
Definition Fl_Timeout.cxx:492
Fl_Timeout::delay
double delay()
Get the timer's delay in seconds.
Definition Fl_Timeout.h:93
Fl_Timeout::remove_next_timeout
static int remove_next_timeout(Fl_Timeout_Handler cb, void *data=NULL, void **data_return=NULL)
Remove the next matching timeout callback and return its data pointer.
Definition Fl_Timeout.cxx:324
Fl_Timeout::time_to_wait
static double time_to_wait(double ttw)
Returns the delay in seconds until the next timer expires, limited by ttw.
Definition Fl_Timeout.cxx:571
Fl_Timeout::release
void release()
Remove the top-most timeout from the stack of currently running timeout callbacks and insert it into ...
Definition Fl_Timeout.cxx:385
Fl_Timeout::current_timeout
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:165
Fl_Timeout::delay
void delay(double t)
Set the timer's delay in seconds.
Definition Fl_Timeout.h:98
Fl_Timeout::add_timeout
static void add_timeout(double time, Fl_Timeout_Handler cb, void *data)
Adds a one-shot timeout callback.
Definition Fl_Timeout.cxx:243
Fl_Timeout::get
static Fl_Timeout * get(double time, Fl_Timeout_Handler cb, void *data)
Get an Fl_Timeout instance for further handling.
Definition Fl_Timeout.cxx:460
Fl_Timeout_Handler
void(* Fl_Timeout_Handler)(void *data)
Signature of timeout callback functions passed as parameters.
Definition Fl.H:97