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