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