merge with master
[platform/core/api/location-manager.git] / src / locations.c
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <locations_private.h>
21 #include <location_bounds.h>
22
23
24 #define LOCATIONS_NULL_ARG_CHECK(arg)   \
25         LOCATIONS_CHECK_CONDITION((arg != NULL),LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER") \
26
27 /*
28 * Internal Implementation
29 */
30
31 static int __convert_error_code(int code)
32 {
33         int ret;
34         char *msg = "LOCATIONS_ERROR_NONE";
35         switch (code) {
36         case LOCATION_ERROR_NONE:
37                 ret = LOCATIONS_ERROR_NONE;
38                 msg = "LOCATIONS_ERROR_NONE";
39                 break;
40         case LOCATION_ERROR_NETWORK_FAILED:
41         case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
42                 ret = LOCATIONS_ERROR_NETWORK_FAILED;
43                 msg = "LOCATIONS_ERROR_NETWORK_FAILED";
44                 break;
45         case LOCATION_ERROR_NOT_ALLOWED:
46                 ret = LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
47                 msg = "LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED";
48                 break;
49         case LOCATION_ERROR_SETTING_OFF:
50                 ret = LOCATIONS_ERROR_GPS_SETTING_OFF;
51                 msg = "LOCATIONS_ERROR_GPS_SETTING_OFF";
52                 break;
53         case LOCATION_ERROR_SECURITY_DENIED:
54                 ret = LOCATIONS_ERROR_SECURITY_RESTRICTED;
55                 msg = "LOCATIONS_ERROR_SECURITY_RESTRICTED";
56                 break;
57         case LOCATION_ERROR_NOT_AVAILABLE:
58         case LOCATION_ERROR_CONFIGURATION:
59         case LOCATION_ERROR_PARAMETER:
60         case LOCATION_ERROR_UNKNOWN:
61         default:
62                 msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE";
63                 ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
64         }
65         LOCATIONS_LOGE("%s(0x%08x) : core fw error(0x%x)", msg, ret, code);
66         return ret;
67 }
68
69 static void __cb_service_updated(GObject * self, guint type, gpointer data, gpointer accuracy, gpointer userdata)
70 {
71         LOCATIONS_LOGI("Callback function has been invoked. ");
72         location_manager_s *handle = (location_manager_s *) userdata;
73         if (type == VELOCITY_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) {
74                 LocationVelocity *vel = (LocationVelocity *) data;
75                 LOCATIONS_LOGI("Current velocity: timestamp : %d, speed: %f, direction : %f, climb : %f",
76                      vel->timestamp, vel->speed, vel->direction, vel->climb);
77                 ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) (vel->speed, vel->direction,
78                                                                                                   vel->climb, vel->timestamp,
79                                                                                                   handle->user_data
80                                                                                                   [_LOCATIONS_EVENT_TYPE_VELOCITY]);
81         }
82         else if (type == POSITION_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) {
83                 LocationPosition *pos = (LocationPosition *) data;
84                 LOCATIONS_LOGI("Current position: timestamp : %d, latitude : %f, altitude: %f, longitude: %f",
85                      pos->timestamp, pos->latitude, pos->altitude, pos->longitude);
86                 ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) (pos->latitude, pos->longitude,
87                                                                                                   pos->altitude, pos->timestamp,
88                                                                                                   handle->user_data
89                                                                                                   [_LOCATIONS_EVENT_TYPE_POSITION]);
90         }
91         else if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
92                 LocationSatellite *sat = (LocationSatellite *)data;
93                 LOCATIONS_LOGI("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
94                      sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
95                 ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) (sat->num_of_sat_used, sat->num_of_sat_inview,
96                                                                                                  sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
97         }
98 }
99
100 static void __cb_service_enabled(GObject * self, guint status, gpointer userdata)
101 {
102         LOCATIONS_LOGI("Callback function has been invoked. ");
103         location_manager_s *handle = (location_manager_s *) userdata;
104         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
105                 ((location_service_state_changed_cb)
106                  handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) (LOCATIONS_SERVICE_ENABLED,
107                                                                         handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
108         }
109 }
110
111 static void __cb_service_disabled(GObject * self, guint status, gpointer userdata)
112 {
113         LOCATIONS_LOGI("Callback function has been invoked. ");
114         location_manager_s *handle = (location_manager_s *) userdata;
115         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
116                 ((location_service_state_changed_cb)
117                  handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) (LOCATIONS_SERVICE_DISABLED,
118                                                                         handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
119 }
120
121 static int __compare_position (gconstpointer a, gconstpointer b)
122 {
123         if(location_position_equal((LocationPosition*) a, (LocationPosition *)b) == TRUE) {
124                 return 0;
125         }
126
127         return -1;
128 }
129
130 static int __boundary_compare(LocationBoundary * bound1, LocationBoundary * bound2)
131 {
132         int ret = -1;
133
134         if (bound1->type == bound2->type) {
135                 switch (bound1->type) {
136                 case LOCATION_BOUNDARY_CIRCLE:
137                         if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) {
138                                 ret = 0;
139                         }
140                         break;
141                 case LOCATION_BOUNDARY_RECT:
142                         if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) {
143                                 ret = 0;
144                         }
145                         break;
146                 case LOCATION_BOUNDARY_POLYGON: {
147                         GList *boundary1_next = NULL;
148                         GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
149                         if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) {
150                                 return -1;
151                         }
152
153                         boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
154                         if (boundary2_start == NULL) return -1;
155
156                         boundary2_prev = g_list_previous(boundary2_start);
157                         boundary2_next = g_list_next(boundary2_start);
158
159                         if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
160                         if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
161
162                         boundary1_next = g_list_next(bound1->polygon.position_list);
163                         if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_prev->data) == TRUE) {
164                                 boundary1_next = g_list_next(boundary1_next);
165                                 while (boundary1_next) {
166                                         boundary2_prev = g_list_previous(boundary2_prev);
167                                         if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
168                                         if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_prev->data) == FALSE) {
169                                                 return -1;
170                                         }
171                                         boundary1_next = g_list_next(boundary1_next);
172                                 }
173                                 ret = 0;
174                         } else if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_next->data) == TRUE) {
175                                 boundary1_next = g_list_next(boundary1_next);
176                                 while(boundary1_next) {
177                                         boundary2_next = g_list_next(boundary2_next);
178                                         if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
179                                         if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_next->data) == FALSE) {
180                                                 return -1;
181                                         }
182                                         boundary1_next = g_list_next(boundary1_next);
183                                 }
184                                 ret = 0;
185                         } else {
186                                 return -1;
187                         }
188                         break;
189                 }
190                 default:
191                         break;
192                 }
193         }
194         return ret;
195 }
196
197 static void __cb_zone_in(GObject * self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
198 {
199         LOCATIONS_LOGI("Callback function has been invoked.");
200         location_manager_s *handle = (location_manager_s *) userdata;
201         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
202                 LocationPosition *pos = (LocationPosition *) position;
203                 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) (LOCATIONS_BOUNDARY_IN,
204                                                                                               pos->latitude, pos->longitude,
205                                                                                               pos->altitude, pos->timestamp,
206                                                                                               handle->user_data
207                                                                                               [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
208         }
209
210         location_bounds_s *bounds;
211         GList *bounds_list = g_list_first(handle->bounds_list);
212         while (bounds_list) {
213                 bounds = (location_bounds_s *)bounds_list->data;
214                 if (__boundary_compare(boundary, bounds->boundary) == 0) {
215                         LOCATIONS_LOGI("Find zone in boundary");
216                         ((location_bounds_state_changed_cb) bounds->user_cb) (LOCATIONS_BOUNDARY_IN, bounds->user_data);
217                         break;
218                 }
219                 bounds_list = g_list_next(bounds_list);
220         }
221 }
222
223 static void __cb_zone_out(GObject * self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
224 {
225         LOCATIONS_LOGI("Callback function has been invoked.");
226         location_manager_s *handle = (location_manager_s *) userdata;
227         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
228                 LocationPosition *pos = (LocationPosition *) position;
229                 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) (LOCATIONS_BOUNDARY_OUT,
230                                                                                               pos->latitude, pos->longitude,
231                                                                                               pos->altitude, pos->timestamp,
232                                                                                               handle->user_data
233                                                                                               [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
234         }
235
236         location_bounds_s *bounds;
237         GList *bounds_list = g_list_first(handle->bounds_list);
238         while (bounds_list) {
239                 bounds = (location_bounds_s *)bounds_list->data;
240                 if (__boundary_compare(boundary, bounds->boundary) == 0) {
241                         LOCATIONS_LOGI("Find zone out boundary");
242                         ((location_bounds_state_changed_cb) bounds->user_cb) (LOCATIONS_BOUNDARY_OUT, bounds->user_data);
243                         break;
244                 }
245                 bounds_list = g_list_next(bounds_list);
246         }
247 }
248
249 static int __set_callback(_location_event_e type, location_manager_h manager, void *callback, void *user_data)
250 {
251         LOCATIONS_NULL_ARG_CHECK(manager);
252         LOCATIONS_NULL_ARG_CHECK(callback);
253         location_manager_s *handle = (location_manager_s *) manager;
254         handle->user_cb[type] = callback;
255         handle->user_data[type] = user_data;
256         LOCATIONS_LOGI("event type : %d. ", type);
257         return LOCATIONS_ERROR_NONE;
258 }
259
260 static int __unset_callback(_location_event_e type, location_manager_h manager)
261 {
262         LOCATIONS_NULL_ARG_CHECK(manager);
263         location_manager_s *handle = (location_manager_s *) manager;
264         handle->user_cb[type] = NULL;
265         handle->user_data[type] = NULL;
266         LOCATIONS_LOGI("event type : %d. ", type);
267         return LOCATIONS_ERROR_NONE;
268 }
269
270 static void __foreach_boundary(LocationBoundary * boundary, void *user_data)
271 {
272         location_manager_s *handle = (location_manager_s *) user_data;
273
274         if (handle != NULL && boundary != NULL) {
275                 int ret = -1;
276                 location_bounds_h bounds;
277                 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
278                         location_coords_s center;
279                         center.latitude = boundary->circle.center->latitude;
280                         center.longitude = boundary->circle.center->longitude;
281                         ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
282                 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
283                         location_coords_s left_top;
284                         location_coords_s right_bottom;
285                         left_top.latitude = boundary->rect.left_top->latitude;
286                         left_top.longitude = boundary->rect.left_top->longitude;
287                         right_bottom.latitude = boundary->rect.right_bottom->latitude;
288                         right_bottom.longitude = boundary->rect.right_bottom->longitude;
289                         ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
290                 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
291                         GList *list = boundary->polygon.position_list;
292                         int size = g_list_length(list);
293                         if (size > 0) {
294                                 location_coords_s coords[size];
295                                 int cnt = 0;
296                                 while (list) {
297                                         LocationPosition *pos = list->data;
298                                         coords[cnt].latitude = pos->latitude;
299                                         coords[cnt].longitude = pos->longitude;
300                                         list = g_list_next(list);
301                                         cnt++;
302                                 }
303                                 ret = location_bounds_create_polygon(coords, size, &bounds);
304                         }
305                 } else {
306                         LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
307                 }
308
309                 if (ret != LOCATIONS_ERROR_NONE) {
310                         LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
311                 } else {
312                         if (handle->is_continue_foreach_bounds) {
313                                 handle->is_continue_foreach_bounds =
314                                     ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]) (bounds,
315                                                                                                                   handle->
316                                                                                                                   user_data
317                                                                                                                   [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
318                         }
319                         location_bounds_destroy(bounds);
320                 }
321         } else {
322                 LOCATIONS_LOGI("__foreach_boundary() has been failed");
323         }
324 }
325
326 /////////////////////////////////////////
327 // Location Manager
328 ////////////////////////////////////////
329
330 /*
331 * Public Implementation
332 */
333
334 bool location_manager_is_supported_method(location_method_e method)
335 {
336         LocationMethod _method = LOCATION_METHOD_NONE;
337         switch (method) {
338         case LOCATIONS_METHOD_HYBRID:
339                 _method = LOCATION_METHOD_HYBRID;
340                 break;
341         case LOCATIONS_METHOD_GPS:
342                 _method = LOCATION_METHOD_GPS;
343                 break;
344         case LOCATIONS_METHOD_WPS:
345                 _method = LOCATION_METHOD_WPS;
346                 break;
347         case LOCATIONS_METHOD_CPS:
348                 _method = LOCATION_METHOD_CPS;
349                 break;
350         default:
351                 _method = LOCATION_METHOD_NONE;
352                 break;
353         }
354         return location_is_supported_method(_method);
355 }
356
357 int location_manager_create(location_method_e method, location_manager_h * manager)
358 {
359         LOCATIONS_NULL_ARG_CHECK(manager);
360         if (location_init() != LOCATION_ERROR_NONE)
361                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
362
363         LocationMethod _method = LOCATION_METHOD_NONE;
364         switch (method) {
365         case LOCATIONS_METHOD_HYBRID:
366                 _method = LOCATION_METHOD_HYBRID;
367                 break;
368         case LOCATIONS_METHOD_GPS:
369                 _method = LOCATION_METHOD_GPS;
370                 break;
371         case LOCATIONS_METHOD_WPS:
372                 _method = LOCATION_METHOD_WPS;
373                 break;
374         case LOCATIONS_METHOD_CPS:
375                 _method = LOCATION_METHOD_CPS;
376                 break;
377         case LOCATIONS_METHOD_NONE:
378                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
379         default:
380                 {
381                         LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
382                              LOCATIONS_ERROR_INVALID_PARAMETER, method);
383                         return LOCATIONS_ERROR_INVALID_PARAMETER;
384                 }
385         }
386
387         location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
388         if (handle == NULL) {
389                 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
390                 return LOCATIONS_ERROR_OUT_OF_MEMORY;
391         }
392
393         memset(handle, 0, sizeof(location_manager_s));
394
395         handle->object = location_new(_method);
396         if (handle->object == NULL) {
397                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new",
398                      LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
399                 free(handle);
400                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
401         }
402         handle->method = method;
403         handle->is_continue_foreach_bounds = TRUE;
404         handle->bounds_list = NULL;
405
406         handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
407         handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
408
409         *manager = (location_manager_h) handle;
410         return LOCATIONS_ERROR_NONE;
411 }
412
413 int location_manager_destroy(location_manager_h manager)
414 {
415         LOCATIONS_NULL_ARG_CHECK(manager);
416         location_manager_s *handle = (location_manager_s *) manager;
417
418         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
419         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
420
421         int ret = location_free(handle->object);
422         if (ret != LOCATIONS_ERROR_NONE) {
423                 return __convert_error_code(ret);
424         }
425         free(handle);
426         return LOCATIONS_ERROR_NONE;
427 }
428
429 int location_manager_start(location_manager_h manager)
430 {
431         LOCATIONS_NULL_ARG_CHECK(manager);
432         location_manager_s *handle = (location_manager_s *) manager;
433
434         handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
435         handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
436         handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
437
438         int ret = location_start(handle->object);
439         if (ret != LOCATION_ERROR_NONE) {
440                 return __convert_error_code(ret);
441         }
442         return LOCATIONS_ERROR_NONE;
443 }
444
445 int location_manager_stop(location_manager_h manager)
446 {
447         LOCATIONS_NULL_ARG_CHECK(manager);
448         location_manager_s *handle = (location_manager_s *) manager;
449
450         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
451         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
452         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
453
454         int ret = location_stop(handle->object);
455         if (ret != LOCATION_ERROR_NONE) {
456                 return __convert_error_code(ret);
457         }
458         return LOCATIONS_ERROR_NONE;
459 }
460
461 int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
462 {
463         LOCATIONS_NULL_ARG_CHECK(manager);
464         LOCATIONS_NULL_ARG_CHECK(bounds);
465
466         location_manager_s *handle = (location_manager_s *) manager;
467         location_bounds_s *bound_handle = (location_bounds_s *) bounds;
468         int ret = location_boundary_add(handle->object, bound_handle->boundary);
469         if (ret != LOCATION_ERROR_NONE) {
470                 return __convert_error_code(ret);
471         }
472         bound_handle->is_added = TRUE;
473         handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
474         return LOCATIONS_ERROR_NONE;
475 }
476
477 int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
478 {
479         LOCATIONS_NULL_ARG_CHECK(manager);
480         LOCATIONS_NULL_ARG_CHECK(bounds);
481
482         location_manager_s *handle = (location_manager_s *) manager;
483         location_bounds_s *bound_handle = (location_bounds_s *) bounds;
484         int ret = location_boundary_remove(handle->object, bound_handle->boundary);
485         if (ret != LOCATION_ERROR_NONE) {
486                 return __convert_error_code(ret);
487         }
488         handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
489         bound_handle->is_added = FALSE;
490         return LOCATIONS_ERROR_NONE;
491 }
492
493 int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
494 {
495         LOCATIONS_NULL_ARG_CHECK(manager);
496         LOCATIONS_NULL_ARG_CHECK(callback);
497
498         location_manager_s *handle = (location_manager_s *) manager;
499         handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
500         handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
501         handle->is_continue_foreach_bounds = TRUE;
502         int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
503         if (ret != LOCATION_ERROR_NONE) {
504                 return __convert_error_code(ret);
505         }
506         return LOCATIONS_ERROR_NONE;
507 }
508
509 int location_manager_get_method(location_manager_h manager, location_method_e * method)
510 {
511         LOCATIONS_NULL_ARG_CHECK(manager);
512         LOCATIONS_NULL_ARG_CHECK(method);
513         location_manager_s *handle = (location_manager_s *) manager;
514         LocationMethod _method = LOCATION_METHOD_NONE;
515         g_object_get(handle->object, "method", &_method, NULL);
516         switch (_method) {
517         case LOCATION_METHOD_NONE:
518                 *method = LOCATIONS_METHOD_NONE;
519                 break;
520         case LOCATION_METHOD_HYBRID:
521                 *method = LOCATIONS_METHOD_HYBRID;
522                 break;
523         case LOCATION_METHOD_GPS:
524                 *method = LOCATIONS_METHOD_GPS;
525                 break;
526         case LOCATION_METHOD_WPS:
527                 *method = LOCATIONS_METHOD_WPS;
528                 break;
529         case LOCATION_METHOD_CPS:
530                 *method = LOCATIONS_METHOD_CPS;
531                 break;
532         default:
533                 {
534                         LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
535                              LOCATIONS_ERROR_INVALID_PARAMETER, method);
536                         return LOCATIONS_ERROR_INVALID_PARAMETER;
537                 }
538         }
539         //*method = handle->method;
540         return LOCATIONS_ERROR_NONE;
541 }
542
543 int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
544                                   time_t * timestamp)
545 {
546         LOCATIONS_NULL_ARG_CHECK(manager);
547         LOCATIONS_NULL_ARG_CHECK(altitude);
548         LOCATIONS_NULL_ARG_CHECK(latitude);
549         LOCATIONS_NULL_ARG_CHECK(longitude);
550         LOCATIONS_NULL_ARG_CHECK(timestamp);
551
552         location_manager_s *handle = (location_manager_s *) manager;
553         int ret;
554         LocationPosition *pos = NULL;
555         LocationAccuracy *acc = NULL;
556         ret = location_get_position(handle->object, &pos, &acc);
557         if (ret != LOCATION_ERROR_NONE) {
558                 return __convert_error_code(ret);
559         }
560
561         if (pos->status == LOCATION_STATUS_NO_FIX) {
562                 *altitude = -1;
563                 *latitude = -1;
564                 *longitude = -1;
565         } else {
566                 if (pos->status == LOCATION_STATUS_3D_FIX) {
567                         *altitude = pos->altitude;
568                 } else {
569                         *altitude = -1;
570                 }
571                 *latitude = pos->latitude;
572                 *longitude = pos->longitude;
573         }
574         *timestamp = pos->timestamp;
575         location_position_free(pos);
576         location_accuracy_free(acc);
577         return LOCATIONS_ERROR_NONE;
578 }
579
580 int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp)
581 {
582         LOCATIONS_NULL_ARG_CHECK(manager);
583         LOCATIONS_NULL_ARG_CHECK(climb);
584         LOCATIONS_NULL_ARG_CHECK(direction);
585         LOCATIONS_NULL_ARG_CHECK(speed);
586         LOCATIONS_NULL_ARG_CHECK(timestamp);
587
588         location_manager_s *handle = (location_manager_s *) manager;
589         int ret;
590         LocationVelocity *vel = NULL;
591         LocationAccuracy *acc = NULL;
592         ret = location_get_velocity(handle->object, &vel, &acc);
593         if (ret != LOCATION_ERROR_NONE) {
594                 return __convert_error_code(ret);
595         }
596
597         *climb = vel->climb;
598         *direction = vel->direction;
599         *speed = vel->speed;
600         *timestamp = vel->timestamp;
601         location_velocity_free(vel);
602         location_accuracy_free(acc);
603         return LOCATIONS_ERROR_NONE;
604 }
605
606 int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal,
607                                   double *vertical)
608 {
609         LOCATIONS_NULL_ARG_CHECK(manager);
610         LOCATIONS_NULL_ARG_CHECK(level);
611         LOCATIONS_NULL_ARG_CHECK(horizontal);
612         LOCATIONS_NULL_ARG_CHECK(vertical);
613         location_manager_s *handle = (location_manager_s *) manager;
614
615         int ret;
616         LocationPosition *pos = NULL;
617         LocationAccuracy *acc = NULL;
618         ret = location_get_position(handle->object, &pos, &acc);
619         if (ret != LOCATION_ERROR_NONE) {
620                 return __convert_error_code(ret);
621         }
622
623         if (acc == NULL) {
624                 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
625         }
626
627         *level = acc->level;
628         *horizontal = acc->horizontal_accuracy;
629         *vertical = acc->vertical_accuracy;
630         location_position_free(pos);
631         location_accuracy_free(acc);
632         return LOCATIONS_ERROR_NONE;
633 }
634
635 int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
636                                        time_t * timestamp)
637 {
638         LOCATIONS_NULL_ARG_CHECK(manager);
639         LOCATIONS_NULL_ARG_CHECK(altitude);
640         LOCATIONS_NULL_ARG_CHECK(latitude);
641         LOCATIONS_NULL_ARG_CHECK(longitude);
642         LOCATIONS_NULL_ARG_CHECK(timestamp);
643
644         location_manager_s *handle = (location_manager_s *) manager;
645
646         int ret;
647         LocationPosition *last_pos = NULL;
648         LocationAccuracy *last_acc = NULL;
649         ret = location_get_last_position(handle->object, &last_pos, &last_acc);
650         if (ret != LOCATION_ERROR_NONE) {
651                 return __convert_error_code(ret);
652         }
653
654         if (last_pos->status == LOCATION_STATUS_NO_FIX) {
655                 *altitude = -1;
656                 *latitude = -1;
657                 *longitude = -1;
658         } else {
659                 if (last_pos->status == LOCATION_STATUS_3D_FIX) {
660                         *altitude = last_pos->altitude;
661                 } else {
662                         *altitude = -1;
663                 }
664                 *latitude = last_pos->latitude;
665                 *longitude = last_pos->longitude;
666         }
667         *timestamp = last_pos->timestamp;
668         location_position_free(last_pos);
669         location_accuracy_free(last_acc);
670         return LOCATIONS_ERROR_NONE;
671 }
672
673 int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp)
674 {
675         LOCATIONS_NULL_ARG_CHECK(manager);
676         LOCATIONS_NULL_ARG_CHECK(climb);
677         LOCATIONS_NULL_ARG_CHECK(direction);
678         LOCATIONS_NULL_ARG_CHECK(speed);
679         LOCATIONS_NULL_ARG_CHECK(timestamp);
680
681         location_manager_s *handle = (location_manager_s *) manager;
682
683         int ret;
684         LocationVelocity *last_vel = NULL;
685         LocationAccuracy *last_acc = NULL;
686         ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
687         if (ret != LOCATION_ERROR_NONE) {
688                 return __convert_error_code(ret);
689         }
690
691         *climb = last_vel->climb;
692         *direction = last_vel->direction;
693         *speed = last_vel->speed;
694         *timestamp = last_vel->timestamp;
695         location_velocity_free(last_vel);
696         location_accuracy_free(last_acc);
697         return LOCATIONS_ERROR_NONE;
698 }
699
700 int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal,
701                                        double *vertical)
702 {
703         LOCATIONS_NULL_ARG_CHECK(manager);
704         LOCATIONS_NULL_ARG_CHECK(level);
705         LOCATIONS_NULL_ARG_CHECK(horizontal);
706         LOCATIONS_NULL_ARG_CHECK(vertical);
707         location_manager_s *handle = (location_manager_s *) manager;
708
709         int ret;
710         LocationPosition *last_pos = NULL;
711         LocationAccuracy *last_acc = NULL;
712         ret = location_get_last_position(handle->object, &last_pos, &last_acc);
713         if (ret != LOCATION_ERROR_NONE) {
714                 return __convert_error_code(ret);
715         }
716
717         *level = last_acc->level;
718         *horizontal = last_acc->horizontal_accuracy;
719         *vertical = last_acc->vertical_accuracy;
720         location_position_free(last_pos);
721         location_accuracy_free(last_acc);
722         return LOCATIONS_ERROR_NONE;
723 }
724
725 int location_manager_get_accessibility_state(location_accessibility_state_e* state)
726 {
727         LOCATIONS_NULL_ARG_CHECK(state);
728
729         int ret = LOCATION_ERROR_NONE;
730         LocationAccessState auth = LOCATION_ACCESS_NONE;
731         ret = location_get_accessibility_state (&auth);
732         if (ret != LOCATION_ERROR_NONE) {
733                 *state = LOCATIONS_ACCESS_STATE_NONE;
734                 return __convert_error_code(ret);
735         }
736
737         switch (auth) {
738                 case LOCATION_ACCESS_DENIED:
739                         *state = LOCATIONS_ACCESS_STATE_DENIED;
740                         break;
741                 case LOCATION_ACCESS_ALLOWED:
742                         *state = LOCATIONS_ACCESS_STATE_ALLOWED;
743                         break;
744                 case LOCATION_ACCESS_NONE:
745                 default:
746                         *state = LOCATIONS_ACCESS_STATE_NONE;
747                         break;
748         }
749
750         return LOCATIONS_ERROR_NONE;
751 }
752
753 int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
754 {
755         LOCATIONS_CHECK_CONDITION(interval >= 1
756                                   && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
757         LOCATIONS_NULL_ARG_CHECK(manager);
758         location_manager_s *handle = (location_manager_s *) manager;
759         g_object_set(handle->object, "pos-interval", interval, NULL);
760         return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
761 }
762
763 int location_manager_unset_position_updated_cb(location_manager_h manager)
764 {
765         return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
766 }
767
768 int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
769 {
770         LOCATIONS_CHECK_CONDITION(interval >= 1
771                                   && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
772         LOCATIONS_NULL_ARG_CHECK(manager);
773         location_manager_s *handle = (location_manager_s *) manager;
774         g_object_set(handle->object, "vel-interval", interval, NULL);
775         return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
776 }
777
778 int location_manager_unset_velocity_updated_cb(location_manager_h manager)
779 {
780         return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
781 }
782
783 int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
784                                                   void *user_data)
785 {
786         return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
787 }
788
789 int location_manager_unset_service_state_changed_cb(location_manager_h manager)
790 {
791         return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
792 }
793
794 int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
795 {
796         return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
797 }
798
799 int location_manager_unset_zone_changed_cb(location_manager_h manager)
800 {
801         return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
802 }
803
804 int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
805 {
806         LOCATIONS_NULL_ARG_CHECK(distance);
807         LOCATIONS_CHECK_CONDITION(start_latitude>=-90 && start_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
808         LOCATIONS_CHECK_CONDITION(start_longitude>=-180 && start_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
809         LOCATIONS_CHECK_CONDITION(end_latitude>=-90 && end_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
810         LOCATIONS_CHECK_CONDITION(end_longitude>=-180 && end_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
811
812         int ret = LOCATION_ERROR_NONE;
813         ulong u_distance;
814
815         LocationPosition *start = location_position_new (0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
816         LocationPosition *end = location_position_new (0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
817
818         ret = location_get_distance (start, end, &u_distance);
819         if (ret != LOCATION_ERROR_NONE) {
820                 return __convert_error_code(ret);
821         }
822
823         *distance = (double)u_distance;
824
825         return LOCATIONS_ERROR_NONE;
826 }
827
828 int location_manager_send_command(const char *cmd)
829 {
830         LOCATIONS_NULL_ARG_CHECK(cmd);
831
832         int ret;
833         ret = location_send_command(cmd);
834         if (ret != LOCATION_ERROR_NONE) {
835                 return __convert_error_code(ret);
836         }
837
838         return LOCATIONS_ERROR_NONE;
839 }
840
841 /////////////////////////////////////////
842 // GPS Status & Satellites
843 ////////////////////////////////////////
844
845 int gps_status_get_nmea(location_manager_h manager, char **nmea)
846 {
847         LOCATIONS_NULL_ARG_CHECK(manager);
848         LOCATIONS_NULL_ARG_CHECK(nmea);
849         location_manager_s *handle = (location_manager_s *) manager;
850
851         if (handle->method == LOCATIONS_METHOD_HYBRID) {
852                 LocationMethod _method = LOCATION_METHOD_NONE;
853                 g_object_get(handle->object, "method", &_method, NULL);
854                 if (_method != LOCATION_METHOD_GPS) {
855                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
856                              LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
857                         return LOCATIONS_ERROR_INCORRECT_METHOD;
858                 }
859         } else if (handle->method != LOCATIONS_METHOD_GPS) {
860                 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
861                      LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
862                 return LOCATIONS_ERROR_INCORRECT_METHOD;
863         }
864         gchar *nmea_data = NULL;
865         g_object_get(handle->object, "nmea", &nmea_data, NULL);
866         if (nmea_data == NULL) {
867                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : nmea data is NULL ",
868                      LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
869                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
870         }
871         *nmea = NULL;
872         *nmea = strdup(nmea_data);
873         if (*nmea == NULL) {
874                 LOCATIONS_LOGE("LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to strdup ",
875                      LOCATIONS_ERROR_OUT_OF_MEMORY);
876                 return LOCATIONS_ERROR_OUT_OF_MEMORY;
877         }
878         g_free(nmea_data);
879         return LOCATIONS_ERROR_NONE;
880 }
881
882 int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
883 {
884         LOCATIONS_NULL_ARG_CHECK(manager);
885         LOCATIONS_NULL_ARG_CHECK(num_of_active);
886         LOCATIONS_NULL_ARG_CHECK(num_of_inview);
887         LOCATIONS_NULL_ARG_CHECK(timestamp);
888         location_manager_s *handle = (location_manager_s *) manager;
889         LocationSatellite *sat = NULL;
890         int ret = location_get_satellite (handle->object, &sat);
891         if (ret != LOCATION_ERROR_NONE || sat == NULL) {
892                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
893                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
894                              LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
895                         return LOCATIONS_ERROR_INCORRECT_METHOD;
896                 }
897
898                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
899                      LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
900                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
901         }
902
903         *num_of_active = sat->num_of_sat_used;
904         *num_of_inview = sat->num_of_sat_inview;
905         *timestamp = sat->timestamp;
906         location_satellite_free(sat);
907         sat = NULL;
908         return LOCATIONS_ERROR_NONE;
909 }
910
911 int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
912 {
913         LOCATIONS_CHECK_CONDITION(interval >= 1
914                                   && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
915         LOCATIONS_NULL_ARG_CHECK(manager);
916         location_manager_s *handle = (location_manager_s *) manager;
917         g_object_set(handle->object, "sat-interval", interval, NULL);
918         return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
919 }
920
921 int gps_status_unset_satellite_updated_cb(location_manager_h manager)
922 {
923         return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
924 }
925
926
927 int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
928 {
929         LOCATIONS_NULL_ARG_CHECK(manager);
930         LOCATIONS_NULL_ARG_CHECK(callback);
931         location_manager_s *handle = (location_manager_s *) manager;
932         LocationSatellite *sat = NULL;
933         int ret = location_get_satellite (handle->object, &sat);
934         if (ret != LOCATION_ERROR_NONE || sat == NULL) {
935                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
936                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
937                              LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
938                         return LOCATIONS_ERROR_INCORRECT_METHOD;
939                 }
940
941                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
942                      LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
943                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
944         }
945
946         int i;
947         for (i = 0; i < sat->num_of_sat_inview; i++) {
948                 guint prn;
949                 gboolean used;
950                 guint elevation;
951                 guint azimuth;
952                 gint snr;
953                 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
954                 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
955                         break;
956         }
957         location_satellite_free(sat);
958         sat = NULL;
959         return LOCATIONS_ERROR_NONE;
960 }
961
962 int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
963 {
964         LOCATIONS_NULL_ARG_CHECK(manager);
965         LOCATIONS_NULL_ARG_CHECK(num_of_active);
966         LOCATIONS_NULL_ARG_CHECK(num_of_inview);
967         LOCATIONS_NULL_ARG_CHECK(timestamp);
968         location_manager_s *handle = (location_manager_s *) manager;
969         int ret = LOCATION_ERROR_NONE;
970         LocationSatellite *last_sat = NULL;
971         ret = location_get_last_satellite(handle->object, &last_sat);
972         if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
973                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
974                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
975                              LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
976                         return LOCATIONS_ERROR_INCORRECT_METHOD;
977                 }
978
979                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
980                      LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
981                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
982         }
983
984         *num_of_active = last_sat->num_of_sat_used;
985         *num_of_inview = last_sat->num_of_sat_inview;
986         *timestamp = last_sat->timestamp;
987         location_satellite_free(last_sat);
988         return LOCATIONS_ERROR_NONE;
989 }
990
991 int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback,
992                                                void *user_data)
993 {
994         LOCATIONS_NULL_ARG_CHECK(manager);
995         LOCATIONS_NULL_ARG_CHECK(callback);
996         location_manager_s *handle = (location_manager_s *) manager;
997         int ret;
998         LocationSatellite *last_sat = NULL;
999         ret = location_get_last_satellite(handle->object, &last_sat);
1000         if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1001                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1002                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
1003                              LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1004                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1005                 }
1006
1007                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
1008                      LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1009                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1010         }
1011
1012         int i;
1013         for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1014                 guint prn;
1015                 gboolean used;
1016                 guint elevation;
1017                 guint azimuth;
1018                 gint snr;
1019                 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1020                 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
1021                         break;
1022                 }
1023         }
1024         location_satellite_free(last_sat);
1025         return LOCATIONS_ERROR_NONE;
1026 }