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