removed wrong contacts, added authors
[platform/core/location/lbs-location.git] / location / manager / location-gps.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <app_manager.h>
24 #include <sensor.h>
25 #include "location-setting.h"
26 #include "location-log.h"
27
28 #include "module-internal.h"
29
30 #include "location-gps.h"
31 #include "location-marshal.h"
32 #include "location-ielement.h"
33 #include "location-signaling-util.h"
34 #include "location-common-util.h"
35
36 #include <vconf-internal-location-keys.h>
37
38 typedef struct _LocationGpsPrivate {
39         LocationGpsMod          *mod;
40         GMutex                          mutex;
41         gboolean                        is_started;
42         gboolean                        is_batch_invoked;
43         gboolean                        is_mock;
44         gboolean                        set_noti;
45         gboolean                        enabled;
46         gint                            signal_type;
47         guint                           app_type;
48         guint                           pos_updated_timestamp;
49         guint                           vel_updated_timestamp;
50         guint                           sat_updated_timestamp;
51         guint                           loc_updated_timestamp;
52         guint                           dist_updated_timestamp;
53         guint                           pos_interval;
54         guint                           vel_interval;
55         guint                           sat_interval;
56         guint                           loc_interval;
57         guint                           optimized_interval;
58         guint                           loc_timeout;
59         guint                           batch_interval;
60         guint                           batch_period;
61         guint                           min_interval;
62         gdouble                         min_distance;
63         LocationPosition        *pos;
64         LocationBatch           *batch;
65         LocationVelocity        *vel;
66         LocationAccuracy        *acc;
67         LocationSatellite       *sat;
68         GList                           *boundary_list;
69 #if defined(TIZEN_DEVICE)
70         sensor_h sensor;
71         sensor_listener_h sensor_listener;
72 #endif
73 } LocationGpsPrivate;
74
75 enum {
76         PROP_0,
77         PROP_METHOD_TYPE,
78         PROP_IS_STARTED,
79         PROP_LAST_POSITION,
80         PROP_POS_INTERVAL,
81         PROP_VEL_INTERVAL,
82         PROP_SAT_INTERVAL,
83         PROP_LOC_INTERVAL,
84         PROP_BATCH_INTERVAL,
85         PROP_BATCH_PERIOD,
86         PROP_BOUNDARY,
87         PROP_REMOVAL_BOUNDARY,
88         PROP_NMEA,
89         PROP_SATELLITE,
90         PROP_MIN_INTERVAL,
91         PROP_MIN_DISTANCE,
92         PROP_SERVICE_STATUS,
93         PROP_MAX
94 };
95
96 static guint32 signals[LAST_SIGNAL] = {0, };
97 static GParamSpec *properties[PROP_MAX] = {NULL, };
98
99 #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), LOCATION_TYPE_GPS, LocationGpsPrivate))
100
101 static void location_ielement_interface_init(LocationIElementInterface *iface);
102 static int location_gps_cancel_single_location(LocationGps *self);
103
104 G_DEFINE_TYPE_WITH_CODE(LocationGps, location_gps, G_TYPE_OBJECT,
105                                                 G_IMPLEMENT_INTERFACE(LOCATION_TYPE_IELEMENT, location_ielement_interface_init));
106
107 static void __reset_pos_data_from_priv(LocationGpsPrivate *priv)
108 {
109         LOC_FUNC_LOG
110         g_return_if_fail(priv);
111
112         if (priv->pos) {
113                 location_position_free(priv->pos);
114                 priv->pos = NULL;
115         }
116
117         if (priv->batch) {
118                 location_batch_free(priv->batch);
119                 priv->batch = NULL;
120         }
121
122         if (priv->vel) {
123                 location_velocity_free(priv->vel);
124                 priv->vel = NULL;
125         }
126
127         if (priv->sat) {
128                 location_satellite_free(priv->sat);
129                 priv->sat = NULL;
130         }
131
132         if (priv->acc) {
133                 location_accuracy_free(priv->acc);
134                 priv->acc = NULL;
135         }
136         priv->pos_updated_timestamp = 0;
137         priv->vel_updated_timestamp = 0;
138         priv->sat_updated_timestamp = 0;
139         priv->loc_updated_timestamp = 0;
140
141         priv->signal_type = 0;
142 }
143
144 static gboolean __get_started(gpointer self)
145 {
146         g_return_val_if_fail(self, FALSE);
147
148         LocationGpsPrivate *priv = GET_PRIVATE(self);
149         g_return_val_if_fail(priv, FALSE);
150
151         return priv->is_started;
152 }
153
154 static int __set_started(gpointer self, gboolean started)
155 {
156         g_return_val_if_fail(self, -1);
157
158         LocationGpsPrivate *priv = GET_PRIVATE(self);
159         g_return_val_if_fail(priv, -1);
160
161         if (priv->is_started != started) {
162                 g_mutex_lock(&priv->mutex);
163                 priv->is_started = started;
164                 g_mutex_unlock(&priv->mutex);
165         }
166
167         return 0;
168 }
169
170 static void gps_status_cb(gboolean enabled, LocationStatus status, gpointer self)
171 {
172         LOC_FUNC_LOG
173         g_return_if_fail(self);
174         LocationGpsPrivate *priv = GET_PRIVATE(self);
175         g_return_if_fail(priv);
176         if (!priv->enabled && enabled) {        /* Update satellite at searching status. */
177                 return; /* Ignored: Support to get position at enabled callback */
178         } else if (priv->enabled == TRUE && enabled == FALSE) {
179                 __set_started(self, FALSE);
180                 enable_signaling(self, signals, &(priv->enabled), enabled, status);
181         }
182 }
183
184 static void gps_location_cb(gboolean enabled, LocationPosition *pos, LocationVelocity *vel, LocationAccuracy *acc, gpointer self)
185 {
186         g_return_if_fail(self);
187         g_return_if_fail(pos);
188         g_return_if_fail(vel);
189         g_return_if_fail(acc);
190
191         LocationGpsPrivate *priv = GET_PRIVATE(self);
192         g_return_if_fail(priv);
193
194         if (priv->min_interval != LOCATION_UPDATE_INTERVAL_NONE) {
195                 distance_based_position_signaling(self, signals, enabled, pos, vel, acc,
196                                                         priv->min_interval, priv->min_distance, &(priv->enabled),
197                                                         &(priv->dist_updated_timestamp), &(priv->pos), &(priv->vel), &(priv->acc));
198         }
199         location_signaling(self, signals, enabled, priv->boundary_list, pos, vel, acc,
200                                                 priv->pos_interval, priv->vel_interval, priv->loc_interval, &(priv->enabled),
201                                                 &(priv->pos_updated_timestamp), &(priv->vel_updated_timestamp),
202                                                 &(priv->loc_updated_timestamp), &(priv->pos), &(priv->vel), &(priv->acc));
203 }
204
205 #ifndef TIZEN_DEVICE
206 static void gps_batch_cb(gboolean enabled, guint num_of_location, gpointer self)
207 {
208         g_return_if_fail(self);
209         LocationGpsPrivate *priv = GET_PRIVATE(self);
210         g_return_if_fail(priv);
211
212         if (priv->batch != NULL)
213                 location_batch_free(priv->batch);
214
215         priv->batch = location_get_batch_file(num_of_location);
216
217         g_signal_emit(self, signals[BATCH_UPDATED], 0, num_of_location);
218 }
219 #endif
220
221 static void gps_satellite_cb(gboolean enabled, LocationSatellite *sat, gpointer self)
222 {
223         g_return_if_fail(self);
224         LocationGpsPrivate *priv = GET_PRIVATE(self);
225         g_return_if_fail(priv);
226
227         satellite_signaling(self, signals, &(priv->enabled), priv->sat_interval, TRUE, &(priv->sat_updated_timestamp), &(priv->sat), sat);
228 }
229
230 static void location_setting_search_cb(keynode_t *key, gpointer self)
231 {
232         LOC_FUNC_LOG
233         g_return_if_fail(key);
234         g_return_if_fail(self);
235         LocationGpsPrivate *priv = GET_PRIVATE(self);
236         g_return_if_fail(priv);
237
238         if (location_setting_get_key_val(key) == VCONFKEY_LOCATION_GPS_SEARCHING) {
239                 if (!location_setting_get_int(VCONFKEY_LOCATION_MOCK_ENABLED)) {
240                         LOCATION_LOGD("enable_signaling : SERVICE_DISABLED");
241                         enable_signaling(self, signals, &(priv->enabled), FALSE, LOCATION_STATUS_NO_FIX);
242                 }
243         }
244 }
245
246 static void location_setting_gps_cb(keynode_t *key, gpointer self)
247 {
248         LOC_FUNC_LOG
249         g_return_if_fail(key);
250         g_return_if_fail(self);
251         LocationGpsPrivate *priv = GET_PRIVATE(self);
252         g_return_if_fail(priv);
253         g_return_if_fail(priv->mod);
254         g_return_if_fail(priv->mod->handler);
255
256         int ret = LOCATION_ERROR_NONE;
257
258         if (0 == location_setting_get_key_val(key) && priv->mod->ops.stop && __get_started(self)) {
259                 LOCATION_LOGD("location stopped by setting");
260                 __set_started(self, FALSE);
261                 ret = priv->mod->ops.stop(priv->mod->handler);
262                 if (ret == LOCATION_ERROR_NONE)
263                         __reset_pos_data_from_priv(priv);
264                 else
265                         LOCATION_LOGI("Fail to stop[%d]", ret);
266
267         } else if (1 == location_setting_get_key_val(key) && priv->mod->ops.start && !__get_started(self)) {
268                 LOCATION_LOGD("location resumed by setting");
269                 __set_started(self, TRUE);
270                 ret = priv->mod->ops.start(priv->mod->handler, priv->optimized_interval, gps_status_cb, gps_location_cb, gps_satellite_cb, self);
271                 if (ret != LOCATION_ERROR_NONE) {
272                         __set_started(self, FALSE);
273                         LOCATION_LOGI("Fail to start[%d]", ret);
274                 }
275         }
276 }
277
278 static int location_gps_start(LocationGps *self)
279 {
280         LOC_FUNC_LOG
281         LocationGpsPrivate *priv = GET_PRIVATE(self);
282         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
283         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
284         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
285         g_return_val_if_fail(priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE);
286
287         LOC_COND_RET(__get_started(self) == TRUE, LOCATION_ERROR_NONE, _E, "gps already started. Error[%s]", err_msg(LOCATION_ERROR_NONE));
288
289         int ret = LOCATION_ERROR_NONE;
290
291         if (!location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
292                 ret = LOCATION_ERROR_SETTING_OFF;
293         } else if (location_setting_get_int(VCONFKEY_SETAPPL_PSMODE) == SETTING_PSMODE_WEARABLE_ENHANCED) {
294                 return LOCATION_ACCESS_DENIED;
295         } else {
296                 __set_started(self, TRUE);
297                 ret = priv->mod->ops.start(priv->mod->handler, priv->optimized_interval, gps_status_cb, gps_location_cb, gps_satellite_cb, self);
298                 if (ret != LOCATION_ERROR_NONE) {
299                         LOCATION_LOGE("Fail to start gps. Error[%d]", ret);
300                         __set_started(self, FALSE);
301                         return ret;
302                 }
303         }
304
305         if (priv->app_type != CPPAPP && priv->set_noti == FALSE) {
306                 location_setting_add_notify(VCONFKEY_LOCATION_ENABLED, location_setting_gps_cb, self);
307                 location_state_add_notify(VCONFKEY_LOCATION_GPS_STATE, location_setting_search_cb, self);
308                 priv->set_noti = TRUE;
309         }
310
311         LOCATION_LOGD("EXIT <<<");
312         return ret;
313 }
314
315 static int location_gps_stop(LocationGps *self)
316 {
317         LOC_FUNC_LOG
318         LocationGpsPrivate *priv = GET_PRIVATE(self);
319         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
320         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
321         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
322         g_return_val_if_fail(priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE);
323
324         int ret = LOCATION_ERROR_NONE;
325
326         if (__get_started(self) == TRUE) {
327                 __set_started(self, FALSE);
328                 ret = priv->mod->ops.stop(priv->mod->handler);
329                 LOC_IF_FAIL_LOG(ret, _E, "Failed to stop [%s]", err_msg(ret));
330         } else {
331                 return LOCATION_ERROR_NONE;
332         }
333
334         if (priv->app_type != CPPAPP && priv->set_noti == TRUE) {
335                 location_setting_ignore_notify(VCONFKEY_LOCATION_ENABLED, location_setting_gps_cb);
336                 location_state_ignore_notify(VCONFKEY_LOCATION_GPS_STATE, location_setting_search_cb);
337                 priv->set_noti = FALSE;
338         }
339
340         __reset_pos_data_from_priv(priv);
341
342         return ret;
343 }
344
345 #if defined(TIZEN_DEVICE)
346 static void __sensor_event_cb(sensor_h s, sensor_event_s *event, void *data)
347 {
348         LocationGpsPrivate *priv = GET_PRIVATE(data);
349         g_return_if_fail(priv);
350         g_return_if_fail(event);
351
352         int remain_idx = (int)(event->values[4]);
353
354         if (priv->is_batch_invoked) {
355                 location_batch_free(priv->batch);
356                 priv->is_batch_invoked = FALSE;
357                 priv->batch = NULL;
358         }
359
360         if (priv->batch == NULL) {
361                 g_return_if_fail(event->value_count <= 5);
362                 priv->batch = location_batch_new(remain_idx + 1);
363                 g_return_if_fail(priv->batch);
364                 priv->batch->num_of_location = remain_idx + 1;
365                 time_t start;
366                 time(&start);
367                 priv->batch->start_time = start + (time_t)((event->timestamp / 1001000) % 100000);
368         }
369
370         location_set_sensor_batch(priv->batch, event);
371
372         if (remain_idx == 0) {
373                 g_signal_emit(data, signals[BATCH_UPDATED], 0, priv->batch->num_of_location);
374                 priv->is_batch_invoked = TRUE;
375         }
376 }
377
378 static int __set_sensor_batch(LocationGps *self, int batch_interval)
379 {
380         LOC_FUNC_LOG
381         LocationGpsPrivate *priv = GET_PRIVATE(self);
382         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
383
384         if (priv->batch != NULL) {
385                 location_batch_free(priv->batch);
386                 priv->batch = NULL;
387         }
388
389         int update_interval = batch_interval * 1000;    /* in ms */
390         int ret = 0;
391         bool supported = false;
392
393         ret = sensor_is_supported((sensor_type_e)0x1A02, &supported);
394         LOC_IF_FAIL(ret, _E, "Fail to sensor_is_supported [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
395         LOC_COND_RET(!supported, LOCATION_ERROR_NOT_SUPPORTED, _E, "Batch sensor is not supported [%s]", err_msg(LOCATION_ERROR_NOT_SUPPORTED));
396
397         ret = sensor_get_default_sensor((sensor_type_e)0x1A02, &priv->sensor);
398         LOC_IF_FAIL(ret, _E, "Fail to sensor_get_default_sensor [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
399
400         ret = sensor_create_listener(priv->sensor, &priv->sensor_listener);
401         LOC_IF_FAIL(ret, _E, "Fail to sensor_create_listener [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
402
403         ret = sensor_listener_set_event_cb(priv->sensor_listener, update_interval, __sensor_event_cb, self);
404         if (ret != SENSOR_ERROR_NONE) {
405                 LOCATION_LOGE("sensor_listener_set_event_cb() failed");
406                 sensor_destroy_listener(priv->sensor_listener);
407                 return LOCATION_ERROR_NOT_AVAILABLE;
408         }
409
410         ret = sensor_listener_set_option(priv->sensor_listener, SENSOR_OPTION_ALWAYS_ON);
411         if (ret != SENSOR_ERROR_NONE) {
412                 LOCATION_LOGE("sensor_listener_set_option() failed");
413                 sensor_destroy_listener(priv->sensor_listener);
414                 return LOCATION_ERROR_NOT_AVAILABLE;
415         }
416         ret = sensor_listener_start(priv->sensor_listener);
417         if (ret != SENSOR_ERROR_NONE) {
418                 LOCATION_LOGE("sensor_listener_set_event_cb() failed");
419                 sensor_destroy_listener(priv->sensor_listener);
420                 return LOCATION_ERROR_NOT_AVAILABLE;
421         }
422
423         return LOCATION_ERROR_NONE;
424 }
425 #endif
426
427 static int location_gps_start_batch(LocationGps *self)
428 {
429         LOC_FUNC_LOG
430         LocationGpsPrivate *priv = GET_PRIVATE(self);
431         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
432         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
433         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
434         g_return_val_if_fail(priv->mod->ops.start_batch, LOCATION_ERROR_NOT_AVAILABLE);
435
436         if (__get_started(self) == TRUE) return LOCATION_ERROR_NONE;
437
438         int ret = LOCATION_ERROR_NONE;
439
440         if (!location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
441                 ret = LOCATION_ERROR_SETTING_OFF;
442         } else {
443 #ifndef TIZEN_DEVICE
444                 __set_started(self, TRUE);
445                 ret = priv->mod->ops.start_batch(priv->mod->handler, gps_batch_cb, priv->batch_interval, priv->batch_period, self);
446                 if (ret != LOCATION_ERROR_NONE) {
447                         LOCATION_LOGE("Fail to start_batch [%s]", err_msg(ret));
448                         __set_started(self, FALSE);
449                         return ret;
450                 }
451 #endif
452
453 #if defined(TIZEN_DEVICE)
454                 if (_get_tizen_profile() != TIZEN_PROFILE_TV)
455                         return  __set_sensor_batch(self, priv->batch_interval);
456 #endif
457         }
458
459         return ret;
460 }
461
462 static int location_gps_stop_batch(LocationGps *self)
463 {
464         LOC_FUNC_LOG
465         LocationGpsPrivate *priv = GET_PRIVATE(self);
466         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
467         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
468         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
469         g_return_val_if_fail(priv->mod->ops.stop_batch, LOCATION_ERROR_NOT_AVAILABLE);
470
471         int ret = LOCATION_ERROR_NONE;
472
473 #if defined(TIZEN_DEVICE)
474         if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
475                 ret = sensor_listener_stop(priv->sensor_listener);
476                 LOC_IF_FAIL(ret, _E, "Fail to listener_stop [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
477
478                 ret = sensor_listener_unset_event_cb(priv->sensor_listener);
479                 LOC_IF_FAIL_LOG(ret, _E, "Fail to listener_unset_event_cb [%s]", err_msg(ret));
480
481                 ret = sensor_destroy_listener(priv->sensor_listener);
482                 LOC_IF_FAIL_LOG(ret, _E, "Fail to destroy_listener [%s]", err_msg(ret));
483         } else {
484 #else
485         if (1) {
486 #endif
487                 if (__get_started(self) == TRUE) {
488                         __set_started(self, FALSE);
489                         ret = priv->mod->ops.stop_batch(priv->mod->handler);
490                         LOC_IF_FAIL_LOG(ret, _E, "Failed to stop_batch [%s]", err_msg(ret));
491                 } else {
492                         return LOCATION_ERROR_NONE;
493                 }
494         }
495
496         __reset_pos_data_from_priv(priv);
497
498         return ret;
499 }
500
501 static void location_gps_dispose(GObject *gobject)
502 {
503         LOC_FUNC_LOG
504         LocationGpsPrivate *priv = GET_PRIVATE(gobject);
505         g_return_if_fail(priv);
506         g_return_if_fail(priv->mod);
507         g_mutex_clear(&priv->mutex);
508
509         if (priv->loc_timeout) g_source_remove(priv->loc_timeout);
510         priv->loc_timeout = 0;
511
512         if (priv->is_mock) {
513                 g_return_if_fail(priv->mod->ops.clear_mock_location);
514                 priv->mod->ops.clear_mock_location(priv->mod->handler, NULL, gobject);
515                 priv->is_mock = FALSE;
516         }
517
518         if (priv->app_type != CPPAPP && priv->set_noti == TRUE) {
519                 location_setting_ignore_notify(VCONFKEY_LOCATION_ENABLED, location_setting_gps_cb);
520                 location_state_ignore_notify(VCONFKEY_LOCATION_GPS_STATE, location_setting_search_cb);
521                 priv->set_noti = FALSE;
522         }
523
524         G_OBJECT_CLASS(location_gps_parent_class)->dispose(gobject);
525 }
526
527 static void location_gps_finalize(GObject *gobject)
528 {
529         LOC_FUNC_LOG
530         LocationGpsPrivate *priv = GET_PRIVATE(gobject);
531         g_return_if_fail(priv);
532
533         module_free(priv->mod, "gps");
534         priv->mod = NULL;
535
536         if (priv->boundary_list) {
537                 g_list_free_full(priv->boundary_list, free_boundary_list);
538                 priv->boundary_list = NULL;
539         }
540
541         if (priv->pos) {
542                 location_position_free(priv->pos);
543                 priv->pos = NULL;
544         }
545
546         if (priv->batch) {
547                 location_batch_free(priv->batch);
548                 priv->batch = NULL;
549         }
550
551         if (priv->vel) {
552                 location_velocity_free(priv->vel);
553                 priv->vel = NULL;
554         }
555
556         if (priv->acc) {
557                 location_accuracy_free(priv->acc);
558                 priv->acc = NULL;
559         }
560
561         if (priv->sat) {
562                 location_satellite_free(priv->sat);
563                 priv->sat = NULL;
564         }
565         G_OBJECT_CLASS(location_gps_parent_class)->finalize(gobject);
566 }
567
568 static guint get_valid_interval(guint interval, int max_interval, int min_interval)
569 {
570         if (interval > max_interval)
571                 return (guint)max_interval;
572         else if (interval < min_interval)
573                 return (guint)min_interval;
574         else
575                 return interval;
576 }
577
578 static void location_gps_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
579 {
580         LocationGpsPrivate *priv = GET_PRIVATE(object);
581         g_return_if_fail(priv);
582         g_return_if_fail(priv->mod);
583         g_return_if_fail(priv->mod->handler);
584
585         int ret = 0;
586         switch (property_id) {
587         case PROP_BOUNDARY: {
588                 GList *boundary_list = g_list_copy(g_value_get_pointer(value));
589                 ret = set_prop_boundary(&priv->boundary_list, boundary_list);
590                 LOC_IF_FAIL_LOG(ret, _E, "Set boundary. Error[%s]", err_msg(ret));
591                 if (boundary_list) g_list_free(boundary_list);
592                 break;
593         }
594         case PROP_REMOVAL_BOUNDARY: {
595                 LocationBoundary *req_boundary = (LocationBoundary *) g_value_dup_boxed(value);
596                 ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary);
597                 LOC_IF_FAIL_LOG(ret, _E, "Removal boundary. Error[%s]", err_msg(ret));
598                 break;
599         }
600         case PROP_POS_INTERVAL: {
601                 guint interval = g_value_get_uint(value);
602                 LOCATION_LOGD("Set prop>> PROP_POS_INTERVAL: %u", interval);
603                 if (interval == priv->pos_interval) break;
604
605                 priv->pos_interval = get_valid_interval(interval, LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_MIN);
606                 priv->optimized_interval = priv->pos_interval;
607
608                 if (__get_started(object) == TRUE) {
609                         LOCATION_LOGD("[update_pos_interval]: update pos-interval while pos-tracking");
610                         g_return_if_fail(priv->mod->ops.set_position_update_interval);
611                         priv->mod->ops.set_position_update_interval(priv->mod->handler, priv->pos_interval);
612                 }
613                 break;
614         }
615         case PROP_VEL_INTERVAL: {
616                 guint interval = g_value_get_uint(value);
617                 LOCATION_LOGD("Set prop>> PROP_VEL_INTERVAL: %u", interval);
618                 if (interval == priv->vel_interval) break;
619                 priv->vel_interval = get_valid_interval(interval, LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_MIN);
620                 break;
621         }
622         case PROP_SAT_INTERVAL: {
623                 guint interval = g_value_get_uint(value);
624                 LOCATION_LOGD("Set prop>> PROP_SAT_INTERVAL: %u", interval);
625                 priv->sat_interval = get_valid_interval(interval, LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_MIN);
626                 break;
627         }
628         case PROP_LOC_INTERVAL: {
629                 guint interval = g_value_get_uint(value);
630                 LOCATION_LOGD("Set prop>> PROP_LOC_INTERVAL: %u", interval);
631                 if (interval == priv->loc_interval) break;
632
633                 priv->loc_interval = get_valid_interval(interval, LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_MIN);
634                 priv->optimized_interval = priv->loc_interval;
635
636                 if (__get_started(object) == TRUE) {
637                         LOCATION_LOGD("[update_pos_interval]: update loc-interval while loc-tracking");
638                         g_return_if_fail(priv->mod->ops.set_position_update_interval);
639                         priv->mod->ops.set_position_update_interval(priv->mod->handler, priv->loc_interval);
640                 }
641                 break;
642         }
643         case PROP_BATCH_INTERVAL: {
644                 guint interval = g_value_get_uint(value);
645                 LOCATION_LOGD("Set prop>> PROP_BATCH_INTERVAL: %u", interval);
646
647                 priv->batch_interval = interval;
648
649                 if (__get_started(object) == TRUE) {
650                         LOCATION_LOGD("[update_batch_interval]: update batch-interval while pos-tracking");
651                         g_return_if_fail(priv->mod->ops.set_position_update_interval);
652                         priv->mod->ops.set_position_update_interval(priv->mod->handler, priv->batch_interval);
653                 }
654                 break;
655         }
656         case PROP_BATCH_PERIOD: {
657                 guint interval = g_value_get_uint(value);
658                 LOCATION_LOGD("Set prop>> PROP_BATCH_PERIOD: %u", interval);
659                 priv->batch_period = interval;
660                 break;
661         }
662         case PROP_MIN_INTERVAL: {
663                 guint interval = g_value_get_uint(value);
664                 LOCATION_LOGD("Set prop>> PROP_MIN_INTERVAL: %u", interval);
665                 priv->min_interval = interval;
666                 break;
667         }
668         case PROP_MIN_DISTANCE: {
669                 gdouble distance = g_value_get_double(value);
670                 LOCATION_LOGD("Set prop>> PROP_MIN_DISTANCE: %f", distance);
671                 priv->min_distance = distance;
672                 break;
673         }
674         case PROP_SERVICE_STATUS: {
675                 gint enabled = g_value_get_int(value);
676                 LOCATION_LOGD("Set prop>> PROP_SERVICE_STATUS: %d", enabled);
677                 priv->enabled = enabled;
678                 break;
679         }
680         default:
681                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
682                 break;
683         }
684 }
685
686 static void location_gps_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
687 {
688         LocationGpsPrivate *priv = GET_PRIVATE(object);
689         g_return_if_fail(priv);
690         g_return_if_fail(priv->mod);
691         g_return_if_fail(priv->mod->handler);
692         LocModGpsOps ops = priv->mod->ops;
693         switch (property_id) {
694         case PROP_METHOD_TYPE:
695                 g_value_set_int(value, LOCATION_METHOD_GPS);
696                 break;
697         case PROP_IS_STARTED:
698                 g_value_set_boolean(value, __get_started(object));
699                 break;
700         case PROP_LAST_POSITION:
701                 g_value_set_boxed(value, priv->pos);
702                 break;
703         case PROP_POS_INTERVAL:
704                 g_value_set_uint(value, priv->pos_interval);
705                 break;
706         case PROP_VEL_INTERVAL:
707                 g_value_set_uint(value, priv->vel_interval);
708                 break;
709         case PROP_SAT_INTERVAL:
710                 g_value_set_uint(value, priv->sat_interval);
711                 break;
712         case PROP_LOC_INTERVAL:
713                 g_value_set_uint(value, priv->loc_interval);
714                 break;
715         case PROP_BATCH_INTERVAL:
716                 g_value_set_uint(value, priv->batch_interval);
717                 break;
718         case PROP_BATCH_PERIOD:
719                 g_value_set_uint(value, priv->batch_period);
720                 break;
721         case PROP_MIN_INTERVAL:
722                 g_value_set_uint(value, priv->min_interval);
723                 break;
724         case PROP_MIN_DISTANCE:
725                 g_value_set_double(value, priv->min_distance);
726                 break;
727         case PROP_BOUNDARY:
728                 g_value_set_pointer(value, g_list_first(priv->boundary_list));
729                 break;
730         case PROP_NMEA: {
731                 char *nmea_data = NULL;
732                 if (ops.get_nmea && LOCATION_ERROR_NONE == ops.get_nmea(priv->mod->handler, &nmea_data) && nmea_data) {
733                         LOCATION_SECLOG("Get prop>> Lastest nmea: \n%s", nmea_data);
734                         g_value_set_string(value, nmea_data);
735                         g_free(nmea_data);
736                 } else {
737                         LOCATION_LOGW("Get prop>> Lastest nmea: failed");
738                         g_value_set_string(value, NULL);
739                 }
740                 break;
741         }
742         case PROP_SATELLITE: {
743                 LocationSatellite *satellite = NULL;
744                 if (ops.get_satellite && priv->mod->handler && LOCATION_ERROR_NONE == ops.get_satellite(priv->mod->handler, &satellite) && satellite) {
745                         LOCATION_LOGD("Get prop>> Last sat: num_used(%d) num_view(%d)", satellite->num_of_sat_used, satellite->num_of_sat_inview);
746                         g_value_set_boxed(value, satellite);
747                         location_satellite_free(satellite);
748                 } else {
749                         LOCATION_LOGW("Get prop>> Last sat: failed");
750                         g_value_set_boxed(value, NULL);
751                 }
752                 break;
753         }
754         case PROP_SERVICE_STATUS:
755                 g_value_set_int(value, priv->enabled);
756                 break;
757         default:
758                 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
759                 break;
760         }
761 }
762
763 static int location_gps_get_position(LocationGps *self, LocationPosition **position, LocationAccuracy **accuracy)
764 {
765         int ret = LOCATION_ERROR_NOT_AVAILABLE;
766         LocationGpsPrivate *priv = GET_PRIVATE(self);
767         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
768         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
769
770         LOC_COND_RET(__get_started(self) != TRUE, LOCATION_ERROR_NOT_AVAILABLE, _E, "Location is not started [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
771         LOCATION_IF_POS_FAIL(VCONFKEY_LOCATION_GPS_STATE);
772
773         if (priv->pos) {
774                 *position = location_position_copy(priv->pos);
775                 if (priv->acc) *accuracy = location_accuracy_copy(priv->acc);
776                 else *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0.0, 0.0);
777                 ret = LOCATION_ERROR_NONE;
778         }
779
780         return ret;
781 }
782
783 static int
784 location_gps_get_position_ext(LocationGps *self, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
785 {
786         int ret = LOCATION_ERROR_NOT_AVAILABLE;
787         LocationGpsPrivate *priv = GET_PRIVATE(self);
788         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
789         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
790
791         LOC_COND_RET(__get_started(self) != TRUE, LOCATION_ERROR_NOT_AVAILABLE, _E, "Location is not started [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
792         LOCATION_IF_POS_FAIL(VCONFKEY_LOCATION_GPS_STATE);
793
794         if (priv->pos && priv->vel) {
795                 *position = location_position_copy(priv->pos);
796                 *velocity = location_velocity_copy(priv->vel);
797                 if (priv->acc) *accuracy = location_accuracy_copy(priv->acc);
798                 else *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0.0, 0.0);
799                 ret = LOCATION_ERROR_NONE;
800         }
801
802         return ret;
803 }
804
805 static int
806 location_gps_get_last_position(LocationGps *self, LocationPosition **position, LocationAccuracy **accuracy)
807 {
808         LocationGpsPrivate *priv = GET_PRIVATE(self);
809         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
810         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
811         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
812
813         int ret = LOCATION_ERROR_NONE;
814         LocationVelocity *_velocity = NULL;
815
816         LocModGpsOps ops = priv->mod->ops;
817         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
818         g_return_val_if_fail(ops.get_last_position, LOCATION_ERROR_NOT_AVAILABLE);
819         ret = ops.get_last_position(priv->mod->handler, position, &_velocity, accuracy);
820         if (_velocity) location_velocity_free(_velocity);
821
822         return ret;
823 }
824
825 static int
826 location_gps_get_last_position_ext(LocationGps *self, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
827 {
828         LocationGpsPrivate *priv = GET_PRIVATE(self);
829         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
830         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
831         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
832
833         LocModGpsOps ops = priv->mod->ops;
834         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
835         g_return_val_if_fail(ops.get_last_position, LOCATION_ERROR_NOT_AVAILABLE);
836         return ops.get_last_position(priv->mod->handler, position, velocity, accuracy);
837 }
838
839
840 static int
841 location_gps_get_velocity(LocationGps *self, LocationVelocity **velocity, LocationAccuracy **accuracy)
842 {
843         int ret = LOCATION_ERROR_NOT_AVAILABLE;
844
845         LocationGpsPrivate *priv = GET_PRIVATE(self);
846         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
847         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
848
849         LOC_COND_RET(__get_started(self) != TRUE, LOCATION_ERROR_NOT_AVAILABLE, _E, "Location is not started [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
850         LOCATION_IF_POS_FAIL(VCONFKEY_LOCATION_GPS_STATE);
851
852         if (priv->vel) {
853                 *velocity = location_velocity_copy(priv->vel);
854                 if (priv->acc) *accuracy = location_accuracy_copy(priv->acc);
855                 else *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0.0, 0.0);
856                 ret = LOCATION_ERROR_NONE;
857         }
858
859         return ret;
860 }
861
862 static int
863 location_gps_get_last_velocity(LocationGps *self, LocationVelocity **velocity, LocationAccuracy **accuracy)
864 {
865         LocationGpsPrivate *priv = GET_PRIVATE(self);
866         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
867         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
868         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
869
870         int ret = LOCATION_ERROR_NONE;
871         LocationPosition *_position = NULL;
872
873         LocModGpsOps ops = priv->mod->ops;
874         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
875         g_return_val_if_fail(ops.get_last_position, LOCATION_ERROR_NOT_AVAILABLE);
876         ret = ops.get_last_position(priv->mod->handler, &_position, velocity, accuracy);
877         if (_position) location_position_free(_position);
878
879         return ret;
880 }
881
882 static gboolean __single_location_timeout_cb(void *data)
883 {
884         LOC_FUNC_LOG
885         LocationGps *self = (LocationGps *)data;
886         LocationGpsPrivate *priv = GET_PRIVATE(self);
887         g_return_val_if_fail(priv, FALSE);
888
889         LocationPosition *pos = location_position_new(0, 0.0, 0.0, 0.0, LOCATION_STATUS_NO_FIX);
890         LocationVelocity *vel = location_velocity_new(0, 0.0, 0.0, 0.0);
891
892         if (priv->loc_timeout) g_source_remove(priv->loc_timeout);
893         priv->loc_timeout = 0;
894
895         g_signal_emit(self, signals[LOCATION_UPDATED], 0, LOCATION_ERROR_NOT_AVAILABLE, pos, vel, NULL);
896         location_gps_stop(self);
897
898         return FALSE;
899 }
900
901 static void
902 gps_single_location_cb(gboolean enabled, LocationPosition *pos, LocationVelocity *vel, LocationAccuracy *acc, gpointer self)
903 {
904         LOC_FUNC_LOG
905         g_return_if_fail(self);
906         g_return_if_fail(pos);
907         g_return_if_fail(vel);
908         g_return_if_fail(acc);
909
910         LocationGps *obj = (LocationGps *)self;
911         LocationGpsPrivate *priv = GET_PRIVATE(obj);
912         g_return_if_fail(priv);
913
914         g_signal_emit(self, signals[LOCATION_UPDATED], 0, LOCATION_ERROR_NONE, pos, vel, acc);
915         if (priv->loc_timeout) {
916                 g_source_remove(priv->loc_timeout);
917                 priv->loc_timeout = 0;
918         }
919         location_gps_stop(self);
920 }
921
922 static int
923 location_gps_request_single_location(LocationGps *self, int timeout)
924 {
925         LOC_FUNC_LOG
926         LocationGpsPrivate *priv = GET_PRIVATE(self);
927         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
928         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
929         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
930         g_return_val_if_fail(priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE);
931
932         if (__get_started(self) == TRUE) return LOCATION_ERROR_NONE;
933
934         int ret = LOCATION_ERROR_NONE;
935         if (!location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
936                 ret = LOCATION_ERROR_SETTING_OFF;
937         } else {
938                 __set_started(self, TRUE);
939                 ret = priv->mod->ops.start(priv->mod->handler, LOCATION_UPDATE_INTERVAL_DEFAULT, gps_status_cb, gps_single_location_cb, NULL, self);
940                 if (ret != LOCATION_ERROR_NONE) {
941                         LOCATION_LOGE("Fail to start request single. Error[%d]", ret);
942                         __set_started(self, FALSE);
943                         return ret;
944                 } else {
945                         if (priv->loc_timeout != 0)
946                                 g_source_remove(priv->loc_timeout);
947
948                         priv->loc_timeout = g_timeout_add_seconds(timeout, __single_location_timeout_cb, self);
949                 }
950
951         }
952         return ret;
953 }
954
955 static int
956 location_gps_cancel_single_location(LocationGps *self)
957 {
958         LOC_FUNC_LOG
959         LocationGpsPrivate* priv = GET_PRIVATE(self);
960         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
961         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
962         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
963         g_return_val_if_fail(priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE);
964
965         int ret = LOCATION_ERROR_NONE;
966
967         if (priv->loc_timeout)
968                 g_source_remove(priv->loc_timeout);
969         priv->loc_timeout = 0;
970
971         if (__get_started(self) == TRUE) {
972                 __set_started(self, FALSE);
973                 __reset_pos_data_from_priv(priv);
974                 ret = priv->mod->ops.stop(priv->mod->handler);
975                 LOC_IF_FAIL_LOG(ret, _E, "Failed to stop [%s]", err_msg(ret));
976         }
977
978         return ret;
979 }
980
981 static int location_gps_get_nmea(LocationGps *self, char **nmea_data)
982 {
983         int ret = LOCATION_ERROR_NOT_AVAILABLE;
984
985         LocationGpsPrivate *priv = GET_PRIVATE(self);
986         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
987         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
988         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
989         g_return_val_if_fail(priv->mod->ops.get_nmea, LOCATION_ERROR_NOT_AVAILABLE);
990         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
991
992         ret = priv->mod->ops.get_nmea(priv->mod->handler, nmea_data);
993         LOC_IF_FAIL_LOG(ret, _E, "Failed to get_nmea [%s]", err_msg(ret));
994
995         return ret;
996 }
997
998 static int location_gps_get_batch(LocationGps *self, LocationBatch **batch)
999 {
1000         int ret = LOCATION_ERROR_NOT_AVAILABLE;
1001
1002         LocationGpsPrivate *priv = GET_PRIVATE(self);
1003         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
1004         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
1005         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
1006
1007 #ifndef TIZEN_DEVICE
1008         LOC_COND_RET(__get_started(self) != TRUE, LOCATION_ERROR_NOT_AVAILABLE, _E, "Location is not started [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
1009 #endif
1010
1011         if (priv->batch) {
1012                 *batch = location_batch_copy(priv->batch);
1013                 ret = LOCATION_ERROR_NONE;
1014         } else {
1015                 LOCATION_LOGE("priv->batch is null");
1016                 ret = LOCATION_ERROR_NOT_AVAILABLE;
1017         }
1018
1019         return ret;
1020 }
1021
1022 static int location_gps_get_satellite(LocationGps *self, LocationSatellite **satellite)
1023 {
1024         int ret = LOCATION_ERROR_NOT_AVAILABLE;
1025
1026         LocationGpsPrivate *priv = GET_PRIVATE(self);
1027         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
1028         setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
1029
1030         LOC_COND_RET(__get_started(self) != TRUE, LOCATION_ERROR_NOT_AVAILABLE, _E, "Location is not started [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
1031
1032         if (priv->sat) {
1033                 *satellite = location_satellite_copy(priv->sat);
1034                 ret = LOCATION_ERROR_NONE;
1035         }
1036
1037         return ret;
1038 }
1039
1040 static int location_gps_get_last_satellite(LocationGps *self, LocationSatellite **satellite)
1041 {
1042         return location_gps_get_satellite(self, satellite);
1043 }
1044
1045 static int location_gps_set_option(LocationGps *self, const char *option)
1046 {
1047         LocationGpsPrivate *priv = GET_PRIVATE(self);
1048         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
1049         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
1050         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
1051         g_return_val_if_fail(priv->mod->ops.set_option, LOCATION_ERROR_NOT_AVAILABLE);
1052
1053         int ret = LOCATION_ERROR_NONE;
1054         ret = priv->mod->ops.set_option(priv->mod->handler, option);
1055         LOC_IF_FAIL_LOG(ret, _E, "Failed to set_option [%s]", err_msg(ret));
1056
1057         return ret;
1058 }
1059
1060 static int
1061 location_gps_set_mock_location(LocationGps *self, LocationPosition *position, LocationVelocity *velocity, LocationAccuracy *accuracy)
1062 {
1063         LOC_FUNC_LOG
1064         LocationGpsPrivate *priv = GET_PRIVATE(self);
1065         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
1066         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
1067         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
1068         g_return_val_if_fail(priv->mod->ops.set_mock_location, LOCATION_ERROR_NOT_AVAILABLE);
1069
1070         int ret = LOCATION_ERROR_NONE;
1071         if (!location_setting_get_int(VCONFKEY_LOCATION_MOCK_ENABLED)) {
1072                 ret = LOCATION_ERROR_SETTING_OFF;
1073         } else {
1074                 ret = priv->mod->ops.set_mock_location(priv->mod->handler, position, velocity, accuracy, NULL, self);
1075                 LOC_IF_FAIL_LOG(ret, _E, "Failed to set_mock_location [%s]", err_msg(ret));
1076                 priv->is_mock = TRUE;
1077         }
1078
1079         return ret;
1080 }
1081
1082 static int
1083 location_gps_clear_mock_location(LocationGps *self)
1084 {
1085         LOC_FUNC_LOG
1086         LocationGpsPrivate *priv = GET_PRIVATE(self);
1087         g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
1088         g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
1089         g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
1090         g_return_val_if_fail(priv->mod->ops.clear_mock_location, LOCATION_ERROR_NOT_AVAILABLE);
1091
1092         int ret = LOCATION_ERROR_NONE;
1093         if (!location_setting_get_int(VCONFKEY_LOCATION_MOCK_ENABLED)) {
1094                 ret = LOCATION_ERROR_SETTING_OFF;
1095         } else {
1096                 ret = priv->mod->ops.clear_mock_location(priv->mod->handler, NULL, self);
1097                 LOC_IF_FAIL_LOG(ret, _E, "Failed to clear_mock_location [%s]", err_msg(ret));
1098                 priv->is_mock = FALSE;
1099         }
1100
1101         return ret;
1102 }
1103
1104 static void location_ielement_interface_init(LocationIElementInterface *iface)
1105 {
1106         iface->start = (TYPE_START_FUNC)location_gps_start;
1107         iface->stop = (TYPE_STOP_FUNC)location_gps_stop;
1108         iface->get_position = (TYPE_GET_POSITION)location_gps_get_position;
1109         iface->get_position_ext = (TYPE_GET_POSITION_EXT)location_gps_get_position_ext;
1110         iface->get_last_position = (TYPE_GET_POSITION)location_gps_get_last_position;
1111         iface->get_last_position_ext = (TYPE_GET_POSITION_EXT)location_gps_get_last_position_ext;
1112         iface->get_velocity = (TYPE_GET_VELOCITY)location_gps_get_velocity;
1113         iface->get_last_velocity = (TYPE_GET_VELOCITY)location_gps_get_last_velocity;
1114         iface->get_satellite = (TYPE_GET_SATELLITE)location_gps_get_satellite;
1115         iface->get_last_satellite = (TYPE_GET_SATELLITE)location_gps_get_last_satellite;
1116         iface->set_option = (TYPE_SET_OPTION)location_gps_set_option;
1117         iface->get_batch = (TYPE_GET_BATCH)location_gps_get_batch;
1118         iface->start_batch = (TYPE_START_BATCH)location_gps_start_batch;
1119         iface->stop_batch = (TYPE_STOP_BATCH)location_gps_stop_batch;
1120         iface->request_single_location = (TYPE_REQUEST_SINGLE_LOCATION)location_gps_request_single_location;
1121         iface->cancel_single_location = (TYPE_CANCEL_SINGLE_LOCATION)location_gps_cancel_single_location;
1122         iface->get_nmea = (TYPE_GET_NMEA)location_gps_get_nmea;
1123         iface->set_mock_location = (TYPE_SET_MOCK_LOCATION) location_gps_set_mock_location;
1124         iface->clear_mock_location = (TYPE_CLEAR_MOCK_LOCATION) location_gps_clear_mock_location;
1125 }
1126
1127 static void location_gps_init(LocationGps *self)
1128 {
1129         LOC_FUNC_LOG
1130         LocationGpsPrivate *priv = GET_PRIVATE(self);
1131         g_return_if_fail(priv);
1132
1133         priv->mod = (LocationGpsMod *)module_new("gps");
1134         LOC_COND_LOG(!priv->mod, _E, "Module loading failed");
1135
1136         g_mutex_init(&priv->mutex);
1137         priv->is_started = FALSE;
1138         priv->is_batch_invoked = FALSE;
1139         priv->is_mock = FALSE;
1140         priv->set_noti = FALSE;
1141         priv->enabled = FALSE;
1142         priv->signal_type = 0;
1143
1144         priv->pos_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
1145         priv->vel_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
1146         priv->sat_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
1147         priv->loc_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
1148         priv->batch_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
1149         priv->batch_period = LOCATION_BATCH_PERIOD_DEFAULT;
1150         priv->min_interval = LOCATION_UPDATE_INTERVAL_NONE;
1151         priv->optimized_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
1152
1153         priv->pos_updated_timestamp = 0;
1154         priv->vel_updated_timestamp = 0;
1155         priv->sat_updated_timestamp = 0;
1156         priv->loc_updated_timestamp = 0;
1157
1158         priv->pos = NULL;
1159         priv->batch = NULL;
1160         priv->vel = NULL;
1161         priv->acc = NULL;
1162         priv->sat = NULL;
1163         priv->boundary_list = NULL;
1164         priv->loc_timeout = 0;
1165
1166 #if defined(TIZEN_DEVICE)
1167         if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
1168                 priv->sensor = NULL;
1169                 priv->sensor_listener = NULL;
1170         }
1171 #endif
1172
1173         priv->app_type = location_get_app_type(NULL);
1174         LOC_COND_LOG(priv->app_type == 0, _W, "Fail to get app_type");
1175 }
1176
1177 static void location_gps_class_init(LocationGpsClass *klass)
1178 {
1179         LOC_FUNC_LOG
1180         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
1181
1182         gobject_class->set_property = location_gps_set_property;
1183         gobject_class->get_property = location_gps_get_property;
1184
1185         gobject_class->dispose = location_gps_dispose;
1186         gobject_class->finalize = location_gps_finalize;
1187
1188         g_type_class_add_private(klass, sizeof(LocationGpsPrivate));
1189
1190         signals[SERVICE_ENABLED] =
1191                         g_signal_new("service-enabled", G_TYPE_FROM_CLASS(klass),
1192                         G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
1193                         G_STRUCT_OFFSET(LocationGpsClass, enabled),
1194                         NULL, NULL, location_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
1195
1196         signals[SERVICE_DISABLED] =
1197                         g_signal_new("service-disabled", G_TYPE_FROM_CLASS(klass),
1198                         G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
1199                         G_STRUCT_OFFSET(LocationGpsClass, disabled),
1200                         NULL, NULL, location_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
1201
1202         signals[SERVICE_UPDATED] =
1203                         g_signal_new("service-updated", G_TYPE_FROM_CLASS(klass),
1204                         G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
1205                         G_STRUCT_OFFSET(LocationGpsClass, service_updated),
1206                         NULL, NULL, location_VOID__INT_POINTER_POINTER_POINTER,
1207                         G_TYPE_NONE, 4, G_TYPE_INT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
1208
1209         signals[LOCATION_UPDATED] =
1210                         g_signal_new("location-updated", G_TYPE_FROM_CLASS(klass),
1211                         G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
1212                         G_STRUCT_OFFSET(LocationGpsClass, location_updated),
1213                         NULL, NULL, location_VOID__INT_POINTER_POINTER_POINTER,
1214                         G_TYPE_NONE, 4, G_TYPE_INT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
1215
1216         signals[BATCH_UPDATED] =
1217                         g_signal_new("batch-updated", G_TYPE_FROM_CLASS(klass),
1218                         G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
1219                         G_STRUCT_OFFSET(LocationGpsClass, batch_updated),
1220                         NULL, NULL, location_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
1221
1222         signals[ZONE_IN] =
1223                         g_signal_new("zone-in", G_TYPE_FROM_CLASS(klass),
1224                         G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
1225                         G_STRUCT_OFFSET(LocationGpsClass, zone_in),
1226                         NULL, NULL, location_VOID__POINTER_POINTER_POINTER,
1227                         G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
1228
1229         signals[ZONE_OUT] =
1230                         g_signal_new("zone-out", G_TYPE_FROM_CLASS(klass),
1231                         G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
1232                         G_STRUCT_OFFSET(LocationGpsClass, zone_out),
1233                         NULL, NULL, location_VOID__POINTER_POINTER_POINTER,
1234                         G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
1235
1236         properties[PROP_METHOD_TYPE] =
1237                         g_param_spec_int("method", "method type", "location method type name",
1238                         LOCATION_METHOD_GPS, LOCATION_METHOD_GPS, LOCATION_METHOD_GPS, G_PARAM_READABLE);
1239
1240         properties[PROP_IS_STARTED] =
1241                         g_param_spec_boolean("is_started", "gps is started prop",
1242                         "gps is started status", FALSE, G_PARAM_READWRITE);
1243
1244         properties[PROP_LAST_POSITION] =
1245                         g_param_spec_boxed("last-position", "gps last position prop",
1246                         "gps last position data", LOCATION_TYPE_POSITION, G_PARAM_READABLE);
1247
1248         properties[PROP_POS_INTERVAL] =
1249                         g_param_spec_uint("pos-interval", "gps position interval prop",
1250                         "gps position interval data", LOCATION_UPDATE_INTERVAL_MIN,
1251                         LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_DEFAULT, G_PARAM_READWRITE);
1252
1253         properties[PROP_VEL_INTERVAL] =
1254                         g_param_spec_uint("vel-interval", "gps velocity interval prop",
1255                         "gps velocity interval data", LOCATION_UPDATE_INTERVAL_MIN,
1256                         LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_DEFAULT, G_PARAM_READWRITE);
1257
1258         properties[PROP_SAT_INTERVAL] =
1259                         g_param_spec_uint("sat-interval", "gps satellite interval prop",
1260                         "gps satellite interval data", LOCATION_UPDATE_INTERVAL_MIN,
1261                         LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_DEFAULT, G_PARAM_READWRITE);
1262
1263         properties[PROP_LOC_INTERVAL] =
1264                         g_param_spec_uint("loc-interval", "gps location interval prop",
1265                         "gps location interval data", LOCATION_UPDATE_INTERVAL_MIN,
1266                         LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_DEFAULT, G_PARAM_READWRITE);
1267
1268         properties[PROP_BATCH_INTERVAL] =
1269                         g_param_spec_uint("batch-interval", "gps batch interval interval prop",
1270                         "gps batch interval interval data", LOCATION_UPDATE_INTERVAL_MIN,
1271                         LOCATION_BATCH_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_DEFAULT, G_PARAM_READWRITE);
1272
1273         properties[PROP_BATCH_PERIOD] =
1274                         g_param_spec_uint("batch-period", "gps batch period prop",
1275                         "gps batch period data", LOCATION_BATCH_PERIOD_MIN,
1276                         LOCATION_BATCH_PERIOD_MAX, LOCATION_BATCH_PERIOD_DEFAULT, G_PARAM_READWRITE);
1277
1278         properties[PROP_MIN_INTERVAL] =
1279                         g_param_spec_uint("min-interval", "gps distance-based interval prop",
1280                         "gps distance-based interval data", LOCATION_MIN_INTERVAL_MIN,
1281                         LOCATION_MIN_INTERVAL_MAX, LOCATION_MIN_INTERVAL_DEFAULT, G_PARAM_READWRITE);
1282
1283         properties[PROP_MIN_DISTANCE] =
1284                         g_param_spec_double("min-distance", "gps distance-based distance prop",
1285                         "gps distance-based distance data", LOCATION_MIN_DISTANCE_MIN,
1286                         LOCATION_MIN_DISTANCE_MAX, LOCATION_MIN_DISTANCE_DEFAULT, G_PARAM_READWRITE);
1287
1288         properties[PROP_BOUNDARY] =
1289                         g_param_spec_pointer("boundary", "gps boundary prop",
1290                         "gps boundary data", G_PARAM_READWRITE);
1291
1292         properties[PROP_REMOVAL_BOUNDARY] =
1293                         g_param_spec_boxed("removal-boundary", "gps removal boundary prop",
1294                         "gps removal boundary data", LOCATION_TYPE_BOUNDARY, G_PARAM_READWRITE);
1295
1296         properties[PROP_NMEA] =
1297                         g_param_spec_string("nmea", "gps NMEA name prop", "gps NMEA",
1298                         NULL, G_PARAM_READABLE);
1299
1300         properties[PROP_SATELLITE] =
1301                         g_param_spec_boxed("satellite", "gps satellite prop",
1302                         "gps satellite data", LOCATION_TYPE_SATELLITE, G_PARAM_READABLE);
1303
1304         properties[PROP_SERVICE_STATUS] =
1305                         g_param_spec_int("service-status", "location service status prop",
1306                         "location service status data", LOCATION_STATUS_NO_FIX,
1307                         LOCATION_STATUS_3D_FIX, LOCATION_STATUS_NO_FIX, G_PARAM_READABLE);
1308
1309         g_object_class_install_properties(gobject_class, PROP_MAX, properties);
1310 }