upload tizen1.0 source
[framework/location/libslp-location.git] / tests / location-api-test.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  */
21
22 #include <glib.h>
23 #include <string.h>
24 #include <glib/gprintf.h>
25 #include <gconf/gconf-client.h>
26 #include <location.h>
27 #include <location-map-service.h>
28 #include <location-poi.h>
29 #include "location-api-test-util.h"
30
31 #define STR_MAX 128
32 LocationObject* location_obj = NULL;
33 static GMainLoop *g_mainloop = NULL;
34
35 #define LOCATION_API_TEST_JSON_FILE "/opt/data/location-api-test.json"
36
37 static gpointer GmainThread(gpointer data)
38 {
39         g_mainloop = g_main_loop_new (NULL, FALSE);
40         g_printf("\n...Entering GMain Loop to Receive Notifications....\n");
41         g_main_loop_run (g_mainloop);
42         g_main_loop_unref (g_mainloop);
43         g_mainloop = NULL;
44         return NULL;
45 }
46
47
48 static void GetLocationError(char str[STR_MAX], int ret)
49 {
50         switch(ret)
51         {
52                 case LOCATION_ERROR_NONE:
53                         g_utf8_strncpy(str, "LOCATION_ERROR_NONE", STR_MAX);
54                         break;
55                 case LOCATION_ERROR_NOT_ALLOWED:
56                         g_utf8_strncpy(str, "LOCATION_ERROR_NOT_ALLOWED", STR_MAX);
57                         break;
58                 case LOCATION_ERROR_NOT_AVAILABLE:
59                         g_utf8_strncpy(str, "LOCATION_ERROR_NOT_AVAILABLE", STR_MAX);
60                         break;
61                 case LOCATION_ERROR_NETWORK_FAILED:
62                         g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_FAILED", STR_MAX);
63                         break;
64                 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
65                         g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_NOT_CONNECTED", STR_MAX);
66                         break;
67                 case LOCATION_ERROR_CONFIGURATION:
68                         g_utf8_strncpy(str, "LOCATION_ERROR_CONFIGURATION", STR_MAX);
69                         break;
70                 case LOCATION_ERROR_PARAMETER:
71                         g_utf8_strncpy(str, "LOCATION_ERROR_PARAMETER", STR_MAX);
72                         break;
73                 case LOCATION_ERROR_UNKNOWN:
74                         g_utf8_strncpy(str, "LOCATION_ERROR_UNKNOWN", STR_MAX);
75                         break;
76                 default:
77                         g_utf8_strncpy(str, "Error: undefined error code", STR_MAX);
78         }
79 }
80
81 static void GetStatus(char str[STR_MAX], LocationStatus acc_level)
82 {
83         switch(acc_level)
84         {
85                 case LOCATION_STATUS_NO_FIX:
86                         g_utf8_strncpy(str, "LOCATION_STATUS_NO_FIX", STR_MAX);
87                         break;
88                 case LOCATION_STATUS_2D_FIX:
89                         g_utf8_strncpy(str, "LOCATION_STATUS_2D_FIX", STR_MAX);
90                         break;
91                 case LOCATION_STATUS_3D_FIX:
92                         g_utf8_strncpy(str, "LOCATION_STATUS_3D_FIX", STR_MAX);
93                         break;
94                 default:
95                         g_utf8_strncpy(str, "Error: undefined status code", STR_MAX);
96         }
97 }
98
99 static void GetMethod(char str[STR_MAX], LocationMethod acc_level)
100 {
101         switch(acc_level)
102         {
103                 case LOCATION_METHOD_HYBRID:
104                         g_utf8_strncpy(str, "LOCATION_METHOD_HYBRID", STR_MAX);
105                         break;
106                 case LOCATION_METHOD_GPS:
107                         g_utf8_strncpy(str, "LOCATION_METHOD_GPS", STR_MAX);
108                         break;
109                 case LOCATION_METHOD_CPS:
110                         g_utf8_strncpy(str, "LOCATION_METHOD_CPS", STR_MAX);
111                         break;
112                 case LOCATION_METHOD_IPS:
113                         g_utf8_strncpy(str, "LOCATION_METHOD_IPS", STR_MAX);
114                         break;
115                 case LOCATION_METHOD_WPS:
116                         g_utf8_strncpy(str, "LOCATION_METHOD_WPS", STR_MAX);
117                         break;
118                 case LOCATION_METHOD_SPS:
119                         g_utf8_strncpy(str, "LOCATION_METHOD_SPS", STR_MAX);
120                         break;
121                 default:
122                         g_utf8_strncpy(str, "Error: undefined method", STR_MAX);
123         }
124 }
125
126 static void GetAccuracyLevel(char str[STR_MAX], LocationAccuracyLevel acc_level)
127 {
128         switch(acc_level)
129         {
130                 case LOCATION_ACCURACY_LEVEL_NONE:
131                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_NONE", STR_MAX);
132                         break;
133                 case LOCATION_ACCURACY_LEVEL_COUNTRY:
134                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_COUNTRY", STR_MAX);
135                         break;
136                 case LOCATION_ACCURACY_LEVEL_REGION:
137                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_REGION", STR_MAX);
138                         break;
139                 case LOCATION_ACCURACY_LEVEL_LOCALITY:
140                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_LOCALITY", STR_MAX);
141                         break;
142                 case LOCATION_ACCURACY_LEVEL_POSTALCODE:
143                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_POSTALCODE", STR_MAX);
144                         break;
145                 case LOCATION_ACCURACY_LEVEL_STREET:
146                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_STREET", STR_MAX);
147                         break;
148                 case LOCATION_ACCURACY_LEVEL_DETAILED:
149                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_DETAILED", STR_MAX);
150                         break;
151                 default:
152                         g_utf8_strncpy(str, "Error: undefined accuracy level", STR_MAX);
153         }
154 }
155
156
157 static void SelectOpt(char* buf)
158 {
159         int iLen = 0;
160         fgets(buf, 255, stdin);
161         iLen = g_utf8_strlen(buf, -1);
162         buf[iLen-1] = '\0';
163 }
164
165 static int PromptInt()
166 {
167         char buf[255];
168         int ret;
169         fgets(buf, 255, stdin);
170         buf[strlen(buf)-1]='\0';
171         ret = g_ascii_strtoll(buf, NULL, 10);
172         return ret;
173 }
174
175 static double PromptDB()
176 {
177         char buf[255];
178         double ret;
179         fgets(buf, 255, stdin);
180         buf[strlen(buf)-1]='\0';
181         ret = g_ascii_strtod(buf, NULL);
182         return ret;
183 }
184
185 static void PrintPos (gpointer data, gpointer user_data)
186 {
187         LocationPosition *pos = (LocationPosition *)data;
188         if (pos) {
189                 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
190                 location_position_free (pos);
191         }
192 }
193
194 static void PrintAcc (gpointer data, gpointer user_data)
195 {
196         LocationAccuracy *acc = (LocationAccuracy *)data;
197         if (acc) {
198                 g_printf("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
199                 location_accuracy_free (acc);
200         }
201
202 }
203
204 gulong g_sig_enable = 0;
205 gulong g_sig_disable = 0;
206 gulong g_sig_update = 0;
207 gulong g_sig_zonein = 0;
208 gulong g_sig_zoneout = 0;
209
210 static void PrintPolygonPosition(gpointer data, gpointer user_data)
211 {
212         LocationPosition *position = (LocationPosition*) data;
213         g_printf("[%lf %lf %lf] ", position->latitude, position->longitude, position->altitude);
214 }
215
216 static void PrintBoundary(LocationBoundary *boundary, void *user_data)
217 {
218         if(boundary == NULL) return;
219         if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
220                 g_printf("\n\tCIRCLE: center[%lf %lf %lf] radius[%lf]",
221                                 boundary->circle.center->latitude, boundary->circle.center->longitude, boundary->circle.center->altitude, boundary->circle.radius);
222         } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
223                 g_printf("\n\tRECT: left_top[%lf %lf %lf] right_bottom[%lf %lf %lf]",
224                                 boundary->rect.left_top->latitude, boundary->rect.left_top->longitude, boundary->rect.left_top->altitude,
225                                 boundary->rect.right_bottom->latitude, boundary->rect.right_bottom->longitude, boundary->rect.right_bottom->altitude);
226         } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
227                 g_printf("\n\tPOLYGON: ");
228
229                 GList *list = boundary->polygon.position_list;
230
231                 g_list_foreach(list, PrintPolygonPosition, NULL);
232         }
233 }
234
235 static void RemoveBoundary(LocationBoundary *boundary, void *user_data)
236 {
237         LocationObject * obj = (LocationObject *)user_data;
238         if(obj == NULL || boundary == NULL) return;
239
240         location_boundary_remove(obj, boundary);
241 }
242
243 static void PrintProperty (LocationObject* loc)
244 {
245         if (!loc) return;
246         LocationMethod method = LOCATION_METHOD_NONE;
247         LocationPosition *pos = NULL;
248         guint interval = 0;
249         gchar method_str[STR_MAX] = {0, };
250         gchar status_str[STR_MAX] = {0, };
251
252         gchar* devname = NULL;
253
254         g_object_get(loc, "method", &method, NULL);
255         GetMethod(method_str, method);
256         g_printf("method[%s] ", method_str);
257
258         if (LOCATION_METHOD_GPS == method) {
259                 g_object_get(loc, "dev-name", &devname, NULL);
260                 if (devname) {
261                         g_printf("dev-name[%s] ", devname);
262                         g_free(devname);
263                 }
264         }
265
266         g_object_get(loc, "last-position", &pos, NULL);
267         if (pos) {
268                 GetStatus(status_str, pos->status);
269                 g_printf("\nLast position [time(%d) lat(%f) long(%f) alt(%f) status(%s)]",
270                                 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, status_str);
271                 location_position_free (pos);
272         }
273
274         g_object_get(loc, "update-interval", &interval, NULL);
275         g_printf("Update interval : [%u]", interval);
276
277         if (LOCATION_METHOD_CPS == method ||  LOCATION_METHOD_IPS == method) return;
278
279         g_printf("\nSignals: ");
280         if (g_sig_enable)  g_printf("[service-enabled], ");
281         if (g_sig_disable) g_printf("[service-disabled], ");
282         if (g_sig_update)  g_printf("[service-updated], ");
283         if (g_sig_zonein)  g_printf("[zone-in], ");
284         if (g_sig_zoneout) g_printf("[zone-out]");
285 }
286
287 static void cb_service_enabled (GObject *self,  guint status, gpointer userdata)
288 {
289         g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
290
291         LocationObject *loc = (LocationObject*)userdata;
292         LocationAccuracy *acc = NULL;
293         LocationPosition *pos = NULL;
294         LocationVelocity *vel = NULL;
295         LocationAddress *addr = NULL;
296         LocationMethod method;
297
298         g_object_get(loc, "method", &method, NULL);
299         g_debug("Get property>> method:%d", method);
300
301         if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
302                 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
303                         pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
304                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
305                         acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
306                 location_position_free(pos);
307                 location_accuracy_free(acc);
308         } else g_warning ("SYNC>> Current position> failed");
309         if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
310                 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
311                         vel->timestamp, vel->speed, vel->direction, vel->climb);
312                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
313                         acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
314                 location_velocity_free(vel);
315                 location_accuracy_free(acc);
316         } else g_warning ("SYNC>> Current velocity> failed");
317         if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
318                 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
319                         addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
320                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
321                 location_address_free(addr);
322                 location_accuracy_free(acc);
323         } else g_warning ("SYNC>> Current address> failed");
324 }
325
326 static void
327 cb_service_disabled (GObject *self,
328         guint status,
329         gpointer userdata)
330 {
331         g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
332 }
333
334 static void
335 cb_zone_in (GObject *self,
336         guint type,
337         gpointer position,
338         gpointer accuracy)
339 {
340         g_debug("cb_zone_in: type(%d)", type);
341         LocationPosition *pos = (LocationPosition*) position;
342         LocationAccuracy *acc = (LocationAccuracy*) accuracy;
343
344         g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
345                 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
346         g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
347                 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
348 }
349
350 static void
351 cb_zone_out (GObject *self,
352         guint type,
353         gpointer position,
354         gpointer accuracy)
355 {
356         g_debug("cb_zone_out: type(%d)", type);
357         LocationPosition *pos = (LocationPosition*) position;
358         LocationAccuracy *acc = (LocationAccuracy*) accuracy;
359
360         g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
361                 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
362         g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
363                 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
364 }
365
366 static void
367 cb_service_updated (GObject *self,
368         guint type,
369         gpointer data,
370         gpointer accuracy,
371         gpointer userdata)
372 {
373         g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
374
375         LocationAccuracy *acc = (LocationAccuracy*) accuracy;
376         switch (type) {
377         case POSITION_UPDATED: {
378                 LocationPosition *pos = (LocationPosition*) data;
379                 g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
380                                 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
381                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
382                                 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
383         }
384                 break;
385         case VELOCITY_UPDATED: {
386                 LocationVelocity *vel = (LocationVelocity*) data;
387                 g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
388                         vel->timestamp, vel->speed, vel->direction, vel->climb);
389                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
390                         acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
391         }
392                 break;
393         case SATELLITE_UPDATED: {
394                 int idx = 0;
395                 guint prn;
396                 gboolean used;
397                 guint elevation;
398                 guint azimuth;
399                 gint snr;
400
401                 LocationSatellite *sat = (LocationSatellite *)data;
402                 g_debug ("SYNC>> Current Satellite> time: %d, satellite in view = %d, satellite in used = %d", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used);
403                 g_debug ("\tinview satellite information = ");
404                 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
405                         location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
406                         g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
407                 }
408         }
409                 break;
410         default:
411                 g_warning ("ASYNC>> Undefined update type");
412                 break;
413         }
414 }
415
416 static void _print_property (gpointer data, gpointer user_data)
417 {
418         LocationLandmark *landmark = (LocationLandmark *)user_data;
419         gpointer key = (gpointer)data;
420         gpointer value = NULL;
421
422         if (key) {
423                 value = (gpointer)location_landmark_get_property(landmark, key);
424                 g_printf(", [%s:%s]", (gchar*) key, (gchar*) value);
425         }
426 }
427
428 static void
429 __plugin_print_poi_list (gpointer data, gpointer user_data)
430 {
431         LocationLandmark *landmark = (LocationLandmark *)data;
432         LocationPosition *pos = location_landmark_get_position (landmark);
433         LocationAddress *addr = location_landmark_get_address (landmark);
434
435         g_printf ("[ID:%d], [NAME:%s], phone[%s],pos[%f:%f], addr[%s:%s:%s:%s:%s]",
436                         location_landmark_get_id (landmark),
437                         location_landmark_get_name(landmark),
438                         location_landmark_get_phone_number (landmark),
439                         pos->latitude, pos->longitude,
440                         addr->building_number, addr->city, addr->country_code, addr->district,
441                         addr->postal_code);
442
443         GList *key_list = location_landmark_get_property_key(landmark);
444         if (key_list) {
445                 g_list_foreach(key_list, _print_property, landmark);
446         }
447
448         g_printf("\n");
449 }
450
451
452 static void cb_poi(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata)
453 {
454         g_printf("\n===== __location_POI_cb ======\n");
455         if (error != LOCATION_ERROR_NONE) {
456                 g_printf("Failed :%d\n", error);
457                 return;
458         }
459         g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)landmark_list, (unsigned int)userdata, req_id);
460         g_list_foreach (landmark_list, __plugin_print_poi_list, NULL);
461
462         if (error_code && error_msg) {
463                 g_printf("__location_POI_cb: error_code[%s], error_msg[%s]\n", error_code, error_msg);
464         }
465 }
466 static void PrintStepInfo(const LocationRouteStep *step)
467 {
468         const LocationPosition *start = location_route_step_get_start_point(step);
469         gdouble start_lat = 0;
470         gdouble start_lon = 0;
471         if (start) {
472                 start_lat = start->latitude;
473                 start_lon = start->longitude;
474         } else {
475                 g_printf("Step start position NULL\n");
476         }
477         const LocationPosition *end = location_route_step_get_end_point(step);
478         gdouble end_lat = 0;
479         gdouble end_lon = 0;
480         if (end) {
481                 end_lat = end->latitude;
482                 end_lon = end->longitude;
483         } else {
484                 g_printf("Step end position NULL\n");
485         }
486         const gchar *inst = location_route_step_get_instruction(step);
487
488         g_printf("Step: start(%f/%f), end(%f/%f), instruction(%s)\n", start_lat, start_lon, end_lat, end_lon, inst);
489 }
490
491 static void cb_print_route_step (gpointer data, gpointer user_data)
492 {
493         g_printf("+++Step begin\n");
494         LocationRouteStep *step = (LocationRouteStep *)data;
495
496         PrintStepInfo(step);
497         g_printf("---Step end\n");
498 }
499
500 static void cb_print_route_segment (gpointer data, gpointer user_data)
501 {
502         g_printf("++Segment begin\n");
503         LocationRouteSegment *seg = (LocationRouteSegment *)data;
504         gdouble seg_dist = location_route_segment_get_distance(seg);
505         glong seg_duration = location_route_segment_get_duration(seg);
506         const LocationPosition *start = location_route_segment_get_start_point(seg);
507         gdouble start_lat = 0;
508         gdouble start_lon = 0;
509         if (start) {
510                 start_lat = start->latitude;
511                 start_lon = start->longitude;
512         } else {
513                 g_printf("Segment start position NULL\n");
514         }
515         const LocationPosition *end = location_route_segment_get_end_point(seg);
516         gdouble end_lat = 0;
517         gdouble end_lon = 0;
518         if (end) {
519                 end_lat = end->latitude;
520                 end_lon = end->longitude;
521         } else {
522                 g_printf("Segment end postion NULL\n");
523         }
524         g_printf("Segment info: Distance[%f], Duration[%ld], start(%f/%f), end(%f/%f)\n", seg_dist, seg_duration,
525                         start_lat, start_lon, end_lat, end_lon);
526
527         GList *step_list = location_route_segment_get_route_step(seg);
528         GList *tmp_list = (GList *)step_list;
529         if (tmp_list) {
530                 g_list_foreach(tmp_list, cb_print_route_step, NULL);
531         }
532         g_printf("--Segment end\n");
533 }
534
535
536 static void cb_print_route_list (gpointer data, gpointer user_data)
537 {
538         g_printf("+Route begin\n");
539         LocationRoute *route = (LocationRoute *)data;
540
541         const LocationPosition *start = location_route_get_origin(route);
542         gdouble start_lat = 0;
543         gdouble start_lon = 0;
544         if (start) {
545                 start_lat = start->latitude;
546                 start_lon = start->longitude;
547         } else {
548                 g_printf("Route start position NULL\n");
549         }
550         const LocationPosition *end = location_route_get_destination(route);
551         gdouble end_lat = 0;
552         gdouble end_lon = 0;
553         if (end) {
554                 end_lat = end->latitude;
555                 end_lon = end->longitude;
556         } else {
557                 g_printf("Route end position NULL\n");
558         }
559         g_printf("Route: start(%f/%f), end(%f/%f)\n", start_lat, start_lon, end_lat, end_lon);
560
561         gdouble distance = location_route_get_total_distance(route);
562         const gchar *dis_unit = location_route_get_distance_unit(route);
563         glong duration = location_route_get_total_duration(route);
564         const LocationBoundary *bound = location_route_get_bounding_box(route);
565         if (bound && bound->type == LOCATION_BOUNDARY_RECT) {
566                 g_printf("RECT left top[%f-%f], right bottom[%f-%f]\n", bound->rect.left_top->latitude, bound->rect.left_top->longitude,
567                         bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude);
568         } else {
569                 g_printf("route boundary not exist, or not RECT\n");
570         }
571         g_printf ("Distance[%f], Distance unit[%s], Duration[%ld]\n", distance, dis_unit, duration);
572
573         GList *seg_list = location_route_get_route_segment(route);
574         if (seg_list) {
575                 g_list_foreach(seg_list, cb_print_route_segment, NULL);
576         }
577
578         g_printf("-Route end\n");
579 }
580
581 static void cb_route(LocationError error, guint req_id, GList * route_list, gchar * error_code, gchar * error_msg, gpointer userdata)
582 {
583         g_printf("\n===== cb_route ======\n");
584         if (error != LOCATION_ERROR_NONE) {
585                 g_printf("Failed :%d\n", error);
586                 return;
587         }
588
589         g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)route_list, (unsigned int)userdata, req_id);
590         g_list_foreach (route_list, cb_print_route_list, NULL);
591
592         if (error_code && error_msg) {
593                 g_printf("cb_route: error_code[%s], error_msg[%s]\n", error_code, error_msg);
594         }
595 }
596
597 static void cb_position (LocationError error,
598         GList *pos_list,
599         GList *acc_list,
600         gpointer userdata)
601 {
602         if (error != LOCATION_ERROR_NONE) {
603                 g_printf("cb_position failed: error=%d\n", error);
604                 return;
605         }
606
607         g_list_foreach (pos_list, PrintPos, NULL);
608         g_list_foreach (acc_list, PrintAcc, NULL);
609 }
610
611 static void cb_address(LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata)
612 {
613         if (error != LOCATION_ERROR_NONE) {
614                 g_printf("cb_address failed: error=%d\n", error);
615                 return;
616         }
617         char str[STR_MAX];
618         g_printf("userdata[0x%x] building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
619                 (unsigned int)userdata, addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
620         GetAccuracyLevel(str, acc->level);
621         g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
622 }
623
624 typedef struct {
625         LocationObject *obj;
626         LocationPosition *pos;
627         LocationAddress *addr;
628         gchar *str_addr;
629         LocationPositionCB pos_cb;
630         LocationAddressCB addr_cb;
631         gpointer user_data;
632 } IdleData;
633
634 static gboolean idle_position_from_address_async(gpointer data)
635 {
636         IdleData* idle_data = (IdleData*)data;
637         char str[STR_MAX];
638         int ret = location_get_position_from_address_async(idle_data->obj, idle_data->addr, idle_data->pos_cb, idle_data->user_data);
639         GetLocationError(str, ret);
640         g_printf("location_get_position_from_address_async: returned value [%s]\n", str);
641         location_address_free(idle_data->addr);
642         g_free(idle_data);
643         return FALSE;
644 }
645
646 static gboolean idle_position_from_freefromed_address_async(gpointer data)
647 {
648         IdleData* idle_data = (IdleData*)data;
649         char str[STR_MAX];
650         int ret = location_get_position_from_freeformed_address_async(idle_data->obj, idle_data->str_addr, idle_data->pos_cb, idle_data->user_data);
651         GetLocationError(str, ret);
652         g_printf("location_get_position_from_freeformed_address_async: returned value [%s]\n", str);
653         g_free(idle_data->str_addr);
654         g_free(idle_data);
655         return FALSE;
656 }
657
658 static gboolean idle_address_async(gpointer data)
659 {
660         IdleData* idle_data = (IdleData*)data;
661         char str[STR_MAX];
662         int ret = location_get_address_async(idle_data->obj, idle_data->addr_cb, idle_data->user_data);
663         GetLocationError(str, ret);
664         g_printf("location_get_address_async: returned value [%s]\n", str);
665         g_free(idle_data);
666         return FALSE;
667 }
668
669 static gboolean idle_address_from_position_async(gpointer data)
670 {
671         IdleData* idle_data = (IdleData*)data;
672         char str[STR_MAX];
673         int ret = location_get_address_from_position_async(idle_data->obj, idle_data->pos, idle_data->addr_cb, idle_data->user_data);
674         GetLocationError(str, ret);
675         g_printf("location_get_address_from_position_async: returned value [%s]\n", str);
676         location_position_free(idle_data->pos);
677         g_free(idle_data);
678         return FALSE;
679 }
680
681 void _print_keys(gpointer value)
682 {
683         g_printf(" %s ", (gchar*) value);
684 }
685
686 static void print_map_service_keys (LocationObject *obj, int type)
687 {
688         GList *key = NULL;
689
690         int ret = location_get_map_provider_capability_key (obj, type, &key);
691
692         if (key) {
693                 g_list_foreach (key, _print_keys, NULL);
694         }
695
696         g_list_free_full(key, g_free);
697 }
698
699 static void print_menu()
700 {
701         g_printf("\n================================= Location API Test =================================\n");
702         g_printf("q.   Exit\n");
703         g_printf("1.   location_init\n");
704         g_printf("2.   location_new\n");
705         g_printf("3.   location_free\n");
706         g_printf("4.   location_start\n");
707         g_printf("5.   location_stop\n");
708         g_printf("6.   location_get_position\n");
709         g_printf("6a.  location_get_last_position\n");
710         g_printf("6b.  location_get_last_known_position - will be deprecated. \n");
711         g_printf("7.   location_get_position_from_address\n");
712         g_printf("7a.  location_get_position_from_address_async\n");
713         g_printf("8.   location_get_position_from_freeformed_address\n");
714         g_printf("8a.  location_get_position_from_freeformed_address_async\n");
715         g_printf("9.   location_get_velocity\n");
716         g_printf("9a.  location_get_last_velocity\n");
717         g_printf("10.  location_get_satellite\n");
718         g_printf("10a. location_get_last_satellite\n");
719         g_printf("11.  location_get_address\n");
720         g_printf("11a. location_get_address_async\n");
721         g_printf("12.  location_get_address_from_position\n");
722         g_printf("12a. location_get_address_from_position_async\n");
723         g_printf("13.  location_get_distance\n");
724         g_printf("14.  location_is_supported_method\n");
725         g_printf("15.  location_is_enabled_gps\n");
726         g_printf("16.  location_search_poi\n");
727         g_printf("16a. location_search_poi_by_area\n");
728         g_printf("16b. location_search_poi_by_addr\n");
729         g_printf("16c. location_search_poi_by_freeformed_address\n");
730         g_printf("16d. location_search_poi_by_area\n");
731         g_printf("16e. location_cancel_poi_request\n");
732         g_printf("17.  location_request_route\n");
733         g_printf("17a. location_cancel_route_request\n");
734         g_printf("18.  location_is_supported_map_provider_capability\n");
735         g_printf("19.  location_get_map_provider_capability_key\n");
736         g_printf("99.  location_send_command\n");
737         g_printf("a?.  signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
738         g_printf("b?.  disconnect signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
739         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");
740         g_printf("==================================== Property ====================================\n");
741         PrintProperty(location_obj);
742         g_printf("\n==================================================================================\n");
743 }
744
745 int main(int argc, char** argv)
746 {
747         char strOpt[255];
748         int ret;
749         char str[STR_MAX];
750         GError *gerr = NULL;
751         guint req_id = 0;
752
753         // If application is executed by AUL, this is not needed.
754         g_setenv("PKG_NAME", "com.samsung.location-api-test", 1);
755
756         g_type_init();
757         if( !g_thread_supported() )
758         {
759                 g_thread_init(NULL);
760         }
761
762         GThread *g_main;
763         g_main = g_thread_create(GmainThread, NULL, TRUE, &gerr);
764         if (!g_main) {
765                 g_debug("Error create gmain thread: Err domain[%d] Err code[%d] Err msg[%s]",
766                         gerr->domain, gerr->code, gerr->message);
767                 g_error_free(gerr);
768                 return 0;
769         }
770
771         json_util_init(LOCATION_API_TEST_JSON_FILE);
772         g_printf("--- Start LBS Test App ---\n");
773         while(1)
774         {
775                 print_menu();
776                 g_printf("Select option: ");
777                 SelectOpt(strOpt);
778                 g_printf("======================================================================================\n");
779                 if (0 == g_strcmp0 ("x", strOpt)) {
780
781                 }
782                 else if (0 == g_strcmp0("1",strOpt)) {
783                         ret = location_init();
784                         GetLocationError(str, ret);
785                         g_printf("location_init: returned value [%s]\n", str);
786                 } else if (0 == g_strcmp0("2",strOpt)) {
787                         if (location_obj) {
788                                 g_printf("Location object already existed: [0x%x]", (unsigned int)location_obj);
789                                 continue;
790                         }
791                         g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n");
792                         g_printf("Select Location Method: ");
793                         LocationMethod method = PromptInt();
794                         location_obj = location_new(method);
795                         if(location_obj) g_printf("Success\n");
796                         else             g_printf("Failed\n");
797                 } else if (0 == g_strcmp0("3",strOpt)) {
798                         ret = location_free (location_obj);
799                         location_obj = NULL;
800                         g_sig_enable = 0;
801                         g_sig_disable = 0;
802                         g_sig_update = 0;
803                         g_sig_zonein = 0;
804                         g_sig_zoneout = 0;
805                         GetLocationError(str, ret);
806                         g_printf("location_free: returned value [%s]\n", str);
807                 } else if (0 == g_strcmp0("4",strOpt)) {
808                         ret = location_start(location_obj);
809                         GetLocationError(str, ret);
810                         g_printf("location_start: returned value [%s]\n", str);
811                 } else if (0 == g_strcmp0("5",strOpt)) {
812                         ret = location_stop(location_obj);
813                         GetLocationError(str, ret);
814                         g_printf("location_stop: returned value [%s]\n", str);
815                 } else if (0 == g_strcmp0("6",strOpt)) {
816                         LocationPosition *pos = NULL;
817                         LocationAccuracy *acc = NULL;
818                         ret = location_get_position(location_obj, &pos, &acc);
819                         GetLocationError(str, ret);
820                         g_printf("location_get_position: returned value [%s]\n", str);
821                         if (ret == LOCATION_ERROR_NONE) {
822                                 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f], status: [%d]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
823                                 GetAccuracyLevel(str, acc->level);
824                                 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
825                         }
826                         if(pos) location_position_free(pos);
827                         if(acc) location_accuracy_free(acc);
828                 } else if (0 == g_strcmp0("6a",strOpt)) {
829                         LocationPosition *last_pos;
830                         LocationAccuracy *last_acc;
831                         int ret = 0;
832
833                         ret = location_get_last_position (location_obj, &last_pos, &last_acc);
834                         GetLocationError(str, ret);
835                         if (ret == LOCATION_ERROR_NONE) {
836                                 g_debug ("SYNC>> Last position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
837                                         last_pos->timestamp, last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->status);
838                                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
839                                         last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
840                                 location_position_free(last_pos);
841                                 location_accuracy_free(last_acc);
842                         } else g_warning ("SYNC>> Last position> failed. Error[%s]",str);
843
844                 } else if (0 == g_strcmp0("6b",strOpt)) {
845                         g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n");
846                         g_printf("Select Location Method: ");
847                         LocationMethod method = PromptInt();
848                         LocationLastPosition last_pos;
849                         ret = location_get_last_known_position(location_obj, method, &last_pos);
850                         GetLocationError(str, ret);
851                         g_printf("location_get_last_known_position: returned value [%s]\n", str);
852                         if (ret == LOCATION_ERROR_NONE) {
853                                 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);
854                         }
855                 } else if (0 == g_strcmp0("7",strOpt)) {
856                         LocationAddress *add = NULL;
857                         GList *pos_list = NULL;
858                         GList *acc_list = NULL;
859
860                         g_printf("[0].San jose [1].수원 삼성  [2].Suwon HQ [*].Custom\n");
861                         g_printf("Select Address: ");
862                         int opt = PromptInt();
863                         if (opt == 0)      add = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
864                         else if (opt == 1) add = location_address_new (NULL, "삼성전자", "매탄 3동", "수원시 영통구", "경기도",  NULL, NULL);
865                         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);
866                         else {
867                                 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
868                                 g_printf("Input building number: ");
869                                 fgets(building_number, 255, stdin);
870                                 building_number[strlen(building_number)-1]='\0';
871                                 g_printf("Input street: ");
872                                 fgets(street, 255, stdin);
873                                 street[strlen(street)-1]='\0';
874                                 g_printf("Input state: ");
875                                 fgets(state, 255, stdin);
876                                 state[strlen(state)-1]='\0';
877                                 g_printf("Input country code: ");
878                                 fgets(country_code, 255, stdin);
879                                 country_code[strlen(country_code)-1]='\0';
880                                 g_printf("Input city: ");
881                                 fgets(city, 255, stdin);
882                                 city[strlen(city)-1]='\0';
883                                 g_printf("Input district: ");
884                                 fgets(district, 255, stdin);
885                                 district[strlen(district)-1]='\0';
886                                 g_printf("Input postal code: ");
887                                 fgets(postal_code, 255, stdin);
888                                 postal_code[strlen(postal_code)-1]='\0';
889                                 add = location_address_new(building_number, street, district, city, state, country_code, postal_code);
890                         }
891                         ret = location_get_position_from_address (location_obj, add, &pos_list, &acc_list);
892                         if(add) location_address_free (add);
893                         GetLocationError(str, ret);
894                         g_printf("location_get_position_from_adress: returned value [%s]\n", str);
895                         if (ret == LOCATION_ERROR_NONE) {
896                                 g_list_foreach (pos_list, PrintPos, NULL);
897                                 g_list_foreach (acc_list, PrintAcc, NULL);
898                         }
899                 } else if (0 == g_strcmp0("7a",strOpt)) {
900                         IdleData* data = g_new0(IdleData, 1);
901                         data->obj = location_obj;
902                         data->pos_cb = cb_position;
903                         data->user_data = location_obj;
904
905                         g_printf("[0].San jose [1].수원 삼성  [2].Suwon HQ [*].Custom\n");
906                         g_printf("Select Address: ");
907                         int opt = PromptInt();
908                         if (opt == 0)      data->addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
909                         else if (opt == 1) data->addr = location_address_new (NULL, "삼성전자", "매탄3동", "수원시 영통구", "경기도",  NULL, NULL);
910                         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);
911                         else {
912                                 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
913                                 g_printf("Input building number: ");
914                                 fgets(building_number, 255, stdin);
915                                 building_number[strlen(building_number)-1]='\0';
916                                 g_printf("Input street: ");
917                                 fgets(street, 255, stdin);
918                                 street[strlen(street)-1]='\0';
919                                 g_printf("Input state: ");
920                                 fgets(state, 255, stdin);
921                                 state[strlen(state)-1]='\0';
922                                 g_printf("Input country code: ");
923                                 fgets(country_code, 255, stdin);
924                                 country_code[strlen(country_code)-1]='\0';
925                                 g_printf("Input city: ");
926                                 fgets(city, 255, stdin);
927                                 city[strlen(city)-1]='\0';
928                                 g_printf("Input district: ");
929                                 fgets(district, 255, stdin);
930                                 district[strlen(district)-1]='\0';
931                                 g_printf("Input postal code: ");
932                                 fgets(postal_code, 255, stdin);
933                                 postal_code[strlen(postal_code)-1]='\0';
934                                 data->addr = location_address_new(building_number, street, district, city, state, country_code, postal_code);
935                         }
936                         g_idle_add((GSourceFunc)idle_position_from_address_async, data);
937                 }else if (0 == g_strcmp0("8",strOpt)) {
938                         gchar* addr = NULL;
939                         GList *pos_list = NULL;
940                         GList *acc_list = NULL;
941
942                         g_printf("[0].San jose [1].수원삼성  [2].Suwon HQ [*].Custom\n");
943                         g_printf("Select Address: ");
944                         int opt = PromptInt();
945                         if(opt == 0){
946                                 addr = g_strdup("4 N 2nd Street 95113");
947                         }else if(opt == 1){
948                                 addr = g_strdup("경기도 수원시 영통구 매탄 3동 삼성전자");
949                         }else if(opt == 2){
950                                 addr = g_strdup("Samsung Electronics Co. LTD Maetan 3-dong, Suwon Si Yeongtong-gu, Gyeonggi-Do (Seoul 443-742 Korea), Rep of KOREA");
951                         }else{
952                                 char buf[255];
953                                 g_printf("Input freeform address: ");
954                                 fgets(buf, 255, stdin);
955                                 buf[strlen(buf)-1]='\0';
956                                 addr = g_strdup(buf);
957                         }
958                         ret = location_get_position_from_freeformed_address(location_obj, addr, &pos_list, &acc_list);
959                         g_free(addr);
960                         GetLocationError(str, ret);
961                         g_printf("location_get_position_from_freeformed_adress: returned value [%s]\n", str);
962                         if(ret == LOCATION_ERROR_NONE){
963                                 g_list_foreach (pos_list, PrintPos, NULL);
964                                 g_list_foreach (acc_list, PrintAcc, NULL);
965                         }
966                 }else if(0 == g_strcmp0("8a",strOpt) ){
967                         IdleData* data = g_new0(IdleData, 1);
968                         data->obj = location_obj;
969                         data->pos_cb = cb_position;
970                         data->user_data = location_obj;
971                         g_printf("[0].San jose [1].수원 삼성  [2].Suwon HQ [*].Custom\n");
972                         g_printf("Select Address: ");
973                         int opt = PromptInt();
974                         if(opt == 0){
975                                 data->str_addr = g_strdup("4 N 2nd Street 95113");
976                         }else if(opt == 1){
977                                 data->str_addr = g_strdup("경기도 수원시 영통구 매탄 3동 삼성전자");
978                         }else if(opt == 2){
979                                 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");
980                         }else{
981                                 char buf[255];
982                                 g_printf("Input freeform address: ");
983                                 fgets(buf, 255, stdin);
984                                 buf[strlen(buf)-1]='\0';
985                                 data->str_addr = g_strdup(buf);
986                         }
987                         g_idle_add((GSourceFunc)idle_position_from_freefromed_address_async, data);
988
989                 }else if(0 == g_strcmp0("9",strOpt) ){
990                         LocationVelocity *vel = NULL;
991                         LocationAccuracy *acc = NULL;
992                         ret = location_get_velocity(location_obj, &vel, &acc);
993                         g_printf("location_get_velocity: returned value [%s]\n", str);
994                         if (ret == LOCATION_ERROR_NONE) {
995                                 g_printf("time: [%d], speed: [%f], direction: [%f], climb: [%f]\n", vel->timestamp, vel->speed, vel->direction, vel->climb);
996                                 GetAccuracyLevel(str, acc->level);
997                                 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
998                         }
999                         else {
1000                                 GetLocationError(str, ret);
1001                                 g_warning ("SYNC>> velocity> failed. Error[%s]", str);
1002                         }
1003                         if(vel) location_velocity_free(vel);
1004                         if(acc) location_accuracy_free(acc);
1005                 }else if(0 == g_strcmp0("9a",strOpt) ){
1006                         LocationVelocity *last_vel = NULL;
1007                         LocationAccuracy *last_acc = NULL;
1008                         ret = location_get_last_velocity (location_obj, &last_vel, &last_acc);
1009                         GetLocationError(str, ret);
1010                         if (ret == LOCATION_ERROR_NONE) {
1011                                 g_debug ("SYNC>> Last velocity> time: %d, speed: %f, direction:%f, climb:%f",
1012                                         last_vel->timestamp, last_vel->speed, last_vel->direction, last_vel->climb);
1013                                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
1014                                         last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
1015                                 location_velocity_free(last_vel);
1016                                 location_accuracy_free(last_acc);
1017                         } else g_warning ("SYNC>> Last velocity> failed. Error[%s]", str);
1018                 }else if(0 == g_strcmp0("10",strOpt) ){
1019                         int ret = 0, idx = 0;
1020                         LocationSatellite *sat = NULL;
1021                         guint prn;
1022                         gboolean used;
1023                         guint elevation;
1024                         guint azimuth;
1025                         gint snr;
1026
1027                         ret =  location_get_satellite (location_obj, &sat);
1028                         GetLocationError(str, ret);
1029                         if (ret == LOCATION_ERROR_NONE) {
1030                                 g_debug ("SYNC>> Current Sattelite> time = %d, satellite in view = %d, satellite in used = %d", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used);
1031                                 g_debug ("\tinview satellite information = ");
1032                                 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
1033                                         location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
1034                                         g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
1035                                 }
1036                                 location_satellite_free (sat);
1037                         } else g_warning ("SYNC>> Current satellite> failed. Error[%s]", str);
1038                 }else if(0 == g_strcmp0("10a",strOpt) ){
1039                         int ret = 0, idx = 0;
1040                         LocationSatellite *last_sat = NULL;
1041                         guint prn;
1042                         gboolean used;
1043                         guint elevation;
1044                         guint azimuth;
1045                         gint snr;
1046
1047                         ret = location_get_last_satellite (location_obj, &last_sat);
1048                         GetLocationError(str, ret);
1049                         if (ret == LOCATION_ERROR_NONE) {
1050                                 g_debug ("SYNC>> Last Sattelite> time = %d, satellite in view = %d, satellite in used = %d", last_sat->timestamp, last_sat->num_of_sat_inview, last_sat->num_of_sat_used);
1051                                 g_debug ("\tinview satellite information = ");
1052                                 for (idx=0; idx<last_sat->num_of_sat_inview; idx++) {
1053                                         location_satellite_get_satellite_details(last_sat, idx, &prn, &used, &elevation, &azimuth, &snr);
1054                                         g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
1055                                 }
1056                                 location_satellite_free (last_sat);
1057                         } else g_warning ("SYNC>> Last satellite> failed. Error[%s]", str);
1058                 } else if(0 == g_strcmp0("11",strOpt) ){
1059                         LocationAddress *addr = NULL;
1060                         LocationAccuracy *acc = NULL;
1061                         ret = location_get_address(location_obj, &addr, &acc);
1062                         GetLocationError(str, ret);
1063                         g_printf("location_get_address: returned value [%s]\n", str);
1064                         if(ret == LOCATION_ERROR_NONE){
1065                                 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
1066                                         addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
1067                                 GetAccuracyLevel(str, acc->level);
1068                                 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
1069                         }
1070                 }else if(0 == g_strcmp0("11a",strOpt) ){
1071                         IdleData* data = g_new0(IdleData, 1);
1072                         data->obj = location_obj;
1073                         data->addr_cb = cb_address;
1074                         data->user_data = location_obj;
1075                         g_idle_add((GSourceFunc)idle_address_async, data);
1076                 }else if(0 == g_strcmp0("12",strOpt) ){
1077                         LocationPosition *pos = NULL;
1078                         LocationAddress *addr = NULL;
1079                         LocationAccuracy *acc = NULL;
1080                         g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
1081                         g_printf("Select Position: ");
1082                         int opt = PromptInt();
1083                         if(opt == 0)      pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
1084                         else if(opt == 1) pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
1085                         else{
1086                                 g_printf("Input latitude: ");
1087                                 gdouble lat = PromptDB();
1088                                 g_printf("Input longitude: ");
1089                                 gdouble lon = PromptDB();
1090                                 pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
1091                         }
1092                         ret = location_get_address_from_position(location_obj, pos, &addr, &acc);
1093                         GetLocationError(str, ret);
1094                         g_printf("location_get_address_from_position: returned value [%s]\n", str);
1095                         if(ret == LOCATION_ERROR_NONE){
1096                                 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
1097                                         addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
1098                         }
1099                         if(addr) location_address_free(addr);
1100                         if(acc) location_accuracy_free(acc);
1101                 }else if(0 == g_strcmp0("12a",strOpt) ){
1102                         IdleData* data = g_new0(IdleData, 1);
1103                         data->obj = location_obj;
1104                         data->addr_cb = cb_address;
1105                         data->user_data = location_obj;
1106
1107                         g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
1108                         g_printf("Select Position: ");
1109                         int opt = PromptInt();
1110                         if(opt == 0)       data->pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
1111                         else if (opt == 1) data->pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
1112                         else {
1113                                 g_printf("Input latitude: ");
1114                                 gdouble lat = PromptDB();
1115                                 g_printf("Input longitude: ");
1116                                 gdouble lon = PromptDB();
1117                                 data->pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
1118                         }
1119                         g_idle_add((GSourceFunc)idle_address_from_position_async, data);
1120                 }else if(0 == g_strcmp0("13",strOpt) ) {
1121
1122                         gulong distance;
1123                         int ret = 0;
1124                         char str[STR_MAX];
1125                         LocationPosition pos1, pos2;
1126
1127                         pos1.latitude = 50.0663222;
1128                         pos1.longitude = -5.71475;
1129
1130                         pos2.latitude = 58.6441;
1131                         pos2.longitude = -3.070094;
1132
1133                         ret = location_get_distance(&pos1, &pos2, &distance);
1134                         GetLocationError(str, ret);
1135                         if(ret != LOCATION_ERROR_NONE) {
1136                                         g_printf("Fail to get position. Error[%s]\n", str);
1137                         }
1138                         else {
1139                                         g_printf("The approximate distance is [%lu]\n", distance);
1140                                         g_printf("cf.) It is approximately 969954.114 meter\n");
1141                         }
1142                 }else if(0 == g_strcmp0("14", strOpt)) {
1143                         int method;
1144                         char method_str[STR_MAX] = {0, };
1145                         char input[8] = {0, };
1146                         gboolean is_supported = FALSE;
1147
1148                         g_printf("0.Hybrid 1.GPS 2.WPS 3.CPS(X) 4.IPS(X) 5.SPS\n");
1149                         g_printf("Select Method :");
1150                         fgets(input, 8, stdin);
1151                         method = atoi(input);
1152                         switch(method) {
1153                                 case LOCATION_METHOD_HYBRID:
1154                                         is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID);
1155                                         break;
1156
1157                                 case LOCATION_METHOD_GPS:
1158                                         is_supported = location_is_supported_method(LOCATION_METHOD_GPS);
1159                                         break;
1160
1161                                 case LOCATION_METHOD_WPS:
1162                                         is_supported = location_is_supported_method(LOCATION_METHOD_WPS);
1163                                         break;
1164
1165                                 case LOCATION_METHOD_SPS:
1166                                         is_supported = location_is_supported_method(LOCATION_METHOD_SPS);
1167                                         break;
1168
1169                                 case LOCATION_METHOD_CPS:
1170                                 case LOCATION_METHOD_IPS:
1171                                 default:
1172                                         break;
1173
1174                         }
1175                         GetMethod(method_str, method);
1176
1177                         g_printf("Method[%s] is %s.", method_str, is_supported ? "supported" : "not supported");
1178
1179                 }else if(0 == g_strcmp0("15", strOpt)) {
1180                         gboolean is_enabled = FALSE;
1181                         is_enabled = location_is_enabled_gps(location_obj);
1182                         if(is_enabled == TRUE) g_printf("GPS is turned on");
1183                         else g_printf("GPS is turned off");
1184                 }else if(0 == g_strcmp0("16", strOpt)) {
1185                         g_printf("location_search_poi\n");
1186                         //guint req_id = 0;  // move to upper
1187
1188                         LocationPOIFilter *filter = location_poi_filter_new();
1189 //                      gchar *key = g_strdup("KEYWORD");
1190 //                      gchar *value = g_strdup("pizza");
1191 //                      location_poi_filter_set(filter, key, value); // same with Type ?  CATEGORY, KEYWORD, POIName
1192                         //location_poi_filter_set(filter, "CATEGORY", "restaurant");  // error, const char* can't be free!!!!, 120214
1193                         location_poi_filter_set(filter, "KEYWORD", "pizza");
1194                         //location_poi_filter_set(filter, "POIName", "cafe");
1195
1196                         LocationPOIPreference *pref = location_poi_pref_new();
1197                         location_poi_pref_set_max_result(pref, 2);
1198                         gchar *item = g_strdup("Distance");
1199                         location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1200                         location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_DESC);  //LOCATION_POI_PREF_SO_ASC
1201
1202                         // only the latitude/longitude
1203                         LocationPosition *position = location_position_new(0, 37.771008, -122.41175, 0, LOCATION_STATUS_2D_FIX);
1204
1205                         ret = location_search_poi(location_obj, filter, position, pref, cb_poi, NULL, &req_id);
1206                         GetLocationError(str, ret);
1207                         if(ret != LOCATION_ERROR_NONE) {
1208                                         g_printf("Fail to search POI. Error[%s]\n", str);
1209                         } else {
1210                                         g_printf("Seach POI success, req_id %d\n", req_id);
1211                         }
1212 //                      g_free(item);
1213 //                      g_free(key);
1214 //                      g_free(value);
1215                         location_poi_filter_free(filter);
1216                         location_poi_pref_free(pref);
1217                         location_position_free(position);
1218
1219                 }else if(0 == g_strcmp0("16a", strOpt)) {
1220                         g_printf("location_search_poi_by_area\n");
1221                         
1222                         // only circle supported by decarta
1223                         LocationPosition *center = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX);
1224                         gdouble radius = 400;
1225                         LocationBoundary *bound = location_boundary_new_for_circle(center, radius);
1226
1227                         LocationPOIFilter *filter = location_poi_filter_new();
1228                         gchar *key = g_strdup("KEYWORD");
1229                         gchar *value = g_strdup("cafe");
1230                         location_poi_filter_set(filter, key, value); // same with Type ?  CATEGORY, KEYWORD, POIName
1231
1232                         LocationPOIPreference *pref = location_poi_pref_new();
1233                         location_poi_pref_set_max_result(pref, 2);
1234                         gchar *item = g_strdup("Distance");
1235                         location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1236                         location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);  //LOCATION_POI_PREF_SO_ASC
1237
1238
1239                         ret = location_search_poi_by_area(location_obj, filter, bound, pref, cb_poi, NULL, &req_id);
1240                         GetLocationError(str, ret);
1241                         if (ret != LOCATION_ERROR_NONE) {
1242                                         g_printf("Fail to search POI by area. Error[%s]\n", str);
1243                         } else {
1244                                         g_printf("Seach POI by area sucess, req_id %d\n", req_id);
1245                         }
1246
1247                         g_free(key);
1248                         g_free(value);
1249                         g_free(item);
1250                         location_position_free(center);
1251                         location_boundary_free(bound);
1252                         location_poi_filter_free(filter);
1253                         location_poi_pref_free(pref);
1254                 }else if(0 == g_strcmp0("16b", strOpt)) {
1255                         g_printf("location_search_poi_by_address\n");
1256
1257                         LocationAddress *addr = location_address_new("51", "N SAN PEDRO ST", NULL, "SAN JOSE", "SANTA CLARA", "CA", "95110");
1258                         //landmark type ?
1259                         //landmark name ?
1260
1261                         LocationPOIFilter *filter = location_poi_filter_new();
1262                         gchar *key = g_strdup("KEYWORD");
1263                         gchar *value = g_strdup("cafe");
1264                         location_poi_filter_set(filter, key, value); // same with Type ?  CATEGORY, KEYWORD, POIName
1265
1266                         LocationPOIPreference *pref = location_poi_pref_new();
1267                         location_poi_pref_set_max_result(pref, 10);
1268                         gchar *item = g_strdup("Distance");
1269                         location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1270                         location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);  //LOCATION_POI_PREF_SO_ASC
1271
1272                         ret = location_search_poi_by_address(location_obj, filter, addr, pref, cb_poi, NULL, &req_id);
1273                         GetLocationError(str, ret);
1274                         if(ret != LOCATION_ERROR_NONE) {
1275                                         g_printf("Fail to search POI by address. Error[%s]\n", str);
1276                         } else {
1277                                         g_printf("Seach POI by address sucess, req_id %d\n", req_id);
1278                         }
1279
1280                         g_free(key);
1281                         g_free(value);
1282                         g_free(item);
1283
1284                         location_address_free(addr);
1285                         location_poi_filter_free(filter);
1286                         location_poi_pref_free(pref);
1287                 }else if(0 == g_strcmp0("16c", strOpt)) {
1288                         g_printf("location_search_poi_by_freeformed_address\n");
1289                 
1290                         gchar *addr = g_strdup("North Second St.");
1291
1292                         LocationPOIFilter *filter = location_poi_filter_new();
1293                         gchar *key = g_strdup("KEYWORD");
1294                         gchar *value = g_strdup("restaurant");
1295                         location_poi_filter_set(filter, key, value); // same with Type ?  CATEGORY, KEYWORD, POIName
1296
1297                         LocationPOIPreference *pref = location_poi_pref_new();
1298                         location_poi_pref_set_max_result(pref, 10);
1299                         gchar *item = g_strdup("Distance");
1300                         location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1301                         location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);  //LOCATION_POI_PREF_SO_ASC
1302                         
1303                         ret = location_search_poi_by_freeformed_address(location_obj, filter, addr, pref, cb_poi, NULL, &req_id);
1304                         GetLocationError(str, ret);
1305                         if (ret != LOCATION_ERROR_NONE) {
1306                                         g_printf("Fail to search POI by address. Error[%s]\n", str);
1307                         } else {
1308                                         g_printf("Seach POI by address success, req_id %d\n", req_id);
1309                 }
1310
1311                         g_free(key);
1312                         g_free(value);
1313                         g_free(item);
1314
1315                         g_free(addr);
1316                         location_poi_filter_free(filter);
1317                         location_poi_pref_free(pref);
1318                 }else if(0 == g_strcmp0("16d", strOpt)) {
1319                         gchar value[255] = {0, };
1320
1321                         // only circle supported by decarta
1322                         LocationPosition *center = location_position_new(0, 37.56693, 126.97819, 0, LOCATION_STATUS_2D_FIX);
1323                         gdouble radius = 800;
1324                         LocationBoundary *bound = location_boundary_new_for_circle(center, radius);
1325
1326                         LocationPOIFilter *filter = location_poi_filter_new();
1327
1328                         g_printf("Input keyword :");
1329                         scanf("%s", value);
1330                         gchar *key = g_strdup("KEYWORD");
1331                         location_poi_filter_set(filter, key, value); // same with Type ?  CATEGORY, KEYWORD, POIName
1332
1333                         LocationPOIPreference *pref = location_poi_pref_new();
1334                         location_poi_pref_set_max_result(pref, 2);
1335                         gchar *item = g_strdup("Distance");
1336                         location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1337                         location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);  //LOCATION_POI_PREF_SO_ASC
1338
1339
1340                         ret = location_search_poi_by_area(location_obj, filter, bound, pref, cb_poi, NULL, &req_id);
1341                         GetLocationError(str, ret);
1342                         if (ret != LOCATION_ERROR_NONE) {
1343                                         g_printf("Fail to search POI by area. Error[%s]\n", str);
1344                         } else {
1345                                         g_printf("Seach POI by area sucess, req_id %d\n", req_id);
1346                         }
1347
1348                         g_free(key);
1349                         g_free(value);
1350                         g_free(item);
1351                         location_position_free(center);
1352                         location_boundary_free(bound);
1353                         location_poi_filter_free(filter);
1354                         location_poi_pref_free(pref);
1355                 }else if(0 == g_strcmp0("16e", strOpt)) {
1356                         int req_id;
1357
1358                         g_printf("Input ReqID : ");
1359                         scanf("%d", &req_id);
1360
1361                         ret = location_cancel_poi_request(location_obj, req_id);
1362                         GetLocationError(str, ret);
1363                         if (ret != LOCATION_ERROR_NONE) {
1364                                 g_printf("Fail to cancel POI request. Error[%s]\n", str);
1365                         }
1366                         else
1367                                 g_printf("location_cancel_poi_request, req_id %d\n", req_id);
1368                 }else if(0 == g_strcmp0("17", strOpt)) {
1369                         g_printf("17.  location_request_route\n\n");
1370
1371                         LocationPosition *origin = location_position_new(0, 37.564263, 126.974676, 0, LOCATION_STATUS_2D_FIX);  // Seoul city hall
1372                         LocationPosition *destination = location_position_new(0, 37.557120, 126.992410, 0, LOCATION_STATUS_2D_FIX);     // NamSan
1373
1374                         GList *waypoint = NULL;
1375                         LocationPosition *via_pos = location_position_new(0, 37.560950, 126.986240, 0, LOCATION_STATUS_2D_FIX); // Wangsimli
1376                         waypoint = g_list_append (waypoint, (gpointer)via_pos);
1377
1378                         LocationRoutePreference *pref = location_route_pref_new();
1379                         location_route_pref_set_route_type(pref, "FASTEST");
1380
1381                         ret = location_request_route(location_obj, origin, destination, waypoint, pref, cb_route, NULL, &req_id);
1382                         GetLocationError(str, ret);
1383                         if (ret != LOCATION_ERROR_NONE) {
1384                                         g_printf("Fail to search route by address. Error[%s]\n", str);
1385                         } else {
1386                                         g_printf("Search Route successfully, req_id %d\n", req_id);
1387                         }
1388                 }else if(0 == g_strcmp0("17a", strOpt)) {
1389                         g_printf("17a.  location_cancel_route_request\n");
1390
1391                         int req_id;
1392                         g_printf("Input ReqID : ");
1393                         scanf("%d", &req_id);
1394
1395                         ret = location_cancel_route_request(location_obj, req_id);
1396                         GetLocationError(str, ret);
1397                         if (ret != LOCATION_ERROR_NONE) {
1398                                 g_printf("Fail to cancel route request. Error[%s]\n", str);
1399                         }
1400                         else {
1401                                 g_printf("location_cancel_route_request, req_id %d\n", req_id);
1402                         }
1403
1404                 }else if (0 == g_strcmp0 ("18", strOpt)) {
1405                         int idx = 0;
1406                         for (idx = 0; idx < MAP_SERVICE_TYPE_MAX; idx++) {
1407                                 g_printf("[%d:%d], ", idx, location_is_supported_map_provider_capability (location_obj, idx));
1408                         }
1409                 }else if (0 == g_strcmp0 ("19", strOpt)) {
1410                         int idx = 0;
1411                         for (idx = 0; idx < MAP_SERVICE_TYPE_MAX; idx++) {
1412                                 g_printf("[%d:", idx);
1413                                 print_map_service_keys(location_obj, idx);
1414                                 g_printf("]\n");
1415                         }
1416                 }else if(0 == g_strcmp0("99", strOpt)) {
1417                         int ret = 0;
1418                         const *str = "command";
1419                         ret = location_send_command(str);
1420                         if(ret == 0)
1421                                 g_printf("Success to send command[%s]", str);
1422                 }else if(0 == g_strcmp0("a1",strOpt)){
1423                         if(location_obj && !g_sig_enable) {
1424                                 g_sig_enable = g_signal_connect (location_obj, "service-enabled", G_CALLBACK(cb_service_enabled), location_obj);
1425                         }
1426                 }else if(0 == g_strcmp0("a2",strOpt)){
1427                         if(location_obj && !g_sig_disable){
1428                                 g_sig_disable = g_signal_connect (location_obj, "service-disabled", G_CALLBACK(cb_service_disabled), location_obj);
1429                         }
1430                 }else if(0 == g_strcmp0("a3",strOpt)){
1431                         if(location_obj && !g_sig_update){
1432                                 g_sig_update = g_signal_connect (location_obj, "service-updated", G_CALLBACK(cb_service_updated), location_obj);
1433                         }
1434                 }else if(0 == g_strcmp0("a4",strOpt)){
1435                         if(location_obj && !g_sig_zonein){
1436                                 g_sig_zonein = g_signal_connect (location_obj, "zone-in", G_CALLBACK(cb_zone_in), location_obj);
1437                         }
1438                 }else if(0 == g_strcmp0("a5",strOpt)){
1439                         if(location_obj && !g_sig_zoneout){
1440                                 g_sig_zoneout = g_signal_connect (location_obj, "zone-out", G_CALLBACK(cb_zone_out), location_obj);
1441                         }
1442                 }else if(0 == g_strcmp0("b1",strOpt)){
1443                         if(location_obj && g_sig_enable) {
1444                                 g_signal_handler_disconnect (location_obj, g_sig_enable);
1445                                 g_sig_enable = 0;
1446                         }
1447                 }else if(0 == g_strcmp0("b2",strOpt)){
1448                         if(location_obj && g_sig_disable){
1449                                 g_signal_handler_disconnect (location_obj, g_sig_disable);
1450                                 g_sig_disable = 0;
1451                         }
1452                 }else if(0 == g_strcmp0("b3",strOpt)){
1453                         if(location_obj && g_sig_update){
1454                                 g_signal_handler_disconnect (location_obj, g_sig_update);
1455                                 g_sig_update = 0;
1456                         }
1457                 }else if(0 == g_strcmp0("b4",strOpt)){
1458                         if(location_obj && g_sig_zonein){
1459                                 g_signal_handler_disconnect (location_obj, g_sig_zonein);
1460                                 g_sig_zonein = 0;
1461                         }
1462                 }else if(0 == g_strcmp0("b5",strOpt)){
1463                         if(location_obj && g_sig_zoneout){
1464                                 g_signal_handler_disconnect (location_obj, g_sig_zoneout);
1465                                 g_sig_zoneout = 0;
1466                         }
1467                 }else if(0 == g_strcmp0("c1",strOpt)){
1468                         LocationBoundary* bound = NULL;
1469                         int i = 0;
1470                         int polygon_count = json_util_get_polygon_count();
1471
1472                         g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
1473                         for(i = 0; i < polygon_count; i++)
1474                                 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
1475
1476                         g_printf("\nSelect Boundary: ");
1477                         int opt = PromptInt();
1478                         if (opt == 0) {
1479                                 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
1480                                 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
1481                                 bound = location_boundary_new_for_rect (lt, rb);
1482                                 location_position_free(rb);
1483                                 location_position_free(lt);
1484
1485                                 location_boundary_add(location_obj, bound);
1486
1487                         } else if(opt == 1) {
1488                                 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
1489                                 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
1490                                 bound = location_boundary_new_for_rect (lt, rb);
1491                                 location_position_free(rb);
1492                                 location_position_free(lt);
1493
1494                                 location_boundary_add(location_obj, bound);
1495                         } else if(opt == 2) {
1496                                 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
1497                                 double radius = 10.0;
1498                                 bound = location_boundary_new_for_circle(center, radius);
1499
1500                                 location_boundary_add(location_obj, bound);
1501                         } else if (opt > 2 && opt < 3 + polygon_count) {
1502                                 int index;
1503                                 int polygon_index = opt - 3;
1504                                 bound = json_util_get_polygon_boundary(polygon_index);
1505                                 location_boundary_add(location_obj, bound);
1506
1507                                 LocationPosition * check_pos = NULL;
1508                                 gboolean ret = FALSE;
1509                                 int count = json_util_get_marker_position_count(polygon_index);
1510                                 for(index = 0; index < count; index++) {
1511                                         check_pos = json_util_get_marker_position(polygon_index, index);
1512
1513                                         ret = location_boundary_if_inside(bound, check_pos);
1514                                         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");
1515                                         location_position_free(check_pos);
1516                                 }
1517                         } else {
1518                                 g_printf("boundary is not set\n");
1519                         }
1520                         location_boundary_free(bound);
1521
1522                 }else if(0 == g_strcmp0("c2",strOpt)){
1523                         g_printf("Get Boundary\n");
1524                         location_boundary_foreach(location_obj, PrintBoundary, NULL);
1525
1526                 }else if(0 == g_strcmp0("c3",strOpt)){
1527                         g_printf("Remove Boundary\n");
1528                         LocationBoundary* bound = NULL;
1529
1530                         int i = 0;
1531                         int polygon_count = json_util_get_polygon_count();
1532
1533                         g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
1534                         for(i = 0; i < polygon_count; i++)
1535                                 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
1536
1537                         g_printf("\nSelect Boundary: ");
1538                         int opt = PromptInt();
1539                         if (opt == 0) {
1540                                 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
1541                                 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
1542                                 bound = location_boundary_new_for_rect (lt, rb);
1543                                 location_position_free(rb);
1544                                 location_position_free(lt);
1545
1546                         } else if(opt == 1) {
1547                                 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
1548                                 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
1549                                 bound = location_boundary_new_for_rect (lt, rb);
1550                                 location_position_free(rb);
1551                                 location_position_free(lt);
1552
1553                         } else if(opt == 2) {
1554                                 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
1555                                 double radius = 10.0;
1556                                 bound = location_boundary_new_for_circle(center, radius);
1557                                 location_position_free(center);
1558
1559                         } else if (opt > 2 && opt < 3 + polygon_count) {
1560                                 int polygon_index = opt - 3;
1561                                 bound = json_util_get_polygon_boundary(polygon_index);
1562                         } else {
1563                                 g_printf("Invalid value\n");
1564                         }
1565
1566                         if(bound != NULL) location_boundary_remove(location_obj, bound);
1567
1568                 }else if(0 == g_strcmp0("c4",strOpt)){
1569                         location_boundary_foreach(location_obj, RemoveBoundary, location_obj);
1570                 }else if(0 == g_strcmp0("c5",strOpt)){
1571                         char buf[255];
1572                         g_printf("Input device name: ");
1573                         fgets(buf, 255, stdin);
1574                         buf[strlen(buf)-1]='\0';
1575                         g_object_set(location_obj, "dev-name", buf, NULL);
1576                 } else if (0 == g_strcmp0("c6", strOpt)) {
1577                         guint interval = 1;
1578                         g_printf("Input interval[1~120]:");
1579                         scanf("%u", &interval);
1580                         g_printf("changed interval to [%u]\n", interval);
1581                         g_object_set(location_obj, "update-interval", interval, NULL);
1582                 }else if(0 == g_strcmp0("q",strOpt) ){
1583                         g_main_loop_quit(g_mainloop);
1584                         break;
1585                 }
1586         }
1587         g_thread_join(g_main);
1588         g_printf("\n--- Exit LBS Test App ---\n");
1589         return 1;
1590 }