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