4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include "location-setting.h"
24 #include "location-log.h"
26 #include "module-internal.h"
28 #include "location-wps.h"
29 #include "location-marshal.h"
30 #include "location-ielement.h"
31 #include "location-signaling-util.h"
32 #include "location-common-util.h"
34 #include <vconf-internal-location-keys.h>
40 typedef struct _LocationWpsPrivate {
48 guint pos_updated_timestamp;
49 guint vel_updated_timestamp;
50 guint loc_updated_timestamp;
51 guint dist_updated_timestamp;
58 LocationPosition *pos;
59 LocationVelocity *vel;
60 LocationAccuracy *acc;
73 PROP_REMOVAL_BOUNDARY,
80 static guint32 signals[LAST_SIGNAL] = {0, };
81 static GParamSpec *properties[PROP_MAX] = {NULL, };
83 #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), LOCATION_TYPE_WPS, LocationWpsPrivate))
85 static void location_ielement_interface_init(LocationIElementInterface *iface);
86 static int location_wps_cancel_single_location(LocationWps *self);
88 G_DEFINE_TYPE_WITH_CODE(LocationWps, location_wps, G_TYPE_OBJECT,
89 G_IMPLEMENT_INTERFACE(LOCATION_TYPE_IELEMENT, location_ielement_interface_init));
92 __reset_pos_data_from_priv(LocationWpsPrivate *priv)
95 g_return_if_fail(priv);
98 location_position_free(priv->pos);
102 location_velocity_free(priv->vel);
106 location_accuracy_free(priv->acc);
109 priv->pos_updated_timestamp = 0;
110 priv->vel_updated_timestamp = 0;
114 __get_started(gpointer self)
116 LocationWpsPrivate *priv = GET_PRIVATE(self);
117 g_return_val_if_fail(priv, FALSE);
119 return priv->is_started;
123 __set_started(gpointer self, gboolean started)
125 LocationWpsPrivate *priv = GET_PRIVATE(self);
126 g_return_val_if_fail(priv, -1);
128 if (priv->is_started != started) {
129 g_mutex_lock(&priv->mutex);
130 priv->is_started = started;
131 g_mutex_unlock(&priv->mutex);
138 wps_status_cb(gboolean enabled, LocationStatus status, gpointer self)
141 g_return_if_fail(self);
142 LocationWpsPrivate *priv = GET_PRIVATE(self);
143 g_return_if_fail(priv);
144 if (priv->enabled == TRUE && enabled == FALSE) {
145 __set_started(self, FALSE);
146 enable_signaling(self, signals, &(priv->enabled), enabled, status);
151 wps_location_cb(gboolean enabled, LocationPosition *pos, LocationVelocity *vel, LocationAccuracy *acc, gpointer self)
153 g_return_if_fail(self);
154 g_return_if_fail(pos);
155 g_return_if_fail(vel);
156 g_return_if_fail(acc);
157 LocationWpsPrivate *priv = GET_PRIVATE(self);
158 g_return_if_fail(priv);
160 if (priv->min_interval != LOCATION_UPDATE_INTERVAL_NONE) {
161 distance_based_position_signaling(self, signals, enabled,
162 pos, vel, acc, priv->min_interval, priv->min_distance, &(priv->enabled),
163 &(priv->dist_updated_timestamp), &(priv->pos), &(priv->vel), &(priv->acc));
165 location_signaling(self, signals, enabled, priv->boundary_list, pos, vel, acc,
166 priv->pos_interval, priv->vel_interval, priv->loc_interval, &(priv->enabled),
167 &(priv->pos_updated_timestamp), &(priv->vel_updated_timestamp), &(priv->loc_updated_timestamp),
168 &(priv->pos), &(priv->vel), &(priv->acc));
172 location_setting_search_cb(keynode_t *key, gpointer self)
175 g_return_if_fail(key);
176 g_return_if_fail(self);
177 LocationWpsPrivate *priv = GET_PRIVATE(self);
178 g_return_if_fail(priv);
180 if (location_setting_get_key_val(key) == VCONFKEY_LOCATION_WPS_SEARCHING) {
181 if (!location_setting_get_int(VCONFKEY_LOCATION_MOCK_ENABLED)) {
182 LOCATION_LOGD("enable_signaling : SERVICE_DISABLED");
183 enable_signaling(self, signals, &(priv->enabled), FALSE, LOCATION_STATUS_NO_FIX);
189 location_setting_wps_cb(keynode_t *key, gpointer self)
192 g_return_if_fail(key);
193 g_return_if_fail(self);
194 LocationWpsPrivate *priv = GET_PRIVATE(self);
195 g_return_if_fail(priv);
196 g_return_if_fail(priv->mod);
197 g_return_if_fail(priv->mod->handler);
199 int ret = LOCATION_ERROR_NONE;
201 if (location_setting_get_key_val(key) == 0) {
202 if (priv->mod->ops.stop && __get_started(self)) {
203 __set_started(self, FALSE);
204 ret = priv->mod->ops.stop(priv->mod->handler);
205 if (ret == LOCATION_ERROR_NONE)
206 __reset_pos_data_from_priv(priv);
209 if (1 == location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED) && priv->mod->ops.start && !__get_started(self)) {
210 LOCATION_LOGD("location resumed by setting");
211 __set_started(self, TRUE);
212 ret = priv->mod->ops.start(priv->mod->handler, wps_status_cb, wps_location_cb, self);
213 if (ret != LOCATION_ERROR_NONE) {
214 __set_started(self, FALSE);
215 LOCATION_LOGD("Fail to start. Error[%d]", ret);
223 location_wps_start(LocationWps *self)
226 LocationWpsPrivate *priv = GET_PRIVATE(self);
227 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
228 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
229 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
230 g_return_val_if_fail(priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE);
232 if (__get_started(self) == TRUE) return LOCATION_ERROR_NONE;
234 int ret = LOCATION_ERROR_NONE;
236 if (!location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
237 ret = LOCATION_ERROR_SETTING_OFF;
239 __set_started(self, TRUE);
240 ret = priv->mod->ops.start(priv->mod->handler, wps_status_cb, wps_location_cb, self);
241 if (ret != LOCATION_ERROR_NONE) {
242 __set_started(self, FALSE);
243 LOCATION_LOGE("Fail to start wps. Error[%d]", ret);
248 if (priv->app_type != CPPAPP && priv->set_noti == FALSE) {
249 location_setting_add_notify(VCONFKEY_LOCATION_NETWORK_ENABLED, location_setting_wps_cb, self);
250 location_state_add_notify(VCONFKEY_LOCATION_WPS_STATE, location_setting_search_cb, self);
251 priv->set_noti = TRUE;
258 location_wps_stop(LocationWps *self)
261 LocationWpsPrivate *priv = GET_PRIVATE(self);
262 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
263 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
264 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
265 g_return_val_if_fail(priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE);
267 int ret = LOCATION_ERROR_NONE;
269 if (__get_started(self) == TRUE) {
270 __set_started(self, FALSE);
271 ret = priv->mod->ops.stop(priv->mod->handler);
272 LOC_IF_FAIL_LOG(ret, _E, "Failed to stop [%s]", err_msg(ret));
275 if (priv->app_type != CPPAPP && priv->set_noti == TRUE) {
276 location_setting_ignore_notify(VCONFKEY_LOCATION_NETWORK_ENABLED, location_setting_wps_cb);
277 location_state_ignore_notify(VCONFKEY_LOCATION_WPS_STATE, location_setting_search_cb);
278 priv->set_noti = FALSE;
281 __reset_pos_data_from_priv(priv);
287 location_wps_dispose(GObject *gobject)
290 LocationWpsPrivate *priv = GET_PRIVATE(gobject);
291 g_return_if_fail(priv);
293 g_mutex_clear(&priv->mutex);
296 priv->mod->ops.clear_mock_location(priv->mod->handler, NULL, gobject);
297 priv->is_mock = FALSE;
300 if (priv->app_type != CPPAPP && priv->set_noti == TRUE) {
301 location_setting_ignore_notify(VCONFKEY_LOCATION_NETWORK_ENABLED, location_setting_wps_cb);
302 location_state_ignore_notify(VCONFKEY_LOCATION_WPS_STATE, location_setting_search_cb);
303 priv->set_noti = FALSE;
307 G_OBJECT_CLASS(location_wps_parent_class)->dispose(gobject);
311 location_wps_finalize(GObject *gobject)
314 LocationWpsPrivate *priv = GET_PRIVATE(gobject);
315 g_return_if_fail(priv);
316 module_free(priv->mod, "wps");
318 if (priv->boundary_list) {
319 g_list_free_full(priv->boundary_list, free_boundary_list);
320 priv->boundary_list = NULL;
324 location_position_free(priv->pos);
329 location_velocity_free(priv->vel);
334 location_accuracy_free(priv->acc);
337 G_OBJECT_CLASS(location_wps_parent_class)->finalize(gobject);
341 location_wps_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
343 LocationWpsPrivate *priv = GET_PRIVATE(object);
344 g_return_if_fail(priv);
347 switch (property_id) {
348 case PROP_BOUNDARY: {
349 GList *boundary_list = (GList *)g_list_copy(g_value_get_pointer(value));
350 ret = set_prop_boundary(&priv->boundary_list, boundary_list);
351 LOC_IF_FAIL_LOG(ret, _E, "Set boundary [%s]", err_msg(ret));
352 if (boundary_list) g_list_free(boundary_list);
355 case PROP_REMOVAL_BOUNDARY: {
356 LocationBoundary *req_boundary = (LocationBoundary *) g_value_dup_boxed(value);
357 ret = set_prop_removal_boundary(&priv->boundary_list, req_boundary);
358 LOC_IF_FAIL_LOG(ret, _E, "Set removal boundary [%s]", err_msg(ret));
361 case PROP_POS_INTERVAL: {
362 guint interval = g_value_get_uint(value);
364 if (interval < LOCATION_UPDATE_INTERVAL_MAX)
365 priv->pos_interval = interval;
367 priv->pos_interval = (guint)LOCATION_UPDATE_INTERVAL_MAX;
369 priv->pos_interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT;
373 case PROP_VEL_INTERVAL: {
374 guint interval = g_value_get_uint(value);
376 if (interval < LOCATION_UPDATE_INTERVAL_MAX)
377 priv->vel_interval = interval;
379 priv->vel_interval = (guint)LOCATION_UPDATE_INTERVAL_MAX;
381 priv->vel_interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT;
385 case PROP_LOC_INTERVAL: {
386 guint interval = g_value_get_uint(value);
387 LOCATION_LOGD("Set prop>> PROP_LOC_INTERVAL: %u", interval);
389 if (interval < LOCATION_UPDATE_INTERVAL_MAX)
390 priv->loc_interval = interval;
392 priv->loc_interval = (guint)LOCATION_UPDATE_INTERVAL_MAX;
394 priv->loc_interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT;
398 case PROP_MIN_INTERVAL: {
399 guint interval = g_value_get_uint(value);
400 LOCATION_LOGD("Set prop>> update-min-interval: %u", interval);
402 if (interval < LOCATION_MIN_INTERVAL_MAX)
403 priv->min_interval = interval;
405 priv->min_interval = (guint)LOCATION_MIN_INTERVAL_MAX;
407 priv->min_interval = (guint)LOCATION_MIN_INTERVAL_DEFAULT;
411 case PROP_MIN_DISTANCE: {
412 gdouble distance = g_value_get_double(value);
413 LOCATION_LOGD("Set prop>> update-min-distance: %f", distance);
415 if (distance < LOCATION_MIN_DISTANCE_MAX)
416 priv->min_distance = distance;
418 priv->min_distance = (gdouble)LOCATION_MIN_DISTANCE_MAX;
420 priv->min_distance = (gdouble)LOCATION_MIN_DISTANCE_DEFAULT;
424 case PROP_SERVICE_STATUS: {
425 gint enabled = g_value_get_int(value);
426 LOCATION_LOGD("Set prop>> PROP_SERVICE_STATUS: %d", enabled);
427 priv->enabled = enabled;
431 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
437 location_wps_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
439 LocationWpsPrivate *priv = GET_PRIVATE(object);
440 g_return_if_fail(priv);
442 switch (property_id) {
443 case PROP_METHOD_TYPE:
444 g_value_set_int(value, LOCATION_METHOD_WPS);
446 case PROP_IS_STARTED:
447 g_value_set_boolean(value, __get_started(object));
449 case PROP_LAST_POSITION:
450 g_value_set_boxed(value, priv->pos);
453 g_value_set_pointer(value, g_list_first(priv->boundary_list));
455 case PROP_POS_INTERVAL:
456 g_value_set_uint(value, priv->pos_interval);
458 case PROP_VEL_INTERVAL:
459 g_value_set_uint(value, priv->vel_interval);
461 case PROP_LOC_INTERVAL:
462 g_value_set_uint(value, priv->loc_interval);
464 case PROP_MIN_INTERVAL:
465 g_value_set_uint(value, priv->min_interval);
467 case PROP_MIN_DISTANCE:
468 g_value_set_double(value, priv->min_distance);
470 case PROP_SERVICE_STATUS:
471 g_value_set_int(value, priv->enabled);
474 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
480 location_wps_get_position(LocationWps *self, LocationPosition **position, LocationAccuracy **accuracy)
482 int ret = LOCATION_ERROR_NOT_AVAILABLE;
484 LocationWpsPrivate *priv = GET_PRIVATE(self);
485 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
486 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
487 setting_retval_if_fail(VCONFKEY_LOCATION_NETWORK_ENABLED);
489 if (__get_started(self) != TRUE) {
490 LOCATION_LOGE("location is not started");
491 return LOCATION_ERROR_NOT_AVAILABLE;
494 LOCATION_IF_POS_FAIL(VCONFKEY_LOCATION_WPS_STATE);
497 *position = location_position_copy(priv->pos);
498 if (priv->acc) *accuracy = location_accuracy_copy(priv->acc);
499 else *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0.0, 0.0);
500 ret = LOCATION_ERROR_NONE;
507 location_wps_get_position_ext(LocationWps *self, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
509 int ret = LOCATION_ERROR_NOT_AVAILABLE;
511 LocationWpsPrivate *priv = GET_PRIVATE(self);
512 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
513 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
514 setting_retval_if_fail(VCONFKEY_LOCATION_NETWORK_ENABLED);
516 LOC_COND_RET(__get_started(self) != TRUE, LOCATION_ERROR_NOT_AVAILABLE, _E, "location is not started [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
517 LOCATION_IF_POS_FAIL(VCONFKEY_LOCATION_WPS_STATE);
519 if (priv->pos && priv->vel) {
520 *position = location_position_copy(priv->pos);
521 *velocity = location_velocity_copy(priv->vel);
522 if (priv->acc) *accuracy = location_accuracy_copy(priv->acc);
523 else *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0.0, 0.0);
524 ret = LOCATION_ERROR_NONE;
532 location_wps_get_last_position(LocationWps *self, LocationPosition **position, LocationAccuracy **accuracy)
534 LocationWpsPrivate *priv = GET_PRIVATE(self);
535 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
536 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
537 setting_retval_if_fail(VCONFKEY_LOCATION_NETWORK_ENABLED);
539 int ret = LOCATION_ERROR_NONE;
540 LocationVelocity *_velocity = NULL;
542 LocModWpsOps ops = priv->mod->ops;
543 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
544 g_return_val_if_fail(ops.get_last_position, LOCATION_ERROR_NOT_AVAILABLE);
546 ret = ops.get_last_position(priv->mod->handler, position, &_velocity, accuracy);
547 if (_velocity) location_velocity_free(_velocity);
553 location_wps_get_last_position_ext(LocationWps *self, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
555 LocationWpsPrivate *priv = GET_PRIVATE(self);
556 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
557 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
558 setting_retval_if_fail(VCONFKEY_LOCATION_NETWORK_ENABLED);
560 LocModWpsOps ops = priv->mod->ops;
561 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
562 g_return_val_if_fail(ops.get_last_position, LOCATION_ERROR_NOT_AVAILABLE);
564 return ops.get_last_position(priv->mod->handler, position, velocity, accuracy);
569 location_wps_get_velocity(LocationWps *self, LocationVelocity **velocity, LocationAccuracy **accuracy)
571 int ret = LOCATION_ERROR_NOT_AVAILABLE;
572 LocationWpsPrivate *priv = GET_PRIVATE(self);
573 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
574 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
575 setting_retval_if_fail(VCONFKEY_LOCATION_NETWORK_ENABLED);
577 LOC_COND_RET(__get_started(self) != TRUE, LOCATION_ERROR_NOT_AVAILABLE, _E, "location is not started [%s]", err_msg(LOCATION_ERROR_NOT_AVAILABLE));
578 LOCATION_IF_POS_FAIL(VCONFKEY_LOCATION_WPS_STATE);
581 *velocity = location_velocity_copy(priv->vel);
582 if (priv->acc) *accuracy = location_accuracy_copy(priv->acc);
583 else *accuracy = location_accuracy_new(LOCATION_ACCURACY_LEVEL_NONE, 0.0, 0.0);
584 ret = LOCATION_ERROR_NONE;
591 location_wps_get_last_velocity(LocationWps *self, LocationVelocity **velocity, LocationAccuracy **accuracy)
593 LocationWpsPrivate *priv = GET_PRIVATE(self);
594 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
595 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
596 setting_retval_if_fail(VCONFKEY_LOCATION_NETWORK_ENABLED);
598 int ret = LOCATION_ERROR_NONE;
599 LocationPosition *_position = NULL;
601 LocModWpsOps ops = priv->mod->ops;
602 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
603 ret = ops.get_last_position(priv->mod->handler, &_position, velocity, accuracy);
604 if (!_position) location_position_free(_position);
609 static gboolean __single_location_timeout_cb(void *data)
612 LocationWps *self = (LocationWps *)data;
613 LocationWpsPrivate *priv = GET_PRIVATE(self);
614 g_return_val_if_fail(priv, FALSE);
616 LocationPosition *pos = location_position_new(0, 0.0, 0.0, 0.0, LOCATION_STATUS_NO_FIX);
617 LocationVelocity *vel = location_velocity_new(0, 0.0, 0.0, 0.0);
619 if (priv->loc_timeout) g_source_remove(priv->loc_timeout);
620 priv->loc_timeout = 0;
622 g_signal_emit(self, signals[LOCATION_UPDATED], 0, LOCATION_ERROR_NOT_AVAILABLE, pos, vel, NULL);
623 location_wps_stop(self);
630 wps_single_location_cb(gboolean enabled, LocationPosition *pos, LocationVelocity *vel, LocationAccuracy *acc, gpointer self)
633 g_return_if_fail(self);
634 g_return_if_fail(pos);
635 g_return_if_fail(vel);
636 g_return_if_fail(acc);
638 LocationWpsPrivate *priv = GET_PRIVATE(self);
639 g_return_if_fail(priv);
641 g_signal_emit(self, signals[LOCATION_UPDATED], 0, LOCATION_ERROR_NONE, pos, vel, acc);
642 if (priv->loc_timeout) {
643 g_source_remove(priv->loc_timeout);
644 priv->loc_timeout = 0;
646 location_wps_stop(self);
650 location_wps_request_single_location(LocationWps *self, int timeout)
653 LocationWpsPrivate *priv = GET_PRIVATE(self);
654 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
655 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
656 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
657 g_return_val_if_fail(priv->mod->ops.start, LOCATION_ERROR_NOT_AVAILABLE);
659 if (__get_started(self) == TRUE) return LOCATION_ERROR_NONE;
661 int ret = LOCATION_ERROR_NONE;
663 if (!location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
664 ret = LOCATION_ERROR_SETTING_OFF;
666 __set_started(self, TRUE);
667 ret = priv->mod->ops.start(priv->mod->handler, wps_status_cb, wps_single_location_cb, self);
668 if (ret != LOCATION_ERROR_NONE) {
669 LOCATION_LOGE("Fail to start request single. Error[%d]", ret);
670 __set_started(self, FALSE);
673 if (priv->loc_timeout != 0)
674 g_source_remove(priv->loc_timeout);
676 priv->loc_timeout = g_timeout_add_seconds(timeout, __single_location_timeout_cb, self);
685 location_wps_cancel_single_location(LocationWps *self)
688 LocationWpsPrivate* priv = GET_PRIVATE(self);
689 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
690 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
691 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
692 g_return_val_if_fail(priv->mod->ops.stop, LOCATION_ERROR_NOT_AVAILABLE);
694 int ret = LOCATION_ERROR_NONE;
696 if (priv->loc_timeout)
697 g_source_remove(priv->loc_timeout);
698 priv->loc_timeout = 0;
700 if (__get_started(self) == TRUE) {
701 __set_started(self, FALSE);
702 __reset_pos_data_from_priv(priv);
703 ret = priv->mod->ops.stop(priv->mod->handler);
704 LOC_IF_FAIL_LOG(ret, _E, "Failed to stop [%s]", err_msg(ret));
711 location_wps_get_satellite(LocationWps *self, LocationSatellite **satellite)
713 return LOCATION_ERROR_NOT_SUPPORTED;
717 location_wps_get_last_satellite(LocationWps *self, LocationSatellite **satellite)
719 return LOCATION_ERROR_NOT_SUPPORTED;
723 location_wps_set_option(LocationWps *self, const char *option)
725 LocationWpsPrivate *priv = GET_PRIVATE(self);
726 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
727 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
728 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
730 return LOCATION_ERROR_NONE;
734 location_wps_get_nmea(LocationWps *self, char **nmea_data)
736 return LOCATION_ERROR_NOT_SUPPORTED;
740 location_wps_set_mock_location(LocationWps *self, LocationPosition *position, LocationVelocity *velocity, LocationAccuracy *accuracy)
743 LocationWpsPrivate *priv = GET_PRIVATE(self);
744 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
745 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
746 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
747 g_return_val_if_fail(priv->mod->ops.set_mock_location, LOCATION_ERROR_NOT_AVAILABLE);
749 int ret = LOCATION_ERROR_NONE;
750 if (!location_setting_get_int(VCONFKEY_LOCATION_MOCK_ENABLED)) {
751 ret = LOCATION_ERROR_SETTING_OFF;
753 ret = priv->mod->ops.set_mock_location(priv->mod->handler, position, velocity, accuracy, NULL, self);
754 LOC_IF_FAIL_LOG(ret, _E, "Failed to set_mock_location [%s]", err_msg(ret));
755 priv->is_mock = TRUE;
762 location_wps_clear_mock_location(LocationWps *self)
765 LocationWpsPrivate *priv = GET_PRIVATE(self);
766 g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
767 g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
768 g_return_val_if_fail(priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
769 g_return_val_if_fail(priv->mod->ops.clear_mock_location, LOCATION_ERROR_NOT_AVAILABLE);
771 int ret = LOCATION_ERROR_NONE;
772 if (!location_setting_get_int(VCONFKEY_LOCATION_MOCK_ENABLED)) {
773 ret = LOCATION_ERROR_SETTING_OFF;
775 ret = priv->mod->ops.clear_mock_location(priv->mod->handler, NULL, self);
776 LOC_IF_FAIL_LOG(ret, _E, "Failed to clear_mock_location [%s]", err_msg(ret));
777 priv->is_mock = FALSE;
784 location_ielement_interface_init(LocationIElementInterface *iface)
786 iface->start = (TYPE_START_FUNC)location_wps_start;
787 iface->stop = (TYPE_STOP_FUNC)location_wps_stop;
788 iface->get_position = (TYPE_GET_POSITION)location_wps_get_position;
789 iface->get_position_ext = (TYPE_GET_POSITION_EXT)location_wps_get_position_ext;
790 iface->get_last_position = (TYPE_GET_POSITION)location_wps_get_last_position;
791 iface->get_last_position_ext = (TYPE_GET_POSITION_EXT)location_wps_get_last_position_ext;
792 iface->get_velocity = (TYPE_GET_VELOCITY)location_wps_get_velocity;
793 iface->get_last_velocity = (TYPE_GET_VELOCITY)location_wps_get_last_velocity;
794 iface->get_satellite = (TYPE_GET_SATELLITE)location_wps_get_satellite;
795 iface->get_last_satellite = (TYPE_GET_SATELLITE)location_wps_get_last_satellite;
796 iface->set_option = (TYPE_SET_OPTION)location_wps_set_option;
797 iface->request_single_location = (TYPE_REQUEST_SINGLE_LOCATION)location_wps_request_single_location;
798 iface->cancel_single_location = (TYPE_CANCEL_SINGLE_LOCATION)location_wps_cancel_single_location;
799 iface->get_nmea = (TYPE_GET_NMEA)location_wps_get_nmea;
800 iface->set_mock_location = (TYPE_SET_MOCK_LOCATION) location_wps_set_mock_location;
801 iface->clear_mock_location = (TYPE_CLEAR_MOCK_LOCATION) location_wps_clear_mock_location;
805 location_wps_init(LocationWps *self)
808 LocationWpsPrivate *priv = GET_PRIVATE(self);
809 g_return_if_fail(priv);
811 priv->mod = (LocationWpsMod *)module_new("wps");
812 if (!priv->mod) LOCATION_LOGW("module loading failed");
814 g_mutex_init(&priv->mutex);
815 priv->is_started = FALSE;
816 priv->is_mock = FALSE;
817 priv->set_noti = FALSE;
818 priv->enabled = FALSE;
820 priv->pos_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
821 priv->vel_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
822 priv->loc_interval = LOCATION_UPDATE_INTERVAL_DEFAULT;
823 priv->min_interval = LOCATION_UPDATE_INTERVAL_NONE;
825 priv->pos_updated_timestamp = 0;
826 priv->vel_updated_timestamp = 0;
827 priv->loc_updated_timestamp = 0;
832 priv->boundary_list = NULL;
834 priv->loc_timeout = 0;
836 priv->app_type = location_get_app_type(NULL);
837 if (priv->app_type == 0)
838 LOCATION_LOGW("Fail to get app_type");
842 location_wps_class_init(LocationWpsClass *klass)
845 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
847 gobject_class->set_property = location_wps_set_property;
848 gobject_class->get_property = location_wps_get_property;
850 gobject_class->dispose = location_wps_dispose;
851 gobject_class->finalize = location_wps_finalize;
853 g_type_class_add_private(klass, sizeof(LocationWpsPrivate));
855 signals[SERVICE_ENABLED] =
856 g_signal_new("service-enabled", G_TYPE_FROM_CLASS(klass),
857 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
858 G_STRUCT_OFFSET(LocationWpsClass, enabled),
859 NULL, NULL, location_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
861 signals[SERVICE_DISABLED] =
862 g_signal_new("service-disabled", G_TYPE_FROM_CLASS(klass),
863 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
864 G_STRUCT_OFFSET(LocationWpsClass, disabled),
865 NULL, NULL, location_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
867 signals[SERVICE_UPDATED] =
868 g_signal_new("service-updated", G_TYPE_FROM_CLASS(klass),
869 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
870 G_STRUCT_OFFSET(LocationWpsClass, service_updated),
871 NULL, NULL, location_VOID__INT_POINTER_POINTER_POINTER,
872 G_TYPE_NONE, 4, G_TYPE_INT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
874 signals[LOCATION_UPDATED] =
875 g_signal_new("location-updated", G_TYPE_FROM_CLASS(klass),
876 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
877 G_STRUCT_OFFSET(LocationWpsClass, location_updated),
878 NULL, NULL, location_VOID__INT_POINTER_POINTER_POINTER,
879 G_TYPE_NONE, 4, G_TYPE_INT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
882 g_signal_new("zone-in", G_TYPE_FROM_CLASS(klass),
883 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
884 G_STRUCT_OFFSET(LocationWpsClass, zone_in),
885 NULL, NULL, location_VOID__POINTER_POINTER_POINTER,
886 G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
889 g_signal_new("zone-out", G_TYPE_FROM_CLASS(klass),
890 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
891 G_STRUCT_OFFSET(LocationWpsClass, zone_out),
892 NULL, NULL, location_VOID__POINTER_POINTER_POINTER,
893 G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
895 properties[PROP_METHOD_TYPE] =
896 g_param_spec_int("method", "method type", "location method type name",
897 LOCATION_METHOD_WPS, LOCATION_METHOD_WPS, LOCATION_METHOD_WPS, G_PARAM_READABLE);
899 properties[PROP_IS_STARTED] =
900 g_param_spec_boolean("is_started", "wps is started prop",
901 "wps is started status", FALSE, G_PARAM_READWRITE);
903 properties[PROP_LAST_POSITION] =
904 g_param_spec_boxed("last-position", "wps last position prop",
905 "wps last position data", LOCATION_TYPE_POSITION, G_PARAM_READABLE);
907 properties[PROP_POS_INTERVAL] =
908 g_param_spec_uint("pos-interval", "wps position interval prop",
909 "wps position interval data", LOCATION_UPDATE_INTERVAL_MIN,
910 LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_DEFAULT, G_PARAM_READWRITE);
912 properties[PROP_VEL_INTERVAL] =
913 g_param_spec_uint("vel-interval", "wps velocity interval prop",
914 "wps velocity interval data", LOCATION_UPDATE_INTERVAL_MIN,
915 LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_DEFAULT, G_PARAM_READWRITE);
917 properties[PROP_LOC_INTERVAL] =
918 g_param_spec_uint("loc-interval", "gps location interval prop",
919 "gps location interval data", LOCATION_UPDATE_INTERVAL_MIN,
920 LOCATION_UPDATE_INTERVAL_MAX, LOCATION_UPDATE_INTERVAL_DEFAULT, G_PARAM_READWRITE);
922 properties[PROP_MIN_INTERVAL] =
923 g_param_spec_uint("min-interval", "wps distance-based interval prop",
924 "wps distance-based interval data", LOCATION_MIN_INTERVAL_MIN,
925 LOCATION_MIN_INTERVAL_MAX, LOCATION_MIN_INTERVAL_DEFAULT, G_PARAM_READWRITE);
927 properties[PROP_MIN_DISTANCE] =
928 g_param_spec_double("min-distance", "wps distance-based distance prop",
929 "wps distance-based distance data", LOCATION_MIN_DISTANCE_MIN,
930 LOCATION_MIN_DISTANCE_MAX, LOCATION_MIN_DISTANCE_DEFAULT, G_PARAM_READWRITE);
932 properties[PROP_BOUNDARY] =
933 g_param_spec_pointer("boundary", "wps boundary prop",
934 "wps boundary data", G_PARAM_READWRITE);
936 properties[PROP_REMOVAL_BOUNDARY] =
937 g_param_spec_boxed("removal-boundary", "wps removal boundary prop",
938 "wps removal boundary data", LOCATION_TYPE_BOUNDARY, G_PARAM_READWRITE);
941 properties[PROP_SERVICE_STATUS] =
942 g_param_spec_int("service-status", "location service status prop",
943 "location service status data", LOCATION_STATUS_NO_FIX,
944 LOCATION_STATUS_3D_FIX, LOCATION_STATUS_NO_FIX, G_PARAM_READABLE);
946 g_object_class_install_properties(gobject_class, PROP_MAX, properties);