NetSurf
frontends
beos
schedule.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2008 François Revol <mmu_man@users.sourceforge.net>
3
*
4
* This file is part of NetSurf, http://www.netsurf-browser.org/
5
*
6
* NetSurf is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
9
*
10
* NetSurf is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#define __STDBOOL_H__ 1
20
#include <stdlib.h>
21
#include <stdbool.h>
22
#include <OS.h>
23
#include <List.h>
24
25
extern
"C"
{
26
#include "
utils/errors.h
"
27
#include "
beos/schedule.h
"
28
#include "
netsurf/inttypes.h
"
29
#include "
netsurf/content_type.h
"
30
#include "
netsurf/browser_window.h
"
31
32
#include "
utils/log.h
"
33
}
34
35
/** Killable callback closure embodiment. */
36
typedef
struct
{
37
void (*callback)(
void
*);
/**< The callback function. */
38
void
*
context
;
/**< The context for the callback. */
39
bool
callback_killed
;
/**< Whether or not this was killed. */
40
bool
callback_fired
;
/**< Whether or not this has fired yet. */
41
bigtime_t
timeout
;
42
}
_nsbeos_callback_t
;
43
44
/** List of all callbacks. */
45
static
BList *
callbacks
= NULL;
46
47
/** earliest deadline. It's used for select() in gui_poll() */
48
bigtime_t
earliest_callback_timeout
= B_INFINITE_TIMEOUT;
49
50
51
static
bool
52
nsbeos_schedule_kill_callback
(
void
*_target,
void
*_match)
53
{
54
_nsbeos_callback_t
*target = (
_nsbeos_callback_t
*)_target;
55
_nsbeos_callback_t
*match = (
_nsbeos_callback_t
*)_match;
56
if
((target->
callback
== match->
callback
) &&
57
(target->
context
== match->
context
)) {
58
NSLOG
(schedule, DEBUG,
59
"Found match for %p(%p), killing."
,
60
target->
callback
,
61
target->
context
);
62
target->
callback
= NULL;
63
target->
context
= NULL;
64
target->
callback_killed
=
true
;
65
}
66
return
false
;
67
}
68
69
static
void
70
schedule_remove
(
void
(*callback)(
void
*p),
void
*p)
71
{
72
NSLOG
(schedule, DEBUG,
73
"schedule_remove() for %p(%p)"
,
74
callback, p);
75
if
(
callbacks
== NULL)
76
return
;
77
_nsbeos_callback_t
cb_match;
78
cb_match.
callback
= callback;
79
cb_match.
context
= p;
80
81
callbacks
->DoForEach(
nsbeos_schedule_kill_callback
, &cb_match);
82
}
83
84
nserror
beos_schedule
(
int
t,
void
(*callback)(
void
*p),
void
*p)
85
{
86
NSLOG
(schedule, DEBUG,
"t:%d cb:%p p:%p"
, t, callback, p);
87
88
if
(
callbacks
== NULL) {
89
callbacks
=
new
BList;
90
}
91
92
/* Kill any pending schedule of this kind. */
93
schedule_remove
(callback, p);
94
95
if
(t < 0) {
96
return
NSERROR_OK
;
97
}
98
99
bigtime_t timeout = system_time() + t * 1000LL;
100
_nsbeos_callback_t
*cb = (
_nsbeos_callback_t
*)malloc(
sizeof
(
_nsbeos_callback_t
));
101
cb->
callback
= callback;
102
cb->
context
= p;
103
cb->
callback_killed
= cb->
callback_fired
=
false
;
104
cb->
timeout
= timeout;
105
if
(
earliest_callback_timeout
> timeout) {
106
earliest_callback_timeout
= timeout;
107
}
108
callbacks
->AddItem(cb);
109
110
return
NSERROR_OK
;
111
}
112
113
bool
114
schedule_run
(
void
)
115
{
116
NSLOG
(schedule, DEBUG,
"schedule_run()"
);
117
118
earliest_callback_timeout
= B_INFINITE_TIMEOUT;
119
if
(
callbacks
== NULL)
120
return
false
;
/* Nothing to do */
121
122
bigtime_t now = system_time();
123
int32
i;
124
125
NSLOG
(schedule, DEBUG,
126
"Checking %"
PRId32
" callbacks to for deadline."
,
127
callbacks
->CountItems());
128
129
/* Run all the callbacks which made it this far. */
130
for
(i = 0; i <
callbacks
->CountItems(); ) {
131
_nsbeos_callback_t
*cb = (
_nsbeos_callback_t
*)(
callbacks
->ItemAt(i));
132
if
(cb->
timeout
> now) {
133
// update next deadline
134
if
(
earliest_callback_timeout
> cb->
timeout
)
135
earliest_callback_timeout
= cb->
timeout
;
136
i++;
137
continue
;
138
}
139
NSLOG
(schedule, DEBUG,
140
"Running callbacks %p(%p)."
,
141
cb->
callback
,
142
cb->
context
);
143
144
if
(!cb->
callback_killed
)
145
cb->
callback
(cb->
context
);
146
callbacks
->RemoveItem(cb);
147
free(cb);
148
}
149
return
true
;
150
}
schedule.h
browser_window.h
Browser window creation and manipulation interface.
content_type.h
Declaration of content enumerations.
errors.h
Error codes.
nserror
nserror
Enumeration of error codes.
Definition:
errors.h:29
NSERROR_OK
@ NSERROR_OK
No error.
Definition:
errors.h:30
inttypes.h
Netsurf additional integer type formatting macros.
log.h
NSLOG
#define NSLOG(catname, level, logmsg, args...)
Definition:
log.h:116
int32
int32_t int32
Definition:
os3support.h:183
callbacks
static BList * callbacks
List of all callbacks.
Definition:
schedule.cpp:45
beos_schedule
nserror beos_schedule(int t, void(*callback)(void *p), void *p)
Definition:
schedule.cpp:84
schedule_run
bool schedule_run(void)
Process events up to current time.
Definition:
schedule.cpp:114
schedule_remove
static void schedule_remove(void(*callback)(void *p), void *p)
Definition:
schedule.cpp:70
nsbeos_schedule_kill_callback
static bool nsbeos_schedule_kill_callback(void *_target, void *_match)
Definition:
schedule.cpp:52
earliest_callback_timeout
bigtime_t earliest_callback_timeout
earliest deadline.
Definition:
schedule.cpp:48
_nsbeos_callback_t
Killable callback closure embodiment.
Definition:
schedule.cpp:36
_nsbeos_callback_t::callback_killed
bool callback_killed
Whether or not this was killed.
Definition:
schedule.cpp:39
_nsbeos_callback_t::callback_fired
bool callback_fired
Whether or not this has fired yet.
Definition:
schedule.cpp:40
_nsbeos_callback_t::timeout
bigtime_t timeout
Definition:
schedule.cpp:41
_nsbeos_callback_t::context
void * context
The context for the callback.
Definition:
schedule.cpp:38
_nsbeos_callback_t::callback
void(* callback)(void *)
The callback function.
Definition:
schedule.cpp:37
Generated on Sun Nov 30 2025 11:26:09 for NetSurf by
1.9.4