EFL 1.7 svn doobies
[profile/ivi/e_dbus.git] / src / lib / ukit / e_udisks.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <E_Ukit.h>
6 #include "e_ukit_private.h"
7
8 #define E_UKIT_BUS E_UDISKS_BUS
9 #define E_UKIT_PATH E_UDISKS_PATH
10 #define E_UKIT_INTERFACE E_UDISKS_INTERFACE
11
12 const char *e_udisks_iface="org.freedesktop.UDisks.Device";
13
14 #if 0
15 static void cb_device_get_property(void *data, DBusMessage *msg, DBusError *err);
16 static void cb_device_get_all_properties(void *data, DBusMessage *msg, DBusError *err);
17 static void cb_device_query_capability(void *data, DBusMessage *msg, DBusError *err);
18 #endif
19
20 /* Properties.Get */
21 EAPI DBusPendingCall *
22 e_udisks_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data)
23 {
24    DBusMessage *msg;
25    DBusPendingCall *ret;
26
27    EINA_SAFETY_ON_NULL_RETURN_VAL(udi, NULL);
28    EINA_SAFETY_ON_TRUE_RETURN_VAL(!udi[0], NULL);
29    EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL);
30    EINA_SAFETY_ON_NULL_RETURN_VAL(property, NULL);
31
32    msg = e_ukit_property_call_new(udi, "Get");
33    dbus_message_append_args(msg, DBUS_TYPE_STRING, &e_udisks_iface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID);
34    ret = e_dbus_method_call_send(conn, msg, unmarshal_property, cb_func, free_property, -1, data);
35    dbus_message_unref(msg);
36    return ret;
37 }
38
39 /* Properties.GetAll */
40 EAPI DBusPendingCall *
41 e_udisks_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data)
42 {
43    DBusMessage *msg;
44    DBusPendingCall *ret;
45
46    EINA_SAFETY_ON_NULL_RETURN_VAL(udi, NULL);
47    EINA_SAFETY_ON_TRUE_RETURN_VAL(!udi[0], NULL);
48    EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL);
49
50    msg = e_ukit_property_call_new(udi, "GetAll");
51    dbus_message_append_args(msg, DBUS_TYPE_STRING, &e_udisks_iface, DBUS_TYPE_INVALID);
52    ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_all_properties, cb_func, free_device_get_all_properties, -1, data);
53    dbus_message_unref(msg);
54    return ret;
55 }
56
57
58
59 /* void FilesystemMount(string fstype, array{string}options) */
60
61 /**
62  * @brief Mount a Filesystem
63  *
64  * @param conn the E_DBus_Connection
65  * @param udi the udi of the device object
66  * @param fstype the fstype of the device (e.g. volume.fstype property)
67  * @param options a list of additional options to pass to mount
68  *
69  * @return mount point of fs or error
70  */
71 EAPI DBusPendingCall *
72 e_udisks_volume_mount(E_DBus_Connection *conn, const char *udi, const char *fstype, Eina_List *options)
73 {
74    DBusMessage *msg;
75    DBusMessageIter iter, subiter;
76    Eina_List *l;
77    DBusPendingCall *ret;
78
79    EINA_SAFETY_ON_NULL_RETURN_VAL(udi, NULL);
80    EINA_SAFETY_ON_TRUE_RETURN_VAL(!udi[0], NULL);
81    EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL);
82
83    msg = e_ukit_device_call_new(udi, "FilesystemMount");
84
85    dbus_message_iter_init_append(msg, &iter);
86    dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &fstype);
87    if (dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter))
88      {
89         if (options)
90           {
91              const char *opt;
92              
93              EINA_LIST_FOREACH(options, l, opt)
94                dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
95           }
96         dbus_message_iter_close_container(&iter, &subiter);
97      }
98    else
99      {
100         ERR("dbus_message_iter_open_container() failed");
101      }
102
103    ret = e_dbus_method_call_send(conn, msg, NULL, NULL, NULL, -1, NULL);
104    dbus_message_unref(msg);
105    return ret;
106 }
107
108 /* void Unmount(array{string} options) */
109
110 /**
111  * @brief Unmount a Volume
112  *
113  * @param conn the E_DBus_Connection
114  * @param udi the udi of the device object
115  * @param options a list of additional options (currently only 'force' is supported)
116  */
117 EAPI DBusPendingCall *
118 e_udisks_volume_unmount(E_DBus_Connection *conn, const char *udi, Eina_List *options)
119 {
120    DBusMessage *msg;
121    DBusMessageIter iter, subiter;
122    Eina_List *l;
123    DBusPendingCall *ret;
124
125    EINA_SAFETY_ON_NULL_RETURN_VAL(udi, NULL);
126    EINA_SAFETY_ON_TRUE_RETURN_VAL(!udi[0], NULL);
127    EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL);
128
129    msg = e_ukit_device_call_new(udi, "FilesystemUnmount");
130
131    dbus_message_iter_init_append(msg, &iter);
132    if (dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter))
133      {
134         if (options)
135           {
136              const char *opt;
137              
138              EINA_LIST_FOREACH(options, l, opt)
139                dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
140           }
141         dbus_message_iter_close_container(&iter, &subiter);
142      }
143    else
144      {
145         ERR("dbus_message_iter_open_container() failed");
146      }
147    
148    ret = e_dbus_method_call_send(conn, msg, NULL, NULL, NULL, -1, NULL);
149    dbus_message_unref(msg);
150    return ret;
151 }
152
153 /**
154  * @brief Eject a Volume
155  *
156  * @param conn the E_DBus_Connection
157  * @param udi the udi of the device object
158  * @param options a list of additional options (none currently supported)
159  */
160 EAPI DBusPendingCall *
161 e_udisks_volume_eject(E_DBus_Connection *conn, const char *udi, Eina_List *options)
162 {
163    DBusMessage *msg;
164    DBusMessageIter iter, subiter;
165    Eina_List *l;
166    DBusPendingCall *ret;
167
168    EINA_SAFETY_ON_NULL_RETURN_VAL(udi, NULL);
169    EINA_SAFETY_ON_TRUE_RETURN_VAL(!udi[0], NULL);
170    EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL);
171
172    msg = e_ukit_device_call_new(udi, "DriveEject");
173
174    dbus_message_iter_init_append(msg, &iter);
175    if (dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter))
176      {
177         if (options)
178           {
179              const char *opt;
180              
181              EINA_LIST_FOREACH(options, l, opt)
182                dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
183           }
184         dbus_message_iter_close_container(&iter, &subiter);
185      }
186    else
187      {
188         ERR("dbus_message_iter_open_container() failed");
189      }
190    
191    ret = e_dbus_method_call_send(conn, msg, NULL, NULL, NULL, -1, NULL);
192    dbus_message_unref(msg);
193    return ret;
194 }
195
196 /* EnumerateDevices */
197 EAPI DBusPendingCall *
198 e_udisks_get_all_devices(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data)
199 {
200    DBusMessage *msg;
201    DBusPendingCall *ret;
202
203    EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL);
204
205    msg = e_ukit_call_new(E_UKIT_PATH, "EnumerateDevices");
206    ret = e_dbus_method_call_send(conn, msg, unmarshal_string_list, cb_func, free_string_list, -1, data);
207    dbus_message_unref(msg);
208    return ret;
209 }