summaryrefslogtreecommitdiff
path: root/navit/navit
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-15 15:40:59 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-15 15:40:59 +0000
commitb5b43b6f1bdf9f5f0d7d4a0cf562ab7eb719271f (patch)
tree96c1c36f399577c509c46963b2ccebe45a42d801 /navit/navit
parent931889b8daf18a31a2281e5a291b23e3a8aeec01 (diff)
downloadnavit-b5b43b6f1bdf9f5f0d7d4a0cf562ab7eb719271f.tar.gz
Fix:Core:Changed core to use event functions instead of glib ones
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1473 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/navit')
-rw-r--r--navit/navit/cursor.c22
-rw-r--r--navit/navit/event_glib.c19
-rw-r--r--navit/navit/log.c18
-rw-r--r--navit/navit/navit.c37
-rw-r--r--navit/navit/start.c2
5 files changed, 53 insertions, 45 deletions
diff --git a/navit/navit/cursor.c b/navit/navit/cursor.c
index 933297059..2a7ef576b 100644
--- a/navit/navit/cursor.c
+++ b/navit/navit/cursor.c
@@ -36,6 +36,7 @@
#include "color.h"
#include "cursor.h"
#include "compass.h"
+#include "event.h"
/* #include "track.h" */
@@ -48,7 +49,8 @@ struct cursor {
int current_gc;
int last_dir;
int last_draw_dir;
- guint animate_timer;
+ struct callback *animate_callback;
+ struct event_timeout *animate_timer;
struct point cursor_pnt;
};
@@ -120,7 +122,8 @@ cursor_draw(struct cursor *this_, struct point *pnt, int dir, int draw_dir, int
}
}
-static gboolean cursor_animate(struct cursor * this)
+static void
+cursor_animate(struct cursor * this)
{
struct point p;
this->current_gc++;
@@ -129,7 +132,6 @@ static gboolean cursor_animate(struct cursor * this)
p.x = this->cursor_pnt.x;
p.y = this->cursor_pnt.y;
cursor_draw(this, &p, this->last_dir, this->last_draw_dir, 1);
- return TRUE;
}
struct cursor *
@@ -165,8 +167,10 @@ cursor_new(struct graphics *gra, struct color *c, struct color *c2, int animate)
break; // no need to create other GCs if we are not animating
}
}
- if (animate)
- this->animate_timer=g_timeout_add(250, (GSourceFunc)cursor_animate, (gpointer *)this);
+ if (animate) {
+ this->animate_callback=callback_new_1(callback_cast(cursor_animate), this);
+ this->animate_timer=event_add_timeout(250, 1, this->animate_callback);
+ }
this->cursor_pnt.x = 0;
this->cursor_pnt.y = 0;
dbg(2,"ret=%p\n", this);
@@ -177,12 +181,14 @@ void
cursor_destroy(struct cursor *this_)
{
int i;
- if (this_->animate_timer)
- g_source_remove(this_->animate_timer);
- for (i=0;i<NUM_GC;i++)
+
+ callback_destroy(this_->animate_callback);
+ event_remove_timeout(this_->animate_timer);
+ for (i=0;i<NUM_GC;i++) {
if(this_->cursor_gc[i])
graphics_gc_destroy(this_->cursor_gc[i]);
if(this_->cursor_gc2[i])
graphics_gc_destroy(this_->cursor_gc2[i]);
+ }
g_free(this_);
}
diff --git a/navit/navit/event_glib.c b/navit/navit/event_glib.c
index 69e6358d2..f7d67c3cf 100644
--- a/navit/navit/event_glib.c
+++ b/navit/navit/event_glib.c
@@ -66,6 +66,8 @@ static void
event_glib_remove_watch(struct event_watch *ev)
{
GError *error = NULL;
+ if (! ev)
+ return;
g_source_remove(ev->source);
g_io_channel_shutdown(ev->iochan, 0, &error);
g_free(ev);
@@ -73,21 +75,21 @@ event_glib_remove_watch(struct event_watch *ev)
struct event_timeout {
guint source;
+ struct callback *cb;
};
static gboolean
-event_glib_call_timeout_single(gpointer t)
+event_glib_call_timeout_single(struct event_timeout *ev)
{
- struct callback *cb=t;
- callback_call_0(cb);
+ callback_call_0(ev->cb);
+ g_free(ev);
return FALSE;
}
static gboolean
-event_glib_call_timeout_multi(gpointer t)
+event_glib_call_timeout_multi(struct event_timeout *ev)
{
- struct callback *cb=t;
- callback_call_0(cb);
+ callback_call_0(ev->cb);
return TRUE;
}
@@ -96,7 +98,8 @@ static struct event_timeout *
event_glib_add_timeout(int timeout, int multi, struct callback *cb)
{
struct event_timeout *ret=g_new0(struct event_timeout, 1);
- ret->source = g_timeout_add(timeout, multi ? (GSourceFunc)event_glib_call_timeout_multi : (GSourceFunc)event_glib_call_timeout_single, (gpointer)cb);
+ ret->cb=cb;
+ ret->source = g_timeout_add(timeout, multi ? (GSourceFunc)event_glib_call_timeout_multi : (GSourceFunc)event_glib_call_timeout_single, (gpointer)ret);
return ret;
}
@@ -104,6 +107,8 @@ event_glib_add_timeout(int timeout, int multi, struct callback *cb)
static void
event_glib_remove_timeout(struct event_timeout *ev)
{
+ if (! ev)
+ return;
g_source_remove(ev->source);
g_free(ev);
}
diff --git a/navit/navit/log.c b/navit/navit/log.c
index 137bb9547..028db134d 100644
--- a/navit/navit/log.c
+++ b/navit/navit/log.c
@@ -27,6 +27,8 @@
#include <glib.h>
#include "file.h"
#include "item.h"
+#include "event.h"
+#include "callback.h"
#include "debug.h"
#include "log.h"
@@ -44,7 +46,8 @@ struct log {
int mkdir;
int flush_size;
int flush_time;
- guint timer;
+ struct event_timeout *timer;
+ struct callback *timer_callback;
struct timeval last_flush;
char *filename;
char *filename_ex1;
@@ -182,10 +185,9 @@ log_change_required(struct log *this_)
return (strcmp(this_->filename_ex1, buffer) != 0);
}
-static gboolean
-log_timer(gpointer data)
+static void
+log_timer(struct log *this_)
{
- struct log *this_=data;
struct timeval tv;
int delta;
gettimeofday(&tv, NULL);
@@ -193,7 +195,6 @@ log_timer(gpointer data)
dbg(1,"delta=%d flush_time=%d\n", delta, this_->flush_time);
if (this_->flush_time && delta >= this_->flush_time*1000)
log_flush(this_);
- return TRUE;
}
int
@@ -242,7 +243,8 @@ log_new(struct attr **attrs)
ret->flush_time=flush_time->u.num;
if (ret->flush_time) {
dbg(1,"interval %d\n", ret->flush_time*1000);
- ret->timer=g_timeout_add(ret->flush_time*1000, log_timer, ret);
+ ret->timer_callback=callback_new_1(callback_cast(log_timer), ret);
+ ret->timer=event_add_timeout(ret->flush_time*1000, 1, ret->timer_callback);
}
expand_filenames(ret);
if (ret->lazy)
@@ -291,8 +293,8 @@ log_write(struct log *this_, char *data, int len)
void
log_destroy(struct log *this_)
{
- if (this_->timer)
- g_source_remove(this_->timer);
+ callback_destroy(this_->timer_callback);
+ event_remove_timeout(this_->timer);
log_flush(this_);
log_close(this_);
g_free(this_);
diff --git a/navit/navit/navit.c b/navit/navit/navit.c
index a9850abae..b33e7781b 100644
--- a/navit/navit/navit.c
+++ b/navit/navit/navit.c
@@ -117,7 +117,8 @@ struct navit {
struct menu *destinations;
struct point pressed, last, current;
int button_pressed,moved,popped;
- guint button_timeout, motion_timeout;
+ struct event_timer *button_timeout, *motion_timeout;
+ struct callback *motion_timeout_callback;
int ignore_button;
struct log *textfile_debug_log;
struct pcoord destination;
@@ -223,18 +224,11 @@ navit_popup(void *data)
{
struct navit *this_=data;
popup(this_, 1, &this_->pressed);
- this_->button_timeout=0;
+ this_->button_timeout=NULL;
this_->popped=1;
}
-static gboolean
-navit_handle_button_timeout(void *data)
-{
- callback_call_0((struct callback *)data);
- return FALSE;
-}
-
int
navit_ignore_button(struct navit *this_)
{
@@ -259,7 +253,7 @@ navit_handle_button(struct navit *this_, int pressed, int button, struct point *
this_->moved=0;
this_->popped=0;
if (popup_callback)
- this_->button_timeout=g_timeout_add(500, navit_handle_button_timeout, popup_callback);
+ this_->button_timeout=event_add_timeout(500, 0, popup_callback);
}
if (button == 2)
navit_set_center_screen(this_, p);
@@ -272,15 +266,15 @@ navit_handle_button(struct navit *this_, int pressed, int button, struct point *
} else {
this_->button_pressed=0;
if (this_->button_timeout) {
- g_source_remove(this_->button_timeout);
- this_->button_timeout=0;
+ event_remove_timeout(this_->button_timeout);
+ this_->button_timeout=NULL;
if (! this_->moved && ! transform_within_border(this_->trans, p, border))
navit_set_center_screen(this_, p);
}
if (this_->motion_timeout) {
- g_source_remove(this_->motion_timeout);
- this_->motion_timeout=0;
+ event_remove_timeout(this_->motion_timeout);
+ this_->motion_timeout=NULL;
}
if (this_->moved) {
struct point pt;
@@ -308,10 +302,9 @@ navit_button(void *data, int pressed, int button, struct point *p)
}
-static gboolean
-navit_motion_timeout(void *data)
+static void
+navit_motion_timeout(struct navit *this_)
{
- struct navit *this_=data;
int dx, dy;
dx=(this_->current.x-this_->last.x);
@@ -323,7 +316,7 @@ navit_motion_timeout(void *data)
graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, 0);
this_->moved=1;
}
- this_->motion_timeout=0;
+ this_->motion_timeout=NULL;
return FALSE;
}
@@ -337,12 +330,14 @@ navit_handle_motion(struct navit *this_, struct point *p)
dy=(p->y-this_->pressed.y);
if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
if (this_->button_timeout) {
- g_source_remove(this_->button_timeout);
- this_->button_timeout=0;
+ event_remove_timeout(this_->button_timeout);
+ this_->button_timeout=NULL;
}
this_->current=*p;
+ if (! this_->motion_timeout_callback)
+ this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
if (! this_->motion_timeout)
- this_->motion_timeout=g_timeout_add(100, navit_motion_timeout, this_);
+ this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
}
}
}
diff --git a/navit/navit/start.c b/navit/navit/start.c
index fe7ac1e38..a7233a155 100644
--- a/navit/navit/start.c
+++ b/navit/navit/start.c
@@ -148,6 +148,7 @@ int main(int argc, char **argv)
} while (!file_exists(config_file));
g_list_free(list);
+ event_request_system("glib","start");
if (!config_load(config_file, &error)) {
printf(_("Error parsing '%s': %s\n"), config_file, error->message);
exit(1);
@@ -158,7 +159,6 @@ int main(int argc, char **argv)
printf(_("No instance has been created, exiting\n"));
exit(1);
}
- event_request_system("glib","start");
event_main_loop_run();
return 0;