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"
30 enable_signaling (LocationObject *obj,
31 guint32 signals[LAST_SIGNAL],
32 gboolean *prev_enabled,
34 LocationStatus status)
36 g_return_if_fail(obj);
37 g_return_if_fail(signals);
38 g_return_if_fail(prev_enabled);
39 if (*prev_enabled == TRUE && enabled == FALSE) {
40 *prev_enabled = FALSE;
41 LOCATION_LOGD("Signal emit: SERVICE_DISABLED");
42 g_signal_emit (obj, signals[SERVICE_DISABLED], 0, LOCATION_STATUS_NO_FIX);
43 } else if (*prev_enabled == FALSE && enabled == TRUE){
45 LOCATION_LOGD("Signal emit: SERVICE_ENABLED");
46 g_signal_emit (obj, signals[SERVICE_ENABLED], 0, status);
51 position_signaling (LocationObject *obj,
52 guint32 signals[LAST_SIGNAL],
53 gboolean *prev_enabled,
56 guint *updated_timestamp,
57 LocationPosition **prev_pos,
58 LocationAccuracy **prev_acc,
60 ZoneStatus *zone_status,
61 const LocationPosition *pos,
62 const LocationAccuracy *acc)
64 g_return_if_fail(zone_status);
65 g_return_if_fail(pos);
66 g_return_if_fail(acc);
67 g_return_if_fail(obj);
68 g_return_if_fail(signals);
71 gboolean is_inside = FALSE;
72 GList *boundary_list = prev_bound;
73 LocationBoundary *boundary = NULL;
75 if (!pos->timestamp) return;
77 if (*prev_pos) location_position_free (*prev_pos);
78 if (*prev_acc) location_accuracy_free (*prev_acc);
80 *prev_pos = location_position_copy(pos);
81 *prev_acc = location_accuracy_copy(acc);
82 LOCATION_LOGD("timestamp[%d], lat [%f], lon [%f]", (*prev_pos)->timestamp, (*prev_pos)->latitude, (*prev_pos)->longitude);
84 if (emit && pos->timestamp - *updated_timestamp >= interval) {
85 LOCATION_LOGD("POSITION SERVICE_UPDATED");
86 g_signal_emit(obj, signals[SERVICE_UPDATED], 0, POSITION_UPDATED, pos, acc);
87 *updated_timestamp = pos->timestamp;
91 while((boundary = (LocationBoundary *)g_list_nth_data(boundary_list, index))!= NULL) {
92 is_inside = location_boundary_if_inside(boundary, pos);
100 if(*zone_status != ZONE_STATUS_IN) {
101 LOCATION_LOGD("Signal emit: ZONE IN");
102 g_signal_emit(obj, signals[ZONE_IN], 0, NULL, pos, acc);
103 *zone_status = ZONE_STATUS_IN;
107 if (*zone_status != ZONE_STATUS_OUT) {
108 LOCATION_LOGD("Signal emit : ZONE_OUT");
109 g_signal_emit(obj, signals[ZONE_OUT], 0, NULL, pos, acc);
110 *zone_status = ZONE_STATUS_OUT;
117 velocity_signaling (LocationObject *obj,
118 guint32 signals[LAST_SIGNAL],
119 gboolean *prev_enabled,
122 guint *updated_timestamp,
123 LocationVelocity **prev_vel,
124 const LocationVelocity *vel,
125 const LocationAccuracy *acc)
127 g_return_if_fail(obj);
128 g_return_if_fail(signals);
129 g_return_if_fail(vel);
131 if (!vel->timestamp) return;
133 if (*prev_vel) location_velocity_free (*prev_vel);
134 *prev_vel = location_velocity_copy (vel);
135 LOCATION_LOGD("timestamp[%d]", (*prev_vel)->timestamp);
137 if (emit && vel->timestamp - *updated_timestamp >= interval) {
138 LOCATION_LOGD("VELOCITY SERVICE_UPDATED");
139 g_signal_emit(obj, signals[SERVICE_UPDATED], 0, VELOCITY_UPDATED, vel, acc);
140 *updated_timestamp = vel->timestamp;
145 satellite_signaling(LocationObject *obj,
146 guint32 signals[LAST_SIGNAL],
147 gboolean *prev_enabled,
150 guint *updated_timestamp,
151 LocationSatellite **prev_sat,
152 const LocationSatellite *sat)
154 g_return_if_fail(obj);
155 g_return_if_fail(signals);
156 g_return_if_fail(sat);
158 if (!sat->timestamp) return;
160 if (*prev_sat) location_satellite_free (*prev_sat);
161 *prev_sat = location_satellite_copy (sat);
163 if (emit && sat->timestamp - *updated_timestamp >= interval) {
164 LOCATION_LOGD("SATELLITE SERVICE_UPDATED");
165 g_signal_emit(obj, signals[SERVICE_UPDATED], 0, SATELLITE_UPDATED, sat, NULL);
166 *updated_timestamp = sat->timestamp;