summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2010-10-05 06:33:23 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2010-10-05 06:33:23 +0000
commit04662b3565fed1a9416154656f2fa77cef8aefeb (patch)
tree13ec764e2d3591bcfef0ee996a1c2668d28a6fd7
parentf9c6eb799c1d842c2acee3264e0887fe2e1e411b (diff)
complete rewrite of all includes and file splitting to completely abstract dbus out of efm
SVN revision: 53051
-rw-r--r--src/bin/Makefile.am6
-rw-r--r--src/bin/e_fm.c9
-rw-r--r--src/bin/e_fm.h4
-rw-r--r--src/bin/e_fm/Makefile.am34
-rw-r--r--src/bin/e_fm/e_fm_ipc.c11
-rw-r--r--src/bin/e_fm/e_fm_ipc.h2
-rw-r--r--src/bin/e_fm/e_fm_main.c971
-rw-r--r--src/bin/e_fm/e_fm_main.h10
-rw-r--r--src/bin/e_fm/e_fm_main_dbus.c1002
-rw-r--r--src/bin/e_fm/e_fm_main_dbus.h25
-rw-r--r--src/bin/e_fm_dbus.c10
-rw-r--r--src/bin/e_fm_shared.h209
-rw-r--r--src/bin/e_fm_shared_codec.c116
-rw-r--r--src/bin/e_fm_shared_codec.h17
-rw-r--r--src/bin/e_fm_shared_dbus.c42
-rw-r--r--src/bin/e_fm_shared_dbus.h9
-rw-r--r--src/bin/e_fm_shared_types.h85
17 files changed, 1403 insertions, 1159 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index ab2f742..4efdd93 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -159,7 +159,9 @@ e_order.h \
159e_exec.h \ 159e_exec.h \
160e_widget_font_preview.h \ 160e_widget_font_preview.h \
161e_fm_custom.h \ 161e_fm_custom.h \
162e_fm_shared.h \ 162e_fm_shared_types.h \
163e_fm_shared_codec.h \
164e_fm_shared_dbus.h \
163e_config_data.h \ 165e_config_data.h \
164e_intl_data.h \ 166e_intl_data.h \
165e_toolbar.h \ 167e_toolbar.h \
@@ -277,6 +279,8 @@ e_confirm_dialog.c \
277e_int_border_prop.c \ 279e_int_border_prop.c \
278e_entry_dialog.c \ 280e_entry_dialog.c \
279e_fm.c \ 281e_fm.c \
282e_fm_shared_codec.c \
283e_fm_shared_dbus.c \
280e_fm_dbus.c \ 284e_fm_dbus.c \
281e_fm_op_registry.c \ 285e_fm_op_registry.c \
282e_widget_scrollframe.c \ 286e_widget_scrollframe.c \
diff --git a/src/bin/e_fm.c b/src/bin/e_fm.c
index 0349783..18e66ab 100644
--- a/src/bin/e_fm.c
+++ b/src/bin/e_fm.c
@@ -449,9 +449,8 @@ static Ecore_Timer *_e_fm2_mime_clear = NULL;
449 * _e_storage_volume_edd_init() 449 * _e_storage_volume_edd_init()
450 * _e_storage_volume_edd_shutdown() 450 * _e_storage_volume_edd_shutdown()
451 */ 451 */
452#define E_FM_SHARED_CODEC 452
453#include "e_fm_shared.h" 453#include "e_fm_shared_codec.h"
454#undef E_FM_SHARED_CODEC
455 454
456static inline Eina_Bool 455static inline Eina_Bool
457_e_fm2_icon_realpath(const E_Fm2_Icon *ic, char *buf, int buflen) 456_e_fm2_icon_realpath(const E_Fm2_Icon *ic, char *buf, int buflen)
@@ -2914,7 +2913,7 @@ e_fm2_client_data(Ecore_Ipc_Event_Client_Data *e)
2914 { 2913 {
2915 E_Storage *s; 2914 E_Storage *s;
2916 2915
2917 s = eet_data_descriptor_decode(_e_storage_edd, e->data, e->size); 2916 s = _e_fm_shared_codec_storage_decode(e->data, e->size);
2918 if (s) e_fm2_dbus_storage_add(s); 2917 if (s) e_fm2_dbus_storage_add(s);
2919 } 2918 }
2920 break; 2919 break;
@@ -2936,7 +2935,7 @@ e_fm2_client_data(Ecore_Ipc_Event_Client_Data *e)
2936 { 2935 {
2937 E_Volume *v; 2936 E_Volume *v;
2938 2937
2939 v = eet_data_descriptor_decode(_e_volume_edd, e->data, e->size); 2938 v = _e_fm_shared_codec_volume_decode(e->data, e->size);
2940 if (v) 2939 if (v)
2941 { 2940 {
2942 e_fm2_dbus_volume_add(v); 2941 e_fm2_dbus_volume_add(v);
diff --git a/src/bin/e_fm.h b/src/bin/e_fm.h
index b7fd78d..55f61a5 100644
--- a/src/bin/e_fm.h
+++ b/src/bin/e_fm.h
@@ -47,9 +47,7 @@ typedef struct _E_Fm2_Config E_Fm2_Config;
47typedef struct _E_Fm2_Icon E_Fm2_Icon; 47typedef struct _E_Fm2_Icon E_Fm2_Icon;
48typedef struct _E_Fm2_Icon_Info E_Fm2_Icon_Info; 48typedef struct _E_Fm2_Icon_Info E_Fm2_Icon_Info;
49 49
50#define E_FM_SHARED_DATATYPES 50#include "e_fm_shared_types.h"
51#include "e_fm_shared.h"
52#undef E_FM_SHARED_DATATYPES
53 51
54#else 52#else
55#ifndef E_FM_H 53#ifndef E_FM_H
diff --git a/src/bin/e_fm/Makefile.am b/src/bin/e_fm/Makefile.am
new file mode 100644
index 0000000..3851427
--- /dev/null
+++ b/src/bin/e_fm/Makefile.am
@@ -0,0 +1,34 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3INCLUDES = -I$(top_builddir) \
4 -I$(top_srcdir) \
5 -I$(top_srcdir)/src/bin \
6 -I$(top_srcdir)/src/lib \
7 @e_cflags@ \
8 @x_cflags@ \
9 @cf_cflags@ \
10 @VALGRIND_CFLAGS@ \
11 @EDJE_DEF@ \
12 -DPACKAGE_BIN_DIR=\"@PACKAGE_BIN_DIR@\" \
13 -DPACKAGE_LIB_DIR=\"@PACKAGE_LIB_DIR@\" \
14 -DPACKAGE_DATA_DIR=\"@PACKAGE_DATA_DIR@\" \
15 -DLOCALE_DIR=\"@LOCALE_DIR@\" \
16 -DPACKAGE_SYSCONF_DIR=\"@PACKAGE_SYSCONF_DIR@\"
17
18internal_bindir = $(libdir)/enlightenment/utils
19internal_bin_PROGRAMS = \
20enlightenment_fm
21
22enlightenment_fm_SOURCES = \
23e_fm_main.c \
24e_fm_main_dbus.c \
25e_fm_ipc.c \
26../e_fm_shared_codec.c \
27../e_fm_shared_dbus.c \
28../e_user.c \
29../e_sha1.c
30
31enlightenment_fm_LDADD = @E_FM_LIBS@
32enlightenment_fm_CFLAGS = $(INCLUDES)
33
34
diff --git a/src/bin/e_fm/e_fm_ipc.c b/src/bin/e_fm/e_fm_ipc.c
index fa0ebda..6fb0971 100644
--- a/src/bin/e_fm/e_fm_ipc.c
+++ b/src/bin/e_fm/e_fm_ipc.c
@@ -33,17 +33,12 @@
33#include <Evas.h> 33#include <Evas.h>
34#include <Efreet.h> 34#include <Efreet.h>
35#include <Eet.h> 35#include <Eet.h>
36#include <E_DBus.h> 36
37#ifdef HAVE_EUKIT
38#include <E_Ukit.h>
39#else
40#include <E_Hal.h>
41#endif
42#include <eina_stringshare.h> 37#include <eina_stringshare.h>
43 38
44#include "e.h" 39#include "e.h"
45#include "e_fm_ipc.h" 40#include "e_fm_ipc.h"
46 41//#include "e_fm_shared_c.h"
47#include "e_fm_op.h" 42#include "e_fm_op.h"
48 43
49 44
@@ -118,7 +113,7 @@ struct _E_Fm_Task
118 int x,y; 113 int x,y;
119}; 114};
120 115
121#include "e_fm_shared.h" 116
122/* local subsystem globals */ 117/* local subsystem globals */
123Ecore_Ipc_Server *_e_fm_ipc_server = NULL; 118Ecore_Ipc_Server *_e_fm_ipc_server = NULL;
124 119
diff --git a/src/bin/e_fm/e_fm_ipc.h b/src/bin/e_fm/e_fm_ipc.h
index c857009..404e666 100644
--- a/src/bin/e_fm/e_fm_ipc.h
+++ b/src/bin/e_fm/e_fm_ipc.h
@@ -1,6 +1,8 @@
1#ifndef E_FM_IPC_H 1#ifndef E_FM_IPC_H
2#define E_FM_IPC_H 2#define E_FM_IPC_H
3 3
4#include "e_fm_shared_types.h"
5
4int _e_fm_ipc_init(void); 6int _e_fm_ipc_init(void);
5Eina_Bool _e_fm_ipc_slave_data_cb(void *data, int type, void *event); 7Eina_Bool _e_fm_ipc_slave_data_cb(void *data, int type, void *event);
6Eina_Bool _e_fm_ipc_slave_error_cb(void *data, int type, void *event); 8Eina_Bool _e_fm_ipc_slave_error_cb(void *data, int type, void *event);
diff --git a/src/bin/e_fm/e_fm_main.c b/src/bin/e_fm/e_fm_main.c
index c91d6a9..3860de4 100644
--- a/src/bin/e_fm/e_fm_main.c
+++ b/src/bin/e_fm/e_fm_main.c
@@ -42,16 +42,8 @@ void *alloca (size_t);
42#include <Ecore.h> 42#include <Ecore.h>
43#include <Ecore_Ipc.h> 43#include <Ecore_Ipc.h>
44#include <Ecore_File.h> 44#include <Ecore_File.h>
45#include <Evas.h>
46#include <Efreet.h>
47#include <Eet.h> 45#include <Eet.h>
48#include <E_DBus.h> 46#include <Evas.h>
49#ifdef HAVE_EUKIT
50#include <E_Ukit.h>
51#else
52#include <E_Hal.h>
53#endif
54#include <eina_stringshare.h>
55 47
56#define E_TYPEDEFS 48#define E_TYPEDEFS
57#include "e_config_data.h" 49#include "e_config_data.h"
@@ -60,56 +52,40 @@ void *alloca (size_t);
60#include "e_config_data.h" 52#include "e_config_data.h"
61#include "e_fm_op.h" 53#include "e_fm_op.h"
62 54
55/* if using ehal, functions will point to _e_fm_main_dbus_X
56 * if using eeze, functions will point to _e_fm_main_eeze_X
57 */
58#ifndef HAVE_EEZE_MOUNT
59#include "e_fm_main_dbus.h"
60#include "e_fm_shared_dbus.h"
61#define _E_FM(FUNC) _e_fm_main_dbus_##FUNC
62#define _E_FM_SHARED(FUNC) _e_fm_shared_dbus_##FUNC
63#else
64#include "e_fm_main_eeze.h"
65#define _E_FM(FUNC) _e_fm_main_eeze_##FUNC
66#define _E_FM_SHARED(FUNC) _e_fm_shared_eeze_##FUNC
67#endif
68
63/* FIXME: things to add to the slave enlightenment_fm process and ipc to e: 69/* FIXME: things to add to the slave enlightenment_fm process and ipc to e:
64 * 70 *
65 * * reporting results of fop's (current status - what has been don, what failed etc.) 71 * * reporting results of fop's (current status - what has been don, what failed etc.)
66 * * dbus removable device monitoring (in e17 itself now via ecore_dbus - move to enlightenment_fm and ipc removable device add/del and anything else) 72 * * dbus removable device monitoring (in e17 itself now via e_dbus - move to enlightenment_fm and ipc removable device add/del and anything else)
67 * * mount/umount of removable devices (to go along with removable device support - put it in here and message back mount success/failure and where it is now mounted - remove from e17 itself) 73 * * mount/umount of removable devices (to go along with removable device support - put it in here and message back mount success/failure and where it is now mounted - remove from e17 itself)
68 * 74 *
69 */ 75 */
70static E_DBus_Signal_Handler *_hal_poll = NULL;
71 76
72#ifndef EAPI 77#ifndef EAPI
73#define EAPI 78#define EAPI
74#endif 79#endif
75 80
76#define E_FM_SHARED_DATATYPES 81#include "e_fm_main.h"
77#include "e_fm_shared.h" 82#include "e_fm_shared_types.h"
78#undef E_FM_SHARED_DATATYPES 83#include "e_fm_shared_codec.h"
84#include "e_fm_ipc.h"
85
79 86
80static void _e_fm_init(void); 87static void _e_fm_init(void);
81static void _e_fm_shutdown(void); 88static void _e_fm_shutdown(void);
82static void _e_dbus_cb_dev_all(void *user_data, void *reply_data, DBusError *error);
83static void _e_dbus_cb_dev_store(void *user_data, void *reply_data, DBusError *error);
84static void _e_dbus_cb_dev_vol(void *user_data, void *reply_data, DBusError *error);
85static void _e_dbus_cb_store_is(void *user_data, void *reply_data, DBusError *error);
86static void _e_dbus_cb_vol_is(void *user_data, void *reply_data, DBusError *error);
87static void _e_dbus_cb_dev_add(void *data, DBusMessage *msg);
88static void _e_dbus_cb_dev_del(void *data, DBusMessage *msg);
89static void _e_dbus_cb_cap_add(void *data, DBusMessage *msg);
90static void _e_dbus_cb_prop_modified(void *data, DBusMessage *msg);
91static void _e_dbus_cb_store_prop(void *data, void *reply_data, DBusError *error);
92static void _e_dbus_cb_vol_prop(void *data, void *reply_data, DBusError *error);
93static void _e_dbus_cb_vol_prop_mount_modified(void *data, void *reply_data, DBusError *error);
94static void _e_dbus_cb_vol_mounted(void *user_data, void *method_return, DBusError *error);
95static void _e_dbus_cb_vol_unmounted(void *user_data, void *method_return, DBusError *error);
96static void _e_dbus_cb_vol_unmounted_before_eject(void *user_data, void *method_return, DBusError *error);
97static Eina_Bool _e_dbus_vb_vol_ejecting_after_unmount(void *data);
98static void _e_dbus_cb_vol_ejected(void *user_data, void *method_return, DBusError *error);
99static int _e_dbus_format_error_msg(char **buf, E_Volume *v, DBusError *error);
100static void _hal_test(void *data, DBusMessage *msg, DBusError *error);
101static void _e_hal_poll(void *data, DBusMessage *msg);
102
103static Eina_Bool _e_dbus_vol_mount_timeout(void *data);
104static Eina_Bool _e_dbus_vol_unmount_timeout(void *data);
105static Eina_Bool _e_dbus_vol_eject_timeout(void *data);
106
107#define E_FM_MOUNT_TIMEOUT 30.0
108#define E_FM_UNMOUNT_TIMEOUT 60.0
109#define E_FM_EJECT_TIMEOUT 15.0
110
111static E_DBus_Connection *_e_dbus_conn = NULL;
112extern Ecore_Ipc_Server *_e_fm_ipc_server;
113 89
114/* contains: 90/* contains:
115 * _e_volume_edd 91 * _e_volume_edd
@@ -121,10 +97,7 @@ extern Ecore_Ipc_Server *_e_fm_ipc_server;
121 * _e_storage_volume_edd_init() 97 * _e_storage_volume_edd_init()
122 * _e_storage_volume_edd_shutdown() 98 * _e_storage_volume_edd_shutdown()
123 */ 99 */
124#define E_FM_SHARED_CODEC 100
125#include "e_fm_shared.h"
126#undef E_FM_SHARED_CODEC
127#include "e_fm_ipc.h"
128/* externally accessible functions */ 101/* externally accessible functions */
129int 102int
130main(int argc, char **argv) 103main(int argc, char **argv)
@@ -169,6 +142,7 @@ main(int argc, char **argv)
169 } 142 }
170 143
171 _e_fm_shutdown(); 144 _e_fm_shutdown();
145 _e_storage_volume_edd_shutdown();
172 ecore_ipc_shutdown(); 146 ecore_ipc_shutdown();
173 ecore_file_shutdown(); 147 ecore_file_shutdown();
174 ecore_shutdown(); 148 ecore_shutdown();
@@ -178,917 +152,60 @@ main(int argc, char **argv)
178static void 152static void
179_e_fm_init(void) 153_e_fm_init(void)
180{ 154{
181 e_dbus_init(); 155 _E_FM(init)();
182 e_hal_init();
183 _e_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
184 /* previously, this assumed that if dbus was running, hal was running. */
185 if (_e_dbus_conn)
186 e_dbus_get_name_owner(_e_dbus_conn, E_HAL_SENDER, _hal_test, NULL);
187} 156}
188 157
189static void 158static void
190_e_fm_shutdown(void) 159_e_fm_shutdown(void)
191{ 160{
192 if (_e_dbus_conn) 161 _E_FM(shutdown)();
193 e_dbus_connection_close(_e_dbus_conn);
194 _e_storage_volume_edd_shutdown();
195 e_hal_shutdown();
196 e_dbus_shutdown();
197}
198
199static void
200_e_hal_poll(void *data __UNUSED__, DBusMessage *msg)
201{
202 DBusError err;
203 const char *name, *from, *to;
204
205 dbus_error_init(&err);
206 if (!dbus_message_get_args(msg, &err,
207 DBUS_TYPE_STRING, &name,
208 DBUS_TYPE_STRING, &from,
209 DBUS_TYPE_STRING, &to,
210 DBUS_TYPE_INVALID))
211 dbus_error_free(&err);
212
213 printf("name: %s\nfrom: %s\nto: %s\n", name, from, to);
214 if ((name) && !strcmp(name, E_HAL_SENDER))
215 _hal_test(NULL, NULL, NULL);
216}
217
218static void
219_hal_test(void *data __UNUSED__, DBusMessage *msg __UNUSED__, DBusError *error)
220{
221 if ((error) && (dbus_error_is_set(error)))
222 {
223 dbus_error_free(error);
224 if (!_hal_poll)
225 _hal_poll =
226 e_dbus_signal_handler_add(_e_dbus_conn,
227 E_DBUS_FDO_BUS, E_DBUS_FDO_PATH,
228 E_DBUS_FDO_INTERFACE,
229 "NameOwnerChanged", _e_hal_poll, NULL);
230 return;
231 }
232 if (_hal_poll)
233 e_dbus_signal_handler_del(_e_dbus_conn, _hal_poll);
234
235 e_hal_manager_get_all_devices(_e_dbus_conn, _e_dbus_cb_dev_all, NULL);
236 e_hal_manager_find_device_by_capability(_e_dbus_conn, "storage",
237 _e_dbus_cb_dev_store, NULL);
238 e_hal_manager_find_device_by_capability(_e_dbus_conn, "volume",
239 _e_dbus_cb_dev_vol, NULL);
240
241 e_dbus_signal_handler_add(_e_dbus_conn, E_HAL_SENDER,
242 E_HAL_MANAGER_PATH,
243 E_HAL_MANAGER_INTERFACE,
244 "DeviceAdded", _e_dbus_cb_dev_add, NULL);
245 e_dbus_signal_handler_add(_e_dbus_conn, E_HAL_SENDER,
246 E_HAL_MANAGER_PATH,
247 E_HAL_MANAGER_INTERFACE,
248 "DeviceRemoved", _e_dbus_cb_dev_del, NULL);
249 e_dbus_signal_handler_add(_e_dbus_conn, E_HAL_SENDER,
250 E_HAL_MANAGER_PATH,
251 E_HAL_MANAGER_INTERFACE,
252 "NewCapability", _e_dbus_cb_cap_add, NULL);
253}
254
255static void
256_e_dbus_cb_dev_all(void *user_data __UNUSED__, void *reply_data, DBusError *error)
257{
258 E_Hal_Manager_Get_All_Devices_Return *ret = reply_data;
259 Eina_List *l;
260 char *udi;
261
262 if (!ret || !ret->strings) return;
263
264 if (dbus_error_is_set(error))
265 {
266 dbus_error_free(error);
267 return;
268 }
269
270 EINA_LIST_FOREACH(ret->strings, l, udi)
271 {
272// printf("DB INIT DEV+: %s\n", udi);
273 e_hal_device_query_capability(_e_dbus_conn, udi, "storage",
274 _e_dbus_cb_store_is, (void*)eina_stringshare_add(udi));
275 e_hal_device_query_capability(_e_dbus_conn, udi, "volume",
276 _e_dbus_cb_vol_is, (void*)eina_stringshare_add(udi));
277 }
278}
279
280static void
281_e_dbus_cb_dev_store(void *user_data __UNUSED__, void *reply_data, DBusError *error)
282{
283 E_Hal_Manager_Find_Device_By_Capability_Return *ret = reply_data;
284 Eina_List *l;
285 char *device;
286
287 if (!ret || !ret->strings) return;
288
289 if (dbus_error_is_set(error))
290 {
291 dbus_error_free(error);
292 return;
293 }
294
295 EINA_LIST_FOREACH(ret->strings, l, device)
296 {
297// printf("DB STORE+: %s\n", device);
298 e_storage_add(device);
299 }
300}
301
302static void
303_e_dbus_cb_dev_vol(void *user_data __UNUSED__, void *reply_data, DBusError *error)
304{
305 E_Hal_Manager_Find_Device_By_Capability_Return *ret = reply_data;
306 Eina_List *l;
307 char *device;
308
309 if (!ret || !ret->strings) return;
310
311 if (dbus_error_is_set(error))
312 {
313 dbus_error_free(error);
314 return;
315 }
316
317 EINA_LIST_FOREACH(ret->strings, l, device)
318 {
319// printf("DB VOL+: %s\n", device);
320 e_volume_add(device, 1);
321 }
322}
323
324static void
325_e_dbus_cb_store_is(void *user_data, void *reply_data, DBusError *error)
326{
327 char *udi = user_data;
328 E_Hal_Device_Query_Capability_Return *ret = reply_data;
329
330 if (dbus_error_is_set(error))
331 {
332 dbus_error_free(error);
333 goto error;
334 }
335
336 if (ret && ret->boolean)
337 {
338// printf("DB STORE IS+: %s\n", udi);
339 e_storage_add(udi);
340 }
341
342 error:
343 eina_stringshare_del(udi);
344}
345
346static void
347_e_dbus_cb_vol_is(void *user_data, void *reply_data, DBusError *error)
348{
349 char *udi = user_data;
350 E_Hal_Device_Query_Capability_Return *ret = reply_data;
351
352 if (dbus_error_is_set(error))
353 {
354 dbus_error_free(error);
355 goto error;
356 }
357
358 if (ret && ret->boolean)
359 {
360// printf("DB VOL IS+: %s\n", udi);
361 e_volume_add(udi, 0);
362 }
363
364 error:
365 eina_stringshare_del(udi);
366}
367
368static void
369_e_dbus_cb_dev_add(void *data __UNUSED__, DBusMessage *msg)
370{
371 DBusError err;
372 char *udi = NULL;
373
374 dbus_error_init(&err);
375 dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
376 if (!udi) return;
377 e_hal_device_query_capability(_e_dbus_conn, udi, "storage",
378 _e_dbus_cb_store_is, (void*)eina_stringshare_add(udi));
379 e_hal_device_query_capability(_e_dbus_conn, udi, "volume",
380 _e_dbus_cb_vol_is, (void*)eina_stringshare_add(udi));
381}
382
383static void
384_e_dbus_cb_dev_del(void *data __UNUSED__, DBusMessage *msg)
385{
386 DBusError err;
387 char *udi;
388
389 dbus_error_init(&err);
390
391 dbus_message_get_args(msg,
392 &err, DBUS_TYPE_STRING,
393 &udi, DBUS_TYPE_INVALID);
394// printf("DB DEV-: %s\n", udi);
395 e_storage_del(udi);
396 e_volume_del(udi);
397}
398
399static void
400_e_dbus_cb_cap_add(void *data __UNUSED__, DBusMessage *msg)
401{
402 DBusError err;
403 char *udi, *capability;
404
405 dbus_error_init(&err);
406
407 dbus_message_get_args(msg,
408 &err, DBUS_TYPE_STRING,
409 &udi, DBUS_TYPE_STRING,
410 &capability, DBUS_TYPE_INVALID);
411 if (!strcmp(capability, "storage"))
412 {
413// printf("DB STORE CAP+: %s\n", udi);
414 e_storage_add(udi);
415 }
416}
417
418static void
419_e_dbus_cb_prop_modified(void *data, DBusMessage *msg)
420{
421 E_Volume *v;
422 DBusMessageIter iter, sub, subsub;
423 struct {
424 const char *name;
425 int added;
426 int removed;
427 } prop;
428 int num_changes = 0, i;
429
430 if (!(v = data)) return;
431
432 if (dbus_message_get_error_name(msg))
433 {
434 printf("DBUS ERROR: %s\n", dbus_message_get_error_name(msg));
435 return;
436 }
437 if (!dbus_message_iter_init(msg, &iter)) return;
438
439 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) return;
440 dbus_message_iter_get_basic(&iter, &num_changes);
441 if (num_changes == 0) return;
442
443 dbus_message_iter_next(&iter);
444 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) return;
445 dbus_message_iter_recurse(&iter, &sub);
446
447 for (i = 0; i < num_changes; i++, dbus_message_iter_next(&sub))
448 {
449 dbus_message_iter_recurse(&sub, &subsub);
450
451 if (dbus_message_iter_get_arg_type(&subsub) != DBUS_TYPE_STRING) break;
452 dbus_message_iter_get_basic(&subsub, &(prop.name));
453 if (!strcmp(prop.name, "volume.mount_point"))
454 {
455 e_hal_device_get_all_properties(_e_dbus_conn, v->udi,
456 _e_dbus_cb_vol_prop_mount_modified,
457 v);
458 return;
459 }
460
461 dbus_message_iter_next(&subsub);
462 dbus_message_iter_next(&subsub);
463 }
464}
465
466static void
467_e_dbus_cb_store_prop(void *data, void *reply_data, DBusError *error)
468{
469 E_Storage *s = data;
470 E_Hal_Properties *ret = reply_data;
471 int err = 0;
472
473 if (!ret) goto error;
474
475 if (dbus_error_is_set(error))
476 {
477 dbus_error_free(error);
478 goto error;
479 }
480
481 s->bus = e_hal_property_string_get(ret, "storage.bus", &err);
482 if (err) goto error;
483 s->bus = eina_stringshare_add(s->bus);
484 s->drive_type = e_hal_property_string_get(ret, "storage.drive_type", &err);
485 if (err) goto error;
486 s->drive_type = eina_stringshare_add(s->drive_type);
487 s->model = e_hal_property_string_get(ret, "storage.model", &err);
488 if (err) goto error;
489 s->model = eina_stringshare_add(s->model);
490 s->vendor = e_hal_property_string_get(ret, "storage.vendor", &err);
491 if (err) goto error;
492 s->vendor = eina_stringshare_add(s->vendor);
493 s->serial = e_hal_property_string_get(ret, "storage.serial", &err);
494// if (err) goto error;
495 if (err) printf("Error getting serial for %s\n", s->udi);
496 s->serial = eina_stringshare_add(s->serial);
497
498 s->removable = e_hal_property_bool_get(ret, "storage.removable", &err);
499
500 if (s->removable)
501 {
502 s->media_available = e_hal_property_bool_get(ret, "storage.removable.media_available", &err);
503 s->media_size = e_hal_property_uint64_get(ret, "storage.removable.media_size", &err);
504 }
505
506 s->requires_eject = e_hal_property_bool_get(ret, "storage.requires_eject", &err);
507 s->hotpluggable = e_hal_property_bool_get(ret, "storage.hotpluggable", &err);
508 s->media_check_enabled = e_hal_property_bool_get(ret, "storage.media_check_enabled", &err);
509
510 s->icon.drive = e_hal_property_string_get(ret, "storage.icon.drive", &err);
511 s->icon.drive = eina_stringshare_add(s->icon.drive);
512 s->icon.volume = e_hal_property_string_get(ret, "storage.icon.volume", &err);
513 s->icon.volume = eina_stringshare_add(s->icon.volume);
514
515// printf("++STO:\n udi: %s\n bus: %s\n drive_type: %s\n model: %s\n vendor: %s\n serial: %s\n icon.drive: %s\n icon.volume: %s\n\n", s->udi, s->bus, s->drive_type, s->model, s->vendor, s->serial, s->icon.drive, s->icon.volume);
516 s->validated = EINA_TRUE;
517 {
518 void *msg_data;
519 int msg_size;
520
521 msg_data = eet_data_descriptor_encode(_e_storage_edd, s, &msg_size);
522 if (msg_data)
523 {
524 ecore_ipc_server_send(_e_fm_ipc_server,
525 6/*E_IPC_DOMAIN_FM*/,
526 E_FM_OP_STORAGE_ADD,
527 0, 0, 0, msg_data, msg_size);
528 free(msg_data);
529 }
530 }
531 return;
532
533 error:
534// printf("ERR %s\n", s->udi);
535 e_storage_del(s->udi);
536}
537
538static Eina_List *_e_stores = NULL;
539
540EAPI E_Storage *
541e_storage_add(const char *udi)
542{
543 E_Storage *s;
544
545 if (!udi) return NULL;
546 if (e_storage_find(udi)) return NULL;
547 s = calloc(1, sizeof(E_Storage));
548 if (!s) return NULL;
549 s->udi = eina_stringshare_add(udi);
550 _e_stores = eina_list_append(_e_stores, s);
551 e_hal_device_get_all_properties(_e_dbus_conn, s->udi,
552 _e_dbus_cb_store_prop, s);
553 return s;
554} 162}
555 163
556EAPI void 164EAPI void
557e_storage_del(const char *udi) 165e_volume_mount(E_Volume *v)
558{
559 E_Storage *s;
560
561 s = e_storage_find(udi);
562 if (!s) return;
563 if (s->validated)
564 {
565// printf("--STO %s\n", s->udi);
566 ecore_ipc_server_send(_e_fm_ipc_server,
567 6/*E_IPC_DOMAIN_FM*/,
568 E_FM_OP_STORAGE_DEL,
569 0, 0, 0, s->udi, strlen(s->udi) + 1);
570 }
571 _e_stores = eina_list_remove(_e_stores, s);
572 _e_storage_free(s);
573}
574
575E_Storage *
576e_storage_find(const char *udi)
577{
578 Eina_List *l;
579 E_Storage *s;
580
581 EINA_LIST_FOREACH(_e_stores, l, s)
582 {
583 if (!strcmp(udi, s->udi)) return s;
584 }
585 return NULL;
586}
587
588static void
589_e_dbus_cb_vol_prop(void *data, void *reply_data, DBusError *error)
590{
591 E_Volume *v = data;
592 E_Storage *s = NULL;
593 E_Hal_Device_Get_All_Properties_Return *ret = reply_data;
594 int err = 0;
595 const char *str = NULL;
596
597 if (!ret) goto error;
598 if (dbus_error_is_set(error))
599 {
600 dbus_error_free(error);
601 goto error;
602 }
603
604 /* skip volumes with volume.ignore set */
605 if (e_hal_property_bool_get(ret, "volume.ignore", &err) || err)
606 goto error;
607
608 /* skip volumes that aren't filesystems */
609 str = e_hal_property_string_get(ret, "volume.fsusage", &err);
610 if (err || !str) goto error;
611 if (strcmp(str, "filesystem")) goto error;
612 str = NULL;
613
614 v->uuid = e_hal_property_string_get(ret, "volume.uuid", &err);
615 if (err) goto error;
616 v->uuid = eina_stringshare_add(v->uuid);
617
618 v->label = e_hal_property_string_get(ret, "volume.label", &err);
619// if (err) goto error;
620 v->label = eina_stringshare_add(v->label);
621
622 v->fstype = e_hal_property_string_get(ret, "volume.fstype", &err);
623// if (err) goto error;
624 v->fstype = eina_stringshare_add(v->fstype);
625
626 v->size = e_hal_property_uint64_get(ret, "volume.size", &err);
627
628 v->mounted = e_hal_property_bool_get(ret, "volume.is_mounted", &err);
629 if (err) goto error;
630
631 v->partition = e_hal_property_bool_get(ret, "volume.is_partition", &err);
632 if (err) goto error;
633
634 v->mount_point = e_hal_property_string_get(ret, "volume.mount_point", &err);
635 if (err) goto error;
636 v->mount_point = eina_stringshare_add(v->mount_point);
637
638 if (v->partition)
639 {
640 v->partition_number = e_hal_property_int_get(ret, "volume.partition.number", NULL);
641 v->partition_label = e_hal_property_string_get(ret, "volume.partition.label", NULL);
642 v->partition_label = eina_stringshare_add(v->partition_label);
643 }
644
645 v->parent = e_hal_property_string_get(ret, "info.parent", &err);
646 if ((!err) && (v->parent))
647 {
648 s = e_storage_find(v->parent);
649 if (s)
650 {
651 v->storage = s;
652 s->volumes = eina_list_append(s->volumes, v);
653 }
654 }
655 v->parent = eina_stringshare_add(v->parent);
656
657// printf("++VOL:\n udi: %s\n uuid: %s\n fstype: %s\n size: %llu\n label: %s\n partition: %d\n partition_number: %d\n partition_label: %s\n mounted: %d\n mount_point: %s\n", v->udi, v->uuid, v->fstype, v->size, v->label, v->partition, v->partition_number, v->partition ? v->partition_label : "(not a partition)", v->mounted, v->mount_point);
658// if (s) printf(" for storage: %s\n", s->udi);
659// else printf(" storage unknown\n");
660 v->validated = EINA_TRUE;
661 {
662 void *msg_data;
663 int msg_size;
664
665 msg_data = eet_data_descriptor_encode(_e_volume_edd, v, &msg_size);
666 if (msg_data)
667 {
668 ecore_ipc_server_send(_e_fm_ipc_server,
669 6/*E_IPC_DOMAIN_FM*/,
670 E_FM_OP_VOLUME_ADD,
671 0, 0, 0, msg_data, msg_size);
672 free(msg_data);
673 }
674 }
675 return;
676
677 error:
678 e_volume_del(v->udi);
679 return;
680}
681
682static int
683_e_dbus_format_error_msg(char **buf, E_Volume *v, DBusError *error)
684{ 166{
685 int size, vu, vm, en; 167 _E_FM(volume_mount)(v);
686 char *tmp;
687
688 vu = strlen(v->udi) + 1;
689 vm = strlen(v->mount_point) + 1;
690 en = strlen(error->name) + 1;
691 size = vu + vm + en + strlen(error->message) + 1;
692 tmp = *buf = malloc(size);
693
694 strcpy(tmp, v->udi);
695 tmp += vu;
696 strcpy(tmp, v->mount_point);
697 tmp += vm;
698 strcpy(tmp, error->name);
699 tmp += en;
700 strcpy(tmp, error->message);
701
702 return size;
703} 168}
704 169
705static void
706_e_dbus_cb_vol_prop_mount_modified(void *data, void *reply_data, DBusError *error)
707{
708 E_Volume *v = data;
709 E_Hal_Device_Get_All_Properties_Return *ret = reply_data;
710 int err = 0;
711 170
712 if (!ret) return; 171EAPI void
713 if (dbus_error_is_set(error)) 172e_volume_unmount(E_Volume *v)
714 {
715 char *buf;
716 int size;
717
718 size = _e_dbus_format_error_msg(&buf, v, error);
719 if (v->mounted)
720 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR,
721 0, 0, 0, buf, size);
722 else
723 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR,
724 0, 0, 0, buf, size);
725 dbus_error_free(error);
726 free(buf);
727 return;
728 }
729
730 v->mounted = e_hal_property_bool_get(ret, "volume.is_mounted", &err);
731 if (err) printf("HAL Error : can't get volume.is_mounted property");
732
733 if (v->mount_point) eina_stringshare_del(v->mount_point);
734 v->mount_point = e_hal_property_string_get(ret, "volume.mount_point", &err);
735 if (err) printf("HAL Error : can't get volume.is_mount_point property");
736 v->mount_point = eina_stringshare_add(v->mount_point);
737
738// printf("**VOL udi: %s mount_point: %s mounted: %d\n", v->udi, v->mount_point, v->mounted);
739 {
740 char *buf;
741 int size;
742
743 size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1;
744 buf = alloca(size);
745 strcpy(buf, v->udi);
746 strcpy(buf + strlen(buf) + 1, v->mount_point);
747 if (v->mounted)
748 ecore_ipc_server_send(_e_fm_ipc_server,
749 6/*E_IPC_DOMAIN_FM*/,
750 E_FM_OP_MOUNT_DONE,
751 0, 0, 0, buf, size);
752 else
753 ecore_ipc_server_send(_e_fm_ipc_server,
754 6/*E_IPC_DOMAIN_FM*/,
755 E_FM_OP_UNMOUNT_DONE,
756 0, 0, 0, buf, size);
757 }
758 return;
759}
760
761static Eina_List *_e_vols = NULL;
762
763EAPI E_Volume *
764e_volume_add(const char *udi, char first_time)
765{ 173{
766 E_Volume *v; 174 _E_FM(volume_unmount)(v);
767
768 if (!udi) return NULL;
769 if (e_volume_find(udi)) return NULL;
770 v = calloc(1, sizeof(E_Volume));
771 if (!v) return NULL;
772// printf("VOL+ %s\n", udi);
773 v->udi = eina_stringshare_add(udi);
774 v->icon = NULL;
775 v->first_time = first_time;
776 _e_vols = eina_list_append(_e_vols, v);
777 e_hal_device_get_all_properties(_e_dbus_conn, v->udi,
778 _e_dbus_cb_vol_prop, v);
779 v->prop_handler = e_dbus_signal_handler_add(_e_dbus_conn, E_HAL_SENDER,
780 udi,
781 E_HAL_DEVICE_INTERFACE,
782 "PropertyModified", _e_dbus_cb_prop_modified, v);
783 v->guard = NULL;
784
785 return v;
786} 175}
787 176
788EAPI void 177EAPI void
789e_volume_del(const char *udi) 178e_volume_eject(E_Volume *v)
790{ 179{
791 E_Volume *v; 180 _E_FM(volume_eject)(v);
792
793 v = e_volume_find(udi);
794 if (!v) return;
795 if (v->guard)
796 {
797 ecore_timer_del(v->guard);
798 v->guard = NULL;
799 }
800 if (v->prop_handler) e_dbus_signal_handler_del(_e_dbus_conn, v->prop_handler);
801 if (v->validated)
802 {
803// printf("--VOL %s\n", v->udi);
804 /* FIXME: send event of storage volume (disk) removed */
805 ecore_ipc_server_send(_e_fm_ipc_server,
806 6/*E_IPC_DOMAIN_FM*/,
807 E_FM_OP_VOLUME_DEL,
808 0, 0, 0, v->udi, strlen(v->udi) + 1);
809 }
810 _e_vols = eina_list_remove(_e_vols, v);
811 _e_volume_free(v);
812} 181}
813 182
814EAPI E_Volume * 183EAPI E_Volume *
815e_volume_find(const char *udi) 184e_volume_find(const char *udi)
816{ 185{
817 Eina_List *l; 186 return _E_FM(volume_find)(udi);
818 E_Volume *v;
819
820 EINA_LIST_FOREACH(_e_vols, l, v)
821 {
822 if (!strcmp(udi, v->udi)) return v;
823 }
824 return NULL;
825}
826
827static Eina_Bool
828_e_dbus_vol_mount_timeout(void *data)
829{
830 E_Volume *v = data;
831 DBusError error;
832 char *buf;
833 int size;
834
835 v->guard = NULL;
836 dbus_pending_call_cancel(v->op);
837 error.name = "org.enlightenment.fm2.MountTimeout";
838 error.message = "Unable to mount the volume with specified time-out.";
839 size = _e_dbus_format_error_msg(&buf, v, &error);
840 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR,
841 0, 0, 0, buf, size);
842 free(buf);
843
844 return ECORE_CALLBACK_CANCEL;
845}
846
847static void
848_e_dbus_cb_vol_mounted(void *user_data, void *method_return __UNUSED__, DBusError *error)
849{
850 E_Volume *v = user_data;
851 char *buf;
852 int size;
853
854 if (v->guard)
855 {
856 ecore_timer_del(v->guard);
857 v->guard = NULL;
858 }
859
860 if (dbus_error_is_set(error))
861 {
862 size = _e_dbus_format_error_msg(&buf, v, error);
863 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR,
864 0, 0, 0, buf, size);
865 dbus_error_free(error);
866 free(buf);
867 return;
868 }
869
870#if 0
871 v->mounted = EINA_TRUE;
872// printf("MOUNT: %s from %s\n", v->udi, v->mount_point);
873 size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1;
874 buf = alloca(size);
875 strcpy(buf, v->udi);
876 strcpy(buf + strlen(buf) + 1, v->mount_point);
877 ecore_ipc_server_send(_e_fm_ipc_server,
878 6/*E_IPC_DOMAIN_FM*/,
879 E_FM_OP_MOUNT_DONE,
880 0, 0, 0, buf, size);
881#endif
882} 187}
883 188
884EAPI void 189EAPI void
885e_volume_mount(E_Volume *v) 190e_storage_del(const char *udi)
886{
887 char buf[256];
888 char buf2[256];
889 const char *mount_point;
890 Eina_List *opt = NULL;
891
892 if (!v || v->guard || !v->mount_point || strncmp(v->mount_point, "/media/", 7))
893 return;
894
895 mount_point = v->mount_point + 7;
896// printf("mount %s %s [fs type = %s]\n", v->udi, v->mount_point, v->fstype);
897
898 if ((!strcmp(v->fstype, "vfat")) ||
899 (!strcmp(v->fstype, "ntfs"))
900 )
901 {
902#if !defined(__FreeBSD__)
903 snprintf(buf, sizeof(buf), "uid=%i", (int)getuid());
904 opt = eina_list_append(opt, buf);
905#endif
906 }
907
908 if ((!strcmp(v->fstype, "vfat")) ||
909 (!strcmp(v->fstype, "ntfs")) ||
910 (!strcmp(v->fstype, "iso9660"))
911 )
912 {
913 snprintf(buf2, sizeof(buf2), "utf8");
914 opt = eina_list_append(opt, buf2);
915 }
916 else if ((!strcmp(v->fstype, "fat")) ||
917 (!strcmp(v->fstype, "jfs"))
918// (!strcmp(v->fstype, "udf"))
919 )
920 {
921 snprintf(buf2, sizeof(buf2), "iocharset=utf8");
922 opt = eina_list_append(opt, buf2);
923 }
924
925 v->guard = ecore_timer_add(E_FM_MOUNT_TIMEOUT, _e_dbus_vol_mount_timeout, v);
926 v->op = e_hal_device_volume_mount(_e_dbus_conn, v->udi, mount_point,
927 v->fstype, opt, _e_dbus_cb_vol_mounted, v);
928 eina_list_free(opt);
929}
930
931static Eina_Bool
932_e_dbus_vol_unmount_timeout(void *data)
933{
934 E_Volume *v = data;
935 DBusError error;
936 char *buf;
937 int size;
938
939 v->guard = NULL;
940 dbus_pending_call_cancel(v->op);
941 error.name = "org.enlightenment.fm2.UnmountTimeout";
942 error.message = "Unable to unmount the volume with specified time-out.";
943 size = _e_dbus_format_error_msg(&buf, v, &error);
944 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR,
945 0, 0, 0, buf, size);
946 free(buf);
947
948 return ECORE_CALLBACK_CANCEL;
949}
950
951static void
952_e_dbus_cb_vol_unmounted(void *user_data, void *method_return __UNUSED__, DBusError *error)
953{
954 E_Volume *v = user_data;
955 char *buf;
956 int size;
957
958 if (v->guard)
959 {
960 ecore_timer_del(v->guard);
961 v->guard = NULL;
962 }
963
964 if (dbus_error_is_set(error))
965 {
966 size = _e_dbus_format_error_msg(&buf, v, error);
967 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR,
968 0, 0, 0, buf, size);
969 dbus_error_free(error);
970 free(buf);
971 return;
972 }
973
974#if 0
975 v->mounted = EINA_FALSE;
976// printf("UNMOUNT: %s from %s\n", v->udi, v->mount_point);
977 size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1;
978 buf = alloca(size);
979 strcpy(buf, v->udi);
980 strcpy(buf + strlen(buf) + 1, v->mount_point);
981 ecore_ipc_server_send(_e_fm_ipc_server,
982 6/*E_IPC_DOMAIN_FM*/,
983 E_FM_OP_UNMOUNT_DONE,
984 0, 0, 0, buf, size);
985#endif
986}
987
988EAPI void
989e_volume_unmount(E_Volume *v)
990{
991// printf("unmount %s %s\n", v->udi, v->mount_point);
992 if (!v || v->guard) return;
993
994 v->guard = ecore_timer_add(E_FM_UNMOUNT_TIMEOUT, _e_dbus_vol_unmount_timeout, v);
995 v->op = e_hal_device_volume_unmount(_e_dbus_conn, v->udi, NULL,
996 _e_dbus_cb_vol_unmounted, v);
997}
998
999static Eina_Bool
1000_e_dbus_vol_eject_timeout(void *data)
1001{
1002 E_Volume *v = data;
1003 DBusError error;
1004 char *buf;
1005 int size;
1006
1007 v->guard = NULL;
1008 dbus_pending_call_cancel(v->op);
1009 error.name = "org.enlightenment.fm2.EjectTimeout";
1010 error.message = "Unable to eject the media with specified time-out.";
1011 size = _e_dbus_format_error_msg(&buf, v, &error);
1012 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_EJECT_ERROR,
1013 0, 0, 0, buf, size);
1014 free(buf);
1015
1016 return ECORE_CALLBACK_CANCEL;
1017}
1018
1019static Eina_Bool
1020_e_dbus_vb_vol_ejecting_after_unmount(void *data)
1021{ 191{
1022 E_Volume *v = data; 192 _E_FM(storage_del)(udi);
1023
1024 v->guard = ecore_timer_add(E_FM_EJECT_TIMEOUT, _e_dbus_vol_eject_timeout, v);
1025 v->op = e_hal_device_volume_eject(_e_dbus_conn, v->udi, NULL,
1026 _e_dbus_cb_vol_ejected, v);
1027
1028 return ECORE_CALLBACK_CANCEL;
1029} 193}
1030 194
1031static void 195EAPI E_Storage *
1032_e_dbus_cb_vol_unmounted_before_eject(void *user_data, void *method_return, DBusError *error) 196e_storage_find(const char *udi)
1033{ 197{
1034 E_Volume *v = user_data; 198 return _E_FM(storage_find)(udi);
1035 char err;
1036
1037 err = dbus_error_is_set(error) ? 1 : 0;
1038 _e_dbus_cb_vol_unmounted(user_data, method_return, error);
1039
1040 // delay is required for all message handlers were executed after unmount
1041 if (!err)
1042 ecore_timer_add(1.0, _e_dbus_vb_vol_ejecting_after_unmount, v);
1043} 199}
1044 200
1045static void 201void
1046_e_dbus_cb_vol_ejected(void *user_data, void *method_return __UNUSED__, DBusError *error) 202_e_storage_free(E_Storage *s)
1047{ 203{
1048 E_Volume *v = user_data; 204 _E_FM_SHARED(storage_free)(s);
1049 char *buf;
1050 int size;
1051
1052 if (v->guard)
1053 {
1054 ecore_timer_del(v->guard);
1055 v->guard = NULL;
1056 }
1057
1058 if (dbus_error_is_set(error))
1059 {
1060 size = _e_dbus_format_error_msg(&buf, v, error);
1061 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_EJECT_ERROR,
1062 0, 0, 0, buf, size);
1063 dbus_error_free(error);
1064 free(buf);
1065 return;
1066 }
1067
1068 size = strlen(v->udi) + 1;
1069 buf = alloca(size);
1070 strcpy(buf, v->udi);
1071 ecore_ipc_server_send(_e_fm_ipc_server,
1072 6/*E_IPC_DOMAIN_FM*/,
1073 E_FM_OP_EJECT_DONE,
1074 0, 0, 0, buf, size);
1075} 205}
1076 206
1077EAPI void 207void
1078e_volume_eject(E_Volume *v) 208_e_volume_free(E_Volume *v)
1079{ 209{
1080 if (!v || v->guard) return; 210 _E_FM_SHARED(volume_free)(v);
1081
1082 if (v->mounted)
1083 {
1084 v->guard = ecore_timer_add(E_FM_UNMOUNT_TIMEOUT, _e_dbus_vol_unmount_timeout, v);
1085 v->op = e_hal_device_volume_unmount(_e_dbus_conn, v->udi, NULL,
1086 _e_dbus_cb_vol_unmounted_before_eject, v);
1087 }
1088 else
1089 {
1090 v->guard = ecore_timer_add(E_FM_EJECT_TIMEOUT, _e_dbus_vol_eject_timeout, v);
1091 v->op = e_hal_device_volume_eject(_e_dbus_conn, v->udi, NULL,
1092 _e_dbus_cb_vol_ejected, v);
1093 }
1094} 211}
diff --git a/src/bin/e_fm/e_fm_main.h b/src/bin/e_fm/e_fm_main.h
new file mode 100644
index 0000000..1022576
--- /dev/null
+++ b/src/bin/e_fm/e_fm_main.h
@@ -0,0 +1,10 @@
1#ifndef E_FM_MAIN_H
2#define E_FM_MAIN_H
3
4extern Ecore_Ipc_Server *_e_fm_ipc_server;
5
6#define E_FM_MOUNT_TIMEOUT 30.0
7#define E_FM_UNMOUNT_TIMEOUT 60.0
8#define E_FM_EJECT_TIMEOUT 15.0
9
10#endif
diff --git a/src/bin/e_fm/e_fm_main_dbus.c b/src/bin/e_fm/e_fm_main_dbus.c
new file mode 100644
index 0000000..5438933
--- /dev/null
+++ b/src/bin/e_fm/e_fm_main_dbus.c
@@ -0,0 +1,1002 @@
1#include "config.h"
2
3#ifdef HAVE_ALLOCA_H
4# include <alloca.h>
5#elif defined __GNUC__
6# define alloca __builtin_alloca
7#elif defined _AIX
8# define alloca __alloca
9#elif defined _MSC_VER
10# include <malloc.h>
11# define alloca _alloca
12#else
13# include <stddef.h>
14# ifdef __cplusplus
15extern "C"
16# endif
17void *alloca (size_t);
18#endif
19
20#ifdef __linux__
21#include <features.h>
22#endif
23#include <stdio.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include <string.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <sys/time.h>
30#include <sys/param.h>
31#include <utime.h>
32#include <math.h>
33#include <fnmatch.h>
34#include <limits.h>
35#include <ctype.h>
36#include <time.h>
37#include <dirent.h>
38#include <pwd.h>
39#include <glob.h>
40#include <errno.h>
41#include <signal.h>
42#include <Ecore.h>
43#include <Ecore_Ipc.h>
44#include <Ecore_File.h>
45#include <Eet.h>
46#include <E_DBus.h>
47#include <E_Hal.h>
48
49#include "e_fm_main.h"
50#include "e_fm_main_dbus.h"
51
52#include "e_fm_shared_codec.h"
53#include "e_fm_shared_dbus.h"
54#include "e_fm_ipc.h"
55#include "e_fm_dbus.h"
56
57static E_DBus_Signal_Handler *_hal_poll = NULL;
58static E_DBus_Connection *_e_fm_main_dbus_conn = NULL;
59
60static void _e_fm_main_dbus_cb_dev_all(void *user_data, void *reply_data, DBusError *error);
61static void _e_fm_main_dbus_cb_dev_store(void *user_data, void *reply_data, DBusError *error);
62static void _e_fm_main_dbus_cb_dev_vol(void *user_data, void *reply_data, DBusError *error);
63static void _e_fm_main_dbus_cb_store_is(void *user_data, void *reply_data, DBusError *error);
64static void _e_fm_main_dbus_cb_vol_is(void *user_data, void *reply_data, DBusError *error);
65static void _e_fm_main_dbus_cb_dev_add(void *data, DBusMessage *msg);
66static void _e_fm_main_dbus_cb_dev_del(void *data, DBusMessage *msg);
67static void _e_fm_main_dbus_cb_cap_add(void *data, DBusMessage *msg);
68static void _e_fm_main_dbus_cb_prop_modified(void *data, DBusMessage *msg);
69static void _e_fm_main_dbus_cb_store_prop(void *data, void *reply_data, DBusError *error);
70static void _e_fm_main_dbus_cb_vol_prop(void *data, void *reply_data, DBusError *error);
71static void _e_fm_main_dbus_cb_vol_prop_mount_modified(void *data, void *reply_data, DBusError *error);
72static void _e_fm_main_dbus_cb_vol_mounted(void *user_data, void *method_return, DBusError *error);
73static void _e_fm_main_dbus_cb_vol_unmounted(void *user_data, void *method_return, DBusError *error);
74static void _e_fm_main_dbus_cb_vol_unmounted_before_eject(void *user_data, void *method_return, DBusError *error);
75
76static Eina_Bool _e_fm_main_dbus_vb_vol_ejecting_after_unmount(void *data);
77static void _e_fm_main_dbus_cb_vol_ejected(void *user_data, void *method_return, DBusError *error);
78static int _e_fm_main_dbus_format_error_msg(char **buf, E_Volume *v, DBusError *error);
79static void _e_fm_main_dbus_hal_test(void *data, DBusMessage *msg, DBusError *error);
80static void _e_fm_main_dbus_hal_poll(void *data, DBusMessage *msg);
81
82static Eina_Bool _e_fm_main_dbus_vol_mount_timeout(void *data);
83static Eina_Bool _e_fm_main_dbus_vol_unmount_timeout(void *data);
84static Eina_Bool _e_fm_main_dbus_vol_eject_timeout(void *data);
85
86static void
87_e_fm_main_dbus_hal_poll(void *data __UNUSED__, DBusMessage *msg)
88{
89 DBusError err;
90 const char *name, *from, *to;
91
92 dbus_error_init(&err);
93 if (!dbus_message_get_args(msg, &err,
94 DBUS_TYPE_STRING, &name,
95 DBUS_TYPE_STRING, &from,
96 DBUS_TYPE_STRING, &to,
97 DBUS_TYPE_INVALID))
98 dbus_error_free(&err);
99
100 printf("name: %s\nfrom: %s\nto: %s\n", name, from, to);
101 if ((name) && !strcmp(name, E_HAL_SENDER))
102 _e_fm_main_dbus_hal_test(NULL, NULL, NULL);
103}
104
105static void
106_e_fm_main_dbus_hal_test(void *data __UNUSED__, DBusMessage *msg __UNUSED__, DBusError *error)
107{
108 if ((error) && (dbus_error_is_set(error)))
109 {
110 dbus_error_free(error);
111 if (!_hal_poll)
112 _hal_poll =
113 e_dbus_signal_handler_add(_e_fm_main_dbus_conn,
114 E_DBUS_FDO_BUS, E_DBUS_FDO_PATH,
115 E_DBUS_FDO_INTERFACE,
116 "NameOwnerChanged", _e_fm_main_dbus_hal_poll, NULL);
117 return;
118 }
119 if (_hal_poll)
120 e_dbus_signal_handler_del(_e_fm_main_dbus_conn, _hal_poll);
121
122 e_hal_manager_get_all_devices(_e_fm_main_dbus_conn, _e_fm_main_dbus_cb_dev_all, NULL);
123 e_hal_manager_find_device_by_capability(_e_fm_main_dbus_conn, "storage",
124 _e_fm_main_dbus_cb_dev_store, NULL);
125 e_hal_manager_find_device_by_capability(_e_fm_main_dbus_conn, "volume",
126 _e_fm_main_dbus_cb_dev_vol, NULL);
127
128 e_dbus_signal_handler_add(_e_fm_main_dbus_conn, E_HAL_SENDER,
129 E_HAL_MANAGER_PATH,
130 E_HAL_MANAGER_INTERFACE,
131 "DeviceAdded", _e_fm_main_dbus_cb_dev_add, NULL);
132 e_dbus_signal_handler_add(_e_fm_main_dbus_conn, E_HAL_SENDER,
133 E_HAL_MANAGER_PATH,
134 E_HAL_MANAGER_INTERFACE,
135 "DeviceRemoved", _e_fm_main_dbus_cb_dev_del, NULL);
136 e_dbus_signal_handler_add(_e_fm_main_dbus_conn, E_HAL_SENDER,
137 E_HAL_MANAGER_PATH,
138 E_HAL_MANAGER_INTERFACE,
139 "NewCapability", _e_fm_main_dbus_cb_cap_add, NULL);
140}
141
142static void
143_e_fm_main_dbus_cb_dev_all(void *user_data __UNUSED__, void *reply_data, DBusError *error)
144{
145 E_Hal_Manager_Get_All_Devices_Return *ret = reply_data;
146 Eina_List *l;
147 char *udi;
148
149 if (!ret || !ret->strings) return;
150
151 if (dbus_error_is_set(error))
152 {
153 dbus_error_free(error);
154 return;
155 }
156
157 EINA_LIST_FOREACH(ret->strings, l, udi)
158 {
159// printf("DB INIT DEV+: %s\n", udi);
160 e_hal_device_query_capability(_e_fm_main_dbus_conn, udi, "storage",
161 _e_fm_main_dbus_cb_store_is, (void*)eina_stringshare_add(udi));
162 e_hal_device_query_capability(_e_fm_main_dbus_conn, udi, "volume",
163 _e_fm_main_dbus_cb_vol_is, (void*)eina_stringshare_add(udi));
164 }
165}
166
167static void
168_e_fm_main_dbus_cb_dev_store(void *user_data __UNUSED__, void *reply_data, DBusError *error)
169{
170 E_Hal_Manager_Find_Device_By_Capability_Return *ret = reply_data;
171 Eina_List *l;
172 char *device;
173
174 if (!ret || !ret->strings) return;
175
176 if (dbus_error_is_set(error))
177 {
178 dbus_error_free(error);
179 return;
180 }
181
182 EINA_LIST_FOREACH(ret->strings, l, device)
183 {
184// printf("DB STORE+: %s\n", device);
185 _e_fm_main_dbus_storage_add(device);
186 }
187}
188
189static void
190_e_fm_main_dbus_cb_dev_vol(void *user_data __UNUSED__, void *reply_data, DBusError *error)
191{
192 E_Hal_Manager_Find_Device_By_Capability_Return *ret = reply_data;
193 Eina_List *l;
194 char *device;
195
196 if (!ret || !ret->strings) return;
197
198 if (dbus_error_is_set(error))
199 {
200 dbus_error_free(error);
201 return;
202 }
203
204 EINA_LIST_FOREACH(ret->strings, l, device)
205 {
206// printf("DB VOL+: %s\n", device);
207 _e_fm_main_dbus_volume_add(device, 1);
208 }
209}
210
211static void
212_e_fm_main_dbus_cb_store_is(void *user_data, void *reply_data, DBusError *error)
213{
214 char *udi = user_data;
215 E_Hal_Device_Query_Capability_Return *ret = reply_data;
216
217 if (dbus_error_is_set(error))
218 {
219 dbus_error_free(error);
220 goto error;
221 }
222
223 if (ret && ret->boolean)
224 {
225// printf("DB STORE IS+: %s\n", udi);
226 _e_fm_main_dbus_storage_add(udi);
227 }
228
229 error:
230 eina_stringshare_del(udi);
231}
232
233static void
234_e_fm_main_dbus_cb_vol_is(void *user_data, void *reply_data, DBusError *error)
235{
236 char *udi = user_data;
237 E_Hal_Device_Query_Capability_Return *ret = reply_data;
238
239 if (dbus_error_is_set(error))
240 {
241 dbus_error_free(error);
242 goto error;
243 }
244
245 if (ret && ret->boolean)
246 {
247// printf("DB VOL IS+: %s\n", udi);
248 _e_fm_main_dbus_volume_add(udi, 0);
249 }
250
251 error:
252 eina_stringshare_del(udi);
253}
254
255static void
256_e_fm_main_dbus_cb_dev_add(void *data __UNUSED__, DBusMessage *msg)
257{
258 DBusError err;
259 char *udi = NULL;
260
261 dbus_error_init(&err);
262 dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
263 if (!udi) return;
264 e_hal_device_query_capability(_e_fm_main_dbus_conn, udi, "storage",
265 _e_fm_main_dbus_cb_store_is, (void*)eina_stringshare_add(udi));
266 e_hal_device_query_capability(_e_fm_main_dbus_conn, udi, "volume",
267 _e_fm_main_dbus_cb_vol_is, (void*)eina_stringshare_add(udi));
268}
269
270static void
271_e_fm_main_dbus_cb_dev_del(void *data __UNUSED__, DBusMessage *msg)
272{
273 DBusError err;
274 char *udi;
275
276 dbus_error_init(&err);
277
278 dbus_message_get_args(msg,
279 &err, DBUS_TYPE_STRING,
280 &udi, DBUS_TYPE_INVALID);
281// printf("DB DEV-: %s\n", udi);
282 _e_fm_main_dbus_storage_del(udi);
283 _e_fm_main_dbus_volume_del(udi);
284}
285
286static void
287_e_fm_main_dbus_cb_cap_add(void *data __UNUSED__, DBusMessage *msg)
288{
289 DBusError err;
290 char *udi, *capability;
291
292 dbus_error_init(&err);
293
294 dbus_message_get_args(msg,
295 &err, DBUS_TYPE_STRING,
296 &udi, DBUS_TYPE_STRING,
297 &capability, DBUS_TYPE_INVALID);
298 if (!strcmp(capability, "storage"))
299 {
300// printf("DB STORE CAP+: %s\n", udi);
301 _e_fm_main_dbus_storage_add(udi);
302 }
303}
304
305static void
306_e_fm_main_dbus_cb_prop_modified(void *data, DBusMessage *msg)
307{
308 E_Volume *v;
309 DBusMessageIter iter, sub, subsub;
310 struct {
311 const char *name;
312 int added;
313 int removed;
314 } prop;
315 int num_changes = 0, i;
316
317 if (!(v = data)) return;
318
319 if (dbus_message_get_error_name(msg))
320 {
321 printf("DBUS ERROR: %s\n", dbus_message_get_error_name(msg));
322 return;
323 }
324 if (!dbus_message_iter_init(msg, &iter)) return;
325
326 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) return;
327 dbus_message_iter_get_basic(&iter, &num_changes);
328 if (num_changes == 0) return;
329
330 dbus_message_iter_next(&iter);
331 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) return;
332 dbus_message_iter_recurse(&iter, &sub);
333
334 for (i = 0; i < num_changes; i++, dbus_message_iter_next(&sub))
335 {
336 dbus_message_iter_recurse(&sub, &subsub);
337
338 if (dbus_message_iter_get_arg_type(&subsub) != DBUS_TYPE_STRING) break;
339 dbus_message_iter_get_basic(&subsub, &(prop.name));
340 if (!strcmp(prop.name, "volume.mount_point"))
341 {
342 e_hal_device_get_all_properties(_e_fm_main_dbus_conn, v->udi,
343 _e_fm_main_dbus_cb_vol_prop_mount_modified,
344 v);
345 return;
346 }
347
348 dbus_message_iter_next(&subsub);
349 dbus_message_iter_next(&subsub);
350 }
351}
352
353static void
354_e_fm_main_dbus_cb_store_prop(void *data, void *reply_data, DBusError *error)
355{
356 E_Storage *s = data;
357 E_Hal_Properties *ret = reply_data;
358 int err = 0;
359
360 if (!ret) goto error;
361
362 if (dbus_error_is_set(error))
363 {
364 dbus_error_free(error);
365 goto error;
366 }
367
368 s->bus = e_hal_property_string_get(ret, "storage.bus", &err);
369 if (err) goto error;
370 s->bus = eina_stringshare_add(s->bus);
371 s->drive_type = e_hal_property_string_get(ret, "storage.drive_type", &err);
372 if (err) goto error;
373 s->drive_type = eina_stringshare_add(s->drive_type);
374 s->model = e_hal_property_string_get(ret, "storage.model", &err);
375 if (err) goto error;
376 s->model = eina_stringshare_add(s->model);
377 s->vendor = e_hal_property_string_get(ret, "storage.vendor", &err);
378 if (err) goto error;
379 s->vendor = eina_stringshare_add(s->vendor);
380 s->serial = e_hal_property_string_get(ret, "storage.serial", &err);
381// if (err) goto error;
382 if (err) printf("Error getting serial for %s\n", s->udi);
383 s->serial = eina_stringshare_add(s->serial);
384
385 s->removable = e_hal_property_bool_get(ret, "storage.removable", &err);
386
387 if (s->removable)
388 {
389 s->media_available = e_hal_property_bool_get(ret, "storage.removable.media_available", &err);
390 s->media_size = e_hal_property_uint64_get(ret, "storage.removable.media_size", &err);
391 }
392
393 s->requires_eject = e_hal_property_bool_get(ret, "storage.requires_eject", &err);
394 s->hotpluggable = e_hal_property_bool_get(ret, "storage.hotpluggable", &err);
395 s->media_check_enabled = e_hal_property_bool_get(ret, "storage.media_check_enabled", &err);
396
397 s->icon.drive = e_hal_property_string_get(ret, "storage.icon.drive", &err);
398 s->icon.drive = eina_stringshare_add(s->icon.drive);
399 s->icon.volume = e_hal_property_string_get(ret, "storage.icon.volume", &err);
400 s->icon.volume = eina_stringshare_add(s->icon.volume);
401
402// printf("++STO:\n udi: %s\n bus: %s\n drive_type: %s\n model: %s\n vendor: %s\n serial: %s\n icon.drive: %s\n icon.volume: %s\n\n", s->udi, s->bus, s->drive_type, s->model, s->vendor, s->serial, s->icon.drive, s->icon.volume);
403 s->validated = EINA_TRUE;
404 {
405 void *msg_data;
406 int msg_size;
407
408 msg_data = _e_fm_shared_codec_storage_encode(s, &msg_size);
409 if (msg_data)
410 {
411 ecore_ipc_server_send(_e_fm_ipc_server,
412 6/*E_IPC_DOMAIN_FM*/,
413 E_FM_OP_STORAGE_ADD,
414 0, 0, 0, msg_data, msg_size);
415 free(msg_data);
416 }
417 }
418 return;
419
420 error:
421// printf("ERR %s\n", s->udi);
422 _e_fm_main_dbus_storage_del(s->udi);
423}
424
425static void
426_e_fm_main_dbus_cb_vol_prop(void *data, void *reply_data, DBusError *error)
427{
428 E_Volume *v = data;
429 E_Storage *s = NULL;
430 E_Hal_Device_Get_All_Properties_Return *ret = reply_data;
431 int err = 0;
432 const char *str = NULL;
433
434 if (!ret) goto error;
435 if (dbus_error_is_set(error))
436 {
437 dbus_error_free(error);
438 goto error;
439 }
440
441 /* skip volumes with volume.ignore set */
442 if (e_hal_property_bool_get(ret, "volume.ignore", &err) || err)
443 goto error;
444
445 /* skip volumes that aren't filesystems */
446 str = e_hal_property_string_get(ret, "volume.fsusage", &err);
447 if (err || !str) goto error;
448 if (strcmp(str, "filesystem")) goto error;
449 str = NULL;
450
451 v->uuid = e_hal_property_string_get(ret, "volume.uuid", &err);
452 if (err) goto error;
453 v->uuid = eina_stringshare_add(v->uuid);
454
455 v->label = e_hal_property_string_get(ret, "volume.label", &err);
456// if (err) goto error;
457 v->label = eina_stringshare_add(v->label);
458
459 v->fstype = e_hal_property_string_get(ret, "volume.fstype", &err);
460// if (err) goto error;
461 v->fstype = eina_stringshare_add(v->fstype);
462
463 v->size = e_hal_property_uint64_get(ret, "volume.size", &err);
464
465 v->mounted = e_hal_property_bool_get(ret, "volume.is_mounted", &err);
466 if (err) goto error;
467
468 v->partition = e_hal_property_bool_get(ret, "volume.is_partition", &err);
469 if (err) goto error;
470
471 v->mount_point = e_hal_property_string_get(ret, "volume.mount_point", &err);
472 if (err) goto error;
473 v->mount_point = eina_stringshare_add(v->mount_point);
474
475 if (v->partition)
476 {
477 v->partition_number = e_hal_property_int_get(ret, "volume.partition.number", NULL);
478 v->partition_label = e_hal_property_string_get(ret, "volume.partition.label", NULL);
479 v->partition_label = eina_stringshare_add(v->partition_label);
480 }
481
482 v->parent = e_hal_property_string_get(ret, "info.parent", &err);
483 if ((!err) && (v->parent))
484 {
485 s = e_storage_find(v->parent);
486 if (s)
487 {
488 v->storage = s;
489 s->volumes = eina_list_append(s->volumes, v);
490 }
491 }
492 v->parent = eina_stringshare_add(v->parent);
493
494// printf("++VOL:\n udi: %s\n uuid: %s\n fstype: %s\n size: %llu\n label: %s\n partition: %d\n partition_number: %d\n partition_label: %s\n mounted: %d\n mount_point: %s\n", v->udi, v->uuid, v->fstype, v->size, v->label, v->partition, v->partition_number, v->partition ? v->partition_label : "(not a partition)", v->mounted, v->mount_point);
495// if (s) printf(" for storage: %s\n", s->udi);
496// else printf(" storage unknown\n");
497 v->validated = EINA_TRUE;
498 {
499 void *msg_data;
500 int msg_size;
501
502 msg_data = _e_fm_shared_codec_volume_encode(v, &msg_size);
503 if (msg_data)
504 {
505 ecore_ipc_server_send(_e_fm_ipc_server,
506 6/*E_IPC_DOMAIN_FM*/,
507 E_FM_OP_VOLUME_ADD,
508 0, 0, 0, msg_data, msg_size);
509 free(msg_data);
510 }
511 }
512 return;
513
514 error:
515 _e_fm_main_dbus_volume_del(v->udi);
516 return;
517}
518
519static int
520_e_fm_main_dbus_format_error_msg(char **buf, E_Volume *v, DBusError *error)
521{
522 int size, vu, vm, en;
523 char *tmp;
524
525 vu = strlen(v->udi) + 1;
526 vm = strlen(v->mount_point) + 1;
527 en = strlen(error->name) + 1;
528 size = vu + vm + en + strlen(error->message) + 1;
529 tmp = *buf = malloc(size);
530
531 strcpy(tmp, v->udi);
532 tmp += vu;
533 strcpy(tmp, v->mount_point);
534 tmp += vm;
535 strcpy(tmp, error->name);
536 tmp += en;
537 strcpy(tmp, error->message);
538
539 return size;
540}
541
542static void
543_e_fm_main_dbus_cb_vol_prop_mount_modified(void *data, void *reply_data, DBusError *error)
544{
545 E_Volume *v = data;
546 E_Hal_Device_Get_All_Properties_Return *ret = reply_data;
547 int err = 0;
548
549 if (!ret) return;
550 if (dbus_error_is_set(error))
551 {
552 char *buf;
553 int size;
554
555 size = _e_fm_main_dbus_format_error_msg(&buf, v, error);
556 if (v->mounted)
557 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR,
558 0, 0, 0, buf, size);
559 else
560 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR,
561 0, 0, 0, buf, size);
562 dbus_error_free(error);
563 free(buf);
564 return;
565 }
566
567 v->mounted = e_hal_property_bool_get(ret, "volume.is_mounted", &err);
568 if (err) printf("HAL Error : can't get volume.is_mounted property");
569
570 if (v->mount_point) eina_stringshare_del(v->mount_point);
571 v->mount_point = e_hal_property_string_get(ret, "volume.mount_point", &err);
572 if (err) printf("HAL Error : can't get volume.is_mount_point property");
573 v->mount_point = eina_stringshare_add(v->mount_point);
574
575// printf("**VOL udi: %s mount_point: %s mounted: %d\n", v->udi, v->mount_point, v->mounted);
576 {
577 char *buf;
578 int size;
579
580 size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1;
581 buf = alloca(size);
582 strcpy(buf, v->udi);
583 strcpy(buf + strlen(buf) + 1, v->mount_point);
584 if (v->mounted)
585 ecore_ipc_server_send(_e_fm_ipc_server,
586 6/*E_IPC_DOMAIN_FM*/,
587 E_FM_OP_MOUNT_DONE,
588 0, 0, 0, buf, size);
589 else
590 ecore_ipc_server_send(_e_fm_ipc_server,
591 6/*E_IPC_DOMAIN_FM*/,
592 E_FM_OP_UNMOUNT_DONE,
593 0, 0, 0, buf, size);
594 }
595 return;
596}
597
598static Eina_Bool
599_e_fm_main_dbus_vol_mount_timeout(void *data)
600{
601 E_Volume *v = data;
602 DBusError error;
603 char *buf;
604 int size;
605
606 v->guard = NULL;
607 dbus_pending_call_cancel(v->op);
608 error.name = "org.enlightenment.fm2.MountTimeout";
609 error.message = "Unable to mount the volume with specified time-out.";
610 size = _e_fm_main_dbus_format_error_msg(&buf, v, &error);
611 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR,
612 0, 0, 0, buf, size);
613 free(buf);
614
615 return ECORE_CALLBACK_CANCEL;
616}
617
618static void
619_e_fm_main_dbus_cb_vol_mounted(void *user_data, void *method_return __UNUSED__, DBusError *error)
620{
621 E_Volume *v = user_data;
622 char *buf;
623 int size;
624
625 if (v->guard)
626 {
627 ecore_timer_del(v->guard);
628 v->guard = NULL;
629 }
630
631 if (dbus_error_is_set(error))
632 {
633 size = _e_fm_main_dbus_format_error_msg(&buf, v, error);
634 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR,
635 0, 0, 0, buf, size);
636 dbus_error_free(error);
637 free(buf);
638 return;
639 }
640
641#if 0
642 v->mounted = EINA_TRUE;
643// printf("MOUNT: %s from %s\n", v->udi, v->mount_point);
644 size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1;
645 buf = alloca(size);
646 strcpy(buf, v->udi);
647 strcpy(buf + strlen(buf) + 1, v->mount_point);
648 ecore_ipc_server_send(_e_fm_ipc_server,
649 6/*E_IPC_DOMAIN_FM*/,
650 E_FM_OP_MOUNT_DONE,
651 0, 0, 0, buf, size);
652#endif
653}
654
655
656static Eina_Bool
657_e_fm_main_dbus_vol_unmount_timeout(void *data)
658{
659 E_Volume *v = data;
660 DBusError error;
661 char *buf;
662 int size;
663
664 v->guard = NULL;
665 dbus_pending_call_cancel(v->op);
666 error.name = "org.enlightenment.fm2.UnmountTimeout";
667 error.message = "Unable to unmount the volume with specified time-out.";
668 size = _e_fm_main_dbus_format_error_msg(&buf, v, &error);
669 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR,
670 0, 0, 0, buf, size);
671 free(buf);
672
673 return ECORE_CALLBACK_CANCEL;
674}
675
676static void
677_e_fm_main_dbus_cb_vol_unmounted(void *user_data, void *method_return __UNUSED__, DBusError *error)
678{
679 E_Volume *v = user_data;
680 char *buf;
681 int size;
682
683 if (v->guard)
684 {
685 ecore_timer_del(v->guard);
686 v->guard = NULL;
687 }
688
689 if (dbus_error_is_set(error))
690 {
691 size = _e_fm_main_dbus_format_error_msg(&buf, v, error);
692 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR,
693 0, 0, 0, buf, size);
694 dbus_error_free(error);
695 free(buf);
696 return;
697 }
698
699#if 0
700 v->mounted = EINA_FALSE;
701// printf("UNMOUNT: %s from %s\n", v->udi, v->mount_point);
702 size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1;
703 buf = alloca(size);
704 strcpy(buf, v->udi);
705 strcpy(buf + strlen(buf) + 1, v->mount_point);
706 ecore_ipc_server_send(_e_fm_ipc_server,
707 6/*E_IPC_DOMAIN_FM*/,
708 E_FM_OP_UNMOUNT_DONE,
709 0, 0, 0, buf, size);
710#endif
711}
712
713
714static Eina_Bool
715_e_fm_main_dbus_vol_eject_timeout(void *data)
716{
717 E_Volume *v = data;
718 DBusError error;
719 char *buf;
720 int size;
721
722 v->guard = NULL;
723 dbus_pending_call_cancel(v->op);
724 error.name = "org.enlightenment.fm2.EjectTimeout";
725 error.message = "Unable to eject the media with specified time-out.";
726 size = _e_fm_main_dbus_format_error_msg(&buf, v, &error);
727 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_EJECT_ERROR,
728 0, 0, 0, buf, size);
729 free(buf);
730
731 return ECORE_CALLBACK_CANCEL;
732}
733
734static Eina_Bool
735_e_fm_main_dbus_vb_vol_ejecting_after_unmount(void *data)
736{
737 E_Volume *v = data;
738
739 v->guard = ecore_timer_add(E_FM_EJECT_TIMEOUT, _e_fm_main_dbus_vol_eject_timeout, v);
740 v->op = e_hal_device_volume_eject(_e_fm_main_dbus_conn, v->udi, NULL,
741 _e_fm_main_dbus_cb_vol_ejected, v);
742
743 return ECORE_CALLBACK_CANCEL;
744}
745
746static void
747_e_fm_main_dbus_cb_vol_unmounted_before_eject(void *user_data, void *method_return, DBusError *error)
748{
749 E_Volume *v = user_data;
750 char err;
751
752 err = dbus_error_is_set(error) ? 1 : 0;
753 _e_fm_main_dbus_cb_vol_unmounted(user_data, method_return, error);
754
755 // delay is required for all message handlers were executed after unmount
756 if (!err)
757 ecore_timer_add(1.0, _e_fm_main_dbus_vb_vol_ejecting_after_unmount, v);
758}
759
760static void
761_e_fm_main_dbus_cb_vol_ejected(void *user_data, void *method_return __UNUSED__, DBusError *error)
762{
763 E_Volume *v = user_data;
764 char *buf;
765 int size;
766
767 if (v->guard)
768 {
769 ecore_timer_del(v->guard);
770 v->guard = NULL;
771 }
772
773 if (dbus_error_is_set(error))
774 {
775 size = _e_fm_main_dbus_format_error_msg(&buf, v, error);
776 ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_EJECT_ERROR,
777 0, 0, 0, buf, size);
778 dbus_error_free(error);
779 free(buf);
780 return;
781 }
782
783 size = strlen(v->udi) + 1;
784 buf = alloca(size);
785 strcpy(buf, v->udi);
786 ecore_ipc_server_send(_e_fm_ipc_server,
787 6/*E_IPC_DOMAIN_FM*/,
788 E_FM_OP_EJECT_DONE,
789 0, 0, 0, buf, size);
790}
791
792static Eina_List *_e_vols = NULL;
793
794E_Volume *
795_e_fm_main_dbus_volume_add(const char *udi, Eina_Bool first_time)
796{
797 E_Volume *v;
798
799 if (!udi) return NULL;
800 if (e_volume_find(udi)) return NULL;
801 v = calloc(1, sizeof(E_Volume));
802 if (!v) return NULL;
803// printf("VOL+ %s\n", udi);
804 v->udi = eina_stringshare_add(udi);
805 v->icon = NULL;
806 v->first_time = first_time;
807 _e_vols = eina_list_append(_e_vols, v);
808 e_hal_device_get_all_properties(_e_fm_main_dbus_conn, v->udi,
809 _e_fm_main_dbus_cb_vol_prop, v);
810 v->prop_handler = e_dbus_signal_handler_add(_e_fm_main_dbus_conn,
811 E_HAL_SENDER,
812 udi,
813 E_HAL_DEVICE_INTERFACE,
814 "PropertyModified",
815 _e_fm_main_dbus_cb_prop_modified, v);
816 v->guard = NULL;
817
818 return v;
819}
820
821void
822_e_fm_main_dbus_volume_del(const char *udi)
823{
824 E_Volume *v;
825
826 v = e_volume_find(udi);
827 if (!v) return;
828 if (v->guard)
829 {
830 ecore_timer_del(v->guard);
831 v->guard = NULL;
832 }
833 if (v->prop_handler) e_dbus_signal_handler_del(_e_fm_main_dbus_conn, v->prop_handler);
834 if (v->validated)
835 {
836 // printf("--VOL %s\n", v->udi);
837 /* FIXME: send event of storage volume (disk) removed */
838 ecore_ipc_server_send(_e_fm_ipc_server,
839 6/*E_IPC_DOMAIN_FM*/,
840 E_FM_OP_VOLUME_DEL,
841 0, 0, 0, v->udi, eina_stringshare_strlen(v->udi) + 1);
842 }
843 _e_vols = eina_list_remove(_e_vols, v);
844 _e_fm_shared_dbus_volume_free(v);
845}
846
847E_Volume *
848_e_fm_main_dbus_volume_find(const char *udi)
849{
850 Eina_List *l;
851 E_Volume *v;
852
853 EINA_LIST_FOREACH(_e_vols, l, v)
854 {
855 if (udi == v->udi) return v;
856 }
857 return NULL;
858}
859
860void
861_e_fm_main_dbus_volume_eject(E_Volume *v)
862{
863 if (!v || v->guard) return;
864 if (v->mounted)
865 {
866 v->guard = ecore_timer_add(E_FM_UNMOUNT_TIMEOUT, _e_fm_main_dbus_vol_unmount_timeout, v);
867 v->op = e_hal_device_volume_unmount(_e_fm_main_dbus_conn, v->udi, NULL,
868 _e_fm_main_dbus_cb_vol_unmounted_before_eject, v);
869 }
870 else
871 {
872 v->guard = ecore_timer_add(E_FM_EJECT_TIMEOUT, _e_fm_main_dbus_vol_eject_timeout, v);
873 v->op = e_hal_device_volume_eject(_e_fm_main_dbus_conn, v->udi, NULL,
874 _e_fm_main_dbus_cb_vol_ejected, v);
875 }
876}
877
878void
879_e_fm_main_dbus_volume_unmount(E_Volume *v)
880{
881// printf("unmount %s %s\n", v->udi, v->mount_point);
882 if (!v || v->guard) return;
883
884 v->guard = ecore_timer_add(E_FM_UNMOUNT_TIMEOUT, _e_fm_main_dbus_vol_unmount_timeout, v);
885 v->op = e_hal_device_volume_unmount(_e_fm_main_dbus_conn, v->udi, NULL,
886 _e_fm_main_dbus_cb_vol_unmounted, v);
887}
888
889void
890_e_fm_main_dbus_volume_mount(E_Volume *v)
891{
892 char buf[256];
893 char buf2[256];
894 const char *mount_point;
895 Eina_List *opt = NULL;
896
897 if (!v || v->guard || !v->mount_point || strncmp(v->mount_point, "/media/", 7))
898 return;
899
900 mount_point = v->mount_point + 7;
901// printf("mount %s %s [fs type = %s]\n", v->udi, v->mount_point, v->fstype);
902
903 if ((!strcmp(v->fstype, "vfat")) ||
904 (!strcmp(v->fstype, "ntfs"))
905 )
906 {
907 snprintf(buf, sizeof(buf), "uid=%i", (int)getuid());
908 opt = eina_list_append(opt, buf);
909 }
910
911 if ((!strcmp(v->fstype, "vfat")) ||
912 (!strcmp(v->fstype, "ntfs")) ||
913 (!strcmp(v->fstype, "iso9660"))
914 )
915 {
916 snprintf(buf2, sizeof(buf2), "utf8");
917 opt = eina_list_append(opt, buf2);
918 }
919 else if ((!strcmp(v->fstype, "fat")) ||
920 (!strcmp(v->fstype, "jfs"))
921// (!strcmp(v->fstype, "udf"))
922 )
923 {
924 snprintf(buf2, sizeof(buf2), "iocharset=utf8");
925 opt = eina_list_append(opt, buf2);
926 }
927
928 v->guard = ecore_timer_add(E_FM_MOUNT_TIMEOUT, _e_fm_main_dbus_vol_mount_timeout, v);
929 v->op = e_hal_device_volume_mount(_e_fm_main_dbus_conn, v->udi, mount_point,
930 v->fstype, opt, _e_fm_main_dbus_cb_vol_mounted, v);
931 eina_list_free(opt);
932}
933
934void
935_e_fm_main_dbus_init(void)
936{
937 e_dbus_init();
938 e_hal_init();
939 _e_fm_main_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
940 /* previously, this assumed that if dbus was running, hal was running. */
941 if (_e_fm_main_dbus_conn)
942 e_dbus_get_name_owner(_e_fm_main_dbus_conn, E_HAL_SENDER, _e_fm_main_dbus_hal_test, NULL);
943}
944
945void
946_e_fm_main_dbus_shutdown(void)
947{
948 if (_e_fm_main_dbus_conn)
949 e_dbus_connection_close(_e_fm_main_dbus_conn);
950 e_hal_shutdown();
951 e_dbus_shutdown();
952}
953
954static Eina_List *_e_stores = NULL;
955
956E_Storage *
957_e_fm_main_dbus_storage_add(const char *udi)
958{
959 E_Storage *s;
960
961 if (!udi) return NULL;
962 if (e_storage_find(udi)) return NULL;
963 s = calloc(1, sizeof(E_Storage));
964 if (!s) return NULL;
965 s->udi = eina_stringshare_add(udi);
966 _e_stores = eina_list_append(_e_stores, s);
967 e_hal_device_get_all_properties(_e_fm_main_dbus_conn, s->udi,
968 _e_fm_main_dbus_cb_store_prop, s);
969 return s;
970}
971
972void
973_e_fm_main_dbus_storage_del(const char *udi)
974{
975 E_Storage *s;
976
977 s = e_storage_find(udi);
978 if (!s) return;
979 if (s->validated)
980 {
981 // printf("--STO %s\n", s->udi);
982 ecore_ipc_server_send(_e_fm_ipc_server,
983 6/*E_IPC_DOMAIN_FM*/,
984 E_FM_OP_STORAGE_DEL,
985 0, 0, 0, s->udi, strlen(s->udi) + 1);
986 }
987 _e_stores = eina_list_remove(_e_stores, s);
988 _e_fm_shared_dbus_storage_free(s);
989}
990
991E_Storage *
992_e_fm_main_dbus_storage_find(const char *udi)
993{
994 Eina_List *l;
995 E_Storage *s;
996
997 EINA_LIST_FOREACH(_e_stores, l, s)
998 {
999 if (udi == s->udi) return s;
1000 }
1001 return NULL;
1002}
diff --git a/src/bin/e_fm/e_fm_main_dbus.h b/src/bin/e_fm/e_fm_main_dbus.h
new file mode 100644
index 0000000..52a1618
--- /dev/null
+++ b/src/bin/e_fm/e_fm_main_dbus.h
@@ -0,0 +1,25 @@
1#ifndef E_FM_MAIN_DBUS_H
2#define E_FM_MAIN_DBUS_H
3
4#include <E_DBus.h>
5#include <E_Hal.h>
6
7#include "e_fm_shared_types.h"
8
9E_Volume *_e_fm_main_dbus_volume_add(const char *udi, Eina_Bool first_time);
10void _e_fm_main_dbus_volume_del(const char *udi);
11E_Volume *_e_fm_main_dbus_volume_find(const char *udi);
12
13void _e_fm_main_dbus_volume_eject(E_Volume *v);
14void _e_fm_main_dbus_volume_unmount(E_Volume *v);
15void _e_fm_main_dbus_volume_mount(E_Volume *v);
16
17E_Storage *_e_fm_main_dbus_storage_add(const char *udi);
18void _e_fm_main_dbus_storage_del(const char *udi);
19E_Storage *_e_fm_main_dbus_storage_find(const char *udi);
20
21
22void _e_fm_main_dbus_init(void);
23void _e_fm_main_dbus_shutdown(void);
24
25#endif
diff --git a/src/bin/e_fm_dbus.c b/src/bin/e_fm_dbus.c
index fe77187..914fdb0 100644
--- a/src/bin/e_fm_dbus.c
+++ b/src/bin/e_fm_dbus.c
@@ -1,8 +1,6 @@
1#include "e_fm_dbus.h" 1#include "e_fm_dbus.h"
2 2#include "e_fm_shared_codec.h"
3#define E_FM_SHARED_CODEC 3#include "e_fm_shared_dbus.h"
4#include "e_fm_shared.h"
5#undef E_FM_SHARED_CODEC
6 4
7static void _e_fm2_volume_write(E_Volume *v) EINA_ARG_NONNULL(1); 5static void _e_fm2_volume_write(E_Volume *v) EINA_ARG_NONNULL(1);
8static void _e_fm2_volume_erase(E_Volume *v) EINA_ARG_NONNULL(1); 6static void _e_fm2_volume_erase(E_Volume *v) EINA_ARG_NONNULL(1);
@@ -74,7 +72,7 @@ e_fm2_dbus_storage_del(E_Storage *s)
74{ 72{
75// printf("STO- %s\n", s->udi); 73// printf("STO- %s\n", s->udi);
76 _e_stores = eina_list_remove(_e_stores, s); 74 _e_stores = eina_list_remove(_e_stores, s);
77 _e_storage_free(s); 75 _e_fm_shared_dbus_storage_free(s);
78} 76}
79 77
80EAPI E_Storage * 78EAPI E_Storage *
@@ -279,7 +277,7 @@ e_fm2_dbus_volume_del(E_Volume *v)
279 _e_fm2_dbus_unmount_ok(m); 277 _e_fm2_dbus_unmount_ok(m);
280 _e_fm2_dbus_mount_free(m); 278 _e_fm2_dbus_mount_free(m);
281 } 279 }
282 _e_volume_free(v); 280 _e_fm_shared_dbus_volume_free(v);
283} 281}
284 282
285static void 283static void
diff --git a/src/bin/e_fm_shared.h b/src/bin/e_fm_shared.h
deleted file mode 100644
index 2617834..0000000
--- a/src/bin/e_fm_shared.h
+++ /dev/null
@@ -1,209 +0,0 @@
1#ifdef E_FM_SHARED_DATATYPES
2
3# define E_DEVICE_TYPE_STORAGE 1
4# define E_DEVICE_TYPE_VOLUME 2
5typedef struct _E_Storage E_Storage;
6typedef struct _E_Volume E_Volume;
7typedef struct _E_Fm2_Mount E_Fm2_Mount;
8
9struct _E_Storage
10{
11 int type;
12 const char *udi, *bus;
13 const char *drive_type;
14
15 const char *model, *vendor, *serial;
16
17 Eina_Bool removable;
18 Eina_Bool media_available;
19 unsigned long long media_size;
20
21 Eina_Bool requires_eject;
22 Eina_Bool hotpluggable;
23 Eina_Bool media_check_enabled;
24
25 struct
26 {
27 const char *drive, *volume;
28 } icon;
29
30 Eina_List *volumes;
31
32 Eina_Bool validated : 1;
33 Eina_Bool trackable : 1;
34};
35
36struct _E_Volume
37{
38 int type;
39 const char *udi, *uuid;
40 const char *label, *icon, *fstype;
41 unsigned long long size;
42
43 Eina_Bool partition;
44 int partition_number;
45 const char *partition_label;
46 Eina_Bool mounted;
47 const char *mount_point;
48
49 const char *parent;
50 E_Storage *storage;
51 void *prop_handler;
52 Eina_List *mounts;
53
54 Eina_Bool validated : 1;
55
56 Eina_Bool auto_unmount : 1; // unmount, when last associated fm window closed
57 Eina_Bool first_time; // volume discovery in init sequence
58 Ecore_Timer *guard; // operation guard timer
59 DBusPendingCall *op; // d-bus call handle
60};
61
62struct _E_Fm2_Mount
63{
64 const char *udi;
65 const char *mount_point;
66
67 Ecore_Cb mount_ok;
68 Ecore_Cb mount_fail;
69 Ecore_Cb unmount_ok;
70 Ecore_Cb unmount_fail;
71 void *data;
72
73 E_Volume *volume;
74
75 Eina_Bool mounted : 1;
76};
77
78#endif
79
80#ifdef E_FM_SHARED_CODEC
81static Eet_Data_Descriptor *_e_volume_edd = NULL;
82static Eet_Data_Descriptor *_e_storage_edd = NULL;
83
84static void
85_e_volume_free(E_Volume *v)
86{
87 if (v->storage)
88 {
89 v->storage->volumes = eina_list_remove(v->storage->volumes, v);
90 v->storage = NULL;
91 }
92 if (v->udi) eina_stringshare_del(v->udi);
93 if (v->uuid) eina_stringshare_del(v->uuid);
94 if (v->label) eina_stringshare_del(v->label);
95 if (v->icon) eina_stringshare_del(v->icon);
96 if (v->fstype) eina_stringshare_del(v->fstype);
97 if (v->partition_label) eina_stringshare_del(v->partition_label);
98 if (v->mount_point) eina_stringshare_del(v->mount_point);
99 if (v->parent) eina_stringshare_del(v->parent);
100 free(v);
101}
102
103static void
104_e_storage_free(E_Storage *s)
105{
106 E_Volume *v;
107 EINA_LIST_FREE(s->volumes, v)
108 {
109 v->storage = NULL;
110 _e_volume_free(v);
111 }
112 if (s->udi) eina_stringshare_del(s->udi);
113 if (s->bus) eina_stringshare_del(s->bus);
114 if (s->drive_type) eina_stringshare_del(s->drive_type);
115 if (s->model) eina_stringshare_del(s->model);
116 if (s->vendor) eina_stringshare_del(s->vendor);
117 if (s->serial) eina_stringshare_del(s->serial);
118 if (s->icon.drive) eina_stringshare_del(s->icon.drive);
119 if (s->icon.volume) eina_stringshare_del(s->icon.volume);
120 free(s);
121}
122
123static Eet_Data_Descriptor *
124_e_volume_edd_new(void)
125{
126 Eet_Data_Descriptor *edd;
127 Eet_Data_Descriptor_Class eddc;
128
129 if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc), "e_volume", sizeof(E_Volume)))
130 return NULL;
131
132// eddc.func.str_alloc = (char *(*)(const char *)) strdup;
133// eddc.func.str_free = (void (*)(const char *)) free;
134
135 edd = eet_data_descriptor_stream_new(&eddc);
136#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, E_Volume, #MEMBER, MEMBER, EET_T_##TYPE)
137 DAT(type, INT);
138 DAT(udi, STRING);
139 DAT(uuid, STRING);
140 DAT(label, STRING);
141 DAT(fstype, STRING);
142 DAT(size, ULONG_LONG);
143 DAT(partition, CHAR);
144 DAT(partition_number, INT);
145 DAT(partition_label, STRING);
146 DAT(mounted, CHAR);
147 DAT(mount_point, STRING);
148 DAT(parent, STRING);
149 DAT(first_time, CHAR);
150#undef DAT
151 return edd;
152}
153
154static Eet_Data_Descriptor *
155_e_storage_edd_new(void)
156{
157 Eet_Data_Descriptor *edd;
158 Eet_Data_Descriptor_Class eddc;
159
160 if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "e_storage", sizeof (E_Storage)))
161 return NULL;
162
163// eddc.func.str_alloc = (char *(*)(const char *)) strdup;
164// eddc.func.str_free = (void (*)(const char *)) free;
165
166 edd = eet_data_descriptor_stream_new(&eddc);
167#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, E_Storage, #MEMBER, MEMBER, EET_T_##TYPE)
168 DAT(type, INT);
169 DAT(udi, STRING);
170 DAT(bus, STRING);
171 DAT(drive_type, STRING);
172 DAT(model, STRING);
173 DAT(vendor, STRING);
174 DAT(serial, STRING);
175 DAT(removable, CHAR);
176 DAT(media_available, CHAR);
177 DAT(media_size, ULONG_LONG);
178 DAT(requires_eject, CHAR);
179 DAT(hotpluggable, CHAR);
180 DAT(media_check_enabled, CHAR);
181 DAT(icon.drive, STRING);
182 DAT(icon.volume, STRING);
183#undef DAT
184 return edd;
185}
186
187static void
188_e_storage_volume_edd_init(void)
189{
190 _e_volume_edd = _e_volume_edd_new();
191 _e_storage_edd = _e_storage_edd_new();
192}
193
194static void
195_e_storage_volume_edd_shutdown(void)
196{
197 if (_e_volume_edd)
198 {
199 eet_data_descriptor_free(_e_volume_edd);
200 _e_volume_edd = NULL;
201 }
202 if (_e_storage_edd)
203 {
204 eet_data_descriptor_free(_e_storage_edd);
205 _e_storage_edd = NULL;
206 }
207}
208
209#endif
diff --git a/src/bin/e_fm_shared_codec.c b/src/bin/e_fm_shared_codec.c
new file mode 100644
index 0000000..dd32424
--- /dev/null
+++ b/src/bin/e_fm_shared_codec.c
@@ -0,0 +1,116 @@
1#include "e_fm_shared_types.h"
2#include "e_fm_shared_codec.h"
3
4static Eet_Data_Descriptor *_e_volume_edd = NULL;
5static Eet_Data_Descriptor *_e_storage_edd = NULL;
6
7Eet_Data_Descriptor *
8_e_volume_edd_new(void)
9{
10 Eet_Data_Descriptor *edd;
11 Eet_Data_Descriptor_Class eddc;
12
13 if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc), "e_volume", sizeof(E_Volume)))
14 return NULL;
15
16// eddc.func.str_alloc = (char *(*)(const char *)) strdup;
17// eddc.func.str_free = (void (*)(const char *)) free;
18
19 edd = eet_data_descriptor_stream_new(&eddc);
20#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, E_Volume, #MEMBER, MEMBER, EET_T_##TYPE)
21 DAT(type, INT);
22 DAT(udi, STRING);
23 DAT(uuid, STRING);
24 DAT(label, STRING);
25 DAT(fstype, STRING);
26 DAT(size, ULONG_LONG);
27 DAT(partition, CHAR);
28 DAT(partition_number, INT);
29 DAT(partition_label, STRING);
30 DAT(mounted, CHAR);
31 DAT(mount_point, STRING);
32 DAT(parent, STRING);
33 DAT(first_time, CHAR);
34#undef DAT
35 return edd;
36}
37
38Eet_Data_Descriptor *
39_e_storage_edd_new(void)
40{
41 Eet_Data_Descriptor *edd;
42 Eet_Data_Descriptor_Class eddc;
43
44 if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "e_storage", sizeof (E_Storage)))
45 return NULL;
46
47// eddc.func.str_alloc = (char *(*)(const char *)) strdup;
48// eddc.func.str_free = (void (*)(const char *)) free;
49
50 edd = eet_data_descriptor_stream_new(&eddc);
51#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, E_Storage, #MEMBER, MEMBER, EET_T_##TYPE)
52 DAT(type, INT);
53 DAT(udi, STRING);
54 DAT(bus, STRING);
55 DAT(drive_type, STRING);
56 DAT(model, STRING);
57 DAT(vendor, STRING);
58 DAT(serial, STRING);
59 DAT(removable, CHAR);
60 DAT(media_available, CHAR);
61 DAT(media_size, ULONG_LONG);
62 DAT(requires_eject, CHAR);
63 DAT(hotpluggable, CHAR);
64 DAT(media_check_enabled, CHAR);
65 DAT(icon.drive, STRING);
66 DAT(icon.volume, STRING);
67#undef DAT
68 return edd;
69}
70
71void *
72_e_fm_shared_codec_storage_encode(E_Storage *s, int *size)
73{
74 return eet_data_descriptor_encode(_e_storage_edd, s, size);
75}
76
77E_Storage *
78_e_fm_shared_codec_storage_decode(void *s, int size)
79{
80 return eet_data_descriptor_decode(_e_storage_edd, s, size);
81}
82
83
84void *
85_e_fm_shared_codec_volume_encode(E_Volume *v, int *size)
86{
87 return eet_data_descriptor_encode(_e_volume_edd, v, size);
88}
89
90E_Volume *
91_e_fm_shared_codec_volume_decode(void *v, int size)
92{
93 return eet_data_descriptor_decode(_e_volume_edd, v, size);
94}
95
96void
97_e_storage_volume_edd_init(void)
98{
99 _e_volume_edd = _e_volume_edd_new();
100 _e_storage_edd = _e_storage_edd_new();
101}
102
103void
104_e_storage_volume_edd_shutdown(void)
105{
106 if (_e_volume_edd)
107 {
108 eet_data_descriptor_free(_e_volume_edd);
109 _e_volume_edd = NULL;
110 }
111 if (_e_storage_edd)
112 {
113 eet_data_descriptor_free(_e_storage_edd);
114 _e_storage_edd = NULL;
115 }
116}
diff --git a/src/bin/e_fm_shared_codec.h b/src/bin/e_fm_shared_codec.h
new file mode 100644
index 0000000..79cb4af
--- /dev/null
+++ b/src/bin/e_fm_shared_codec.h
@@ -0,0 +1,17 @@
1#ifndef E_FM_SHARED_CODEC
2#define E_FM_SHARED_CODEC
3
4#include <Eet.h>
5
6void *_e_fm_shared_codec_storage_encode(E_Storage *s, int *size);
7E_Storage *_e_fm_shared_codec_storage_decode(void *s, int size);
8void *_e_fm_shared_codec_volume_encode(E_Volume *v, int *size);
9E_Volume *_e_fm_shared_codec_volume_decode(void *v, int size);
10
11Eet_Data_Descriptor *_e_volume_edd_new(void);
12Eet_Data_Descriptor *_e_storage_edd_new(void);
13void _e_storage_volume_edd_init(void);
14void _e_storage_volume_edd_shutdown(void);
15
16
17#endif
diff --git a/src/bin/e_fm_shared_dbus.c b/src/bin/e_fm_shared_dbus.c
new file mode 100644
index 0000000..ee0e2ff
--- /dev/null
+++ b/src/bin/e_fm_shared_dbus.c
@@ -0,0 +1,42 @@
1#include "e_fm_shared_types.h"
2#include "e_fm_shared_dbus.h"
3
4void
5_e_fm_shared_dbus_storage_free(E_Storage *s)
6{
7 E_Volume *v;
8 EINA_LIST_FREE(s->volumes, v)
9 {
10 v->storage = NULL;
11 _e_fm_shared_dbus_volume_free(v);
12 }
13 if (s->udi) eina_stringshare_del(s->udi);
14 if (s->bus) eina_stringshare_del(s->bus);
15 if (s->drive_type) eina_stringshare_del(s->drive_type);
16 if (s->model) eina_stringshare_del(s->model);
17 if (s->vendor) eina_stringshare_del(s->vendor);
18 if (s->serial) eina_stringshare_del(s->serial);
19 if (s->icon.drive) eina_stringshare_del(s->icon.drive);
20 if (s->icon.volume) eina_stringshare_del(s->icon.volume);
21 free(s);
22}
23
24
25void
26_e_fm_shared_dbus_volume_free(E_Volume *v)
27{
28 if (v->storage)
29 {
30 v->storage->volumes = eina_list_remove(v->storage->volumes, v);
31 v->storage = NULL;
32 }
33 if (v->udi) eina_stringshare_del(v->udi);
34 if (v->uuid) eina_stringshare_del(v->uuid);
35 if (v->label) eina_stringshare_del(v->label);
36 if (v->icon) eina_stringshare_del(v->icon);
37 if (v->fstype) eina_stringshare_del(v->fstype);
38 if (v->partition_label) eina_stringshare_del(v->partition_label);
39 if (v->mount_point) eina_stringshare_del(v->mount_point);
40 if (v->parent) eina_stringshare_del(v->parent);
41 free(v);
42}
diff --git a/src/bin/e_fm_shared_dbus.h b/src/bin/e_fm_shared_dbus.h
new file mode 100644
index 0000000..e056bee
--- /dev/null
+++ b/src/bin/e_fm_shared_dbus.h
@@ -0,0 +1,9 @@
1#ifndef E_FM_SHARED_DBUS_H
2#define E_FM_SHARED_DBUS_H
3
4#include "e_fm_shared_types.h"
5
6void _e_fm_shared_dbus_storage_free(E_Storage *s);
7void _e_fm_shared_dbus_volume_free(E_Volume *v);
8
9#endif
diff --git a/src/bin/e_fm_shared_types.h b/src/bin/e_fm_shared_types.h
new file mode 100644
index 0000000..ee927dc
--- /dev/null
+++ b/src/bin/e_fm_shared_types.h
@@ -0,0 +1,85 @@
1#ifndef E_FM_SHARED_TYPES
2#define E_FM_SHARED_TYPES
3
4#include <Eina.h>
5#include <Ecore.h>
6#include <E_DBus.h>
7
8# define E_DEVICE_TYPE_STORAGE 1
9# define E_DEVICE_TYPE_VOLUME 2
10typedef struct _E_Storage E_Storage;
11typedef struct _E_Volume E_Volume;
12typedef struct _E_Fm2_Mount E_Fm2_Mount;
13
14#ifndef HAVE_EEZE_MOUNT
15struct _E_Storage
16{
17 int type;
18 const char *udi, *bus;
19 const char *drive_type;
20
21 const char *model, *vendor, *serial;
22
23 Eina_Bool removable;
24 Eina_Bool media_available;
25 unsigned long long media_size;
26
27 Eina_Bool requires_eject;
28 Eina_Bool hotpluggable;
29 Eina_Bool media_check_enabled;
30
31 struct
32 {
33 const char *drive, *volume;
34 } icon;
35
36 Eina_List *volumes;
37
38 Eina_Bool validated : 1;
39 Eina_Bool trackable : 1;
40};
41
42struct _E_Volume
43{
44 int type;
45 const char *udi, *uuid;
46 const char *label, *icon, *fstype;
47 unsigned long long size;
48
49 Eina_Bool partition;
50 int partition_number;
51 const char *partition_label;
52 Eina_Bool mounted;
53 const char *mount_point;
54
55 const char *parent;
56 E_Storage *storage;
57 void *prop_handler;
58 Eina_List *mounts;
59
60 Eina_Bool validated : 1;
61
62 Eina_Bool auto_unmount : 1; // unmount, when last associated fm window closed
63 Eina_Bool first_time; // volume discovery in init sequence
64 Ecore_Timer *guard; // operation guard timer
65 DBusPendingCall *op; // d-bus call handle
66};
67
68struct _E_Fm2_Mount
69{
70 const char *udi;
71 const char *mount_point;
72
73 Ecore_Cb mount_ok;
74 Ecore_Cb mount_fail;
75 Ecore_Cb unmount_ok;
76 Ecore_Cb unmount_fail;
77 void *data;
78
79 E_Volume *volume;
80
81 Eina_Bool mounted : 1;
82};
83
84#endif
85#endif