4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7 * Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include "location-signaling-util.h"
27 #include "location-log.h"
29 #define POS_EXPIRATION_TIME 9 /* sec */
32 enable_signaling (LocationObject *obj,
33 guint32 signals[LAST_SIGNAL],
34 gboolean *prev_enabled,
36 LocationStatus status)
38 g_return_if_fail(obj);
39 g_return_if_fail(signals);
40 g_return_if_fail(prev_enabled);
41 if (*prev_enabled == TRUE && enabled == FALSE) {
42 *prev_enabled = FALSE;
43 LOCATION_LOGD("Signal emit: SERVICE_DISABLED");
44 g_signal_emit (obj, signals[SERVICE_DISABLED], 0, LOCATION_STATUS_NO_FIX);
45 } else if (*prev_enabled == FALSE && enabled == TRUE){
47 LOCATION_LOGD("Signal emit: SERVICE_ENABLED");
48 g_signal_emit (obj, signals[SERVICE_ENABLED], 0, status);
53 position_signaling (LocationObject *obj,
54 guint32 signals[LAST_SIGNAL],
55 gboolean *prev_enabled,
57 LocationPosition **prev_pos,
58 LocationAccuracy **prev_acc,
60 ZoneStatus *zone_status,
62 const LocationPosition *pos,
63 const LocationAccuracy *acc)
65 g_return_if_fail(zone_status);
66 g_return_if_fail(pos);
67 g_return_if_fail(acc);
68 g_return_if_fail(obj);
69 g_return_if_fail(signals);
72 gboolean is_inside = FALSE;
73 guint updated_timestamp = 0;
74 GList *boundary_list = prev_bound;
75 LocationBoundary *boundary = NULL;
77 if(!*prev_pos || !*prev_acc || location_accuracy_level_compare(*prev_acc, acc) != -1 ||
78 (pos->timestamp - (*prev_pos)->timestamp) > POS_EXPIRATION_TIME) {
81 updated_timestamp = (*prev_pos)->updated_timestamp;
82 location_position_free(*prev_pos);
84 if(*prev_acc) location_accuracy_free(*prev_acc);
86 if(!updated_timestamp || pos->timestamp - updated_timestamp >= interval) {
87 LOCATION_LOGD("Signal emit: POSITION SERVICE_UPDATED");
88 g_signal_emit(obj, signals[SERVICE_UPDATED], 0, POSITION_UPDATED, pos, acc);
89 updated_timestamp = pos->timestamp;
93 while((boundary = (LocationBoundary *)g_list_nth_data(boundary_list, index))!= NULL) {
95 is_inside = location_boundary_if_inside(boundary, pos);
103 if(*zone_status != ZONE_STATUS_IN) {
104 LOCATION_LOGD("Signal emit: ZONE IN");
105 g_signal_emit(obj, signals[ZONE_IN], 0, NULL, pos, acc);
106 *zone_status = ZONE_STATUS_IN;
110 if (*zone_status != ZONE_STATUS_OUT) {
111 LOCATION_LOGD("Signal emit : ZONE_OUT");
112 g_signal_emit(obj, signals[ZONE_OUT], 0, NULL, pos, acc);
113 *zone_status = ZONE_STATUS_OUT;
120 *prev_pos = location_position_copy(pos);
121 *prev_acc = location_accuracy_copy(acc);
122 (*prev_pos)->updated_timestamp = updated_timestamp;
126 velocity_signaling (LocationObject *obj,
127 guint32 signals[LAST_SIGNAL],
128 gboolean *prev_enabled,
130 LocationVelocity **prev_vel,
132 const LocationVelocity *vel,
133 const LocationAccuracy *acc)
135 g_return_if_fail(obj);
136 g_return_if_fail(signals);
137 g_return_if_fail(vel);
139 guint updated_timestamp = 0;
142 updated_timestamp = (*prev_vel)->updated_timestamp;
143 if(!location_velocity_equal(*prev_vel, vel)) {
144 location_velocity_free (*prev_vel);
148 *prev_vel = location_velocity_copy (vel);
150 if(!updated_timestamp || vel->timestamp - updated_timestamp >= interval) {
152 LOCATION_LOGD ("Signal emit: VELOCITY SERVICE_UPDATED");
153 LocationVelocity *temp_vel = location_velocity_copy (*prev_vel);
154 LocationAccuracy *temp_acc = location_accuracy_copy(acc);
156 g_signal_emit (obj, signals[SERVICE_UPDATED], 0, VELOCITY_UPDATED, temp_vel, temp_acc);
158 (*prev_vel)->updated_timestamp = vel->timestamp;
160 location_velocity_free(temp_vel);
161 location_accuracy_free(temp_acc);
164 (*prev_vel)->updated_timestamp = updated_timestamp;
170 satellite_signaling(LocationObject *obj,
171 guint32 signals[LAST_SIGNAL],
172 gboolean *prev_enabled,
174 guint *sat_timestamp,
175 LocationSatellite **prev_sat,
177 const LocationSatellite *sat)
179 g_return_if_fail(obj);
180 g_return_if_fail(signals);
181 g_return_if_fail(sat);
184 location_satellite_free(*prev_sat);
187 *prev_sat = location_satellite_copy (sat);
188 if (!(*sat_timestamp) || sat->timestamp - *sat_timestamp > interval) {
190 LOCATION_LOGD ("Signal emit: SATELLITE SERVICE_UPDATED");
191 LocationSatellite *temp_sat = location_satellite_copy (sat);
193 g_signal_emit (obj, signals[SERVICE_UPDATED], 0, SATELLITE_UPDATED, temp_sat, NULL);
195 *sat_timestamp = sat->timestamp;
197 location_satellite_free(temp_sat);