packaging: add AMB configuration that enables the plugin
[profile/ivi/ico-vic-amb-plugin.git] / tests / dbustest1.cc
1 #include <appcore-efl.h>
2 #include <Elementary.h>
3 #include <stdio.h>
4
5 #include <cassert>
6
7 #include <ico_dbus_amb_efl.h>
8
9 #include "ambconfig.h"
10 #include "logresult.h"
11
12 void notifyvalue(const char *objectname, const char *property, dbus_type type, union dbus_value_variant value, int sequence, struct timeval tv, void *user_data) {
13     enum ClientType cltype = CLIENT_APP;
14     enum CommandType cotype = CMDTYPE_NOTIFY;
15     LogResult *logger = reinterpret_cast<LogResult*>(user_data);
16     switch (type) {
17     case DBUS_TYPE_BYTE :
18         logger->PutOut(cltype, cotype, std::string(property), value.yval, tv);
19         break;
20     case DBUS_TYPE_BOOLEAN :
21         if (value.bval) {
22             logger->PutOut(cltype, cotype, std::string(property), true, tv);
23         }
24         else {
25             logger->PutOut(cltype, cotype, std::string(property), false, tv);
26         }
27         break;
28     case DBUS_TYPE_INT16 :
29         logger->PutOut(cltype, cotype, std::string(property), value.i16val, tv);
30         break;
31     case DBUS_TYPE_UINT16 :
32         logger->PutOut(cltype, cotype, std::string(property), value.ui16val, tv);
33         break;
34     case DBUS_TYPE_INT32 :
35         logger->PutOut(cltype, cotype, std::string(property), value.i32val, tv);
36         break;
37     case DBUS_TYPE_UINT32 :
38         logger->PutOut(cltype, cotype, std::string(property), value.ui32val, tv);
39         break;
40     case DBUS_TYPE_DOUBLE :
41         logger->PutOut(cltype, cotype, std::string(property), value.dval, tv);
42         break;
43     case DBUS_TYPE_STRING :
44         logger->PutOut(cltype, cotype, std::string(property), value.sval, tv);
45         break;
46     default :
47         break;
48     }
49     return;
50 }
51
52 EAPI int elm_main(int argc, char *argv[]) {
53     int ret;
54     std::string configpath = "/etc/ambd/AMBformat.conf";
55     while ((ret = getopt(argc, argv, "c:")) != -1) {
56         switch (ret) {
57         case 'c':
58             configpath = std::string(optarg);
59             break;
60         default :
61             break;
62         }
63     }
64
65     struct appcore_ops ops;
66     ops.create = NULL;
67     ops.resume = NULL;
68     ops.reset = NULL;
69     ops.pause = NULL;
70     ops.terminate = NULL;
71     ops.data = NULL;
72
73     assert(ico_dbus_amb_start() == 0);
74
75     AMBConfig config;
76     if (!config.readConfig(configpath)) {
77         std::cerr << "Can't read VIC-Plugin config file." << std::endl;
78         return -1;
79     }
80
81     std::vector<VehicleInfoDefine> vehicleinfolist =config.getVehicleInfoConfig();
82     LogResult logger;
83
84     auto itr_end = vehicleinfolist.end();
85     for (auto itr = vehicleinfolist.begin(); itr != itr_end; itr++) {
86         auto itr2_end = (*itr).status.end();
87         for (auto itr2 = (*itr).status.begin(); itr2 != itr2_end; itr2++) {
88             std::cerr << "dbusObjectName = " << (*itr2).dbusObjectName << ", dbusPropertyName = " << (*itr2).dbusPropertyName << std::endl;
89             switch ((*itr2).type) {
90             case INT : {
91                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_INT32, notifyvalue, &logger);
92                 break;
93             }
94             case DOUBLE : {
95                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_DOUBLE, notifyvalue, &logger);
96                 break;
97             }
98             case CHAR : {
99                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_BYTE, notifyvalue, &logger);
100                 break;
101             }
102             case INT16 : {
103                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_INT16, notifyvalue, &logger);
104                 break;
105             }
106             case UINT16 : {
107                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_UINT16, notifyvalue, &logger);
108                 break;
109             }
110             case UINT32 : {
111                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_UINT32, notifyvalue, &logger);
112                 break;
113             }
114             case INT64 : {
115                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_INT64, notifyvalue, &logger);
116                 break;
117             }
118             case UINT64 : {
119                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_UINT64, notifyvalue, &logger);
120                 break;
121             }
122             case BOOL : {
123                 ico_dbus_amb_subscribe((*itr2).dbusObjectName.c_str(), (*itr2).dbusPropertyName.c_str(), 0, DBUS_TYPE_BOOLEAN, notifyvalue, &logger);
124                 break;
125             }
126             default : {
127                 break;
128             }
129             }
130         }
131     }
132
133     appcore_efl_main("org.tizen.ico.testdbus", &argc, &argv, &ops);
134
135     assert(ico_dbus_amb_end() == 0);
136
137     elm_shutdown();
138     return 0;
139 }
140 ELM_MAIN()