Test application enabled
[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,
249                                                                                                                                                                         pos->altitude, pos->timestamp,
250                                                                                                                                                                         handle->user_data
251                                                                                                                                                                         [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
252         }
253
254         location_bounds_s *bounds;
255         GList *bounds_list = g_list_first(handle->bounds_list);
256         while (bounds_list) {
257                 bounds = (location_bounds_s *)bounds_list->data;
258                 if (__boundary_compare(boundary, bounds->boundary) == 0) {
259                         LOCATIONS_LOGD("Find zone in boundary");
260                         if (bounds->user_cb)
261                                 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
262
263                         break;
264                 }
265                 bounds_list = g_list_next(bounds_list);
266         }
267         LOCATIONS_LOGD("EXIT <<<");
268 }
269
270 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
271 {
272         LOCATIONS_LOGD("ENTER >>>");
273         location_manager_s *handle = (location_manager_s *) userdata;
274         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
275                 LocationPosition *pos = (LocationPosition *) position;
276                 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
277                                                                                                                                                                         pos->latitude, pos->longitude,
278                                                                                                                                                                         pos->altitude, pos->timestamp,
279                                                                                                                                                                         handle->user_data
280                                                                                                                                                                         [_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
498         LocationMethod _method = __convert_LocationMethod(method);
499         if (_method == LOCATION_METHOD_NONE) {
500                 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
501                 return LOCATIONS_ERROR_NOT_SUPPORTED;
502         }
503
504         if (!location_is_supported_method(_method)) {
505                 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
506                 return LOCATIONS_ERROR_NOT_SUPPORTED;
507         }
508
509         /*It is moved here becasue of TCS. */
510         LOCATIONS_NULL_ARG_CHECK(manager);
511
512         if (location_init() != LOCATION_ERROR_NONE) {
513                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); //LCOV_EXCL_LINE
514                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;   //LCOV_EXCL_LINE
515         }
516
517         location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
518         if (handle == NULL) {
519                 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY); //LCOV_EXCL_LINE
520                 return LOCATIONS_ERROR_OUT_OF_MEMORY;   //LCOV_EXCL_LINE
521         }
522
523         memset(handle, 0, sizeof(location_manager_s));
524
525         handle->object = location_new(_method, FALSE);
526         if (handle->object == NULL) {
527                 //LCOV_EXCL_START
528                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
529                 free(handle);
530                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
531                 //LCOV_EXCL_STOP
532         }
533         handle->method = method;
534         handle->is_continue_foreach_bounds = TRUE;
535         handle->bounds_list = NULL;
536
537         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
538                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
539
540         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
541                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
542
543         *manager = (location_manager_h) handle;
544         return LOCATIONS_ERROR_NONE;
545 }
546
547 EXPORT_API int location_manager_destroy(location_manager_h manager)
548 {
549         LOCATIONS_LOGD("location_manager_destroy");
550         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
551         LOCATIONS_NULL_ARG_CHECK(manager);
552         location_manager_s *handle = (location_manager_s *) manager;
553
554         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
555                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
556                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
557         }
558
559         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
560                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
561                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
562         }
563
564         if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
565                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);    //LCOV_EXCL_LINE
566                 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;     //LCOV_EXCL_LINE
567         }
568
569         int ret = location_free(handle->object, FALSE);
570         if (ret != LOCATIONS_ERROR_NONE)
571                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
572
573         free(handle);
574         return LOCATIONS_ERROR_NONE;
575 }
576
577 EXPORT_API int location_manager_start(location_manager_h manager)
578 {
579         LOCATIONS_LOGD("location_manager_start");
580         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
581         LOCATIONS_NULL_ARG_CHECK(manager);
582         location_manager_s *handle = (location_manager_s *) manager;
583
584         if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
585                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
586
587         if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
588                 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
589                         handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
590
591                 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
592                         handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
593         } else {
594                 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);  //LCOV_EXCL_LINE
595         }
596
597         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
598                 LOCATIONS_LOGI("Satellite update_cb is set");
599                 location_set_option(handle->object, "USE_SV");
600         }
601
602         int ret = location_start(handle->object);
603         if (ret != LOCATION_ERROR_NONE)
604                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
605
606         return LOCATIONS_ERROR_NONE;
607 }
608
609 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
610 {
611         LOCATIONS_LOGD("location_manager_request_single_location");
612         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
613         LOCATIONS_NULL_ARG_CHECK(manager);
614         LOCATIONS_NULL_ARG_CHECK(callback);
615         if (timeout <= 0 || timeout > 120) {
616                 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
617                 return LOCATIONS_ERROR_INVALID_PARAMETER;
618         }
619
620         location_manager_s *handle = (location_manager_s *) manager;
621         int ret = LOCATIONS_ERROR_NONE;
622
623         if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
624                 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
625
626         ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
627         if (ret != LOCATIONS_ERROR_NONE)
628                 return ret;
629
630         ret = location_request_single_location(handle->object, timeout);
631         if (ret != LOCATION_ERROR_NONE) {
632                 //LCOV_EXCL_START
633                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
634                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD : method - %d", handle->method);
635                         return LOCATIONS_ERROR_INCORRECT_METHOD;
636                 }
637                 return __convert_error_code(ret);
638                 //LCOV_EXCL_STOP
639         }
640
641         return LOCATIONS_ERROR_NONE;
642 }
643
644 EXPORT_API int location_manager_stop(location_manager_h manager)
645 {
646         LOCATIONS_LOGD("location_manager_stop");
647         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
648         LOCATIONS_NULL_ARG_CHECK(manager);
649
650         location_manager_s *handle = (location_manager_s *) manager;
651
652         if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
653                 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
654                 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
655         }
656
657         if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
658                 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
659                         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
660                         handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
661                 }
662
663                 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
664                         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
665                         handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
666                 }
667         }
668
669         int ret = location_stop(handle->object);
670         if (ret != LOCATION_ERROR_NONE)
671                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
672
673         return LOCATIONS_ERROR_NONE;
674 }
675
676 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
677 {
678         LOCATIONS_LOGD("location_manager_add_boundary");
679         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
680         LOCATIONS_NULL_ARG_CHECK(manager);
681         LOCATIONS_NULL_ARG_CHECK(bounds);
682
683         location_manager_s *handle = (location_manager_s *) manager;
684         location_bounds_s *bound_handle = (location_bounds_s *) bounds;
685         int ret = location_boundary_add(handle->object, bound_handle->boundary);
686         if (ret != LOCATION_ERROR_NONE)
687                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
688
689         bound_handle->is_added = TRUE;
690         handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
691         return LOCATIONS_ERROR_NONE;
692 }
693
694 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
695 {
696         LOCATIONS_LOGD("location_manager_remove_boundary");
697         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
698         LOCATIONS_NULL_ARG_CHECK(manager);
699         LOCATIONS_NULL_ARG_CHECK(bounds);
700
701         location_manager_s *handle = (location_manager_s *) manager;
702         location_bounds_s *bound_handle = (location_bounds_s *) bounds;
703         int ret = location_boundary_remove(handle->object, bound_handle->boundary);
704         if (ret != LOCATION_ERROR_NONE)
705                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
706
707         handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
708         bound_handle->is_added = FALSE;
709         return LOCATIONS_ERROR_NONE;
710 }
711
712 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
713 {
714         LOCATIONS_LOGD("location_manager_foreach_boundary");
715         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
716         LOCATIONS_NULL_ARG_CHECK(manager);
717         LOCATIONS_NULL_ARG_CHECK(callback);
718
719         location_manager_s *handle = (location_manager_s *) manager;
720         handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
721         handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
722         handle->is_continue_foreach_bounds = TRUE;
723         int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
724         if (ret != LOCATION_ERROR_NONE)
725                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
726
727         return LOCATIONS_ERROR_NONE;
728 }
729
730 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
731 {
732         LOCATIONS_LOGD("location_manager_get_method");
733         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
734         LOCATIONS_NULL_ARG_CHECK(manager);
735         LOCATIONS_NULL_ARG_CHECK(method);
736
737         location_manager_s *handle = (location_manager_s *) manager;
738         LocationMethod _method = LOCATION_METHOD_NONE;
739         g_object_get(handle->object, "method", &_method, NULL);
740         switch (_method) {
741         case LOCATION_METHOD_NONE:
742                 *method = LOCATIONS_METHOD_NONE;
743                 break;
744         case LOCATION_METHOD_HYBRID:
745                 *method = LOCATIONS_METHOD_HYBRID;
746                 break;
747         case LOCATION_METHOD_GPS:
748                 *method = LOCATIONS_METHOD_GPS;
749                 break;
750         case LOCATION_METHOD_WPS:
751                 *method = LOCATIONS_METHOD_WPS; //LCOV_EXCL_LINE
752                 break;                                                  //LCOV_EXCL_LINE
753         case LOCATION_METHOD_PASSIVE:
754                 *method = LOCATIONS_METHOD_PASSIVE;
755                 break;
756         default: {
757                 LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] invalid method");   //LCOV_EXCL_LINE
758                         return LOCATIONS_ERROR_INVALID_PARAMETER;                                                       //LCOV_EXCL_LINE
759                 }
760         }
761         return LOCATIONS_ERROR_NONE;
762 }
763
764 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
765                                                                                          time_t *timestamp)
766 {
767         LOCATIONS_LOGD("location_manager_get_position");
768         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
769         LOCATIONS_NULL_ARG_CHECK(manager);
770         LOCATIONS_NULL_ARG_CHECK(altitude);
771         LOCATIONS_NULL_ARG_CHECK(latitude);
772         LOCATIONS_NULL_ARG_CHECK(longitude);
773         LOCATIONS_NULL_ARG_CHECK(timestamp);
774
775         location_manager_s *handle = (location_manager_s *) manager;
776         LocationPosition *pos = NULL;
777         LocationAccuracy *acc = NULL;
778         int ret = location_get_position(handle->object, &pos, &acc);
779         if (ret != LOCATION_ERROR_NONE)
780                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
781
782         if (pos->status == LOCATION_STATUS_NO_FIX) {
783                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;   //LCOV_EXCL_LINE
784         } else {
785                 *latitude = pos->latitude;
786                 *longitude = pos->longitude;
787                 *altitude = pos->altitude;
788         }
789         *timestamp = pos->timestamp;
790         location_position_free(pos);
791         location_accuracy_free(acc);
792         return LOCATIONS_ERROR_NONE;
793 }
794
795 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)
796 {
797         LOCATIONS_LOGD("location_manager_get_location");
798         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
799         LOCATIONS_NULL_ARG_CHECK(manager);
800         LOCATIONS_NULL_ARG_CHECK(altitude);
801         LOCATIONS_NULL_ARG_CHECK(latitude);
802         LOCATIONS_NULL_ARG_CHECK(longitude);
803         LOCATIONS_NULL_ARG_CHECK(climb);
804         LOCATIONS_NULL_ARG_CHECK(direction);
805         LOCATIONS_NULL_ARG_CHECK(speed);
806         LOCATIONS_NULL_ARG_CHECK(level);
807         LOCATIONS_NULL_ARG_CHECK(horizontal);
808         LOCATIONS_NULL_ARG_CHECK(vertical);
809         LOCATIONS_NULL_ARG_CHECK(timestamp);
810
811         location_manager_s *handle = (location_manager_s *) manager;
812         LocationPosition *pos = NULL;
813         LocationVelocity *vel = NULL;
814         LocationAccuracy *acc = NULL;
815         int ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
816         if (ret != LOCATION_ERROR_NONE)
817                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
818
819         if (pos->status == LOCATION_STATUS_NO_FIX) {
820                 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);      //LCOV_EXCL_LINE
821         } else {
822                 *latitude = pos->latitude;
823                 *longitude = pos->longitude;
824                 *altitude = pos->altitude;
825         }
826         *timestamp = pos->timestamp;
827         *climb = vel->climb;
828         *direction = vel->direction;
829         *speed = vel->speed;
830         *level = acc->level;
831         *horizontal = acc->horizontal_accuracy;
832         *vertical = acc->vertical_accuracy;
833
834         location_position_free(pos);
835         location_velocity_free(vel);
836         location_accuracy_free(acc);
837         return LOCATIONS_ERROR_NONE;
838 }
839
840 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
841 {
842         LOCATIONS_LOGD("location_manager_get_velocity");
843         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
844         LOCATIONS_NULL_ARG_CHECK(manager);
845         LOCATIONS_NULL_ARG_CHECK(climb);
846         LOCATIONS_NULL_ARG_CHECK(direction);
847         LOCATIONS_NULL_ARG_CHECK(speed);
848         LOCATIONS_NULL_ARG_CHECK(timestamp);
849
850         location_manager_s *handle = (location_manager_s *) manager;
851         LocationVelocity *vel = NULL;
852         LocationAccuracy *acc = NULL;
853
854         int ret = location_get_velocity(handle->object, &vel, &acc);
855         if (ret != LOCATION_ERROR_NONE)
856                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
857
858         *climb = vel->climb;
859         *direction = vel->direction;
860         *speed = vel->speed;
861         *timestamp = vel->timestamp;
862         location_velocity_free(vel);
863         location_accuracy_free(acc);
864         return LOCATIONS_ERROR_NONE;
865 }
866
867 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
868                                                                                          double *vertical)
869 {
870         LOCATIONS_LOGD("location_manager_get_accuracy");
871         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
872         LOCATIONS_NULL_ARG_CHECK(manager);
873         LOCATIONS_NULL_ARG_CHECK(level);
874         LOCATIONS_NULL_ARG_CHECK(horizontal);
875         LOCATIONS_NULL_ARG_CHECK(vertical);
876         location_manager_s *handle = (location_manager_s *) manager;
877
878         int ret;
879         LocationPosition *pos = NULL;
880         LocationAccuracy *acc = NULL;
881         ret = location_get_position(handle->object, &pos, &acc);
882         if (ret != LOCATION_ERROR_NONE)
883                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
884
885         if (acc == NULL)
886                 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);      //LCOV_EXCL_LINE
887
888         *level = acc->level;
889         *horizontal = acc->horizontal_accuracy;
890         *vertical = acc->vertical_accuracy;
891         location_position_free(pos);
892         location_accuracy_free(acc);
893         return LOCATIONS_ERROR_NONE;
894 }
895
896 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
897 {
898         LOCATIONS_LOGD("location_manager_get_last_position");
899         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
900         LOCATIONS_NULL_ARG_CHECK(manager);
901         LOCATIONS_NULL_ARG_CHECK(altitude);
902         LOCATIONS_NULL_ARG_CHECK(latitude);
903         LOCATIONS_NULL_ARG_CHECK(longitude);
904         LOCATIONS_NULL_ARG_CHECK(timestamp);
905
906         location_manager_s *handle = (location_manager_s *) manager;
907
908         int ret;
909         LocationPosition *last_pos = NULL;
910         LocationAccuracy *last_acc = NULL;
911         ret = location_get_last_position(handle->object, &last_pos, &last_acc);
912         if (ret != LOCATION_ERROR_NONE)
913                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
914
915         if (last_pos->status == LOCATION_STATUS_NO_FIX) {
916                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
917         } else {
918                 *latitude = last_pos->latitude;
919                 *longitude = last_pos->longitude;
920                 *altitude = last_pos->altitude;
921         }
922         *timestamp = last_pos->timestamp;
923         location_position_free(last_pos);
924         location_accuracy_free(last_acc);
925         return LOCATIONS_ERROR_NONE;
926 }
927
928 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)
929 {
930         LOCATIONS_LOGD("location_manager_get_last_location");
931         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
932         LOCATIONS_NULL_ARG_CHECK(manager);
933         LOCATIONS_NULL_ARG_CHECK(altitude);
934         LOCATIONS_NULL_ARG_CHECK(latitude);
935         LOCATIONS_NULL_ARG_CHECK(longitude);
936         LOCATIONS_NULL_ARG_CHECK(climb);
937         LOCATIONS_NULL_ARG_CHECK(direction);
938         LOCATIONS_NULL_ARG_CHECK(speed);
939         LOCATIONS_NULL_ARG_CHECK(level);
940         LOCATIONS_NULL_ARG_CHECK(horizontal);
941         LOCATIONS_NULL_ARG_CHECK(vertical);
942         LOCATIONS_NULL_ARG_CHECK(timestamp);
943
944         location_manager_s *handle = (location_manager_s *) manager;
945
946         int ret;
947         LocationPosition *last_pos = NULL;
948         LocationVelocity *last_vel = NULL;
949         LocationAccuracy *last_acc = NULL;
950         ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
951         if (ret != LOCATION_ERROR_NONE)
952                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
953
954         if (last_pos->status == LOCATION_STATUS_NO_FIX) {
955                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
956         } else {
957                 *latitude = last_pos->latitude;
958                 *longitude = last_pos->longitude;
959                 *altitude = last_pos->altitude;
960         }
961         *timestamp = last_pos->timestamp;
962         *climb = last_vel->climb;
963         *direction = last_vel->direction;
964         *speed = last_vel->speed;
965         *level = last_acc->level;
966         *horizontal = last_acc->horizontal_accuracy;
967         *vertical = last_acc->vertical_accuracy;
968         location_position_free(last_pos);
969         location_velocity_free(last_vel);
970         location_accuracy_free(last_acc);
971         return LOCATIONS_ERROR_NONE;
972 }
973
974 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
975 {
976         LOCATIONS_LOGD("location_manager_get_last_velocity");
977         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
978         LOCATIONS_NULL_ARG_CHECK(manager);
979         LOCATIONS_NULL_ARG_CHECK(climb);
980         LOCATIONS_NULL_ARG_CHECK(direction);
981         LOCATIONS_NULL_ARG_CHECK(speed);
982         LOCATIONS_NULL_ARG_CHECK(timestamp);
983
984         location_manager_s *handle = (location_manager_s *) manager;
985
986         int ret;
987         LocationVelocity *last_vel = NULL;
988         LocationAccuracy *last_acc = NULL;
989         ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
990         if (ret != LOCATION_ERROR_NONE)
991                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
992
993         *climb = last_vel->climb;
994         *direction = last_vel->direction;
995         *speed = last_vel->speed;
996         *timestamp = last_vel->timestamp;
997         location_velocity_free(last_vel);
998         location_accuracy_free(last_acc);
999         return LOCATIONS_ERROR_NONE;
1000 }
1001
1002 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
1003 {
1004         LOCATIONS_LOGD("location_manager_get_last_accuracy");
1005         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1006         LOCATIONS_NULL_ARG_CHECK(manager);
1007         LOCATIONS_NULL_ARG_CHECK(level);
1008         LOCATIONS_NULL_ARG_CHECK(horizontal);
1009         LOCATIONS_NULL_ARG_CHECK(vertical);
1010         location_manager_s *handle = (location_manager_s *) manager;
1011
1012         int ret;
1013         LocationPosition *last_pos = NULL;
1014         LocationAccuracy *last_acc = NULL;
1015         ret = location_get_last_position(handle->object, &last_pos, &last_acc);
1016         if (ret != LOCATION_ERROR_NONE)
1017                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
1018
1019         *level = last_acc->level;
1020         *horizontal = last_acc->horizontal_accuracy;
1021         *vertical = last_acc->vertical_accuracy;
1022         location_position_free(last_pos);
1023         location_accuracy_free(last_acc);
1024         return LOCATIONS_ERROR_NONE;
1025 }
1026
1027 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1028 {
1029         dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: location_manager_get_accessibility_state() is deprecated and will be removed from next release.");
1030         LOCATIONS_LOGD("location_manager_get_accessibility_state");
1031         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1032         LOCATIONS_NULL_ARG_CHECK(state);
1033
1034         int ret = LOCATION_ERROR_NONE;
1035         LocationAccessState auth = LOCATION_ACCESS_NONE;
1036         ret = location_get_accessibility_state(&auth);
1037         if (ret != LOCATION_ERROR_NONE) {
1038                 *state = LOCATIONS_ACCESS_STATE_NONE;   //LCOV_EXCL_LINE
1039                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
1040         }
1041
1042         switch (auth) {
1043         //LCOV_EXCL_START
1044         case LOCATION_ACCESS_DENIED:
1045                 *state = LOCATIONS_ACCESS_STATE_DENIED;
1046                 break;
1047         case LOCATION_ACCESS_ALLOWED:
1048                 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1049                 break;
1050         case LOCATION_ACCESS_NONE:
1051         default:
1052                 *state = LOCATIONS_ACCESS_STATE_NONE;
1053                 break;
1054         //LCOV_EXCL_STOP
1055         }
1056
1057         return LOCATIONS_ERROR_NONE;
1058 }
1059
1060 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)
1061 {
1062         LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1063         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1064         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1065         LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1066         LOCATIONS_NULL_ARG_CHECK(manager);
1067         location_manager_s *handle = (location_manager_s *) manager;
1068         g_object_set(handle->object, "min-interval", interval, NULL);
1069         g_object_set(handle->object, "min-distance", distance, NULL);
1070         return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1071 }
1072
1073 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1074 {
1075         LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1076         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1077         LOCATIONS_NULL_ARG_CHECK(manager);
1078         return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1079 }
1080
1081 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1082 {
1083         LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1084         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1085         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1086         LOCATIONS_NULL_ARG_CHECK(manager);
1087         location_manager_s *handle = (location_manager_s *) manager;
1088         g_object_set(handle->object, "loc-interval", interval, NULL);
1089         return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1090 }
1091
1092 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1093 {
1094         LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1095         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1096         return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1097 }
1098
1099 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1100 {
1101         LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1102         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1103         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1104         LOCATIONS_NULL_ARG_CHECK(manager);
1105         location_manager_s *handle = (location_manager_s *) manager;
1106         g_object_set(handle->object, "pos-interval", interval, NULL);
1107         return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1108 }
1109
1110 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1111 {
1112         LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1113         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1114         return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1115 }
1116
1117 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1118 {
1119         LOCATIONS_LOGD("location_manager_set_velocity_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         g_object_set(handle->object, "vel-interval", interval, NULL);
1125         return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1126 }
1127
1128 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1129 {
1130         LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1131         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1132         return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1133 }
1134
1135 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1136                                                                                                                          void *user_data)
1137 {
1138         LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1139         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1140         return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1141 }
1142
1143 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1144 {
1145         LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1146         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1147         return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1148 }
1149
1150 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1151 {
1152         LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1153         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1154         return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1155 }
1156
1157 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1158 {
1159         LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1160         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1161         return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1162 }
1163
1164 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1165 {
1166         LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1167         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1168         LOCATIONS_NULL_ARG_CHECK(callback);
1169
1170         LocationMethod _method = __convert_LocationMethod(method);
1171         int ret = LOCATION_ERROR_NONE;
1172
1173         if (_method == LOCATION_METHOD_NONE) {
1174                 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1175         } else if (_method == LOCATION_METHOD_PASSIVE) {
1176                 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");     //LCOV_EXCL_LINE
1177                 return LOCATIONS_ERROR_INCORRECT_METHOD;        //LCOV_EXCL_LINE
1178         }
1179
1180         g_location_setting[_method].callback = callback;
1181         g_location_setting[_method].user_data = user_data;
1182
1183         ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1184         if (ret != LOCATION_ERROR_NONE)
1185                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
1186
1187         return LOCATIONS_ERROR_NONE;
1188 }
1189
1190 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1191 {
1192         LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1193         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1194         LocationMethod _method = __convert_LocationMethod(method);
1195         int ret = LOCATION_ERROR_NONE;
1196
1197         if (_method == LOCATION_METHOD_NONE) {
1198                 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1199         } else if (_method == LOCATION_METHOD_PASSIVE) {
1200                 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");     //LCOV_EXCL_LINE
1201                 return LOCATIONS_ERROR_INCORRECT_METHOD;        //LCOV_EXCL_LINE
1202         }
1203
1204         ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1205         if (ret != LOCATION_ERROR_NONE) {
1206                 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);        //LCOV_EXCL_LINE
1207                 ret = __convert_error_code(ret);        //LCOV_EXCL_LINE
1208         }
1209
1210         g_location_setting[method].callback = NULL;
1211         g_location_setting[method].user_data = NULL;
1212
1213         return LOCATIONS_ERROR_NONE;
1214 }
1215
1216 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1217 {
1218         LOCATIONS_LOGD("location_manager_get_distance");
1219         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1220         LOCATIONS_NULL_ARG_CHECK(distance);
1221         LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1222         LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1223         LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1224         LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1225
1226         int ret = LOCATION_ERROR_NONE;
1227         ulong u_distance;
1228
1229         LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1230         LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1231
1232         ret = location_get_distance(start, end, &u_distance);
1233         if (ret != LOCATION_ERROR_NONE)
1234                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
1235
1236         *distance = (double)u_distance;
1237
1238         return LOCATIONS_ERROR_NONE;
1239 }
1240
1241 /*/////////////////////////////////////// */
1242 /* GPS Status & Satellites */
1243 /*////////////////////////////////////// */
1244
1245 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1246 {
1247         LOCATIONS_LOGD("gps_status_get_nmea");
1248         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1249         LOCATIONS_NULL_ARG_CHECK(manager);
1250         LOCATIONS_NULL_ARG_CHECK(nmea);
1251         location_manager_s *handle = (location_manager_s *) manager;
1252         char *nmea_data;
1253
1254         int ret = location_get_nmea(handle->object, &nmea_data);
1255         if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1256                 //LCOV_EXCL_START
1257                 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1258                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1259                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1260                 }
1261
1262                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1263                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1264                 //LCOV_EXCL_STOP
1265         }
1266
1267         *nmea = g_strdup(nmea_data);
1268         g_free(nmea_data);
1269
1270         return LOCATIONS_ERROR_NONE;
1271 }
1272
1273 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1274 {
1275         LOCATIONS_LOGD("gps_status_get_satellite");
1276         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1277         LOCATIONS_NULL_ARG_CHECK(manager);
1278         LOCATIONS_NULL_ARG_CHECK(num_of_active);
1279         LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1280         LOCATIONS_NULL_ARG_CHECK(timestamp);
1281         location_manager_s *handle = (location_manager_s *) manager;
1282         LocationSatellite *sat = NULL;
1283         int ret = location_get_satellite(handle->object, &sat);
1284         if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1285                 //LCOV_EXCL_START
1286                 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1287                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1288                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1289                 }
1290
1291                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1292                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1293                 //LCOV_EXCL_STOP
1294         }
1295
1296         *num_of_active = sat->num_of_sat_used;
1297         *num_of_inview = sat->num_of_sat_inview;
1298         *timestamp = sat->timestamp;
1299         location_satellite_free(sat);
1300         sat = NULL;
1301         return LOCATIONS_ERROR_NONE;
1302 }
1303
1304 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1305 {
1306         LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1307         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1308         LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1309         LOCATIONS_NULL_ARG_CHECK(manager);
1310         LOCATIONS_NULL_ARG_CHECK(callback);
1311
1312         location_manager_s *handle = (location_manager_s *) manager;
1313         int ret = location_set_option(handle->object, "USE_SV");
1314         if (ret != LOCATION_ERROR_NONE) {
1315                 //LCOV_EXCL_START
1316                 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1317                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1318                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1319                 }
1320                 return ret;
1321                 //LCOV_EXCL_STOP
1322         }
1323         g_object_set(handle->object, "sat-interval", interval, NULL);
1324         return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1325 }
1326
1327 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1328 {
1329         LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1330         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1331         return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1332 }
1333
1334 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1335 {
1336         LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1337         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1338         LOCATIONS_NULL_ARG_CHECK(manager);
1339         LOCATIONS_NULL_ARG_CHECK(callback);
1340
1341         location_manager_s *handle = (location_manager_s *) manager;
1342         LocationSatellite *sat = NULL;
1343         int ret = location_get_satellite(handle->object, &sat);
1344         //LCOV_EXCL_START
1345         if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1346                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1347                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1348                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1349                 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1350                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1351                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1352                 }
1353
1354                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1355                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1356         }
1357         //LCOV_EXCL_STOP
1358
1359         int i;
1360         for (i = 0; i < sat->num_of_sat_inview; i++) {
1361                 guint prn;
1362                 gboolean used;
1363                 guint elevation;
1364                 guint azimuth;
1365                 gint snr;
1366                 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1367                 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1368                         break;
1369         }
1370         location_satellite_free(sat);
1371         sat = NULL;
1372         return LOCATIONS_ERROR_NONE;
1373 }
1374
1375 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1376 {
1377         LOCATIONS_LOGD("gps_status_get_last_satellite");
1378         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1379         LOCATIONS_NULL_ARG_CHECK(manager);
1380         LOCATIONS_NULL_ARG_CHECK(num_of_active);
1381         LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1382         LOCATIONS_NULL_ARG_CHECK(timestamp);
1383
1384         location_manager_s *handle = (location_manager_s *) manager;
1385         int ret = LOCATION_ERROR_NONE;
1386         LocationSatellite *last_sat = NULL;
1387         ret = location_get_last_satellite(handle->object, &last_sat);
1388         if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1389                 //LCOV_EXCL_START
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                 //LCOV_EXCL_STOP
1401         }
1402
1403         *num_of_active = last_sat->num_of_sat_used;
1404         *num_of_inview = last_sat->num_of_sat_inview;
1405         *timestamp = last_sat->timestamp;
1406         location_satellite_free(last_sat);
1407         return LOCATIONS_ERROR_NONE;
1408 }
1409
1410 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1411 {
1412         LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1413         LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1414         LOCATIONS_NULL_ARG_CHECK(manager);
1415         LOCATIONS_NULL_ARG_CHECK(callback);
1416         location_manager_s *handle = (location_manager_s *) manager;
1417         int ret = LOCATION_ERROR_NONE;
1418         LocationSatellite *last_sat = NULL;
1419
1420         ret = location_get_last_satellite(handle->object, &last_sat);
1421         if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1422                 //LCOV_EXCL_START
1423                 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1424                         LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1425                         return LOCATIONS_ERROR_INCORRECT_METHOD;
1426                 }
1427
1428                 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1429                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1430                 //LCOV_EXCL_STOP
1431         }
1432
1433         int i;
1434         for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1435                 guint prn;
1436                 gboolean used;
1437                 guint elevation;
1438                 guint azimuth;
1439                 gint snr;
1440                 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1441                 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1442                         break;
1443         }
1444         location_satellite_free(last_sat);
1445         return LOCATIONS_ERROR_NONE;
1446 }
1447
1448
1449 /**
1450  * Tizen 3.0
1451  */
1452 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)
1453 {
1454         LOCATIONS_LOGD("location_manager_set_location_batch_cb");
1455         LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1456
1457 //LCOV_EXCL_START
1458         LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1459         LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1460         LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1461         LOCATIONS_NULL_ARG_CHECK(manager);
1462         LOCATIONS_NULL_ARG_CHECK(callback);
1463         location_manager_s *handle = (location_manager_s *) manager;
1464         g_object_set(handle->object, "batch-period", batch_period, NULL);
1465         g_object_set(handle->object, "batch-interval", batch_interval, NULL);
1466         return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
1467 //LCOV_EXCL_STOP
1468 }
1469
1470 EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
1471 {
1472         LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
1473         LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1474         return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);  //LCOV_EXCL_LINE
1475 }
1476
1477 EXPORT_API int location_manager_start_batch(location_manager_h manager)
1478 {
1479         LOCATIONS_LOGD("location_manager_start_batch");
1480         LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1481
1482 //LCOV_EXCL_START
1483         LOCATIONS_NULL_ARG_CHECK(manager);
1484         location_manager_s *handle = (location_manager_s *) manager;
1485
1486         if (LOCATIONS_METHOD_GPS == handle->method) {
1487                 if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED])
1488                         handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
1489         } else {
1490                 LOCATIONS_LOGE("method is not GPS [LOCATIONS_ERROR_INCORRECT_METHOD]");
1491                 return LOCATIONS_ERROR_INCORRECT_METHOD;
1492         }
1493
1494         if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
1495                 LOCATIONS_LOGD("batch status set : Start");
1496
1497         int ret = location_start_batch(handle->object);
1498         if (ret != LOCATION_ERROR_NONE)
1499                 return __convert_error_code(ret);
1500
1501         return LOCATIONS_ERROR_NONE;
1502 //LCOV_EXCL_STOP
1503 }
1504
1505 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
1506 {
1507         LOCATIONS_LOGD("location_manager_stop_batch");
1508         LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1509
1510 //LCOV_EXCL_START
1511         LOCATIONS_NULL_ARG_CHECK(manager);
1512         location_manager_s *handle = (location_manager_s *) manager;
1513
1514         if (LOCATIONS_METHOD_GPS == handle->method) {
1515                 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
1516                         g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
1517                         handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
1518                 }
1519         }
1520
1521         int ret = location_stop_batch(handle->object);
1522         if (ret != LOCATION_ERROR_NONE)
1523                 return __convert_error_code(ret);
1524
1525         return LOCATIONS_ERROR_NONE;
1526 //LCOV_EXCL_STOP
1527 }
1528
1529 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
1530 {
1531         LOCATIONS_LOGD("location_manager_foreach_location_batch");
1532         LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1533 //LCOV_EXCL_START
1534         LOCATIONS_NULL_ARG_CHECK(manager);
1535         LOCATIONS_NULL_ARG_CHECK(callback);
1536         location_manager_s *handle = (location_manager_s *) manager;
1537         LocationBatch *batch = NULL;
1538
1539         int ret = location_get_batch(handle->object, &batch);
1540         if (ret != LOCATION_ERROR_NONE || batch == NULL) {
1541                 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1542                         LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1543                         return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1544                 }
1545
1546                 LOCATIONS_LOGE("Batch is NULL [LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE]");
1547                 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1548         }
1549
1550         int i;
1551         for (i = 0; i < batch->num_of_location; i++) {
1552                 gdouble latitude;
1553                 gdouble longitude;
1554                 gdouble altitude;
1555                 gdouble speed;
1556                 gdouble direction;
1557                 gdouble h_accuracy;
1558                 gdouble v_accuracy;
1559                 guint timestamp;
1560
1561                 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, &timestamp);
1562                 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
1563                         break;
1564         }
1565         location_batch_free(batch);
1566         batch = NULL;
1567         return LOCATIONS_ERROR_NONE;
1568 //LCOV_EXCL_STOP
1569 }
1570
1571 EXPORT_API int location_manager_is_enabled_mock_location(bool *enabled)
1572 {
1573         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1574         LOCATIONS_NULL_ARG_CHECK(enabled);
1575         int is_enabled_val = -1;
1576         int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &is_enabled_val);
1577         if (ret != LOCATION_ERROR_NONE)
1578                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
1579
1580         if (is_enabled_val == -1)
1581                 return TIZEN_ERROR_PERMISSION_DENIED;   //LCOV_EXCL_LINE
1582
1583         *enabled = (is_enabled_val == 0) ? FALSE : TRUE;
1584         return LOCATIONS_ERROR_NONE;
1585 }
1586
1587 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1588 {
1589         LOCATIONS_LOGD("enable: %d", enable);
1590         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1591         int ret = LOCATION_ERROR_NONE;
1592
1593         ret = location_enable_mock(enable);
1594         return __convert_error_code(ret);
1595 }
1596
1597 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1598         const double speed, const double direction, const double accuracy)
1599 {
1600         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1601         LOCATIONS_NULL_ARG_CHECK(manager);
1602
1603         LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1604         LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1605         LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1606
1607         location_manager_s *handle = (location_manager_s *) manager;
1608         int ret = LOCATION_ERROR_NONE;
1609         int enabled;
1610         LocationPosition *pos = NULL;
1611         LocationVelocity *vel = NULL;
1612         LocationAccuracy *acc = NULL;
1613
1614         ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1615         LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1616         if (ret == LOCATIONS_ERROR_NONE) {
1617                 if (enabled == 0)
1618                         return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1619         } else {
1620                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
1621         }
1622
1623         pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1624         if (!pos) {
1625                 LOCATIONS_LOGE("Failed to create position");    //LCOV_EXCL_LINE
1626                 return LOCATIONS_ERROR_OUT_OF_MEMORY;   //LCOV_EXCL_LINE
1627         }
1628         vel = location_velocity_new(0, speed, direction, 0);
1629         if (!vel) {
1630                 //LCOV_EXCL_START
1631                 LOCATIONS_LOGE("Failed to create velocity");
1632                 location_position_free(pos);
1633                 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1634                 //LCOV_EXCL_STOP
1635         }
1636
1637         acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1638         if (!acc) {
1639                 //LCOV_EXCL_START
1640                 LOCATIONS_LOGE("Failed to create accuracy");
1641                 location_position_free(pos);
1642                 location_velocity_free(vel);
1643                 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1644                 //LCOV_EXCL_STOP
1645         }
1646
1647         ret = location_set_mock_location(handle->object, pos, vel, acc);
1648         if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1649                 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1650                 return LOCATIONS_ERROR_INCORRECT_METHOD;
1651         }
1652
1653         location_position_free(pos);
1654         location_velocity_free(vel);
1655         location_accuracy_free(acc);
1656
1657         return __convert_error_code(ret);
1658 }
1659
1660 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1661 {
1662         LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1663         LOCATIONS_NULL_ARG_CHECK(manager);
1664
1665         location_manager_s *handle = (location_manager_s *) manager;
1666         int enabled;
1667
1668         int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1669         LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1670         if (ret == LOCATIONS_ERROR_NONE) {
1671                 if (enabled == 0)
1672                         return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1673         } else {
1674                 return __convert_error_code(ret);       //LCOV_EXCL_LINE
1675         }
1676
1677         ret = location_clear_mock_location(handle->object);
1678         if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1679                 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1680                 return LOCATIONS_ERROR_INCORRECT_METHOD;
1681         }
1682
1683         return __convert_error_code(ret);
1684 }