From 87f6314dabdc2067a19e01f8b29f9ecc38ed825b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 8 Mar 2014 14:13:27 +0000 Subject: move scheduleing into browser operation table --- riscos/download.c | 49 +++++++++++++------------- riscos/gui.c | 8 +++-- riscos/gui.h | 17 ++++++++- riscos/gui/progress_bar.c | 23 ++++++++----- riscos/gui/status_bar.c | 5 ++- riscos/hotlist.c | 18 +++++----- riscos/schedule.c | 88 +++++++++++++++++++++++------------------------ 7 files changed, 116 insertions(+), 92 deletions(-) (limited to 'riscos') diff --git a/riscos/download.c b/riscos/download.c index b10c6c1d4..804a66459 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -33,7 +33,6 @@ #include #include #include - #include "oslib/mimemap.h" #include "oslib/osargs.h" #include "oslib/osfile.h" @@ -42,22 +41,24 @@ #include "oslib/osgbpb.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" + #include "desktop/gui.h" #include "desktop/netsurf.h" #include "desktop/download.h" -#include "riscos/dialog.h" #include "utils/nsoption.h" -#include "riscos/mouse.h" -#include "riscos/save.h" -#include "riscos/query.h" -#include "riscos/wimp.h" -#include "riscos/wimp_event.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/schedule.h" #include "utils/url.h" #include "utils/utf8.h" #include "utils/utils.h" + +#include "riscos/gui.h" +#include "riscos/dialog.h" +#include "riscos/mouse.h" +#include "riscos/save.h" +#include "riscos/query.h" +#include "riscos/wimp.h" +#include "riscos/wimp_event.h" #include "riscos/ucstables.h" #define ICON_DOWNLOAD_ICON 0 @@ -455,7 +456,7 @@ static void gui_download_window_error(struct gui_download_window *dw, dw->ctx = NULL; dw->error = true; - schedule_remove(ro_gui_download_update_status_wrapper, dw); + riscos_schedule(-1, ro_gui_download_update_status_wrapper, dw); /* place error message in status icon in red */ strncpy(dw->status, error_msg, sizeof dw->status); @@ -715,15 +716,16 @@ void ro_gui_download_update_status(struct gui_download_window *dw) warn_user("WimpError", error->errmess); } - if (dw->ctx) - schedule(100, ro_gui_download_update_status_wrapper, dw); - else - schedule_remove(ro_gui_download_update_status_wrapper, dw); + if (dw->ctx) { + riscos_schedule(1000, ro_gui_download_update_status_wrapper, dw); + } else { + riscos_schedule(-1, ro_gui_download_update_status_wrapper, dw); + } } /** - * Wrapper for ro_gui_download_update_status(), suitable for schedule(). + * Wrapper for ro_gui_download_update_status(), suitable for riscos_schedule(). */ void ro_gui_download_update_status_wrapper(void *p) @@ -795,10 +797,11 @@ static void gui_download_window_done(struct gui_download_window *dw) warn_user("SaveError", error->errmess); } - if (dw->send_dataload) + if (dw->send_dataload) { ro_gui_download_send_dataload(dw); + } - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } } @@ -889,7 +892,7 @@ bool ro_gui_download_keypress(wimp_key *key) !nsoption_bool(confirm_overwrite)) && !dw->ctx) { /* finished already */ - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } return true; } @@ -985,7 +988,7 @@ void ro_gui_download_datasave_ack(wimp_message *message) ro_gui_download_send_dataload(dw); - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } } @@ -1417,7 +1420,7 @@ void ro_gui_download_send_dataload(struct gui_download_window *dw) warn_user("WimpError", error->errmess); } - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } @@ -1480,8 +1483,8 @@ bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit) return false; } - schedule_remove(ro_gui_download_update_status_wrapper, dw); - schedule_remove(ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(-1, ro_gui_download_update_status_wrapper, dw); + riscos_schedule(-1, ro_gui_download_window_destroy_wrapper, dw); /* remove from list */ if (dw->prev) @@ -1534,7 +1537,7 @@ bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit) /** - * Wrapper for ro_gui_download_window_destroy(), suitable for schedule(). + * Wrapper for ro_gui_download_window_destroy(), suitable for riscos_schedule(). */ void ro_gui_download_window_destroy_wrapper(void *p) @@ -1613,7 +1616,7 @@ void ro_gui_download_overwrite_confirmed(query_id id, enum query_response res, v ro_gui_download_send_dataload(dw); - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } } diff --git a/riscos/gui.c b/riscos/gui.c index 1663c1703..59a0138e7 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -1077,7 +1077,7 @@ void ro_gui_cleanup(void) * \param active return as soon as possible */ -void gui_poll(bool active) +static void riscos_poll(bool active) { wimp_event_no event; wimp_block block; @@ -1116,8 +1116,9 @@ void gui_poll(bool active) * from gui_multitask(). Scheduled callbacks must only be run from the * top-level. */ - if (event == wimp_NULL_REASON_CODE) + if (event == wimp_NULL_REASON_CODE) { schedule_run(); + } ro_gui_window_update_boxes(); @@ -2358,7 +2359,8 @@ static struct gui_fetch_table riscos_fetch_table = { }; static struct gui_browser_table riscos_browser_table = { - .poll = gui_poll, + .poll = riscos_poll, + .schedule = riscos_schedule, .quit = gui_quit, .launch_url = gui_launch_url, diff --git a/riscos/gui.h b/riscos/gui.h index dbf6373c0..3ea0c0b72 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -123,7 +123,6 @@ void ro_gui_dump_browser_window(struct browser_window *bw); void ro_gui_drag_box_start(wimp_pointer *pointer); bool ro_gui_prequit(void); const char *ro_gui_default_language(void); -void gui_poll(bool active); /* exported for riscos/wimp_event.c:722 */ char *url_to_path(const char *url); /* in download.c */ @@ -183,8 +182,24 @@ bits ro_filetype_from_unix_path(const char *unix_path); /* in schedule.c */ extern bool sched_active; extern os_t sched_time; + +/** + * Process events up to current time. + */ bool schedule_run(void); +/** + * Schedule a callback. + * + * \param t interval before the callback should be made in ms + * \param callback callback function + * \param p user parameter, passed to callback function + * + * The callback function will be called as soon as possible after t ms have + * passed. + */ +nserror riscos_schedule(int t, void (*callback)(void *p), void *p); + /* in search.c */ void ro_gui_search_init(void); void ro_gui_search_prepare(struct browser_window *g); diff --git a/riscos/gui/progress_bar.c b/riscos/gui/progress_bar.c index 445797611..f5b47313b 100644 --- a/riscos/gui/progress_bar.c +++ b/riscos/gui/progress_bar.c @@ -29,10 +29,11 @@ #include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" + #include "desktop/plotters.h" #include "utils/log.h" -#include "utils/schedule.h" #include "utils/utils.h" + #include "riscos/gui.h" #include "riscos/tinct.h" #include "riscos/wimp_event.h" @@ -159,8 +160,9 @@ void ro_gui_progress_bar_destroy(struct progress_bar *pb) os_error *error; assert(pb); - if (pb->animating) - schedule_remove(ro_gui_progress_bar_animate, pb); + if (pb->animating) { + riscos_schedule(-1, ro_gui_progress_bar_animate, pb); + } ro_gui_wimp_event_finalise(pb->w); error = xwimp_delete_window(pb->w); if (error) { @@ -292,12 +294,14 @@ void ro_gui_progress_bar_update(struct progress_bar *pb, int width, int height) /* update the animation state */ if ((pb->value == 0) || (pb->value == pb->range)) { - if (pb->animating) - schedule_remove(ro_gui_progress_bar_animate, pb); + if (pb->animating) { + riscos_schedule(-1, ro_gui_progress_bar_animate, pb); + } pb->animating = false; } else { - if (!pb->animating) - schedule(20, ro_gui_progress_bar_animate, pb); + if (!pb->animating) { + riscos_schedule(200, ro_gui_progress_bar_animate, pb); + } pb->animating = true; } @@ -372,8 +376,9 @@ void ro_gui_progress_bar_animate(void *p) if (pb->offset < 0) pb->offset += progress_width * 2; - if (pb->animating) - schedule(20, ro_gui_progress_bar_animate, pb); + if (pb->animating) { + riscos_schedule(200, ro_gui_progress_bar_animate, pb); + } redraw.w = pb->w; redraw.box = pb->visible; diff --git a/riscos/gui/status_bar.c b/riscos/gui/status_bar.c index 899fe99b6..46a511f95 100644 --- a/riscos/gui/status_bar.c +++ b/riscos/gui/status_bar.c @@ -30,7 +30,6 @@ #include "oslib/wimpspriteop.h" #include "desktop/plotters.h" #include "utils/log.h" -#include "utils/schedule.h" #include "utils/utils.h" #include "riscos/gui.h" #include "riscos/wimp.h" @@ -171,7 +170,7 @@ void ro_gui_status_bar_destroy(struct status_bar *sb) ro_gui_progress_bar_destroy(sb->pb); /* Remove any scheduled redraw callbacks */ - schedule_remove(ro_gui_status_bar_redraw_callback, (void *) sb); + riscos_schedule(-1, ro_gui_status_bar_redraw_callback, (void *) sb); free(sb); } @@ -331,7 +330,7 @@ void ro_gui_status_bar_set_text(struct status_bar *sb, const char *text) * { callback, handle } pair is registered at once. */ if (sb->visible && text != NULL) { - schedule(1, ro_gui_status_bar_redraw_callback, (void *) sb); + riscos_schedule(10, ro_gui_status_bar_redraw_callback, sb); } } diff --git a/riscos/hotlist.c b/riscos/hotlist.c index 791035331..14e90fbfa 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -30,27 +30,29 @@ #include "oslib/osfile.h" #include "oslib/osmodule.h" #include "oslib/wimp.h" + #include "content/content.h" #include "content/hlcache.h" #include "content/urldb.h" #include "desktop/hotlist.h" #include "desktop/tree.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/url.h" +#include "utils/nsoption.h" + +#include "riscos/gui.h" #include "riscos/dialog.h" #include "riscos/hotlist.h" #include "riscos/menus.h" #include "riscos/message.h" -#include "utils/nsoption.h" #include "riscos/save.h" #include "riscos/toolbar.h" #include "riscos/treeview.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/query.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/schedule.h" -#include "utils/utils.h" -#include "utils/url.h" static void ro_gui_hotlist_toolbar_update_buttons(void); static void ro_gui_hotlist_toolbar_save_buttons(char *config); @@ -543,7 +545,7 @@ void ro_gui_hotlist_add_page(nsurl *url) * message didn't bounce. */ - schedule(0, ro_gui_hotlist_scheduled_callback, NULL); + riscos_schedule(0, ro_gui_hotlist_scheduled_callback, NULL); } @@ -569,7 +571,7 @@ static void ro_gui_hotlist_addurl_bounce(wimp_message *message) /* There's no longer any need to listen for the next Null poll. */ - schedule_remove(ro_gui_hotlist_scheduled_callback, NULL); + riscos_schedule(-1, ro_gui_hotlist_scheduled_callback, NULL); } diff --git a/riscos/schedule.c b/riscos/schedule.c index 257f2e72f..51290056d 100644 --- a/riscos/schedule.c +++ b/riscos/schedule.c @@ -24,10 +24,11 @@ #include #include + #include "oslib/os.h" -#include "riscos/gui.h" #include "utils/log.h" -#include "utils/schedule.h" + +#include "riscos/gui.h" /** Entry in the queue of scheduled callbacks. */ @@ -50,25 +51,53 @@ bool sched_active = false; /** Time of soonest scheduled event (valid only if sched_active is true). */ os_t sched_time; - /** - * Schedule a callback. + * Unschedule a callback. * - * \param t interval before the callback should be made / cs * \param callback callback function * \param p user parameter, passed to callback function * - * The callback function will be called as soon as possible after t cs have - * passed. + * All scheduled callbacks matching both callback and p are removed. */ -void schedule(int t, void (*callback)(void *p), void *p) +static nserror schedule_remove(void (*callback)(void *p), void *p) +{ + struct sched_entry *entry, *next; + + for (entry = &sched_queue; entry->next; entry = entry->next) { + if (entry->next->callback != callback || entry->next->p != p) + continue; + next = entry->next; + entry->next = entry->next->next; + free(next); + if (!entry->next) + break; + } + + if (sched_queue.next) { + sched_active = true; + sched_time = sched_queue.next->time; + } else { + sched_active = false; + } + + return NSERROR_OK; +} + +/* exported function documented in riscos/gui.h */ +nserror riscos_schedule(int t, void (*callback)(void *p), void *p) { struct sched_entry *entry; struct sched_entry *queue; os_t time; + nserror ret; - schedule_remove(callback, p); + ret = schedule_remove(callback, p); + if ((t < 0) || (ret != NSERROR_OK)) { + return ret; + } + + t = t / 10; /* convert to centiseconds */ time = os_read_monotonic_time() + t; @@ -91,44 +120,12 @@ void schedule(int t, void (*callback)(void *p), void *p) sched_active = true; sched_time = sched_queue.next->time; -} - -/** - * Unschedule a callback. - * - * \param callback callback function - * \param p user parameter, passed to callback function - * - * All scheduled callbacks matching both callback and p are removed. - */ - -void schedule_remove(void (*callback)(void *p), void *p) -{ - struct sched_entry *entry, *next; - - for (entry = &sched_queue; entry->next; entry = entry->next) { - if (entry->next->callback != callback || entry->next->p != p) - continue; - next = entry->next; - entry->next = entry->next->next; - free(next); - if (!entry->next) - break; - } - - if (sched_queue.next) { - sched_active = true; - sched_time = sched_queue.next->time; - } else - sched_active = false; + return NSERROR_OK; } -/** - * Process events up to current time. - */ - +/* exported function documented in riscos/gui.h */ bool schedule_run(void) { struct sched_entry *entry; @@ -144,8 +141,9 @@ bool schedule_run(void) p = entry->p; sched_queue.next = entry->next; free(entry); - /* The callback may call schedule() or schedule_remove(), so - * leave the queue in a safe state. */ + /* The callback may call riscos_schedule(), so leave + * the queue in a safe state. + */ callback(p); } -- cgit v1.2.3