Package upload
[framework/uifw/edbus.git] / src / bin / e_dbus_ukit_test.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <E_Ukit.h>
6 #include <E_DBus.h>
7 #include <Ecore.h>
8 #include <stdio.h>
9
10 static E_DBus_Connection *econ = NULL;
11
12 Eina_Bool
13 print_prop(const Eina_Hash *hash, const void *key, void *data, __UNUSED__ void *fdata)
14 {
15    const Eina_List *strlist, *l;
16    char *y;
17    E_Ukit_Property *p = data;
18    E_Ukit_Properties props;
19    int err = 0;
20
21    props.properties = (Eina_Hash*)hash;
22    switch (p->type)
23      {
24         case E_UKIT_PROPERTY_TYPE_STRING:
25           printf("\t%s = [%s]\n", (char*)key, e_ukit_property_string_get(&props, key, &err));
26           break;
27         case E_UKIT_PROPERTY_TYPE_INT:
28           printf("\t%s = [%d]\n", (char*)key, e_ukit_property_int_get(&props, key, &err));
29           break;
30         case E_UKIT_PROPERTY_TYPE_UINT32:
31           printf("\t%s = [%llu]\n", (char*)key, (long long unsigned)e_ukit_property_uint32_get(&props, key, &err));
32           break;
33         case E_UKIT_PROPERTY_TYPE_UINT64:
34           printf("\t%s = [%llu]\n", (char*)key, (long long unsigned)e_ukit_property_uint64_get(&props, key, &err));
35           break;
36         case E_UKIT_PROPERTY_TYPE_INT64:
37           printf("\t%s = [%lld]\n", (char*)key, (long long int)e_ukit_property_int64_get(&props, key, &err));
38           break;
39         case E_UKIT_PROPERTY_TYPE_BOOL:
40           printf("\t%s = [%d]\n", (char*)key, e_ukit_property_bool_get(&props, key, &err));
41           break;
42         case E_UKIT_PROPERTY_TYPE_DOUBLE:
43           printf("\t%s = [%f]\n", (char*)key, e_ukit_property_double_get(&props, key, &err));
44           break;
45         case E_UKIT_PROPERTY_TYPE_STRLIST:
46           printf("\t%s = [", (char*)key);
47           strlist = e_ukit_property_strlist_get(&props, key, &err);
48           EINA_LIST_FOREACH(strlist, l, y)
49            printf("%s%s", y, (l->next) ? " " : "");
50           printf("]\n");
51           break;
52      }
53
54    return EINA_TRUE;
55 }
56
57 static void
58 hash_props(void *user_data, void *reply_data, DBusError *error)
59 {
60    printf("%s:\n", (char*)user_data);
61    E_Ukit_Get_All_Properties_Return *ret = reply_data;
62
63    if (!ret || dbus_error_is_set(error))
64      {
65         free(user_data);
66         dbus_error_free(error);
67         return;
68      }
69
70    eina_hash_foreach(ret->properties, print_prop, NULL);
71    printf("\n");
72    free(user_data);
73 }
74
75 static void
76 test_mount(void *user_data, void *reply_data, DBusError *error)
77 {
78    E_Ukit_Get_Property_Return *ret = reply_data;
79
80    if (!ret || dbus_error_is_set(error))
81      {
82         free(user_data);
83         dbus_error_free(error);
84         return;
85      }
86
87    if (ret->val.b)
88      {
89         printf("[%s] is mounted!\n\tGrabbing more stats to fill your screen...\n", (char*)user_data);
90         e_udisks_get_all_properties(econ, user_data, hash_props, strdup(user_data));
91      }
92    else printf("[%s] is not mounted!\n", (char*)user_data);
93    free(user_data);
94 }
95
96 static void
97 print_devs(void *user_data, void *reply_data, DBusError *error)
98 {
99    E_Ukit_Get_All_Devices_Return *ret = reply_data;
100    Eina_List *l;
101    char *udi;
102
103    if (!ret || !ret->strings || dbus_error_is_set(error))
104      {
105         free(user_data);
106         dbus_error_free(error);
107         return;
108      }
109
110    EINA_LIST_FOREACH(ret->strings, l, udi)
111      {
112         if (!strcmp((char*)user_data, "disks"))
113           e_udisks_get_property(econ, udi, "DeviceIsMounted", test_mount, strdup(udi));
114         else
115           e_upower_get_all_properties(econ, udi, hash_props, strdup(udi));
116      }
117    free(user_data);
118 }
119
120 static Eina_Bool
121 my_quit(__UNUSED__ void *data)
122 {
123    ecore_main_loop_quit();
124    return ECORE_CALLBACK_CANCEL;
125 }
126
127 int main(void)
128 {
129    ecore_init();
130    eina_init();
131    e_dbus_init();
132    e_ukit_init();
133
134    econ = e_dbus_bus_get(DBUS_BUS_SYSTEM);
135    if (econ)
136      {
137         e_udisks_get_all_devices(econ, print_devs, strdup("disks"));
138         e_upower_get_all_devices(econ, print_devs, strdup("power"));
139      }
140    /*add a short timer to quit to try and ensure that all the tests run*/
141    ecore_timer_add(1, my_quit, NULL);
142    ecore_main_loop_begin();
143
144    if (econ) e_dbus_connection_close(econ);
145    e_ukit_shutdown();
146    e_dbus_shutdown();
147    eina_shutdown();
148    ecore_shutdown();
149    
150    return 0;
151 }