Git init
[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 <glib/gprintf.h>
24 #include <gconf/gconf-client.h>
25 #include <location/location.h>
26 #include "location-api-test-util.h"
27
28 #define STR_MAX 128
29 LocationObject* location_obj = NULL;
30 static GMainLoop *g_mainloop = NULL;
31
32 #define GCONF_PROXY_MODE            "/system/proxy/mode"
33 #define GCONF_HTTP_PROXY_HOST       "/system/http_proxy/host"
34 #define GCONF_HTTP_PROXY_PORT       "/system/http_proxy/port"
35 #define ENV_HTTP_PROXY              "http_proxy"
36
37 #define LOCATION_API_TEST_JSON_FILE "/opt/data/location-api-test.json"
38
39 static gpointer GmainThread(gpointer data)
40 {
41         g_mainloop = g_main_loop_new (NULL, FALSE);
42         g_printf("\n...Entering GMain Loop to Receive Notifications....\n");
43         g_main_loop_run (g_mainloop);
44         g_main_loop_unref (g_mainloop);
45         g_mainloop = NULL;
46         return NULL;
47 }
48
49
50 static void GetLocationError(char str[STR_MAX], int ret)
51 {
52         switch(ret)
53         {
54                 case LOCATION_ERROR_NONE:
55                         g_utf8_strncpy(str, "LOCATION_ERROR_NONE", STR_MAX);
56                         break;
57                 case LOCATION_ERROR_NOT_ALLOWED:
58                         g_utf8_strncpy(str, "LOCATION_ERROR_NOT_ALLOWED", STR_MAX);
59                         break;
60                 case LOCATION_ERROR_NOT_AVAILABLE:
61                         g_utf8_strncpy(str, "LOCATION_ERROR_NOT_AVAILABLE", STR_MAX);
62                         break;
63                 case LOCATION_ERROR_NETWORK_FAILED:
64                         g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_FAILED", STR_MAX);
65                         break;
66                 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
67                         g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_NOT_CONNECTED", STR_MAX);
68                         break;
69                 case LOCATION_ERROR_CONFIGURATION:
70                         g_utf8_strncpy(str, "LOCATION_ERROR_CONFIGURATION", STR_MAX);
71                         break;
72                 case LOCATION_ERROR_PARAMETER:
73                         g_utf8_strncpy(str, "LOCATION_ERROR_PARAMETER", STR_MAX);
74                         break;
75                 case LOCATION_ERROR_UNKNOWN:
76                         g_utf8_strncpy(str, "LOCATION_ERROR_UNKNOWN", STR_MAX);
77                         break;
78                 default:
79                         g_utf8_strncpy(str, "Error: undefined error code", STR_MAX);
80         }
81 }
82
83 static void GetStatus(char str[STR_MAX], LocationStatus acc_level)
84 {
85         switch(acc_level)
86         {
87                 case LOCATION_STATUS_NO_FIX:
88                         g_utf8_strncpy(str, "LOCATION_STATUS_NO_FIX", STR_MAX);
89                         break;
90                 case LOCATION_STATUS_2D_FIX:
91                         g_utf8_strncpy(str, "LOCATION_STATUS_2D_FIX", STR_MAX);
92                         break;
93                 case LOCATION_STATUS_3D_FIX:
94                         g_utf8_strncpy(str, "LOCATION_STATUS_3D_FIX", STR_MAX);
95                         break;
96                 default:
97                         g_utf8_strncpy(str, "Error: undefined status code", STR_MAX);
98         }
99 }
100
101 static void GetMethod(char str[STR_MAX], LocationMethod acc_level)
102 {
103         switch(acc_level)
104         {
105                 case LOCATION_METHOD_HYBRID:
106                         g_utf8_strncpy(str, "LOCATION_METHOD_HYBRID", STR_MAX);
107                         break;
108                 case LOCATION_METHOD_GPS:
109                         g_utf8_strncpy(str, "LOCATION_METHOD_GPS", STR_MAX);
110                         break;
111                 case LOCATION_METHOD_CPS:
112                         g_utf8_strncpy(str, "LOCATION_METHOD_CPS", STR_MAX);
113                         break;
114                 case LOCATION_METHOD_IPS:
115                         g_utf8_strncpy(str, "LOCATION_METHOD_IPS", STR_MAX);
116                         break;
117                 case LOCATION_METHOD_WPS:
118                         g_utf8_strncpy(str, "LOCATION_METHOD_WPS", STR_MAX);
119                         break;
120                 case LOCATION_METHOD_SPS:
121                         g_utf8_strncpy(str, "LOCATION_METHOD_SPS", STR_MAX);
122                         break;
123                 default:
124                         g_utf8_strncpy(str, "Error: undefined method", STR_MAX);
125         }
126 }
127
128 static void GetAccuracyLevel(char str[STR_MAX], LocationAccuracyLevel acc_level)
129 {
130         switch(acc_level)
131         {
132                 case LOCATION_ACCURACY_LEVEL_NONE:
133                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_NONE", STR_MAX);
134                         break;
135                 case LOCATION_ACCURACY_LEVEL_COUNTRY:
136                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_COUNTRY", STR_MAX);
137                         break;
138                 case LOCATION_ACCURACY_LEVEL_REGION:
139                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_REGION", STR_MAX);
140                         break;
141                 case LOCATION_ACCURACY_LEVEL_LOCALITY:
142                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_LOCALITY", STR_MAX);
143                         break;
144                 case LOCATION_ACCURACY_LEVEL_POSTALCODE:
145                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_POSTALCODE", STR_MAX);
146                         break;
147                 case LOCATION_ACCURACY_LEVEL_STREET:
148                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_STREET", STR_MAX);
149                         break;
150                 case LOCATION_ACCURACY_LEVEL_DETAILED:
151                         g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_DETAILED", STR_MAX);
152                         break;
153                 default:
154                         g_utf8_strncpy(str, "Error: undefined accuracy level", STR_MAX);
155         }
156 }
157
158
159 static void SelectOpt(char* buf)
160 {
161         int iLen = 0;
162         fgets(buf, 255, stdin);
163         iLen = g_utf8_strlen(buf, -1);
164         buf[iLen-1] = '\0';
165 }
166
167 static int PromptInt()
168 {
169         char buf[255];
170         int ret;
171         fgets(buf, 255, stdin);
172         buf[strlen(buf)-1]='\0';
173         ret = g_ascii_strtoll(buf, NULL, 10);
174         return ret;
175 }
176
177 static double PromptDB()
178 {
179         char buf[255];
180         double ret;
181         fgets(buf, 255, stdin);
182         buf[strlen(buf)-1]='\0';
183         ret = g_ascii_strtod(buf, NULL);
184         return ret;
185 }
186
187 gulong g_sig_enable = 0;
188 gulong g_sig_disable = 0;
189 gulong g_sig_update = 0;
190 gulong g_sig_zonein = 0;
191 gulong g_sig_zoneout = 0;
192
193 static void PrintPolygonPosition(gpointer data, gpointer user_data)
194 {
195         LocationPosition *position = (LocationPosition*) data;
196         g_printf("[%lf %lf %lf] ", position->latitude, position->longitude, position->altitude);
197 }
198
199 static void PrintBoundary(LocationBoundary *boundary, void *user_data)
200 {
201         if(boundary == NULL) return;
202         if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
203                 g_printf("\n\tCIRCLE: center[%lf %lf %lf] radius[%lf]",
204                                 boundary->circle.center->latitude, boundary->circle.center->longitude, boundary->circle.center->altitude, boundary->circle.radius);
205         } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
206                 g_printf("\n\tRECT: left_top[%lf %lf %lf] right_bottom[%lf %lf %lf]",
207                                 boundary->rect.left_top->latitude, boundary->rect.left_top->longitude, boundary->rect.left_top->altitude,
208                                 boundary->rect.right_bottom->latitude, boundary->rect.right_bottom->longitude, boundary->rect.right_bottom->altitude);
209         } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
210                 g_printf("\n\tPOLYGON: ");
211
212                 GList *list = boundary->polygon.position_list;
213
214                 g_list_foreach(list, PrintPolygonPosition, NULL);
215         }
216 }
217
218 static void RemoveBoundary(LocationBoundary *boundary, void *user_data)
219 {
220         LocationObject * obj = (LocationObject *)user_data;
221         if(obj == NULL || boundary == NULL) return;
222
223         location_boundary_remove(obj, boundary);
224 }
225
226 static void PrintProperty (LocationObject* loc)
227 {
228         if (!loc) return;
229         LocationMethod method = LOCATION_METHOD_NONE;
230         LocationPosition *pos = NULL;
231         guint interval = 0;
232         gchar method_str[STR_MAX] = {0, };
233         gchar status_str[STR_MAX] = {0, };
234
235         gchar* devname = NULL;
236
237         g_object_get(loc, "method", &method, NULL);
238         GetMethod(method_str, method);
239         g_printf("method[%s] ", method_str);
240
241         if (LOCATION_METHOD_GPS == method) {
242                 g_object_get(loc, "dev-name", &devname, NULL);
243                 if (devname) {
244                         g_printf("dev-name[%s] ", devname);
245                         g_free(devname);
246                 }
247         }
248
249         g_object_get(loc, "last-position", &pos, NULL);
250         if (pos) {
251                 GetStatus(status_str, pos->status);
252                 g_printf("\nLast position [time(%d) lat(%f) long(%f) alt(%f) status(%s)]",
253                                 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, status_str);
254                 location_position_free (pos);
255         }
256
257         g_object_get(loc, "update-interval", &interval, NULL);
258         g_printf("Update interval : [%u]", interval);
259
260         if (LOCATION_METHOD_CPS == method ||  LOCATION_METHOD_IPS == method) return;
261
262         g_printf("\nSignals: ");
263         if (g_sig_enable)  g_printf("[service-enabled], ");
264         if (g_sig_disable) g_printf("[service-disabled], ");
265         if (g_sig_update)  g_printf("[service-updated], ");
266         if (g_sig_zonein)  g_printf("[zone-in], ");
267         if (g_sig_zoneout) g_printf("[zone-out]");
268 }
269
270 static void cb_service_enabled (GObject *self,  guint status, gpointer userdata)
271 {
272         g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
273
274         LocationObject *loc = (LocationObject*)userdata;
275         LocationAccuracy *acc = NULL;
276         LocationPosition *pos = NULL;
277         LocationVelocity *vel = NULL;
278         LocationAddress *addr = NULL;
279         LocationMethod method;
280
281         g_object_get(loc, "method", &method, NULL);
282         g_debug("Get property>> method:%d", method);
283
284         if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
285                 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
286                         pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
287                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
288                         acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
289                 location_position_free(pos);
290                 location_accuracy_free(acc);
291         } else g_warning ("SYNC>> Current position> failed");
292         if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
293                 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
294                         vel->timestamp, vel->speed, vel->direction, vel->climb);
295                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
296                         acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
297                 location_velocity_free(vel);
298                 location_accuracy_free(acc);
299         } else g_warning ("SYNC>> Current velocity> failed");
300         if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
301                 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
302                         addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
303                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
304                 location_address_free(addr);
305                 location_accuracy_free(acc);
306         } else g_warning ("SYNC>> Current address> failed");
307 }
308
309 static void
310 cb_service_disabled (GObject *self,
311         guint status,
312         gpointer userdata)
313 {
314         g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
315 }
316
317 static void
318 cb_zone_in (GObject *self,
319         guint type,
320         gpointer position,
321         gpointer accuracy)
322 {
323         g_debug("cb_zone_in: type(%d)", type);
324         LocationPosition *pos = (LocationPosition*) position;
325         LocationAccuracy *acc = (LocationAccuracy*) accuracy;
326
327         g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
328                 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
329         g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
330                 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
331 }
332
333 static void
334 cb_zone_out (GObject *self,
335         guint type,
336         gpointer position,
337         gpointer accuracy)
338 {
339         g_debug("cb_zone_out: type(%d)", type);
340         LocationPosition *pos = (LocationPosition*) position;
341         LocationAccuracy *acc = (LocationAccuracy*) accuracy;
342
343         g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
344                 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
345         g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
346                 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
347 }
348
349 static void
350 cb_service_updated (GObject *self,
351         guint type,
352         gpointer data,
353         gpointer accuracy,
354         gpointer userdata)
355 {
356         g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
357
358         LocationAccuracy *acc = (LocationAccuracy*) accuracy;
359         switch (type) {
360         case POSITION_UPDATED: {
361                         LocationPosition *pos = (LocationPosition*) data;
362                         g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
363                                 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
364                         g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
365                                 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
366                 }
367                 break;
368         case VELOCITY_UPDATED: {
369                         LocationVelocity *vel = (LocationVelocity*) data;
370                         g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
371                                 vel->timestamp, vel->speed, vel->direction, vel->climb);
372                         g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
373                                 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
374                 }
375                 break;
376         default:
377                 g_warning ("ASYNC>> Undefined update type");
378                 break;
379         }
380 }
381
382 static void cb_position (LocationError error,
383         LocationPosition *position,
384         LocationAccuracy *acc,
385         gpointer userdata)
386 {
387         if (error != LOCATION_ERROR_NONE) {
388                 g_printf("cb_position failed: error=%d\n", error);
389                 return;
390         }
391         char str[STR_MAX];
392         g_printf("userdata[0x%x] time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", (unsigned int)userdata, position->timestamp, position->latitude, position->longitude, position->altitude);
393         GetAccuracyLevel(str, acc->level);
394         g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
395 }
396
397 static void cb_address(LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata)
398 {
399         if (error != LOCATION_ERROR_NONE) {
400                 g_printf("cb_address failed: error=%d\n", error);
401                 return;
402         }
403         char str[STR_MAX];
404         g_printf("userdata[0x%x] building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
405                 (unsigned int)userdata, addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
406         GetAccuracyLevel(str, acc->level);
407         g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
408 }
409
410 typedef struct {
411         LocationObject *obj;
412         LocationPosition *pos;
413         LocationAddress *addr;
414         gchar *str_addr;
415         LocationPositionCB pos_cb;
416         LocationAddressCB addr_cb;
417         gpointer user_data;
418 } IdleData;
419
420 static gboolean idle_position_from_address_async(gpointer data)
421 {
422         IdleData* idle_data = (IdleData*)data;
423         char str[STR_MAX];
424         int ret = location_get_position_from_address_async(idle_data->obj, idle_data->addr, idle_data->pos_cb, idle_data->user_data);
425         GetLocationError(str, ret);
426         g_printf("location_get_position_from_address_async: returned value [%s]\n", str);
427         location_address_free(idle_data->addr);
428         g_free(idle_data);
429         return FALSE;
430 }
431
432 static gboolean idle_position_from_freefromed_address_async(gpointer data)
433 {
434         IdleData* idle_data = (IdleData*)data;
435         char str[STR_MAX];
436         int ret = location_get_position_from_freeformed_address_async(idle_data->obj, idle_data->str_addr, idle_data->pos_cb, idle_data->user_data);
437         GetLocationError(str, ret);
438         g_printf("location_get_position_from_freeformed_address_async: returned value [%s]\n", str);
439         g_free(idle_data->str_addr);
440         g_free(idle_data);
441         return FALSE;
442 }
443
444 static gboolean idle_address_async(gpointer data)
445 {
446         IdleData* idle_data = (IdleData*)data;
447         char str[STR_MAX];
448         int ret = location_get_address_async(idle_data->obj, idle_data->addr_cb, idle_data->user_data);
449         GetLocationError(str, ret);
450         g_printf("location_get_address_async: returned value [%s]\n", str);
451         g_free(idle_data);
452         return FALSE;
453 }
454
455 static gboolean idle_address_from_position_async(gpointer data)
456 {
457         IdleData* idle_data = (IdleData*)data;
458         char str[STR_MAX];
459         int ret = location_get_address_from_position_async(idle_data->obj, idle_data->pos, idle_data->addr_cb, idle_data->user_data);
460         GetLocationError(str, ret);
461         g_printf("location_get_address_from_position_async: returned value [%s]\n", str);
462         location_position_free(idle_data->pos);
463         g_free(idle_data);
464         return FALSE;
465 }
466
467 static void print_menu()
468 {
469         g_printf("\n================================= Location API Test =================================\n");
470         g_printf("q.   Exit\n");
471         g_printf("1.   location_init\n");
472         g_printf("2.   location_new\n");
473         g_printf("3.   location_free\n");
474         g_printf("4.   location_start\n");
475         g_printf("5.   location_stop\n");
476         g_printf("6.   location_get_position\n");
477         g_printf("6a.  location_get_last_known_position\n");
478         g_printf("7.   location_get_position_from_address\n");
479         g_printf("7a.  location_get_position_from_address_async\n");
480         g_printf("8.   location_get_position_from_freeformed_address\n");
481         g_printf("8a.  location_get_position_from_freeformed_address_async\n");
482         g_printf("9.   location_get_velocity\n");
483         g_printf("10.  location_get_address\n");
484         g_printf("10a. location_get_address_async\n");
485         g_printf("11.  location_get_address_from_position\n");
486         g_printf("11a. location_get_address_from_position_async\n");
487         g_printf("12.  location_get_distance\n");
488         g_printf("13.  location_is_supported_method\n");
489         g_printf("14.  location_is_enabled_gps\n");
490         g_printf("99.  location_send_command\n");
491         g_printf("a?.  signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
492         g_printf("b?.  disconnect signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
493         g_printf("c?. (1)Set boundary, (2)Get boundary, (3) Remove boundary, (4) Remove all boundaries, (5)Set device name, (6)Set update interval\n");
494         g_printf("==================================== Property ====================================\n");
495         PrintProperty(location_obj);
496         g_printf("\n==================================================================================\n");
497 }
498
499 int main(int argc, char** argv)
500 {
501         char strOpt[255];
502         int ret;
503         char str[STR_MAX];
504         GError *gerr = NULL;
505
506         // If application is executed by AUL, this is not needed.
507         g_setenv("PKG_NAME", "org.tizen.location-api-test", 1);
508
509         g_type_init();
510         if( !g_thread_supported() )
511         {
512                 g_thread_init(NULL);
513         }
514
515         GThread *g_main;
516         g_main = g_thread_create(GmainThread, NULL, TRUE, &gerr);
517         if (!g_main) {
518                 g_debug("Error create gmain thread: Err domain[%d] Err code[%d] Err msg[%s]",
519                         gerr->domain, gerr->code, gerr->message);
520                 g_error_free(gerr);
521                 return 0;
522         }
523
524         json_util_init(LOCATION_API_TEST_JSON_FILE);
525         g_printf("--- Start LBS Test App ---\n");
526         while(1)
527         {
528                 print_menu();
529                 g_printf("Select option: ");
530                 SelectOpt(strOpt);
531                 g_printf("======================================================================================\n");
532                 if (0 == g_strcmp0 ("x", strOpt)) {
533
534                 }
535                 else if (0 == g_strcmp0("1",strOpt)) {
536                         ret = location_init();
537                         GetLocationError(str, ret);
538                         g_printf("location_init: returned value [%s]\n", str);
539                 } else if (0 == g_strcmp0("2",strOpt)) {
540                         if (location_obj) {
541                                 g_printf("Location object already existed: [0x%x]", (unsigned int)location_obj);
542                                 continue;
543                         }
544                         g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_CPS[3] LOCATION_METHOD_IPS[4] LOCATION_METHOD_SPS[5]\n");
545                         g_printf("Select Location Method: ");
546                         LocationMethod method = PromptInt();
547                         location_obj = location_new(method);
548                         if(location_obj) g_printf("Success\n");
549                         else             g_printf("Failed\n");
550                 } else if (0 == g_strcmp0("3",strOpt)) {
551                         ret = location_free (location_obj);
552                         location_obj = NULL;
553                         g_sig_enable = 0;
554                         g_sig_disable = 0;
555                         g_sig_update = 0;
556                         g_sig_zonein = 0;
557                         g_sig_zoneout = 0;
558                         GetLocationError(str, ret);
559                         g_printf("location_free: returned value [%s]\n", str);
560                 } else if (0 == g_strcmp0("4",strOpt)) {
561                         ret = location_start(location_obj);
562                         GetLocationError(str, ret);
563                         g_printf("location_start: returned value [%s]\n", str);
564                 } else if (0 == g_strcmp0("5",strOpt)) {
565                         ret = location_stop(location_obj);
566                         GetLocationError(str, ret);
567                         g_printf("location_stop: returned value [%s]\n", str);
568                 } else if (0 == g_strcmp0("6",strOpt)) {
569                         LocationPosition *pos = NULL;
570                         LocationAccuracy *acc = NULL;
571                         ret = location_get_position(location_obj, &pos, &acc);
572                         GetLocationError(str, ret);
573                         g_printf("location_get_position: returned value [%s]\n", str);
574                         if (ret == LOCATION_ERROR_NONE) {
575                                 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f], status: [%d]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
576                                 GetAccuracyLevel(str, acc->level);
577                                 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
578                         }
579                         if(pos) location_position_free(pos);
580                         if(acc) location_accuracy_free(acc);
581                 } else if (0 == g_strcmp0("6a",strOpt)) {
582                         LocationLastPosition last_pos;
583                         ret = location_get_last_known_position(location_obj, &last_pos);
584                         GetLocationError(str, ret);
585                         g_printf("location_get_last_known_position: returned value [%s]\n", str);
586                         if (ret == LOCATION_ERROR_NONE) {
587                                 g_printf("last position latitude: [%f], longitude: [%f], accuracy: [%f]\n", last_pos.latitude, last_pos.longitude, last_pos.accuracy);
588                         }
589                 } else if (0 == g_strcmp0("7",strOpt)) {
590                         LocationAddress *add = NULL;
591                         LocationPosition *pos = NULL;
592                         LocationAccuracy *acc = NULL;
593
594                         g_printf("[0].San jose [1].¼ö¿ø»ï¼º [2].Suwon HQ [*].Custom\n");
595                         g_printf("Select Address: ");
596                         int opt = PromptInt();
597                         if (opt == 0)      add = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
598                         else if (opt == 1) add = location_address_new (NULL, "»ï¼º·Î", "¸Åź3µ¿", "¼ö¿ø½Ã Â¿ÂµÃ…뱸", "°æ±âµµ", NULL, NULL);
599                         else if (opt == 2) add = location_address_new (NULL, "Samsung Electro-Mechanics Co. LTD", "Maetan 3-dong", "Suwon Si Yeongtong-gu", "Gyeonggi-do", NULL, NULL);
600                         else {
601                                 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
602                                 g_printf("Input building number: ");
603                                 fgets(building_number, 255, stdin);
604                                 building_number[strlen(building_number)-1]='\0';
605                                 g_printf("Input street: ");
606                                 fgets(street, 255, stdin);
607                                 street[strlen(street)-1]='\0';
608                                 g_printf("Input state: ");
609                                 fgets(state, 255, stdin);
610                                 state[strlen(state)-1]='\0';
611                                 g_printf("Input country code: ");
612                                 fgets(country_code, 255, stdin);
613                                 country_code[strlen(country_code)-1]='\0';
614                                 g_printf("Input city: ");
615                                 fgets(city, 255, stdin);
616                                 city[strlen(city)-1]='\0';
617                                 g_printf("Input district: ");
618                                 fgets(district, 255, stdin);
619                                 district[strlen(district)-1]='\0';
620                                 g_printf("Input postal code: ");
621                                 fgets(postal_code, 255, stdin);
622                                 postal_code[strlen(postal_code)-1]='\0';
623                                 add = location_address_new(building_number, street, district, city, state, country_code, postal_code);
624                         }
625                         ret = location_get_position_from_address (location_obj, add, &pos, &acc);
626                         if(add) location_address_free (add);
627                         GetLocationError(str, ret);
628                         g_printf("location_get_position_from_adress: returned value [%s]\n", str);
629                         if (ret == LOCATION_ERROR_NONE)
630                                 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
631                         if(pos) location_position_free(pos);
632                         if(acc) location_accuracy_free(acc);
633                 } else if (0 == g_strcmp0("7a",strOpt)) {
634                         IdleData* data = g_new0(IdleData, 1);
635                         data->obj = location_obj;
636                         data->pos_cb = cb_position;
637                         data->user_data = location_obj;
638
639                         g_printf("[0].San jose [1].¼ö¿ø»ï¼º [2].Suwon HQ [*].Custom\n");
640                         g_printf("Select Address: ");
641                         int opt = PromptInt();
642                         if (opt == 0)      data->addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
643                         else if (opt == 1) data->addr = location_address_new (NULL, "»ï¼º·Î", "¸Åź3µ¿", "¼ö¿ø½Ã Â¿ÂµÃ…뱸", "°æ±âµµ", NULL, NULL);
644                         else if (opt == 2) data->addr = location_address_new (NULL, "Samsung Electro-Mechanics Co. LTD", "Maetan 3-dong", "Suwon Si Yeongtong-gu", "Gyeonggi-do", NULL, NULL);
645                         else {
646                                 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
647                                 g_printf("Input building number: ");
648                                 fgets(building_number, 255, stdin);
649                                 building_number[strlen(building_number)-1]='\0';
650                                 g_printf("Input street: ");
651                                 fgets(street, 255, stdin);
652                                 street[strlen(street)-1]='\0';
653                                 g_printf("Input state: ");
654                                 fgets(state, 255, stdin);
655                                 state[strlen(state)-1]='\0';
656                                 g_printf("Input country code: ");
657                                 fgets(country_code, 255, stdin);
658                                 country_code[strlen(country_code)-1]='\0';
659                                 g_printf("Input city: ");
660                                 fgets(city, 255, stdin);
661                                 city[strlen(city)-1]='\0';
662                                 g_printf("Input district: ");
663                                 fgets(district, 255, stdin);
664                                 district[strlen(district)-1]='\0';
665                                 g_printf("Input postal code: ");
666                                 fgets(postal_code, 255, stdin);
667                                 postal_code[strlen(postal_code)-1]='\0';
668                                 data->addr = location_address_new(building_number, street, district, city, state, country_code, postal_code);
669                         }
670                         g_idle_add((GSourceFunc)idle_position_from_address_async, data);
671                 }else if (0 == g_strcmp0("8",strOpt)) {
672                         gchar* addr = NULL;
673                         LocationPosition *pos = NULL;
674                         LocationAccuracy *acc = NULL;
675
676                         g_printf("[0].San jose [1].¼ö¿ø»ï¼º [2].Suwon HQ [*].Custom\n");
677                         g_printf("Select Address: ");
678                         int opt = PromptInt();
679                         if(opt == 0){
680                                 addr = g_strdup("4 N 2nd Street 95113");
681                         }else if(opt == 1){
682                                 addr = g_strdup("´ëÇѹα¹ Â°Ã¦Â±Ã¢ÂµÂµ Â¼Ã¶Â¿Ã¸Â½Ãƒ Â¿ÂµÃ…뱸 Â¸Ã…źµ¿ 436-52");
683                         }else if(opt == 2){
684                                 addr = g_strdup("Samsung Electronics Co. LTD Maetan 3-dong, Suwon Si Yeongtong-gu, Gyeonggi-Do (Seoul 443-742 Korea), Rep of KOREA");
685                         }else{
686                                 char buf[255];
687                                 g_printf("Input freeform address: ");
688                                 fgets(buf, 255, stdin);
689                                 buf[strlen(buf)-1]='\0';
690                                 addr = g_strdup(buf);
691                         }
692                         ret = location_get_position_from_freeformed_address(location_obj, addr, &pos, &acc);
693                         g_free(addr);
694                         GetLocationError(str, ret);
695                         g_printf("location_get_position_from_freeformed_adress: returned value [%s]\n", str);
696                         if(ret == LOCATION_ERROR_NONE){
697                                 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
698                         }
699                         if(pos) location_position_free(pos);
700                         if(acc) location_accuracy_free(acc);
701                 }else if(0 == g_strcmp0("8a",strOpt) ){
702                         IdleData* data = g_new0(IdleData, 1);
703                         data->obj = location_obj;
704                         data->pos_cb = cb_position;
705                         data->user_data = location_obj;
706                         g_printf("[0].San jose [1].¼ö¿ø»ï¼º [2].Suwon HQ [*].Custom\n");
707                         g_printf("Select Address: ");
708                         int opt = PromptInt();
709                         if(opt == 0){
710                                 data->str_addr = g_strdup("4 N 2nd Street 95113");
711                         }else if(opt == 1){
712                                 data->str_addr = g_strdup("´ëÇѹα¹ Â°Ã¦Â±Ã¢ÂµÂµ Â¼Ã¶Â¿Ã¸Â½Ãƒ Â¿ÂµÃ…뱸 Â¸Ã…źµ¿ 436-52");
713                         }else if(opt == 2){
714                                 data->str_addr = g_strdup("Samsung Electronics Co. LTD Maetan 3-dong, Suwon Si Yeongtong-gu, Gyeonggi-Do (Seoul 443-742 Korea), Rep of KOREA");
715                         }else{
716                                 char buf[255];
717                                 g_printf("Input freeform address: ");
718                                 fgets(buf, 255, stdin);
719                                 buf[strlen(buf)-1]='\0';
720                                 data->str_addr = g_strdup(buf);
721                         }
722                         g_idle_add((GSourceFunc)idle_position_from_freefromed_address_async, data);
723
724                 }else if(0 == g_strcmp0("9",strOpt) ){
725                         LocationVelocity *vel = NULL;
726                         LocationAccuracy *acc = NULL;
727                         ret = location_get_velocity(location_obj, &vel, &acc);
728                         GetLocationError(str, ret);
729                         g_printf("location_get_velocity: returned value [%s]\n", str);
730                         if (ret == LOCATION_ERROR_NONE) {
731                                 g_printf("time: [%d], speed: [%f], direction: [%f], climb: [%f]\n", vel->timestamp, vel->speed, vel->direction, vel->climb);
732                                 GetAccuracyLevel(str, acc->level);
733                                 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
734                         }
735                         if(vel) location_velocity_free(vel);
736                         if(acc) location_accuracy_free(acc);
737                 } else if(0 == g_strcmp0("10",strOpt) ){
738                         LocationAddress *addr = NULL;
739                         LocationAccuracy *acc = NULL;
740                         ret = location_get_address(location_obj, &addr, &acc);
741                         GetLocationError(str, ret);
742                         g_printf("location_get_address: returned value [%s]\n", str);
743                         if(ret == LOCATION_ERROR_NONE){
744                                 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
745                                         addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
746                                 GetAccuracyLevel(str, acc->level);
747                                 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
748                         }
749                 }else if(0 == g_strcmp0("10a",strOpt) ){
750                         IdleData* data = g_new0(IdleData, 1);
751                         data->obj = location_obj;
752                         data->addr_cb = cb_address;
753                         data->user_data = location_obj;
754                         g_idle_add((GSourceFunc)idle_address_async, data);
755                 }else if(0 == g_strcmp0("11",strOpt) ){
756                         LocationPosition *pos = NULL;
757                         LocationAddress *addr = NULL;
758                         LocationAccuracy *acc = NULL;
759                         g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
760                         g_printf("Select Position: ");
761                         int opt = PromptInt();
762                         if(opt == 0)      pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
763                         else if(opt == 1) pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
764                         else{
765                                 g_printf("Input latitude: ");
766                                 gdouble lat = PromptDB();
767                                 g_printf("Input longitude: ");
768                                 gdouble lon = PromptDB();
769                                 pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
770                         }
771                         ret = location_get_address_from_position(location_obj, pos, &addr, &acc);
772                         GetLocationError(str, ret);
773                         g_printf("location_get_address_from_position: returned value [%s]\n", str);
774                         if(ret == LOCATION_ERROR_NONE){
775                                 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
776                                         addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
777                         }
778                         if(addr) location_address_free(addr);
779                         if(acc) location_accuracy_free(acc);
780                 }else if(0 == g_strcmp0("11a",strOpt) ){
781                         IdleData* data = g_new0(IdleData, 1);
782                         data->obj = location_obj;
783                         data->addr_cb = cb_address;
784                         data->user_data = location_obj;
785
786                         g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
787                         g_printf("Select Position: ");
788                         int opt = PromptInt();
789                         if(opt == 0)       data->pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
790                         else if (opt == 1) data->pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
791                         else {
792                                 g_printf("Input latitude: ");
793                                 gdouble lat = PromptDB();
794                                 g_printf("Input longitude: ");
795                                 gdouble lon = PromptDB();
796                                 data->pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
797                         }
798                         g_idle_add((GSourceFunc)idle_address_from_position_async, data);
799                 }else if(0 == g_strcmp0("12",strOpt) ) {
800
801                         gulong distance;
802                         int ret = 0;
803                         char str[STR_MAX];
804                         LocationPosition pos1, pos2;
805
806                         pos1.latitude = 50.0663222;
807                         pos1.longitude = -5.71475;
808
809                         pos2.latitude = 58.6441;
810                         pos2.longitude = -3.070094;
811
812                         ret = location_get_distance(&pos1, &pos2, &distance);
813                         GetLocationError(str, ret);
814                         if(ret != LOCATION_ERROR_NONE) {
815                                         g_printf("Fail to get position. Error[%s]\n", str);
816                         }
817                         else {
818                                         g_printf("The approximate distance is [%lu]\n", distance);
819                                         g_printf("cf.) It is approximately 969954.114 meter\n");
820                         }
821                 }else if(0 == g_strcmp0("13", strOpt)) {
822                         int method;
823                         char method_str[STR_MAX] = {0, };
824                         char input[8] = {0, };
825                         gboolean is_supported = FALSE;
826
827                         g_printf("0.Hybrid 1.GPS 2.WPS 3.CPS(X) 4.IPS(X) 5.SPS\n");
828                         g_printf("Select Method :");
829                         fgets(input, 8, stdin);
830                         method = atoi(input);
831                         switch(method) {
832                                 case LOCATION_METHOD_HYBRID:
833                                         is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID);
834                                         break;
835
836                                 case LOCATION_METHOD_GPS:
837                                         is_supported = location_is_supported_method(LOCATION_METHOD_GPS);
838                                         break;
839
840                                 case LOCATION_METHOD_WPS:
841                                         is_supported = location_is_supported_method(LOCATION_METHOD_WPS);
842                                         break;
843
844                                 case LOCATION_METHOD_SPS:
845                                         is_supported = location_is_supported_method(LOCATION_METHOD_SPS);
846                                         break;
847
848                                 case LOCATION_METHOD_CPS:
849                                 case LOCATION_METHOD_IPS:
850                                 default:
851                                         break;
852
853                         }
854                         GetMethod(method_str, method);
855
856                         g_printf("Method[%s] is %s.", method_str, is_supported ? "supported" : "not supported");
857
858                 }else if(0 == g_strcmp0("14", strOpt)) {
859                         gboolean is_enabled = FALSE;
860                         is_enabled = location_is_enabled_gps(location_obj);
861                         if(is_enabled == TRUE) g_printf("GPS is turned on");
862                         else g_printf("GPS is turned off");
863                 }else if(0 == g_strcmp0("99", strOpt)) {
864                         int ret = 0;
865                         const *str = "command";
866                         ret = location_send_command(str);
867                         if(ret == 0)
868                                 g_printf("Success to send command[%s]", str);
869                 }else if(0 == g_strcmp0("a1",strOpt)){
870                         if(location_obj && !g_sig_enable) {
871                                 g_sig_enable = g_signal_connect (location_obj, "service-enabled", G_CALLBACK(cb_service_enabled), location_obj);
872                         }
873                 }else if(0 == g_strcmp0("a2",strOpt)){
874                         if(location_obj && !g_sig_disable){
875                                 g_sig_disable = g_signal_connect (location_obj, "service-disabled", G_CALLBACK(cb_service_disabled), location_obj);
876                         }
877                 }else if(0 == g_strcmp0("a3",strOpt)){
878                         if(location_obj && !g_sig_update){
879                                 g_sig_update = g_signal_connect (location_obj, "service-updated", G_CALLBACK(cb_service_updated), location_obj);
880                         }
881                 }else if(0 == g_strcmp0("a4",strOpt)){
882                         if(location_obj && !g_sig_zonein){
883                                 g_sig_zonein = g_signal_connect (location_obj, "zone-in", G_CALLBACK(cb_zone_in), location_obj);
884                         }
885                 }else if(0 == g_strcmp0("a5",strOpt)){
886                         if(location_obj && !g_sig_zoneout){
887                                 g_sig_zoneout = g_signal_connect (location_obj, "zone-out", G_CALLBACK(cb_zone_out), location_obj);
888                         }
889                 }else if(0 == g_strcmp0("b1",strOpt)){
890                         if(location_obj && g_sig_enable) {
891                                 g_signal_handler_disconnect (location_obj, g_sig_enable);
892                                 g_sig_enable = 0;
893                         }
894                 }else if(0 == g_strcmp0("b2",strOpt)){
895                         if(location_obj && g_sig_disable){
896                                 g_signal_handler_disconnect (location_obj, g_sig_disable);
897                                 g_sig_disable = 0;
898                         }
899                 }else if(0 == g_strcmp0("b3",strOpt)){
900                         if(location_obj && g_sig_update){
901                                 g_signal_handler_disconnect (location_obj, g_sig_update);
902                                 g_sig_update = 0;
903                         }
904                 }else if(0 == g_strcmp0("b4",strOpt)){
905                         if(location_obj && g_sig_zonein){
906                                 g_signal_handler_disconnect (location_obj, g_sig_zonein);
907                                 g_sig_zonein = 0;
908                         }
909                 }else if(0 == g_strcmp0("b5",strOpt)){
910                         if(location_obj && g_sig_zoneout){
911                                 g_signal_handler_disconnect (location_obj, g_sig_zoneout);
912                                 g_sig_zoneout = 0;
913                         }
914                 }else if(0 == g_strcmp0("c1",strOpt)){
915                         LocationBoundary* bound = NULL;
916                         int i = 0;
917                         int polygon_count = json_util_get_polygon_count();
918
919                         g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
920                         for(i = 0; i < polygon_count; i++)
921                                 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
922
923                         g_printf("\nSelect Boundary: ");
924                         int opt = PromptInt();
925                         if (opt == 0) {
926                                 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
927                                 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
928                                 bound = location_boundary_new_for_rect (lt, rb);
929                                 location_position_free(rb);
930                                 location_position_free(lt);
931
932                                 location_boundary_add(location_obj, bound);
933
934                         } else if(opt == 1) {
935                                 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
936                                 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
937                                 bound = location_boundary_new_for_rect (lt, rb);
938                                 location_position_free(rb);
939                                 location_position_free(lt);
940
941                                 location_boundary_add(location_obj, bound);
942                         } else if(opt == 2) {
943                                 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
944                                 double radius = 10.0;
945                                 bound = location_boundary_new_for_circle(center, radius);
946
947                                 location_boundary_add(location_obj, bound);
948                         } else if (opt > 2 && opt < 3 + polygon_count) {
949                                 int index;
950                                 int polygon_index = opt - 3;
951                                 bound = json_util_get_polygon_boundary(polygon_index);
952                                 location_boundary_add(location_obj, bound);
953
954                                 LocationPosition * check_pos = NULL;
955                                 gboolean ret = FALSE;
956                                 int count = json_util_get_marker_position_count(polygon_index);
957                                 for(index = 0; index < count; index++) {
958                                         check_pos = json_util_get_marker_position(polygon_index, index);
959
960                                         ret = location_boundary_if_inside(bound, check_pos);
961                                         g_printf("[%s] is [%s] and the test result is [%s]\n", json_util_get_marker_name(polygon_index, index), json_util_result_zone_test(polygon_index, index), ret == TRUE? "inside": "outside");
962                                         location_position_free(check_pos);
963                                 }
964                         } else {
965                                 g_printf("boundary is not set\n");
966                         }
967                         location_boundary_free(bound);
968
969                 }else if(0 == g_strcmp0("c2",strOpt)){
970                         g_printf("Get Boundary\n");
971                         location_boundary_foreach(location_obj, PrintBoundary, NULL);
972
973                 }else if(0 == g_strcmp0("c3",strOpt)){
974                         g_printf("Remove Boundary\n");
975                         LocationBoundary* bound = NULL;
976
977                         int i = 0;
978                         int polygon_count = json_util_get_polygon_count();
979
980                         g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
981                         for(i = 0; i < polygon_count; i++)
982                                 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
983
984                         g_printf("\nSelect Boundary: ");
985                         int opt = PromptInt();
986                         if (opt == 0) {
987                                 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
988                                 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
989                                 bound = location_boundary_new_for_rect (lt, rb);
990                                 location_position_free(rb);
991                                 location_position_free(lt);
992
993                         } else if(opt == 1) {
994                                 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
995                                 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
996                                 bound = location_boundary_new_for_rect (lt, rb);
997                                 location_position_free(rb);
998                                 location_position_free(lt);
999
1000                         } else if(opt == 2) {
1001                                 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
1002                                 double radius = 10.0;
1003                                 bound = location_boundary_new_for_circle(center, radius);
1004                                 location_position_free(center);
1005
1006                         } else if (opt > 2 && opt < 3 + polygon_count) {
1007                                 int polygon_index = opt - 3;
1008                                 bound = json_util_get_polygon_boundary(polygon_index);
1009                         } else {
1010                                 g_printf("Invalid value\n");
1011                         }
1012
1013                         if(bound != NULL) location_boundary_remove(location_obj, bound);
1014
1015                 }else if(0 == g_strcmp0("c4",strOpt)){
1016                         location_boundary_foreach(location_obj, RemoveBoundary, location_obj);
1017                 }else if(0 == g_strcmp0("c5",strOpt)){
1018                         char buf[255];
1019                         g_printf("Input device name: ");
1020                         fgets(buf, 255, stdin);
1021                         buf[strlen(buf)-1]='\0';
1022                         g_object_set(location_obj, "dev-name", buf, NULL);
1023                 } else if (0 == g_strcmp0("c6", strOpt)) {
1024                         guint interval = 1;
1025                         g_printf("Input interval[1~120]:");
1026                         scanf("%u", &interval);
1027                         g_printf("changed interval to [%u]\n", interval);
1028                         g_object_set(location_obj, "update-interval", interval, NULL);
1029                 }else if(0 == g_strcmp0("q",strOpt) ){
1030                         g_main_loop_quit(g_mainloop);
1031                         break;
1032                 }
1033         }
1034         g_thread_join(g_main);
1035         g_printf("\n--- Exit LBS Test App ---\n");
1036         return 1;
1037 }