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