[TSAM-639] Applied Tizen 3.0 coding rule
[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 <system_info.h>
21 #include "locations.h"
22 #include "location_internal.h"
23
24 static location_setting_changed_s g_location_setting[LOCATIONS_METHOD_WPS + 1];
25
26 static location_method_e __convert_location_method_e(LocationMethod method)
27 {
28         location_method_e _method = LOCATIONS_METHOD_NONE;
29         switch (method) {
30                 case LOCATION_METHOD_HYBRID:
31                         _method = LOCATIONS_METHOD_HYBRID;
32                         break;
33                 case LOCATION_METHOD_GPS:
34                         _method = LOCATIONS_METHOD_GPS;
35                         break;
36                 case LOCATION_METHOD_WPS:
37                         _method = LOCATIONS_METHOD_WPS;
38                         break;
39                 case LOCATION_METHOD_NONE:
40                 default:
41                         break;
42         }
43         return _method;
44 }
45
46 static LocationMethod __convert_LocationMethod(location_method_e method)
47 {
48         LocationMethod _method = LOCATION_METHOD_NONE;
49         switch (method) {
50                 case LOCATIONS_METHOD_HYBRID:
51                         _method = LOCATION_METHOD_HYBRID;
52                         break;
53                 case LOCATIONS_METHOD_GPS:
54                         _method = LOCATION_METHOD_GPS;
55                         break;
56                 case LOCATIONS_METHOD_WPS:
57                         _method = LOCATION_METHOD_WPS;
58                         break;
59                 case LOCATIONS_METHOD_NONE:
60                 default:
61                         _method = LOCATION_METHOD_NONE;
62                         break;
63         }
64         return _method;
65 }
66
67 static void __cb_service_updated(GObject *self, guint type, gpointer data, gpointer velocity, gpointer accuracy, gpointer userdata)
68 {
69         LOCATIONS_LOGD("Callback function has been invoked. ");
70         location_manager_s *handle = (location_manager_s *) userdata;
71
72         if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
73                 LocationSatellite *sat = (LocationSatellite *)data;
74                 LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
75                                                 sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
76                 ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE])(sat->num_of_sat_used, sat->num_of_sat_inview,
77                                 sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
78         } else if (type == DISTANCE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE]) {
79                 LocationPosition *pos = (LocationPosition *) data;
80                 LocationVelocity *vel = (LocationVelocity *) velocity;  /* current velocity */
81                 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(0, pos->latitude, pos->longitude, pos->altitude,
82                                                                                                                                                                 vel->speed, vel->direction, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
83         } else {
84
85                 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION] && (type & POSITION_UPDATED) != 0) {
86                         LocationPosition *pos = (LocationPosition *) data;
87                         ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude, pos->altitude, pos->timestamp,
88                                         handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
89                 }
90
91                 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY] && (type & VELOCITY_UPDATED) != 0) {
92                         LocationVelocity *vel = (LocationVelocity *) velocity;
93                         ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction, vel->climb, vel->timestamp,
94                                         handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
95                 }
96
97                 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL] && (type & LOCATION_CHANGED) != 0) {
98                         LocationPosition *pos = (LocationPosition *) data;
99                         LocationVelocity *vel = (LocationVelocity *) velocity;
100                         LocationAccuracy *acc = (LocationAccuracy *) accuracy;
101                         ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL])(pos->latitude, pos->longitude, pos->altitude,
102                                                                                                                                                                         vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
103                 }
104         }
105 }
106
107 static void __cb_location_updated(GObject *self, int error, gpointer position, gpointer velocity, gpointer accuracy, gpointer userdata)
108 {
109         LOCATIONS_LOGD("Callback function has been invoked. ");
110         int converted_err = __convert_error_code(error);
111         location_manager_s *handle = (location_manager_s *) userdata;
112         LocationPosition *pos = (LocationPosition *) position;
113         LocationVelocity *vel = (LocationVelocity *) velocity;
114
115         LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp);
116         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
117                 ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION])(converted_err, pos->latitude, pos->longitude, pos->altitude,
118                                                                                                                                                                 pos->timestamp, vel->speed, vel->climb, vel->direction, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
119         }
120 }
121
122 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
123 {
124         LOCATIONS_LOGD("Callback function has been invoked. ");
125         location_manager_s *handle = (location_manager_s *) userdata;
126         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
127                 ((location_service_state_changed_cb)
128                  handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
129         }
130 }
131
132 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
133 {
134         LOCATIONS_LOGD("Callback function has been invoked. ");
135         location_manager_s *handle = (location_manager_s *) userdata;
136         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
137                 ((location_service_state_changed_cb)
138                  handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
139 }
140
141 static int __compare_position(gconstpointer a, gconstpointer b)
142 {
143         if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) {
144                 return 0;
145         }
146
147         return -1;
148 }
149
150 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
151 {
152         int ret = -1;
153
154         if (bound1->type == bound2->type) {
155                 switch (bound1->type) {
156                         case LOCATION_BOUNDARY_CIRCLE:
157                                 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) {
158                                         ret = 0;
159                                 }
160                                 break;
161                         case LOCATION_BOUNDARY_RECT:
162                                 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) {
163                                         ret = 0;
164                                 }
165                                 break;
166                         case LOCATION_BOUNDARY_POLYGON: {
167                                         GList *boundary1_next = NULL;
168                                         GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
169                                         if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) {
170                                                 return -1;
171                                         }
172
173                                         boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
174                                         if (boundary2_start == NULL) return -1;
175
176                                         boundary2_prev = g_list_previous(boundary2_start);
177                                         boundary2_next = g_list_next(boundary2_start);
178
179                                         if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
180                                         if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
181
182                                         boundary1_next = g_list_next(bound1->polygon.position_list);
183                                         if (boundary1_next != NULL && boundary2_prev != NULL &&
184                                                 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
185                                                 boundary1_next = g_list_next(boundary1_next);
186                                                 while (boundary1_next) {
187                                                         boundary2_prev = g_list_previous(boundary2_prev);
188                                                         if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
189                                                         if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) {
190                                                                 return -1;
191                                                         }
192                                                         boundary1_next = g_list_next(boundary1_next);
193                                                 }
194                                                 ret = 0;
195                                         } else if (boundary1_next != NULL && boundary2_next != NULL &&
196                                                                 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
197                                                 boundary1_next = g_list_next(boundary1_next);
198                                                 while (boundary1_next) {
199                                                         boundary2_next = g_list_next(boundary2_next);
200                                                         if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
201                                                         if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) {
202                                                                 return -1;
203                                                         }
204                                                         boundary1_next = g_list_next(boundary1_next);
205                                                 }
206                                                 ret = 0;
207                                         } else {
208                                                 return -1;
209                                         }
210                                         break;
211                                 }
212                         default:
213                                 break;
214                 }
215         }
216         return ret;
217 }
218
219 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
220 {
221         LOCATIONS_LOGD("ENTER >>>");
222         location_manager_s *handle = (location_manager_s *) userdata;
223         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
224                 LocationPosition *pos = (LocationPosition *) position;
225                 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
226                                                                                                                                                                         pos->latitude, pos->longitude,
227                                                                                                                                                                         pos->altitude, pos->timestamp,
228                                                                                                                                                                         handle->user_data
229                                                                                                                                                                         [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
230         }
231
232         location_bounds_s *bounds;
233         GList *bounds_list = g_list_first(handle->bounds_list);
234         while (bounds_list) {
235                 bounds = (location_bounds_s *)bounds_list->data;
236                 if (__boundary_compare(boundary, bounds->boundary) == 0) {
237                         LOCATIONS_LOGD("Find zone in boundary");
238                         if (bounds->user_cb) {
239                                 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
240                         }
241                         break;
242                 }
243                 bounds_list = g_list_next(bounds_list);
244         }
245         LOCATIONS_LOGD("EXIT <<<");
246 }
247
248 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
249 {
250         LOCATIONS_LOGD("ENTER >>>");
251         location_manager_s *handle = (location_manager_s *) userdata;
252         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
253                 LocationPosition *pos = (LocationPosition *) position;
254                 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
255                                                                                                                                                                         pos->latitude, pos->longitude,
256                                                                                                                                                                         pos->altitude, pos->timestamp,
257                                                                                                                                                                         handle->user_data
258                                                                                                                                                                         [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
259         }
260
261         location_bounds_s *bounds;
262         GList *bounds_list = g_list_first(handle->bounds_list);
263         while (bounds_list) {
264                 bounds = (location_bounds_s *)bounds_list->data;
265                 if (__boundary_compare(boundary, bounds->boundary) == 0) {
266                         LOCATIONS_LOGD("Find zone out boundary");
267                         if (bounds->user_cb) {
268                                 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
269                         }
270                         break;
271                 }
272                 bounds_list = g_list_next(bounds_list);
273         }
274         LOCATIONS_LOGD("EXIT <<<");
275 }
276
277 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
278 {
279         location_manager_s *handle = (location_manager_s *) user_data;
280
281         if (handle != NULL && boundary != NULL) {
282                 int ret = -1;
283                 location_bounds_h bounds;
284                 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
285                         location_coords_s center;
286                         center.latitude = boundary->circle.center->latitude;
287                         center.longitude = boundary->circle.center->longitude;
288                         ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
289                 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
290                         location_coords_s left_top;
291                         location_coords_s right_bottom;
292                         left_top.latitude = boundary->rect.left_top->latitude;
293                         left_top.longitude = boundary->rect.left_top->longitude;
294                         right_bottom.latitude = boundary->rect.right_bottom->latitude;
295                         right_bottom.longitude = boundary->rect.right_bottom->longitude;
296                         ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
297                 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
298                         GList *list = boundary->polygon.position_list;
299                         int size = g_list_length(list);
300                         if (size > 0) {
301                                 location_coords_s coords[size];
302                                 int cnt = 0;
303                                 while (list) {
304                                         LocationPosition *pos = list->data;
305                                         coords[cnt].latitude = pos->latitude;
306                                         coords[cnt].longitude = pos->longitude;
307                                         list = g_list_next(list);
308                                         cnt++;
309                                 }
310                                 ret = location_bounds_create_polygon(coords, size, &bounds);
311                         }
312                 } else {
313                         LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
314                 }
315
316                 if (ret != LOCATIONS_ERROR_NONE) {
317                         LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
318                 } else {
319                         if (handle->is_continue_foreach_bounds) {
320                                 handle->is_continue_foreach_bounds =
321                                         ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
322                                                         handle->
323                                                         user_data
324                                                         [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
325                         }
326                         location_bounds_destroy(bounds);
327                 }
328         } else {
329                 LOCATIONS_LOGD("__foreach_boundary() has been failed");
330         }
331 }
332
333 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
334 {
335         LOCATIONS_LOGD("method: [%d]", method);
336         location_method_e _method = __convert_location_method_e(method);
337         location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
338         if (_setting_changed == NULL) {
339                 LOCATIONS_LOGE("Invaild userdata\n");
340                 return;
341         }
342
343         if (_setting_changed[_method].callback != NULL) {
344                 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
345         }
346 }
347
348 /*/////////////////////////////////////// */
349 /* Location Manager */
350 /*////////////////////////////////////// */
351
352 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
353 {
354         LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
355         if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
356                 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
357                 return false;
358         }
359
360         if (method == LOCATIONS_METHOD_GPS) {
361                 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
362                         set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
363                         return false;
364                 }
365         } else if (method == LOCATIONS_METHOD_WPS) {
366                 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
367                         set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
368                         return false;
369                 }
370         }
371
372         LocationMethod _method = __convert_LocationMethod(method);
373         if (_method == LOCATION_METHOD_NONE) {
374                 LOCATIONS_LOGE("Not supported method [%d]", method);
375                 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
376                 return false;
377         }
378
379         set_last_result(LOCATIONS_ERROR_NONE);
380         return location_is_supported_method(_method);
381 }
382
383 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
384 {
385         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
386
387         if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
388                 LOCATIONS_LOGE("Not supported method [%d]", method);
389                 return LOCATIONS_ERROR_INCORRECT_METHOD;
390         }
391
392         LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
393         LOCATIONS_NULL_ARG_CHECK(enable);
394         int is_enabled_val = -1;
395         LocationMethod _method = __convert_LocationMethod(method);
396         int ret = location_is_enabled_method(_method, &is_enabled_val);
397         if (ret != LOCATION_ERROR_NONE) {
398                 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
399                         return LOCATIONS_ERROR_INCORRECT_METHOD;
400                 return __convert_error_code(ret);
401         }
402         if (is_enabled_val == -1) {
403                 return TIZEN_ERROR_PERMISSION_DENIED;
404         }
405
406         *enable = (is_enabled_val == 0) ? FALSE : TRUE;
407         return LOCATIONS_ERROR_NONE;
408 }
409
410 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
411 {
412         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
413
414         if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
415                 LOCATIONS_LOGE("Not supported method [%d]", method);
416                 return LOCATIONS_ERROR_INCORRECT_METHOD;
417         }
418
419         LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
420
421         int ret = 0;
422         if (LOCATIONS_METHOD_HYBRID == method) {
423                 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
424                         ret = location_enable_method(LOCATION_METHOD_GPS, enable);
425                         if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
426                 }
427                 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
428                         ret = location_enable_method(LOCATION_METHOD_WPS, enable);
429                         return __convert_error_code(ret);
430                 }
431                 return LOCATIONS_ERROR_NONE;
432
433         } else {
434                 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
435                         LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
436                         return LOCATIONS_ERROR_NOT_SUPPORTED;
437                 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
438                         LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
439                         return LOCATIONS_ERROR_NOT_SUPPORTED;
440                 }
441
442                 LocationMethod _method = __convert_LocationMethod(method);
443
444                 int ret = location_enable_method(_method, enable);
445
446                 return __convert_error_code(ret);
447         }
448 }
449
450
451 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
452 {
453         LOCATIONS_LOGD("location_manager_create (method : %d)", method);
454
455         if (method == LOCATIONS_METHOD_HYBRID) {
456                 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
457         } else if (method == LOCATIONS_METHOD_GPS) {
458                 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
459                         LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
460                         return LOCATIONS_ERROR_NOT_SUPPORTED;
461                 }
462         } else if (method == LOCATIONS_METHOD_WPS) {
463                 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
464                         LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
465                         return LOCATIONS_ERROR_NOT_SUPPORTED;
466                 }
467         }
468
469         LocationMethod _method = __convert_LocationMethod(method);
470         if (_method == LOCATION_METHOD_NONE) {
471                 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
472                 return LOCATIONS_ERROR_NOT_SUPPORTED;
473         }
474         if (!location_is_supported_method(_method)) {
475                 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
476                 return LOCATIONS_ERROR_NOT_SUPPORTED;
477         }
478
479         /*It is moved here becasue of TCS. */
480         LOCATIONS_NULL_ARG_CHECK(manager);
481
482         if (location_init() != LOCATION_ERROR_NONE) {
483                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
484                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
485         }
486
487         location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
488         if (handle == NULL) {
489                 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
490                 return LOCATIONS_ERROR_OUT_OF_MEMORY;
491         }
492
493         memset(handle, 0, sizeof(location_manager_s));
494
495         handle->object = location_new(_method);
496         if (handle->object == NULL) {
497                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
498                 free(handle);
499                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
500         }
501         handle->method = method;
502         handle->is_continue_foreach_bounds = TRUE;
503         handle->bounds_list = NULL;
504
505         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
506                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
507
508         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
509                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
510
511         *manager = (location_manager_h) handle;
512         return LOCATIONS_ERROR_NONE;
513 }
514
515 EXPORT_API int location_manager_destroy(location_manager_h manager)
516 {
517         LOCATIONS_LOGD("location_manager_destroy");
518         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
519         LOCATIONS_NULL_ARG_CHECK(manager);
520         location_manager_s *handle = (location_manager_s *) manager;
521
522         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
523                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
524                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
525         }
526
527         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
528                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
529                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
530         }
531
532         int ret = location_free(handle->object);
533         if (ret != LOCATIONS_ERROR_NONE) {
534                 return __convert_error_code(ret);
535         }
536         free(handle);
537         return LOCATIONS_ERROR_NONE;
538 }
539
540 EXPORT_API int location_manager_start(location_manager_h manager)
541 {
542         LOCATIONS_LOGD("location_manager_start");
543         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
544         LOCATIONS_NULL_ARG_CHECK(manager);
545         location_manager_s *handle = (location_manager_s *) manager;
546
547         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
548                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
549
550         if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
551                 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
552                         handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
553
554                 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
555                         handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
556         } else {
557                 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
558         }
559
560         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
561                 LOCATIONS_LOGI("Satellite update_cb is set");
562                 location_set_option(handle->object, "USE_SV");
563         }
564
565         int ret = location_start(handle->object);
566         if (ret != LOCATION_ERROR_NONE) {
567                 return __convert_error_code(ret);
568         }
569         return LOCATIONS_ERROR_NONE;
570 }
571
572 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
573 {
574         LOCATIONS_LOGD("location_manager_request_single_location");
575         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
576         LOCATIONS_NULL_ARG_CHECK(manager);
577         LOCATIONS_NULL_ARG_CHECK(callback);
578         if (timeout <= 0 || timeout > 120) {
579                 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
580                 return LOCATIONS_ERROR_INVALID_PARAMETER;
581         }
582
583         location_manager_s *handle = (location_manager_s *) manager;
584         int ret = LOCATIONS_ERROR_NONE;
585
586         if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
587                 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
588
589         ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
590         if (ret != LOCATIONS_ERROR_NONE) {
591                 return ret;
592         }
593
594         ret = location_request_single_location(handle->object, timeout);
595         if (ret != LOCATION_ERROR_NONE) {
596                 return __convert_error_code(ret);
597         }
598         return LOCATIONS_ERROR_NONE;
599 }
600
601 EXPORT_API int location_manager_stop(location_manager_h manager)
602 {
603         LOCATIONS_LOGD("location_manager_stop");
604         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
605         LOCATIONS_NULL_ARG_CHECK(manager);
606
607         location_manager_s *handle = (location_manager_s *) manager;
608
609         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
610                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
611                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
612         }
613
614         if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
615                 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
616                         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
617                         handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
618                 }
619
620                 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
621                         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
622                         handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
623                 }
624         }
625
626         int ret = location_stop(handle->object);
627         if (ret != LOCATION_ERROR_NONE) {
628                 return __convert_error_code(ret);
629         }
630         return LOCATIONS_ERROR_NONE;
631 }
632
633 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
634 {
635         LOCATIONS_LOGD("location_manager_add_boundary");
636         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
637         LOCATIONS_NULL_ARG_CHECK(manager);
638         LOCATIONS_NULL_ARG_CHECK(bounds);
639
640         location_manager_s *handle = (location_manager_s *) manager;
641         location_bounds_s *bound_handle = (location_bounds_s *) bounds;
642         int ret = location_boundary_add(handle->object, bound_handle->boundary);
643         if (ret != LOCATION_ERROR_NONE) {
644                 return __convert_error_code(ret);
645         }
646         bound_handle->is_added = TRUE;
647         handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
648         return LOCATIONS_ERROR_NONE;
649 }
650
651 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
652 {
653         LOCATIONS_LOGD("location_manager_remove_boundary");
654         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
655         LOCATIONS_NULL_ARG_CHECK(manager);
656         LOCATIONS_NULL_ARG_CHECK(bounds);
657
658         location_manager_s *handle = (location_manager_s *) manager;
659         location_bounds_s *bound_handle = (location_bounds_s *) bounds;
660         int ret = location_boundary_remove(handle->object, bound_handle->boundary);
661         if (ret != LOCATION_ERROR_NONE) {
662                 return __convert_error_code(ret);
663         }
664         handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
665         bound_handle->is_added = FALSE;
666         return LOCATIONS_ERROR_NONE;
667 }
668
669 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
670 {
671         LOCATIONS_LOGD("location_manager_foreach_boundary");
672         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
673         LOCATIONS_NULL_ARG_CHECK(manager);
674         LOCATIONS_NULL_ARG_CHECK(callback);
675
676         location_manager_s *handle = (location_manager_s *) manager;
677         handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
678         handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
679         handle->is_continue_foreach_bounds = TRUE;
680         int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
681         if (ret != LOCATION_ERROR_NONE) {
682                 return __convert_error_code(ret);
683         }
684         return LOCATIONS_ERROR_NONE;
685 }
686
687 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
688 {
689         LOCATIONS_LOGD("location_manager_get_method %d", method);
690         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
691         LOCATIONS_NULL_ARG_CHECK(manager);
692         LOCATIONS_NULL_ARG_CHECK(method);
693
694         location_manager_s *handle = (location_manager_s *) manager;
695         LocationMethod _method = LOCATION_METHOD_NONE;
696         g_object_get(handle->object, "method", &_method, NULL);
697         switch (_method) {
698                 case LOCATION_METHOD_NONE:
699                         *method = LOCATIONS_METHOD_NONE;
700                         break;
701                 case LOCATION_METHOD_HYBRID:
702                         *method = LOCATIONS_METHOD_HYBRID;
703                         break;
704                 case LOCATION_METHOD_GPS:
705                         *method = LOCATIONS_METHOD_GPS;
706                         break;
707                 case LOCATION_METHOD_WPS:
708                         *method = LOCATIONS_METHOD_WPS;
709                         break;
710                 default: {
711                                 LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
712                                                                 LOCATIONS_ERROR_INVALID_PARAMETER, method);
713                                 return LOCATIONS_ERROR_INVALID_PARAMETER;
714                         }
715         }
716         /**method = handle->method; */
717         return LOCATIONS_ERROR_NONE;
718 }
719
720 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
721                                                                                          time_t *timestamp)
722 {
723         LOCATIONS_LOGD("location_manager_get_position");
724         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
725         LOCATIONS_NULL_ARG_CHECK(manager);
726         LOCATIONS_NULL_ARG_CHECK(altitude);
727         LOCATIONS_NULL_ARG_CHECK(latitude);
728         LOCATIONS_NULL_ARG_CHECK(longitude);
729         LOCATIONS_NULL_ARG_CHECK(timestamp);
730
731         location_manager_s *handle = (location_manager_s *) manager;
732         int ret;
733         LocationPosition *pos = NULL;
734         LocationAccuracy *acc = NULL;
735         ret = location_get_position(handle->object, &pos, &acc);
736         if (ret != LOCATION_ERROR_NONE) {
737                 return __convert_error_code(ret);
738         }
739
740         if (pos->status == LOCATION_STATUS_NO_FIX) {
741                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
742         } else {
743                 *latitude = pos->latitude;
744                 *longitude = pos->longitude;
745                 *altitude = pos->altitude;
746         }
747         *timestamp = pos->timestamp;
748         location_position_free(pos);
749         location_accuracy_free(acc);
750         return LOCATIONS_ERROR_NONE;
751 }
752
753 EXPORT_API int location_manager_get_location(location_manager_h manager, double *altitude, double *latitude, double *longitude, double *climb, double *direction, double *speed, location_accuracy_level_e *level, double *horizontal, double *vertical, time_t *timestamp)
754 {
755         LOCATIONS_LOGD("location_manager_get_location");
756         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
757         LOCATIONS_NULL_ARG_CHECK(manager);
758         LOCATIONS_NULL_ARG_CHECK(altitude);
759         LOCATIONS_NULL_ARG_CHECK(latitude);
760         LOCATIONS_NULL_ARG_CHECK(longitude);
761         LOCATIONS_NULL_ARG_CHECK(climb);
762         LOCATIONS_NULL_ARG_CHECK(direction);
763         LOCATIONS_NULL_ARG_CHECK(speed);
764         LOCATIONS_NULL_ARG_CHECK(level);
765         LOCATIONS_NULL_ARG_CHECK(horizontal);
766         LOCATIONS_NULL_ARG_CHECK(vertical);
767         LOCATIONS_NULL_ARG_CHECK(timestamp);
768
769         location_manager_s *handle = (location_manager_s *) manager;
770         int ret;
771         LocationPosition *pos = NULL;
772         LocationVelocity *vel = NULL;
773         LocationAccuracy *acc = NULL;
774         ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
775         if (ret != LOCATION_ERROR_NONE) {
776                 return __convert_error_code(ret);
777         }
778
779         if (pos->status == LOCATION_STATUS_NO_FIX) {
780                 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
781         } else {
782                 *latitude = pos->latitude;
783                 *longitude = pos->longitude;
784                 *altitude = pos->altitude;
785         }
786         *timestamp = pos->timestamp;
787         *climb = vel->climb;
788         *direction = vel->direction;
789         *speed = vel->speed;
790         *level = acc->level;
791         *horizontal = acc->horizontal_accuracy;
792         *vertical = acc->vertical_accuracy;
793
794         location_position_free(pos);
795         location_velocity_free(vel);
796         location_accuracy_free(acc);
797         return LOCATIONS_ERROR_NONE;
798 }
799
800 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
801 {
802         LOCATIONS_LOGD("location_manager_get_velocity");
803         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
804         LOCATIONS_NULL_ARG_CHECK(manager);
805         LOCATIONS_NULL_ARG_CHECK(climb);
806         LOCATIONS_NULL_ARG_CHECK(direction);
807         LOCATIONS_NULL_ARG_CHECK(speed);
808         LOCATIONS_NULL_ARG_CHECK(timestamp);
809
810         location_manager_s *handle = (location_manager_s *) manager;
811         int ret;
812         LocationVelocity *vel = NULL;
813         LocationAccuracy *acc = NULL;
814         ret = location_get_velocity(handle->object, &vel, &acc);
815         if (ret != LOCATION_ERROR_NONE) {
816                 return __convert_error_code(ret);
817         }
818
819         *climb = vel->climb;
820         *direction = vel->direction;
821         *speed = vel->speed;
822         *timestamp = vel->timestamp;
823         location_velocity_free(vel);
824         location_accuracy_free(acc);
825         return LOCATIONS_ERROR_NONE;
826 }
827
828 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
829                                                                                          double *vertical)
830 {
831         LOCATIONS_LOGD("location_manager_get_accuracy");
832         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
833         LOCATIONS_NULL_ARG_CHECK(manager);
834         LOCATIONS_NULL_ARG_CHECK(level);
835         LOCATIONS_NULL_ARG_CHECK(horizontal);
836         LOCATIONS_NULL_ARG_CHECK(vertical);
837         location_manager_s *handle = (location_manager_s *) manager;
838
839         int ret;
840         LocationPosition *pos = NULL;
841         LocationAccuracy *acc = NULL;
842         ret = location_get_position(handle->object, &pos, &acc);
843         if (ret != LOCATION_ERROR_NONE) {
844                 return __convert_error_code(ret);
845         }
846
847         if (acc == NULL) {
848                 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
849         }
850
851         *level = acc->level;
852         *horizontal = acc->horizontal_accuracy;
853         *vertical = acc->vertical_accuracy;
854         location_position_free(pos);
855         location_accuracy_free(acc);
856         return LOCATIONS_ERROR_NONE;
857 }
858
859 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
860 {
861         LOCATIONS_LOGD("location_manager_get_last_position");
862         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
863         LOCATIONS_NULL_ARG_CHECK(manager);
864         LOCATIONS_NULL_ARG_CHECK(altitude);
865         LOCATIONS_NULL_ARG_CHECK(latitude);
866         LOCATIONS_NULL_ARG_CHECK(longitude);
867         LOCATIONS_NULL_ARG_CHECK(timestamp);
868
869         location_manager_s *handle = (location_manager_s *) manager;
870
871         int ret;
872         LocationPosition *last_pos = NULL;
873         LocationAccuracy *last_acc = NULL;
874         ret = location_get_last_position(handle->object, &last_pos, &last_acc);
875         if (ret != LOCATION_ERROR_NONE) {
876                 return __convert_error_code(ret);
877         }
878
879         if (last_pos->status == LOCATION_STATUS_NO_FIX) {
880                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
881         } else {
882                 *latitude = last_pos->latitude;
883                 *longitude = last_pos->longitude;
884                 *altitude = last_pos->altitude;
885         }
886         *timestamp = last_pos->timestamp;
887         location_position_free(last_pos);
888         location_accuracy_free(last_acc);
889         return LOCATIONS_ERROR_NONE;
890 }
891
892 EXPORT_API int location_manager_get_last_location(location_manager_h manager, double *altitude, double *latitude, double *longitude, double *climb, double *direction, double *speed, location_accuracy_level_e *level, double *horizontal, double *vertical, time_t *timestamp)
893 {
894         LOCATIONS_LOGD("location_manager_get_last_location");
895         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
896         LOCATIONS_NULL_ARG_CHECK(manager);
897         LOCATIONS_NULL_ARG_CHECK(altitude);
898         LOCATIONS_NULL_ARG_CHECK(latitude);
899         LOCATIONS_NULL_ARG_CHECK(longitude);
900         LOCATIONS_NULL_ARG_CHECK(climb);
901         LOCATIONS_NULL_ARG_CHECK(direction);
902         LOCATIONS_NULL_ARG_CHECK(speed);
903         LOCATIONS_NULL_ARG_CHECK(level);
904         LOCATIONS_NULL_ARG_CHECK(horizontal);
905         LOCATIONS_NULL_ARG_CHECK(vertical);
906         LOCATIONS_NULL_ARG_CHECK(timestamp);
907
908         location_manager_s *handle = (location_manager_s *) manager;
909
910         int ret;
911         LocationPosition *last_pos = NULL;
912         LocationVelocity *last_vel = NULL;
913         LocationAccuracy *last_acc = NULL;
914         ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
915         if (ret != LOCATION_ERROR_NONE) {
916                 return __convert_error_code(ret);
917         }
918
919         if (last_pos->status == LOCATION_STATUS_NO_FIX) {
920                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
921         } else {
922                 *latitude = last_pos->latitude;
923                 *longitude = last_pos->longitude;
924                 *altitude = last_pos->altitude;
925         }
926         *timestamp = last_pos->timestamp;
927         *climb = last_vel->climb;
928         *direction = last_vel->direction;
929         *speed = last_vel->speed;
930         *level = last_acc->level;
931         *horizontal = last_acc->horizontal_accuracy;
932         *vertical = last_acc->vertical_accuracy;
933         location_position_free(last_pos);
934         location_velocity_free(last_vel);
935         location_accuracy_free(last_acc);
936         return LOCATIONS_ERROR_NONE;
937 }
938
939 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
940 {
941         LOCATIONS_LOGD("location_manager_get_last_velocity");
942         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
943         LOCATIONS_NULL_ARG_CHECK(manager);
944         LOCATIONS_NULL_ARG_CHECK(climb);
945         LOCATIONS_NULL_ARG_CHECK(direction);
946         LOCATIONS_NULL_ARG_CHECK(speed);
947         LOCATIONS_NULL_ARG_CHECK(timestamp);
948
949         location_manager_s *handle = (location_manager_s *) manager;
950
951         int ret;
952         LocationVelocity *last_vel = NULL;
953         LocationAccuracy *last_acc = NULL;
954         ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
955         if (ret != LOCATION_ERROR_NONE) {
956                 return __convert_error_code(ret);
957         }
958
959         *climb = last_vel->climb;
960         *direction = last_vel->direction;
961         *speed = last_vel->speed;
962         *timestamp = last_vel->timestamp;
963         location_velocity_free(last_vel);
964         location_accuracy_free(last_acc);
965         return LOCATIONS_ERROR_NONE;
966 }
967
968 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
969 {
970         LOCATIONS_LOGD("location_manager_get_last_accuracy");
971         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
972         LOCATIONS_NULL_ARG_CHECK(manager);
973         LOCATIONS_NULL_ARG_CHECK(level);
974         LOCATIONS_NULL_ARG_CHECK(horizontal);
975         LOCATIONS_NULL_ARG_CHECK(vertical);
976         location_manager_s *handle = (location_manager_s *) manager;
977
978         int ret;
979         LocationPosition *last_pos = NULL;
980         LocationAccuracy *last_acc = NULL;
981         ret = location_get_last_position(handle->object, &last_pos, &last_acc);
982         if (ret != LOCATION_ERROR_NONE) {
983                 return __convert_error_code(ret);
984         }
985
986         *level = last_acc->level;
987         *horizontal = last_acc->horizontal_accuracy;
988         *vertical = last_acc->vertical_accuracy;
989         location_position_free(last_pos);
990         location_accuracy_free(last_acc);
991         return LOCATIONS_ERROR_NONE;
992 }
993
994 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
995 {
996         LOCATIONS_LOGD("location_manager_get_accessibility_state");
997         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
998         LOCATIONS_NULL_ARG_CHECK(state);
999
1000         int ret = LOCATION_ERROR_NONE;
1001         LocationAccessState auth = LOCATION_ACCESS_NONE;
1002         ret = location_get_accessibility_state(&auth);
1003         if (ret != LOCATION_ERROR_NONE) {
1004                 *state = LOCATIONS_ACCESS_STATE_NONE;
1005                 return __convert_error_code(ret);
1006         }
1007
1008         switch (auth) {
1009                 case LOCATION_ACCESS_DENIED:
1010                         *state = LOCATIONS_ACCESS_STATE_DENIED;
1011                         break;
1012                 case LOCATION_ACCESS_ALLOWED:
1013                         *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1014                         break;
1015                 case LOCATION_ACCESS_NONE:
1016                 default:
1017                         *state = LOCATIONS_ACCESS_STATE_NONE;
1018                         break;
1019         }
1020
1021         return LOCATIONS_ERROR_NONE;
1022 }
1023
1024 EXPORT_API int location_manager_set_distance_based_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, double distance, void *user_data)
1025 {
1026         LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1027         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1028         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1029         LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1030         LOCATIONS_NULL_ARG_CHECK(manager);
1031         location_manager_s *handle = (location_manager_s *) manager;
1032         g_object_set(handle->object, "min-interval", interval, NULL);
1033         g_object_set(handle->object, "min-distance", distance, NULL);
1034         return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1035 }
1036
1037 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1038 {
1039         LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1040         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1041         LOCATIONS_NULL_ARG_CHECK(manager);
1042         location_manager_s *handle = (location_manager_s *) manager;
1043         g_object_set(handle->object, "min-interval", 0, NULL);
1044         g_object_set(handle->object, "min-distance", 0, NULL);
1045         return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1046 }
1047
1048 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1049 {
1050         LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1051         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1052         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1053         LOCATIONS_NULL_ARG_CHECK(manager);
1054         location_manager_s *handle = (location_manager_s *) manager;
1055         g_object_set(handle->object, "loc-interval", interval, NULL);
1056         return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1057 }
1058
1059 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1060 {
1061         LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1062         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1063         return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1064 }
1065
1066 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1067 {
1068         LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1069         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1070         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1071         LOCATIONS_NULL_ARG_CHECK(manager);
1072         location_manager_s *handle = (location_manager_s *) manager;
1073         g_object_set(handle->object, "pos-interval", interval, NULL);
1074         return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1075 }
1076
1077 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1078 {
1079         LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1080         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1081         return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1082 }
1083
1084 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1085 {
1086         LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1087         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1088         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1089         LOCATIONS_NULL_ARG_CHECK(manager);
1090         location_manager_s *handle = (location_manager_s *) manager;
1091         g_object_set(handle->object, "vel-interval", interval, NULL);
1092         return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1093 }
1094
1095 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1096 {
1097         LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1098         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1099         return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1100 }
1101
1102 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1103                                                                                                                          void *user_data)
1104 {
1105         LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1106         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1107         return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1108 }
1109
1110 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1111 {
1112         LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1113         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1114         return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1115 }
1116
1117 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1118 {
1119         LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1120         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1121         return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1122 }
1123
1124 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1125 {
1126         LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1127         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1128         return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1129 }
1130
1131 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1132 {
1133         LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1134         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1135         LOCATIONS_NULL_ARG_CHECK(callback);
1136
1137         LocationMethod _method = __convert_LocationMethod(method);
1138         int ret = LOCATION_ERROR_NONE;
1139
1140         if (_method == LOCATION_METHOD_NONE) {
1141                 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1142         }
1143
1144         g_location_setting[_method].callback = callback;
1145         g_location_setting[_method].user_data = user_data;
1146
1147         ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1148         if (ret != LOCATION_ERROR_NONE) {
1149                 return __convert_error_code(ret);
1150         }
1151
1152         return LOCATIONS_ERROR_NONE;
1153 }
1154
1155 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1156 {
1157         LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1158         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1159         LocationMethod _method = __convert_LocationMethod(method);
1160         int ret = LOCATION_ERROR_NONE;
1161
1162         if (_method == LOCATION_METHOD_NONE) {
1163                 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1164         }
1165
1166         ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1167         if (ret != LOCATION_ERROR_NONE) {
1168                 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1169                 ret = __convert_error_code(ret);
1170         }
1171
1172         g_location_setting[method].callback = NULL;
1173         g_location_setting[method].user_data = NULL;
1174
1175         return LOCATIONS_ERROR_NONE;
1176 }
1177
1178 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1179 {
1180         LOCATIONS_LOGD("location_manager_get_distance");
1181         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1182         LOCATIONS_NULL_ARG_CHECK(distance);
1183         LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1184         LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1185         LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1186         LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1187
1188         int ret = LOCATION_ERROR_NONE;
1189         ulong u_distance;
1190
1191         LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1192         LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1193
1194         ret = location_get_distance(start, end, &u_distance);
1195         if (ret != LOCATION_ERROR_NONE) {
1196                 return __convert_error_code(ret);
1197         }
1198
1199         *distance = (double)u_distance;
1200
1201         return LOCATIONS_ERROR_NONE;
1202 }
1203
1204 /*/////////////////////////////////////// */
1205 /* GPS Status & Satellites */
1206 /*////////////////////////////////////// */
1207
1208 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1209 {
1210         LOCATIONS_LOGD("gps_status_get_nmea");
1211         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1212         LOCATIONS_NULL_ARG_CHECK(manager);
1213         LOCATIONS_NULL_ARG_CHECK(nmea);
1214         location_manager_s *handle = (location_manager_s *) manager;
1215         char *nmea_data;
1216
1217         int ret = location_get_nmea(handle->object, &nmea_data);
1218         if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1219                 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1220                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1221                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1222                 }
1223
1224                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1225                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1226         }
1227
1228         *nmea = g_strdup(nmea_data);
1229         g_free(nmea_data);
1230
1231         return LOCATIONS_ERROR_NONE;
1232 }
1233
1234 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1235 {
1236         LOCATIONS_LOGD("gps_status_get_satellite");
1237         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1238         LOCATIONS_NULL_ARG_CHECK(manager);
1239         LOCATIONS_NULL_ARG_CHECK(num_of_active);
1240         LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1241         LOCATIONS_NULL_ARG_CHECK(timestamp);
1242         location_manager_s *handle = (location_manager_s *) manager;
1243         LocationSatellite *sat = NULL;
1244         int ret = location_get_satellite(handle->object, &sat);
1245         if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1246                 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1247                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1248                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1249                 }
1250
1251                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1252                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1253         }
1254
1255         *num_of_active = sat->num_of_sat_used;
1256         *num_of_inview = sat->num_of_sat_inview;
1257         *timestamp = sat->timestamp;
1258         location_satellite_free(sat);
1259         sat = NULL;
1260         return LOCATIONS_ERROR_NONE;
1261 }
1262
1263 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1264 {
1265         LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1266         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1267         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1268         LOCATIONS_NULL_ARG_CHECK(manager);
1269         LOCATIONS_NULL_ARG_CHECK(callback);
1270
1271         location_manager_s *handle = (location_manager_s *) manager;
1272         location_set_option(handle->object, "USE_SV");
1273         g_object_set(handle->object, "sat-interval", interval, NULL);
1274         return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1275 }
1276
1277 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1278 {
1279         LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1280         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1281         return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1282 }
1283
1284 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1285 {
1286         LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1287         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1288         LOCATIONS_NULL_ARG_CHECK(manager);
1289         LOCATIONS_NULL_ARG_CHECK(callback);
1290
1291         location_manager_s *handle = (location_manager_s *) manager;
1292         LocationSatellite *sat = NULL;
1293         int ret = location_get_satellite(handle->object, &sat);
1294         if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1295                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1296                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1297                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1298                 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1299                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1300                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1301                 }
1302
1303                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1304                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1305         }
1306
1307         int i;
1308         for (i = 0; i < sat->num_of_sat_inview; i++) {
1309                 guint prn;
1310                 gboolean used;
1311                 guint elevation;
1312                 guint azimuth;
1313                 gint snr;
1314                 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1315                 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1316                         break;
1317         }
1318         location_satellite_free(sat);
1319         sat = NULL;
1320         return LOCATIONS_ERROR_NONE;
1321 }
1322
1323 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1324 {
1325         LOCATIONS_LOGD("gps_status_get_last_satellite");
1326         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1327         LOCATIONS_NULL_ARG_CHECK(manager);
1328         LOCATIONS_NULL_ARG_CHECK(num_of_active);
1329         LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1330         LOCATIONS_NULL_ARG_CHECK(timestamp);
1331
1332         location_manager_s *handle = (location_manager_s *) manager;
1333         int ret = LOCATION_ERROR_NONE;
1334         LocationSatellite *last_sat = NULL;
1335         ret = location_get_last_satellite(handle->object, &last_sat);
1336         if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1337                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1338                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1339                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1340                 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1341                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1342                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1343                 }
1344
1345                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1346                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1347         }
1348
1349         *num_of_active = last_sat->num_of_sat_used;
1350         *num_of_inview = last_sat->num_of_sat_inview;
1351         *timestamp = last_sat->timestamp;
1352         location_satellite_free(last_sat);
1353         return LOCATIONS_ERROR_NONE;
1354 }
1355
1356 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1357 {
1358         LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1359         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1360         LOCATIONS_NULL_ARG_CHECK(manager);
1361         LOCATIONS_NULL_ARG_CHECK(callback);
1362         location_manager_s *handle = (location_manager_s *) manager;
1363         int ret;
1364         LocationSatellite *last_sat = NULL;
1365         ret = location_get_last_satellite(handle->object, &last_sat);
1366         if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1367                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1368                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1369                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1370                 }
1371
1372                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1373                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1374         }
1375
1376         int i;
1377         for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1378                 guint prn;
1379                 gboolean used;
1380                 guint elevation;
1381                 guint azimuth;
1382                 gint snr;
1383                 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1384                 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
1385                         break;
1386                 }
1387         }
1388         location_satellite_free(last_sat);
1389         return LOCATIONS_ERROR_NONE;
1390 }