Fix:Core:Some cleanups
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 5 Jan 2009 07:30:17 +0000 (07:30 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 5 Jan 2009 07:30:17 +0000 (07:30 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1886 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/attr_def.h
navit/main.c
navit/main.h
navit/navit.c

index 0bcf4f6..199be1f 100644 (file)
@@ -225,6 +225,7 @@ ATTR(osd)
 ATTR(plugin)
 ATTR(speech)
 ATTR(coord)
+ATTR(private_data)
 ATTR2(0x0008ffff,type_object_end)
 ATTR2(0x00090000,type_coord_begin)
 ATTR2(0x0009ffff,type_coord_end)
index a547782..18499a6 100644 (file)
@@ -44,6 +44,7 @@
 #include "route.h"
 #include "navigation.h"
 #include "event.h"
+#include "callback.h"
 #include "navit_nls.h"
 #if HAVE_API_WIN32_BASE
 #include <windows.h>
@@ -53,6 +54,9 @@
 
 struct map_data *map_data_default;
 
+struct callback_list *cbl;
+
+
 static void sigchld(int sig)
 {
 #if !defined(_WIN32) && !defined(__CEGCC__)
@@ -120,16 +124,45 @@ void
 main_add_navit(struct navit *nav)
 {
        navit=g_list_prepend(navit, nav);
+       callback_list_call_2(cbl, nav, 1);
 }
 
 void
 main_remove_navit(struct navit *nav)
 {
        navit=g_list_remove(navit, nav);
+       callback_list_call_2(cbl, nav, 0);
        if (! navit) 
                event_main_loop_quit();
 }
 
+int
+main_add_attr(struct attr *attr)
+{
+       switch (attr->type)
+       {
+       case attr_callback:
+               callback_list_add(cbl, attr->u.callback);
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+int
+main_remove_attr(struct attr *attr)
+{
+       switch (attr->type)
+       {
+       case attr_callback:
+               callback_list_remove(cbl, attr->u.callback);
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+
 #ifdef HAVE_API_WIN32
 void
 setenv(char *var, char *val, int overwrite)
@@ -186,7 +219,7 @@ main_init(char *program)
 #ifndef _WIN32
        signal(SIGCHLD, sigchld);
 #endif
-
+       cbl=callback_list_new();
        setenv("LC_NUMERIC","C",1);
        setlocale(LC_ALL,"");
        setlocale(LC_NUMERIC,"C");
index d51979c..f39e8e2 100644 (file)
@@ -28,6 +28,8 @@ void main_iter_destroy(struct iter *iter);
 struct navit * main_get_navit(struct iter *iter);
 void main_add_navit(struct navit *nav);
 void main_remove_navit(struct navit *nav);
+int main_add_attr(struct attr *attr);
+int main_remove_attr(struct attr *attr);
 void main_init(char *program);
 void main_init_nls(void);
 int main(int argc, char **argv);
index bf30cd7..5ef477d 100644 (file)
@@ -506,10 +506,10 @@ navit_new(struct attr *parent, struct attr **attrs)
        g.lat=53.13;
        g.lng=11.70;
 
-       main_add_navit(this_);
        this_->self.type=attr_navit;
        this_->self.u.navit=this_;
        this_->attr_cbl=callback_list_new();
+       main_add_navit(this_);
 
 #if !defined(_WIN32) && !defined(__CEGCC__)
        f=popen("pidof /usr/bin/ipaq-sleep","r");
@@ -1150,6 +1150,7 @@ navit_init(struct navit *this_)
                return;
        }
        graphics_init(this_->gra);
+#if 0
        l=this_->vehicles;
        while (l) {
                dbg(1,"parsed one vehicle\n");
@@ -1160,6 +1161,7 @@ navit_init(struct navit *this_)
                vehicle_set_attr(nv->vehicle, &this_->self, NULL);
                l=g_list_next(l);
        }
+#endif
        if (this_->mapsets) {
                ms=this_->mapsets->data;
                if (this_->route) {
@@ -1816,6 +1818,10 @@ navit_add_vehicle(struct navit *this_, struct vehicle *v)
                navit_set_vehicle(this_, nv);
        if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
                nv->animate_cursor=animate.u.num;
+       nv->callback.type=attr_callback;
+       nv->callback.u.callback=callback_new_2(callback_cast(navit_vehicle_update), this_, nv);
+       vehicle_add_attr(nv->vehicle, &nv->callback);
+       vehicle_set_attr(nv->vehicle, &this_->self, NULL);
        return 1;
 }