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 cb_service_updated (GObject *self,
34 g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
36 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
38 case POSITION_UPDATED: {
39 LocationPosition *pos = (LocationPosition*) data;
40 g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
41 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
42 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
43 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
46 case VELOCITY_UPDATED: {
47 LocationVelocity *vel = (LocationVelocity*) data;
48 g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
49 vel->timestamp, vel->speed, vel->direction, vel->climb);
50 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
51 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
55 g_warning ("ASYNC>> Undefined update type");
61 cb_service_enabled (GObject *self,
65 g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
67 LocationObject *loc = (LocationObject*)userdata;
68 LocationAccuracy *acc = NULL;
69 LocationPosition *pos = NULL;
70 LocationVelocity *vel = NULL;
71 LocationMethod method;
73 g_object_get(loc, "method", &method, NULL);
74 g_debug("Get property>> method:%d", method);
76 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
77 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
78 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
79 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
80 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
81 location_position_free(pos);
82 location_accuracy_free(acc);
83 } else g_warning ("SYNC>> Current position> failed");
84 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
85 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
86 vel->timestamp, vel->speed, vel->direction, vel->climb);
87 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
88 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
89 location_velocity_free(vel);
90 location_accuracy_free(acc);
91 } else g_warning ("SYNC>> Current velocity> failed");
95 cb_service_disabled (GObject *self,
99 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
103 cb_zone_in (GObject *self,
108 g_debug("cb_zone_in: type(%d)", type);
109 LocationPosition *pos = (LocationPosition*) position;
110 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
112 g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
113 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
114 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
115 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
119 cb_zone_out (GObject *self,
124 g_debug("cb_zone_out: type(%d)", type);
125 LocationPosition *pos = (LocationPosition*) position;
126 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
128 g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
129 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
130 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
131 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
135 main (int argc, char *argv[])
137 LocationObject *loc = NULL;
139 // If application is executed by AUL, this is not needed.
140 g_setenv("PKG_NAME", "com.samsung.hybrid-test", 1);
144 loop = g_main_loop_new (NULL, TRUE);
146 loc = location_new (LOCATION_METHOD_HYBRID);
148 g_debug("location_new failed");
152 LocationMethod method = LOCATION_METHOD_NONE;
153 g_object_get(loc, "method", &method, NULL);
154 g_debug("Get property>> method:%d", method);
156 LocationBoundary *bound = NULL;
157 g_object_get(loc, "boundary", &bound, NULL);
159 g_debug("Get property>> boundary> type: %d", bound->type);
160 location_boundary_free (bound);
161 } else g_warning("failed to get property> boundary");
163 LocationPosition *rb = location_position_new(0, 37.258, 127.056, 0, LOCATION_STATUS_2D_FIX);
164 LocationPosition *lt = location_position_new(0, 37.260, 127.054, 0, LOCATION_STATUS_2D_FIX);
165 bound = location_boundary_new_for_rect(lt, rb);
166 location_position_free (rb);
167 location_position_free (lt);
169 g_object_set(loc, "boundary", bound, NULL);
170 location_boundary_free(bound);
171 } else g_warning("failed to location_boundary_new_for_rect()");
172 g_object_get(loc, "boundary", &bound, NULL);
174 g_debug("Set property>> boundary> type: %d, (%f,%f),(%f,%f)",
176 bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude,
177 bound->rect.left_top->latitude, bound->rect.left_top->longitude);
178 location_boundary_free (bound);
179 } else g_warning("failed to set property> boundary");
181 g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
182 g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
183 g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc);
184 g_signal_connect (loc, "zone-in", G_CALLBACK(cb_zone_in), loc);
185 g_signal_connect (loc, "zone-out", G_CALLBACK(cb_zone_out), loc);
187 if (LOCATION_ERROR_NONE != location_start (loc)) {
188 g_debug("location_start failed");
192 g_main_loop_run (loop);
196 LocationPosition *pos = NULL;
197 g_object_get(loc, "last-position", &pos, NULL);
199 g_debug ("Get property>> last-position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
200 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
201 location_position_free(pos);
202 } else g_warning("failed to get property> last-position");