summaryrefslogtreecommitdiffstats
path: root/geoclue/gpsd-3.3.patch
blob: 965aa1d268a07f9053222e301c5569853cbca93e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
--- providers/gpsd/geoclue-gpsd.c.bak	2011-11-06 00:43:28.832224036 +0100
+++ providers/gpsd/geoclue-gpsd.c	2011-11-06 01:59:54.512878539 +0100
@@ -40,7 +40,6 @@
 #include <geoclue/gc-iface-position.h>
 #include <geoclue/gc-iface-velocity.h>
 
-typedef struct gps_data_t gps_data;
 typedef struct gps_fix_t gps_fix;
 
 /* only listing used tags */
@@ -59,7 +58,7 @@
 	char *host;
 	char *port;
 	
-	gps_data *gpsdata;
+	struct gps_data_t gpsdata;
 	
 	gps_fix *last_fix;
 	
@@ -152,6 +151,10 @@
 		port = DEFAULT_GPSD_PORT;
 	}
 	
+	if (host == NULL) {
+		host = "localhost";
+	}
+	
 	/* new values? */
 	if (g_strcmp0 (host, gpsd->host) != 0 ||
 	    g_strcmp0 (port, gpsd->port) != 0) {
@@ -228,16 +231,16 @@
 static void
 geoclue_gpsd_update_position (GeoclueGpsd *gpsd, NmeaTag nmea_tag)
 {
-	gps_fix *fix = &gpsd->gpsdata->fix;
+	gps_fix *fix = &gpsd->gpsdata.fix;
 	gps_fix *last_fix = gpsd->last_fix;
 	
 	last_fix->time = fix->time;
 	
 	/* If a flag is not set, bail out.*/
-	if (!((gpsd->gpsdata->set & LATLON_SET) || (gpsd->gpsdata->set & ALTITUDE_SET))) {
+	if (!((gpsd->gpsdata.set & LATLON_SET) || (gpsd->gpsdata.set & ALTITUDE_SET))) {
 		return;
 	}
-	gpsd->gpsdata->set &= ~(LATLON_SET | ALTITUDE_SET);
+	gpsd->gpsdata.set &= ~(LATLON_SET | ALTITUDE_SET);
 	
 	if (equal_or_nan (fix->latitude, last_fix->latitude) &&
 	    equal_or_nan (fix->longitude, last_fix->longitude) &&
@@ -279,7 +282,7 @@
 static void
 geoclue_gpsd_update_velocity (GeoclueGpsd *gpsd, NmeaTag nmea_tag)
 {
-	gps_fix *fix = &gpsd->gpsdata->fix;
+	gps_fix *fix = &gpsd->gpsdata.fix;
 	gps_fix *last_fix = gpsd->last_fix;
 	gboolean changed = FALSE;
 	
@@ -290,10 +293,10 @@
 	 * couldn't think of an smart way to handle this, I don't think there is one
 	 */
 	
-	if (((gpsd->gpsdata->set & TRACK_SET) || (gpsd->gpsdata->set & SPEED_SET)) &&
+	if (((gpsd->gpsdata.set & TRACK_SET) || (gpsd->gpsdata.set & SPEED_SET)) &&
 	    nmea_tag == NMEA_RMC) {
 		
-		gpsd->gpsdata->set &= ~(TRACK_SET | SPEED_SET);
+		gpsd->gpsdata.set &= ~(TRACK_SET | SPEED_SET);
 		
 		last_fix->time = fix->time;
 		
@@ -305,12 +308,12 @@
 			last_fix->track = fix->track;
 			last_fix->speed = fix->speed;
 		}
-	} else if ((gpsd->gpsdata->set & CLIMB_SET) &&
+	} else if ((gpsd->gpsdata.set & CLIMB_SET) &&
 	           (nmea_tag == NMEA_GGA || 
 	            nmea_tag == NMEA_GSA || 
 	            nmea_tag == NMEA_GSV)) {
 		
-		gpsd->gpsdata->set &= ~(CLIMB_SET);
+		gpsd->gpsdata.set &= ~(CLIMB_SET);
 		
 		last_fix->time = fix->time;
 		
@@ -344,12 +347,12 @@
 	GeoclueStatus status;
 	
 	/* gpsdata->online is supposedly always up-to-date */
-	if (gpsd->gpsdata->online <= 0) {
+	if (gpsd->gpsdata.online <= 0) {
 		status = GEOCLUE_STATUS_UNAVAILABLE;
-	} else if (gpsd->gpsdata->set & STATUS_SET) {
-		gpsd->gpsdata->set &= ~(STATUS_SET);
+	} else if (gpsd->gpsdata.set & STATUS_SET) {
+		gpsd->gpsdata.set &= ~(STATUS_SET);
 		
-		if (gpsd->gpsdata->status > 0) {
+		if (gpsd->gpsdata.status > 0) {
 			status = GEOCLUE_STATUS_AVAILABLE;
 		} else {
 			status = GEOCLUE_STATUS_ACQUIRING;
@@ -362,9 +365,9 @@
 }
 
 static void 
-gpsd_raw_hook (struct gps_data_t *gpsdata, char *message, size_t len)
+gpsd_raw_hook (struct gps_data_t gpsdata)
 {
-	char *tag_str = gpsd->gpsdata->tag;
+	char *tag_str = gpsd->gpsdata.tag;
 	NmeaTag nmea_tag = NMEA_NONE;
 	
 	if (tag_str[0] == 'G' && tag_str[1] == 'S' && tag_str[2] == 'A') {
@@ -385,23 +388,22 @@
 static void
 geoclue_gpsd_stop_gpsd (GeoclueGpsd *self)
 {
-	if (self->gpsdata) {
-		gps_close (self->gpsdata);
-		self->gpsdata = NULL;
+	struct gps_data_t *gpsdata = &self->gpsdata; 
+	if (gpsdata) {
+		gps_close (gpsdata);
+		gpsdata = NULL;
 	}
 }
 
 static gboolean
 geoclue_gpsd_start_gpsd (GeoclueGpsd *self)
 {
-	self->gpsdata = gps_open (self->host, self->port);
-	if (self->gpsdata) {
-		gps_stream(self->gpsdata, WATCH_ENABLE | WATCH_NMEA | POLL_NONBLOCK, NULL);
-		gps_set_raw_hook (self->gpsdata, gpsd_raw_hook);
-		return TRUE;
-	} else {
+	if (gps_open(self->host, self->port, &self->gpsdata) != 0) {
 		g_warning ("gps_open() failed, is gpsd running (host=%s,port=%s)?", self->host, self->port);
 		return FALSE;
+	} else {
+		gps_stream(&self->gpsdata, WATCH_ENABLE | WATCH_NMEA, NULL);
+		return TRUE;
 	}
 }
 
@@ -409,12 +411,13 @@
 gpsd_poll(gpointer data)
 {
 	GeoclueGpsd *self = (GeoclueGpsd*)data;
-	if (self->gpsdata) {
-		if (gps_poll(self->gpsdata) < 0) {
+	if (&self->gpsdata) {
+		if (gps_read(&self->gpsdata) < 0) {
 			geoclue_gpsd_set_status (self, GEOCLUE_STATUS_ERROR);
 			geoclue_gpsd_stop_gpsd(self);
 			return FALSE;
 		}
+		gpsd_raw_hook(self->gpsdata);
 	}
 	return TRUE;
 }
@@ -422,7 +425,6 @@
 static void
 geoclue_gpsd_init (GeoclueGpsd *self)
 {
-	self->gpsdata = NULL;
 	self->last_fix = g_new0 (gps_fix, 1);
 	
 	self->last_pos_fields = GEOCLUE_POSITION_FIELDS_NONE;
@@ -435,7 +437,7 @@
 				 "Gpsd", "Gpsd provider");
 	
 	self->port = g_strdup (DEFAULT_GPSD_PORT);
-	self->host = NULL;
+	self->host = "localhost";
 	geoclue_gpsd_set_status (self, GEOCLUE_STATUS_ACQUIRING);
 	if (!geoclue_gpsd_start_gpsd (self)) {
 		geoclue_gpsd_set_status (self, GEOCLUE_STATUS_ERROR);