Sync with 2.4
[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                 }
438                 else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
439                         LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
440                         return LOCATIONS_ERROR_NOT_SUPPORTED;
441                 }
442
443                 LocationMethod _method = __convert_LocationMethod(method);
444
445                 int ret = location_enable_method(_method, enable);
446
447                 return __convert_error_code(ret);
448         }
449 }
450
451
452 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
453 {
454         LOCATIONS_LOGD("location_manager_create (method : %d)", method);
455
456         if (method == LOCATIONS_METHOD_HYBRID) {
457                 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
458         } else if (method == LOCATIONS_METHOD_GPS) {
459                 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
460                         LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
461                         return LOCATIONS_ERROR_NOT_SUPPORTED;
462                 }
463         } else if (method == LOCATIONS_METHOD_WPS) {
464                 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
465                         LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
466                         return LOCATIONS_ERROR_NOT_SUPPORTED;
467                 }
468         }
469
470         LocationMethod _method = __convert_LocationMethod(method);
471         if (_method == LOCATION_METHOD_NONE) {
472                 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
473                 return LOCATIONS_ERROR_NOT_SUPPORTED;
474         }
475         if (!location_is_supported_method(_method)) {
476                 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
477                 return LOCATIONS_ERROR_NOT_SUPPORTED;
478         }
479
480         /*It is moved here becasue of TCS. */
481         LOCATIONS_NULL_ARG_CHECK(manager);
482
483         if (location_init() != LOCATION_ERROR_NONE) {
484                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
485                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
486         }
487
488         location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
489         if (handle == NULL) {
490                 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
491                 return LOCATIONS_ERROR_OUT_OF_MEMORY;
492         }
493
494         memset(handle, 0, sizeof(location_manager_s));
495
496         handle->object = location_new(_method);
497         if (handle->object == NULL) {
498                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
499                 free(handle);
500                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
501         }
502         handle->method = method;
503         handle->is_continue_foreach_bounds = TRUE;
504         handle->bounds_list = NULL;
505
506         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
507                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
508
509         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
510                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
511
512         *manager = (location_manager_h) handle;
513         return LOCATIONS_ERROR_NONE;
514 }
515
516 EXPORT_API int location_manager_destroy(location_manager_h manager)
517 {
518         LOCATIONS_LOGD("location_manager_destroy");
519         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
520         LOCATIONS_NULL_ARG_CHECK(manager);
521         location_manager_s *handle = (location_manager_s *) manager;
522
523         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
524                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
525                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
526         }
527
528         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
529                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
530                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
531         }
532
533         int ret = location_free(handle->object);
534         if (ret != LOCATIONS_ERROR_NONE) {
535                 return __convert_error_code(ret);
536         }
537         free(handle);
538         return LOCATIONS_ERROR_NONE;
539 }
540
541 EXPORT_API int location_manager_start(location_manager_h manager)
542 {
543         LOCATIONS_LOGD("location_manager_start");
544         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
545         LOCATIONS_NULL_ARG_CHECK(manager);
546         location_manager_s *handle = (location_manager_s *) manager;
547
548         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
549                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
550
551         if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
552                 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
553                         handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
554
555                 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
556                         handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
557         } else {
558                 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
559         }
560
561         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
562                 LOCATIONS_LOGI("Satellite update_cb is set");
563                 location_set_option(handle->object, "USE_SV");
564         }
565
566         int ret = location_start(handle->object);
567         if (ret != LOCATION_ERROR_NONE) {
568                 return __convert_error_code(ret);
569         }
570         return LOCATIONS_ERROR_NONE;
571 }
572
573 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
574 {
575         LOCATIONS_LOGD("location_manager_request_single_location");
576         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
577         LOCATIONS_NULL_ARG_CHECK(manager);
578         LOCATIONS_NULL_ARG_CHECK(callback);
579         if (timeout <= 0 || timeout > 120) {
580                 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
581                 return LOCATIONS_ERROR_INVALID_PARAMETER;
582         }
583
584         location_manager_s *handle = (location_manager_s *) manager;
585         int ret = LOCATIONS_ERROR_NONE;
586
587         if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
588                 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
589
590         ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
591         if (ret != LOCATIONS_ERROR_NONE) {
592                 return ret;
593         }
594
595         ret = location_request_single_location(handle->object, timeout);
596         if (ret != LOCATION_ERROR_NONE) {
597                 return __convert_error_code(ret);
598         }
599         return LOCATIONS_ERROR_NONE;
600 }
601
602 EXPORT_API int location_manager_stop(location_manager_h manager)
603 {
604         LOCATIONS_LOGD("location_manager_stop");
605         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
606         LOCATIONS_NULL_ARG_CHECK(manager);
607
608         location_manager_s *handle = (location_manager_s *) manager;
609
610         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
611                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
612                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
613         }
614
615         if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
616                 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
617                         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
618                         handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
619                 }
620
621                 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
622                         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
623                         handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
624                 }
625         }
626
627         int ret = location_stop(handle->object);
628         if (ret != LOCATION_ERROR_NONE) {
629                 return __convert_error_code(ret);
630         }
631         return LOCATIONS_ERROR_NONE;
632 }
633
634 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
635 {
636         LOCATIONS_LOGD("location_manager_add_boundary");
637         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
638         LOCATIONS_NULL_ARG_CHECK(manager);
639         LOCATIONS_NULL_ARG_CHECK(bounds);
640
641         location_manager_s *handle = (location_manager_s *) manager;
642         location_bounds_s *bound_handle = (location_bounds_s *) bounds;
643         int ret = location_boundary_add(handle->object, bound_handle->boundary);
644         if (ret != LOCATION_ERROR_NONE) {
645                 return __convert_error_code(ret);
646         }
647         bound_handle->is_added = TRUE;
648         handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
649         return LOCATIONS_ERROR_NONE;
650 }
651
652 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
653 {
654         LOCATIONS_LOGD("location_manager_remove_boundary");
655         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
656         LOCATIONS_NULL_ARG_CHECK(manager);
657         LOCATIONS_NULL_ARG_CHECK(bounds);
658
659         location_manager_s *handle = (location_manager_s *) manager;
660         location_bounds_s *bound_handle = (location_bounds_s *) bounds;
661         int ret = location_boundary_remove(handle->object, bound_handle->boundary);
662         if (ret != LOCATION_ERROR_NONE) {
663                 return __convert_error_code(ret);
664         }
665         handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
666         bound_handle->is_added = FALSE;
667         return LOCATIONS_ERROR_NONE;
668 }
669
670 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
671 {
672         LOCATIONS_LOGD("location_manager_foreach_boundary");
673         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
674         LOCATIONS_NULL_ARG_CHECK(manager);
675         LOCATIONS_NULL_ARG_CHECK(callback);
676
677         location_manager_s *handle = (location_manager_s *) manager;
678         handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
679         handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
680         handle->is_continue_foreach_bounds = TRUE;
681         int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
682         if (ret != LOCATION_ERROR_NONE) {
683                 return __convert_error_code(ret);
684         }
685         return LOCATIONS_ERROR_NONE;
686 }
687
688 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
689 {
690         LOCATIONS_LOGD("location_manager_get_method %d", method);
691         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
692         LOCATIONS_NULL_ARG_CHECK(manager);
693         LOCATIONS_NULL_ARG_CHECK(method);
694
695         location_manager_s *handle = (location_manager_s *) manager;
696         LocationMethod _method = LOCATION_METHOD_NONE;
697         g_object_get(handle->object, "method", &_method, NULL);
698         switch (_method) {
699                 case LOCATION_METHOD_NONE:
700                         *method = LOCATIONS_METHOD_NONE;
701                         break;
702                 case LOCATION_METHOD_HYBRID:
703                         *method = LOCATIONS_METHOD_HYBRID;
704                         break;
705                 case LOCATION_METHOD_GPS:
706                         *method = LOCATIONS_METHOD_GPS;
707                         break;
708                 case LOCATION_METHOD_WPS:
709                         *method = LOCATIONS_METHOD_WPS;
710                         break;
711                 default: {
712                                 LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
713                                                                 LOCATIONS_ERROR_INVALID_PARAMETER, method);
714                                 return LOCATIONS_ERROR_INVALID_PARAMETER;
715                         }
716         }
717         /**method = handle->method; */
718         return LOCATIONS_ERROR_NONE;
719 }
720
721 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
722                                                                                          time_t *timestamp)
723 {
724         LOCATIONS_LOGD("location_manager_get_position");
725         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
726         LOCATIONS_NULL_ARG_CHECK(manager);
727         LOCATIONS_NULL_ARG_CHECK(altitude);
728         LOCATIONS_NULL_ARG_CHECK(latitude);
729         LOCATIONS_NULL_ARG_CHECK(longitude);
730         LOCATIONS_NULL_ARG_CHECK(timestamp);
731
732         location_manager_s *handle = (location_manager_s *) manager;
733         int ret;
734         LocationPosition *pos = NULL;
735         LocationAccuracy *acc = NULL;
736         ret = location_get_position(handle->object, &pos, &acc);
737         if (ret != LOCATION_ERROR_NONE) {
738                 return __convert_error_code(ret);
739         }
740
741         if (pos->status == LOCATION_STATUS_NO_FIX) {
742                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
743         } else {
744                 *latitude = pos->latitude;
745                 *longitude = pos->longitude;
746                 *altitude = pos->altitude;
747         }
748         *timestamp = pos->timestamp;
749         location_position_free(pos);
750         location_accuracy_free(acc);
751         return LOCATIONS_ERROR_NONE;
752 }
753
754 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)
755 {
756         LOCATIONS_LOGD("location_manager_get_location");
757         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
758         LOCATIONS_NULL_ARG_CHECK(manager);
759         LOCATIONS_NULL_ARG_CHECK(altitude);
760         LOCATIONS_NULL_ARG_CHECK(latitude);
761         LOCATIONS_NULL_ARG_CHECK(longitude);
762         LOCATIONS_NULL_ARG_CHECK(climb);
763         LOCATIONS_NULL_ARG_CHECK(direction);
764         LOCATIONS_NULL_ARG_CHECK(speed);
765         LOCATIONS_NULL_ARG_CHECK(level);
766         LOCATIONS_NULL_ARG_CHECK(horizontal);
767         LOCATIONS_NULL_ARG_CHECK(vertical);
768         LOCATIONS_NULL_ARG_CHECK(timestamp);
769
770         location_manager_s *handle = (location_manager_s *) manager;
771         int ret;
772         LocationPosition *pos = NULL;
773         LocationVelocity *vel = NULL;
774         LocationAccuracy *acc = NULL;
775         ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
776         if (ret != LOCATION_ERROR_NONE) {
777                 return __convert_error_code(ret);
778         }
779
780         if (pos->status == LOCATION_STATUS_NO_FIX) {
781                 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
782         } else {
783                 *latitude = pos->latitude;
784                 *longitude = pos->longitude;
785                 *altitude = pos->altitude;
786         }
787         *timestamp = pos->timestamp;
788         *climb = vel->climb;
789         *direction = vel->direction;
790         *speed = vel->speed;
791         *level = acc->level;
792         *horizontal = acc->horizontal_accuracy;
793         *vertical = acc->vertical_accuracy;
794
795         location_position_free(pos);
796         location_velocity_free(vel);
797         location_accuracy_free(acc);
798         return LOCATIONS_ERROR_NONE;
799 }
800
801 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
802 {
803         LOCATIONS_LOGD("location_manager_get_velocity");
804         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
805         LOCATIONS_NULL_ARG_CHECK(manager);
806         LOCATIONS_NULL_ARG_CHECK(climb);
807         LOCATIONS_NULL_ARG_CHECK(direction);
808         LOCATIONS_NULL_ARG_CHECK(speed);
809         LOCATIONS_NULL_ARG_CHECK(timestamp);
810
811         location_manager_s *handle = (location_manager_s *) manager;
812         int ret;
813         LocationVelocity *vel = NULL;
814         LocationAccuracy *acc = NULL;
815         ret = location_get_velocity(handle->object, &vel, &acc);
816         if (ret != LOCATION_ERROR_NONE) {
817                 return __convert_error_code(ret);
818         }
819
820         *climb = vel->climb;
821         *direction = vel->direction;
822         *speed = vel->speed;
823         *timestamp = vel->timestamp;
824         location_velocity_free(vel);
825         location_accuracy_free(acc);
826         return LOCATIONS_ERROR_NONE;
827 }
828
829 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
830                                                                                          double *vertical)
831 {
832         LOCATIONS_LOGD("location_manager_get_accuracy");
833         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
834         LOCATIONS_NULL_ARG_CHECK(manager);
835         LOCATIONS_NULL_ARG_CHECK(level);
836         LOCATIONS_NULL_ARG_CHECK(horizontal);
837         LOCATIONS_NULL_ARG_CHECK(vertical);
838         location_manager_s *handle = (location_manager_s *) manager;
839
840         int ret;
841         LocationPosition *pos = NULL;
842         LocationAccuracy *acc = NULL;
843         ret = location_get_position(handle->object, &pos, &acc);
844         if (ret != LOCATION_ERROR_NONE) {
845                 return __convert_error_code(ret);
846         }
847
848         if (acc == NULL) {
849                 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
850         }
851
852         *level = acc->level;
853         *horizontal = acc->horizontal_accuracy;
854         *vertical = acc->vertical_accuracy;
855         location_position_free(pos);
856         location_accuracy_free(acc);
857         return LOCATIONS_ERROR_NONE;
858 }
859
860 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
861 {
862         LOCATIONS_LOGD("location_manager_get_last_position");
863         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
864         LOCATIONS_NULL_ARG_CHECK(manager);
865         LOCATIONS_NULL_ARG_CHECK(altitude);
866         LOCATIONS_NULL_ARG_CHECK(latitude);
867         LOCATIONS_NULL_ARG_CHECK(longitude);
868         LOCATIONS_NULL_ARG_CHECK(timestamp);
869
870         location_manager_s *handle = (location_manager_s *) manager;
871
872         int ret;
873         LocationPosition *last_pos = NULL;
874         LocationAccuracy *last_acc = NULL;
875         ret = location_get_last_position(handle->object, &last_pos, &last_acc);
876         if (ret != LOCATION_ERROR_NONE) {
877                 return __convert_error_code(ret);
878         }
879
880         if (last_pos->status == LOCATION_STATUS_NO_FIX) {
881                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
882         } else {
883                 *latitude = last_pos->latitude;
884                 *longitude = last_pos->longitude;
885                 *altitude = last_pos->altitude;
886         }
887         *timestamp = last_pos->timestamp;
888         location_position_free(last_pos);
889         location_accuracy_free(last_acc);
890         return LOCATIONS_ERROR_NONE;
891 }
892
893 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)
894 {
895         LOCATIONS_LOGD("location_manager_get_last_location");
896         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
897         LOCATIONS_NULL_ARG_CHECK(manager);
898         LOCATIONS_NULL_ARG_CHECK(altitude);
899         LOCATIONS_NULL_ARG_CHECK(latitude);
900         LOCATIONS_NULL_ARG_CHECK(longitude);
901         LOCATIONS_NULL_ARG_CHECK(climb);
902         LOCATIONS_NULL_ARG_CHECK(direction);
903         LOCATIONS_NULL_ARG_CHECK(speed);
904         LOCATIONS_NULL_ARG_CHECK(level);
905         LOCATIONS_NULL_ARG_CHECK(horizontal);
906         LOCATIONS_NULL_ARG_CHECK(vertical);
907         LOCATIONS_NULL_ARG_CHECK(timestamp);
908
909         location_manager_s *handle = (location_manager_s *) manager;
910
911         int ret;
912         LocationPosition *last_pos = NULL;
913         LocationVelocity *last_vel = NULL;
914         LocationAccuracy *last_acc = NULL;
915         ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
916         if (ret != LOCATION_ERROR_NONE) {
917                 return __convert_error_code(ret);
918         }
919
920         if (last_pos->status == LOCATION_STATUS_NO_FIX) {
921                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
922         } else {
923                 *latitude = last_pos->latitude;
924                 *longitude = last_pos->longitude;
925                 *altitude = last_pos->altitude;
926         }
927         *timestamp = last_pos->timestamp;
928         *climb = last_vel->climb;
929         *direction = last_vel->direction;
930         *speed = last_vel->speed;
931         *level = last_acc->level;
932         *horizontal = last_acc->horizontal_accuracy;
933         *vertical = last_acc->vertical_accuracy;
934         location_position_free(last_pos);
935         location_velocity_free(last_vel);
936         location_accuracy_free(last_acc);
937         return LOCATIONS_ERROR_NONE;
938 }
939
940 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
941 {
942         LOCATIONS_LOGD("location_manager_get_last_velocity");
943         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
944         LOCATIONS_NULL_ARG_CHECK(manager);
945         LOCATIONS_NULL_ARG_CHECK(climb);
946         LOCATIONS_NULL_ARG_CHECK(direction);
947         LOCATIONS_NULL_ARG_CHECK(speed);
948         LOCATIONS_NULL_ARG_CHECK(timestamp);
949
950         location_manager_s *handle = (location_manager_s *) manager;
951
952         int ret;
953         LocationVelocity *last_vel = NULL;
954         LocationAccuracy *last_acc = NULL;
955         ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
956         if (ret != LOCATION_ERROR_NONE) {
957                 return __convert_error_code(ret);
958         }
959
960         *climb = last_vel->climb;
961         *direction = last_vel->direction;
962         *speed = last_vel->speed;
963         *timestamp = last_vel->timestamp;
964         location_velocity_free(last_vel);
965         location_accuracy_free(last_acc);
966         return LOCATIONS_ERROR_NONE;
967 }
968
969 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
970 {
971         LOCATIONS_LOGD("location_manager_get_last_accuracy");
972         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
973         LOCATIONS_NULL_ARG_CHECK(manager);
974         LOCATIONS_NULL_ARG_CHECK(level);
975         LOCATIONS_NULL_ARG_CHECK(horizontal);
976         LOCATIONS_NULL_ARG_CHECK(vertical);
977         location_manager_s *handle = (location_manager_s *) manager;
978
979         int ret;
980         LocationPosition *last_pos = NULL;
981         LocationAccuracy *last_acc = NULL;
982         ret = location_get_last_position(handle->object, &last_pos, &last_acc);
983         if (ret != LOCATION_ERROR_NONE) {
984                 return __convert_error_code(ret);
985         }
986
987         *level = last_acc->level;
988         *horizontal = last_acc->horizontal_accuracy;
989         *vertical = last_acc->vertical_accuracy;
990         location_position_free(last_pos);
991         location_accuracy_free(last_acc);
992         return LOCATIONS_ERROR_NONE;
993 }
994
995 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
996 {
997         LOCATIONS_LOGD("location_manager_get_accessibility_state");
998         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
999         LOCATIONS_NULL_ARG_CHECK(state);
1000
1001         int ret = LOCATION_ERROR_NONE;
1002         LocationAccessState auth = LOCATION_ACCESS_NONE;
1003         ret = location_get_accessibility_state(&auth);
1004         if (ret != LOCATION_ERROR_NONE) {
1005                 *state = LOCATIONS_ACCESS_STATE_NONE;
1006                 return __convert_error_code(ret);
1007         }
1008
1009         switch (auth) {
1010                 case LOCATION_ACCESS_DENIED:
1011                         *state = LOCATIONS_ACCESS_STATE_DENIED;
1012                         break;
1013                 case LOCATION_ACCESS_ALLOWED:
1014                         *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1015                         break;
1016                 case LOCATION_ACCESS_NONE:
1017                 default:
1018                         *state = LOCATIONS_ACCESS_STATE_NONE;
1019                         break;
1020         }
1021
1022         return LOCATIONS_ERROR_NONE;
1023 }
1024
1025 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)
1026 {
1027         LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1028         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1029         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1030         LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1031         LOCATIONS_NULL_ARG_CHECK(manager);
1032         location_manager_s *handle = (location_manager_s *) manager;
1033         g_object_set(handle->object, "min-interval", interval, NULL);
1034         g_object_set(handle->object, "min-distance", distance, NULL);
1035         return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1036 }
1037
1038 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1039 {
1040         LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1041         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1042         LOCATIONS_NULL_ARG_CHECK(manager);
1043         location_manager_s *handle = (location_manager_s *) manager;
1044         g_object_set(handle->object, "min-interval", 0, NULL);
1045         g_object_set(handle->object, "min-distance", 0, NULL);
1046         return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1047 }
1048
1049 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1050 {
1051         LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1052         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1053         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1054         LOCATIONS_NULL_ARG_CHECK(manager);
1055         location_manager_s *handle = (location_manager_s *) manager;
1056         g_object_set(handle->object, "loc-interval", interval, NULL);
1057         return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1058 }
1059
1060 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1061 {
1062         LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1063         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1064         return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1065 }
1066
1067 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1068 {
1069         LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1070         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1071         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1072         LOCATIONS_NULL_ARG_CHECK(manager);
1073         location_manager_s *handle = (location_manager_s *) manager;
1074         g_object_set(handle->object, "pos-interval", interval, NULL);
1075         return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1076 }
1077
1078 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1079 {
1080         LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1081         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1082         return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1083 }
1084
1085 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1086 {
1087         LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1088         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1089         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1090         LOCATIONS_NULL_ARG_CHECK(manager);
1091         location_manager_s *handle = (location_manager_s *) manager;
1092         g_object_set(handle->object, "vel-interval", interval, NULL);
1093         return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1094 }
1095
1096 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1097 {
1098         LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1099         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1100         return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1101 }
1102
1103 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1104                                                                                                                          void *user_data)
1105 {
1106         LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1107         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1108         return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1109 }
1110
1111 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1112 {
1113         LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1114         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1115         return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1116 }
1117
1118 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1119 {
1120         LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1121         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1122         return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1123 }
1124
1125 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1126 {
1127         LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1128         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1129         return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1130 }
1131
1132 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1133 {
1134         LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1135         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1136         LOCATIONS_NULL_ARG_CHECK(callback);
1137
1138         LocationMethod _method = __convert_LocationMethod(method);
1139         int ret = LOCATION_ERROR_NONE;
1140
1141         if (_method == LOCATION_METHOD_NONE) {
1142                 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1143         }
1144
1145         g_location_setting[_method].callback = callback;
1146         g_location_setting[_method].user_data = user_data;
1147
1148         ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1149         if (ret != LOCATION_ERROR_NONE) {
1150                 return __convert_error_code(ret);
1151         }
1152
1153         return LOCATIONS_ERROR_NONE;
1154 }
1155
1156 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1157 {
1158         LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1159         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1160         LocationMethod _method = __convert_LocationMethod(method);
1161         int ret = LOCATION_ERROR_NONE;
1162
1163         if (_method == LOCATION_METHOD_NONE) {
1164                 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1165         }
1166
1167         ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1168         if (ret != LOCATION_ERROR_NONE) {
1169                 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1170                 ret = __convert_error_code(ret);
1171         }
1172
1173         g_location_setting[method].callback = NULL;
1174         g_location_setting[method].user_data = NULL;
1175
1176         return LOCATIONS_ERROR_NONE;
1177 }
1178
1179 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1180 {
1181         LOCATIONS_LOGD("location_manager_get_distance");
1182         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1183         LOCATIONS_NULL_ARG_CHECK(distance);
1184         LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1185         LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1186         LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1187         LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1188
1189         int ret = LOCATION_ERROR_NONE;
1190         ulong u_distance;
1191
1192         LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1193         LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1194
1195         ret = location_get_distance(start, end, &u_distance);
1196         if (ret != LOCATION_ERROR_NONE) {
1197                 return __convert_error_code(ret);
1198         }
1199
1200         *distance = (double)u_distance;
1201
1202         return LOCATIONS_ERROR_NONE;
1203 }
1204
1205 /*/////////////////////////////////////// */
1206 /* GPS Status & Satellites */
1207 /*////////////////////////////////////// */
1208
1209 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1210 {
1211         LOCATIONS_LOGD("gps_status_get_nmea");
1212         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1213         LOCATIONS_NULL_ARG_CHECK(manager);
1214         LOCATIONS_NULL_ARG_CHECK(nmea);
1215         location_manager_s *handle = (location_manager_s *) manager;
1216         char *nmea_data;
1217
1218         int ret = location_get_nmea(handle->object, &nmea_data);
1219         if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1220                 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1221                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1222                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1223                 }
1224
1225                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1226                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1227         }
1228
1229         *nmea = g_strdup(nmea_data);
1230         g_free(nmea_data);
1231
1232         return LOCATIONS_ERROR_NONE;
1233 }
1234
1235 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1236 {
1237         LOCATIONS_LOGD("gps_status_get_satellite");
1238         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1239         LOCATIONS_NULL_ARG_CHECK(manager);
1240         LOCATIONS_NULL_ARG_CHECK(num_of_active);
1241         LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1242         LOCATIONS_NULL_ARG_CHECK(timestamp);
1243         location_manager_s *handle = (location_manager_s *) manager;
1244         LocationSatellite *sat = NULL;
1245         int ret = location_get_satellite(handle->object, &sat);
1246         if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1247                 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1248                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1249                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1250                 }
1251
1252                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1253                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1254         }
1255
1256         *num_of_active = sat->num_of_sat_used;
1257         *num_of_inview = sat->num_of_sat_inview;
1258         *timestamp = sat->timestamp;
1259         location_satellite_free(sat);
1260         sat = NULL;
1261         return LOCATIONS_ERROR_NONE;
1262 }
1263
1264 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1265 {
1266         LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1267         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1268         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1269         LOCATIONS_NULL_ARG_CHECK(manager);
1270         LOCATIONS_NULL_ARG_CHECK(callback);
1271
1272         location_manager_s *handle = (location_manager_s *) manager;
1273         location_set_option(handle->object, "USE_SV");
1274         g_object_set(handle->object, "sat-interval", interval, NULL);
1275         return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1276 }
1277
1278 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1279 {
1280         LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1281         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1282         return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1283 }
1284
1285 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1286 {
1287         LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1288         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1289         LOCATIONS_NULL_ARG_CHECK(manager);
1290         LOCATIONS_NULL_ARG_CHECK(callback);
1291
1292         location_manager_s *handle = (location_manager_s *) manager;
1293         LocationSatellite *sat = NULL;
1294         int ret = location_get_satellite(handle->object, &sat);
1295         if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1296                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1297                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1298                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1299                 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1300                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1301                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1302                 }
1303
1304                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1305                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1306         }
1307
1308         int i;
1309         for (i = 0; i < sat->num_of_sat_inview; i++) {
1310                 guint prn;
1311                 gboolean used;
1312                 guint elevation;
1313                 guint azimuth;
1314                 gint snr;
1315                 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1316                 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1317                         break;
1318         }
1319         location_satellite_free(sat);
1320         sat = NULL;
1321         return LOCATIONS_ERROR_NONE;
1322 }
1323
1324 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1325 {
1326         LOCATIONS_LOGD("gps_status_get_last_satellite");
1327         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1328         LOCATIONS_NULL_ARG_CHECK(manager);
1329         LOCATIONS_NULL_ARG_CHECK(num_of_active);
1330         LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1331         LOCATIONS_NULL_ARG_CHECK(timestamp);
1332
1333         location_manager_s *handle = (location_manager_s *) manager;
1334         int ret = LOCATION_ERROR_NONE;
1335         LocationSatellite *last_sat = NULL;
1336         ret = location_get_last_satellite(handle->object, &last_sat);
1337         if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1338                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1339                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1340                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1341                 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1342                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1343                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1344                 }
1345
1346                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1347                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1348         }
1349
1350         *num_of_active = last_sat->num_of_sat_used;
1351         *num_of_inview = last_sat->num_of_sat_inview;
1352         *timestamp = last_sat->timestamp;
1353         location_satellite_free(last_sat);
1354         return LOCATIONS_ERROR_NONE;
1355 }
1356
1357 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1358 {
1359         LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1360         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1361         LOCATIONS_NULL_ARG_CHECK(manager);
1362         LOCATIONS_NULL_ARG_CHECK(callback);
1363         location_manager_s *handle = (location_manager_s *) manager;
1364         int ret;
1365         LocationSatellite *last_sat = NULL;
1366         ret = location_get_last_satellite(handle->object, &last_sat);
1367         if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1368                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1369                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1370                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1371                 }
1372
1373                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1374                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1375         }
1376
1377         int i;
1378         for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1379                 guint prn;
1380                 gboolean used;
1381                 guint elevation;
1382                 guint azimuth;
1383                 gint snr;
1384                 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1385                 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
1386                         break;
1387                 }
1388         }
1389         location_satellite_free(last_sat);
1390         return LOCATIONS_ERROR_NONE;
1391 }