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