From 710e697d4cdf89a0db1da95f13455274f4bbd957 Mon Sep 17 00:00:00 2001 From: horwitz Date: Tue, 19 Feb 2008 13:04:14 +0000 Subject: [PATCH] core:Add:Merge callback lists into one callback list. git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@887 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/src/callback.h | 29 ++++++++++++++++++++ navit/src/gui/gtk/gui_gtk_statusbar.c | 5 ++-- navit/src/gui/sdl/gui_sdl_window.cpp | 6 +++-- navit/src/navit.c | 51 +++++------------------------------ navit/src/navit.h | 9 +++---- navit/src/osd/core/osd_core.c | 2 +- 6 files changed, 47 insertions(+), 55 deletions(-) diff --git a/navit/src/callback.h b/navit/src/callback.h index 6cafb7a..102f8e1 100644 --- a/navit/src/callback.h +++ b/navit/src/callback.h @@ -1,6 +1,9 @@ #ifndef NAVIT_CALLBACK_H #define NAVIT_CALLBACK_H +#include "item.h" +#include "attr.h" + #ifdef __cplusplus extern "C" { #endif @@ -22,11 +25,23 @@ void callback_list_call(struct callback_list *l, int pcount, void **p); void callback_list_destroy(struct callback_list *l); /* end of prototypes */ +static inline struct callback *callback_new_attr_0(void (*func)(void), enum attr_type type) +{ + return callback_new_attr(func, type, 0, NULL); +} + static inline struct callback *callback_new_0(void (*func)(void)) { return callback_new(func, 0, NULL); } +static inline struct callback *callback_new_attr_1(void (*func)(void), enum attr_type type, void *p1) +{ + void *p[1]; + p[0]=p1; + return callback_new_attr(func, type, 1, p); +} + static inline struct callback *callback_new_1(void (*func)(void), void *p1) { void *p[1]; @@ -68,6 +83,12 @@ static inline void callback_list_call_0(struct callback_list *l) callback_list_call(l, 0, NULL); } +static inline void callback_list_call_attr_1(struct callback_list *l, enum attr_type type, void *p1) +{ + void *p[1]; + p[0]=p1; + callback_list_call_attr(l, type, 1, p); +} static inline void callback_list_call_1(struct callback_list *l, void *p1) { @@ -76,6 +97,14 @@ static inline void callback_list_call_1(struct callback_list *l, void *p1) callback_list_call(l, 1, p); } +static inline void callback_list_call_attr_2(struct callback_list *l, enum attr_type type, void *p1, void *p2) +{ + void *p[2]; + p[0]=p1; + p[1]=p2; + callback_list_call_attr(l, type, 2, p); +} + static inline void callback_list_call_2(struct callback_list *l, void *p1, void *p2) { void *p[2]; diff --git a/navit/src/gui/gtk/gui_gtk_statusbar.c b/navit/src/gui/gtk/gui_gtk_statusbar.c index 912cd6f..2c843fe 100644 --- a/navit/src/gui/gtk/gui_gtk_statusbar.c +++ b/navit/src/gui/gtk/gui_gtk_statusbar.c @@ -162,8 +162,9 @@ gui_gtk_statusbar_new(struct gui_priv *gui, struct statusbar_methods *meth) gtk_box_pack_end(GTK_BOX(gui->vbox), this->hbox, FALSE, FALSE, 0); gtk_widget_show_all(this->hbox); - this->vehicle_cb=callback_new_1(callback_cast(statusbar_route_update), this); - navit_add_vehicle_cb(gui->nav, this->vehicle_cb); + /* add a callback for position updates */ + this->vehicle_cb=callback_new_attr_1(callback_cast(statusbar_route_update), attr_position_coord_geo, this); + navit_add_callback(gui->nav, this->vehicle_cb); return this; } diff --git a/navit/src/gui/sdl/gui_sdl_window.cpp b/navit/src/gui/sdl/gui_sdl_window.cpp index 681712d..36416a5 100644 --- a/navit/src/gui/sdl/gui_sdl_window.cpp +++ b/navit/src/gui/sdl/gui_sdl_window.cpp @@ -897,9 +897,11 @@ gui_sdl_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs) dbg(1,"End SDL init\n"); //gui_sdl_window.cpp:710: error: invalid conversion from 'void (*)(vehicle*)' to 'void (*)()' - struct callback *cb=callback_new_0(callback_cast(vehicle_callback_handler)); + + /* add callback for position updates */ + struct callback *cb=callback_new_attr_0(callback_cast(vehicle_callback_handler), attr_position_coord_geo); - navit_add_vehicle_cb(nav,cb); + navit_add_callback(nav,cb); this_->nav=nav; return this_; diff --git a/navit/src/navit.c b/navit/src/navit.c index d0c9c12..ce4779b 100644 --- a/navit/src/navit.c +++ b/navit/src/navit.c @@ -85,8 +85,6 @@ struct navit { GList *vehicles; GList *windows_items; struct navit_vehicle *vehicle; - struct callback_list *vehicle_cbl; - struct callback_list *init_cbl; struct callback_list *attr_cbl; int pid; struct callback *nav_speech_cb; @@ -336,8 +334,6 @@ navit_new(struct attr **attrs) main_add_navit(this_); this_->self.type=attr_navit; this_->self.u.navit=this_; - this_->vehicle_cbl=callback_list_new(); - this_->init_cbl=callback_list_new(); this_->attr_cbl=callback_list_new(); f=popen("pidof /usr/bin/ipaq-sleep","r"); @@ -1184,8 +1180,6 @@ navit_init(struct navit *this_) if (this_->navigation && this_->speech) { this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_); navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb); -#if 0 -#endif } if (this_->menubar) { men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL); @@ -1199,7 +1193,7 @@ navit_init(struct navit *this_) navit_window_items_new(this_); #endif navit_debug(this_); - callback_list_call_1(this_->init_cbl, this_); + callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_); } void @@ -1305,12 +1299,7 @@ navit_set_attr(struct navit *this_, struct attr *attr) return 0; } if (attr_updated) { - void *p[2]; - - p[0] = this_; - p[1] = attr; - - callback_list_call_attr(this_->attr_cbl, attr->type, 2, p); + callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr); } return 1; } @@ -1339,8 +1328,7 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr) } static int -navit_add_log(struct navit *this_, struct log *log, - struct attr **attrs) +navit_add_log(struct navit *this_, struct log *log, struct attr **attrs) { struct attr *type; type = attr_search(attrs, NULL, attr_type); @@ -1356,8 +1344,7 @@ navit_add_log(struct navit *this_, struct log *log, } int -navit_add_attr(struct navit *this_, struct attr *attr, - struct attr **attrs) +navit_add_attr(struct navit *this_, struct attr *attr, struct attr **attrs) { switch (attr->type) { case attr_log: @@ -1369,13 +1356,13 @@ navit_add_attr(struct navit *this_, struct attr *attr, } void -navit_add_attr_cb(struct navit *this_, struct callback *cb) +navit_add_callback(struct navit *this_, struct callback *cb) { callback_list_add(this_->attr_cbl, cb); } void -navit_remove_attr_cb(struct navit *this_, struct callback *cb) +navit_remove_callback(struct navit *this_, struct callback *cb) { callback_list_remove(this_->attr_cbl, cb); } @@ -1478,7 +1465,7 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv) nv->update_curr--; else nv->update_curr=nv->update; - callback_list_call_2(this_->vehicle_cbl, this_, nv->vehicle); + callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle); if (pnt) navit_vehicle_draw(this_, nv, pnt); } @@ -1541,30 +1528,6 @@ navit_add_vehicle(struct navit *this_, struct vehicle *v, struct attr **attrs) } void -navit_add_vehicle_cb(struct navit *this_, struct callback *cb) -{ - callback_list_add(this_->vehicle_cbl, cb); -} - -void -navit_remove_vehicle_cb(struct navit *this_, struct callback *cb) -{ - callback_list_remove(this_->vehicle_cbl, cb); -} - -void -navit_add_init_cb(struct navit *this_, struct callback *cb) -{ - callback_list_add(this_->init_cbl, cb); -} - -void -navit_remove_init_cb(struct navit *this_, struct callback *cb) -{ - callback_list_remove(this_->init_cbl, cb); -} - -void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv) { this_->vehicle=nv; diff --git a/navit/src/navit.h b/navit/src/navit.h index 540b75a..a18add1 100644 --- a/navit/src/navit.h +++ b/navit/src/navit.h @@ -63,14 +63,11 @@ void navit_set_center(struct navit *this_, struct pcoord *center); void navit_set_center_screen(struct navit *this_, struct point *p); int navit_set_attr(struct navit *this_, struct attr *attr); int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr); -void navit_add_attr_cb(struct navit *this_, struct callback *cb); -void navit_remove_attr_cb(struct navit *this_, struct callback *cb); +int navit_add_attr(struct navit *this_, struct attr *attr, struct attr **attrs); +void navit_add_callback(struct navit *this_, struct callback *cb); +void navit_remove_callback(struct navit *this_, struct callback *cb); void navit_set_position(struct navit *this_, struct pcoord *c); struct navit_vehicle *navit_add_vehicle(struct navit *this_, struct vehicle *v, struct attr **attrs); -void navit_add_vehicle_cb(struct navit *this_, struct callback *cb); -void navit_remove_vehicle_cb(struct navit *this_, struct callback *cb); -void navit_add_init_cb(struct navit *this_, struct callback *cb); -void navit_remove_init_cb(struct navit *this_, struct callback *cb); void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv); void navit_tracking_add(struct navit *this_, struct tracking *tracking); void navit_route_add(struct navit *this_, struct route *route); diff --git a/navit/src/osd/core/osd_core.c b/navit/src/osd/core/osd_core.c index 2c5f9d3..02324e9 100644 --- a/navit/src/osd/core/osd_core.c +++ b/navit/src/osd/core/osd_core.c @@ -153,7 +153,7 @@ osd_compass_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs attr=attr_search(attrs, NULL, attr_y); if (attr) this->p.y=attr->u.num; - navit_add_init_cb(nav, callback_new_1(osd_compass_init, this)); + navit_add_callback(nav, callback_new_attr_1(osd_compass_init, attr_navit, this)); return (struct osd_priv *) this; } -- 2.7.4