summaryrefslogtreecommitdiff
path: root/framebuffer
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-03-08 14:13:27 +0000
committerVincent Sanders <vince@kyllikki.org>2014-03-09 15:37:40 +0000
commit87f6314dabdc2067a19e01f8b29f9ecc38ed825b (patch)
tree78f8f8395e3bf3b7ee2c18a7b5a5e6d2d5ca9ddc /framebuffer
parentfb9b171e325488dc9792ee0f3062f15d8ec597ee (diff)
downloadnetsurf-87f6314dabdc2067a19e01f8b29f9ecc38ed825b.tar.gz
netsurf-87f6314dabdc2067a19e01f8b29f9ecc38ed825b.tar.bz2
move scheduleing into browser operation table
Diffstat (limited to 'framebuffer')
-rw-r--r--framebuffer/gui.c10
-rw-r--r--framebuffer/schedule.c103
-rw-r--r--framebuffer/schedule.h20
3 files changed, 78 insertions, 55 deletions
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index cee58b9d7..7d3e95c38 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -40,7 +40,6 @@
#include "utils/filepath.h"
#include "utils/log.h"
#include "utils/messages.h"
-#include "utils/schedule.h"
#include "utils/types.h"
#include "desktop/textinput.h"
#include "render/form.h"
@@ -557,7 +556,7 @@ static bool nslog_stream_configure(FILE *fptr)
-static void gui_poll(bool active)
+static void framebuffer_poll(bool active)
{
nsfb_event_t event;
int timeout; /* timeout in miliseconds */
@@ -1696,7 +1695,7 @@ throbber_advance(void *pw)
if (g->throbber_index >= 0) {
fbtk_set_bitmap(g->throbber, image);
- schedule(10, throbber_advance, g);
+ framebuffer_schedule(100, throbber_advance, g);
}
}
@@ -1704,7 +1703,7 @@ static void
gui_window_start_throbber(struct gui_window *g)
{
g->throbber_index = 0;
- schedule(10, throbber_advance, g);
+ framebuffer_schedule(100, throbber_advance, g);
}
static void
@@ -1785,7 +1784,8 @@ static struct gui_window_table framebuffer_window_table = {
static struct gui_browser_table framebuffer_browser_table = {
- .poll = gui_poll,
+ .poll = framebuffer_poll,
+ .schedule = framebuffer_schedule,
.quit = gui_quit,
};
diff --git a/framebuffer/schedule.c b/framebuffer/schedule.c
index 43f531838..151b6f99f 100644
--- a/framebuffer/schedule.c
+++ b/framebuffer/schedule.c
@@ -20,10 +20,15 @@
#include <time.h>
#include <stdlib.h>
-#include "utils/schedule.h"
+#include "utils/log.h"
+
#include "framebuffer/schedule.h"
-#include "utils/log.h"
+#ifdef DEBUG_SCHEDULER
+#define SRLOG(x) LOG(x)
+#else
+#define SRLOG(x)
+#endif
/* linked list of scheduled callbacks */
static struct nscallback *schedule_list = NULL;
@@ -39,39 +44,6 @@ struct nscallback
void *p;
};
-
-/**
- * Schedule a callback.
- *
- * \param tival 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.
- */
-
-void schedule(int cs_ival, void (*callback)(void *p), void *p)
-{
- struct nscallback *nscb;
- struct timeval tv;
-
- tv.tv_sec = cs_ival / 100; /* cs to seconds */
- tv.tv_usec = (cs_ival % 100) * 10000; /* remainder to microseconds */
-
- nscb = calloc(1, sizeof(struct nscallback));
-
- gettimeofday(&nscb->tv, NULL);
- timeradd(&nscb->tv, &tv, &nscb->tv);
-
- nscb->callback = callback;
- nscb->p = p;
-
- /* add to list front */
- nscb->next = schedule_list;
- schedule_list = nscb;
-}
-
/**
* Unschedule a callback.
*
@@ -80,17 +52,18 @@ void schedule(int cs_ival, void (*callback)(void *p), void *p)
*
* All scheduled callbacks matching both callback and p are removed.
*/
-
-void schedule_remove(void (*callback)(void *p), void *p)
+static nserror schedule_remove(void (*callback)(void *p), void *p)
{
struct nscallback *cur_nscb;
struct nscallback *prev_nscb;
struct nscallback *unlnk_nscb;
- if (schedule_list == NULL)
- return;
+ /* check there is something on the list to remove */
+ if (schedule_list == NULL) {
+ return NSERROR_OK;
+ }
- LOG(("removing %p, %p", callback, p));
+ SRLOG(("removing %p, %p", callback, p));
cur_nscb = schedule_list;
prev_nscb = NULL;
@@ -100,7 +73,7 @@ void schedule_remove(void (*callback)(void *p), void *p)
(cur_nscb->p == p)) {
/* item to remove */
- LOG(("callback entry %p removing %p(%p)",
+ SRLOG(("callback entry %p removing %p(%p)",
cur_nscb, cur_nscb->callback, cur_nscb->p));
/* remove callback */
@@ -119,16 +92,45 @@ void schedule_remove(void (*callback)(void *p), void *p)
cur_nscb = prev_nscb->next;
}
}
+
+ return NSERROR_OK;
}
-/**
- * Process scheduled callbacks up to current time.
- *
- * @return The number of milliseconds untill the next scheduled event
- * or -1 for no event.
- */
-int
-schedule_run(void)
+/* exported function documented in framebuffer/schedule.h */
+nserror framebuffer_schedule(int tival, void (*callback)(void *p), void *p)
+{
+ struct nscallback *nscb;
+ struct timeval tv;
+ nserror ret;
+
+ /* ensure uniqueness of the callback and context */
+ ret = schedule_remove(callback, p);
+ if ((tival < 0) || (ret != NSERROR_OK)) {
+ return ret;
+ }
+
+ SRLOG(("Adding %p(%p) in %d", callback, p, tival));
+
+ tv.tv_sec = tival / 1000; /* miliseconds to seconds */
+ tv.tv_usec = (tival % 1000) * 1000; /* remainder to microseconds */
+
+ nscb = calloc(1, sizeof(struct nscallback));
+
+ gettimeofday(&nscb->tv, NULL);
+ timeradd(&nscb->tv, &tv, &nscb->tv);
+
+ nscb->callback = callback;
+ nscb->p = p;
+
+ /* add to list front */
+ nscb->next = schedule_list;
+ schedule_list = nscb;
+
+ return NSERROR_OK;
+}
+
+/* exported function documented in framebuffer/schedule.h */
+int schedule_run(void)
{
struct timeval tv;
struct timeval nexttime;
@@ -188,7 +190,8 @@ schedule_run(void)
/* make rettime relative to now */
timersub(&nexttime, &tv, &rettime);
- /*LOG(("returning time to next event as %ldms",(rettime.tv_sec * 1000) + (rettime.tv_usec / 1000))); */
+ SRLOG(("returning time to next event as %ldms",(rettime.tv_sec * 1000) + (rettime.tv_usec / 1000)));
+
/* return next event time in milliseconds (24days max wait) */
return (rettime.tv_sec * 1000) + (rettime.tv_usec / 1000);
}
diff --git a/framebuffer/schedule.h b/framebuffer/schedule.h
index 2c9b55f82..4e94da68e 100644
--- a/framebuffer/schedule.h
+++ b/framebuffer/schedule.h
@@ -19,7 +19,27 @@
#ifndef FRAMEBUFFER_SCHEDULE_H
#define FRAMEBUFFER_SCHEDULE_H
+/**
+ * Schedule a callback.
+ *
+ * \param tival 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 framebuffer_schedule(int tival, void (*callback)(void *p), void *p);
+
+/**
+ * Process scheduled callbacks up to current time.
+ *
+ * @return The number of milliseconds untill the next scheduled event
+ * or -1 for no event.
+ */
int schedule_run(void);
+
void list_schedule(void);
#endif