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.
23 #include <glib/gprintf.h>
24 #include <gconf/gconf-client.h>
25 #include <location/location.h>
26 #include "location-api-test-util.h"
29 LocationObject* location_obj = NULL;
30 static GMainLoop *g_mainloop = NULL;
32 #define GCONF_PROXY_MODE "/system/proxy/mode"
33 #define GCONF_HTTP_PROXY_HOST "/system/http_proxy/host"
34 #define GCONF_HTTP_PROXY_PORT "/system/http_proxy/port"
35 #define ENV_HTTP_PROXY "http_proxy"
37 #define LOCATION_API_TEST_JSON_FILE "/opt/data/location-api-test.json"
39 static gpointer GmainThread(gpointer data)
41 g_mainloop = g_main_loop_new (NULL, FALSE);
42 g_printf("\n...Entering GMain Loop to Receive Notifications....\n");
43 g_main_loop_run (g_mainloop);
44 g_main_loop_unref (g_mainloop);
50 static void GetLocationError(char str[STR_MAX], int ret)
54 case LOCATION_ERROR_NONE:
55 g_utf8_strncpy(str, "LOCATION_ERROR_NONE", STR_MAX);
57 case LOCATION_ERROR_NOT_ALLOWED:
58 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_ALLOWED", STR_MAX);
60 case LOCATION_ERROR_NOT_AVAILABLE:
61 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_AVAILABLE", STR_MAX);
63 case LOCATION_ERROR_NETWORK_FAILED:
64 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_FAILED", STR_MAX);
66 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
67 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_NOT_CONNECTED", STR_MAX);
69 case LOCATION_ERROR_CONFIGURATION:
70 g_utf8_strncpy(str, "LOCATION_ERROR_CONFIGURATION", STR_MAX);
72 case LOCATION_ERROR_PARAMETER:
73 g_utf8_strncpy(str, "LOCATION_ERROR_PARAMETER", STR_MAX);
75 case LOCATION_ERROR_UNKNOWN:
76 g_utf8_strncpy(str, "LOCATION_ERROR_UNKNOWN", STR_MAX);
79 g_utf8_strncpy(str, "Error: undefined error code", STR_MAX);
83 static void GetStatus(char str[STR_MAX], LocationStatus acc_level)
87 case LOCATION_STATUS_NO_FIX:
88 g_utf8_strncpy(str, "LOCATION_STATUS_NO_FIX", STR_MAX);
90 case LOCATION_STATUS_2D_FIX:
91 g_utf8_strncpy(str, "LOCATION_STATUS_2D_FIX", STR_MAX);
93 case LOCATION_STATUS_3D_FIX:
94 g_utf8_strncpy(str, "LOCATION_STATUS_3D_FIX", STR_MAX);
97 g_utf8_strncpy(str, "Error: undefined status code", STR_MAX);
101 static void GetMethod(char str[STR_MAX], LocationMethod acc_level)
105 case LOCATION_METHOD_HYBRID:
106 g_utf8_strncpy(str, "LOCATION_METHOD_HYBRID", STR_MAX);
108 case LOCATION_METHOD_GPS:
109 g_utf8_strncpy(str, "LOCATION_METHOD_GPS", STR_MAX);
111 case LOCATION_METHOD_CPS:
112 g_utf8_strncpy(str, "LOCATION_METHOD_CPS", STR_MAX);
114 case LOCATION_METHOD_IPS:
115 g_utf8_strncpy(str, "LOCATION_METHOD_IPS", STR_MAX);
117 case LOCATION_METHOD_WPS:
118 g_utf8_strncpy(str, "LOCATION_METHOD_WPS", STR_MAX);
120 case LOCATION_METHOD_SPS:
121 g_utf8_strncpy(str, "LOCATION_METHOD_SPS", STR_MAX);
124 g_utf8_strncpy(str, "Error: undefined method", STR_MAX);
128 static void GetAccuracyLevel(char str[STR_MAX], LocationAccuracyLevel acc_level)
132 case LOCATION_ACCURACY_LEVEL_NONE:
133 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_NONE", STR_MAX);
135 case LOCATION_ACCURACY_LEVEL_COUNTRY:
136 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_COUNTRY", STR_MAX);
138 case LOCATION_ACCURACY_LEVEL_REGION:
139 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_REGION", STR_MAX);
141 case LOCATION_ACCURACY_LEVEL_LOCALITY:
142 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_LOCALITY", STR_MAX);
144 case LOCATION_ACCURACY_LEVEL_POSTALCODE:
145 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_POSTALCODE", STR_MAX);
147 case LOCATION_ACCURACY_LEVEL_STREET:
148 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_STREET", STR_MAX);
150 case LOCATION_ACCURACY_LEVEL_DETAILED:
151 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_DETAILED", STR_MAX);
154 g_utf8_strncpy(str, "Error: undefined accuracy level", STR_MAX);
159 static void SelectOpt(char* buf)
162 fgets(buf, 255, stdin);
163 iLen = g_utf8_strlen(buf, -1);
167 static int PromptInt()
171 fgets(buf, 255, stdin);
172 buf[strlen(buf)-1]='\0';
173 ret = g_ascii_strtoll(buf, NULL, 10);
177 static double PromptDB()
181 fgets(buf, 255, stdin);
182 buf[strlen(buf)-1]='\0';
183 ret = g_ascii_strtod(buf, NULL);
187 gulong g_sig_enable = 0;
188 gulong g_sig_disable = 0;
189 gulong g_sig_update = 0;
190 gulong g_sig_zonein = 0;
191 gulong g_sig_zoneout = 0;
193 static void PrintPolygonPosition(gpointer data, gpointer user_data)
195 LocationPosition *position = (LocationPosition*) data;
196 g_printf("[%lf %lf %lf] ", position->latitude, position->longitude, position->altitude);
199 static void PrintBoundary(LocationBoundary *boundary, void *user_data)
201 if(boundary == NULL) return;
202 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
203 g_printf("\n\tCIRCLE: center[%lf %lf %lf] radius[%lf]",
204 boundary->circle.center->latitude, boundary->circle.center->longitude, boundary->circle.center->altitude, boundary->circle.radius);
205 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
206 g_printf("\n\tRECT: left_top[%lf %lf %lf] right_bottom[%lf %lf %lf]",
207 boundary->rect.left_top->latitude, boundary->rect.left_top->longitude, boundary->rect.left_top->altitude,
208 boundary->rect.right_bottom->latitude, boundary->rect.right_bottom->longitude, boundary->rect.right_bottom->altitude);
209 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
210 g_printf("\n\tPOLYGON: ");
212 GList *list = boundary->polygon.position_list;
214 g_list_foreach(list, PrintPolygonPosition, NULL);
218 static void RemoveBoundary(LocationBoundary *boundary, void *user_data)
220 LocationObject * obj = (LocationObject *)user_data;
221 if(obj == NULL || boundary == NULL) return;
223 location_boundary_remove(obj, boundary);
226 static void PrintProperty (LocationObject* loc)
229 LocationMethod method = LOCATION_METHOD_NONE;
230 LocationPosition *pos = NULL;
232 gchar method_str[STR_MAX] = {0, };
233 gchar status_str[STR_MAX] = {0, };
235 gchar* devname = NULL;
237 g_object_get(loc, "method", &method, NULL);
238 GetMethod(method_str, method);
239 g_printf("method[%s] ", method_str);
241 if (LOCATION_METHOD_GPS == method) {
242 g_object_get(loc, "dev-name", &devname, NULL);
244 g_printf("dev-name[%s] ", devname);
249 g_object_get(loc, "last-position", &pos, NULL);
251 GetStatus(status_str, pos->status);
252 g_printf("\nLast position [time(%d) lat(%f) long(%f) alt(%f) status(%s)]",
253 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, status_str);
254 location_position_free (pos);
257 g_object_get(loc, "update-interval", &interval, NULL);
258 g_printf("Update interval : [%u]", interval);
260 if (LOCATION_METHOD_CPS == method || LOCATION_METHOD_IPS == method) return;
262 g_printf("\nSignals: ");
263 if (g_sig_enable) g_printf("[service-enabled], ");
264 if (g_sig_disable) g_printf("[service-disabled], ");
265 if (g_sig_update) g_printf("[service-updated], ");
266 if (g_sig_zonein) g_printf("[zone-in], ");
267 if (g_sig_zoneout) g_printf("[zone-out]");
270 static void cb_service_enabled (GObject *self, guint status, gpointer userdata)
272 g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
274 LocationObject *loc = (LocationObject*)userdata;
275 LocationAccuracy *acc = NULL;
276 LocationPosition *pos = NULL;
277 LocationVelocity *vel = NULL;
278 LocationAddress *addr = NULL;
279 LocationMethod method;
281 g_object_get(loc, "method", &method, NULL);
282 g_debug("Get property>> method:%d", method);
284 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
285 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
286 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
287 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
288 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
289 location_position_free(pos);
290 location_accuracy_free(acc);
291 } else g_warning ("SYNC>> Current position> failed");
292 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
293 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
294 vel->timestamp, vel->speed, vel->direction, vel->climb);
295 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
296 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
297 location_velocity_free(vel);
298 location_accuracy_free(acc);
299 } else g_warning ("SYNC>> Current velocity> failed");
300 if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
301 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
302 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
303 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
304 location_address_free(addr);
305 location_accuracy_free(acc);
306 } else g_warning ("SYNC>> Current address> failed");
310 cb_service_disabled (GObject *self,
314 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
318 cb_zone_in (GObject *self,
323 g_debug("cb_zone_in: type(%d)", type);
324 LocationPosition *pos = (LocationPosition*) position;
325 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
327 g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
328 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
329 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
330 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
334 cb_zone_out (GObject *self,
339 g_debug("cb_zone_out: type(%d)", type);
340 LocationPosition *pos = (LocationPosition*) position;
341 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
343 g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
344 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
345 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
346 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
350 cb_service_updated (GObject *self,
356 g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
358 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
360 case POSITION_UPDATED: {
361 LocationPosition *pos = (LocationPosition*) data;
362 g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
363 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
364 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
365 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
368 case VELOCITY_UPDATED: {
369 LocationVelocity *vel = (LocationVelocity*) data;
370 g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
371 vel->timestamp, vel->speed, vel->direction, vel->climb);
372 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
373 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
377 g_warning ("ASYNC>> Undefined update type");
382 static void cb_position (LocationError error,
383 LocationPosition *position,
384 LocationAccuracy *acc,
387 if (error != LOCATION_ERROR_NONE) {
388 g_printf("cb_position failed: error=%d\n", error);
392 g_printf("userdata[0x%x] time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", (unsigned int)userdata, position->timestamp, position->latitude, position->longitude, position->altitude);
393 GetAccuracyLevel(str, acc->level);
394 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
397 static void cb_address(LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata)
399 if (error != LOCATION_ERROR_NONE) {
400 g_printf("cb_address failed: error=%d\n", error);
404 g_printf("userdata[0x%x] building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
405 (unsigned int)userdata, addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
406 GetAccuracyLevel(str, acc->level);
407 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
412 LocationPosition *pos;
413 LocationAddress *addr;
415 LocationPositionCB pos_cb;
416 LocationAddressCB addr_cb;
420 static gboolean idle_position_from_address_async(gpointer data)
422 IdleData* idle_data = (IdleData*)data;
424 int ret = location_get_position_from_address_async(idle_data->obj, idle_data->addr, idle_data->pos_cb, idle_data->user_data);
425 GetLocationError(str, ret);
426 g_printf("location_get_position_from_address_async: returned value [%s]\n", str);
427 location_address_free(idle_data->addr);
432 static gboolean idle_position_from_freefromed_address_async(gpointer data)
434 IdleData* idle_data = (IdleData*)data;
436 int ret = location_get_position_from_freeformed_address_async(idle_data->obj, idle_data->str_addr, idle_data->pos_cb, idle_data->user_data);
437 GetLocationError(str, ret);
438 g_printf("location_get_position_from_freeformed_address_async: returned value [%s]\n", str);
439 g_free(idle_data->str_addr);
444 static gboolean idle_address_async(gpointer data)
446 IdleData* idle_data = (IdleData*)data;
448 int ret = location_get_address_async(idle_data->obj, idle_data->addr_cb, idle_data->user_data);
449 GetLocationError(str, ret);
450 g_printf("location_get_address_async: returned value [%s]\n", str);
455 static gboolean idle_address_from_position_async(gpointer data)
457 IdleData* idle_data = (IdleData*)data;
459 int ret = location_get_address_from_position_async(idle_data->obj, idle_data->pos, idle_data->addr_cb, idle_data->user_data);
460 GetLocationError(str, ret);
461 g_printf("location_get_address_from_position_async: returned value [%s]\n", str);
462 location_position_free(idle_data->pos);
467 static void print_menu()
469 g_printf("\n================================= Location API Test =================================\n");
470 g_printf("q. Exit\n");
471 g_printf("1. location_init\n");
472 g_printf("2. location_new\n");
473 g_printf("3. location_free\n");
474 g_printf("4. location_start\n");
475 g_printf("5. location_stop\n");
476 g_printf("6. location_get_position\n");
477 g_printf("6a. location_get_last_known_position\n");
478 g_printf("7. location_get_position_from_address\n");
479 g_printf("7a. location_get_position_from_address_async\n");
480 g_printf("8. location_get_position_from_freeformed_address\n");
481 g_printf("8a. location_get_position_from_freeformed_address_async\n");
482 g_printf("9. location_get_velocity\n");
483 g_printf("10. location_get_address\n");
484 g_printf("10a. location_get_address_async\n");
485 g_printf("11. location_get_address_from_position\n");
486 g_printf("11a. location_get_address_from_position_async\n");
487 g_printf("12. location_get_distance\n");
488 g_printf("13. location_is_supported_method\n");
489 g_printf("14. location_is_enabled_gps\n");
490 g_printf("99. location_send_command\n");
491 g_printf("a?. signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
492 g_printf("b?. disconnect signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
493 g_printf("c?. (1)Set boundary, (2)Get boundary, (3) Remove boundary, (4) Remove all boundaries, (5)Set device name, (6)Set update interval\n");
494 g_printf("==================================== Property ====================================\n");
495 PrintProperty(location_obj);
496 g_printf("\n==================================================================================\n");
499 int main(int argc, char** argv)
506 // If application is executed by AUL, this is not needed.
507 g_setenv("PKG_NAME", "org.tizen.location-api-test", 1);
510 if( !g_thread_supported() )
516 g_main = g_thread_create(GmainThread, NULL, TRUE, &gerr);
518 g_debug("Error create gmain thread: Err domain[%d] Err code[%d] Err msg[%s]",
519 gerr->domain, gerr->code, gerr->message);
524 json_util_init(LOCATION_API_TEST_JSON_FILE);
525 g_printf("--- Start LBS Test App ---\n");
529 g_printf("Select option: ");
531 g_printf("======================================================================================\n");
532 if (0 == g_strcmp0 ("x", strOpt)) {
535 else if (0 == g_strcmp0("1",strOpt)) {
536 ret = location_init();
537 GetLocationError(str, ret);
538 g_printf("location_init: returned value [%s]\n", str);
539 } else if (0 == g_strcmp0("2",strOpt)) {
541 g_printf("Location object already existed: [0x%x]", (unsigned int)location_obj);
544 g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_CPS[3] LOCATION_METHOD_IPS[4] LOCATION_METHOD_SPS[5]\n");
545 g_printf("Select Location Method: ");
546 LocationMethod method = PromptInt();
547 location_obj = location_new(method);
548 if(location_obj) g_printf("Success\n");
549 else g_printf("Failed\n");
550 } else if (0 == g_strcmp0("3",strOpt)) {
551 ret = location_free (location_obj);
558 GetLocationError(str, ret);
559 g_printf("location_free: returned value [%s]\n", str);
560 } else if (0 == g_strcmp0("4",strOpt)) {
561 ret = location_start(location_obj);
562 GetLocationError(str, ret);
563 g_printf("location_start: returned value [%s]\n", str);
564 } else if (0 == g_strcmp0("5",strOpt)) {
565 ret = location_stop(location_obj);
566 GetLocationError(str, ret);
567 g_printf("location_stop: returned value [%s]\n", str);
568 } else if (0 == g_strcmp0("6",strOpt)) {
569 LocationPosition *pos = NULL;
570 LocationAccuracy *acc = NULL;
571 ret = location_get_position(location_obj, &pos, &acc);
572 GetLocationError(str, ret);
573 g_printf("location_get_position: returned value [%s]\n", str);
574 if (ret == LOCATION_ERROR_NONE) {
575 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f], status: [%d]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
576 GetAccuracyLevel(str, acc->level);
577 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
579 if(pos) location_position_free(pos);
580 if(acc) location_accuracy_free(acc);
581 } else if (0 == g_strcmp0("6a",strOpt)) {
582 LocationLastPosition last_pos;
583 ret = location_get_last_known_position(location_obj, &last_pos);
584 GetLocationError(str, ret);
585 g_printf("location_get_last_known_position: returned value [%s]\n", str);
586 if (ret == LOCATION_ERROR_NONE) {
587 g_printf("last position latitude: [%f], longitude: [%f], accuracy: [%f]\n", last_pos.latitude, last_pos.longitude, last_pos.accuracy);
589 } else if (0 == g_strcmp0("7",strOpt)) {
590 LocationAddress *add = NULL;
591 LocationPosition *pos = NULL;
592 LocationAccuracy *acc = NULL;
594 g_printf("[0].San jose [1].¼ö¿ø»ï¼º [2].Suwon HQ [*].Custom\n");
595 g_printf("Select Address: ");
596 int opt = PromptInt();
597 if (opt == 0) add = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
598 else if (opt == 1) add = location_address_new (NULL, "»ï¼º·Î", "¸Åź3µ¿", "¼ö¿ø½Ã ¿µÅ뱸", "°æ±âµµ", NULL, NULL);
599 else if (opt == 2) add = location_address_new (NULL, "Samsung Electro-Mechanics Co. LTD", "Maetan 3-dong", "Suwon Si Yeongtong-gu", "Gyeonggi-do", NULL, NULL);
601 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
602 g_printf("Input building number: ");
603 fgets(building_number, 255, stdin);
604 building_number[strlen(building_number)-1]='\0';
605 g_printf("Input street: ");
606 fgets(street, 255, stdin);
607 street[strlen(street)-1]='\0';
608 g_printf("Input state: ");
609 fgets(state, 255, stdin);
610 state[strlen(state)-1]='\0';
611 g_printf("Input country code: ");
612 fgets(country_code, 255, stdin);
613 country_code[strlen(country_code)-1]='\0';
614 g_printf("Input city: ");
615 fgets(city, 255, stdin);
616 city[strlen(city)-1]='\0';
617 g_printf("Input district: ");
618 fgets(district, 255, stdin);
619 district[strlen(district)-1]='\0';
620 g_printf("Input postal code: ");
621 fgets(postal_code, 255, stdin);
622 postal_code[strlen(postal_code)-1]='\0';
623 add = location_address_new(building_number, street, district, city, state, country_code, postal_code);
625 ret = location_get_position_from_address (location_obj, add, &pos, &acc);
626 if(add) location_address_free (add);
627 GetLocationError(str, ret);
628 g_printf("location_get_position_from_adress: returned value [%s]\n", str);
629 if (ret == LOCATION_ERROR_NONE)
630 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
631 if(pos) location_position_free(pos);
632 if(acc) location_accuracy_free(acc);
633 } else if (0 == g_strcmp0("7a",strOpt)) {
634 IdleData* data = g_new0(IdleData, 1);
635 data->obj = location_obj;
636 data->pos_cb = cb_position;
637 data->user_data = location_obj;
639 g_printf("[0].San jose [1].¼ö¿ø»ï¼º [2].Suwon HQ [*].Custom\n");
640 g_printf("Select Address: ");
641 int opt = PromptInt();
642 if (opt == 0) data->addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
643 else if (opt == 1) data->addr = location_address_new (NULL, "»ï¼º·Î", "¸Åź3µ¿", "¼ö¿ø½Ã ¿µÅ뱸", "°æ±âµµ", NULL, NULL);
644 else if (opt == 2) data->addr = location_address_new (NULL, "Samsung Electro-Mechanics Co. LTD", "Maetan 3-dong", "Suwon Si Yeongtong-gu", "Gyeonggi-do", NULL, NULL);
646 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
647 g_printf("Input building number: ");
648 fgets(building_number, 255, stdin);
649 building_number[strlen(building_number)-1]='\0';
650 g_printf("Input street: ");
651 fgets(street, 255, stdin);
652 street[strlen(street)-1]='\0';
653 g_printf("Input state: ");
654 fgets(state, 255, stdin);
655 state[strlen(state)-1]='\0';
656 g_printf("Input country code: ");
657 fgets(country_code, 255, stdin);
658 country_code[strlen(country_code)-1]='\0';
659 g_printf("Input city: ");
660 fgets(city, 255, stdin);
661 city[strlen(city)-1]='\0';
662 g_printf("Input district: ");
663 fgets(district, 255, stdin);
664 district[strlen(district)-1]='\0';
665 g_printf("Input postal code: ");
666 fgets(postal_code, 255, stdin);
667 postal_code[strlen(postal_code)-1]='\0';
668 data->addr = location_address_new(building_number, street, district, city, state, country_code, postal_code);
670 g_idle_add((GSourceFunc)idle_position_from_address_async, data);
671 }else if (0 == g_strcmp0("8",strOpt)) {
673 LocationPosition *pos = NULL;
674 LocationAccuracy *acc = NULL;
676 g_printf("[0].San jose [1].¼ö¿ø»ï¼º [2].Suwon HQ [*].Custom\n");
677 g_printf("Select Address: ");
678 int opt = PromptInt();
680 addr = g_strdup("4 N 2nd Street 95113");
682 addr = g_strdup("´ëÇѹα¹ °æ±âµµ ¼ö¿ø½Ã ¿µÅ뱸 ¸Åźµ¿ 436-52");
684 addr = g_strdup("Samsung Electronics Co. LTD Maetan 3-dong, Suwon Si Yeongtong-gu, Gyeonggi-Do (Seoul 443-742 Korea), Rep of KOREA");
687 g_printf("Input freeform address: ");
688 fgets(buf, 255, stdin);
689 buf[strlen(buf)-1]='\0';
690 addr = g_strdup(buf);
692 ret = location_get_position_from_freeformed_address(location_obj, addr, &pos, &acc);
694 GetLocationError(str, ret);
695 g_printf("location_get_position_from_freeformed_adress: returned value [%s]\n", str);
696 if(ret == LOCATION_ERROR_NONE){
697 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
699 if(pos) location_position_free(pos);
700 if(acc) location_accuracy_free(acc);
701 }else if(0 == g_strcmp0("8a",strOpt) ){
702 IdleData* data = g_new0(IdleData, 1);
703 data->obj = location_obj;
704 data->pos_cb = cb_position;
705 data->user_data = location_obj;
706 g_printf("[0].San jose [1].¼ö¿ø»ï¼º [2].Suwon HQ [*].Custom\n");
707 g_printf("Select Address: ");
708 int opt = PromptInt();
710 data->str_addr = g_strdup("4 N 2nd Street 95113");
712 data->str_addr = g_strdup("´ëÇѹα¹ °æ±âµµ ¼ö¿ø½Ã ¿µÅ뱸 ¸Åźµ¿ 436-52");
714 data->str_addr = g_strdup("Samsung Electronics Co. LTD Maetan 3-dong, Suwon Si Yeongtong-gu, Gyeonggi-Do (Seoul 443-742 Korea), Rep of KOREA");
717 g_printf("Input freeform address: ");
718 fgets(buf, 255, stdin);
719 buf[strlen(buf)-1]='\0';
720 data->str_addr = g_strdup(buf);
722 g_idle_add((GSourceFunc)idle_position_from_freefromed_address_async, data);
724 }else if(0 == g_strcmp0("9",strOpt) ){
725 LocationVelocity *vel = NULL;
726 LocationAccuracy *acc = NULL;
727 ret = location_get_velocity(location_obj, &vel, &acc);
728 GetLocationError(str, ret);
729 g_printf("location_get_velocity: returned value [%s]\n", str);
730 if (ret == LOCATION_ERROR_NONE) {
731 g_printf("time: [%d], speed: [%f], direction: [%f], climb: [%f]\n", vel->timestamp, vel->speed, vel->direction, vel->climb);
732 GetAccuracyLevel(str, acc->level);
733 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
735 if(vel) location_velocity_free(vel);
736 if(acc) location_accuracy_free(acc);
737 } else if(0 == g_strcmp0("10",strOpt) ){
738 LocationAddress *addr = NULL;
739 LocationAccuracy *acc = NULL;
740 ret = location_get_address(location_obj, &addr, &acc);
741 GetLocationError(str, ret);
742 g_printf("location_get_address: returned value [%s]\n", str);
743 if(ret == LOCATION_ERROR_NONE){
744 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
745 addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
746 GetAccuracyLevel(str, acc->level);
747 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
749 }else if(0 == g_strcmp0("10a",strOpt) ){
750 IdleData* data = g_new0(IdleData, 1);
751 data->obj = location_obj;
752 data->addr_cb = cb_address;
753 data->user_data = location_obj;
754 g_idle_add((GSourceFunc)idle_address_async, data);
755 }else if(0 == g_strcmp0("11",strOpt) ){
756 LocationPosition *pos = NULL;
757 LocationAddress *addr = NULL;
758 LocationAccuracy *acc = NULL;
759 g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
760 g_printf("Select Position: ");
761 int opt = PromptInt();
762 if(opt == 0) pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
763 else if(opt == 1) pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
765 g_printf("Input latitude: ");
766 gdouble lat = PromptDB();
767 g_printf("Input longitude: ");
768 gdouble lon = PromptDB();
769 pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
771 ret = location_get_address_from_position(location_obj, pos, &addr, &acc);
772 GetLocationError(str, ret);
773 g_printf("location_get_address_from_position: returned value [%s]\n", str);
774 if(ret == LOCATION_ERROR_NONE){
775 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
776 addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
778 if(addr) location_address_free(addr);
779 if(acc) location_accuracy_free(acc);
780 }else if(0 == g_strcmp0("11a",strOpt) ){
781 IdleData* data = g_new0(IdleData, 1);
782 data->obj = location_obj;
783 data->addr_cb = cb_address;
784 data->user_data = location_obj;
786 g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
787 g_printf("Select Position: ");
788 int opt = PromptInt();
789 if(opt == 0) data->pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
790 else if (opt == 1) data->pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
792 g_printf("Input latitude: ");
793 gdouble lat = PromptDB();
794 g_printf("Input longitude: ");
795 gdouble lon = PromptDB();
796 data->pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
798 g_idle_add((GSourceFunc)idle_address_from_position_async, data);
799 }else if(0 == g_strcmp0("12",strOpt) ) {
804 LocationPosition pos1, pos2;
806 pos1.latitude = 50.0663222;
807 pos1.longitude = -5.71475;
809 pos2.latitude = 58.6441;
810 pos2.longitude = -3.070094;
812 ret = location_get_distance(&pos1, &pos2, &distance);
813 GetLocationError(str, ret);
814 if(ret != LOCATION_ERROR_NONE) {
815 g_printf("Fail to get position. Error[%s]\n", str);
818 g_printf("The approximate distance is [%lu]\n", distance);
819 g_printf("cf.) It is approximately 969954.114 meter\n");
821 }else if(0 == g_strcmp0("13", strOpt)) {
823 char method_str[STR_MAX] = {0, };
824 char input[8] = {0, };
825 gboolean is_supported = FALSE;
827 g_printf("0.Hybrid 1.GPS 2.WPS 3.CPS(X) 4.IPS(X) 5.SPS\n");
828 g_printf("Select Method :");
829 fgets(input, 8, stdin);
830 method = atoi(input);
832 case LOCATION_METHOD_HYBRID:
833 is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID);
836 case LOCATION_METHOD_GPS:
837 is_supported = location_is_supported_method(LOCATION_METHOD_GPS);
840 case LOCATION_METHOD_WPS:
841 is_supported = location_is_supported_method(LOCATION_METHOD_WPS);
844 case LOCATION_METHOD_SPS:
845 is_supported = location_is_supported_method(LOCATION_METHOD_SPS);
848 case LOCATION_METHOD_CPS:
849 case LOCATION_METHOD_IPS:
854 GetMethod(method_str, method);
856 g_printf("Method[%s] is %s.", method_str, is_supported ? "supported" : "not supported");
858 }else if(0 == g_strcmp0("14", strOpt)) {
859 gboolean is_enabled = FALSE;
860 is_enabled = location_is_enabled_gps(location_obj);
861 if(is_enabled == TRUE) g_printf("GPS is turned on");
862 else g_printf("GPS is turned off");
863 }else if(0 == g_strcmp0("99", strOpt)) {
865 const *str = "command";
866 ret = location_send_command(str);
868 g_printf("Success to send command[%s]", str);
869 }else if(0 == g_strcmp0("a1",strOpt)){
870 if(location_obj && !g_sig_enable) {
871 g_sig_enable = g_signal_connect (location_obj, "service-enabled", G_CALLBACK(cb_service_enabled), location_obj);
873 }else if(0 == g_strcmp0("a2",strOpt)){
874 if(location_obj && !g_sig_disable){
875 g_sig_disable = g_signal_connect (location_obj, "service-disabled", G_CALLBACK(cb_service_disabled), location_obj);
877 }else if(0 == g_strcmp0("a3",strOpt)){
878 if(location_obj && !g_sig_update){
879 g_sig_update = g_signal_connect (location_obj, "service-updated", G_CALLBACK(cb_service_updated), location_obj);
881 }else if(0 == g_strcmp0("a4",strOpt)){
882 if(location_obj && !g_sig_zonein){
883 g_sig_zonein = g_signal_connect (location_obj, "zone-in", G_CALLBACK(cb_zone_in), location_obj);
885 }else if(0 == g_strcmp0("a5",strOpt)){
886 if(location_obj && !g_sig_zoneout){
887 g_sig_zoneout = g_signal_connect (location_obj, "zone-out", G_CALLBACK(cb_zone_out), location_obj);
889 }else if(0 == g_strcmp0("b1",strOpt)){
890 if(location_obj && g_sig_enable) {
891 g_signal_handler_disconnect (location_obj, g_sig_enable);
894 }else if(0 == g_strcmp0("b2",strOpt)){
895 if(location_obj && g_sig_disable){
896 g_signal_handler_disconnect (location_obj, g_sig_disable);
899 }else if(0 == g_strcmp0("b3",strOpt)){
900 if(location_obj && g_sig_update){
901 g_signal_handler_disconnect (location_obj, g_sig_update);
904 }else if(0 == g_strcmp0("b4",strOpt)){
905 if(location_obj && g_sig_zonein){
906 g_signal_handler_disconnect (location_obj, g_sig_zonein);
909 }else if(0 == g_strcmp0("b5",strOpt)){
910 if(location_obj && g_sig_zoneout){
911 g_signal_handler_disconnect (location_obj, g_sig_zoneout);
914 }else if(0 == g_strcmp0("c1",strOpt)){
915 LocationBoundary* bound = NULL;
917 int polygon_count = json_util_get_polygon_count();
919 g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
920 for(i = 0; i < polygon_count; i++)
921 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
923 g_printf("\nSelect Boundary: ");
924 int opt = PromptInt();
926 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
927 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
928 bound = location_boundary_new_for_rect (lt, rb);
929 location_position_free(rb);
930 location_position_free(lt);
932 location_boundary_add(location_obj, bound);
934 } else if(opt == 1) {
935 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
936 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
937 bound = location_boundary_new_for_rect (lt, rb);
938 location_position_free(rb);
939 location_position_free(lt);
941 location_boundary_add(location_obj, bound);
942 } else if(opt == 2) {
943 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
944 double radius = 10.0;
945 bound = location_boundary_new_for_circle(center, radius);
947 location_boundary_add(location_obj, bound);
948 } else if (opt > 2 && opt < 3 + polygon_count) {
950 int polygon_index = opt - 3;
951 bound = json_util_get_polygon_boundary(polygon_index);
952 location_boundary_add(location_obj, bound);
954 LocationPosition * check_pos = NULL;
955 gboolean ret = FALSE;
956 int count = json_util_get_marker_position_count(polygon_index);
957 for(index = 0; index < count; index++) {
958 check_pos = json_util_get_marker_position(polygon_index, index);
960 ret = location_boundary_if_inside(bound, check_pos);
961 g_printf("[%s] is [%s] and the test result is [%s]\n", json_util_get_marker_name(polygon_index, index), json_util_result_zone_test(polygon_index, index), ret == TRUE? "inside": "outside");
962 location_position_free(check_pos);
965 g_printf("boundary is not set\n");
967 location_boundary_free(bound);
969 }else if(0 == g_strcmp0("c2",strOpt)){
970 g_printf("Get Boundary\n");
971 location_boundary_foreach(location_obj, PrintBoundary, NULL);
973 }else if(0 == g_strcmp0("c3",strOpt)){
974 g_printf("Remove Boundary\n");
975 LocationBoundary* bound = NULL;
978 int polygon_count = json_util_get_polygon_count();
980 g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
981 for(i = 0; i < polygon_count; i++)
982 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
984 g_printf("\nSelect Boundary: ");
985 int opt = PromptInt();
987 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
988 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
989 bound = location_boundary_new_for_rect (lt, rb);
990 location_position_free(rb);
991 location_position_free(lt);
993 } else if(opt == 1) {
994 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
995 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
996 bound = location_boundary_new_for_rect (lt, rb);
997 location_position_free(rb);
998 location_position_free(lt);
1000 } else if(opt == 2) {
1001 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
1002 double radius = 10.0;
1003 bound = location_boundary_new_for_circle(center, radius);
1004 location_position_free(center);
1006 } else if (opt > 2 && opt < 3 + polygon_count) {
1007 int polygon_index = opt - 3;
1008 bound = json_util_get_polygon_boundary(polygon_index);
1010 g_printf("Invalid value\n");
1013 if(bound != NULL) location_boundary_remove(location_obj, bound);
1015 }else if(0 == g_strcmp0("c4",strOpt)){
1016 location_boundary_foreach(location_obj, RemoveBoundary, location_obj);
1017 }else if(0 == g_strcmp0("c5",strOpt)){
1019 g_printf("Input device name: ");
1020 fgets(buf, 255, stdin);
1021 buf[strlen(buf)-1]='\0';
1022 g_object_set(location_obj, "dev-name", buf, NULL);
1023 } else if (0 == g_strcmp0("c6", strOpt)) {
1025 g_printf("Input interval[1~120]:");
1026 scanf("%u", &interval);
1027 g_printf("changed interval to [%u]\n", interval);
1028 g_object_set(location_obj, "update-interval", interval, NULL);
1029 }else if(0 == g_strcmp0("q",strOpt) ){
1030 g_main_loop_quit(g_mainloop);
1034 g_thread_join(g_main);
1035 g_printf("\n--- Exit LBS Test App ---\n");