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