Leave application vicsample, soundsamples. remove other application.
[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 <Ecore.h>
25 #include <Ecore_Evas.h>
26 #include <Elementary.h>
27 //#include <Ecore_X.h>
28 #include <app.h>
29 #include <dbus/dbus.h>
30 #include <string.h>
31 #include <stdbool.h>
32 #include <bundle.h>
33 //#include "ico_apf.h"
34 //#include "ico_apf_ecore.h"
35 //#include "ico_apf_log.h"
36 #include <aul.h>
37 #include "ico_log.h"
38
39 /*============================================================================*/
40 /* Define fixed parameters                                                    */
41 /*============================================================================*/
42 #define STATUS_BAR_HEIGHT (64)
43 #define CTRL_BAR_HEIGHT   (128)
44 #define WIDTH  (1080) /* Base Background width  */
45 #define HEIGHT (1920 - STATUS_BAR_HEIGHT - CTRL_BAR_HEIGHT) /* Base Background height */
46
47 /* Base */
48 #define SCRN_TYPE_W  800
49 #define SCRN_TYPE_H  20
50 #define CTG_BX_W     530
51 #define CTG_BX_H     250
52 //#define VIC_LI_W     1000
53 #define VIC_LI_W     1060
54 //#define VIC_LI_H     700
55 #define VIC_LI_H     1050
56 #define GET_BTN_W    800
57 #define GET_BTN_H    160
58
59 #define SCRN_TYPE_X  20
60 #define SCRN_TYPE_Y  20
61 #define CTG_BX_X     10
62 #define CTG_BX_Y     40
63 //#define VIC_LI_X     900
64 //#define VIC_LI_Y     40
65 #define VIC_LI_X     10
66 //#define VIC_LI_Y     800
67 #define VIC_LI_Y     450
68 //#define GET_BTN_X    1000
69 //#define GET_BTN_Y    800
70 #define GET_BTN_X    140
71 #define GET_BTN_Y    1530
72
73 /* font */
74 #define FONT_SIZE       48
75 #define FONT_FAMILY     (char *)"Sans"  // Mono, Sans, Serif
76
77 /* Text class name */
78 #define TEXT_BUTTON     (char *)"button"
79 #define TEXT_LIST_ITEM  (char *)"list_item"
80 #define TEXT_LABEL      (char *)"label"
81
82 /* Count vehicle information */
83 static int property_num = 0;
84
85 /* max size of vehicle information */
86 #define MAX_PARA_NUM 32
87
88 /* vehicle information ID */
89 #define VEHICLESPEED       0
90 #define ACCELERATIONX      1
91 #define SHIFTPOSITION      2
92 #define ENGINESPEED        3
93 #define LATITUDE           4
94 #define ALTITUDE           5
95 #define GEARPOSITION       6
96 #define LONGITUDE          7
97 #define MODE               8
98 #define DIRECTION          9
99 #define WHEELBRAKEPRESSURE 10
100 #define LEFTTURN           11
101 #define RIGHTTURN          12
102 #define BRAKESIGNAL        13
103 #define ACCELERATIONY      14
104 #define ACCELERATIONZ      15
105 #define EXTERIORBRIGHTNESS 16
106
107 /* maximum categories */
108 #define PACKAG "ico-app-vicsample"
109 #define MAX_CATEGORY_NUM 8
110
111 /* vehicle information Parameter Category */
112 #define DRIVINGSAFETY   0
113 #define ELECTRICVEHICLE 1
114 #define ENVIRONMENT     2
115 #define MAINTENANCE     3
116 #define PARKING         4
117 #define PERSONALIZATION 5
118 #define RUNNINGSTATUS   6
119 #define VEHICLEINFO     7
120
121 /* Definition for use with D-Bus */
122 #define DBUS_SERVICE   "org.automotive.message.broker"
123 #define DBUS_INTERFACE "org.freedesktop.DBus.Properties"
124 #define DBUS_METHOD    "Get"
125
126 /* Definition for files */
127 #define CONFIG_FILE    "/usr/apps/org.tizen.ico.app-vicsample/res/vicsample_config.txt"
128 #define BG_IMAGE_FILE  "/usr/apps/org.tizen.ico.app-vicsample/res/images/vicinfo_bg.png"
129 /*============================================================================*/
130 /* Define data types                                                          */
131 /*============================================================================*/
132 union VicVal_t
133 {
134     dbus_int32_t i32_val;
135     dbus_int32_t i16_val;
136     dbus_uint32_t u32_val;
137     dbus_uint16_t u16_val;
138     uint8_t byte_val;
139     dbus_bool_t b_val;
140     double d_val;
141     char *s_val;
142 };
143
144 struct vic_data_t
145 {
146     int property;
147     int category;
148     char name[32];
149     char path_name[64];
150     char interface_name[64];
151     char property_name[32];
152 };
153
154 struct vic_key_data_t
155 {
156     int id;
157     int category;
158     char name[32];
159 };
160
161 struct vic_category_data_t
162 {
163     int category;
164     char name[32];
165 };
166
167 struct appdata_t
168 {
169     Evas_Object *win;           //main window
170     Evas_Object *bg;
171
172     Evas_Object *scrn_type;
173     Evas_Object *ctg_bx;
174     Evas_Object *ctg_bx2;
175     Evas_Object *ctg_btn[MAX_CATEGORY_NUM];
176     Evas_Object *vic_ini_li;
177     Evas_Object *vic_li[MAX_CATEGORY_NUM];
178     Evas_Object *vic_val_text[MAX_PARA_NUM];
179     Evas_Object *vic_val_dmy_text[MAX_CATEGORY_NUM];
180     Evas_Object *get_btn;
181 };
182 /*============================================================================*/
183 /* Function prototype for static(internal) functions                          */
184 /*============================================================================*/
185 static double Width = 0;        /* Background width  */
186 static double Height = 0;       /* Background height */
187 static void drawVehicleInfo(void);
188 static void _on_mousedown(void *data, Evas_Object *obj, void *event_info);
189 static void _on_ctg_mousedown(void *data, Evas_Object *obj,
190                               void *event_info);
191 static int getVehicleInfo(int key, union VicVal_t *vic_val_p);
192 static bool parse_elementary_value(union VicVal_t *vic_val_p,
193                                    DBusMessageIter *iter);
194 // TEST
195 static bool parse_value(union VicVal_t *vic_val_p, DBusMessageIter *iter);
196 // TEST
197 static bool parse_dict_entry(union VicVal_t *vic_val_p,
198                              DBusMessageIter *iter);
199 // TEST
200 static bool parse_array(union VicVal_t *vic_val_p, DBusMessageIter *iter);
201 // TEST
202 static bool parse_struct(union VicVal_t *vic_val_p, DBusMessageIter *iter);
203
204 static int get_config(void);
205 static void _winCreate(void);
206 static void elmListCreate(void);
207 /*============================================================================*/
208 /* Tables and Valiables                                                       */
209 /*============================================================================*/
210 const static char Bus_name[] = DBUS_SERVICE;
211 static struct vic_data_t vic_data[MAX_PARA_NUM];
212 static DBusConnection *g_connection = NULL;
213 static struct appdata_t Ad;
214 static char SscrnType[32];
215 static int ListDispSts = -1;
216
217 const struct vic_category_data_t vic_category_data[MAX_CATEGORY_NUM] = {
218     {DRIVINGSAFETY, "Driving safety"},
219     {ELECTRICVEHICLE, "Electric Vehicle"},
220     {ENVIRONMENT, "Environment"},
221     {MAINTENANCE, "Maintenance"},
222     {PARKING, "Parking"},
223     {PERSONALIZATION, "Personalization"},
224     {RUNNINGSTATUS, "Running Status"},
225     {VEHICLEINFO, "Vehicle Info"}
226 };
227
228 const struct vic_key_data_t vic_key_data[] = {
229     {VEHICLESPEED, RUNNINGSTATUS, "VehicleSpeed"},
230     {ACCELERATIONX, RUNNINGSTATUS, "AccelerationX"},
231     {SHIFTPOSITION, RUNNINGSTATUS, "ShiftPosition"},
232     {ENGINESPEED, RUNNINGSTATUS, "EngineSpeed"},
233     {LATITUDE, RUNNINGSTATUS, "Latitude"},
234     {ALTITUDE, RUNNINGSTATUS, "Altitude"},
235     {GEARPOSITION, RUNNINGSTATUS, "GearPosition"},
236     {LONGITUDE, RUNNINGSTATUS, "Longitude"},
237     {MODE, RUNNINGSTATUS, "Mode"},
238     {DIRECTION, RUNNINGSTATUS, "Direction"},
239     {WHEELBRAKEPRESSURE, RUNNINGSTATUS, "WheelBrakePressure"},
240     {LEFTTURN, RUNNINGSTATUS, "LeftTurn"},
241     {RIGHTTURN, RUNNINGSTATUS, "RightTurn"},
242     {BRAKESIGNAL, RUNNINGSTATUS, "BrakeSignal"},
243     {ACCELERATIONY, RUNNINGSTATUS, "AccelerationY"},
244     {ACCELERATIONZ, RUNNINGSTATUS, "AccelerationZ"},
245     {EXTERIORBRIGHTNESS, ENVIRONMENT, "ExteriorBrightness"},
246     {-1, -1, "END"}
247 };
248
249 /*============================================================================*/
250 /* Function                                                                   */
251 /*============================================================================*/
252 static void drawVehicleInfo()
253 {
254     union VicVal_t vic_val[32];
255     int result = 0;
256     int i;
257     char vic_str[256];
258
259     for (i = 0; i < property_num; i++) {
260         result = getVehicleInfo(i, vic_val);
261         memset(vic_str, 0x00, sizeof(vic_str));
262
263         if (result != 0) {
264             ICO_DBG("Err getVehicleInfo : %s", vic_data[i].name);
265             continue;
266         }
267
268         switch (vic_data[i].property) {
269         case VEHICLESPEED:
270             ICO_DBG("%s(D-bus I/F Result) = %d", vic_data[i].name,
271                       vic_val[0].i32_val);
272             /* Drawing update */
273             sprintf(vic_str, "%d", vic_val[0].i32_val);
274             elm_object_text_set(Ad.vic_val_text[i], vic_str);
275             break;
276
277         case ACCELERATIONX:
278         case ACCELERATIONZ:
279             ICO_DBG("%s(D-bus I/F Result) = %d", vic_data[i].name,
280                       vic_val[0].u16_val);
281             /* Drawing update */
282             sprintf(vic_str, "%d", vic_val[0].u16_val);
283             elm_object_text_set(Ad.vic_val_text[i], vic_str);
284             break;
285
286         case SHIFTPOSITION:
287             ICO_DBG("%s(D-bus I/F Result) = %d", vic_data[i].name,
288                       vic_val[0].byte_val);
289             /* Drawing update */
290             sprintf(vic_str, "%d", vic_val[0].byte_val);
291             elm_object_text_set(Ad.vic_val_text[i], vic_str);
292             break;
293
294         case ENGINESPEED:
295         case DIRECTION:
296         case WHEELBRAKEPRESSURE:
297         case ACCELERATIONY:
298             ICO_DBG("%s(D-bus I/F Result) = %d", vic_data[i].name,
299                       vic_val[0].i32_val);
300             sprintf(vic_str, "%d", vic_val[0].i32_val);
301             elm_object_text_set(Ad.vic_val_text[i], vic_str);
302             break;
303
304         case LATITUDE:
305         case ALTITUDE:
306         case LONGITUDE:
307             ICO_DBG("%s(D-bus I/F Result) = %f", vic_data[i].name,
308                       vic_val[0].d_val);
309             sprintf(vic_str, "%f", vic_val[0].d_val);
310             elm_object_text_set(Ad.vic_val_text[i], vic_str);
311             break;
312
313         case GEARPOSITION:
314         case MODE:
315         case EXTERIORBRIGHTNESS:
316             ICO_DBG("%s(D-bus I/F Result) = %d", vic_data[i].name,
317                       vic_val[0].byte_val);
318             sprintf(vic_str, "%d", vic_val[0].byte_val);
319             elm_object_text_set(Ad.vic_val_text[i], vic_str);
320             break;
321
322         case LEFTTURN:
323         case RIGHTTURN:
324         case BRAKESIGNAL:
325             ICO_DBG("%s(D-bus I/F Result) = %d", vic_data[i].name,
326                       vic_val[0].b_val);
327             if (vic_val[0].b_val == TRUE) {
328                 sprintf(vic_str, "%s", "true");
329             }
330             else {
331                 sprintf(vic_str, "%s", "false");
332             }
333             elm_object_text_set(Ad.vic_val_text[i], vic_str);
334             break;
335
336         default:
337             ICO_DBG("Err no property : %s\n", vic_data[i].name);
338             break;
339         }
340     }
341     return;
342 }
343
344 static void _on_mousedown(void *data, Evas_Object *obj, void *event_info)
345 {
346     drawVehicleInfo();
347     return;
348 }
349
350 static void _on_ctg_mousedown(void *data, Evas_Object *obj, void *event_info)
351 {
352     int category = -1;
353     if (data != NULL) {
354         category = *((int *) data);
355     }
356
357     if ((category != -1) && (category != ListDispSts)) {
358         if (ListDispSts != -1) {
359             evas_object_color_set(Ad.ctg_btn[ListDispSts], 255, 255, 255,
360                                   255);
361             evas_object_hide(Ad.vic_li[ListDispSts]);
362         }
363         else {
364             evas_object_hide(Ad.vic_ini_li);
365             elm_list_clear(Ad.vic_ini_li);
366         }
367         evas_object_color_set(Ad.ctg_btn[category], 0, 255, 255, 255);
368
369         elm_list_go(Ad.vic_li[category]);
370         evas_object_show(Ad.vic_li[category]);
371
372         ListDispSts = category;
373
374     }
375     return;
376 }
377
378 /* Get the vehicle information than AMB */
379 static int getVehicleInfo(int key, union VicVal_t *vic_val_p)
380 {
381     /* local variable */
382     DBusMessage *message;
383     DBusError error;
384     int result = 0;
385     const char *v_string[] = {
386         vic_data[key].interface_name,
387         vic_data[key].property_name
388     };
389     const char *dest = Bus_name;
390     DBusMessage *reply;
391     int reply_timeout = 1000;   /* Millisecond */
392     DBusMessageIter iter;
393     DBusMessageIter iter_array;
394
395     /* initialize */
396     dbus_error_init(&error);
397
398     if (NULL == g_connection) {
399         /* obtain the right to use dbus */
400         g_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
401
402         if (g_connection == NULL) {
403             ICO_DBG("Err dbus_bus_get");
404
405             /* Release err parameter */
406             dbus_error_free(&error);
407             return -1;
408         }
409     }
410     /* Constructs a new message */
411     message = dbus_message_new_method_call(DBUS_SERVICE,
412                                            vic_data[key].path_name,
413                                            DBUS_INTERFACE, DBUS_METHOD);
414     if (message == NULL) {
415         ICO_DBG("Err dbus_message_new_method_call");
416
417         /* Release the connection */
418         dbus_connection_unref(g_connection);
419         g_connection = NULL;
420         return -1;
421     }
422
423     /* Gets the type of a message */
424     result = dbus_message_append_args(message,
425                                       DBUS_TYPE_STRING,
426                                       &v_string[0],
427                                       DBUS_TYPE_STRING,
428                                       &v_string[1], DBUS_TYPE_INVALID);
429     if (!result) {
430         ICO_DBG("Err dbus_message_append_args");
431
432         /* Release the connection */
433         dbus_connection_unref(g_connection);
434         g_connection = NULL;
435         /* Release the message */
436         dbus_message_unref(message);
437
438         return -1;
439     }
440
441     /* Gets the error name */
442     if ((dest) && (!dbus_message_set_destination(message, dest))) {
443         ICO_DBG("Err dbus_message_new_method_call");
444
445         /* Release the connection */
446         dbus_connection_unref(g_connection);
447         g_connection = NULL;
448
449         /* Release the message */
450         dbus_message_unref(message);
451
452         return -1;
453     }
454
455     /* Queues a message to send */
456     reply = dbus_connection_send_with_reply_and_block(g_connection,
457                                                       message,
458                                                       reply_timeout, &error);
459     if (reply == NULL) {
460         ICO_DBG("Err dbus_connection_send_with_reply_and_block");
461
462         /* Release the connection */
463         dbus_connection_unref(g_connection);
464         g_connection = NULL;
465
466         /* Release the message */
467         dbus_message_unref(message);
468
469         /* Release err parameter */
470         dbus_error_free(&error);
471
472         return -1;
473     }
474
475     /* Gets the result */
476     dbus_message_iter_init(reply, &iter);
477     dbus_message_iter_recurse(&iter, &iter_array);
478
479     /* Type conversion of the resulting value */
480 //    result = parse_elementary_value(vic_val_p, &iter_array);
481     union VicVal_t *tmp_vic_val_p = vic_val_p;  //TEST
482     result = parse_value(tmp_vic_val_p, &iter_array);   //TEST
483
484     if (result != TRUE) {
485         ICO_DBG("Err parse_elementary_value");
486
487         /* Release the connection */
488         dbus_connection_unref(g_connection);
489         g_connection = NULL;
490
491         /* Release the message */
492         dbus_message_unref(message);
493         dbus_message_unref(reply);
494
495         return -1;
496     }
497
498     /* Release the message */
499     dbus_message_unref(message);
500     dbus_message_unref(reply);
501
502     return 0;
503 }
504
505 /* Parse of the value */
506 static bool parse_elementary_value(union VicVal_t *vic_val_p,
507                                    DBusMessageIter *iter)
508 {
509     dbus_int32_t i32_val;
510     dbus_int32_t i16_val;
511     dbus_uint32_t u32_val;
512     dbus_uint16_t u16_val;
513     uint8_t byte_val;
514     dbus_bool_t b_val;
515     double d_val;
516     char *s_val;
517     char *w_s_val;
518
519     char sig;
520
521     if ((vic_val_p == NULL) || (iter == NULL)) {
522         ICO_DBG("Err Parameter NG ");
523         return FALSE;
524     }
525
526     sig = dbus_message_iter_get_arg_type(iter);
527
528     switch (sig) {
529     case DBUS_TYPE_INT32:
530         dbus_message_iter_get_basic(iter, &i32_val);
531         vic_val_p->i32_val = i32_val;
532         vic_val_p++;
533         break;
534     case DBUS_TYPE_INT16:
535         dbus_message_iter_get_basic(iter, &i16_val);
536         vic_val_p->i16_val = i16_val;
537         vic_val_p++;
538         break;
539     case DBUS_TYPE_UINT32:
540         dbus_message_iter_get_basic(iter, &u32_val);
541         vic_val_p->u32_val = u32_val;
542         vic_val_p++;
543         break;
544     case DBUS_TYPE_UINT16:
545         dbus_message_iter_get_basic(iter, &u16_val);
546         vic_val_p->u16_val = u16_val;
547         vic_val_p++;
548         break;
549     case DBUS_TYPE_BOOLEAN:
550         dbus_message_iter_get_basic(iter, &b_val);
551         vic_val_p->b_val = b_val;
552         vic_val_p++;
553         break;
554     case DBUS_TYPE_BYTE:
555         dbus_message_iter_get_basic(iter, &byte_val);
556         vic_val_p->byte_val = byte_val;
557         vic_val_p++;
558         break;
559     case DBUS_TYPE_DOUBLE:
560         dbus_message_iter_get_basic(iter, &d_val);
561         vic_val_p->d_val = d_val;
562         vic_val_p++;
563         break;
564     case DBUS_TYPE_STRING:
565         dbus_message_iter_get_basic(iter, &s_val);
566         w_s_val = (char *) malloc(strlen(s_val) + 1);   // Release required
567         if (w_s_val == NULL) {
568             ICO_DBG("Err malloc");
569             return FALSE;
570         }
571         strncpy(w_s_val, s_val, strlen(s_val));
572         vic_val_p->s_val = w_s_val;
573         vic_val_p++;
574 //        vic_val_p->s_val = s_val;
575         break;
576     default:
577         ICO_DBG("Err parse_elementary_value: unknown type");
578         return FALSE;
579     }
580
581     return TRUE;
582 }
583
584 static bool parse_value(union VicVal_t *vic_val_p, DBusMessageIter *iter)
585 {
586     char curr;
587
588     if ((vic_val_p == NULL) || (iter == NULL)) {
589         ICO_DBG("Err Parameter NG ");
590         return FALSE;
591     }
592
593     curr = dbus_message_iter_get_arg_type(iter);
594
595     switch (curr) {
596     case DBUS_TYPE_BYTE:
597     case DBUS_TYPE_BOOLEAN:
598     case DBUS_TYPE_INT16:
599     case DBUS_TYPE_INT32:
600     case DBUS_TYPE_UINT16:
601     case DBUS_TYPE_UINT32:
602     case DBUS_TYPE_DOUBLE:
603     case DBUS_TYPE_STRING:
604         return parse_elementary_value(vic_val_p, iter);
605     case DBUS_TYPE_ARRAY:
606         return parse_array(vic_val_p, iter);
607     case DBUS_TYPE_STRUCT:
608         return parse_struct(vic_val_p, iter);
609     case DBUS_TYPE_DICT_ENTRY:
610 //            goto error; /* these are handled from parse_array */
611         return FALSE;
612     case DBUS_TYPE_INVALID:
613         return TRUE;
614     default:
615         break;
616     }
617     return FALSE;
618 }
619
620 static bool parse_array(union VicVal_t *vic_val_p, DBusMessageIter *iter)
621 {
622     DBusMessageIter new_iter;
623     int element_type;
624
625     if ((vic_val_p == NULL) || (iter == NULL)) {
626         ICO_DBG("Err Parameter NG ");
627         return FALSE;
628     }
629
630     /* the lua array */
631 //    lua_newtable(L);
632
633     element_type = dbus_message_iter_get_element_type(iter);
634
635     dbus_message_iter_recurse(iter, &new_iter);
636
637     /* the problem: if the value inside array is a dict entry, the
638      * indexing of elements need to be done with dict keys instead
639      * of numbers. */
640
641     if (element_type == DBUS_TYPE_DICT_ENTRY) {
642         while (dbus_message_iter_get_arg_type(&new_iter) != DBUS_TYPE_INVALID) {
643
644             parse_dict_entry(vic_val_p, &new_iter);
645             dbus_message_iter_next(&new_iter);
646         }
647     }
648
649     else {
650         while (dbus_message_iter_get_arg_type(&new_iter) != DBUS_TYPE_INVALID) {
651
652             /* array index */
653 //            lua_pushinteger(L, i++);
654
655             parse_value(vic_val_p, &new_iter);
656             dbus_message_iter_next(&new_iter);
657
658             /* put the values to the table */
659 //            lua_settable(L, -3);
660         }
661     }
662
663     return TRUE;
664 }
665
666 static bool parse_dict_entry(union VicVal_t *vic_val_p,
667                              DBusMessageIter *iter)
668 {
669     DBusMessageIter new_iter;
670
671     if ((vic_val_p == NULL) || (iter == NULL)) {
672         ICO_DBG("Err Parameter NG ");
673         return FALSE;
674     }
675
676     dbus_message_iter_recurse(iter, &new_iter);
677
678     while (dbus_message_iter_get_arg_type(&new_iter) != DBUS_TYPE_INVALID) {
679
680         /* key must be elementary, value can be anything */
681
682         parse_elementary_value(vic_val_p, &new_iter);
683         dbus_message_iter_next(&new_iter);
684
685         parse_value(vic_val_p, &new_iter);
686         dbus_message_iter_next(&new_iter);
687
688         /* put the values to the table */
689 //        lua_settable(L, -3);
690     }
691
692     return TRUE;
693 }
694
695 static bool parse_struct(union VicVal_t *vic_val_p, DBusMessageIter *iter)
696 {
697     DBusMessageIter new_iter;
698
699     if ((vic_val_p == NULL) || (iter == NULL)) {
700         ICO_DBG("Err Parameter NG ");
701         return FALSE;
702     }
703
704     /* initialize the table */
705 //    lua_newtable(L);
706
707     dbus_message_iter_recurse(iter, &new_iter);
708
709     while (dbus_message_iter_get_arg_type(&new_iter) != DBUS_TYPE_INVALID) {
710
711         /* struct "index" */
712 //        lua_pushinteger(L, i++);
713
714         parse_value(vic_val_p, &new_iter);
715         dbus_message_iter_next(&new_iter);
716
717         /* put the values to the table */
718 //        lua_settable(L, -3);
719     }
720
721     return TRUE;
722 }
723
724 /* Read configuration file */
725 static int get_config(void)
726 {
727     ICO_DBG("ENTER get_config");
728
729     FILE *fp;
730     int k = 0;
731     int j, m;
732     char buff[512];
733     char *tp;
734     char *clm = " \n";
735
736     fp = fopen(CONFIG_FILE, "r");
737     if (fp == NULL) {
738         ICO_DBG("File open error");
739         return -1;
740     }
741
742     for (m = 0; k < MAX_PARA_NUM; m++) {
743         if (fgets(buff, sizeof(buff) - 2, fp) != NULL) {
744             tp = strtok(buff, clm);
745             if (tp != NULL) {
746                 if (tp[0] != '#') {
747                     for (j = 0; vic_key_data[j].id != -1; j++) {
748                         if (strcmp(tp, vic_key_data[j].name) == 0) {
749                             vic_data[k].property = vic_key_data[j].id;
750                             vic_data[k].category = vic_key_data[j].category;
751                             strcpy(vic_data[k].name, tp);
752                             strcpy(vic_data[k].path_name, strtok(NULL, clm));
753                             strcpy(vic_data[k].interface_name,
754                                    strtok(NULL, clm));
755                             strcpy(vic_data[k].property_name,
756                                    strtok(NULL, clm));
757                             ICO_DBG("vic_data[%d].property=%d", k,
758                                       vic_data[k].property);
759                             ICO_DBG("vic_data[%d].name=%s", k,
760                                       vic_data[k].name);
761                             ICO_DBG("vic_data[%d].path_name=%s", k,
762                                       vic_data[k].path_name);
763                             ICO_DBG("vic_data[%d].interface_name=%s", k,
764                                       vic_data[k].interface_name);
765                             ICO_DBG("vic_data[%d].property_name=%s", k,
766                                       vic_data[k].property_name);
767
768                             k++;
769                             break;
770                         }
771                     }
772                     if (vic_key_data[j].id == -1) {
773                         ICO_DBG
774                             ("Err vicsample_config.txt Line:%d Unregistered"
775                              " parameter name", m + 1);
776                     }
777
778                 }
779                 else {
780                     ICO_DBG
781                         ("vicsample_config.txt Line:%d Comment out  '#'Discovery",
782                          m + 1);
783                 }
784             }
785             else {
786                 ICO_DBG
787                     ("vicsample_config.txt Line:%d Comment out  Null line",
788                      m + 1);
789             }
790         }
791         else {
792             ICO_DBG("vicsample_config.txt The end of data reading");
793             break;
794         }
795     }
796     fclose(fp);
797
798     property_num = k;
799     if (property_num == 0) {
800         ICO_DBG("vicsample_config.txt No valid data");
801         return -1;
802     }
803
804     ICO_DBG("LEAVE get_config");
805     return 0;
806 }
807 #if 0
808 static void res_callback(ico_apf_resource_notify_info_t *info,
809                          void *user_data)
810 {
811     int ret;
812
813     ICO_DBG("##==> Callbacked evt=%d res=%d id=%d bid=%d appid=%s dev=%s"
814               " user_data=%d", info->state, info->resid, info->id,
815               info->bid, info->appid, info->device, (int) user_data);
816     switch (info->state) {
817     case ICO_APF_RESOURCE_STATE_ACQUIRED:
818     case ICO_APF_RESOURCE_STATE_DEPRIVED:
819     case ICO_APF_RESOURCE_STATE_WAITTING:
820     case ICO_APF_RESOURCE_STATE_RELEASED:
821         if (info->resid == ICO_APF_RESID_INT_SCREEN) {
822             ret = ico_apf_resource_reply_int_screen_mode(info->device,
823                                                          info->bid, info->id,
824                                                          1);
825             ICO_DBG("##==> callback reply int_screen(%s,%d,%d,1) = %d",
826                       info->device, info->bid, info->id, ret);
827         }
828         else if (info->resid == ICO_APF_RESID_ON_SCREEN) {
829             ret = ico_apf_resource_reply_int_screen_mode_disp(info->device,
830                                                               info->id, 1);
831             ICO_DBG("##==> callback reply on_screen(%s,%d,1) = %d",
832                       info->device, info->id, ret);
833         }
834         else {
835             ret =
836                 ico_apf_resource_reply_screen_mode(info->device, info->id, 1);
837             ICO_DBG("##==> callback reply screen(%s,%d,1) = %d",
838                       info->device, info->id, ret);
839         }
840         break;
841     default:
842         /* NOP  */
843         break;
844     }
845 }
846 #endif
847 /**
848  * @breif _winCreate
849  */
850 static void _winCreate(void)
851 {
852     ICO_DBG("ENTER _winCreate");
853
854     int i;
855     double w_mag;
856     double h_mag;
857
858     if (NULL == Ad.win) {
859         ICO_DBG("Err Param NG");
860         return;
861     }
862
863     w_mag = Width / WIDTH;
864     h_mag = Height / HEIGHT;
865     ICO_DBG("Width =%f,Height=%f", Width, Height);
866     ICO_DBG("w_mag =%f,h_magh=%f", w_mag, h_mag);
867
868     Ad.scrn_type = elm_label_add(Ad.win);
869     elm_object_text_set(Ad.scrn_type, SscrnType);
870     evas_object_resize(Ad.scrn_type, SCRN_TYPE_W * w_mag,
871                        SCRN_TYPE_H * h_mag);
872     evas_object_move(Ad.scrn_type, SCRN_TYPE_X * w_mag, SCRN_TYPE_Y * h_mag);
873     evas_object_show(Ad.scrn_type);
874
875     Ad.ctg_bx = elm_box_add(Ad.win);
876     evas_object_resize(Ad.ctg_bx, CTG_BX_W * w_mag, CTG_BX_H * h_mag);
877     evas_object_move(Ad.ctg_bx, CTG_BX_X * w_mag, CTG_BX_Y * h_mag);
878     evas_object_show(Ad.ctg_bx);
879
880     Ad.ctg_bx2 = elm_box_add(Ad.win);
881     evas_object_resize(Ad.ctg_bx2, CTG_BX_W * w_mag , CTG_BX_H * h_mag);
882     evas_object_move(Ad.ctg_bx2, (CTG_BX_X + CTG_BX_W) * w_mag, CTG_BX_Y * h_mag);
883     evas_object_show(Ad.ctg_bx2);
884
885     for (i = 0; i < MAX_CATEGORY_NUM; i++) {
886         /* category buttn create */
887         Ad.ctg_btn[i] = elm_button_add(Ad.win);
888         elm_object_text_set(Ad.ctg_btn[i], vic_category_data[i].name);
889         if (i < (MAX_CATEGORY_NUM / 2)) { 
890             elm_box_pack_end(Ad.ctg_bx, Ad.ctg_btn[i]);
891         }
892         else {
893             elm_box_pack_end(Ad.ctg_bx2, Ad.ctg_btn[i]);
894         }
895
896         /* The present category to support "Running Status" "Eenvironment" */
897         if ((vic_category_data[i].category == RUNNINGSTATUS)
898             || (vic_category_data[i].category == ENVIRONMENT)) {
899             evas_object_smart_callback_add(Ad.ctg_btn[i], "clicked",
900                                            _on_ctg_mousedown,
901                                            &(vic_category_data[i].category));
902         }
903         else {
904             /* Unsupported Grayout */
905             evas_object_color_set(Ad.ctg_btn[i], 128, 128, 128, 255);
906         }
907
908         evas_object_size_hint_weight_set(Ad.ctg_btn[i], EVAS_HINT_EXPAND, 0);
909         evas_object_size_hint_align_set(Ad.ctg_btn[i], EVAS_HINT_FILL, 0);
910         evas_object_show(Ad.ctg_btn[i]);
911
912         /* list create */
913         Ad.vic_li[i] = elm_list_add(Ad.win);
914         elm_list_select_mode_set(Ad.vic_li[i], ELM_OBJECT_SELECT_MODE_NONE);
915         evas_object_resize(Ad.vic_li[i], VIC_LI_W * w_mag, VIC_LI_H * h_mag);
916         evas_object_move(Ad.vic_li[i], VIC_LI_X * w_mag, VIC_LI_Y * h_mag);
917     }
918
919     /* Initial list display */
920     Ad.vic_ini_li = elm_list_add(Ad.win);
921     elm_list_select_mode_set(Ad.vic_ini_li, ELM_OBJECT_SELECT_MODE_NONE);
922     evas_object_resize(Ad.vic_ini_li, VIC_LI_W * w_mag, VIC_LI_H * h_mag);
923     evas_object_move(Ad.vic_ini_li, VIC_LI_X * w_mag, VIC_LI_Y * h_mag);
924     elm_list_item_append(Ad.vic_ini_li, NULL, NULL, NULL, NULL, NULL);
925     elm_list_go(Ad.vic_ini_li);
926     evas_object_show(Ad.vic_ini_li);
927
928     Ad.get_btn = elm_button_add(Ad.win);
929     elm_object_text_set(Ad.get_btn, "Get VehicleInfo");
930     evas_object_smart_callback_add(Ad.get_btn, "clicked", _on_mousedown,
931                                    NULL);
932     evas_object_resize(Ad.get_btn, GET_BTN_W * w_mag, GET_BTN_H * h_mag);
933     evas_object_move(Ad.get_btn, GET_BTN_X * w_mag, GET_BTN_Y * h_mag);
934     evas_object_show(Ad.get_btn);
935
936     ICO_DBG("LEAVE _winCreate");
937     return;
938 }
939
940 /**
941  * @brief elmListCreate
942  */
943 static void elmListCreate(void)
944 {
945     ICO_DBG("ENTER elmListCreate");
946
947     int i;
948
949     if (NULL == Ad.win) {
950         ICO_DBG("Err Param NG");
951         return;
952     }
953
954     for (i = 0; vic_key_data[i].id != -1 && i < MAX_PARA_NUM; i++) {
955         Ad.vic_val_text[i] = elm_label_add(Ad.win);
956         elm_list_item_append(Ad.vic_li[vic_data[i].category],
957                              vic_data[i].name, NULL, Ad.vic_val_text[i], NULL,
958                              NULL);
959     }
960
961     /* dummy set */
962     for (i = 0; i < MAX_CATEGORY_NUM; i++) {
963         Ad.vic_val_dmy_text[i] = elm_label_add(Ad.win);
964         elm_list_item_append(Ad.vic_li[i], NULL, NULL, NULL, NULL, NULL);
965     }
966
967     ICO_DBG("LEAVE elmListCreate");
968     return;
969 }
970
971 /**
972  * @brief app_terminate
973  */
974 static void app_terminate(void *data)
975 {
976     ICO_DBG("ENTER app_terminate");
977     // Release all resources
978     int i;
979
980     if (Ad.win) {
981         evas_object_del(Ad.win);
982         Ad.win = NULL;
983     }
984
985     if (Ad.bg) {
986         evas_object_del(Ad.bg);
987         Ad.bg = NULL;
988     }
989
990     if (Ad.scrn_type) {
991         evas_object_del(Ad.scrn_type);
992         Ad.scrn_type = NULL;
993     }
994
995     if (Ad.ctg_bx) {
996         evas_object_del(Ad.ctg_bx);
997         Ad.ctg_bx = NULL;
998     }
999
1000     if (Ad.ctg_bx2) {
1001         evas_object_del(Ad.ctg_bx2);
1002         Ad.ctg_bx2 = NULL;
1003     }
1004
1005     for (i = 0; i < MAX_CATEGORY_NUM; i++) {
1006         if (Ad.ctg_btn[i]) {
1007             evas_object_del(Ad.ctg_btn[i]);
1008             Ad.ctg_btn[i] = NULL;
1009         }
1010
1011         if (Ad.vic_li[i]) {
1012             evas_object_del(Ad.vic_li[i]);
1013             Ad.vic_li[i] = NULL;
1014         }
1015
1016         if (Ad.vic_val_dmy_text[i]) {
1017             evas_object_del(Ad.vic_val_dmy_text[i]);
1018             Ad.vic_val_dmy_text[i] = NULL;
1019         }
1020     }
1021
1022     if (Ad.vic_ini_li) {
1023         evas_object_del(Ad.vic_ini_li);
1024         Ad.vic_ini_li = NULL;
1025     }
1026
1027     for (i = 0; i < MAX_PARA_NUM; i++) {
1028         if (Ad.vic_val_text[i]) {
1029             evas_object_del(Ad.vic_val_text[i]);
1030             Ad.vic_val_text[i] = NULL;
1031         }
1032     }
1033
1034     if (Ad.get_btn) {
1035         evas_object_del(Ad.get_btn);
1036         Ad.get_btn = NULL;
1037     }
1038     ICO_DBG("LEAVE app_terminate");
1039     return;
1040 }
1041
1042 /**
1043  * @brief _win_del
1044  */
1045 static void _win_del(void *data, Evas_Object *obj, void *event_info)
1046 {
1047     ICO_DBG("ENTER _win_del");
1048
1049     elm_exit();
1050
1051     ICO_DBG("LEAVE _win_del");
1052     return;
1053 }
1054
1055 /**
1056  * @brief _create_win
1057  */
1058 static Evas_Object *_create_win(const char *name)
1059 {
1060     ICO_DBG("ENTER _create_win");
1061
1062     Evas_Object *eo;
1063 //    int w, h;
1064     eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
1065     if (eo) {
1066         elm_win_title_set(eo, name);
1067         evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
1068 //        ecore_x_window_size_get(ecore_x_window_root_first_get(), &w,
1069 //                                &h);
1070 //      ICO_DBG("window size w=%d,h=%d",w,h);
1071 //        evas_object_resize(eo, w, h - STATUS_BAR_HEIGHT);
1072     }
1073     ICO_DBG("LEAVE _create_win");
1074
1075     return eo;
1076 }
1077
1078 /**
1079  * @brief app_create
1080  */
1081 static bool app_create(void *data)
1082 {
1083     ICO_DBG("ENTER app_create");
1084
1085 #if 0 //TEST.s
1086     int w, h;
1087
1088     /* get display size */
1089     ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
1090     ICO_DBG("window size w=%d,h=%d", w, h);
1091
1092     /* set app screen size */
1093     Width = w;
1094     Height = h - STATUS_BAR_HEIGHT;
1095 #else
1096     Width = WIDTH;
1097     Height = HEIGHT;
1098 #endif //TEST.e
1099
1100     /* main widnow */
1101     Ad.win = _create_win(PACKAGE);
1102     if (Ad.win == NULL) {
1103         return FALSE;
1104     }
1105     evas_object_show(Ad.win);
1106
1107     elm_win_indicator_mode_set(Ad.win, ELM_WIN_INDICATOR_SHOW);
1108     elm_win_fullscreen_set(Ad.win, EINA_TRUE);
1109
1110     Ad.bg = elm_bg_add(Ad.win);
1111     elm_win_resize_object_add(Ad.win, Ad.bg);
1112     evas_object_size_hint_weight_set(Ad.bg, EVAS_HINT_EXPAND,
1113                                      EVAS_HINT_EXPAND);
1114     elm_bg_file_set(Ad.bg, BG_IMAGE_FILE, NULL);
1115     evas_object_show(Ad.bg);
1116
1117     evas_object_resize(Ad.win, Width, Height);
1118
1119     /* set font size */
1120     (void)elm_config_font_overlay_set(TEXT_LIST_ITEM, FONT_FAMILY, FONT_SIZE);
1121     (void)elm_config_font_overlay_set(TEXT_BUTTON, FONT_FAMILY, FONT_SIZE);
1122     (void)elm_config_font_overlay_set(TEXT_LABEL, FONT_FAMILY, FONT_SIZE);
1123     (void)elm_config_font_overlay_apply();
1124
1125     _winCreate();
1126
1127     elmListCreate();
1128
1129     ICO_DBG("LEAVE app_create");
1130
1131     return TRUE;                /* EXIT_SUCCESS */
1132 }
1133 #if 0
1134 /**
1135  * @brief get_screen
1136  */
1137 static int get_screen(int argc, char **argv)
1138 {
1139     ICO_DBG("ENTER get_screen");
1140
1141     int getscreen;
1142     bundle *b;
1143     const char *val;
1144
1145     b = bundle_import_from_argv(argc, argv);
1146     getscreen = 0;
1147     SscrnType[0] = 0;
1148     if (b != NULL) {
1149         val = bundle_get_val(b, "rightoption");
1150         if (val != NULL) {
1151             if (strcasecmp(val, "-basescreen") == 0) {
1152                 getscreen = 1;  /* get base screen */
1153                 strcpy(SscrnType, "BasicScreen");
1154                 ICO_DBG("BasicScreen");
1155             }
1156             else if (strcasecmp(val, "-intscreen") == 0) {
1157                 getscreen = 2;  /* get interrupt screen */
1158                 strcpy(SscrnType, "IntScreen");
1159             }
1160             else if (strcasecmp(val, "-onscreen") == 0) {
1161                 getscreen = 3;  /* get on screen */
1162                 strcpy(SscrnType, "OnScreen");
1163             }
1164         }
1165     }
1166
1167     if (getscreen > 0) {
1168         /* initialize resource control for Ecore */
1169         if (ico_apf_ecore_init(NULL) != ICO_APF_E_NONE) {
1170             ICO_DBG("ico_apf_ecore_init() Error");
1171             ecore_evas_shutdown();
1172             return -1;
1173         }
1174
1175         /* set resource request callback */
1176         ico_apf_resource_set_event_cb(res_callback, NULL);
1177
1178         /* acquire a right to display a screen */
1179         if (getscreen == 1) {
1180             ico_apf_resource_get_screen_mode(NULL, 0);
1181         }
1182         else if (getscreen == 2) {
1183             ico_apf_resource_get_int_screen_mode(NULL, 0, 0);
1184         }
1185         else {
1186             ico_apf_resource_get_int_screen_mode_disp(NULL, 0);
1187         }
1188     }
1189     ICO_DBG("LEAVE get_screen");
1190     return 0;
1191 }
1192 #endif
1193
1194 int main(int argc, char *argv[])
1195 {
1196 //    char appid[ICO_UXF_MAX_PROCESS_NAME + 1];
1197     char appid[256];
1198     int pid;
1199     app_event_callback_s event_callback;
1200     int result = 0;
1201
1202     if (!ecore_evas_init()) {
1203         return EXIT_FAILURE;
1204     }
1205
1206     /* Setting the log output */
1207 //    if (ico_apf_get_app_id(0, appid) == ICO_APP_CTL_E_NONE) {
1208 //        ico_apf_log_open(appid);
1209 //    }
1210
1211     /* Setting the log output */
1212     memset(appid, 0, sizeof(appid));
1213     pid = getpid();
1214     if (aul_app_get_appid_bypid(pid, appid, sizeof(appid)) == AUL_R_OK) {
1215         ico_log_open(appid);
1216     }
1217     else {
1218         ico_log_open("org.tizen.ico.app-vicsample");
1219     }
1220
1221     ICO_DBG("ENTER main");
1222
1223     /* Read configuration file */
1224     if (get_config() != 0) {
1225         ICO_DBG("Err get_config");
1226         return EXIT_FAILURE;
1227     }
1228
1229     /* get argument */
1230 //    if (get_screen(argc, argv) != 0) {
1231 //        ICO_DBG("Err get_argument");
1232 //        return EXIT_FAILURE;
1233 //    }
1234
1235     /* set callback fanc */
1236     event_callback.create = app_create;
1237     event_callback.terminate = app_terminate;
1238     event_callback.pause = NULL;
1239     event_callback.resume = NULL;
1240     event_callback.service = NULL;
1241     event_callback.low_memory = NULL;
1242     event_callback.low_battery = NULL;
1243     event_callback.device_orientation = NULL;
1244     event_callback.language_changed = NULL;
1245     event_callback.region_format_changed = NULL;
1246
1247     memset(&Ad, 0x0, sizeof(struct appdata_t));
1248
1249     result = app_efl_main(&argc, &argv, &event_callback, &Ad);
1250
1251 //    ico_apf_ecore_term();
1252     ecore_evas_shutdown();
1253
1254     if (NULL != g_connection) {
1255         dbus_connection_unref(g_connection);
1256         g_connection = NULL;
1257     }
1258     ICO_DBG("EXIT main");
1259
1260     return result;
1261 }