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