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.
24 #include <glib/gprintf.h>
25 #include <gconf/gconf-client.h>
26 #include <location/location.h>
27 #include "location-api-test-util.h"
30 LocationObject* location_obj = NULL;
31 static GMainLoop *g_mainloop = NULL;
33 #define GCONF_PROXY_MODE "/system/proxy/mode"
34 #define GCONF_HTTP_PROXY_HOST "/system/http_proxy/host"
35 #define GCONF_HTTP_PROXY_PORT "/system/http_proxy/port"
36 #define ENV_HTTP_PROXY "http_proxy"
38 #define LOCATION_API_TEST_JSON_FILE "/opt/data/location-api-test.json"
40 static gpointer GmainThread(gpointer data)
42 g_mainloop = g_main_loop_new (NULL, FALSE);
43 g_printf("\n...Entering GMain Loop to Receive Notifications....\n");
44 g_main_loop_run (g_mainloop);
45 g_main_loop_unref (g_mainloop);
51 static void GetLocationError(char str[STR_MAX], int ret)
55 case LOCATION_ERROR_NONE:
56 g_utf8_strncpy(str, "LOCATION_ERROR_NONE", STR_MAX);
58 case LOCATION_ERROR_NOT_ALLOWED:
59 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_ALLOWED", STR_MAX);
61 case LOCATION_ERROR_NOT_AVAILABLE:
62 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_AVAILABLE", STR_MAX);
64 case LOCATION_ERROR_NETWORK_FAILED:
65 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_FAILED", STR_MAX);
67 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
68 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_NOT_CONNECTED", STR_MAX);
70 case LOCATION_ERROR_CONFIGURATION:
71 g_utf8_strncpy(str, "LOCATION_ERROR_CONFIGURATION", STR_MAX);
73 case LOCATION_ERROR_PARAMETER:
74 g_utf8_strncpy(str, "LOCATION_ERROR_PARAMETER", STR_MAX);
76 case LOCATION_ERROR_UNKNOWN:
77 g_utf8_strncpy(str, "LOCATION_ERROR_UNKNOWN", STR_MAX);
80 g_utf8_strncpy(str, "Error: undefined error code", STR_MAX);
84 static void GetStatus(char str[STR_MAX], LocationStatus acc_level)
88 case LOCATION_STATUS_NO_FIX:
89 g_utf8_strncpy(str, "LOCATION_STATUS_NO_FIX", STR_MAX);
91 case LOCATION_STATUS_2D_FIX:
92 g_utf8_strncpy(str, "LOCATION_STATUS_2D_FIX", STR_MAX);
94 case LOCATION_STATUS_3D_FIX:
95 g_utf8_strncpy(str, "LOCATION_STATUS_3D_FIX", STR_MAX);
98 g_utf8_strncpy(str, "Error: undefined status code", STR_MAX);
102 static void GetMethod(char str[STR_MAX], LocationMethod acc_level)
106 case LOCATION_METHOD_HYBRID:
107 g_utf8_strncpy(str, "LOCATION_METHOD_HYBRID", STR_MAX);
109 case LOCATION_METHOD_GPS:
110 g_utf8_strncpy(str, "LOCATION_METHOD_GPS", STR_MAX);
112 case LOCATION_METHOD_CPS:
113 g_utf8_strncpy(str, "LOCATION_METHOD_CPS", STR_MAX);
115 case LOCATION_METHOD_IPS:
116 g_utf8_strncpy(str, "LOCATION_METHOD_IPS", STR_MAX);
118 case LOCATION_METHOD_WPS:
119 g_utf8_strncpy(str, "LOCATION_METHOD_WPS", STR_MAX);
121 case LOCATION_METHOD_SPS:
122 g_utf8_strncpy(str, "LOCATION_METHOD_SPS", STR_MAX);
125 g_utf8_strncpy(str, "Error: undefined method", STR_MAX);
129 static void GetAccuracyLevel(char str[STR_MAX], LocationAccuracyLevel acc_level)
133 case LOCATION_ACCURACY_LEVEL_NONE:
134 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_NONE", STR_MAX);
136 case LOCATION_ACCURACY_LEVEL_COUNTRY:
137 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_COUNTRY", STR_MAX);
139 case LOCATION_ACCURACY_LEVEL_REGION:
140 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_REGION", STR_MAX);
142 case LOCATION_ACCURACY_LEVEL_LOCALITY:
143 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_LOCALITY", STR_MAX);
145 case LOCATION_ACCURACY_LEVEL_POSTALCODE:
146 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_POSTALCODE", STR_MAX);
148 case LOCATION_ACCURACY_LEVEL_STREET:
149 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_STREET", STR_MAX);
151 case LOCATION_ACCURACY_LEVEL_DETAILED:
152 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_DETAILED", STR_MAX);
155 g_utf8_strncpy(str, "Error: undefined accuracy level", STR_MAX);
160 static void SelectOpt(char* buf)
163 fgets(buf, 255, stdin);
164 iLen = g_utf8_strlen(buf, -1);
168 static int PromptInt()
172 fgets(buf, 255, stdin);
173 buf[strlen(buf)-1]='\0';
174 ret = g_ascii_strtoll(buf, NULL, 10);
178 static double PromptDB()
182 fgets(buf, 255, stdin);
183 buf[strlen(buf)-1]='\0';
184 ret = g_ascii_strtod(buf, NULL);
188 static void PrintPos (gpointer data, gpointer user_data)
190 LocationPosition *pos = (LocationPosition *)data;
192 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
193 location_position_free (pos);
197 static void PrintAcc (gpointer data, gpointer user_data)
199 LocationAccuracy *acc = (LocationAccuracy *)data;
201 g_printf("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
202 location_accuracy_free (acc);
207 gulong g_sig_enable = 0;
208 gulong g_sig_disable = 0;
209 gulong g_sig_update = 0;
210 gulong g_sig_zonein = 0;
211 gulong g_sig_zoneout = 0;
213 static void PrintPolygonPosition(gpointer data, gpointer user_data)
215 LocationPosition *position = (LocationPosition*) data;
216 g_printf("[%lf %lf %lf] ", position->latitude, position->longitude, position->altitude);
219 static void PrintBoundary(LocationBoundary *boundary, void *user_data)
221 if(boundary == NULL) return;
222 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
223 g_printf("\n\tCIRCLE: center[%lf %lf %lf] radius[%lf]",
224 boundary->circle.center->latitude, boundary->circle.center->longitude, boundary->circle.center->altitude, boundary->circle.radius);
225 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
226 g_printf("\n\tRECT: left_top[%lf %lf %lf] right_bottom[%lf %lf %lf]",
227 boundary->rect.left_top->latitude, boundary->rect.left_top->longitude, boundary->rect.left_top->altitude,
228 boundary->rect.right_bottom->latitude, boundary->rect.right_bottom->longitude, boundary->rect.right_bottom->altitude);
229 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
230 g_printf("\n\tPOLYGON: ");
232 GList *list = boundary->polygon.position_list;
234 g_list_foreach(list, PrintPolygonPosition, NULL);
238 static void RemoveBoundary(LocationBoundary *boundary, void *user_data)
240 LocationObject * obj = (LocationObject *)user_data;
241 if(obj == NULL || boundary == NULL) return;
243 location_boundary_remove(obj, boundary);
246 static void PrintProperty (LocationObject* loc)
249 LocationMethod method = LOCATION_METHOD_NONE;
250 LocationPosition *pos = NULL;
252 gchar method_str[STR_MAX] = {0, };
253 gchar status_str[STR_MAX] = {0, };
255 gchar* devname = NULL;
257 g_object_get(loc, "method", &method, NULL);
258 GetMethod(method_str, method);
259 g_printf("method[%s] ", method_str);
261 if (LOCATION_METHOD_GPS == method) {
262 g_object_get(loc, "dev-name", &devname, NULL);
264 g_printf("dev-name[%s] ", devname);
269 g_object_get(loc, "last-position", &pos, NULL);
271 GetStatus(status_str, pos->status);
272 g_printf("\nLast position [time(%d) lat(%f) long(%f) alt(%f) status(%s)]",
273 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, status_str);
274 location_position_free (pos);
277 g_object_get(loc, "update-interval", &interval, NULL);
278 g_printf("Update interval : [%u]", interval);
280 if (LOCATION_METHOD_CPS == method || LOCATION_METHOD_IPS == method) return;
282 g_printf("\nSignals: ");
283 if (g_sig_enable) g_printf("[service-enabled], ");
284 if (g_sig_disable) g_printf("[service-disabled], ");
285 if (g_sig_update) g_printf("[service-updated], ");
286 if (g_sig_zonein) g_printf("[zone-in], ");
287 if (g_sig_zoneout) g_printf("[zone-out]");
290 static void cb_service_enabled (GObject *self, guint status, gpointer userdata)
292 g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
294 LocationObject *loc = (LocationObject*)userdata;
295 LocationAccuracy *acc = NULL;
296 LocationPosition *pos = NULL;
297 LocationVelocity *vel = NULL;
298 LocationAddress *addr = NULL;
299 LocationMethod method;
301 g_object_get(loc, "method", &method, NULL);
302 g_debug("Get property>> method:%d", method);
304 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
305 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
306 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
307 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
308 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
309 location_position_free(pos);
310 location_accuracy_free(acc);
311 } else g_warning ("SYNC>> Current position> failed");
312 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
313 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
314 vel->timestamp, vel->speed, vel->direction, vel->climb);
315 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
316 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
317 location_velocity_free(vel);
318 location_accuracy_free(acc);
319 } else g_warning ("SYNC>> Current velocity> failed");
320 if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
321 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
322 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
323 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
324 location_address_free(addr);
325 location_accuracy_free(acc);
326 } else g_warning ("SYNC>> Current address> failed");
330 cb_service_disabled (GObject *self,
334 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
338 cb_zone_in (GObject *self,
343 g_debug("cb_zone_in: type(%d)", type);
344 LocationPosition *pos = (LocationPosition*) position;
345 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
347 g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
348 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
349 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
350 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
354 cb_zone_out (GObject *self,
359 g_debug("cb_zone_out: type(%d)", type);
360 LocationPosition *pos = (LocationPosition*) position;
361 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
363 g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
364 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
365 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
366 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
370 cb_service_updated (GObject *self,
376 g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
378 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
380 case POSITION_UPDATED: {
381 LocationPosition *pos = (LocationPosition*) data;
382 g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
383 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
384 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
385 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
388 case VELOCITY_UPDATED: {
389 LocationVelocity *vel = (LocationVelocity*) data;
390 g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
391 vel->timestamp, vel->speed, vel->direction, vel->climb);
392 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
393 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
397 g_warning ("ASYNC>> Undefined update type");
402 static void cb_position (LocationError error,
407 if (error != LOCATION_ERROR_NONE) {
408 g_printf("cb_position failed: error=%d\n", error);
412 g_list_foreach (pos_list, PrintPos, NULL);
413 g_list_foreach (acc_list, PrintAcc, NULL);
416 static void cb_address(LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata)
418 if (error != LOCATION_ERROR_NONE) {
419 g_printf("cb_address failed: error=%d\n", error);
423 g_printf("userdata[0x%x] building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
424 (unsigned int)userdata, addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
425 GetAccuracyLevel(str, acc->level);
426 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
431 LocationPosition *pos;
432 LocationAddress *addr;
434 LocationPositionCB pos_cb;
435 LocationAddressCB addr_cb;
439 static gboolean idle_position_from_address_async(gpointer data)
441 IdleData* idle_data = (IdleData*)data;
443 int ret = location_get_position_from_address_async(idle_data->obj, idle_data->addr, idle_data->pos_cb, idle_data->user_data);
444 GetLocationError(str, ret);
445 g_printf("location_get_position_from_address_async: returned value [%s]\n", str);
446 location_address_free(idle_data->addr);
451 static gboolean idle_position_from_freefromed_address_async(gpointer data)
453 IdleData* idle_data = (IdleData*)data;
455 int ret = location_get_position_from_freeformed_address_async(idle_data->obj, idle_data->str_addr, idle_data->pos_cb, idle_data->user_data);
456 GetLocationError(str, ret);
457 g_printf("location_get_position_from_freeformed_address_async: returned value [%s]\n", str);
458 g_free(idle_data->str_addr);
463 static gboolean idle_address_async(gpointer data)
465 IdleData* idle_data = (IdleData*)data;
467 int ret = location_get_address_async(idle_data->obj, idle_data->addr_cb, idle_data->user_data);
468 GetLocationError(str, ret);
469 g_printf("location_get_address_async: returned value [%s]\n", str);
474 static gboolean idle_address_from_position_async(gpointer data)
476 IdleData* idle_data = (IdleData*)data;
478 int ret = location_get_address_from_position_async(idle_data->obj, idle_data->pos, idle_data->addr_cb, idle_data->user_data);
479 GetLocationError(str, ret);
480 g_printf("location_get_address_from_position_async: returned value [%s]\n", str);
481 location_position_free(idle_data->pos);
486 static void print_menu()
488 g_printf("\n================================= Location API Test =================================\n");
489 g_printf("q. Exit\n");
490 g_printf("1. location_init\n");
491 g_printf("2. location_new\n");
492 g_printf("3. location_free\n");
493 g_printf("4. location_start\n");
494 g_printf("5. location_stop\n");
495 g_printf("6. location_get_position\n");
496 g_printf("6a. location_get_last_position\n");
497 g_printf("6b. location_get_last_known_position - will be deprecated. \n");
498 g_printf("7. location_get_position_from_address\n");
499 g_printf("7a. location_get_position_from_address_async\n");
500 g_printf("8. location_get_position_from_freeformed_address\n");
501 g_printf("8a. location_get_position_from_freeformed_address_async\n");
502 g_printf("9. location_get_velocity\n");
503 g_printf("9a. location_get_last_velocity\n");
504 g_printf("10. location_get_satellite\n");
505 g_printf("10a. location_get_last_satellite\n");
506 g_printf("11. location_get_address\n");
507 g_printf("11a. location_get_address_async\n");
508 g_printf("12. location_get_address_from_position\n");
509 g_printf("12a. location_get_address_from_position_async\n");
510 g_printf("13. location_get_distance\n");
511 g_printf("14. location_is_supported_method\n");
512 g_printf("15. location_is_enabled_gps\n");
513 g_printf("99. location_send_command\n");
514 g_printf("a?. signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
515 g_printf("b?. disconnect signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
516 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");
517 g_printf("==================================== Property ====================================\n");
518 PrintProperty(location_obj);
519 g_printf("\n==================================================================================\n");
522 int main(int argc, char** argv)
529 // If application is executed by AUL, this is not needed.
530 g_setenv("PKG_NAME", "com.samsung.location-api-test", 1);
533 if( !g_thread_supported() )
539 g_main = g_thread_create(GmainThread, NULL, TRUE, &gerr);
541 g_debug("Error create gmain thread: Err domain[%d] Err code[%d] Err msg[%s]",
542 gerr->domain, gerr->code, gerr->message);
547 json_util_init(LOCATION_API_TEST_JSON_FILE);
548 g_printf("--- Start LBS Test App ---\n");
552 g_printf("Select option: ");
554 g_printf("======================================================================================\n");
555 if (0 == g_strcmp0 ("x", strOpt)) {
558 else if (0 == g_strcmp0("1",strOpt)) {
559 ret = location_init();
560 GetLocationError(str, ret);
561 g_printf("location_init: returned value [%s]\n", str);
562 } else if (0 == g_strcmp0("2",strOpt)) {
564 g_printf("Location object already existed: [0x%x]", (unsigned int)location_obj);
567 g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n");
568 g_printf("Select Location Method: ");
569 LocationMethod method = PromptInt();
570 location_obj = location_new(method);
571 if(location_obj) g_printf("Success\n");
572 else g_printf("Failed\n");
573 } else if (0 == g_strcmp0("3",strOpt)) {
574 ret = location_free (location_obj);
581 GetLocationError(str, ret);
582 g_printf("location_free: returned value [%s]\n", str);
583 } else if (0 == g_strcmp0("4",strOpt)) {
584 ret = location_start(location_obj);
585 GetLocationError(str, ret);
586 g_printf("location_start: returned value [%s]\n", str);
587 } else if (0 == g_strcmp0("5",strOpt)) {
588 ret = location_stop(location_obj);
589 GetLocationError(str, ret);
590 g_printf("location_stop: returned value [%s]\n", str);
591 } else if (0 == g_strcmp0("6",strOpt)) {
592 LocationPosition *pos = NULL;
593 LocationAccuracy *acc = NULL;
594 ret = location_get_position(location_obj, &pos, &acc);
595 GetLocationError(str, ret);
596 g_printf("location_get_position: returned value [%s]\n", str);
597 if (ret == LOCATION_ERROR_NONE) {
598 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f], status: [%d]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
599 GetAccuracyLevel(str, acc->level);
600 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
602 if(pos) location_position_free(pos);
603 if(acc) location_accuracy_free(acc);
604 } else if (0 == g_strcmp0("6a",strOpt)) {
605 g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n");
606 g_printf("Select Location Method: ");
607 LocationMethod method = PromptInt();
608 LocationPosition *last_pos;
609 LocationAccuracy *last_acc;
612 ret = location_get_last_position (location_obj, LOCATION_METHOD_GPS, &last_pos, &last_acc);
613 if (ret == LOCATION_ERROR_NONE) {
614 g_debug ("SYNC>> Last position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
615 last_pos->timestamp, last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->status);
616 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
617 last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
618 location_position_free(last_pos);
619 location_accuracy_free(last_acc);
620 } else g_warning ("SYNC>> Last position> failed. Error[%d]",ret);
622 } else if (0 == g_strcmp0("6b",strOpt)) {
623 g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n");
624 g_printf("Select Location Method: ");
625 LocationMethod method = PromptInt();
626 LocationLastPosition last_pos;
627 ret = location_get_last_known_position(location_obj, method, &last_pos);
628 GetLocationError(str, ret);
629 g_printf("location_get_last_known_position: returned value [%s]\n", str);
630 if (ret == LOCATION_ERROR_NONE) {
631 g_printf("last position method[%d], latitude: [%f], longitude: [%f], altitude: [%f], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", last_pos.method, last_pos.latitude, last_pos.longitude, last_pos.altitude, last_pos.horizontal_accuracy, last_pos.vertical_accuracy);
633 } else if (0 == g_strcmp0("7",strOpt)) {
634 LocationAddress *add = NULL;
635 GList *pos_list = NULL;
636 GList *acc_list = NULL;
638 g_printf("[0].San jose [1].수원 삼성 [2].Suwon HQ [*].Custom\n");
639 g_printf("Select Address: ");
640 int opt = PromptInt();
641 if (opt == 0) add = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
642 else if (opt == 1) add = location_address_new (NULL, "삼성전자", "매탄 3동", "수원시 영통구", "경기도", NULL, NULL);
643 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);
645 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
646 g_printf("Input building number: ");
647 fgets(building_number, 255, stdin);
648 building_number[strlen(building_number)-1]='\0';
649 g_printf("Input street: ");
650 fgets(street, 255, stdin);
651 street[strlen(street)-1]='\0';
652 g_printf("Input state: ");
653 fgets(state, 255, stdin);
654 state[strlen(state)-1]='\0';
655 g_printf("Input country code: ");
656 fgets(country_code, 255, stdin);
657 country_code[strlen(country_code)-1]='\0';
658 g_printf("Input city: ");
659 fgets(city, 255, stdin);
660 city[strlen(city)-1]='\0';
661 g_printf("Input district: ");
662 fgets(district, 255, stdin);
663 district[strlen(district)-1]='\0';
664 g_printf("Input postal code: ");
665 fgets(postal_code, 255, stdin);
666 postal_code[strlen(postal_code)-1]='\0';
667 add = location_address_new(building_number, street, district, city, state, country_code, postal_code);
669 ret = location_get_position_from_address (location_obj, add, &pos_list, &acc_list);
670 if(add) location_address_free (add);
671 GetLocationError(str, ret);
672 g_printf("location_get_position_from_adress: returned value [%s]\n", str);
673 if (ret == LOCATION_ERROR_NONE) {
674 g_list_foreach (pos_list, PrintPos, NULL);
675 g_list_foreach (acc_list, PrintAcc, NULL);
677 } else if (0 == g_strcmp0("7a",strOpt)) {
678 IdleData* data = g_new0(IdleData, 1);
679 data->obj = location_obj;
680 data->pos_cb = cb_position;
681 data->user_data = location_obj;
683 g_printf("[0].San jose [1].수원 삼성 [2].Suwon HQ [*].Custom\n");
684 g_printf("Select Address: ");
685 int opt = PromptInt();
686 if (opt == 0) data->addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
687 else if (opt == 1) data->addr = location_address_new (NULL, "삼성전자", "매탄3동", "수원시 영통구", "경기도", NULL, NULL);
688 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);
690 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
691 g_printf("Input building number: ");
692 fgets(building_number, 255, stdin);
693 building_number[strlen(building_number)-1]='\0';
694 g_printf("Input street: ");
695 fgets(street, 255, stdin);
696 street[strlen(street)-1]='\0';
697 g_printf("Input state: ");
698 fgets(state, 255, stdin);
699 state[strlen(state)-1]='\0';
700 g_printf("Input country code: ");
701 fgets(country_code, 255, stdin);
702 country_code[strlen(country_code)-1]='\0';
703 g_printf("Input city: ");
704 fgets(city, 255, stdin);
705 city[strlen(city)-1]='\0';
706 g_printf("Input district: ");
707 fgets(district, 255, stdin);
708 district[strlen(district)-1]='\0';
709 g_printf("Input postal code: ");
710 fgets(postal_code, 255, stdin);
711 postal_code[strlen(postal_code)-1]='\0';
712 data->addr = location_address_new(building_number, street, district, city, state, country_code, postal_code);
714 g_idle_add((GSourceFunc)idle_position_from_address_async, data);
715 }else if (0 == g_strcmp0("8",strOpt)) {
717 GList *pos_list = NULL;
718 GList *acc_list = NULL;
720 g_printf("[0].San jose [1].수원삼성 [2].Suwon HQ [*].Custom\n");
721 g_printf("Select Address: ");
722 int opt = PromptInt();
724 addr = g_strdup("4 N 2nd Street 95113");
726 addr = g_strdup("경기도 수원시 영통구 매탄 3동 삼성전자");
728 addr = g_strdup("Samsung Electronics Co. LTD Maetan 3-dong, Suwon Si Yeongtong-gu, Gyeonggi-Do (Seoul 443-742 Korea), Rep of KOREA");
731 g_printf("Input freeform address: ");
732 fgets(buf, 255, stdin);
733 buf[strlen(buf)-1]='\0';
734 addr = g_strdup(buf);
736 ret = location_get_position_from_freeformed_address(location_obj, addr, &pos_list, &acc_list);
738 GetLocationError(str, ret);
739 g_printf("location_get_position_from_freeformed_adress: returned value [%s]\n", str);
740 if(ret == LOCATION_ERROR_NONE){
741 g_list_foreach (pos_list, PrintPos, NULL);
742 g_list_foreach (acc_list, PrintAcc, NULL);
744 }else if(0 == g_strcmp0("8a",strOpt) ){
745 IdleData* data = g_new0(IdleData, 1);
746 data->obj = location_obj;
747 data->pos_cb = cb_position;
748 data->user_data = location_obj;
749 g_printf("[0].San jose [1].수원 삼성 [2].Suwon HQ [*].Custom\n");
750 g_printf("Select Address: ");
751 int opt = PromptInt();
753 data->str_addr = g_strdup("4 N 2nd Street 95113");
755 data->str_addr = g_strdup("경기도 수원시 영통구 매탄 3동 삼성전자");
757 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");
760 g_printf("Input freeform address: ");
761 fgets(buf, 255, stdin);
762 buf[strlen(buf)-1]='\0';
763 data->str_addr = g_strdup(buf);
765 g_idle_add((GSourceFunc)idle_position_from_freefromed_address_async, data);
767 }else if(0 == g_strcmp0("9",strOpt) ){
768 LocationVelocity *vel = NULL;
769 LocationAccuracy *acc = NULL;
770 ret = location_get_velocity(location_obj, &vel, &acc);
771 GetLocationError(str, ret);
772 g_printf("location_get_velocity: returned value [%s]\n", str);
773 if (ret == LOCATION_ERROR_NONE) {
774 g_printf("time: [%d], speed: [%f], direction: [%f], climb: [%f]\n", vel->timestamp, vel->speed, vel->direction, vel->climb);
775 GetAccuracyLevel(str, acc->level);
776 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
778 if(vel) location_velocity_free(vel);
779 if(acc) location_accuracy_free(acc);
780 }else if(0 == g_strcmp0("9a",strOpt) ){
781 LocationVelocity *last_vel = NULL;
782 LocationAccuracy *last_acc = NULL;
783 if (LOCATION_ERROR_NONE == location_get_last_velocity (location_obj, &last_vel, &last_acc)) {
784 g_debug ("SYNC>> Last velocity> time: %d, speed: %f, direction:%f, climb:%f",
785 last_vel->timestamp, last_vel->speed, last_vel->direction, last_vel->climb);
786 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
787 last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
788 location_velocity_free(last_vel);
789 location_accuracy_free(last_acc);
790 } else g_warning ("SYNC>> Last velocity> failed.");
791 }else if(0 == g_strcmp0("10",strOpt) ){
792 int ret = 0, idx = 0;
793 LocationSatellite *sat = NULL;
800 ret = location_get_satellite (location_obj, &sat);
801 if (ret == LOCATION_ERROR_NONE) {
802 g_debug ("SYNC>> Current Sattelite> satellite in view = %d, satellite in used = %d", sat->num_of_sat_inview, sat->num_of_sat_used);
803 g_debug ("\tinview satellite information = ");
804 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
805 location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
806 g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
808 location_satellite_free (sat);
809 } else g_warning ("SYNC>> Current satellite> failed. Error[%d]", ret);
810 }else if(0 == g_strcmp0("10a",strOpt) ){
811 int ret = 0, idx = 0;
812 LocationSatellite *last_sat = NULL;
819 ret = location_get_last_satellite (location_obj, &last_sat);
821 if (ret == LOCATION_ERROR_NONE) {
822 g_debug ("SYNC>> Last Sattelite> satellite in view = %d, satellite in used = %d", last_sat->num_of_sat_inview, last_sat->num_of_sat_used);
823 g_debug ("\tinview satellite information = ");
824 for (idx=0; idx<last_sat->num_of_sat_inview; idx++) {
825 location_satellite_get_satellite_details(last_sat, idx, &prn, &used, &elevation, &azimuth, &snr);
826 g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
828 location_satellite_free (last_sat);
829 } else g_warning ("SYNC>> Last satellite> failed");
830 } else if(0 == g_strcmp0("11",strOpt) ){
831 LocationAddress *addr = NULL;
832 LocationAccuracy *acc = NULL;
833 ret = location_get_address(location_obj, &addr, &acc);
834 GetLocationError(str, ret);
835 g_printf("location_get_address: returned value [%s]\n", str);
836 if(ret == LOCATION_ERROR_NONE){
837 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
838 addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
839 GetAccuracyLevel(str, acc->level);
840 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
842 }else if(0 == g_strcmp0("11a",strOpt) ){
843 IdleData* data = g_new0(IdleData, 1);
844 data->obj = location_obj;
845 data->addr_cb = cb_address;
846 data->user_data = location_obj;
847 g_idle_add((GSourceFunc)idle_address_async, data);
848 }else if(0 == g_strcmp0("12",strOpt) ){
849 LocationPosition *pos = NULL;
850 LocationAddress *addr = NULL;
851 LocationAccuracy *acc = NULL;
852 g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
853 g_printf("Select Position: ");
854 int opt = PromptInt();
855 if(opt == 0) pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
856 else if(opt == 1) pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
858 g_printf("Input latitude: ");
859 gdouble lat = PromptDB();
860 g_printf("Input longitude: ");
861 gdouble lon = PromptDB();
862 pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
864 ret = location_get_address_from_position(location_obj, pos, &addr, &acc);
865 GetLocationError(str, ret);
866 g_printf("location_get_address_from_position: returned value [%s]\n", str);
867 if(ret == LOCATION_ERROR_NONE){
868 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
869 addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
871 if(addr) location_address_free(addr);
872 if(acc) location_accuracy_free(acc);
873 }else if(0 == g_strcmp0("12a",strOpt) ){
874 IdleData* data = g_new0(IdleData, 1);
875 data->obj = location_obj;
876 data->addr_cb = cb_address;
877 data->user_data = location_obj;
879 g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
880 g_printf("Select Position: ");
881 int opt = PromptInt();
882 if(opt == 0) data->pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
883 else if (opt == 1) data->pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
885 g_printf("Input latitude: ");
886 gdouble lat = PromptDB();
887 g_printf("Input longitude: ");
888 gdouble lon = PromptDB();
889 data->pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
891 g_idle_add((GSourceFunc)idle_address_from_position_async, data);
892 }else if(0 == g_strcmp0("13",strOpt) ) {
897 LocationPosition pos1, pos2;
899 pos1.latitude = 50.0663222;
900 pos1.longitude = -5.71475;
902 pos2.latitude = 58.6441;
903 pos2.longitude = -3.070094;
905 ret = location_get_distance(&pos1, &pos2, &distance);
906 GetLocationError(str, ret);
907 if(ret != LOCATION_ERROR_NONE) {
908 g_printf("Fail to get position. Error[%s]\n", str);
911 g_printf("The approximate distance is [%lu]\n", distance);
912 g_printf("cf.) It is approximately 969954.114 meter\n");
914 }else if(0 == g_strcmp0("14", strOpt)) {
916 char method_str[STR_MAX] = {0, };
917 char input[8] = {0, };
918 gboolean is_supported = FALSE;
920 g_printf("0.Hybrid 1.GPS 2.WPS 3.CPS(X) 4.IPS(X) 5.SPS\n");
921 g_printf("Select Method :");
922 fgets(input, 8, stdin);
923 method = atoi(input);
925 case LOCATION_METHOD_HYBRID:
926 is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID);
929 case LOCATION_METHOD_GPS:
930 is_supported = location_is_supported_method(LOCATION_METHOD_GPS);
933 case LOCATION_METHOD_WPS:
934 is_supported = location_is_supported_method(LOCATION_METHOD_WPS);
937 case LOCATION_METHOD_SPS:
938 is_supported = location_is_supported_method(LOCATION_METHOD_SPS);
941 case LOCATION_METHOD_CPS:
942 case LOCATION_METHOD_IPS:
947 GetMethod(method_str, method);
949 g_printf("Method[%s] is %s.", method_str, is_supported ? "supported" : "not supported");
951 }else if(0 == g_strcmp0("15", strOpt)) {
952 gboolean is_enabled = FALSE;
953 is_enabled = location_is_enabled_gps(location_obj);
954 if(is_enabled == TRUE) g_printf("GPS is turned on");
955 else g_printf("GPS is turned off");
956 }else if(0 == g_strcmp0("99", strOpt)) {
958 const *str = "command";
959 ret = location_send_command(str);
961 g_printf("Success to send command[%s]", str);
962 }else if(0 == g_strcmp0("a1",strOpt)){
963 if(location_obj && !g_sig_enable) {
964 g_sig_enable = g_signal_connect (location_obj, "service-enabled", G_CALLBACK(cb_service_enabled), location_obj);
966 }else if(0 == g_strcmp0("a2",strOpt)){
967 if(location_obj && !g_sig_disable){
968 g_sig_disable = g_signal_connect (location_obj, "service-disabled", G_CALLBACK(cb_service_disabled), location_obj);
970 }else if(0 == g_strcmp0("a3",strOpt)){
971 if(location_obj && !g_sig_update){
972 g_sig_update = g_signal_connect (location_obj, "service-updated", G_CALLBACK(cb_service_updated), location_obj);
974 }else if(0 == g_strcmp0("a4",strOpt)){
975 if(location_obj && !g_sig_zonein){
976 g_sig_zonein = g_signal_connect (location_obj, "zone-in", G_CALLBACK(cb_zone_in), location_obj);
978 }else if(0 == g_strcmp0("a5",strOpt)){
979 if(location_obj && !g_sig_zoneout){
980 g_sig_zoneout = g_signal_connect (location_obj, "zone-out", G_CALLBACK(cb_zone_out), location_obj);
982 }else if(0 == g_strcmp0("b1",strOpt)){
983 if(location_obj && g_sig_enable) {
984 g_signal_handler_disconnect (location_obj, g_sig_enable);
987 }else if(0 == g_strcmp0("b2",strOpt)){
988 if(location_obj && g_sig_disable){
989 g_signal_handler_disconnect (location_obj, g_sig_disable);
992 }else if(0 == g_strcmp0("b3",strOpt)){
993 if(location_obj && g_sig_update){
994 g_signal_handler_disconnect (location_obj, g_sig_update);
997 }else if(0 == g_strcmp0("b4",strOpt)){
998 if(location_obj && g_sig_zonein){
999 g_signal_handler_disconnect (location_obj, g_sig_zonein);
1002 }else if(0 == g_strcmp0("b5",strOpt)){
1003 if(location_obj && g_sig_zoneout){
1004 g_signal_handler_disconnect (location_obj, g_sig_zoneout);
1007 }else if(0 == g_strcmp0("c1",strOpt)){
1008 LocationBoundary* bound = NULL;
1010 int polygon_count = json_util_get_polygon_count();
1012 g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
1013 for(i = 0; i < polygon_count; i++)
1014 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
1016 g_printf("\nSelect Boundary: ");
1017 int opt = PromptInt();
1019 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
1020 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
1021 bound = location_boundary_new_for_rect (lt, rb);
1022 location_position_free(rb);
1023 location_position_free(lt);
1025 location_boundary_add(location_obj, bound);
1027 } else if(opt == 1) {
1028 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
1029 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
1030 bound = location_boundary_new_for_rect (lt, rb);
1031 location_position_free(rb);
1032 location_position_free(lt);
1034 location_boundary_add(location_obj, bound);
1035 } else if(opt == 2) {
1036 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
1037 double radius = 10.0;
1038 bound = location_boundary_new_for_circle(center, radius);
1040 location_boundary_add(location_obj, bound);
1041 } else if (opt > 2 && opt < 3 + polygon_count) {
1043 int polygon_index = opt - 3;
1044 bound = json_util_get_polygon_boundary(polygon_index);
1045 location_boundary_add(location_obj, bound);
1047 LocationPosition * check_pos = NULL;
1048 gboolean ret = FALSE;
1049 int count = json_util_get_marker_position_count(polygon_index);
1050 for(index = 0; index < count; index++) {
1051 check_pos = json_util_get_marker_position(polygon_index, index);
1053 ret = location_boundary_if_inside(bound, check_pos);
1054 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");
1055 location_position_free(check_pos);
1058 g_printf("boundary is not set\n");
1060 location_boundary_free(bound);
1062 }else if(0 == g_strcmp0("c2",strOpt)){
1063 g_printf("Get Boundary\n");
1064 location_boundary_foreach(location_obj, PrintBoundary, NULL);
1066 }else if(0 == g_strcmp0("c3",strOpt)){
1067 g_printf("Remove Boundary\n");
1068 LocationBoundary* bound = NULL;
1071 int polygon_count = json_util_get_polygon_count();
1073 g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
1074 for(i = 0; i < polygon_count; i++)
1075 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
1077 g_printf("\nSelect Boundary: ");
1078 int opt = PromptInt();
1080 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
1081 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
1082 bound = location_boundary_new_for_rect (lt, rb);
1083 location_position_free(rb);
1084 location_position_free(lt);
1086 } else if(opt == 1) {
1087 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
1088 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
1089 bound = location_boundary_new_for_rect (lt, rb);
1090 location_position_free(rb);
1091 location_position_free(lt);
1093 } else if(opt == 2) {
1094 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
1095 double radius = 10.0;
1096 bound = location_boundary_new_for_circle(center, radius);
1097 location_position_free(center);
1099 } else if (opt > 2 && opt < 3 + polygon_count) {
1100 int polygon_index = opt - 3;
1101 bound = json_util_get_polygon_boundary(polygon_index);
1103 g_printf("Invalid value\n");
1106 if(bound != NULL) location_boundary_remove(location_obj, bound);
1108 }else if(0 == g_strcmp0("c4",strOpt)){
1109 location_boundary_foreach(location_obj, RemoveBoundary, location_obj);
1110 }else if(0 == g_strcmp0("c5",strOpt)){
1112 g_printf("Input device name: ");
1113 fgets(buf, 255, stdin);
1114 buf[strlen(buf)-1]='\0';
1115 g_object_set(location_obj, "dev-name", buf, NULL);
1116 } else if (0 == g_strcmp0("c6", strOpt)) {
1118 g_printf("Input interval[1~120]:");
1119 scanf("%u", &interval);
1120 g_printf("changed interval to [%u]\n", interval);
1121 g_object_set(location_obj, "update-interval", interval, NULL);
1122 }else if(0 == g_strcmp0("q",strOpt) ){
1123 g_main_loop_quit(g_mainloop);
1127 g_thread_join(g_main);
1128 g_printf("\n--- Exit LBS Test App ---\n");