4 #include "e_hal_private.h"
6 #define e_hal_device_call_new(udi, member) dbus_message_new_method_call(E_HAL_SENDER, udi, E_HAL_DEVICE_INTERFACE, member)
7 #define e_hal_device_volume_call_new(udi, member) dbus_message_new_method_call(E_HAL_SENDER, udi, E_HAL_DEVICE_VOLUME_INTERFACE, member)
10 static void cb_device_get_property(void *data, DBusMessage *msg, DBusError *err);
11 static void cb_device_get_all_properties(void *data, DBusMessage *msg, DBusError *err);
12 static void cb_device_query_capability(void *data, DBusMessage *msg, DBusError *err);
15 /* Device.GetProperty */
17 unmarshal_device_get_property(DBusMessage *msg, DBusError *err)
19 E_Hal_Device_Get_Property_Return *ret = NULL;
24 ret = calloc(1, sizeof(E_Hal_Device_Get_Property_Return));
27 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
31 dbus_message_iter_init(msg, &iter);
32 type = dbus_message_iter_get_arg_type(&iter);
35 case DBUS_TYPE_STRING:
36 ret->type = E_HAL_PROPERTY_TYPE_STRING;
37 dbus_message_iter_get_basic(&iter, &str);
38 ret->val.s = eina_stringshare_add(str);
41 ret->type = E_HAL_PROPERTY_TYPE_INT;
42 dbus_message_iter_get_basic(&iter, &(ret->val.i));
44 case DBUS_TYPE_BOOLEAN:
45 ret->type = E_HAL_PROPERTY_TYPE_BOOL;
46 dbus_message_iter_get_basic(&iter, &(ret->val.b));
48 case DBUS_TYPE_DOUBLE:
49 ret->type = E_HAL_PROPERTY_TYPE_DOUBLE;
50 dbus_message_iter_get_basic(&iter, &(ret->val.d));
58 free_device_get_property(void *data)
60 E_Hal_Device_Get_Property_Return *ret = data;
63 if (ret->type == E_HAL_PROPERTY_TYPE_STRLIST)
66 EINA_LIST_FREE(ret->val.strlist, str)
67 eina_stringshare_del(str);
69 else if (ret->type == E_HAL_PROPERTY_TYPE_STRING)
70 eina_stringshare_del(ret->val.s);
74 EAPI DBusPendingCall *
75 e_hal_device_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data)
80 msg = e_hal_device_call_new(udi, "GetProperty");
81 dbus_message_append_args(msg, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID);
82 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_property, cb_func, free_device_get_property, -1, data);
83 dbus_message_unref(msg);
87 /* Device.GetAllProperties */
90 unmarshal_device_get_all_properties(DBusMessage *msg, DBusError *err)
92 E_Hal_Device_Get_All_Properties_Return *ret = NULL;
93 DBusMessageIter iter, a_iter, s_iter, v_iter;
95 /* a{sv} = array of string+variant */
96 if (!dbus_message_has_signature(msg, "a{sv}"))
98 dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, "");
102 ret = calloc(1, sizeof(E_Hal_Device_Get_All_Properties_Return));
105 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
109 ret->properties = eina_hash_string_small_new(EINA_FREE_CB(e_hal_property_free));
111 dbus_message_iter_init(msg, &iter);
112 dbus_message_iter_recurse(&iter, &a_iter);
113 while (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID)
117 E_Hal_Property *prop = calloc(1, sizeof(E_Hal_Property));
118 dbus_message_iter_recurse(&a_iter, &s_iter);
119 dbus_message_iter_get_basic(&s_iter, &name);
120 dbus_message_iter_next(&s_iter);
121 dbus_message_iter_recurse(&s_iter, &v_iter);
123 switch(dbus_message_iter_get_arg_type(&v_iter))
125 case DBUS_TYPE_STRING:
126 prop->type = E_HAL_PROPERTY_TYPE_STRING;
127 dbus_message_iter_get_basic(&v_iter, &str);
128 prop->val.s = eina_stringshare_add(str);
130 case DBUS_TYPE_INT32:
131 prop->type = E_HAL_PROPERTY_TYPE_INT;
132 dbus_message_iter_get_basic(&v_iter, &(prop->val.i));
134 case DBUS_TYPE_UINT64:
135 prop->type = E_HAL_PROPERTY_TYPE_UINT64;
136 dbus_message_iter_get_basic(&v_iter, &(prop->val.u64));
138 case DBUS_TYPE_BOOLEAN:
139 prop->type = E_HAL_PROPERTY_TYPE_BOOL;
140 dbus_message_iter_get_basic(&v_iter, &(prop->val.b));
142 case DBUS_TYPE_DOUBLE:
143 prop->type = E_HAL_PROPERTY_TYPE_DOUBLE;
144 dbus_message_iter_get_basic(&v_iter, &(prop->val.d));
146 case DBUS_TYPE_ARRAY:
147 prop->type = E_HAL_PROPERTY_TYPE_STRLIST;
149 DBusMessageIter list_iter;
150 prop->val.strlist = NULL;
151 dbus_message_iter_recurse(&v_iter, &list_iter);
152 while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID)
154 dbus_message_iter_get_basic(&list_iter, &str);
155 prop->val.strlist = eina_list_append(prop->val.strlist, eina_stringshare_add(str));
156 dbus_message_iter_next(&list_iter);
161 WARN("Ehal Error: unexpected property type (%s): %c", name, dbus_message_iter_get_arg_type(&v_iter));
164 eina_hash_add(ret->properties, name, prop);
166 dbus_message_iter_next(&a_iter);
173 free_device_get_all_properties(void *data)
175 E_Hal_Device_Get_All_Properties_Return *ret = data;
178 eina_hash_free(ret->properties);
182 EAPI DBusPendingCall *
183 e_hal_device_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data)
186 DBusPendingCall *ret;
188 msg = e_hal_device_call_new(udi, "GetAllProperties");
189 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_all_properties, cb_func, free_device_get_all_properties, -1, data);
190 dbus_message_unref(msg);
196 /* bool Device.QueryCapability(string udi) */
198 // XXX this is same as Device_Exists in manager.
200 unmarshal_device_query_capability(DBusMessage *msg, DBusError *err)
202 E_Hal_Device_Query_Capability_Return *ret = NULL;
205 ret = calloc(1, sizeof(E_Hal_Manager_Device_Exists_Return));
208 dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
212 dbus_message_get_args(msg, err, DBUS_TYPE_BOOLEAN, &val, DBUS_TYPE_INVALID);
214 if (dbus_error_is_set(err))
225 free_device_query_capability(void *data)
227 E_Hal_Device_Query_Capability_Return *ret = data;
233 EAPI DBusPendingCall *
234 e_hal_device_query_capability(E_DBus_Connection *conn, const char *udi, const char *capability, E_DBus_Callback_Func cb_func, void *data)
237 DBusPendingCall *ret;
239 msg = e_hal_device_call_new(udi, "QueryCapability");
240 dbus_message_append_args(msg, DBUS_TYPE_STRING, &capability, DBUS_TYPE_INVALID);
241 ret = e_dbus_method_call_send(conn, msg, unmarshal_device_query_capability, cb_func, free_device_query_capability, -1, data);
242 dbus_message_unref(msg);
248 /* void Device.Mount(string mount_point, string fstype, array{string}options) */
251 * @brief Mount a Volume
253 * @param conn the E_DBus_Connection
254 * @param udi the udi of the device object
255 * @param mount_point the path to mount to, or null for default
256 * @param fstype the fstype of the device (e.g. volume.fstype property)
257 * @param options a list of additional options (not sure... fstype dependent?)
258 * @param cb_func an optional callback to call when the mount is done
259 * @param data custom data pointer for the callback function
261 EAPI DBusPendingCall *
262 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)
265 DBusMessageIter iter, subiter;
267 DBusPendingCall *ret;
269 msg = e_hal_device_volume_call_new(udi, "Mount");
271 dbus_message_iter_init_append(msg, &iter);
272 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &mount_point);
273 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &fstype);
274 if (dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter))
280 EINA_LIST_FOREACH(options, l, opt)
282 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
285 dbus_message_iter_close_container(&iter, &subiter);
289 ERR("dbus_message_iter_open_container() failed");
292 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
293 dbus_message_unref(msg);
297 /* void Unmount(array{string} options) */
300 * @brief Unmount a Volume
302 * @param conn the E_DBus_Connection
303 * @param udi the udi of the device object
304 * @param options a list of additional options (not sure... fstype dependent?)
305 * @param cb_func an optional callback to call when the unmount is done
306 * @param data cuatom data pointer for the callback function
308 EAPI DBusPendingCall *
309 e_hal_device_volume_unmount(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data)
312 DBusMessageIter iter, subiter;
314 DBusPendingCall *ret;
316 msg = e_hal_device_volume_call_new(udi, "Unmount");
318 dbus_message_iter_init_append(msg, &iter);
319 if (dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter))
325 EINA_LIST_FOREACH(options, l, opt)
327 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
330 dbus_message_iter_close_container(&iter, &subiter);
334 ERR("dbus_message_iter_open_container() failed");
337 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
338 dbus_message_unref(msg);
343 * @brief Eject a Volume
345 * @param conn the E_DBus_Connection
346 * @param udi the udi of the device object
347 * @param options a list of additional options (not sure... fstype dependent?)
348 * @param cb_func an optional callback to call when the eject is done
349 * @param data cuatom data pointer for the callback function
351 EAPI DBusPendingCall *
352 e_hal_device_volume_eject(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data)
355 DBusMessageIter iter, subiter;
357 DBusPendingCall *ret;
359 msg = e_hal_device_volume_call_new(udi, "Eject");
361 dbus_message_iter_init_append(msg, &iter);
362 if (dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter))
368 EINA_LIST_FOREACH(options, l, opt)
370 dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt);
373 dbus_message_iter_close_container(&iter, &subiter);
377 ERR("dbus_message_iter_open_container() failed");
380 ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data);
381 dbus_message_unref(msg);