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.
25 static GMainLoop *loop = NULL;
28 update_gps(LocationObject* loc)
30 g_debug("update gps");
31 double ran = g_random_double()/200;
32 LocationPosition* pos = location_position_new (time(NULL), 37.257809 + ran, 127.056383 + ran, 150.199997 + ran, LOCATION_STATUS_3D_FIX);
33 g_object_set(loc, "position-base", pos, NULL);
34 location_position_free (pos);
36 LocationVelocity* vel = location_velocity_new (pos->timestamp, 0, 0, 0);
37 g_object_set(loc, "velocity-base", vel, NULL);
38 location_velocity_free (vel);
40 LocationAccuracy* acc = location_accuracy_new (LOCATION_ACCURACY_LEVEL_DETAILED, 0, 0);
41 g_object_set(loc, "accuracy-info", acc, NULL);
42 location_accuracy_free (acc);
44 LocationSatellite* sat = location_satellite_new (9);
45 location_satellite_set_satellite_details(sat, 0, 5, 1, 0, 0, 41);
46 location_satellite_set_satellite_details(sat, 1, 9, 1, 0, 0, 46);
47 location_satellite_set_satellite_details(sat, 2, 15, 1, 0, 0, 45);
48 location_satellite_set_satellite_details(sat, 3, 18, 1, 0, 0, 41);
49 location_satellite_set_satellite_details(sat, 4, 21, 1, 0, 0, 34);
50 location_satellite_set_satellite_details(sat, 5, 22, 0, 0, 0, 41);
51 location_satellite_set_satellite_details(sat, 6, 26, 0, 0, 0, 46);
52 location_satellite_set_satellite_details(sat, 7, 27, 0, 0, 0, 31);
53 location_satellite_set_satellite_details(sat, 8, 28, 0, 0, 0, 33);
54 g_object_set(loc, "satellite-info", sat, NULL);
55 location_satellite_free (sat);
59 update_timer(gpointer data)
66 cb_service_updated (GObject *self,
72 g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
74 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
76 case POSITION_UPDATED: {
77 LocationPosition *pos = (LocationPosition*) data;
78 g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
79 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
80 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
81 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
84 case VELOCITY_UPDATED: {
85 LocationVelocity *vel = (LocationVelocity*) data;
86 g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
87 vel->timestamp, vel->speed, vel->direction, vel->climb);
88 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
89 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
93 g_warning ("ASYNC>> Undefined update type");
99 cb_service_enabled (GObject *self,
103 g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
105 LocationObject *loc = (LocationObject*)userdata;
106 LocationAccuracy *acc = NULL;
107 LocationPosition *pos = NULL;
108 LocationVelocity *vel = NULL;
109 LocationAddress *addr = NULL;
111 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
112 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
113 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
114 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
115 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
116 location_position_free(pos);
117 location_accuracy_free(acc);
118 } else g_warning ("SYNC>> Current position> failed");
119 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
120 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
121 vel->timestamp, vel->speed, vel->direction, vel->climb);
122 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
123 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
124 location_velocity_free(vel);
125 location_accuracy_free(acc);
126 } else g_warning ("SYNC>> Current velocity> failed");
127 if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
128 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
129 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
130 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
131 location_address_free(addr);
132 location_accuracy_free(acc);
133 } else g_warning ("SYNC>> Current address> failed");
137 cb_service_disabled (GObject *self,
141 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
145 cb_zone_in (GObject *self,
150 g_debug("cb_zone_in: type(%d)", type);
151 LocationPosition *pos = (LocationPosition*) position;
152 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
154 g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
155 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
156 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
157 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
161 cb_zone_out (GObject *self,
166 g_debug("cb_zone_out: type(%d)", type);
167 LocationPosition *pos = (LocationPosition*) position;
168 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
170 g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
171 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
172 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
173 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
178 main (int argc, char *argv[])
180 LocationObject *loc = NULL;
182 // If application is executed by AUL, this is not needed.
183 g_setenv("PKG_NAME", "com.samsung.sps-test", 1);
187 loop = g_main_loop_new (NULL, TRUE);
189 loc = location_new (LOCATION_METHOD_SPS);
191 g_debug("location_new failed");
195 LocationMethod method = LOCATION_METHOD_NONE;
196 g_object_get(loc, "method", &method, NULL);
197 g_debug("Get property>> method:%d", method);
199 LocationBoundary *bound = NULL;
200 g_object_get(loc, "boundary", &bound, NULL);
202 g_debug("Get property>> boundary> type: %d", bound->type);
203 location_boundary_free (bound);
204 } else g_warning("failed to get property> boundary");
206 LocationPosition *rb = location_position_new(0, 37.255, 127.060, 0, LOCATION_STATUS_2D_FIX);
207 LocationPosition *lt = location_position_new(0, 37.260, 127.055, 0, LOCATION_STATUS_2D_FIX);
208 bound = location_boundary_new_for_rect(lt, rb);
209 location_position_free (rb);
210 location_position_free (lt);
212 g_object_set(loc, "boundary", bound, NULL);
213 location_boundary_free(bound);
214 } else g_warning("failed to location_boundary_new_for_rect()");
215 g_object_get(loc, "boundary", &bound, NULL);
217 g_debug("Set property>> boundary> type: %d, (%f,%f),(%f,%f)",
219 bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude,
220 bound->rect.left_top->latitude, bound->rect.left_top->longitude);
221 location_boundary_free (bound);
222 } else g_warning("failed to set property> boundary");
225 g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
226 g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
227 g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc);
228 g_signal_connect (loc, "zone-in", G_CALLBACK(cb_zone_in), loc);
229 g_signal_connect (loc, "zone-out", G_CALLBACK(cb_zone_out), loc);
231 if( LOCATION_ERROR_NONE != location_start (loc) ){
232 g_debug("location_start failed");
236 g_timeout_add_seconds(1, update_timer, loc);
237 g_main_loop_run (loop);
241 LocationPosition *pos = NULL;
242 g_object_get(loc, "last-position", &pos, NULL);
244 g_debug ("Get property>> last-position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
245 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
246 location_position_free(pos);
247 } else g_warning("failed to get property> last-position");