Fix internal bug and change the design of ico-app-samplenavi
[profile/ivi/ico-uxf-homescreen-sample-apps.git] / src / samplenavi.c
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the 
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   sample navigation application main
11  *
12  * @date    Apr-25-2013
13  */
14
15 #include "define.h"
16 #include <stdio.h>
17 #include <stdbool.h>
18 #include <time.h>
19 #include <stddef.h>
20 #include <getopt.h>
21 #include <dbus/dbus.h>
22 #include <libwebsockets.h>
23 #include <EWebKit2.h>
24 #include <Eina.h>
25 #include <Ecore.h>
26 #include <Ecore_Evas.h>
27 #include <Elementary.h>
28 #include "samplenavi.h"
29 #include "e3d.h"
30 #include "ico_apf.h"
31 #include "ico_apf_ecore.h"
32 #include "ico_apf_log.h"
33
34 #ifdef _USE_OPENCV_
35 #include <highgui.h>
36 #endif
37
38 /* DEBUG.s */
39 //#define TEST_TIME 0.001
40 //#define TEST_TIME 0.066
41 #define TEST_TIME 0.5
42
43 //#define DEBUG_METER_TEXT_DSP
44
45 //#define DEBUG_VIC_INFO_SET
46 #ifdef DEBUG_VIC_INFO_SET
47 #include <math.h>
48 extern int route_data_count;
49 extern CsvRoute csv_route[MAX_ROUTE_POINTS];
50 static double test_lat = 35.47945;
51 static double test_lon = 139.40026;
52 static int test_dir = 0;
53 static int test_cnt = 0;
54 #endif
55 /* DEBUG.e */
56
57 /*============================================================================*/
58 /* Define fixed parameters                                                    */
59 /*============================================================================*/
60 /* AMB */
61 #define CONFIG_FILE    "/opt/apps/org.tizen.ico.app-samplenavi/res/config.txt"
62 #define DBUS_SERVICE   "org.automotive.message.broker"
63 #define DBUS_INTERFACE "org.freedesktop.DBus.Properties"
64 #define DBUS_METHOD    "Get"
65 #define MAX_PARA_NUM   4        /* Lat,Lon,Dir,VicSpeed */
66 #define LATITUDE       0
67 #define LONGITUDE      1
68 #define DIRECTION      2
69 #define VEHICLESPEED   3
70
71 /* Setting screen */
72 #define ICO_APP_BUF_SIZE    (1024)
73
74 /*============================================================================*/
75 /* Define data types                                                          */
76 /*============================================================================*/
77 /* AMB */
78 union VicVal_t
79 {
80     dbus_int32_t i32_val;
81     dbus_int32_t i16_val;
82     dbus_uint32_t u32_val;
83     dbus_uint16_t u16_val;
84     uint8_t byte_val;
85     dbus_bool_t b_val;
86     double d_val;
87     char *s_val;
88 };
89
90 struct vic_data_t
91 {
92     int property;
93     char name[32];
94     char path_name[64];
95     char interface_name[64];
96     char property_name[32];
97 };
98
99 struct vic_key_data_t
100 {
101     int id;
102     char name[32];
103 };
104
105 /*============================================================================*/
106 /* Function prototype for static(internal) functions                          */
107 /*============================================================================*/
108 static double get_time();
109 static void set_default_data();
110 static void load_config_file();
111 static void e_ui_draw();
112 static void e_ui_init();
113 static void e_map_init();
114 static void e_map_draw();
115 #ifdef _USE_OPENCV_
116 static void convert_data_evas_cv(Evas_Object *eo, IplImage *iplimage);
117 static void evas_object_image_from_cv(Evas_Object *eo, const char *filepath);
118 #endif
119 static Eina_Bool _time_interval_navi_cb(void *cam);
120 static Eina_Bool _time_interval_map_renew_cb(void *data);
121 static Eina_Bool callback_listener(void *data);
122 static int callback_http(struct libwebsocket_context *context,
123                          struct libwebsocket *wsi,
124                          enum libwebsocket_callback_reasons reason,
125                          void *user, void *in, size_t len);
126 static bool parse_elementary_value(union VicVal_t *vic_val_p,
127                                    DBusMessageIter *iter);
128 static bool parse_value(union VicVal_t *vic_val_p, DBusMessageIter *iter);
129 static int getAmbDbus(int key, union VicVal_t *vic_val_p);
130 static void getLocationFromAmb();
131 static int get_config();
132 static char *edje_parse_str(void *in, int arg_num);
133 static void event_message(struct libwebsocket *wsi, char *format, ...);
134 static void _touch_up_edje(void *data, Evas *evas, Evas_Object *obj,
135                            void *event_info);
136 static int loading_edje_file(const char *edje_file);
137 static void res_callback(ico_apf_resource_notify_info_t *info,
138                          void *user_data);
139
140 /*============================================================================*/
141 /* Tables and Valiables                                                       */
142 /*============================================================================*/
143 int conf_data[CONF_DATA_MAX];
144 static const char *config_path = RESOURCE_DIR "/samplenavi.conf";
145 static const char *setting_button_path = IMAGES_DIR "/na_bt3_off.png";
146 static const char *goal_text_img_path = IMAGES_DIR "/na_goal_text.png";
147 static const char *default_url =
148     "file:///opt/apps/org.tizen.ico.app-samplenavi/res/Map/map.html";
149
150 /* Screen right */
151 static char sscrntype[32];
152
153 /* Setting screen */
154 static Evas *g_evas;
155 static Evas_Object *g_edje;     /* loaded edje objects */
156 static char edje_str[ICO_APP_BUF_SIZE];
157
158 /* Meter Display */
159 static int ui_vicspeed = 0;
160 static Evas_Object *ui_vicspeed_text;
161 static Evas_Object *ui_meter_l;
162 static Evas_Object *ui_meter_c[10];
163 static Evas_Object *ui_meter_r[10];
164 static int fig_l = 0;
165 static int fig_c = 0;
166 static int fig_r = 0;
167
168 const static char *meter_l_path = {
169     IMAGES_DIR "/Meter/Meters_SpeedNum_1l.png"
170 };
171
172 const static char *meter_c_path[10] = {
173     IMAGES_DIR "/Meter/Meters_SpeedNum_0c.png",
174     IMAGES_DIR "/Meter/Meters_SpeedNum_1c.png",
175     IMAGES_DIR "/Meter/Meters_SpeedNum_2c.png",
176     IMAGES_DIR "/Meter/Meters_SpeedNum_3c.png",
177     IMAGES_DIR "/Meter/Meters_SpeedNum_4c.png",
178     IMAGES_DIR "/Meter/Meters_SpeedNum_5c.png",
179     IMAGES_DIR "/Meter/Meters_SpeedNum_6c.png",
180     IMAGES_DIR "/Meter/Meters_SpeedNum_7c.png",
181     IMAGES_DIR "/Meter/Meters_SpeedNum_8c.png",
182     IMAGES_DIR "/Meter/Meters_SpeedNum_9c.png"
183 };
184
185 const static char *meter_r_path[10] = {
186     IMAGES_DIR "/Meter/Meters_SpeedNum_0r.png",
187     IMAGES_DIR "/Meter/Meters_SpeedNum_1r.png",
188     IMAGES_DIR "/Meter/Meters_SpeedNum_2r.png",
189     IMAGES_DIR "/Meter/Meters_SpeedNum_3r.png",
190     IMAGES_DIR "/Meter/Meters_SpeedNum_4r.png",
191     IMAGES_DIR "/Meter/Meters_SpeedNum_5r.png",
192     IMAGES_DIR "/Meter/Meters_SpeedNum_6r.png",
193     IMAGES_DIR "/Meter/Meters_SpeedNum_7r.png",
194     IMAGES_DIR "/Meter/Meters_SpeedNum_8r.png",
195     IMAGES_DIR "/Meter/Meters_SpeedNum_9r.png"
196 };
197
198 /* AMB */
199 static DBusConnection *g_connection = NULL;     /* D-Bus Connection */
200 static int property_num = 0;
201 const static char Bus_name[] = DBUS_SERVICE;
202 static struct vic_data_t vic_data[MAX_PARA_NUM];
203
204 const struct vic_key_data_t vic_key_data[] = {
205     {LATITUDE    , "Latitude"    },
206     {LONGITUDE   , "Longitude"   },
207     {DIRECTION   , "Direction"   },
208     {VEHICLESPEED, "VehicleSpeed"},
209     {-1          , "END"         }
210 };
211
212 /* BASE */
213 static Ecore_Evas *window;
214 static Evas *e_cam;
215 static Evas *e_3d;
216 static Evas *e_ui;
217 static Evas *e_map;
218
219 #ifdef _USE_OPENCV_
220 IplImage *captureImage;
221 static CvCapture *capture;
222 #endif
223
224 Evas_Object *cam;
225
226 Evas_Object *ui_bg;
227 Evas_Object *ui_btn;
228 Evas_Object *ui_goal_text;
229 Evas_Object *ui_address;
230
231 #ifdef _SHOW_FPS_
232 Evas_Object *ui_fps;
233 Evas_Object *ui_fps_bg;
234 Evas_Object *ui_polygon_count;
235 Evas_Object *ui_polygon_count_bg;
236 double fps;
237 #endif
238
239 Evas_Object *browser;
240
241 /* CAMERA */
242 static const char *test_camera_path = IMAGES_DIR "/test_cameraview.png";
243
244 /* WEBSOCKET */
245 static int connected = 0;
246 static struct libwebsocket *socket_val = NULL;
247 static struct libwebsocket_context *context;
248 static struct libwebsocket_protocols protocols[] = {
249     {
250      "http-only",          /* name */
251      callback_http,        /* callback */
252      0                     /* per_session_data_size */
253      },
254     {
255      NULL, NULL, 0}
256 };
257
258 static int port = 50414;
259 static char addr[16] = "127.0.0.1";
260 static char proxy_uri[512] = "";
261
262 /*============================================================================*/
263 /* functions                                                                  */
264 /*============================================================================*/
265 /*--------------------------------------------------------------------------*/
266 /*
267  * @brief   get_time
268  *          Time acquisition(second).
269  *
270  * @param       none
271  * @return      time(second)
272  */
273 /*--------------------------------------------------------------------------*/
274 static double get_time()
275 {
276     struct timeval sec_timeofday;
277     gettimeofday(&sec_timeofday, NULL);
278     return ((sec_timeofday.tv_sec) + (sec_timeofday.tv_usec / 1000000.0));
279 }
280
281 /*--------------------------------------------------------------------------*/
282 /*
283  * @brief   set_default_data
284  *          Set Default data without define in conf file.
285  *
286  * @param       none
287  * @return      none
288  */
289 /*--------------------------------------------------------------------------*/
290 static void set_default_data()
291 {
292     int i;
293
294     for (i = 0; i < CONF_DATA_MAX; i++) {
295         if (conf_data[i] == 0) {
296             switch (i) {
297             case USB_CAMERA_ID:
298                 conf_data[USB_CAMERA_ID] = DEF_USB_CAMERA_ID;
299                 break;
300             case LANDMARK_POSITION:
301                 conf_data[LANDMARK_POSITION] = DEF_LANDMARK_POSITION;
302                 break;
303             case LANDMARK_ROTATION:
304                 conf_data[LANDMARK_ROTATION] = DEF_LANDMARK_ROTATION;
305                 break;
306             }
307         }
308     }
309 }
310
311 /*--------------------------------------------------------------------------*/
312 /*
313  * @brief   load_config_file
314  *          A config file is loaded.
315  *
316  * @param       none
317  * @return      none
318  */
319 /*--------------------------------------------------------------------------*/
320 static void load_config_file()
321 {
322     FILE *fp;
323     char str[512];
324     char *valuestr;
325     int i = 0;
326
327     for (i = 0; i < CONF_DATA_MAX; i++) {
328         conf_data[i] = 0;
329     }
330
331     if ((fp = fopen(config_path, "r")) == NULL) {
332         fprintf(stderr, "%s\n",
333                 "Error : can't open file.(samplenavi.conf)\n");
334         set_default_data();
335
336         uim_debug("USB_CAMERA_ID = %d", conf_data[USB_CAMERA_ID]);
337         uim_debug("LANDMARK_POSITION = %d", conf_data[LANDMARK_POSITION]);
338         uim_debug("LANDMARK_ROTATION = %d", conf_data[LANDMARK_ROTATION]);
339         return;
340     }
341
342     while (fscanf(fp, "%s", str) != EOF) {
343         if (strncmp(str, "USBCAMERAID", 11) == 0) {
344             valuestr = strtok((char *) (str) + 12, "=");
345             if (valuestr != NULL) {
346                 conf_data[USB_CAMERA_ID] = atoi(valuestr);
347             }
348         }
349         else if (strncmp(str, "LANDMARKPOSITION", 16) == 0) {
350             valuestr = strtok((char *) (str) + 17, "=");
351             if (valuestr != NULL) {
352                 conf_data[LANDMARK_POSITION] = atoi(valuestr);
353             }
354         }
355         else if (strncmp(str, "LANDMARKROTATION", 16) == 0) {
356             valuestr = strtok((char *) (str) + 17, "=");
357             if (valuestr != NULL) {
358                 conf_data[LANDMARK_ROTATION] = atoi(valuestr);
359             }
360         }
361         else if (strncmp(str, "WEBSOCKETPORT", 13) == 0) {
362             valuestr = strtok((char *) (str) + 14, "=");
363             if (valuestr != NULL) {
364                 port = atoi(valuestr);
365             }
366         }
367         else if (strncmp(str, "IPADDR", 6) == 0) {
368             valuestr = strtok((char *) (str) + 7, "=");
369             if (valuestr != NULL) {
370                 strcpy(addr, valuestr);
371             }
372         }
373         else if (strncmp(str, "PROXYURI", 8) == 0) {
374             valuestr = strtok((char *) (str) + 9, "=");
375             if (valuestr != NULL) {
376                 strcpy(proxy_uri, valuestr);
377             }
378         }
379     }
380
381     fclose(fp);
382
383     set_default_data();
384
385     uim_debug("USB_CAMERA_ID = %d", conf_data[USB_CAMERA_ID]);
386     uim_debug("LANDMARK_POSITION = %d", conf_data[LANDMARK_POSITION]);
387     uim_debug("LANDMARK_ROTATION = %d", conf_data[LANDMARK_ROTATION]);
388     uim_debug("WEBSOKET_PORT  = %d", port);
389     uim_debug("IP_ADDR = %s", addr);
390     uim_debug("PROXY_URI = %s", proxy_uri);
391
392     return;
393 }
394
395 /*--------------------------------------------------------------------------*/
396 /*
397  * @brief   e_ui_draw
398  *          Draw UI Layer.
399  *
400  * @param       none
401  * @return      none
402  */
403 /*--------------------------------------------------------------------------*/
404 static void e_ui_draw()
405 {
406 #ifdef _SHOW_FPS_
407     char str[15];
408 #endif
409
410     int value = 0;
411     int w_fig_r = 0;
412     int w_fig_c = 0;
413     int w_fig_l = 0;
414
415     evas_object_show(ui_bg);
416     evas_object_show(ui_btn);
417
418     /* Meter */
419 #ifdef DEBUG_METER_TEXT_DSP
420     sprintf(str, "[kph]  %d", ui_vicspeed);
421     evas_object_text_text_set(ui_vicspeed_text, str);
422     evas_object_show(ui_vicspeed_text);
423 #else
424     evas_object_show(ui_vicspeed_text);
425     value = ui_vicspeed;
426     if (value > 199) {
427         uim_debug("MAX SPEED OVER [%d]", value);
428         value = 199;
429     }
430
431     w_fig_r = (value % 10);
432     value /= 10;
433     w_fig_c = (value % 10);
434     value /= 10;
435     w_fig_l = (value % 10);
436     value /= 10;
437
438     if (w_fig_r != fig_r) {
439         evas_object_hide(ui_meter_r[fig_r]);
440         evas_object_show(ui_meter_r[w_fig_r]);
441         fig_r = w_fig_r;
442     }
443
444     if (w_fig_c != fig_c || fig_c == 0) {
445         evas_object_hide(ui_meter_c[fig_c]);
446
447         if (w_fig_c != 0 || w_fig_l == 1) {
448             evas_object_show(ui_meter_c[w_fig_c]);
449         }
450
451         fig_c = w_fig_c;
452     }
453
454     if (w_fig_l != fig_l) {
455         evas_object_hide(ui_meter_l);
456
457         if (w_fig_l != 0) {
458             evas_object_show(ui_meter_l);
459         }
460
461         fig_l = w_fig_l;
462     }
463 #endif
464
465     if (enable_navi == TRUE && set_route == TRUE) {
466         if (goal_square_length <= (GOAL_MESSAGE_LENGTH * GOAL_MESSAGE_LENGTH)) {
467             evas_object_show(ui_goal_text);
468         }
469         else {
470             evas_object_hide(ui_goal_text);
471         }
472     }
473
474 #ifdef _SHOW_FPS_
475     sprintf(str, "FPS : %.2f", fps);
476     evas_object_text_text_set(ui_fps, str);
477     sprintf(str, "Polygon : %d", polygon_count);
478     evas_object_text_text_set(ui_polygon_count, str);
479 #endif
480 }
481
482 /*--------------------------------------------------------------------------*/
483 /*
484  * @brief   e_ui_init
485  *          Initialize UI Layer.
486  *
487  * @param       none
488  * @return      none
489  */
490 /*--------------------------------------------------------------------------*/
491 static void e_ui_init()
492 {
493 #ifdef _SHOW_FPS_
494     char str[15];
495 #endif
496     int i = 0;
497
498     ui_bg = evas_object_rectangle_add(e_ui);
499     evas_object_color_set(ui_bg, 0, 34, 119, 255);
500     evas_object_move(ui_bg, W_TEXTAREA_X, W_TEXTAREA_Y);
501     evas_object_resize(ui_bg, W_TEXTAREA_WIDTH, W_TEXTAREA_HEIGHT);
502     evas_object_show(ui_bg);
503     evas_object_layer_set(ui_bg, LAYER_UI);
504
505     ui_btn = evas_object_image_add(e_ui);
506     evas_object_image_file_set(ui_btn, setting_button_path, NULL);
507     evas_object_image_fill_set(ui_btn, 0, 0, W_NAVIBUTTON_WIDTH,
508                                W_NAVIBUTTON_HEIGHT);
509     evas_object_move(ui_btn, W_NAVIBUTTON_X, W_NAVIBUTTON_Y);
510     evas_object_resize(ui_btn, W_NAVIBUTTON_WIDTH, W_NAVIBUTTON_HEIGHT);
511     evas_object_show(ui_btn);
512     evas_object_layer_set(ui_btn, LAYER_UI);
513
514     ui_goal_text = evas_object_image_add(e_ui);
515     evas_object_image_file_set(ui_goal_text, goal_text_img_path, NULL);
516     evas_object_image_fill_set(ui_goal_text, 0, 0, W_GOALMESSAGE_WIDTH,
517                                W_GOALMESSAGE_HEIGHT);
518     evas_object_move(ui_goal_text, W_GOALMESSAGE_X, W_GOALMESSAGE_Y);
519     evas_object_resize(ui_goal_text, W_GOALMESSAGE_WIDTH,
520                        W_GOALMESSAGE_HEIGHT);
521     evas_object_hide(ui_goal_text);
522     evas_object_layer_set(ui_goal_text, LAYER_UI);
523
524     /* Meter */
525 #ifdef DEBUG_METER_TEXT_DSP
526     ui_vicspeed_text = evas_object_text_add(e_ui);
527     evas_object_text_style_set(ui_vicspeed_text, EVAS_TEXT_STYLE_PLAIN);
528     evas_object_color_set(ui_vicspeed_text, 255, 255, 255, 255);
529     evas_object_text_font_set(ui_vicspeed_text, "Utopia", 28);
530     sprintf(str, "[kph]  %d", ui_vicspeed);
531     evas_object_text_text_set(ui_vicspeed_text, str);
532     evas_object_move(ui_vicspeed_text, 0, 430);
533     evas_object_resize(ui_vicspeed_text, W_METER_UNIT_WIDTH,
534                        W_METER_UNIT_HEIGHT);
535     evas_object_show(ui_vicspeed_text);
536     evas_object_layer_set(ui_vicspeed_text, LAYER_UI);
537 #else
538     ui_meter_l = evas_object_image_add(e_ui);
539     evas_object_image_file_set(ui_meter_l, meter_l_path, NULL);
540     evas_object_image_fill_set(ui_meter_l, 0, 0, W_METER_HEIGHT,
541                                W_METER_WIDTH);
542     evas_object_move(ui_meter_l, W_METER_X, W_METER_Y);
543     evas_object_resize(ui_meter_l, W_METER_HEIGHT, W_METER_WIDTH);
544     evas_object_hide(ui_meter_l);
545     evas_object_layer_set(ui_meter_l, LAYER_UI);
546
547     for (i = 0; i < 10; i++) {
548         ui_meter_c[i] = evas_object_image_add(e_ui);
549         evas_object_image_file_set(ui_meter_c[i], meter_c_path[i], NULL);
550         evas_object_image_fill_set(ui_meter_c[i], 0, 0, W_METER_HEIGHT,
551                                    W_METER_WIDTH);
552         evas_object_move(ui_meter_c[i], W_METER_X, W_METER_Y);
553         evas_object_resize(ui_meter_c[i], W_METER_HEIGHT, W_METER_WIDTH);
554         evas_object_hide(ui_meter_c[i]);
555         evas_object_layer_set(ui_meter_c[i], LAYER_UI);
556
557         ui_meter_r[i] = evas_object_image_add(e_ui);
558         evas_object_image_file_set(ui_meter_r[i], meter_r_path[i], NULL);
559         evas_object_image_fill_set(ui_meter_r[i], 0, 0, W_METER_HEIGHT,
560                                    W_METER_WIDTH);
561         evas_object_move(ui_meter_r[i], W_METER_X, W_METER_Y);
562         evas_object_resize(ui_meter_r[i], W_METER_HEIGHT, W_METER_WIDTH);
563         evas_object_hide(ui_meter_r[i]);
564         evas_object_layer_set(ui_meter_r[i], LAYER_UI);
565     }
566     evas_object_show(ui_meter_r[0]);
567
568     ui_vicspeed_text = evas_object_text_add(e_ui);
569     evas_object_text_style_set(ui_vicspeed_text, EVAS_TEXT_STYLE_PLAIN);
570     evas_object_color_set(ui_vicspeed_text, 255, 255, 255, 255);
571     evas_object_text_font_set(ui_vicspeed_text, "Utopia", 24);
572     evas_object_text_text_set(ui_vicspeed_text, "kph");
573     evas_object_move(ui_vicspeed_text, W_METER_UNIT_X, W_METER_UNIT_Y);
574     evas_object_resize(ui_vicspeed_text, W_METER_UNIT_WIDTH,
575                        W_METER_UNIT_HEIGHT);
576     evas_object_show(ui_vicspeed_text);
577
578     evas_object_layer_set(ui_vicspeed_text, LAYER_UI);
579 #endif
580
581 #ifdef _SHOW_FPS_
582     sprintf(str, "FPS : %.2f", fps);
583
584     ui_fps_bg = evas_object_rectangle_add(e_ui);
585     evas_object_color_set(ui_fps_bg, 255, 255, 255, 255);
586     evas_object_move(ui_fps_bg, 0, 0);
587     evas_object_resize(ui_fps_bg, 150, 20);
588     evas_object_show(ui_fps_bg);
589     evas_object_layer_set(ui_fps_bg, LAYER_UI);
590
591     ui_fps = evas_object_text_add(e_ui);
592     evas_object_text_style_set(ui_fps, EVAS_TEXT_STYLE_PLAIN);
593     evas_object_color_set(ui_fps, 0, 0, 0, 255);
594     evas_object_text_font_set(ui_fps, "Utopia", 14);
595     evas_object_text_text_set(ui_fps, str);
596     evas_object_move(ui_fps, 0, 0);
597     evas_object_resize(ui_fps, 250, 250);
598     evas_object_show(ui_fps);
599     evas_object_layer_set(ui_fps, LAYER_UI);
600
601     sprintf(str, "Polygon : %d", polygon_count);
602
603     ui_polygon_count_bg = evas_object_rectangle_add(e_ui);
604     evas_object_color_set(ui_polygon_count_bg, 255, 255, 255, 255);
605     evas_object_move(ui_polygon_count_bg, 0, 20);
606     evas_object_resize(ui_polygon_count_bg, 150, 20);
607     evas_object_show(ui_polygon_count_bg);
608     evas_object_layer_set(ui_polygon_count_bg, LAYER_UI);
609
610     ui_polygon_count = evas_object_text_add(e_ui);
611     evas_object_text_style_set(ui_polygon_count, EVAS_TEXT_STYLE_PLAIN);
612     evas_object_color_set(ui_polygon_count, 0, 0, 0, 255);
613     evas_object_text_font_set(ui_polygon_count, "Utopia", 14);
614     evas_object_text_text_set(ui_polygon_count, str);
615     evas_object_move(ui_polygon_count, 0, 20);
616     evas_object_resize(ui_polygon_count, 250, 250);
617     evas_object_show(ui_polygon_count);
618     evas_object_layer_set(ui_polygon_count, LAYER_UI);
619 #endif
620 }
621
622 /*--------------------------------------------------------------------------*/
623 /*
624  * @brief   e_map_init
625  *          Initialize MAP Layer.
626  *
627  * @param       none
628  * @return      none
629  */
630 /*--------------------------------------------------------------------------*/
631 static void e_map_init()
632 {
633     e_map = ecore_evas_get(window);
634     browser = ewk_view_add(e_map);
635     ewk_context_proxy_uri_set(ewk_view_context_get(browser), proxy_uri);
636     evas_object_move(browser, W_MAP_ORIGINE_X, W_MAP_ORIGINE_Y);
637     evas_object_resize(browser, W_MAP_WIDTH, W_MAP_HEIGHT);
638     evas_object_show(browser);
639     ewk_view_uri_set(browser, default_url);
640     evas_object_layer_set(browser, LAYER_MAP);
641 }
642
643 /*--------------------------------------------------------------------------*/
644 /*
645  * @brief   e_map_draw
646  *          Draw Map Layer(EWebKit2)
647  *
648  * @param       none
649  * @return      none
650  */
651 /*--------------------------------------------------------------------------*/
652 static void e_map_draw()
653 {
654     evas_object_show(browser);
655 }
656
657 #ifdef _USE_OPENCV_
658 /*--------------------------------------------------------------------------*/
659 /*
660  * @brief   convert_data_evas_cv
661  *          Convert IplImage object to Evas_Object.
662  *
663  * @param[out]  eo              Evas_Object 
664  * @param[in]   iplimagenone    IplImage object
665  * @return      none
666  */
667 /*--------------------------------------------------------------------------*/
668 static void convert_data_evas_cv(Evas_Object *eo, IplImage *iplimage)
669 {
670     int image_data_size = (iplimage->width) * iplimage->height * 4;
671     unsigned char image[image_data_size];
672     int i = 0;
673
674     if (image_data_size == 0) {
675         uim_debug("convert_data_evas_cv: IplImage empty error.");
676         return;
677     }
678
679     for (i = 0; i < (iplimage->width * iplimage->height); i++) {
680         image[i * 4] = iplimage->imageData[(3 * i)];
681         image[(i * 4) + 1] = iplimage->imageData[(3 * i) + 1];
682         image[(i * 4) + 2] = iplimage->imageData[(3 * i) + 2];
683         image[(i * 4) + 3] = 255;
684     }
685
686     /* convert to Evas_Object */
687     evas_object_image_colorspace_set(eo, EVAS_COLORSPACE_ARGB8888);
688     evas_object_image_size_set(eo, iplimage->width, iplimage->height);
689     evas_object_image_data_set(eo, image);
690 }
691
692 /*--------------------------------------------------------------------------*/
693 /*
694  * @brief   evas_object_image_from_cv
695  *          Load the picture to an IplImage object. 
696  *
697  * @param[out]  eo          Evas_Object 
698  * @param[in]   filepath    path of the file
699  * @return      none
700  */
701 /*--------------------------------------------------------------------------*/
702 static void evas_object_image_from_cv(Evas_Object *eo, const char *filepath)
703 {
704     IplImage *iplimage;
705
706     /* load picture */
707     iplimage = cvLoadImage(filepath, CV_LOAD_IMAGE_COLOR);
708     if (iplimage == 0) {
709         uim_debug("cvLoadImageError.");
710     }
711
712     convert_data_evas_cv(eo, iplimage);
713 }
714 #endif
715
716 /*--------------------------------------------------------------------------*/
717 /*
718  * @brief   _time_interval_navi_cb
719  *          main timer for navigation. 
720  *
721  * @param[out]  cam    Evas_Object 
722  * @return      result
723  * @retval      ECORE_CALLBACK_RENEW    Return value to keep a callback
724  * @retval      ECORE_CALLBACK_CANCEL   Return value to remove a callback
725  */
726 /*--------------------------------------------------------------------------*/
727 static Eina_Bool _time_interval_navi_cb(void *cam)
728 {
729     static double webcam_timer = 0;
730
731     /* for calc fps */
732 #ifdef _SHOW_FPS_
733     static double total_frame_time = 0;
734     static int frame_count = 0;
735     static double t0;
736     double t1;
737 #endif
738
739 #ifdef _USE_CAMERA_
740     webcam_timer += TIME_INTERVAL_AR;
741
742     if (webcam_timer >= TIME_INTERVAL_CAMERA) {
743         webcam_timer = 0;
744
745         /* Capture from Camera */
746         cam = evas_object_image_add(e_cam);
747
748         captureImage = cvQueryFrame(capture);
749         convert_data_evas_cv(cam, captureImage);
750
751         evas_object_image_fill_set(cam, 0, 0, W_WIDTH, W_NAVI_HEIGHT);
752         evas_object_move(cam, W_NAVI_ORIGINE_X, W_NAVI_ORIGINE_Y);
753         evas_object_resize(cam, W_WIDTH, W_NAVI_HEIGHT);
754         evas_object_show(cam);
755     }
756 #else
757     evas_object_image_fill_set(cam, 0, 0, W_NAVI_WIDTH, W_NAVI_HEIGHT);
758     evas_object_move(cam, W_NAVI_ORIGINE_X, W_NAVI_ORIGINE_Y);
759     evas_object_resize(cam, W_NAVI_WIDTH, W_NAVI_HEIGHT);
760     evas_object_show(cam);
761 #endif
762
763     getLocationFromAmb();
764
765     calc_camera_coord();
766
767     /* render 3D view */
768     draw_route(e_3d);
769     draw_landmark(e_3d);
770
771     /* render UI view */
772     e_ui_draw();
773
774     /* render Map View */
775     e_map_draw();
776
777 #ifdef _SHOW_FPS_
778     // Moving Average
779     if (frame_count == 0) {
780         t0 = get_time();
781         frame_count++;
782     }
783     else if (frame_count < 5) {
784         t1 = get_time();
785         total_frame_time += t1 - t0;
786         t0 = t1;
787         frame_count++;
788     }
789     else {
790         t1 = get_time();
791         total_frame_time -= total_frame_time / 4;
792         total_frame_time += t1 - t0;
793         t0 = t1;
794
795         fps = 4.0 * 1.0 / total_frame_time;
796
797     }
798 #endif
799
800     return ECORE_CALLBACK_RENEW;
801 }
802
803 /*--------------------------------------------------------------------------*/
804 /*
805  * @brief   _time_interval_map_renew_cb
806  *          timer for renewal of a map.
807  *
808  * @param[out]  data    user data(UNUSED) 
809  * @return      result
810  * @retval      ECORE_CALLBACK_RENEW    Return value to keep a callback
811  * @retval      ECORE_CALLBACK_CANCEL   Return value to remove a callback
812  */
813 /*--------------------------------------------------------------------------*/
814 static Eina_Bool _time_interval_map_renew_cb(void *data)
815 {
816 /* DEBUG.s */
817 #ifdef DEBUG_VIC_INFO_SET
818 double lat_tmp = 0;
819 double lon_tmp = 0;
820 int add_angle = 0;
821
822 if (test_cnt < route_data_count) {
823     test_lat = csv_route[test_cnt].lat;
824     test_lon = csv_route[test_cnt].lon;
825
826     if ((test_cnt + 1) != route_data_count) {
827         lat_tmp = csv_route[test_cnt + 1].lat - test_lat;
828         lon_tmp = csv_route[test_cnt + 1].lon - test_lon;
829
830         if (lat_tmp >= 0 && lon_tmp >= 0) {
831             add_angle = 0;
832             test_dir =
833                 atan((fabs(lon_tmp) / fabs(lat_tmp))) * 180.0 / (atan(1.0) *
834                                                                  4.0);
835         }
836         else if (lat_tmp < 0 && lon_tmp >= 0) {
837             add_angle = 90;
838             test_dir =
839                 atan((fabs(lat_tmp) / fabs(lon_tmp))) * 180.0 / (atan(1.0) *
840                                                                  4.0);
841         }
842         else if (lat_tmp < 0 && lon_tmp < 0) {
843             add_angle = 180;
844             test_dir =
845                 atan((fabs(lon_tmp) / fabs(lat_tmp))) * 180.0 / (atan(1.0) *
846                                                                  4.0);
847         }
848         else if (lat_tmp >= 0 && lon_tmp < 0) {
849             add_angle = 270;
850             test_dir =
851                 atan((fabs(lat_tmp) / fabs(lon_tmp))) * 180.0 / (atan(1.0) *
852                                                                  4.0);
853         }
854         test_dir = test_dir + add_angle;
855     }
856     camera_geocode.lat = test_lat;
857     camera_geocode.lon = test_lon;
858     camera_geocode.dir = test_dir;
859     test_cnt++;
860
861     uim_debug("test_lat = [%f]", test_lat);
862     uim_debug("test_lon = [%f]", test_lon);
863     uim_debug("test_dir = [%d]", test_dir);
864 }
865 #endif
866 /* DEBUG.e */
867
868     if ((socket_val)
869         && ((map_pos.lat != camera_geocode.lat)
870             || (map_pos.lon != camera_geocode.lon))) {
871         map_pos.lat = camera_geocode.lat;
872         map_pos.lon = camera_geocode.lon;
873
874         uim_debug("map_pos.lat = [%f]", map_pos.lat);
875         uim_debug("map_pos.lon = [%f]", map_pos.lon);
876
877         event_message(socket_val, "CHG VAL VIC_INFO LAT %f LON %f",
878                       map_pos.lat, map_pos.lon);
879         uim_debug("SEND LAT LON TO SINARIO(samplenavi)");
880     }
881
882     return ECORE_CALLBACK_RENEW;
883 }
884
885 /*--------------------------------------------------------------------------*/
886 /*
887  * @brief   callback_listener
888  *          timer for libwebsocket connection surveillance.
889  *
890  * @param[out]  data    libwebsocket context 
891  * @return      result
892  * @retval      ECORE_CALLBACK_RENEW    Return value to keep a callback
893  * @retval      ECORE_CALLBACK_CANCEL   Return value to remove a callback
894  */
895 /*--------------------------------------------------------------------------*/
896 static Eina_Bool callback_listener(void *data)
897 {
898     if (connected) {
899         libwebsocket_service((struct libwebsocket_context *) data, 0);
900     }
901     else {
902         uim_debug("WEBSOCKET CONNECTED ERROR");
903         if (context != NULL) {
904             libwebsocket_context_destroy(context);
905         }
906         /* Server */
907         context = libwebsocket_create_context(port, NULL,
908                                               protocols,
909                                               libwebsocket_internal_extensions,
910                                               NULL, NULL, -1, -1, 0);
911
912         if (context == NULL) {
913             uim_debug("libwebsocket_create_context failed. (line:%d)",
914                       __LINE__);
915             sleep(1);
916             return 0;
917         }
918
919         connected = 1;
920     }
921
922     return ECORE_CALLBACK_RENEW;
923 }
924
925 /*--------------------------------------------------------------------------*/
926 /*
927  * @brief   callback_http
928  *          this callback function is notified from libwebsockets
929  *
930  * @param[in]   context    libwebsocket context 
931  * @param[in]   wsi        libwebsockets management table
932  * @param[in]   reason     event type 
933  * @param[in]   user       intact 
934  * @param[in]   in         receive message 
935  * @param[in]   len        message size[BYTE]
936  * @return      result
937  * @retval      =0         success
938  * @retval      =1         error
939  */
940 /*--------------------------------------------------------------------------*/
941 static int
942 callback_http(struct libwebsocket_context *context, struct libwebsocket *wsi,
943               enum libwebsocket_callback_reasons reason, void *user, void *in,
944               size_t len)
945 {
946     int n = 0;
947     unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 +
948                       LWS_SEND_BUFFER_POST_PADDING];
949     unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
950     char data[512];
951
952     uim_debug("call callback_http! size = %d", len);
953     uim_debug("callback_http REASON %d", reason);
954
955     switch (reason) {
956     case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
957         uim_debug("CONNECTION %x", wsi);
958         break;
959     case LWS_CALLBACK_ESTABLISHED:
960         uim_debug("ESTABLISHED %x", wsi);
961         socket_val = wsi;
962         n = sprintf((char *) p, "%s", "ANS HELLO");
963         break;
964     case LWS_CALLBACK_ADD_POLL_FD:
965         uim_debug("RECIEVE REASON LWS_CALLBACK_ADD_POLL_FD");
966         break;
967     case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED:
968         uim_debug
969             ("RECIEVE REASON LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED");
970         break;
971     case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
972         uim_debug
973             ("RECIEVE REASON LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER");
974         break;
975     case LWS_CALLBACK_CLIENT_ESTABLISHED:
976         uim_debug("RECIEVE REASON LWS_CALLBACK_CLIENT_ESTABLISHED");
977         break;
978     case LWS_CALLBACK_SET_MODE_POLL_FD:
979         uim_debug("RECIEVE REASON LWS_CALLBACK_SET_MODE_POLL_FD");
980         break;
981     case LWS_CALLBACK_CLEAR_MODE_POLL_FD:
982         uim_debug("RECIEVE REASON LWS_CALLBACK_CLEAR_MODE_POLL_FD");
983         break;
984     case LWS_CALLBACK_CLIENT_WRITEABLE:
985         uim_debug("RECIEVE REASON LWS_CALLBACK_CLIENT_WRITEABLE");
986         break;
987     case LWS_CALLBACK_RECEIVE:
988
989         if ((in != NULL)
990             && (strncmp((char *) in, "OPEN", strlen("OPEN")) == 0)) {
991
992             uim_debug("OPEN loading_edje_file [%s]", (char *) in);
993             strncpy(edje_str, edje_parse_str(in, 1), sizeof(edje_str));
994             loading_edje_file(&edje_str[0]);
995             if (socket_val) {
996                 event_message(socket_val, "RESULT SUCCESS");
997                 uim_debug("SEND RESULT SUCCESS");
998             }
999         }
1000         else if ((in != NULL) && (strncmp("CLOSE", in, strlen("CLOSE")) == 0)) {
1001             evas_object_hide(g_edje);
1002             evas_object_del(g_edje);
1003             uim_debug("ONSCREEN CLOSE");
1004         }
1005
1006         /* Get route from navi.js */
1007         if (strncmp((char *) in, "<route>", strlen("<route>")) == 0) {
1008             uim_debug("<route> recv");
1009             init_e3d(e_3d, in, len);
1010             set_route = TRUE;
1011             break;
1012         }
1013
1014         memset(data, 0, sizeof(data));
1015         strncpy(data, (char *) in, len);
1016         uim_debug("RECIEVE[%d] %s", len, data);
1017
1018         if (len == 0) {
1019             uim_debug("ERROR data=null (line:%d)", __LINE__);
1020             break;
1021         }
1022
1023         if (strncmp((char *) data, "CHG SEQ REQ_NAV", 15) == 0) {
1024             uim_debug("RECIEVE COMMAND CHG SEQ REQ_NAV");
1025
1026             enable_navi = TRUE;
1027         }
1028         else if (strncmp((char *) data, "CHG SEQ END_NAV", 15) == 0) {
1029             uim_debug("RECIEVE COMMAND CHG SEQ END_NAV");
1030
1031             enable_navi = FALSE;
1032         }
1033         else if (strncmp((char *) data, "ERR", 3) == 0) {
1034         }
1035         break;
1036     case LWS_CALLBACK_CLIENT_RECEIVE:
1037         memset(data, 0, sizeof(data));
1038         strncpy(data, (char *) in, len);
1039         uim_debug("CLIENT_RECIEVE[%d] %s", len, data);
1040         break;
1041     case LWS_CALLBACK_CLOSED:
1042         uim_debug("RECIEVE REASON LWS_CALLBACK_CLOSED");
1043         connected = 0;
1044         break;
1045     default:
1046         uim_debug("REASON %d", reason);
1047         break;
1048     }
1049
1050     return 0;
1051 }
1052
1053 /*--------------------------------------------------------------------------*/
1054 /*
1055  * @brief   parse_elementary_value
1056  *          The message content received from DBus is acquired. 
1057  *
1058  * @param[out]   vic_val_p    Vehicles information data
1059  * @param[in]    iter         message received from DBus
1060  * @return       result
1061  * @retval       TRUE     success
1062  * @retval       FALSE    error
1063  */
1064 /*--------------------------------------------------------------------------*/
1065 static bool
1066 parse_elementary_value(union VicVal_t *vic_val_p, DBusMessageIter *iter)
1067 {
1068     dbus_int32_t i32_val;
1069     dbus_int32_t i16_val;
1070     dbus_uint32_t u32_val;
1071     dbus_uint16_t u16_val;
1072     uint8_t byte_val;
1073     dbus_bool_t b_val;
1074     double d_val;
1075     char *s_val;
1076     char *w_s_val;
1077
1078     char sig;
1079
1080     if (vic_val_p == NULL || iter == NULL) {
1081         uim_debug("Err Parameter NG ");
1082         return FALSE;
1083     }
1084
1085     sig = dbus_message_iter_get_arg_type(iter);
1086
1087     switch (sig) {
1088     case DBUS_TYPE_INT32:
1089         dbus_message_iter_get_basic(iter, &i32_val);
1090         vic_val_p->i32_val = i32_val;
1091         vic_val_p++;
1092         break;
1093     case DBUS_TYPE_INT16:
1094         dbus_message_iter_get_basic(iter, &i16_val);
1095         vic_val_p->i16_val = i16_val;
1096         vic_val_p++;
1097         break;
1098     case DBUS_TYPE_UINT32:
1099         dbus_message_iter_get_basic(iter, &u32_val);
1100         vic_val_p->u32_val = u32_val;
1101         vic_val_p++;
1102         break;
1103     case DBUS_TYPE_UINT16:
1104         dbus_message_iter_get_basic(iter, &u16_val);
1105         vic_val_p->u16_val = u16_val;
1106         vic_val_p++;
1107         break;
1108     case DBUS_TYPE_BOOLEAN:
1109         dbus_message_iter_get_basic(iter, &b_val);
1110         vic_val_p->b_val = b_val;
1111         vic_val_p++;
1112         break;
1113     case DBUS_TYPE_BYTE:
1114         dbus_message_iter_get_basic(iter, &byte_val);
1115         vic_val_p->byte_val = byte_val;
1116         vic_val_p++;
1117         break;
1118     case DBUS_TYPE_DOUBLE:
1119         dbus_message_iter_get_basic(iter, &d_val);
1120         vic_val_p->d_val = d_val;
1121         vic_val_p++;
1122         break;
1123     case DBUS_TYPE_STRING:
1124 #if 0
1125         dbus_message_iter_get_basic(iter, &s_val);
1126         w_s_val = (char *) malloc(strlen(s_val) + 1);
1127         if (w_s_val == NULL) {
1128             uim_debug("Err malloc");
1129             return FALSE;
1130         }
1131         strncpy(w_s_val, s_val, strlen(s_val));
1132         vic_val_p->s_val = w_s_val;
1133         vic_val_p++;
1134         break;
1135 #endif
1136     default:
1137         uim_debug("Err parse_elementary_value: unknown type");
1138         return FALSE;
1139     }
1140
1141     return TRUE;
1142 }
1143
1144 /*--------------------------------------------------------------------------*/
1145 /*
1146  * @brief   parse_value
1147  *          parse message received from DBus
1148  *
1149  * @param[out]   vic_val_p    Vehicles information data
1150  * @param[in]    iter         message received from DBus
1151  * @return       result
1152  * @retval       TRUE     success
1153  * @retval       FALSE    error
1154  */
1155 /*--------------------------------------------------------------------------*/
1156 static bool parse_value(union VicVal_t *vic_val_p, DBusMessageIter *iter)
1157 {
1158     char curr;
1159
1160     if (vic_val_p == NULL || iter == NULL) {
1161         uim_debug("Err Parameter NG ");
1162         return FALSE;
1163     }
1164
1165     curr = dbus_message_iter_get_arg_type(iter);
1166
1167     switch (curr) {
1168     case DBUS_TYPE_BYTE:
1169     case DBUS_TYPE_BOOLEAN:
1170     case DBUS_TYPE_INT16:
1171     case DBUS_TYPE_INT32:
1172     case DBUS_TYPE_UINT16:
1173     case DBUS_TYPE_UINT32:
1174     case DBUS_TYPE_DOUBLE:
1175     case DBUS_TYPE_STRING:
1176         return parse_elementary_value(vic_val_p, iter);
1177     case DBUS_TYPE_ARRAY:
1178     case DBUS_TYPE_STRUCT:
1179     case DBUS_TYPE_DICT_ENTRY:
1180         return FALSE;
1181     case DBUS_TYPE_INVALID:
1182         return TRUE;
1183     default:
1184         break;
1185     }
1186     return FALSE;
1187 }
1188
1189 /*--------------------------------------------------------------------------*/
1190 /*
1191  * @brief   getAmbDbus
1192  *          Vehicle information is acquired from AMB.(D-Bus)
1193  *
1194  * @param[in]    key          vic_data index
1195  * @param[out]   vic_val_p    Vehicles information data
1196  * @return       result
1197  * @retval       = 0      success
1198  * @retval       =-1      error
1199  */
1200 /*--------------------------------------------------------------------------*/
1201 static int getAmbDbus(int key, union VicVal_t *vic_val_p)
1202 {
1203     /* local variable */
1204     DBusMessage *message;
1205     DBusError error;
1206     int result = 0;
1207     const char *v_string[] = { vic_data[key].interface_name,
1208         vic_data[key].property_name
1209     };
1210     const char *dest = Bus_name;
1211     DBusMessage *reply;
1212     int reply_timeout = 1000;   /* Millisecond */
1213     DBusMessageIter iter;
1214     DBusMessageIter iter_array;
1215     union VicVal_t *tmp_vic_val_p = vic_val_p;
1216
1217     /* initialize */
1218     dbus_error_init(&error);
1219
1220     if (NULL == g_connection) {
1221         /* obtain the right to use dbus */
1222         g_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
1223
1224         if (g_connection == NULL) {
1225             uim_debug("Err dbus_bus_get");
1226
1227             /* Release err parameter */
1228             dbus_error_free(&error);
1229             return -1;
1230         }
1231     }
1232
1233     /* Constructs a new message */
1234     message = dbus_message_new_method_call(DBUS_SERVICE,
1235                                            vic_data[key].path_name,
1236                                            DBUS_INTERFACE, DBUS_METHOD);
1237     if (message == NULL) {
1238         uim_debug("Err dbus_message_new_method_call");
1239
1240         /* Release the connection */
1241         dbus_connection_unref(g_connection);
1242         g_connection = NULL;
1243         return -1;
1244     }
1245
1246     /* Gets the type of a message */
1247     result = dbus_message_append_args(message,
1248                                       DBUS_TYPE_STRING,
1249                                       &v_string[0],
1250                                       DBUS_TYPE_STRING,
1251                                       &v_string[1], DBUS_TYPE_INVALID);
1252
1253     if (!result) {
1254         uim_debug("Err dbus_message_append_args");
1255
1256         /* Release the connection */
1257         dbus_connection_unref(g_connection);
1258         g_connection = NULL;
1259
1260         /* Release the message */
1261         dbus_message_unref(message);
1262
1263         return -1;
1264     }
1265
1266     /* Gets the error name */
1267     if (dest && !dbus_message_set_destination(message, dest)) {
1268         uim_debug("Err dbus_message_new_method_call");
1269
1270         /* Release the connection */
1271         dbus_connection_unref(g_connection);
1272         g_connection = NULL;
1273
1274         /* Release the message */
1275         dbus_message_unref(message);
1276
1277         return -1;
1278     }
1279
1280     /* Queues a message to send */
1281     reply = dbus_connection_send_with_reply_and_block(g_connection,
1282                                                       message,
1283                                                       reply_timeout, &error);
1284     if (reply == NULL) {
1285         uim_debug( "Err dbus_connection_send_with_reply_and_block" );
1286
1287         /* Release the connection */
1288         dbus_connection_unref(g_connection);
1289         g_connection = NULL;
1290
1291         /* Release the message */
1292         dbus_message_unref(message);
1293
1294         /* Release err parameter */
1295         dbus_error_free(&error);
1296
1297         return -1;
1298     }
1299
1300     /* Gets the result */
1301     dbus_message_iter_init(reply, &iter);
1302     dbus_message_iter_recurse(&iter, &iter_array);
1303
1304     /* Type conversion of the resulting value */
1305     result = parse_value(tmp_vic_val_p, &iter_array);
1306     if (result != TRUE) {
1307         uim_debug("Err parse_elementary_value");
1308
1309         /* Release the connection */
1310         dbus_connection_unref(g_connection);
1311         g_connection = NULL;
1312
1313         /* Release the message */
1314         dbus_message_unref(message);
1315         dbus_message_unref(reply);
1316
1317         return -1;
1318     }
1319
1320     /* Release the message */
1321     dbus_message_unref(message);
1322     dbus_message_unref(reply);
1323
1324     return 0;
1325 }
1326
1327 /*--------------------------------------------------------------------------*/
1328 /*
1329  * @brief   getLocationFromAmb
1330  *          Location information acquisition from AMB.
1331  *
1332  * @param    none
1333  * @return   none
1334  */
1335 /*--------------------------------------------------------------------------*/
1336 static void getLocationFromAmb()
1337 {
1338     union VicVal_t vic_val[32];
1339     int result = 0;
1340     int i;
1341
1342     for (i = 0; i < property_num; i++) {
1343         result = getAmbDbus(i, vic_val);
1344
1345         if (result != 0) {
1346             uim_debug("Err getAmbDbus : Unacquired [%s]",vic_data[i].name);
1347             continue;
1348         }
1349
1350         switch (vic_data[i].property) {
1351         case LATITUDE:
1352             if ((camera_geocode.lat != vic_val[0].d_val) &&
1353                 (vic_val[0].d_val != 0)) {
1354                 uim_debug("%s(%f)", vic_data[i].name, vic_val[0].d_val);
1355                 camera_geocode.lat = vic_val[0].d_val;
1356             }
1357             break;
1358         case LONGITUDE:
1359             if ((camera_geocode.lon != vic_val[0].d_val) &&
1360                 (vic_val[0].d_val != 0)) {
1361                 uim_debug("%s(%f)", vic_data[i].name, vic_val[0].d_val);
1362                 camera_geocode.lon = vic_val[0].d_val;
1363             }
1364             break;
1365         case DIRECTION:
1366             if (camera_geocode.dir != vic_val[0].i32_val) {
1367                 uim_debug("%s(%d)", vic_data[i].name, vic_val[0].i32_val);
1368                 camera_geocode.dir = vic_val[0].i32_val;
1369             }
1370             break;
1371         case VEHICLESPEED:
1372             if (ui_vicspeed != vic_val[0].i32_val) {
1373                 uim_debug("%s(%d)", vic_data[i].name, vic_val[0].i32_val);
1374                 ui_vicspeed = vic_val[0].i32_val;
1375             }
1376             break;
1377         default:
1378             uim_debug("ERROR no property : %s", vic_data[i].name);
1379             break;
1380         }
1381     }
1382     return;
1383 }
1384
1385 /*--------------------------------------------------------------------------*/
1386 /*
1387  * @brief   get_config
1388  *          The config file for vehicle information acquisition is read.
1389  *
1390  * @param    none
1391  * @return   result
1392  * @retval   = 0      success
1393  * @retval   =-1      error
1394  */
1395 /*--------------------------------------------------------------------------*/
1396 static int get_config()
1397 {
1398     FILE *fp;
1399     int k = 0;
1400     int j, m;
1401     char buff[512];
1402     char *tp;
1403     char *clm = " \n";
1404
1405     fp = fopen(CONFIG_FILE, "r");
1406     if (fp == NULL) {
1407         uim_debug("File open error");
1408         return -1;
1409     }
1410
1411     for (m = 0; k < MAX_PARA_NUM; m++) {
1412         if (fgets(buff, sizeof(buff) - 2, fp) != NULL) {
1413             tp = strtok(buff, clm);
1414             if (tp != NULL) {
1415                 if (tp[0] != '#') {
1416                     for (j = 0; vic_key_data[j].id != -1; j++) {
1417                         if (strcmp(tp, vic_key_data[j].name) == 0) {
1418                             vic_data[k].property = vic_key_data[j].id;
1419                             strcpy(vic_data[k].name, tp);
1420                             strcpy(vic_data[k].path_name, strtok(NULL, clm));
1421                             strcpy(vic_data[k].interface_name,
1422                                    strtok(NULL, clm));
1423                             strcpy(vic_data[k].property_name,
1424                                    strtok(NULL, clm));
1425
1426                             uim_debug("vic_data[%d].property=%d", k,
1427                                       vic_data[k].property);
1428                             uim_debug("vic_data[%d].name=%s", k,
1429                                       vic_data[k].name);
1430                             uim_debug("vic_data[%d].path_name=%s", k,
1431                                       vic_data[k].path_name);
1432                             uim_debug("vic_data[%d].interface_name=%s", k,
1433                                       vic_data[k].interface_name);
1434                             uim_debug("vic_data[%d].property_name=%s", k,
1435                                       vic_data[k].property_name);
1436                             k++;
1437                             break;
1438                         }
1439                     }
1440                     if (vic_key_data[j].id == -1) {
1441                         uim_debug
1442                             ("Err config.txt Line:%d Unregistered parameter name",
1443                              m + 1);
1444                     }
1445
1446                 }
1447                 else {
1448                     uim_debug("config.txt Line:%d Comment out  '#'Discovery",
1449                               m + 1);
1450                 }
1451             }
1452             else {
1453                 uim_debug("config.txt Line:%d Comment out  Null line", m + 1);
1454             }
1455         }
1456         else {
1457             uim_debug("config.txt The end of data reading");
1458             break;
1459         }
1460     }
1461     fclose(fp);
1462
1463     property_num = k;
1464     if (property_num == 0) {
1465         uim_debug("config.txt No valid data");
1466         return -1;
1467     }
1468
1469     return 0;
1470 }
1471
1472 /*--------------------------------------------------------------------------*/
1473 /*
1474  * @brief   edje_parse_str
1475  *          A character string is decomposed by a delimiter.
1476  *
1477  * @param[in]    key          vic_data index
1478  * @param[in]    vic_val_p    Vehicles information data
1479  * @return       The pointer address to a lexical token
1480  * @retval       > 0      success
1481  * @retval       NULL     error
1482  */
1483 /*--------------------------------------------------------------------------*/
1484 static char *edje_parse_str(void *in, int arg_num)
1485 {
1486     int i;
1487     char *data;
1488
1489     uim_debug("edje_parse_str %s, arg = %d", in, arg_num);
1490     data = strtok(in, " ");
1491     /* arg_num : 0 to n */
1492     for (i = 0; i < arg_num; i++) {
1493         data = strtok(NULL, " ");
1494     }
1495     uim_debug("edje_parse_str data: %s", data);
1496     return data;
1497 }
1498
1499 /*--------------------------------------------------------------------------*/
1500 /**
1501  * @brief   event_message
1502  *          send message
1503  *
1504  * @param[in]   wsi                 libwebsockets management table to send
1505  * @param[in]   fromat              message to send
1506  * @return      none
1507  */
1508 /*--------------------------------------------------------------------------*/
1509 static void event_message(struct libwebsocket *wsi, char *format, ...)
1510 {
1511     va_list list;
1512     char message[256];
1513
1514     va_start(list, format);
1515     vsnprintf(message, sizeof(message), format, list);
1516     va_end(list);
1517
1518     uim_debug("Setting screen: event_message wsi = %p, %s", wsi, message);
1519     if (wsi) {
1520         int n = 0;
1521         unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 +
1522                           LWS_SEND_BUFFER_POST_PADDING];
1523         unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
1524
1525         n = sprintf((char *) p, "%s", message);
1526         n = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
1527         uim_debug("Setting screen: libwebsocket_write return = %d", n);
1528     }
1529     else {
1530         uim_debug("Setting screen: wsi is not initialized");
1531     }
1532
1533     return;
1534 }
1535
1536 /*--------------------------------------------------------------------------*/
1537 /**
1538  * @brief   _touch_up_edje
1539  *          Touch-up event processing.
1540  *
1541  * @param[in]   data                user data
1542  * @param[in]   obj                 evas object of the button
1543  * @param[in]   event_info          evas event infomation
1544  * @return      none
1545  */
1546 /*--------------------------------------------------------------------------*/
1547 static void
1548 _touch_up_edje(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1549 {
1550     /* get name from userdata */
1551     if (data != NULL) {
1552         uim_debug("Setting screen: user data is %s", (const char *) data);
1553
1554         if (socket_val) {
1555             event_message(socket_val, "TOUCH %s %s", edje_str, data);
1556             uim_debug("SEND TOUCH %s ", data);
1557         }
1558     }
1559     else {
1560         uim_debug("Setting screen: user data is NULL");
1561     }
1562 }
1563
1564 /*--------------------------------------------------------------------------*/
1565 /**
1566  * @brief   loading_edje_file
1567  *          Loading of edje file.
1568  *
1569  * @param[in]   edje_file    edje file
1570  * @return      result
1571  * @retval      = 0      success
1572  * @retval      =-1      error
1573  */
1574 /*--------------------------------------------------------------------------*/
1575 static int loading_edje_file(const char *edje_file)
1576 {
1577     Evas_Object *part;          /* part handle */
1578     Eina_List *group;           /* edje group list */
1579     Eina_List *list;            /* part list in edje */
1580     int group_count = 0;        /* group counter */
1581     int name_count = 0;         /* name counter */
1582
1583     g_evas = ecore_evas_get(window);
1584     if (!g_evas) {
1585         uim_debug("Setting screen: could not create evas.");
1586         return -1;
1587     }
1588
1589     /* delete edge */
1590     evas_object_del(g_edje);
1591
1592     /* create and add object in canvas from edje */
1593     g_edje = edje_object_add(g_evas);
1594     if (!g_edje) {
1595         uim_debug("Setting screen: could not create edje object!");
1596         return -1;
1597     }
1598
1599     /* get group list */
1600     group = edje_file_collection_list(edje_file);
1601     while (group != NULL) {
1602         /* Set the edj file */
1603         if (!edje_object_file_set
1604             (g_edje, edje_file, (const char *) group->data)) {
1605             int err = edje_object_load_error_get(g_edje);
1606             const char *errmsg = edje_load_error_str(err);
1607             uim_debug("Setting screen: could not load %s: %s", edje_file,
1608                       errmsg);
1609
1610             edje_file_collection_list_free(group);
1611             evas_object_del(g_edje);
1612             return -1;
1613         }
1614         uim_debug("Setting screen: group[%d] data : %s", group_count,
1615                   (const char *) group->data);
1616
1617         /* get list */
1618         list = edje_object_access_part_list_get(g_edje);
1619         while (list != NULL) {
1620             uim_debug("Setting screen: list[%d] data : %s", name_count,
1621                       (const char *) list->data);
1622
1623             /* set callback for part name */
1624             part =
1625                 edje_object_part_object_get((const Evas_Object *) g_edje,
1626                                             (const char *) list->data);
1627             if (part != NULL) {
1628                 uim_debug("Setting screen: list[%d] name : %s", name_count,
1629                           (const char *) list->data);
1630                 evas_object_event_callback_add(part, EVAS_CALLBACK_MOUSE_UP,
1631                                                _touch_up_edje, list->data);
1632             }
1633             else {
1634                 uim_debug("Setting screen: list[%d] is NULL", name_count);
1635             }
1636
1637             /* to next list */
1638             list = list->next;
1639             name_count++;
1640         }
1641
1642         /* to next group */
1643         group = group->next;
1644         group_count++;
1645     }
1646     uim_debug("Setting screen: group num is %d", group_count);
1647     uim_debug("Setting screen: name num is %d", name_count);
1648
1649     /* Put in the image */
1650     evas_object_move(g_edje, 0, 0);
1651     /* Resize the image */
1652     evas_object_resize(g_edje, W_WIDTH, W_HEIGHT);
1653     /* Show the image */
1654     evas_object_show(g_edje);
1655
1656     evas_object_layer_set(g_edje, LAYER_UI);
1657
1658     return 0;
1659 }
1660
1661 /*--------------------------------------------------------------------------*/
1662 /**
1663  * @brief   res_callback
1664  *          Notice event processing of a resource state.
1665  *
1666  * @param[in]   info                rsource information
1667  * @param[in]   user_data           user data(UNUSED)
1668  * @return      none
1669  */
1670 /*--------------------------------------------------------------------------*/
1671 static void
1672 res_callback(ico_apf_resource_notify_info_t *info, void *user_data)
1673 {
1674     int ret;
1675
1676     uim_debug("##==> Callbacked evt=%d res=%d id=%d bid=%d appid=%s dev=%s"
1677               " user_data=%d", info->state, info->resid, info->id, info->bid,
1678               info->appid, info->device, (int) user_data);
1679
1680     switch (info->state) {
1681     case ICO_APF_RESOURCE_STATE_ACQUIRED:
1682     case ICO_APF_RESOURCE_STATE_DEPRIVED:
1683     case ICO_APF_RESOURCE_STATE_WAITTING:
1684     case ICO_APF_RESOURCE_STATE_RELEASED:
1685         if (info->resid == ICO_APF_RESID_INT_SCREEN) {
1686             ret =
1687                 ico_apf_resource_reply_int_screen_mode(info->device,
1688                                                        info->bid, info->id,
1689                                                        1);
1690             uim_debug("##==> callback reply int_screen(%s,%d,%d,1) = %d",
1691                       info->device, info->bid, info->id, ret);
1692         }
1693         else if (info->resid == ICO_APF_RESID_ON_SCREEN) {
1694             ret =
1695                 ico_apf_resource_reply_int_screen_mode_disp(info->device,
1696                                                             info->id, 1);
1697             uim_debug("##==> callback reply on_screen(%s,%d,1) = %d",
1698                       info->device, info->id, ret);
1699         }
1700         else {
1701             ret =
1702                 ico_apf_resource_reply_screen_mode(info->device, info->id, 1);
1703             uim_debug("##==> callback reply screen(%s,%d,1) = %d",
1704                       info->device, info->id, ret);
1705         }
1706         break;
1707     default:
1708         /* NOP  */
1709         break;
1710     }
1711 }
1712
1713 /*--------------------------------------------------------------------------*/
1714 /*
1715  * @brief   sample navigation application
1716  *          main routine
1717  *
1718  * @param   main() finction's standard parameter (argc,argv)
1719  * @return  result
1720  * @retval  =0       success
1721  * @retval  =-1      failed
1722  */
1723 /*--------------------------------------------------------------------------*/
1724 int main(int argc, char *argv[])
1725 {
1726     int i;
1727     int getscreen;
1728     char appid[ICO_UXF_MAX_PROCESS_NAME + 1];
1729     int ret = 0;
1730     connected = 0;
1731
1732     /* Setting the log output */
1733     if (ico_apf_get_app_id(0, appid) == ICO_APP_CTL_E_NONE) {
1734         ico_apf_log_open(appid);
1735     }
1736
1737     load_config_file();
1738
1739     elm_init(argc, argv);
1740
1741     enable_navi = FALSE;
1742     set_route = FALSE;
1743
1744     /* initialize */
1745     if (0 != get_config()) {
1746         uim_debug("ERROR get_config()");
1747         return -1;
1748     }
1749
1750     getscreen = 0;
1751     sscrntype[0] = 0;
1752     for (i = 1; i < argc; i++) {
1753         if (argv[i][0] == '-') {
1754             if (strcasecmp(argv[i], "-basescreen") == 0) {
1755                 getscreen = 1;  /* get base screen */
1756                 strcpy(sscrntype, "BasicScreen");
1757                 uim_debug("BasicScreen");
1758             }
1759             else if (strcasecmp(argv[i], "-intscreen") == 0) {
1760                 getscreen = 2;  /* get interrupt screen */
1761                 strcpy(sscrntype, "IntScreen");
1762             }
1763             else if (strcasecmp(argv[i], "-onscreen") == 0) {
1764                 getscreen = 3;  /* get on screen */
1765                 strcpy(sscrntype, "OnScreen");
1766             }
1767         }
1768     }
1769
1770     ecore_evas_init();
1771
1772     if (getscreen > 0) {
1773         /* initialize resource control for Ecore */
1774         if (ico_apf_ecore_init(NULL) != ICO_APF_E_NONE) {
1775             uim_debug("ico_apf_ecore_init() Error");
1776             ecore_evas_shutdown();
1777             return -1;
1778         }
1779
1780         /* set resource request callback */
1781         ico_apf_resource_set_event_cb(res_callback, NULL);
1782
1783         /* acquire a right to display a screen */
1784         if (getscreen == 1) {
1785             ret = ico_apf_resource_get_screen_mode(NULL, 0);
1786         }
1787         else if (getscreen == 2) {
1788             ret = ico_apf_resource_get_int_screen_mode(NULL, 0, 0);
1789         }
1790         else {
1791             ret = ico_apf_resource_get_int_screen_mode_disp(NULL, 0);
1792         }
1793     }
1794     uim_debug("getscreen = %d, ret = %d", getscreen, ret);
1795
1796     /* window setup */
1797     window = ecore_evas_new(NULL, 0, 0, W_WIDTH, W_HEIGHT, "frame=0");
1798     if (!window)
1799         goto error;
1800
1801     ecore_evas_show(window);
1802
1803     /* Camera Layer */
1804     e_cam = ecore_evas_get(window);
1805     cam = evas_object_image_add(e_cam);
1806 #ifdef _USE_CAMERA_
1807     capture = cvCreateCameraCapture(conf_data[USB_CAMERA_ID]);
1808     if (!capture) {
1809         uim_debug("cvCaptureFromCAM failed.");
1810         return -1;
1811     }
1812
1813     captureImage = cvQueryFrame(capture);
1814     uim_debug("camera width = %d, height = %d", captureImage->width,
1815               captureImage->height);
1816     convert_data_evas_cv(cam, captureImage);
1817 #else
1818
1819 #ifdef _USE_OPENCV_
1820     evas_object_image_from_cv(cam, test_camera_path);
1821 #else /* _USE_OPENCV_ */
1822     evas_object_image_file_set(cam, test_camera_path, NULL);
1823 #endif /* _USE_OPENCV_ */
1824
1825 #endif
1826
1827     evas_object_image_fill_set(cam, 0, 0, W_NAVI_WIDTH, W_NAVI_HEIGHT);
1828     evas_object_move(cam, W_NAVI_ORIGINE_X, W_NAVI_ORIGINE_Y);
1829     evas_object_resize(cam, W_NAVI_WIDTH, W_NAVI_HEIGHT);
1830     evas_object_show(cam);
1831
1832     /* 3D Layer */
1833     e_3d = ecore_evas_get(window);
1834
1835     /* UI Layer */
1836     e_ui = ecore_evas_get(window);
1837     e_ui_init();
1838
1839     /* Server */
1840     context =
1841         libwebsocket_create_context(port, NULL, protocols,
1842                                     libwebsocket_internal_extensions, NULL,
1843                                     NULL, -1, -1, 0);
1844     if (context == NULL) {
1845         fprintf(stderr, "libwebsocket_create_context failed.");
1846         goto error;
1847     }
1848
1849     connected = 1;
1850     ecore_timer_add(0.05, callback_listener, context);
1851
1852     /* Browser(Map) Layer */
1853     e_map_init();
1854
1855     edje_init();
1856
1857     /* timer */
1858     ecore_timer_add(TIME_INTERVAL_AR, _time_interval_navi_cb, cam);
1859
1860     ecore_timer_add(TEST_TIME, _time_interval_map_renew_cb, NULL);
1861
1862     /* main loop */
1863     ecore_main_loop_begin();
1864
1865     /* cleanup */
1866     e3d_cleanup();
1867
1868 #ifdef _USE_CAMERA_
1869     cvReleaseCapture(&capture);
1870 #endif
1871
1872     if (NULL != g_connection) {
1873         dbus_connection_unref(g_connection);
1874         g_connection = NULL;
1875     }
1876
1877     ico_apf_ecore_term();
1878
1879     ecore_evas_free(window);
1880     ecore_evas_shutdown();
1881
1882     return 0;
1883
1884   error:
1885     fprintf(stderr, "Evas engine error.");
1886     ecore_evas_shutdown();
1887     return -1;
1888 }