summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Schmidt <stefan@datenfreihafen.org>2012-10-22 12:59:25 +0000
committerStefan Schmidt <stefan@datenfreihafen.org>2012-10-22 12:59:25 +0000
commit4ae7924eddc3b755baf5c43d2fa546d85121ecb5 (patch)
treec8bdd3169df3d6c3b0c16cba8c1393db5d2c905d
parent45b02c33f898345fe415b5fec8322fae77a0ac36 (diff)
PROTO/elocation: Generate geocode events and hand them off to the event handler
SVN revision: 78333
-rw-r--r--src/lib/Elocation.h2
-rw-r--r--src/lib/elocation.c72
2 files changed, 49 insertions, 25 deletions
diff --git a/src/lib/Elocation.h b/src/lib/Elocation.h
index a51238e..c9ad97d 100644
--- a/src/lib/Elocation.h
+++ b/src/lib/Elocation.h
@@ -49,6 +49,8 @@ EAPI extern int ELOCATION_EVENT_STATUS; /**< Status changed */
49EAPI extern int ELOCATION_EVENT_POSITION; /**< Position changed */ 49EAPI extern int ELOCATION_EVENT_POSITION; /**< Position changed */
50EAPI extern int ELOCATION_EVENT_ADDRESS; /**< Address changed */ 50EAPI extern int ELOCATION_EVENT_ADDRESS; /**< Address changed */
51EAPI extern int ELOCATION_EVENT_VELOCITY; /**< Velocity changed */ 51EAPI extern int ELOCATION_EVENT_VELOCITY; /**< Velocity changed */
52EAPI extern int ELOCATION_EVENT_GEOCODE; /**< Reply for geocode convertion arrived */
53EAPI extern int ELOCATION_EVENT_REVERSEGEOCODE; /**< Reply for geocode convertion arrived */
52/**@}*/ 54/**@}*/
53 55
54/** 56/**
diff --git a/src/lib/elocation.c b/src/lib/elocation.c
index 9ec2612..b3cca2b 100644
--- a/src/lib/elocation.c
+++ b/src/lib/elocation.c
@@ -25,6 +25,8 @@ static EDBus_Proxy *geonames_geocode = NULL;
25static EDBus_Proxy *geonames_rgeocode = NULL; 25static EDBus_Proxy *geonames_rgeocode = NULL;
26static Elocation_Address *address = NULL; 26static Elocation_Address *address = NULL;
27static Elocation_Position *position = NULL; 27static Elocation_Position *position = NULL;
28static Elocation_Address *addr_geocode = NULL;
29static Elocation_Position *pos_geocode = NULL;
28static Elocation_Velocity *velocity = NULL; 30static Elocation_Velocity *velocity = NULL;
29static int *status = 0; 31static int *status = 0;
30 32
@@ -36,6 +38,8 @@ EAPI int ELOCATION_EVENT_STATUS;
36EAPI int ELOCATION_EVENT_POSITION; 38EAPI int ELOCATION_EVENT_POSITION;
37EAPI int ELOCATION_EVENT_ADDRESS; 39EAPI int ELOCATION_EVENT_ADDRESS;
38EAPI int ELOCATION_EVENT_VELOCITY; 40EAPI int ELOCATION_EVENT_VELOCITY;
41EAPI int ELOCATION_EVENT_GEOCODE;
42EAPI int ELOCATION_EVENT_REVERSEGEOCODE;
39 43
40static void 44static void
41_dummy_free(void *user_data, void *func_data) 45_dummy_free(void *user_data, void *func_data)
@@ -146,12 +150,8 @@ rgeocode_cb(void *data, const EDBus_Message *reply, EDBus_Pending *pending)
146 double vertical; 150 double vertical;
147 const char *key; 151 const char *key;
148 char *value; 152 char *value;
149 Elocation_Address *addr;
150 const char *err, *errmsg; 153 const char *err, *errmsg;
151 154
152 addr = alloca(sizeof(Elocation_Address));
153 addr->accur = alloca(sizeof(Elocation_Accuracy));
154
155 if (edbus_message_error_get(reply, &err, &errmsg)) 155 if (edbus_message_error_get(reply, &err, &errmsg))
156 { 156 {
157 ERR("Error: %s %s", err, errmsg); 157 ERR("Error: %s %s", err, errmsg);
@@ -167,34 +167,35 @@ rgeocode_cb(void *data, const EDBus_Message *reply, EDBus_Pending *pending)
167 167
168 if (!strcmp(key, "country")) 168 if (!strcmp(key, "country"))
169 { 169 {
170 addr->country = strdup(value); 170 addr_geocode->country = strdup(value);
171 } 171 }
172 else if (!strcmp(key, "countrycode")) 172 else if (!strcmp(key, "countrycode"))
173 { 173 {
174 addr->countrycode = strdup(value); 174 addr_geocode->countrycode = strdup(value);
175 } 175 }
176 else if (!strcmp(key, "locality")) 176 else if (!strcmp(key, "locality"))
177 { 177 {
178 addr->locality = strdup(value); 178 addr_geocode->locality = strdup(value);
179 } 179 }
180 else if (!strcmp(key, "postalcode")) 180 else if (!strcmp(key, "postalcode"))
181 { 181 {
182 addr->postalcode = strdup(value); 182 addr_geocode->postalcode = strdup(value);
183 } 183 }
184 else if (!strcmp(key, "region")) 184 else if (!strcmp(key, "region"))
185 { 185 {
186 addr->region = strdup(value); 186 addr_geocode->region = strdup(value);
187 } 187 }
188 else if (!strcmp(key, "timezone")) 188 else if (!strcmp(key, "timezone"))
189 { 189 {
190 addr->timezone = strdup(value); 190 addr_geocode->timezone = strdup(value);
191 } 191 }
192 } 192 }
193 193
194 edbus_message_iter_arguments_get(sub, "idd", &level, &horizontal, &vertical); 194 edbus_message_iter_arguments_get(sub, "idd", &level, &horizontal, &vertical);
195 addr->accur->level = level; 195 addr_geocode->accur->level = level;
196 addr->accur->horizontal = horizontal; 196 addr_geocode->accur->horizontal = horizontal;
197 addr->accur->vertical = vertical; 197 addr_geocode->accur->vertical = vertical;
198 ecore_event_add(ELOCATION_EVENT_REVERSEGEOCODE, addr_geocode, _dummy_free, NULL);
198} 199}
199 200
200static void 201static void
@@ -211,9 +212,6 @@ geocode_cb(void *data, const EDBus_Message *reply, EDBus_Pending *pending)
211 Elocation_Position *pos; 212 Elocation_Position *pos;
212 const char *err, *errmsg; 213 const char *err, *errmsg;
213 214
214 pos = alloca(sizeof(Elocation_Position));
215 pos->accur = alloca(sizeof(Elocation_Accuracy));
216
217 if (edbus_message_error_get(reply, &err, &errmsg)) 215 if (edbus_message_error_get(reply, &err, &errmsg))
218 { 216 {
219 ERR("Error: %s %s", err, errmsg); 217 ERR("Error: %s %s", err, errmsg);
@@ -227,24 +225,25 @@ geocode_cb(void *data, const EDBus_Message *reply, EDBus_Pending *pending)
227 /* GeoClue uses some flags to mark position fields as valid. We set invalid 225 /* GeoClue uses some flags to mark position fields as valid. We set invalid
228 * fields to 0.0 */ 226 * fields to 0.0 */
229 if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE) 227 if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)
230 pos->latitude = latitude; 228 pos_geocode->latitude = latitude;
231 else 229 else
232 pos->latitude = 0.0; 230 pos_geocode->latitude = 0.0;
233 231
234 if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) 232 if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)
235 pos->longitude = longitude; 233 pos_geocode->longitude = longitude;
236 else 234 else
237 pos->longitude = 0.0; 235 pos_geocode->longitude = 0.0;
238 236
239 if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) 237 if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)
240 pos->altitude = altitude; 238 pos_geocode->altitude = altitude;
241 else 239 else
242 pos->altitude = 0.0; 240 pos_geocode->altitude = 0.0;
243 241
244 edbus_message_iter_arguments_get(sub, "idd", &level, &horizontal, &vertical); 242 edbus_message_iter_arguments_get(sub, "idd", &level, &horizontal, &vertical);
245 pos->accur->level = level; 243 pos_geocode->accur->level = level;
246 pos->accur->horizontal = horizontal; 244 pos_geocode->accur->horizontal = horizontal;
247 pos->accur->vertical = vertical; 245 pos_geocode->accur->vertical = vertical;
246 ecore_event_add(ELOCATION_EVENT_GEOCODE, pos_geocode, _dummy_free, NULL);
248} 247}
249 248
250static Eina_Bool 249static Eina_Bool
@@ -931,6 +930,18 @@ elocation_init()
931 address_provider = calloc(1, sizeof(Elocation_Provider)); 930 address_provider = calloc(1, sizeof(Elocation_Provider));
932 position_provider = calloc(1, sizeof(Elocation_Provider)); 931 position_provider = calloc(1, sizeof(Elocation_Provider));
933 932
933 addr_geocode = calloc(1, sizeof(Elocation_Address));
934 if (!addr_geocode) return EINA_FALSE;
935
936 addr_geocode->accur = calloc(1, sizeof(Elocation_Accuracy));
937 if (!addr_geocode->accur) return EINA_FALSE;
938
939 pos_geocode = calloc(1, sizeof(Elocation_Position));
940 if (!pos_geocode) return EINA_FALSE;
941
942 pos_geocode->accur = calloc(1, sizeof(Elocation_Position));
943 if (!pos_geocode->accur) return EINA_FALSE;
944
934 conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION); 945 conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
935 if (!conn) 946 if (!conn)
936 { 947 {
@@ -956,6 +967,12 @@ elocation_init()
956 if (ELOCATION_EVENT_VELOCITY == 0) 967 if (ELOCATION_EVENT_VELOCITY == 0)
957 ELOCATION_EVENT_VELOCITY = ecore_event_type_new(); 968 ELOCATION_EVENT_VELOCITY = ecore_event_type_new();
958 969
970 if (ELOCATION_EVENT_GEOCODE == 0)
971 ELOCATION_EVENT_GEOCODE = ecore_event_type_new();
972
973 if (ELOCATION_EVENT_REVERSEGEOCODE == 0)
974 ELOCATION_EVENT_REVERSEGEOCODE = ecore_event_type_new();
975
959 obj_master= edbus_object_get(conn, GEOCLUE_DBUS_NAME, GEOCLUE_OBJECT_PATH); 976 obj_master= edbus_object_get(conn, GEOCLUE_DBUS_NAME, GEOCLUE_OBJECT_PATH);
960 if (!obj_master) 977 if (!obj_master)
961 { 978 {
@@ -1034,6 +1051,11 @@ elocation_shutdown()
1034 free(position_provider->path); 1051 free(position_provider->path);
1035 free(position_provider); 1052 free(position_provider);
1036 1053
1054 free(pos_geocode->accur);
1055 free(pos_geocode);
1056 free(addr_geocode->accur);
1057 free(addr_geocode);
1058
1037 edbus_name_owner_changed_callback_del(conn, GEOCLUE_DBUS_NAME, _name_owner_changed, NULL); 1059 edbus_name_owner_changed_callback_del(conn, GEOCLUE_DBUS_NAME, _name_owner_changed, NULL);
1038 edbus_connection_unref(conn); 1060 edbus_connection_unref(conn);
1039 edbus_shutdown(); 1061 edbus_shutdown();