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;
21 ret = calloc(1, sizeof(E_Hal_Device_Get_Property_Return));
24 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
28 dbus_message_iter_init(msg, &iter);
29 type = dbus_message_iter_get_arg_type(&iter);
33 dbus_message_iter_get_basic(&iter, &(ret->val.s));
36 dbus_message_iter_get_basic(&iter, &(ret->val.i));
39 dbus_message_iter_get_basic(&iter, &(ret->val.b));
42 dbus_message_iter_get_basic(&iter, &(ret->val.d));
50 free_device_get_property(void *data)
52 E_Hal_Device_Get_Property_Return *ret = data;
58 EAPI DBusPendingCall *
59 e_hal_device_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data)
64 msg = e_hal_device_call_new(udi, "GetProperty");
65 dbus_message_append_args(msg, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID);
66 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_property, cb_func, free_device_get_property, -1, data);
67 dbus_message_unref(msg);
71 /* Device.GetAllProperties */
74 unmarshal_device_get_all_properties(DBusMessage *msg, DBusError *err)
76 E_Hal_Device_Get_All_Properties_Return *ret = NULL;
77 DBusMessageIter iter, a_iter, s_iter, v_iter;
79 if (!dbus_message_has_signature(msg, "a{sv}"))
81 dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, "");
85 ret = calloc(1, sizeof(E_Hal_Device_Get_All_Properties_Return));
88 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
92 ret->properties = eina_hash_string_small_new(EINA_FREE_CB(e_hal_property_free));
94 dbus_message_iter_init(msg, &iter);
95 dbus_message_iter_recurse(&iter, &a_iter);
96 while (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID)
99 E_Hal_Property *prop = calloc(1, sizeof(E_Hal_Property));
100 dbus_message_iter_recurse(&a_iter, &s_iter);
101 dbus_message_iter_get_basic(&s_iter, &name);
102 dbus_message_iter_next(&s_iter);
103 dbus_message_iter_recurse(&s_iter, &v_iter);
105 switch(dbus_message_iter_get_arg_type(&v_iter))
108 prop->type = E_HAL_PROPERTY_TYPE_STRING;
109 dbus_message_iter_get_basic(&v_iter, &(prop->val.s));
112 prop->type = E_HAL_PROPERTY_TYPE_INT;
113 dbus_message_iter_get_basic(&v_iter, &(prop->val.i));
116 prop->type = E_HAL_PROPERTY_TYPE_UINT64;
117 dbus_message_iter_get_basic(&v_iter, &(prop->val.u64));
120 prop->type = E_HAL_PROPERTY_TYPE_BOOL;
121 dbus_message_iter_get_basic(&v_iter, &(prop->val.b));
124 prop->type = E_HAL_PROPERTY_TYPE_DOUBLE;
125 dbus_message_iter_get_basic(&v_iter, &(prop->val.d));
128 prop->type = E_HAL_PROPERTY_TYPE_STRLIST;
130 DBusMessageIter list_iter;
131 prop->val.strlist = NULL;
132 dbus_message_iter_recurse(&v_iter, &list_iter);
133 while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID)
136 dbus_message_iter_get_basic(&list_iter, &str);
137 prop->val.strlist = eina_list_append(prop->val.strlist, str);
138 dbus_message_iter_next(&list_iter);
143 WARN("Ehal Error: unexpected property type (%s): %c", name, dbus_message_iter_get_arg_type(&v_iter));
146 eina_hash_add(ret->properties, name, prop);
148 dbus_message_iter_next(&a_iter);
155 free_device_get_all_properties(void *data)
157 E_Hal_Device_Get_All_Properties_Return *ret = data;
160 eina_hash_free(ret->properties);
164 EAPI DBusPendingCall *
165 e_hal_device_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data)
168 DBusPendingCall *ret;
170 msg = e_hal_device_call_new(udi, "GetAllProperties");
171 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_all_properties, cb_func, free_device_get_all_properties, -1, data);
172 dbus_message_unref(msg);
178 /* bool Device.QueryCapability(string udi) */
180 // XXX this is same as Device_Exists in manager.
182 unmarshal_device_query_capability(DBusMessage *msg, DBusError *err)
184 E_Hal_Device_Query_Capability_Return *ret = NULL;
187 ret = calloc(1, sizeof(E_Hal_Manager_Device_Exists_Return));
190 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
194 dbus_message_get_args(msg, err, DBUS_TYPE_BOOLEAN, &val, DBUS_TYPE_INVALID);
196 if (dbus_error_is_set(err))
207 free_device_query_capability(void *data)
209 E_Hal_Device_Query_Capability_Return *ret = data;
215 EAPI DBusPendingCall *
216 e_hal_device_query_capability(E_DBus_Connection *conn, const char *udi, const char *capability, E_DBus_Callback_Func cb_func, void *data)
219 DBusPendingCall *ret;
221 msg = e_hal_device_call_new(udi, "QueryCapability");
222 dbus_message_append_args(msg, DBUS_TYPE_STRING, &capability, DBUS_TYPE_INVALID);
223 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_query_capability, cb_func, free_device_query_capability, -1, data);
224 dbus_message_unref(msg);
230 /* void Device.Mount(string mount_point, string fstype, array{string}options) */
233 * @brief Mount a Volume
235 * @param conn the E_DBus_Connection
236 * @param udi the udi of the device object
237 * @param mount_point the path to mount to, or null for default
238 * @param fstype the fstype of the device (e.g. volume.fstype property)
239 * @param options a list of additional options (not sure... fstype dependant?)
240 * @param cb_func an optional callback to call when the mount is done
241 * @param data custom data pointer for the callback function
243 EAPI DBusPendingCall *
244 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)
247 DBusMessageIter iter, subiter;
249 DBusPendingCall *ret;
251 msg = e_hal_device_volume_call_new(udi, "Mount");
253 dbus_message_iter_init_append(msg, &iter);
254 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &mount_point);
255 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &fstype);
256 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &subiter);
262 EINA_LIST_FOREACH(options, l, opt)
264 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
267 dbus_message_iter_close_container(&iter, &subiter) ;
269 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
270 dbus_message_unref(msg);
274 /* void Unmount(array{string} options) */
277 * @brief Unmount a Volume
279 * @param conn the E_DBus_Connection
280 * @param udi the udi of the device object
281 * @param options a list of additional options (not sure... fstype dependant?)
282 * @param cb_func an optional callback to call when the unmount is done
283 * @param data cuatom data pointer for the callback function
285 EAPI DBusPendingCall *
286 e_hal_device_volume_unmount(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data)
289 DBusMessageIter iter, subiter;
291 DBusPendingCall *ret;
293 msg = e_hal_device_volume_call_new(udi, "Unmount");
295 dbus_message_iter_init_append(msg, &iter);
296 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &subiter);
301 EINA_LIST_FOREACH(options, l, opt)
303 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
306 dbus_message_iter_close_container(&iter, &subiter) ;
308 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
309 dbus_message_unref(msg);
314 * @brief Eject a Volume
316 * @param conn the E_DBus_Connection
317 * @param udi the udi of the device object
318 * @param options a list of additional options (not sure... fstype dependant?)
319 * @param cb_func an optional callback to call when the eject is done
320 * @param data cuatom data pointer for the callback function
322 EAPI DBusPendingCall *
323 e_hal_device_volume_eject(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data)
326 DBusMessageIter iter, subiter;
328 DBusPendingCall *ret;
330 msg = e_hal_device_volume_call_new(udi, "Eject");
332 dbus_message_iter_init_append(msg, &iter);
333 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &subiter);
338 EINA_LIST_FOREACH(options, l, opt)
340 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
343 dbus_message_iter_close_container(&iter, &subiter) ;
345 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
346 dbus_message_unref(msg);