Moved coordinate transformation proto to a subdirectory
[ptas] / location-provider.c
1 #include "location-provider.h"
2
3 #include <location/location-gps-device.h>
4 #include <location/location-gpsd-control.h>
5
6 void (*listener)(double, double) = NULL;
7
8 /*static void on_error(LocationGPSDControl *control, LocationGPSDControlError error, gpointer data)
9 {
10         g_debug("location error: %d... quitting", error);
11         g_main_loop_quit((GMainLoop *) data);
12 }*/
13
14 static void on_changed(LocationGPSDevice *device, gpointer data)
15 {
16     if (device == NULL || listener == NULL) {
17         return;
18     }
19
20     if (device->fix) {
21         if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
22             listener(device->fix->latitude, device->fix->longitude);
23         }
24     }
25 }
26
27 /*static void on_stop(LocationGPSDControl *control, gpointer data)
28 {
29         g_debug("quitting");
30         g_main_loop_quit((GMainLoop *) data);
31 }*/
32
33 /*static gboolean start_location(gpointer data)
34 {
35         location_gpsd_control_start((LocationGPSDControl *) data);
36         return FALSE;
37 }*/
38
39 LocationGPSDControl *control = NULL;
40 LocationGPSDevice *device = NULL;
41
42 void setup_location_provider()
43 {
44 //      GMainLoop *loop;
45
46 //      g_type_init();
47
48 //      loop = g_main_loop_new(NULL, FALSE);
49
50     if (control != NULL) {
51         return;
52     }
53
54     control = location_gpsd_control_get_default();
55     device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
56
57     g_object_set(G_OBJECT(control),
58         "preferred-method", LOCATION_METHOD_USER_SELECTED,
59         "preferred-interval", LOCATION_INTERVAL_DEFAULT,
60         NULL);
61
62 //      g_signal_connect(control, "error-verbose", G_CALLBACK(on_error), loop);
63     g_signal_connect(device, "changed", G_CALLBACK(on_changed), control);
64 //      g_signal_connect(control, "gpsd-stopped", G_CALLBACK(on_stop), loop);
65
66 //      g_idle_add(start_location, control);
67
68 //      g_main_loop_run(loop);
69 }
70
71 void cleanup_location_provider()
72 {
73     if (control != NULL) {
74         location_gpsd_control_stop(control);
75
76         g_object_unref(device);
77         g_object_unref(control);
78         device = NULL;
79         control = NULL;
80     }
81 }
82
83 void start_location_provider()
84 {
85     if (control != NULL) {
86         location_gpsd_control_start(control);
87     }
88 }
89
90 void stop_location_provider()
91 {
92     if (control != NULL) {
93         location_gpsd_control_stop(control);
94     }
95 }
96
97 void set_location_listener(void (*newListener)(double, double))
98 {
99     listener = newListener;
100 }