2 #include "e_hal_private.h"
4 #define e_hal_device_call_new(udi, member) dbus_message_new_method_call(E_HAL_SENDER, udi, E_HAL_DEVICE_INTERFACE, member)
5 #define e_hal_device_volume_call_new(udi, member) dbus_message_new_method_call(E_HAL_SENDER, udi, E_HAL_DEVICE_VOLUME_INTERFACE, member)
8 static void cb_device_get_property(void *data, DBusMessage *msg, DBusError *err);
9 static void cb_device_get_all_properties(void *data, DBusMessage *msg, DBusError *err);
10 static void cb_device_query_capability(void *data, DBusMessage *msg, DBusError *err);
13 /* Device.GetProperty */
15 unmarshal_device_get_property(DBusMessage *msg, DBusError *err)
17 E_Hal_Device_Get_Property_Return *ret = NULL;
22 ret = calloc(1, sizeof(E_Hal_Device_Get_Property_Return));
25 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
29 dbus_message_iter_init(msg, &iter);
30 type = dbus_message_iter_get_arg_type(&iter);
33 case DBUS_TYPE_STRING:
34 dbus_message_iter_get_basic(&iter, &tmp);
35 ret->val.s = (char*)eina_stringshare_add(tmp);
38 dbus_message_iter_get_basic(&iter, &(ret->val.i));
40 case DBUS_TYPE_BOOLEAN:
41 dbus_message_iter_get_basic(&iter, &(ret->val.b));
43 case DBUS_TYPE_DOUBLE:
44 dbus_message_iter_get_basic(&iter, &(ret->val.d));
52 free_device_get_property(void *data)
54 E_Hal_Device_Get_Property_Return *ret = data;
57 if (ret->type == E_HAL_PROPERTY_TYPE_STRLIST)
60 EINA_LIST_FREE(ret->val.strlist, s)
61 eina_stringshare_del(s);
63 else if (ret->type == E_HAL_PROPERTY_TYPE_STRING)
64 eina_stringshare_del(ret->val.s);
68 EAPI DBusPendingCall *
69 e_hal_device_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data)
74 msg = e_hal_device_call_new(udi, "GetProperty");
75 dbus_message_append_args(msg, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID);
76 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_property, cb_func, free_device_get_property, -1, data);
77 dbus_message_unref(msg);
81 /* Device.GetAllProperties */
84 unmarshal_device_get_all_properties(DBusMessage *msg, DBusError *err)
86 E_Hal_Device_Get_All_Properties_Return *ret = NULL;
87 DBusMessageIter iter, a_iter, s_iter, v_iter;
90 /* a{sv} = array of string+variant */
91 if (!dbus_message_has_signature(msg, "a{sv}"))
93 dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, "");
97 ret = calloc(1, sizeof(E_Hal_Device_Get_All_Properties_Return));
100 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
104 ret->properties = eina_hash_string_small_new(EINA_FREE_CB(e_hal_property_free));
106 dbus_message_iter_init(msg, &iter);
107 dbus_message_iter_recurse(&iter, &a_iter);
108 while (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID)
111 E_Hal_Property *prop = calloc(1, sizeof(E_Hal_Property));
112 dbus_message_iter_recurse(&a_iter, &s_iter);
113 dbus_message_iter_get_basic(&s_iter, &name);
114 dbus_message_iter_next(&s_iter);
115 dbus_message_iter_recurse(&s_iter, &v_iter);
117 switch(dbus_message_iter_get_arg_type(&v_iter))
119 case DBUS_TYPE_STRING:
120 prop->type = E_HAL_PROPERTY_TYPE_STRING;
121 dbus_message_iter_get_basic(&v_iter, &tmp);
122 prop->val.s = (char*)eina_stringshare_add(tmp);
124 case DBUS_TYPE_INT32:
125 prop->type = E_HAL_PROPERTY_TYPE_INT;
126 dbus_message_iter_get_basic(&v_iter, &(prop->val.i));
128 case DBUS_TYPE_UINT64:
129 prop->type = E_HAL_PROPERTY_TYPE_UINT64;
130 dbus_message_iter_get_basic(&v_iter, &(prop->val.u64));
132 case DBUS_TYPE_BOOLEAN:
133 prop->type = E_HAL_PROPERTY_TYPE_BOOL;
134 dbus_message_iter_get_basic(&v_iter, &(prop->val.b));
136 case DBUS_TYPE_DOUBLE:
137 prop->type = E_HAL_PROPERTY_TYPE_DOUBLE;
138 dbus_message_iter_get_basic(&v_iter, &(prop->val.d));
140 case DBUS_TYPE_ARRAY:
141 prop->type = E_HAL_PROPERTY_TYPE_STRLIST;
143 DBusMessageIter list_iter;
144 prop->val.strlist = NULL;
145 dbus_message_iter_recurse(&v_iter, &list_iter);
146 while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID)
149 dbus_message_iter_get_basic(&list_iter, &str);
150 tmp = (char*)eina_stringshare_add(str);
151 prop->val.strlist = eina_list_append(prop->val.strlist, tmp);
152 dbus_message_iter_next(&list_iter);
157 WARN("Ehal Error: unexpected property type (%s): %c", name, dbus_message_iter_get_arg_type(&v_iter));
160 eina_hash_add(ret->properties, name, prop);
162 dbus_message_iter_next(&a_iter);
169 free_device_get_all_properties(void *data)
171 E_Hal_Device_Get_All_Properties_Return *ret = data;
174 eina_hash_free(ret->properties);
178 EAPI DBusPendingCall *
179 e_hal_device_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data)
182 DBusPendingCall *ret;
184 msg = e_hal_device_call_new(udi, "GetAllProperties");
185 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_all_properties, cb_func, free_device_get_all_properties, -1, data);
186 dbus_message_unref(msg);
192 /* bool Device.QueryCapability(string udi) */
194 // XXX this is same as Device_Exists in manager.
196 unmarshal_device_query_capability(DBusMessage *msg, DBusError *err)
198 E_Hal_Device_Query_Capability_Return *ret = NULL;
201 ret = calloc(1, sizeof(E_Hal_Manager_Device_Exists_Return));
204 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
208 dbus_message_get_args(msg, err, DBUS_TYPE_BOOLEAN, &val, DBUS_TYPE_INVALID);
210 if (dbus_error_is_set(err))
221 free_device_query_capability(void *data)
223 E_Hal_Device_Query_Capability_Return *ret = data;
229 EAPI DBusPendingCall *
230 e_hal_device_query_capability(E_DBus_Connection *conn, const char *udi, const char *capability, E_DBus_Callback_Func cb_func, void *data)
233 DBusPendingCall *ret;
235 msg = e_hal_device_call_new(udi, "QueryCapability");
236 dbus_message_append_args(msg, DBUS_TYPE_STRING, &capability, DBUS_TYPE_INVALID);
237 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_query_capability, cb_func, free_device_query_capability, -1, data);
238 dbus_message_unref(msg);
244 /* void Device.Mount(string mount_point, string fstype, array{string}options) */
247 * @brief Mount a Volume
249 * @param conn the E_DBus_Connection
250 * @param udi the udi of the device object
251 * @param mount_point the path to mount to, or null for default
252 * @param fstype the fstype of the device (e.g. volume.fstype property)
253 * @param options a list of additional options (not sure... fstype dependant?)
254 * @param cb_func an optional callback to call when the mount is done
255 * @param data custom data pointer for the callback function
257 EAPI DBusPendingCall *
258 e_hal_device_volume_mount(E_DBus_Connection *conn, const char *udi, const char *mount_point, const char *fstype, Eina_List *options, E_DBus_Callback_Func cb_func, void *data)
261 DBusMessageIter iter, subiter;
263 DBusPendingCall *ret;
265 msg = e_hal_device_volume_call_new(udi, "Mount");
267 dbus_message_iter_init_append(msg, &iter);
268 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &mount_point);
269 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &fstype);
270 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter);
276 EINA_LIST_FOREACH(options, l, opt)
278 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
281 dbus_message_iter_close_container(&iter, &subiter) ;
283 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
284 dbus_message_unref(msg);
288 /* void Unmount(array{string} options) */
291 * @brief Unmount a Volume
293 * @param conn the E_DBus_Connection
294 * @param udi the udi of the device object
295 * @param options a list of additional options (not sure... fstype dependant?)
296 * @param cb_func an optional callback to call when the unmount is done
297 * @param data cuatom data pointer for the callback function
299 EAPI DBusPendingCall *
300 e_hal_device_volume_unmount(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data)
303 DBusMessageIter iter, subiter;
305 DBusPendingCall *ret;
307 msg = e_hal_device_volume_call_new(udi, "Unmount");
309 dbus_message_iter_init_append(msg, &iter);
310 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter);
315 EINA_LIST_FOREACH(options, l, opt)
317 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
320 dbus_message_iter_close_container(&iter, &subiter) ;
322 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
323 dbus_message_unref(msg);
328 * @brief Eject a Volume
330 * @param conn the E_DBus_Connection
331 * @param udi the udi of the device object
332 * @param options a list of additional options (not sure... fstype dependant?)
333 * @param cb_func an optional callback to call when the eject is done
334 * @param data cuatom data pointer for the callback function
336 EAPI DBusPendingCall *
337 e_hal_device_volume_eject(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data)
340 DBusMessageIter iter, subiter;
342 DBusPendingCall *ret;
344 msg = e_hal_device_volume_call_new(udi, "Eject");
346 dbus_message_iter_init_append(msg, &iter);
347 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter);
352 EINA_LIST_FOREACH(options, l, opt)
354 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
357 dbus_message_iter_close_container(&iter, &subiter) ;
359 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
360 dbus_message_unref(msg);