Fix internal bug and change the design of ico-app-samplenavi
[profile/ivi/ico-uxf-homescreen-sample-apps.git] / ico-app-vicsample / src / vicsample.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   Vehicles Sample APP
11  *          Vehicles information is displayed.
12  *
13  * @date    Mar-04-2013
14  */
15
16 #ifdef HAVE_CONFIG_H
17
18 #include "config.h"
19 #define __UNUSED__
20 #else
21 #define __UNUSED__
22 #endif
23
24 //#include <VehicleInfo.h>
25 #include <Ecore.h>
26 #include <Ecore_Evas.h>
27
28 #include <dbus/dbus.h>          /* dbus */
29 #include <string.h>             /* test log output */
30 #include <stdbool.h>            // bool type define //TEST
31 //#include "app_log.h"
32 #include "ico_apf.h"
33 #include "ico_apf_ecore.h"
34 #include "ico_apf_log.h"
35 //#include    "ico_uxf_conf_common.h"
36 /* macro for debug */
37 //#define DEBUG_PRINT(...)    ICO_UXF_DEBUG(__VA_ARGS__)
38 //#define ERROR_PRINT(...)    ICO_UXF_WARN(__VA_ARGS__)
39
40 #if 0
41 // log output define
42 #include <unistd.h>
43
44 #define DEBUG_PRINT(...)    LOG_PRINT(__VA_ARGS__)
45 #define LOG_PRINT(fmt,...)  \
46     {log_print("%s> "fmt" (%s,%s:%d)\n", log_curtime("DBG"), ##__VA_ARGS__,\
47                __func__, __FILE__, __LINE__); }
48
49 static FILE *sDbgFd = (FILE *) 0;
50 void log_print(const char *fmt, ...)
51 {
52     va_list list;
53
54     va_start(list, fmt);
55     vfprintf(sDbgFd, fmt, list);
56     va_end(list);
57     fflush(sDbgFd);
58 }
59
60 /* local time difference(sec) */
61 static int sTimeZone = (99 * 60 * 60);
62
63 char *log_curtime(const char *level)
64 {
65
66     struct timeval NowTime;
67     extern long timezone;
68     static char sBuf[28];
69
70     gettimeofday(&NowTime, (struct timezone *) 0);
71     if (sTimeZone > (24 * 60 * 60)) {
72         tzset();
73         sTimeZone = timezone;
74     }
75     NowTime.tv_sec -= sTimeZone;
76
77     sprintf(sBuf, "%02d:%02d:%02d.%03d[%s]@%d",
78             (int) ((NowTime.tv_sec / 3600) % 24),
79             (int) ((NowTime.tv_sec / 60) % 60),
80             (int) (NowTime.tv_sec % 60),
81             (int) NowTime.tv_usec / 1000, level, getpid());
82
83     return (sBuf);
84 }
85 #endif
86
87 /*============================================================================*/
88 /* Define fixed parameters                                                    */
89 /*============================================================================*/
90 #define WIDTH  (700)            /* Background width  */
91 #define HEIGHT (934)            /* Background height */
92
93 /* Count vehicle information */
94 static int property_num = 0;
95
96 /* max size of vehicle information */
97 #define MAX_PARA_NUM 32
98
99 /* vehicle information ID */
100 #define VEHICLESPEED  0
101 #define ACCELERATIONX 1
102 #define SHIFTPOSITION 2
103 #define ENGINESPEED   3
104 #define LATITUDE      4
105 #define ALTITUDE      5
106 #define GEARPOSITION  6
107 #define LONGITUDE     7
108 #define MODE          8
109
110 #define DIRECTION     9
111 #define BRAKEPRESSURE 10
112 #define LEFTTURN      11
113 #define RIGHTTURN     12
114 #define BRAKESIGNAL   13
115
116 /* Definition for use with D-Bus */
117 #define DBUS_SERVICE   "org.automotive.message.broker"
118 #define DBUS_INTERFACE "org.freedesktop.DBus.Properties"
119 #define DBUS_METHOD    "Get"
120
121 /* Definition for files */
122 //#define CONFIG_FILE    "/home/rpf/src/app/vic_inf_dspTP/vicsample_config.txt"
123 //#define TMP_LOG        "/home/rpf/var/log/uifw/tmp_vic_inf_dspTP.log"
124 //#define LOG_NAME       "/home/rpf/var/log/uifw/vic_inf_dspTP.log"
125 #define CONFIG_FILE    "/opt/apps/org.tizen.ico.app-vicsample/res/vicsample_config.txt"
126 #define TMP_LOG        "/tmp/tmp_ico-app-vicsample.log"
127 #define LOG_NAME       "/tmp/ico-app-vicsample.log"
128
129
130 /* coordinates of  vehicle information table frame */
131 #define VTX_SX         50.0F    /* X position of the upper left corner */
132 #define VTX_SY         30.0F    /* Y position of the upper left corner */
133 #define VTX_EX         650.0F   /* X position of the lower right */
134 #define VTX_EY         830.0F   /* Y position of the lower right */
135 #define FIX_LINE_NUM   6        /* The number of lines of the table */
136                                 /* Percentage of the column 13 = 1+4+4+4 */
137                                 /* No.[1]:Name(JP)[4]:Name(EN)[4]:Value[4] */
138 #define FIX_SEQ_BASE   (VTX_EX - VTX_SX) / 13
139                                 /* X position of the 1st frame vertical line */
140 #define FIX_SEQ_LINE1  VTX_SX + FIX_SEQ_BASE
141                                 /* X position of the 2nd frame vertical line */
142 #define FIX_SEQ_LINE2  FIX_SEQ_LINE1 + (FIX_SEQ_BASE * 4)
143                                 /* X position of the 3rd frame vertical line */
144 #define FIX_SEQ_LINE3  FIX_SEQ_LINE2 + (FIX_SEQ_BASE * 4)
145
146 /* Horizontal line interval size */
147 #define UFIX_LINE_BASE (VTX_EY - VTX_SY)/MAX_PARA_NUM
148
149 /*============================================================================*/
150 /* Define data types                                                          */
151 /*============================================================================*/
152 union VicVal_t
153 {
154     dbus_int32_t i32_val;
155     dbus_int32_t i16_val;
156     dbus_uint32_t u32_val;
157     dbus_uint16_t u16_val;
158     uint8_t byte_val;
159     dbus_bool_t b_val;
160     double d_val;
161     char *s_val;
162 };
163
164 struct vic_data_t
165 {
166     int property;
167     char name[32];
168     char path_name[64];
169     char interface_name[64];
170     char property_name[32];
171 };
172
173 struct vic_key_data_t
174 {
175     int id;
176     char name[32];
177 };
178
179 /*============================================================================*/
180 /* Function prototype for static(internal) functions                          */
181 /*============================================================================*/
182 static void _canvas_resize_cb(Ecore_Evas *ee);
183 static void _on_destroy(Ecore_Evas *ee __UNUSED__);
184 static Eina_Bool _timer_cb(void *data);
185 static void cmdlog_output(int key);
186 static void drawVehicleInfo(void);
187 static void _on_mousedown(void *data, Evas *evas, Evas_Object *o,
188                           void *einfo);
189 static int getVehicleInfo(int key, union VicVal_t *vic_val_p);
190 static bool parse_elementary_value(union VicVal_t *vic_val_p,
191                                    DBusMessageIter *iter);
192 // TEST
193 static bool parse_value(union VicVal_t *vic_val_p, DBusMessageIter *iter);
194 // TEST
195 static bool parse_dict_entry(union VicVal_t *vic_val_p,
196                              DBusMessageIter *iter);
197 // TEST
198 static bool parse_array(union VicVal_t *vic_val_p, DBusMessageIter *iter);
199 // TEST
200 static bool parse_struct(union VicVal_t *vic_val_p, DBusMessageIter *iter);
201 static int get_config(void);
202
203 /*============================================================================*/
204 /* Tables and Valiables                                                       */
205 /*============================================================================*/
206 const static char Bus_name[] = DBUS_SERVICE;
207 static struct vic_data_t vic_data[MAX_PARA_NUM];
208
209 const struct vic_key_data_t vic_key_data[] = {
210     {VEHICLESPEED, "VehicleSpeed"},
211     {ACCELERATIONX, "AccelerationX"},
212     {SHIFTPOSITION, "ShiftPosition"},
213     {ENGINESPEED, "EngineSpeed"},
214     {LATITUDE, "Latitude"},
215     {ALTITUDE, "Altitude"},
216     {GEARPOSITION, "GearPosition"},
217     {LONGITUDE, "Longitude"},
218     {MODE, "Mode"},
219     {DIRECTION, "Direction"},
220     {BRAKEPRESSURE, "BrakePressure"},
221     {LEFTTURN, "LeftTurn"},
222     {RIGHTTURN, "RightTurn"},
223     {BRAKESIGNAL, "BrakeSignal"},
224     {-1, "END"}
225 };
226
227 /* Storage area of vehicle information */
228 static union VicVal_t s_vic_val[MAX_PARA_NUM];
229 /* Object for displaying vehicle information */
230 static Evas_Object *vic_val_text[MAX_PARA_NUM];
231
232 /* Table border line */
233 const static Evas_Coord f_vtx[FIX_LINE_NUM][4] = {
234     {VTX_SX, VTX_SY, VTX_SX, VTX_EY},   // Border of the Left frame
235     {VTX_EX, VTX_SY, VTX_EX, VTX_EY},   // Border of the Right frame
236     {VTX_SX, VTX_SY, VTX_EX, VTX_SY},   // Border of the upper frame
237     {VTX_SX, VTX_EY, VTX_EX, VTX_EY},   // Border of the lower frame
238
239     {FIX_SEQ_LINE1, VTX_SY, FIX_SEQ_LINE1, VTX_EY},     // Border of the column 1
240     {FIX_SEQ_LINE2, VTX_SY, FIX_SEQ_LINE2, VTX_EY},     // Border of the column 2
241 //{FIX_SEQ_LINE3, VTX_SY, FIX_SEQ_LINE3, VTX_EY}  // Border of the column 3
242 };
243
244 //#define WIDTH  (300)
245 //#define HEIGHT (300)
246
247 static Ecore_Evas *ee;
248 static Evas_Object *text, *bg;
249 static char sscrntype[32];
250
251 static const char commands[] =
252     "commands are:\n"
253     "\tm - impose a minumum size to the window\n"
254     "\tx - impose a maximum size to the window\n"
255     "\tb - impose a base size to the window\n"
256     "\ts - impose a step size (different than 1 px) to the window\n"
257     "\th - print help\n";
258
259 /* to inform current window's size */
260 static void _canvas_resize_cb(Ecore_Evas *ee)
261 {
262     int w, h;
263     char buf[256];
264
265     ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
266     snprintf(buf, sizeof(buf), "%s %d x %d", sscrntype, w, h);
267     evas_object_text_text_set(text, buf);
268     evas_object_move(text, VTX_SX, VTX_SY - 22);
269     evas_object_resize(bg, w, h);
270 }
271
272 static void _on_destroy(Ecore_Evas *ee __UNUSED__)
273 {
274     ecore_main_loop_quit();
275 }
276
277 /* drawing current time */
278 static Eina_Bool _timer_cb(void *data)
279 {
280     char str[32];
281     time_t timer;
282     struct tm *date;
283     timer = time(NULL);         /* get time in seconds */
284     date = localtime(&timer);   /* Converted to calendar time */
285     sprintf(str, "%s", asctime(date));
286     evas_object_text_text_set((Evas_Object *) data, str);
287
288 //    drawVehicleInfo(); /* Get the vehicle information than AMB */ TEST
289
290     return EINA_TRUE;           /* Continuation of the timer */
291 }
292
293 /* log output for DBUS command result (Debug functin) */
294 static void cmdlog_output(int key)
295 {
296 #if 0
297     char mes1[] =
298         "dbus-send --system --dest=org.automotive.message.broker --type=method_call --print-reply";
299     char mes2[] = "org.freedesktop.DBus.Properties.Get";
300     char mes3[] = "string:";
301     char str[1024];
302     sprintf(str, "%s %s %s %s\"%s\" %s\"%s\" > %s",
303             mes1, vic_data[key].path_name, mes2, mes3,
304             vic_data[key].interface_name, mes3, vic_data[key].property_name,
305             TMP_LOG);
306
307     DEBUG_PRINT("%s(D-bus  Command Result)", vic_data[key].name);
308     system(str);
309
310     /* logout */
311     log_output();
312 #endif
313     return;
314 }
315
316 static void drawVehicleInfo()
317 {
318     union VicVal_t vic_val[32];
319     int result = 0;
320     int i;
321     char vic_str[256];
322
323     for (i = 0; i < property_num; i++) {
324         result = getVehicleInfo(i, vic_val);
325
326         if (result != 0) {
327             uim_debug("Err getVehicleInfo : %s", vic_data[i].name);
328             continue;
329         }
330
331         switch (vic_data[i].property) {
332         case VEHICLESPEED:
333             uim_debug("%s(D-bus I/F Result) = %d", vic_data[i].name,
334                         vic_val[0].i32_val);
335             cmdlog_output(i);
336
337 //            if (vic_val[0].i32_val != s_vic_val[i].i32_val) {
338 //                uim_debug("%s update Front:%d Back:%d", vic_data[i].name,
339 //                            s_vic_val[i].i32_val, vic_val[0].i32_val);
340             s_vic_val[i].i32_val = vic_val[0].i32_val;
341
342             /* Drawing update */
343             sprintf(vic_str, "%d", vic_val[0].i32_val);
344             evas_object_text_text_set(vic_val_text[i], vic_str);
345
346 //            }
347 //            else {
348 //                uim_debug("%s no update:%d", vic_data[i].name,
349 //                            vic_val[0].i32_val);
350 //            }
351
352             break;
353
354         case ACCELERATIONX:
355             uim_debug("%s(D-bus I/F Result) = %d", vic_data[i].name,
356                         vic_val[0].u16_val);
357             cmdlog_output(i);
358
359 //            if (vic_val[0].u16_val != s_vic_val[i].u16_val) {
360 //                uim_debug("%s update Front:%d Back:%d", vic_data[i].name,
361 //                            s_vic_val[i].u16_val, vic_val[0].u16_val);
362             s_vic_val[i].u16_val = vic_val[0].u16_val;
363
364             /* Drawing update */
365             sprintf(vic_str, "%d", vic_val[0].i32_val);
366             sprintf(vic_str, "%d", vic_val[0].u16_val);
367             evas_object_text_text_set(vic_val_text[i], vic_str);
368 //            }
369 //            else {
370 //                uim_debug("%s no update:%d", vic_data[i].name,
371 //                            vic_val[0].u16_val);
372 //            }
373
374             break;
375
376         case SHIFTPOSITION:
377             uim_debug("%s(D-bus I/F Result) = %d", vic_data[i].name,
378                         vic_val[0].byte_val);
379             cmdlog_output(i);
380
381 //            if (vic_val[0].byte_val != s_vic_val[i].byte_val) {
382 //                uim_debug("%s update Front:%d Back:%d", vic_data[i].name,
383 //                            s_vic_val[i].byte_val, vic_val[0].byte_val);
384             s_vic_val[i].byte_val = vic_val[0].byte_val;
385
386             /* Drawing update */
387             sprintf(vic_str, "%d", vic_val[0].byte_val);
388             evas_object_text_text_set(vic_val_text[i], vic_str);
389 //            }
390 //            else {
391 //                uim_debug("%s noupdate:%d", vic_data[i].name,
392 //                            vic_val[0].byte_val);
393 //            }
394
395             break;
396
397         case ENGINESPEED:
398         case DIRECTION:
399         case BRAKEPRESSURE:
400             uim_debug("%s(D-bus I/F Result) = %d", vic_data[i].name,
401                         vic_val[0].i32_val);
402             cmdlog_output(i);
403             s_vic_val[i].i32_val = vic_val[0].i32_val;
404             sprintf(vic_str, "%d", vic_val[0].i32_val);
405             evas_object_text_text_set(vic_val_text[i], vic_str);
406             break;
407
408         case LATITUDE:
409         case ALTITUDE:
410         case LONGITUDE:
411             uim_debug("%s(D-bus I/F Result) = %f", vic_data[i].name,
412                         vic_val[0].d_val);
413             cmdlog_output(i);
414             s_vic_val[i].d_val = vic_val[0].d_val;
415             sprintf(vic_str, "%f", vic_val[0].d_val);
416             evas_object_text_text_set(vic_val_text[i], vic_str);
417             break;
418
419         case GEARPOSITION:
420         case MODE:
421             uim_debug("%s(D-bus I/F Result) = %d", vic_data[i].name,
422                         vic_val[0].byte_val);
423             cmdlog_output(i);
424             s_vic_val[i].byte_val = vic_val[0].byte_val;
425             sprintf(vic_str, "%d", vic_val[0].byte_val);
426             evas_object_text_text_set(vic_val_text[i], vic_str);
427             break;
428
429         case LEFTTURN:
430         case RIGHTTURN:
431         case BRAKESIGNAL:
432             uim_debug("%s(D-bus I/F Result) = %d", vic_data[i].name,
433                         vic_val[0].b_val);
434             cmdlog_output(i);
435             s_vic_val[i].b_val = vic_val[0].b_val;
436             if (vic_val[0].b_val == TRUE) {
437                 sprintf(vic_str, "%s", "true");
438             }
439             else {
440                 sprintf(vic_str, "%s", "false");
441             }
442             evas_object_text_text_set(vic_val_text[i], vic_str);
443             break;
444
445         default:
446             uim_debug("Err no property : %s\n", vic_data[i].name);
447             break;
448         }
449     }
450     return;
451 }
452
453 static void _on_mousedown(void *data, Evas *evas, Evas_Object *o,
454                           void *einfo)
455 {
456     drawVehicleInfo();
457     return;
458 }
459
460 /* Get the vehicle information than AMB */
461 DBusConnection *g_connection = NULL;
462 static int getVehicleInfo(int key, union VicVal_t *vic_val_p)
463 {
464     /* local variable */
465     DBusMessage *message;
466     DBusError error;
467     int result = 0;
468     const char *v_string[] = {
469         vic_data[key].interface_name,
470         vic_data[key].property_name
471     };
472     const char *dest = Bus_name;
473     DBusMessage *reply;
474     int reply_timeout = 1000;   /* Millisecond */
475     DBusMessageIter iter;
476     DBusMessageIter iter_array;
477
478     /* initialize */
479     dbus_error_init(&error);
480
481     if (NULL == g_connection) {
482         /* obtain the right to use dbus */
483         g_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
484
485         if (g_connection == NULL) {
486             uim_debug("Err dbus_bus_get");
487
488                         /* Release err parameter */
489             dbus_error_free(&error);
490                         return -1;
491         }
492     }
493     /* Constructs a new message */
494     message = dbus_message_new_method_call(DBUS_SERVICE,
495                                            vic_data[key].path_name,
496                                            DBUS_INTERFACE, DBUS_METHOD);
497     if (message == NULL) {
498         uim_debug("Err dbus_message_new_method_call");
499
500         /* Release the connection */
501         dbus_connection_unref(g_connection);
502         g_connection = NULL;
503         return -1;
504     }
505
506     /* Gets the type of a message */
507     result = dbus_message_append_args(message,
508                                       DBUS_TYPE_STRING,
509                                       &v_string[0],
510                                       DBUS_TYPE_STRING,
511                                       &v_string[1], DBUS_TYPE_INVALID);
512     if (!result) {
513         uim_debug("Err dbus_message_append_args");
514
515         /* Release the connection */
516         dbus_connection_unref(g_connection);
517         g_connection = NULL;
518         /* Release the message */
519         dbus_message_unref(message);
520
521         return -1;
522     }
523
524     /* Gets the error name */
525     if ((dest) && (!dbus_message_set_destination(message, dest))) {
526         uim_debug("Err dbus_message_new_method_call");
527
528         /* Release the connection */
529         dbus_connection_unref(g_connection);
530         g_connection = NULL;
531
532         /* Release the message */
533         dbus_message_unref(message);
534
535         return -1;
536     }
537
538     /* Queues a message to send */
539     reply = dbus_connection_send_with_reply_and_block(g_connection,
540                                                       message,
541                                                       reply_timeout, &error);
542     if (reply == NULL) {
543         uim_debug("Err dbus_connection_send_with_reply_and_block");
544
545         /* Release the connection */
546         dbus_connection_unref(g_connection);
547         g_connection = NULL;
548
549         /* Release the message */
550         dbus_message_unref(message);
551
552                 /* Release err parameter */
553         dbus_error_free(&error);
554
555         return -1;
556     }
557
558     /* Gets the result */
559     dbus_message_iter_init(reply, &iter);
560     dbus_message_iter_recurse(&iter, &iter_array);
561
562     /* Type conversion of the resulting value */
563 //    result = parse_elementary_value(vic_val_p, &iter_array);
564     union VicVal_t *tmp_vic_val_p = vic_val_p;  //TEST
565     result = parse_value(tmp_vic_val_p, &iter_array);   //TEST
566
567     if (result != TRUE) {
568         uim_debug("Err parse_elementary_value");
569
570         /* Release the connection */
571         dbus_connection_unref(g_connection);
572         g_connection = NULL;
573
574         /* Release the message */
575         dbus_message_unref(message);
576         dbus_message_unref(reply);
577
578         return -1;
579     }
580
581     /* Release the message */
582     dbus_message_unref(message);
583     dbus_message_unref(reply);
584
585     return 0;
586 }
587
588 /* Parse of the value */
589 static bool parse_elementary_value(union VicVal_t *vic_val_p,
590                                    DBusMessageIter *iter)
591 {
592     dbus_int32_t i32_val;
593     dbus_int32_t i16_val;
594     dbus_uint32_t u32_val;
595     dbus_uint16_t u16_val;
596     uint8_t byte_val;
597     dbus_bool_t b_val;
598     double d_val;
599     char *s_val;
600     char *w_s_val;
601
602     char sig;
603
604     if ((vic_val_p == NULL) || (iter == NULL)) {
605         uim_debug("Err Parameter NG ");
606         return FALSE;
607     }
608
609     sig = dbus_message_iter_get_arg_type(iter);
610
611     switch (sig) {
612     case DBUS_TYPE_INT32:
613         dbus_message_iter_get_basic(iter, &i32_val);
614         vic_val_p->i32_val = i32_val;
615         vic_val_p++;
616         break;
617     case DBUS_TYPE_INT16:
618         dbus_message_iter_get_basic(iter, &i16_val);
619         vic_val_p->i16_val = i16_val;
620         vic_val_p++;
621         break;
622     case DBUS_TYPE_UINT32:
623         dbus_message_iter_get_basic(iter, &u32_val);
624         vic_val_p->u32_val = u32_val;
625         vic_val_p++;
626         break;
627     case DBUS_TYPE_UINT16:
628         dbus_message_iter_get_basic(iter, &u16_val);
629         vic_val_p->u16_val = u16_val;
630         vic_val_p++;
631         break;
632     case DBUS_TYPE_BOOLEAN:
633         dbus_message_iter_get_basic(iter, &b_val);
634         vic_val_p->b_val = b_val;
635         vic_val_p++;
636         break;
637     case DBUS_TYPE_BYTE:
638         dbus_message_iter_get_basic(iter, &byte_val);
639         vic_val_p->byte_val = byte_val;
640         vic_val_p++;
641         break;
642     case DBUS_TYPE_DOUBLE:
643         dbus_message_iter_get_basic(iter, &d_val);
644         vic_val_p->d_val = d_val;
645         vic_val_p++;
646         break;
647     case DBUS_TYPE_STRING:
648         dbus_message_iter_get_basic(iter, &s_val);
649         w_s_val = (char *) malloc(strlen(s_val) + 1);   // Release required
650         if (w_s_val == NULL) {
651             uim_debug("Err malloc");
652             return FALSE;
653         }
654         strncpy(w_s_val, s_val, strlen(s_val));
655         vic_val_p->s_val = w_s_val;
656         vic_val_p++;
657 //        vic_val_p->s_val = s_val;
658         break;
659     default:
660         uim_debug("Err parse_elementary_value: unknown type");
661         return FALSE;
662     }
663
664     return TRUE;
665 }
666
667 static bool parse_value(union VicVal_t *vic_val_p, DBusMessageIter *iter)
668 {
669     char curr;
670
671     if ((vic_val_p == NULL) || (iter == NULL)) {
672         uim_debug("Err Parameter NG ");
673         return FALSE;
674     }
675
676     curr = dbus_message_iter_get_arg_type(iter);
677
678     switch (curr) {
679     case DBUS_TYPE_BYTE:
680     case DBUS_TYPE_BOOLEAN:
681     case DBUS_TYPE_INT16:
682     case DBUS_TYPE_INT32:
683     case DBUS_TYPE_UINT16:
684     case DBUS_TYPE_UINT32:
685     case DBUS_TYPE_DOUBLE:
686     case DBUS_TYPE_STRING:
687         return parse_elementary_value(vic_val_p, iter);
688     case DBUS_TYPE_ARRAY:
689         return parse_array(vic_val_p, iter);
690     case DBUS_TYPE_STRUCT:
691         return parse_struct(vic_val_p, iter);
692     case DBUS_TYPE_DICT_ENTRY:
693 //            goto error; /* these are handled from parse_array */
694         return FALSE;
695     case DBUS_TYPE_INVALID:
696         return TRUE;
697     default:
698         break;
699     }
700     return FALSE;
701 }
702
703 static bool parse_array(union VicVal_t *vic_val_p, DBusMessageIter *iter)
704 {
705     DBusMessageIter new_iter;
706     int element_type;
707
708     if ((vic_val_p == NULL) || (iter == NULL)) {
709         uim_debug("Err Parameter NG ");
710         return FALSE;
711     }
712
713     /* the lua array */
714 //    lua_newtable(L);
715
716     element_type = dbus_message_iter_get_element_type(iter);
717
718     dbus_message_iter_recurse(iter, &new_iter);
719
720     /* the problem: if the value inside array is a dict entry, the
721      * indexing of elements need to be done with dict keys instead
722      * of numbers. */
723
724     if (element_type == DBUS_TYPE_DICT_ENTRY) {
725         while (dbus_message_iter_get_arg_type(&new_iter) != DBUS_TYPE_INVALID) {
726
727             parse_dict_entry(vic_val_p, &new_iter);
728             dbus_message_iter_next(&new_iter);
729         }
730     }
731
732     else {
733         while (dbus_message_iter_get_arg_type(&new_iter) != DBUS_TYPE_INVALID) {
734
735             /* array index */
736 //            lua_pushinteger(L, i++);
737
738             parse_value(vic_val_p, &new_iter);
739             dbus_message_iter_next(&new_iter);
740
741             /* put the values to the table */
742 //            lua_settable(L, -3);
743         }
744     }
745
746     return TRUE;
747 }
748
749 static bool parse_dict_entry(union VicVal_t *vic_val_p,
750                              DBusMessageIter *iter)
751 {
752     DBusMessageIter new_iter;
753
754     if ((vic_val_p == NULL) || (iter == NULL)) {
755         uim_debug("Err Parameter NG ");
756         return FALSE;
757     }
758
759     dbus_message_iter_recurse(iter, &new_iter);
760
761     while (dbus_message_iter_get_arg_type(&new_iter) != DBUS_TYPE_INVALID) {
762
763         /* key must be elementary, value can be anything */
764
765         parse_elementary_value(vic_val_p, &new_iter);
766         dbus_message_iter_next(&new_iter);
767
768         parse_value(vic_val_p, &new_iter);
769         dbus_message_iter_next(&new_iter);
770
771         /* put the values to the table */
772 //        lua_settable(L, -3);
773     }
774
775     return TRUE;
776 }
777
778 static bool parse_struct(union VicVal_t *vic_val_p, DBusMessageIter *iter)
779 {
780     DBusMessageIter new_iter;
781
782     if ((vic_val_p == NULL) || (iter == NULL)) {
783         uim_debug("Err Parameter NG ");
784         return FALSE;
785     }
786
787     /* initialize the table */
788 //    lua_newtable(L);
789
790     dbus_message_iter_recurse(iter, &new_iter);
791
792     while (dbus_message_iter_get_arg_type(&new_iter) != DBUS_TYPE_INVALID) {
793
794         /* struct "index" */
795 //        lua_pushinteger(L, i++);
796
797         parse_value(vic_val_p, &new_iter);
798         dbus_message_iter_next(&new_iter);
799
800         /* put the values to the table */
801 //        lua_settable(L, -3);
802     }
803
804     return TRUE;
805 }
806
807 /* Read configuration file */
808 static int get_config(void)
809 {
810
811     FILE *fp;
812     int k = 0;
813     int j, m;
814     char buff[512];
815     char *tp;
816     char *clm = " \n";
817
818     fp = fopen(CONFIG_FILE, "r");
819     if (fp == NULL) {
820         uim_debug("File open error");
821         return -1;
822     }
823
824     for (m = 0; k < MAX_PARA_NUM; m++) {
825         if (fgets(buff, sizeof(buff) - 2, fp) != NULL) {
826             tp = strtok(buff, clm);
827             if (tp != NULL) {
828                 if (tp[0] != '#') {
829                     for (j = 0; vic_key_data[j].id != -1; j++) {
830                         if (strcmp(tp, vic_key_data[j].name) == 0) {
831                             vic_data[k].property = vic_key_data[j].id;
832                             strcpy(vic_data[k].name, tp);
833                             strcpy(vic_data[k].path_name, strtok(NULL, clm));
834                             strcpy(vic_data[k].interface_name,
835                                    strtok(NULL, clm));
836                             strcpy(vic_data[k].property_name,
837                                    strtok(NULL, clm));
838                            uim_debug("vic_data[%d].property=%d", k,
839                                    vic_data[k].property);
840                            uim_debug("vic_data[%d].name=%s", k,
841                                    vic_data[k].name);
842                            uim_debug("vic_data[%d].path_name=%s", k,
843                                    vic_data[k].path_name);
844                            uim_debug("vic_data[%d].interface_name=%s", k,
845                                    vic_data[k].interface_name);
846                            uim_debug("vic_data[%d].property_name=%s", k,
847                                    vic_data[k].property_name);
848
849                             k++;
850                             break;
851                         }
852                     }
853                     if (vic_key_data[j].id == -1) {
854                         uim_debug("Err vicsample_config.txt Line:%d Unregistered"
855                                     " parameter name", m + 1);
856                     }
857
858                 }
859                 else {
860                     uim_debug
861                         ("vicsample_config.txt Line:%d Comment out  '#'Discovery",
862                          m + 1);
863                 }
864             }
865             else {
866                 uim_debug("vicsample_config.txt Line:%d Comment out  Null line",
867                             m + 1);
868             }
869         }
870         else {
871             uim_debug("vicsample_config.txt The end of data reading");
872             break;
873         }
874     }
875     fclose(fp);
876
877     property_num = k;
878     if (property_num == 0) {
879         uim_debug("vicsample_config.txt No valid data");
880         return -1;
881     }
882     return 0;
883 }
884
885 static void res_callback(ico_apf_resource_notify_info_t *info,
886                          void *user_data)
887 {
888     int ret;
889
890     uim_debug("##==> Callbacked evt=%d res=%d id=%d bid=%d appid=%s dev=%s"
891                 " user_data=%d", info->state, info->resid, info->id,
892                 info->bid, info->appid, info->device, (int) user_data);
893     switch (info->state) {
894     case ICO_APF_RESOURCE_STATE_ACQUIRED:
895     case ICO_APF_RESOURCE_STATE_DEPRIVED:
896     case ICO_APF_RESOURCE_STATE_WAITTING:
897     case ICO_APF_RESOURCE_STATE_RELEASED:
898         if (info->resid == ICO_APF_RESID_INT_SCREEN) {
899             ret = ico_apf_resource_reply_int_screen_mode(info->device,
900                                                          info->bid, info->id,
901                                                          1);
902             uim_debug("##==> callback reply int_screen(%s,%d,%d,1) = %d",
903                         info->device, info->bid, info->id, ret);
904         }
905         else if (info->resid == ICO_APF_RESID_ON_SCREEN) {
906             ret = ico_apf_resource_reply_int_screen_mode_disp(info->device,
907                                                               info->id, 1);
908             uim_debug("##==> callback reply on_screen(%s,%d,1) = %d",
909                         info->device, info->id, ret);
910         }
911         else {
912             ret =
913                 ico_apf_resource_reply_screen_mode(info->device, info->id, 1);
914             uim_debug("##==> callback reply screen(%s,%d,1) = %d",
915                         info->device, info->id, ret);
916         }
917         break;
918     default:
919         /* NOP  */
920         break;
921     }
922 }
923
924 int main(int argc, char *argv[])
925 {
926     int i;
927     int getscreen;
928     Evas *evas;
929     char appid[ICO_UXF_MAX_PROCESS_NAME + 1];
930
931     getscreen = 0;
932     sscrntype[0] = 0;
933     for (i = 1; i < argc; i++) {
934         if (argv[i][0] == '-') {
935             if (strcasecmp(argv[i], "-basescreen") == 0) {
936                 getscreen = 1;  /* get base screen */
937                 strcpy(sscrntype, "BasicScreen");
938             }
939             else if (strcasecmp(argv[i], "-intscreen") == 0) {
940                 getscreen = 2;  /* get interrupt screen */
941                 strcpy(sscrntype, "IntScreen");
942             }
943             else if (strcasecmp(argv[i], "-onscreen") == 0) {
944                 getscreen = 3;  /* get on screen */
945                 strcpy(sscrntype, "OnScreen");
946             }
947         }
948     }
949
950     if (!ecore_evas_init()) {
951         return EXIT_FAILURE;
952     }
953     /* Setting the log output */
954     if (ico_apf_get_app_id(0, appid) == ICO_APP_CTL_E_NONE) {
955         ico_apf_log_open(appid);
956     }
957
958     uim_debug("main ENTER");
959
960     /* Read configuration file */
961     if (get_config() != 0) {
962         uim_debug("Err get_config");
963         return -1;
964     }
965
966     if (getscreen > 0) {
967         /* initialize resource control for Ecore */
968         if (ico_apf_ecore_init(NULL) != ICO_APF_E_NONE) {
969             uim_debug("ico_apf_ecore_init() Error");
970             ecore_evas_shutdown();
971             return -1;
972         }
973
974         /* set resource request callback */
975         ico_apf_resource_set_event_cb(res_callback, NULL);
976
977         /* acquire a right to display a screen */
978         if (getscreen == 1) {
979             ico_apf_resource_get_screen_mode(NULL, 0);
980         }
981         else if (getscreen == 2) {
982             ico_apf_resource_get_int_screen_mode(NULL, 0, 0);
983         }
984         else {
985             ico_apf_resource_get_int_screen_mode_disp(NULL, 0);
986         }
987     }
988
989     /* this will give you a window with an Evas canvas under the first
990      * engine available */
991     ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, "frame=0");
992     if (!ee) {
993         goto error;
994     }
995
996     ecore_evas_callback_delete_request_set(ee, _on_destroy);
997     ecore_evas_title_set(ee, "Ecore_Evas window sizes example");
998     ecore_evas_callback_resize_set(ee, _canvas_resize_cb);
999     ecore_evas_show(ee);
1000
1001     evas = ecore_evas_get(ee);
1002
1003     /* Background printing */
1004     bg = evas_object_rectangle_add(evas);
1005     evas_object_color_set(bg, 255, 255, 255, 255);      /* white bg */
1006     evas_object_move(bg, 0, 0); /* at canvas' origin */
1007     evas_object_resize(bg, WIDTH, HEIGHT);      /* covers full canvas */
1008     evas_object_show(bg);
1009
1010     evas_object_focus_set(bg, EINA_TRUE);
1011
1012     /* Drawing window */
1013     text = evas_object_text_add(evas);
1014     evas_object_color_set(text, 255, 0, 0, 255);
1015     evas_object_resize(text, 150, 50);
1016     evas_object_text_font_set(text, "Sans", 20);
1017     evas_object_show(text);
1018
1019     /* Button on the output drawing vehicle information */
1020     static Evas_Object *sikaku;
1021     sikaku = evas_object_rectangle_add(evas);
1022     evas_object_color_set(sikaku, 255, 0, 0, 100);
1023     evas_object_move(sikaku, 50, ((int) VTX_EY) + 7);
1024     int hsz = HEIGHT - (int) VTX_EY - 7 - 7;
1025     evas_object_resize(sikaku, 200, hsz);
1026     evas_object_show(sikaku);
1027
1028     /* draw table */
1029     static Evas_Object *fix_line[FIX_LINE_NUM];
1030
1031     for (i = 0; i < FIX_LINE_NUM; i++) {
1032         fix_line[i] = evas_object_line_add(evas);
1033         evas_object_color_set(fix_line[i], 55, 55, 55, 255);
1034         evas_object_line_xy_set(fix_line[i], f_vtx[i][0], f_vtx[i][1],
1035                                 f_vtx[i][2], f_vtx[i][3]);
1036         evas_object_show(fix_line[i]);
1037     }
1038
1039     /* draw order line */
1040     static Evas_Object *ufix_line[MAX_PARA_NUM - 1];
1041
1042     for (i = 0; i < MAX_PARA_NUM - 1; i++) {
1043         ufix_line[i] = evas_object_line_add(evas);
1044         evas_object_color_set(ufix_line[i], 55, 55, 55, 255);
1045         evas_object_line_xy_set(ufix_line[i],
1046                                 VTX_SX, VTX_SY + UFIX_LINE_BASE * (i + 1),
1047                                 VTX_EX, VTX_SY + UFIX_LINE_BASE * (i + 1));
1048         evas_object_show(ufix_line[i]);
1049     }
1050
1051     /* draw table item */
1052     static Evas_Object *num_text[MAX_PARA_NUM];
1053     char str[11];
1054     static Evas_Object *pname_text2[MAX_PARA_NUM];
1055
1056     for (i = 0; i < MAX_PARA_NUM; i++) {
1057         /* draw table item (No.) */
1058         num_text[i] = evas_object_text_add(evas);
1059         evas_object_color_set(num_text[i], 0, 0, 0, 255);
1060         evas_object_resize(num_text[i], FIX_SEQ_BASE, UFIX_LINE_BASE);
1061         evas_object_text_font_set(num_text[i], "Sans",
1062                                   (UFIX_LINE_BASE / 3) * 2);
1063         evas_object_show(num_text[i]);
1064         sprintf(str, "%d", i + 1);
1065         evas_object_text_text_set(num_text[i], str);
1066         evas_object_move(num_text[i], VTX_SX + FIX_SEQ_BASE / 4,
1067                          VTX_SY + UFIX_LINE_BASE * (i) + UFIX_LINE_BASE / 6);
1068
1069         /* draw table item (Name of vehicle information) */
1070         pname_text2[i] = evas_object_text_add(evas);
1071         evas_object_color_set(pname_text2[i], 0, 0, 0, 255);
1072         evas_object_resize(pname_text2[i], 150, 50);
1073         evas_object_text_font_set(pname_text2[i], "Sans",
1074                                   (UFIX_LINE_BASE / 3) * 2);
1075         evas_object_show(pname_text2[i]);
1076         evas_object_text_text_set(pname_text2[i], vic_data[i].name);
1077         evas_object_move(pname_text2[i], FIX_SEQ_LINE1 + FIX_SEQ_BASE / 4,
1078                          VTX_SY + UFIX_LINE_BASE * (i) + UFIX_LINE_BASE / 6);
1079
1080         /* draw table item (Value of vehicle information) */
1081         vic_val_text[i] = evas_object_text_add(evas);
1082         evas_object_color_set(vic_val_text[i], 0, 0, 0, 255);
1083         evas_object_resize(vic_val_text[i], FIX_SEQ_BASE, UFIX_LINE_BASE);
1084         evas_object_text_font_set(vic_val_text[i], "Sans",
1085                                   (UFIX_LINE_BASE / 3) * 2);
1086         evas_object_show(vic_val_text[i]);
1087         evas_object_move(vic_val_text[i], FIX_SEQ_LINE2 + FIX_SEQ_BASE / 4,
1088                          VTX_SY + UFIX_LINE_BASE * (i) + UFIX_LINE_BASE / 6);
1089     }
1090
1091     /* entry of the function event callback Vehicle Information */
1092     evas_object_event_callback_add(sikaku, EVAS_CALLBACK_MOUSE_DOWN,
1093                                    _on_mousedown, vic_val_text);
1094
1095     /* drawing current time */
1096     static Evas_Object *time_text;
1097
1098     time_text = evas_object_text_add(evas);
1099     evas_object_color_set(time_text, 0, 0, 0, 255);
1100     evas_object_resize(time_text, 150, 50);
1101     evas_object_text_font_set(time_text, "Sans", 20);
1102     evas_object_show(time_text);
1103     evas_object_move(time_text, 400, VTX_SY - 22);
1104
1105     /* entry of the function event Interval Timer */
1106     ecore_timer_add(0.1, _timer_cb, time_text);
1107
1108     _canvas_resize_cb(ee);
1109     fprintf(stdout, commands);
1110     ecore_main_loop_begin();
1111
1112     ico_apf_ecore_term();
1113
1114     ecore_evas_free(ee);
1115     ecore_evas_shutdown();
1116
1117     if (NULL != g_connection) {
1118         dbus_connection_unref(g_connection);
1119         g_connection = NULL;
1120     }
1121     uim_debug("main EXIT");
1122     return 0;
1123
1124   error:
1125     fprintf(stderr, "You got to have at least one Evas engine built"
1126             " and linked up to ecore-evas for this example to run"
1127             " properly.\n");
1128     ecore_evas_shutdown();
1129     if (NULL != g_connection) {
1130         dbus_connection_unref(g_connection);
1131         g_connection = NULL;
1132     }
1133     return -1;
1134 }