23 |
|
|
24 |
#include "appdata.h" |
#include "appdata.h" |
25 |
|
|
26 |
#ifdef USE_HILDON |
#ifdef ENABLE_LIBLOCATION |
27 |
|
|
28 |
|
#include <location/location-gps-device.h> |
29 |
|
|
30 |
|
pos_t *gps_get_pos(appdata_t *appdata) { |
31 |
|
gps_state_t *gps_state = appdata->gps_state; |
32 |
|
static pos_t retval; |
33 |
|
|
34 |
|
if(!gps_state->fix) |
35 |
|
return NULL; |
36 |
|
|
37 |
|
retval.lat = gps_state->latitude; |
38 |
|
retval.lon = gps_state->longitude; |
39 |
|
|
40 |
|
return &retval; |
41 |
|
} |
42 |
|
|
43 |
|
static void |
44 |
|
location_changed(LocationGPSDevice *device, gps_state_t *gps_state) { |
45 |
|
|
46 |
|
gps_state->fix = |
47 |
|
(device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET); |
48 |
|
|
49 |
|
if(gps_state->fix) { |
50 |
|
gps_state->latitude = device->fix->latitude; |
51 |
|
gps_state->longitude = device->fix->longitude; |
52 |
|
} |
53 |
|
} |
54 |
|
|
55 |
|
void gps_init(appdata_t *appdata) { |
56 |
|
gps_state_t *gps_state = appdata->gps_state = g_new0(gps_state_t, 1); |
57 |
|
|
58 |
|
printf("GPS init: Using liblocation\n"); |
59 |
|
|
60 |
|
gps_state->device = g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL); |
61 |
|
if(!gps_state->device) { |
62 |
|
printf("Unable to connect to liblocation\n"); |
63 |
|
return; |
64 |
|
} |
65 |
|
|
66 |
|
gps_state->idd_changed = |
67 |
|
g_signal_connect(gps_state->device, "changed", |
68 |
|
G_CALLBACK(location_changed), gps_state); |
69 |
|
|
70 |
|
#if MAEMO_VERSION_MAJOR < 5 |
71 |
|
gps_state->control = location_gpsd_control_get_default(); |
72 |
|
if(gps_state->control->can_control) { |
73 |
|
printf("Having control over GPSD, starting it\n"); |
74 |
|
location_gpsd_control_start(gps_state->control); |
75 |
|
} |
76 |
|
#endif |
77 |
|
} |
78 |
|
|
79 |
|
void gps_release(appdata_t *appdata) { |
80 |
|
gps_state_t *gps_state = appdata->gps_state; |
81 |
|
|
82 |
|
if(!gps_state->device) return; |
83 |
|
|
84 |
|
#if MAEMO_VERSION_MAJOR < 5 |
85 |
|
/* Disconnect signal */ |
86 |
|
if(gps_state->control->can_control) { |
87 |
|
printf("Having control over GPSD, stopping it\n"); |
88 |
|
location_gpsd_control_stop(gps_state->control); |
89 |
|
} |
90 |
|
#endif |
91 |
|
|
92 |
|
g_signal_handler_disconnect(gps_state->device, gps_state->idd_changed); |
93 |
|
|
94 |
|
g_free(appdata->gps_state); |
95 |
|
appdata->gps_state = NULL; |
96 |
|
} |
97 |
|
|
98 |
|
#else // ENABLE_LIBLOCATION |
99 |
|
|
100 |
|
#ifdef ENABLE_GPSBT |
101 |
#include <gpsbt.h> |
#include <gpsbt.h> |
102 |
#include <gpsmgr.h> |
#include <gpsmgr.h> |
103 |
#include <errno.h> |
#include <errno.h> |
128 |
|
|
129 |
static int gps_connect(gps_state_t *gps_state) { |
static int gps_connect(gps_state_t *gps_state) { |
130 |
GnomeVFSResult vfs_result; |
GnomeVFSResult vfs_result; |
131 |
#ifdef USE_HILDON |
#ifdef ENABLE_GPSBT |
132 |
char errstr[256] = ""; |
char errstr[256] = ""; |
133 |
|
|
134 |
/* We need to start gpsd (via gpsbt) first. */ |
/* We need to start gpsd (via gpsbt) first. */ |
303 |
printf("stopping GPS connection due to user request\n"); |
printf("stopping GPS connection due to user request\n"); |
304 |
gnome_vfs_inet_connection_destroy(appdata->gps_state->iconn, NULL); |
gnome_vfs_inet_connection_destroy(appdata->gps_state->iconn, NULL); |
305 |
|
|
306 |
#ifdef USE_HILDON |
#ifdef ENABLE_GPSBT |
307 |
gpsbt_stop(&appdata->gps_state->context); |
gpsbt_stop(&appdata->gps_state->context); |
308 |
#endif |
#endif |
309 |
connected = FALSE; |
connected = FALSE; |
319 |
void gps_init(appdata_t *appdata) { |
void gps_init(appdata_t *appdata) { |
320 |
appdata->gps_state = g_new0(gps_state_t, 1); |
appdata->gps_state = g_new0(gps_state_t, 1); |
321 |
|
|
322 |
|
printf("GPS init: Using gpsd\n"); |
323 |
|
|
324 |
/* start a new thread to listen to gpsd */ |
/* start a new thread to listen to gpsd */ |
325 |
appdata->gps_state->mutex = g_mutex_new(); |
appdata->gps_state->mutex = g_mutex_new(); |
326 |
appdata->gps_state->thread_p = |
appdata->gps_state->thread_p = |
328 |
} |
} |
329 |
|
|
330 |
void gps_release(appdata_t *appdata) { |
void gps_release(appdata_t *appdata) { |
331 |
#ifdef USE_HILDON |
#ifdef ENABLE_GPSBT |
332 |
gpsbt_stop(&appdata->gps_state->context); |
gpsbt_stop(&appdata->gps_state->context); |
333 |
#endif |
#endif |
334 |
g_free(appdata->gps_state); |
g_free(appdata->gps_state); |
335 |
|
appdata->gps_state = NULL; |
336 |
} |
} |
337 |
|
|
338 |
|
#endif // ENABLE_LIBLOCATION |