gtk and libgps



Hi, 

I'm trying to communicate with gpsd within a gtk application. 
Unsuccessful so far. It works until i issue gtk_init(). After that, the
gps callback still gets called but won't return any data anymore.
My guess is that it has something to do with the thread libgps is using 
for the callback. I tried it with mutex locks and g_thread_init() but 
have no idea how to do this right.
Does anybody have an idea what i am doing wrong here?

#include <gtk/gtk.h>
#include <gps.h>

void gps_callback (struct gps_data_t *gps, char *buf, size_t len, int 
level) {

    if (gps->fix.mode == MODE_NOT_SEEN)
        return;
    printf("%f N %f E (fix: %d)\n", gps->fix.latitude,   
                                                  gps->fix.longitude,
                                                  gps->fix.mode);
}

int gps_connect_with_callback(void)
{
    struct gps_data_t *gpsdata;
    pthread_t gps_thread;

    gpsdata = gps_open("localhost", "2947");
    if (gpsdata == NULL) {
        fprintf(stderr, "Error gps_open\n");
        exit(1);
    }
    gps_set_callback(gpsdata, &gps_callback, &gps_thread);

    return 0;
}
int main(int argc, char **argv)
{
    gps_connect_with_callback();
    /* valid gps data is printed to stdout */
    sleep(5);
    gtk_init(&argc, &argv);
    /* no more gps data is coming - callback still gets called */
    sleep(5);
    return(0);
}

Many thanks,

Andreas
      



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]