2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <locations_private.h>
26 #define LOG_TAG "TIZEN_N_LOCATION_MANAGER"
31 #define LOCATIONS_CHECK_CONDITION(condition,error,msg) \
32 if(condition) {} else \
33 { LOGE("[%s] %s(0x%08x)",__FUNCTION__, msg,error); return error;}; \
35 #define LOCATIONS_NULL_ARG_CHECK(arg) \
36 LOCATIONS_CHECK_CONDITION(arg != NULL,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER")
40 * Internal Implementation
43 static int __convert_error_code(int code,char *func_name)
46 char* msg = "LOCATIONS_ERROR_NONE";
49 case LOCATION_ERROR_NONE:
50 ret = LOCATIONS_ERROR_NONE;
51 msg = "LOCATIONS_ERROR_NONE";
53 case LOCATION_ERROR_NETWORK_FAILED:
54 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
55 ret = LOCATIONS_ERROR_NETWORK_FAILED;
56 msg = "LOCATIONS_ERROR_NETWORK_FAILED";
58 case LOCATION_ERROR_NOT_ALLOWED:
59 ret = LOCATIONS_ERROR_GPS_SETTING_OFF;
60 msg = "LOCATIONS_ERROR_GPS_SETTING_OFF";
62 case LOCATION_ERROR_NOT_AVAILABLE:
63 case LOCATION_ERROR_CONFIGURATION:
64 case LOCATION_ERROR_PARAMETER:
65 case LOCATION_ERROR_UNKNOWN:
67 msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE";
68 ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
70 LOGE("[%s] %s(0x%08x) : core fw error(0x%x)",func_name,msg, ret, code);
74 static void __cb_service_updated (GObject *self, guint type, gpointer data, gpointer accuracy, gpointer userdata)
76 LOGI("[%s] Callback function has been invoked. ",__FUNCTION__);
77 location_manager_s * handle = (location_manager_s*)userdata;
78 if( type == VELOCITY_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])
80 LocationVelocity *vel = (LocationVelocity*) data;
81 LOGI("[%s] Current velocity: timestamp : %d, speed: %f, direction : %f, climb : %f", __FUNCTION__ , vel->timestamp, vel->speed, vel->direction, vel->climb);
82 ((location_velocity_updated_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction,vel->climb, vel->timestamp ,handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
84 if( type == POSITION_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])
86 LocationPosition *pos = (LocationPosition*) data;
87 LOGI("[%s] Current position: timestamp : %d, latitude : %f, altitude: %f, longitude: %f", __FUNCTION__ , pos->timestamp, pos->latitude, pos->altitude, pos->longitude);
88 ((location_position_updated_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude,pos->altitude, pos->timestamp ,handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
92 static void __cb_service_enabled (GObject *self, guint status, gpointer userdata)
94 LOGI("[%s] Callback function has been invoked. ",__FUNCTION__);
95 location_manager_s * handle = (location_manager_s*)userdata;
96 if(handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
98 ((location_service_state_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED,handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
102 static void __cb_service_disabled (GObject *self, guint status, gpointer userdata)
104 LOGI("[%s] Callback function has been invoked. ",__FUNCTION__);
105 location_manager_s * handle = (location_manager_s*)userdata;
106 if( handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE] )
107 ((location_service_state_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED,handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
110 static void __cb_zone_in (GObject *self, guint type, gpointer position, gpointer accuracy, gpointer userdata)
112 location_manager_s * handle = (location_manager_s*)userdata;
113 if( handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY] )
115 LocationPosition *pos = (LocationPosition*) position;
116 ((location_zone_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN, pos->latitude,pos->longitude,pos->altitude, pos->timestamp ,handle->user_data[_LOCATIONS_EVENT_TYPE_BOUNDARY]);
120 static void __cb_zone_out (GObject *self, guint type, gpointer position, gpointer accuracy, gpointer userdata)
122 location_manager_s * handle = (location_manager_s*)userdata;
123 if( handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY] )
125 LocationPosition *pos = (LocationPosition*) position;
126 ((location_zone_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT, pos->latitude,pos->longitude,pos->altitude, pos->timestamp ,handle->user_data[_LOCATIONS_EVENT_TYPE_BOUNDARY]);
130 static int __set_callback(_location_event_e type, location_manager_h manager, void* callback, void *user_data)
132 LOCATIONS_NULL_ARG_CHECK(manager);
133 LOCATIONS_NULL_ARG_CHECK(callback);
134 location_manager_s * handle = (location_manager_s *) manager;
135 handle->user_cb[type] = callback;
136 handle->user_data[type] = user_data;
137 LOGI("[%s] event type : %d. ",__FUNCTION__, type);
138 return LOCATIONS_ERROR_NONE;
141 static int __unset_callback(_location_event_e type, location_manager_h manager)
143 LOCATIONS_NULL_ARG_CHECK(manager);
144 location_manager_s * handle = (location_manager_s *) manager;
145 handle->user_cb[type] = NULL;
146 handle->user_data[type] = NULL;
147 LOGI("[%s] event type : %d. ",__FUNCTION__, type);
148 return LOCATIONS_ERROR_NONE;
151 static void __remove_boundary(LocationBoundary *boundary, void *user_data)
153 LocationObject* loc = (LocationObject*) user_data;
154 if (loc != NULL && boundary != NULL)
156 int ret = location_boundary_remove(loc, boundary);
157 if(ret != LOCATION_ERROR_NONE)
159 LOGI("[%s] Failed to remove boundary : 0x%x. ",__FUNCTION__, ret);
163 LOGI("[%s] Delete previous boundary - type : %d ",__FUNCTION__, boundary->type);
168 /////////////////////////////////////////
170 ////////////////////////////////////////
173 * Public Implementation
176 bool location_manager_is_supported_method(location_method_e method)
178 LocationMethod _method = LOCATION_METHOD_NONE;
181 case LOCATIONS_METHOD_HYBRID :
182 _method = LOCATION_METHOD_HYBRID;
184 case LOCATIONS_METHOD_GPS:
185 _method = LOCATION_METHOD_GPS;
187 case LOCATIONS_METHOD_WPS :
188 _method = LOCATION_METHOD_WPS;
190 case LOCATIONS_METHOD_SPS :
191 _method = LOCATION_METHOD_SPS;
194 _method = LOCATION_METHOD_NONE;
197 return location_is_supported_method(_method);
200 int location_manager_create(location_method_e method, location_manager_h* manager)
202 LOCATIONS_NULL_ARG_CHECK(manager);
203 if(location_init()!=LOCATION_ERROR_NONE)
204 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
206 LocationMethod _method = LOCATION_METHOD_NONE;
209 case LOCATIONS_METHOD_NONE :
210 _method = LOCATION_METHOD_NONE;
212 case LOCATIONS_METHOD_HYBRID :
213 _method = LOCATION_METHOD_HYBRID;
215 case LOCATIONS_METHOD_GPS:
216 _method = LOCATION_METHOD_GPS;
218 case LOCATIONS_METHOD_WPS :
219 _method = LOCATION_METHOD_WPS;
221 case LOCATIONS_METHOD_SPS :
222 _method = LOCATION_METHOD_SPS;
226 LOGE("[%s] LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",__FUNCTION__,LOCATIONS_ERROR_INVALID_PARAMETER, method);
227 return LOCATIONS_ERROR_INVALID_PARAMETER;
231 location_manager_s *handle = (location_manager_s*)malloc(sizeof(location_manager_s));
234 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
235 return LOCATIONS_ERROR_OUT_OF_MEMORY;
238 memset(handle, 0 , sizeof(location_manager_s));
240 handle->object = location_new(_method);
241 if(handle->object == NULL)
243 LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", __FUNCTION__, LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
245 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
247 handle->method = method;
248 handle->boundary= NULL;
249 *manager = (location_manager_h)handle;
250 return LOCATIONS_ERROR_NONE;
253 int location_manager_destroy(location_manager_h manager)
255 LOCATIONS_NULL_ARG_CHECK(manager);
256 location_manager_s *handle = (location_manager_s*)manager;
260 location_boundary_free(handle->boundary);
263 int ret = location_free(handle->object);
264 if(ret!=LOCATIONS_ERROR_NONE)
266 return __convert_error_code(ret,(char*)__FUNCTION__);
269 return LOCATIONS_ERROR_NONE;
272 int location_manager_start(location_manager_h manager)
274 LOCATIONS_NULL_ARG_CHECK(manager);
275 location_manager_s *handle = (location_manager_s*)manager;
277 g_signal_connect (handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
278 g_signal_connect (handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
279 g_signal_connect (handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
280 g_signal_connect (handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
281 g_signal_connect (handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
283 int ret = location_start (handle->object);
284 if( ret != LOCATION_ERROR_NONE)
286 return __convert_error_code(ret,(char*)__FUNCTION__);
288 return LOCATIONS_ERROR_NONE;
291 int location_manager_stop(location_manager_h manager)
293 LOCATIONS_NULL_ARG_CHECK(manager);
294 location_manager_s *handle = (location_manager_s*)manager;
296 int ret = location_stop (handle->object);
297 if( ret != LOCATION_ERROR_NONE)
299 return __convert_error_code(ret,(char*)__FUNCTION__);
301 return LOCATIONS_ERROR_NONE;
304 int location_manager_set_boundary_rect(location_manager_h manager, double top_left_latitude,double top_left_longitude,double bottom_right_latitude,double bottom_right_longitude)
306 LOCATIONS_NULL_ARG_CHECK(manager);
307 LOCATIONS_CHECK_CONDITION(top_left_latitude>=-90 && top_left_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
308 LOCATIONS_CHECK_CONDITION(top_left_longitude>=-180 && bottom_right_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
309 LOCATIONS_CHECK_CONDITION(bottom_right_latitude>=-90 && bottom_right_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
310 LOCATIONS_CHECK_CONDITION(bottom_right_longitude>=-180 && bottom_right_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
312 location_manager_s *handle = (location_manager_s*)manager;
315 ret = location_boundary_foreach(handle->object, __remove_boundary,handle->object );
316 if(ret != LOCATION_ERROR_NONE)
318 LOGI("[%s] Failed to foreach boundary : 0x%x. ",__FUNCTION__, ret);
321 LocationPosition *rb = location_position_new(0, bottom_right_latitude, bottom_right_longitude, 0, LOCATION_STATUS_2D_FIX);
324 LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
325 return LOCATIONS_ERROR_OUT_OF_MEMORY;
327 LocationPosition *lt = location_position_new(0, top_left_latitude, top_left_longitude, 0, LOCATION_STATUS_2D_FIX);
330 LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
331 location_position_free (rb);
332 return LOCATIONS_ERROR_OUT_OF_MEMORY;
335 LocationBoundary* bound = NULL;
336 bound = location_boundary_new_for_rect(lt, rb);
337 location_position_free (rb);
338 location_position_free (lt);
342 ret = location_boundary_add(handle->object, bound);
345 location_boundary_free(handle->boundary);
346 handle->boundary = NULL;
348 handle->boundary = location_boundary_copy(bound);
349 location_boundary_free(bound);
350 if( ret != LOCATION_ERROR_NONE)
352 return __convert_error_code(ret,(char*)__FUNCTION__);
357 LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_rect", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
358 return LOCATIONS_ERROR_OUT_OF_MEMORY;
360 return LOCATIONS_ERROR_NONE;
363 int location_manager_set_boundary_circle(location_manager_h manager, double center_latitude,double center_longitude, double radius)
365 LOCATIONS_NULL_ARG_CHECK(manager);
367 LOCATIONS_CHECK_CONDITION(center_latitude>=-90 && center_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
368 LOCATIONS_CHECK_CONDITION(center_longitude>=-180 && center_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
369 LOCATIONS_CHECK_CONDITION(radius>=0,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
371 location_manager_s *handle = (location_manager_s*)manager;
374 ret = location_boundary_foreach(handle->object, __remove_boundary, handle->object);
375 if(ret != LOCATION_ERROR_NONE)
377 LOGI("[%s] Failed to foreach boundary : 0x%x. ",__FUNCTION__, ret);
380 LocationPosition *center = location_position_new(0, center_latitude, center_longitude, 0, LOCATION_STATUS_2D_FIX);
383 LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
384 return LOCATIONS_ERROR_OUT_OF_MEMORY;
387 LocationBoundary* bound = NULL;
388 bound = location_boundary_new_for_circle(center,radius);
389 location_position_free (center);
392 ret = location_boundary_add(handle->object, bound);
395 location_boundary_free(handle->boundary);
396 handle->boundary = NULL;
398 handle->boundary = location_boundary_copy(bound);
399 location_boundary_free(bound);
400 if( ret != LOCATION_ERROR_NONE)
402 return __convert_error_code(ret,(char*)__FUNCTION__);
407 LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_circle", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
408 return LOCATIONS_ERROR_OUT_OF_MEMORY;
410 return LOCATIONS_ERROR_NONE;
413 int location_manager_is_boundary_contains_coordinate(location_manager_h manager, double latitude, double longitude, bool *contained)
415 LOCATIONS_NULL_ARG_CHECK(manager);
416 LOCATIONS_NULL_ARG_CHECK(contained);
418 LOCATIONS_CHECK_CONDITION(latitude>=-90 && latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
419 LOCATIONS_CHECK_CONDITION(longitude>=-180 && longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
421 location_manager_s *handle = (location_manager_s*)manager;
423 if(handle->boundary==NULL)
425 LOGI("[%s] There is no boundary ",__FUNCTION__);
427 return LOCATIONS_ERROR_NONE;
430 LocationPosition *pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_2D_FIX);
433 LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", __FUNCTION__, LOCATIONS_ERROR_OUT_OF_MEMORY);
435 return LOCATIONS_ERROR_OUT_OF_MEMORY;
437 gboolean is_inside = location_boundary_if_inside(handle->boundary, pos);
447 location_position_free (pos);
448 return LOCATIONS_ERROR_NONE;
451 int location_manager_get_method(location_manager_h manager, location_method_e* method)
453 LOCATIONS_NULL_ARG_CHECK(manager);
454 LOCATIONS_NULL_ARG_CHECK(method);
455 location_manager_s *handle = (location_manager_s*)manager;
456 LocationMethod _method = LOCATION_METHOD_NONE;
457 g_object_get(handle->object, "method", &_method, NULL);
460 case LOCATION_METHOD_NONE :
461 *method = LOCATIONS_METHOD_NONE;
463 case LOCATION_METHOD_HYBRID :
464 case LOCATION_METHOD_CPS:
465 case LOCATION_METHOD_IPS :
466 *method = LOCATIONS_METHOD_HYBRID;
468 case LOCATION_METHOD_GPS:
469 *method = LOCATIONS_METHOD_GPS;
471 case LOCATION_METHOD_WPS :
472 *method = LOCATIONS_METHOD_WPS;
474 case LOCATION_METHOD_SPS :
475 *method = LOCATIONS_METHOD_SPS;
479 LOGE("[%s] LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",__FUNCTION__,LOCATIONS_ERROR_INVALID_PARAMETER, method);
480 return LOCATIONS_ERROR_INVALID_PARAMETER;
483 //*method = handle->method;
484 return LOCATIONS_ERROR_NONE;
488 int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
490 LOCATIONS_NULL_ARG_CHECK(manager);
491 LOCATIONS_NULL_ARG_CHECK(altitude);
492 LOCATIONS_NULL_ARG_CHECK(latitude);
493 LOCATIONS_NULL_ARG_CHECK(longitude);
494 LOCATIONS_NULL_ARG_CHECK(timestamp);
496 location_manager_s *handle = (location_manager_s*)manager;
498 LocationPosition *pos = NULL;
499 LocationAccuracy *acc = NULL;
500 ret = location_get_position(handle->object, &pos, &acc);
501 if( ret != LOCATION_ERROR_NONE)
503 return __convert_error_code(ret,(char*)__FUNCTION__);
506 if(pos->status == LOCATION_STATUS_NO_FIX)
514 if(pos->status == LOCATION_STATUS_3D_FIX)
516 *altitude = pos->altitude;
522 *latitude = pos->latitude;
523 *longitude = pos->longitude;
525 *timestamp = pos->timestamp;
526 location_position_free (pos);
527 location_accuracy_free (acc);
528 return LOCATIONS_ERROR_NONE;
531 int location_manager_get_velocity(location_manager_h manager, int *climb, int *direction, int *speed, time_t *timestamp)
533 LOCATIONS_NULL_ARG_CHECK(manager);
534 LOCATIONS_NULL_ARG_CHECK(climb);
535 LOCATIONS_NULL_ARG_CHECK(direction);
536 LOCATIONS_NULL_ARG_CHECK(speed);
537 LOCATIONS_NULL_ARG_CHECK(timestamp);
539 location_manager_s *handle = (location_manager_s*)manager;
541 LocationVelocity *vel = NULL;
542 LocationAccuracy *acc = NULL;
543 ret = location_get_velocity(handle->object, &vel, &acc);
544 if( ret != LOCATION_ERROR_NONE)
546 return __convert_error_code(ret,(char*)__FUNCTION__);
550 *direction = vel->direction;
552 *timestamp = vel->timestamp;
553 location_velocity_free(vel);
554 location_accuracy_free(acc);
555 return LOCATIONS_ERROR_NONE;
558 int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
560 LOCATIONS_NULL_ARG_CHECK(manager);
561 LOCATIONS_NULL_ARG_CHECK(level);
562 LOCATIONS_NULL_ARG_CHECK(horizontal);
563 LOCATIONS_NULL_ARG_CHECK(vertical);
564 location_manager_s *handle = (location_manager_s*)manager;
567 LocationPosition *pos = NULL;
568 LocationAccuracy *acc = NULL;
569 ret = location_get_position(handle->object, &pos, &acc);
570 if( ret != LOCATION_ERROR_NONE)
572 return __convert_error_code(ret,(char*)__FUNCTION__);
576 *horizontal = acc->horizontal_accuracy;
577 *vertical = acc->vertical_accuracy;
578 location_position_free(pos);
579 location_accuracy_free(acc);
580 return LOCATIONS_ERROR_NONE;
583 int location_manager_get_last_known_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
585 LOCATIONS_NULL_ARG_CHECK(manager);
586 LOCATIONS_NULL_ARG_CHECK(altitude);
587 LOCATIONS_NULL_ARG_CHECK(latitude);
588 LOCATIONS_NULL_ARG_CHECK(longitude);
589 LOCATIONS_NULL_ARG_CHECK(timestamp);
591 location_manager_s *handle = (location_manager_s*)manager;
593 LocationMethod _method = LOCATION_METHOD_NONE;
594 g_object_get(handle->object, "method", &_method, NULL);
597 LocationPosition *pos = NULL;
598 LocationAccuracy *acc = NULL;
599 ret = location_get_last_position(handle->object, _method, &pos,&acc);
600 if (ret == LOCATION_ERROR_UNKNOWN)
606 LOGI("[%s] There is no record of any previous position information. ",__FUNCTION__);
607 return LOCATIONS_ERROR_NONE;
609 else if( ret != LOCATION_ERROR_NONE)
611 return __convert_error_code(ret,(char*)__FUNCTION__);
614 *altitude = pos->altitude;
615 *latitude = pos->latitude;
616 *longitude = pos->longitude;
617 *timestamp = pos->timestamp;
618 location_position_free(pos);
619 location_accuracy_free(acc);
620 return LOCATIONS_ERROR_NONE;
623 int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
625 LOCATIONS_CHECK_CONDITION(interval>=1 && interval<=120, LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
626 LOCATIONS_NULL_ARG_CHECK(manager);
627 location_manager_s *handle = (location_manager_s*)manager;
628 g_object_set(handle->object, "update-interval", interval, NULL);
629 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION,manager,callback,user_data);
632 int location_manager_unset_position_updated_cb(location_manager_h manager)
634 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION,manager);
637 int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, void *user_data)
639 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY,manager,callback,user_data);
642 int location_manager_unset_velocity_updated_cb(location_manager_h manager)
644 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY,manager);
647 int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback, void *user_data)
649 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE,manager,callback,user_data);
652 int location_manager_unset_service_state_changed_cb(location_manager_h manager)
654 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE,manager);
657 int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
659 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY,manager,callback,user_data);
662 int location_manager_unset_zone_changed_cb(location_manager_h manager)
664 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY,manager);
667 /////////////////////////////////////////
668 // GPS Status & Satellites
669 ////////////////////////////////////////
671 int gps_status_get_nmea(location_manager_h manager, char** nmea)
673 LOCATIONS_NULL_ARG_CHECK(manager);
674 LOCATIONS_NULL_ARG_CHECK(nmea);
675 location_manager_s *handle = (location_manager_s*)manager;
677 if(handle->method == LOCATIONS_METHOD_HYBRID)
679 LocationMethod _method = LOCATION_METHOD_NONE;
680 g_object_get(handle->object, "method", &_method, NULL);
681 if(_method!=LOCATION_METHOD_GPS)
683 LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
684 return LOCATIONS_ERROR_INCORRECT_METHOD;
687 else if(handle->method != LOCATIONS_METHOD_GPS)
689 LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
690 return LOCATIONS_ERROR_INCORRECT_METHOD;
692 gchar* nmea_data = NULL;
693 g_object_get(handle->object, "nmea", &nmea_data, NULL);
694 if(nmea_data == NULL)
696 LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : nmea data is NULL ",__FUNCTION__,LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
697 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
700 *nmea = strdup(nmea_data);
703 LOGE("[%s] LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to strdup ",__FUNCTION__,LOCATIONS_ERROR_OUT_OF_MEMORY);
704 return LOCATIONS_ERROR_OUT_OF_MEMORY;
707 return LOCATIONS_ERROR_NONE;
710 int gps_status_get_satellite_count_in_view(location_manager_h manager, int *count)
712 LOCATIONS_NULL_ARG_CHECK(manager);
713 LOCATIONS_NULL_ARG_CHECK(count);
714 location_manager_s *handle = (location_manager_s*)manager;
715 if(handle->method == LOCATIONS_METHOD_HYBRID)
717 LocationMethod _method = LOCATION_METHOD_NONE;
718 g_object_get(handle->object, "method", &_method, NULL);
719 if(_method!=LOCATION_METHOD_GPS)
721 LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
722 return LOCATIONS_ERROR_INCORRECT_METHOD;
725 else if(handle->method != LOCATIONS_METHOD_GPS)
727 LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
728 return LOCATIONS_ERROR_INCORRECT_METHOD;
731 LocationSatellite *sat = NULL;
732 g_object_get (handle->object, "satellite", &sat, NULL);
735 LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",__FUNCTION__,LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
736 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
738 *count = sat->num_of_sat_inview;
739 location_satellite_free (sat);
741 return LOCATIONS_ERROR_NONE;
744 int gps_status_foreach_satellites_in_view (location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
746 LOCATIONS_NULL_ARG_CHECK(manager);
747 LOCATIONS_NULL_ARG_CHECK(callback);
748 location_manager_s *handle = (location_manager_s*)manager;
749 if(handle->method == LOCATIONS_METHOD_HYBRID)
751 LocationMethod _method = LOCATION_METHOD_NONE;
752 g_object_get(handle->object, "method", &_method, NULL);
753 if(_method!=LOCATION_METHOD_GPS)
755 LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
756 return LOCATIONS_ERROR_INCORRECT_METHOD;
759 else if(handle->method != LOCATIONS_METHOD_GPS)
761 LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
762 return LOCATIONS_ERROR_INCORRECT_METHOD;
765 LocationSatellite *sat = NULL;
766 g_object_get (handle->object, "satellite", &sat, NULL);
769 LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",__FUNCTION__,LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
770 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
774 for (i=0; i<sat->num_of_sat_inview; i++)
781 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
782 if ( callback(azimuth, elevation, prn, snr, used, user_data) != TRUE )
785 location_satellite_free (sat);
787 return LOCATIONS_ERROR_NONE;
790 int gps_status_get_active_satellite_count(location_manager_h manager, int *count)
792 LOCATIONS_NULL_ARG_CHECK(manager);
793 LOCATIONS_NULL_ARG_CHECK(count);
794 location_manager_s *handle = (location_manager_s*)manager;
795 if(handle->method == LOCATIONS_METHOD_HYBRID)
797 LocationMethod _method = LOCATION_METHOD_NONE;
798 g_object_get(handle->object, "method", &_method, NULL);
799 if(_method!=LOCATION_METHOD_GPS)
801 LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
802 return LOCATIONS_ERROR_INCORRECT_METHOD;
805 else if(handle->method != LOCATIONS_METHOD_GPS)
807 LOGE("[%s] LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", __FUNCTION__, LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
808 return LOCATIONS_ERROR_INCORRECT_METHOD;
811 LocationSatellite *sat = NULL;
812 g_object_get (handle->object, "satellite", &sat, NULL);
815 LOGE("[%s] LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",__FUNCTION__,LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
816 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
818 *count = sat->num_of_sat_used;
819 location_satellite_free (sat);
821 return LOCATIONS_ERROR_NONE;