From 04662b3565fed1a9416154656f2fa77cef8aefeb Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 5 Oct 2010 06:33:23 +0000 Subject: [PATCH] complete rewrite of all includes and file splitting to completely abstract dbus out of efm SVN revision: 53051 --- src/bin/Makefile.am | 6 +- src/bin/e_fm.c | 9 +- src/bin/e_fm.h | 4 +- src/bin/e_fm/Makefile.am | 34 ++ src/bin/e_fm/e_fm_ipc.c | 11 +- src/bin/e_fm/e_fm_ipc.h | 2 + src/bin/e_fm/e_fm_main.c | 999 ++------------------------------ src/bin/e_fm/e_fm_main.h | 10 + src/bin/e_fm/e_fm_main_dbus.c | 1002 +++++++++++++++++++++++++++++++++ src/bin/e_fm/e_fm_main_dbus.h | 25 + src/bin/e_fm_dbus.c | 10 +- src/bin/e_fm_shared.h | 209 ------- src/bin/e_fm_shared_codec.c | 116 ++++ src/bin/e_fm_shared_codec.h | 17 + src/bin/e_fm_shared_dbus.c | 42 ++ src/bin/e_fm_shared_dbus.h | 9 + src/bin/e_fm_shared_types.h | 85 +++ 17 files changed, 1417 insertions(+), 1173 deletions(-) create mode 100644 src/bin/e_fm/Makefile.am create mode 100644 src/bin/e_fm/e_fm_main.h create mode 100644 src/bin/e_fm/e_fm_main_dbus.c create mode 100644 src/bin/e_fm/e_fm_main_dbus.h delete mode 100644 src/bin/e_fm_shared.h create mode 100644 src/bin/e_fm_shared_codec.c create mode 100644 src/bin/e_fm_shared_codec.h create mode 100644 src/bin/e_fm_shared_dbus.c create mode 100644 src/bin/e_fm_shared_dbus.h create mode 100644 src/bin/e_fm_shared_types.h diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index ab2f74205..4efdd937d 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -159,7 +159,9 @@ e_order.h \ e_exec.h \ e_widget_font_preview.h \ e_fm_custom.h \ -e_fm_shared.h \ +e_fm_shared_types.h \ +e_fm_shared_codec.h \ +e_fm_shared_dbus.h \ e_config_data.h \ e_intl_data.h \ e_toolbar.h \ @@ -277,6 +279,8 @@ e_confirm_dialog.c \ e_int_border_prop.c \ e_entry_dialog.c \ e_fm.c \ +e_fm_shared_codec.c \ +e_fm_shared_dbus.c \ e_fm_dbus.c \ e_fm_op_registry.c \ e_widget_scrollframe.c \ diff --git a/src/bin/e_fm.c b/src/bin/e_fm.c index 034978337..18e66abb8 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; * _e_storage_volume_edd_init() * _e_storage_volume_edd_shutdown() */ -#define E_FM_SHARED_CODEC -#include "e_fm_shared.h" -#undef E_FM_SHARED_CODEC + +#include "e_fm_shared_codec.h" static inline Eina_Bool _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) { E_Storage *s; - s = eet_data_descriptor_decode(_e_storage_edd, e->data, e->size); + s = _e_fm_shared_codec_storage_decode(e->data, e->size); if (s) e_fm2_dbus_storage_add(s); } break; @@ -2936,7 +2935,7 @@ e_fm2_client_data(Ecore_Ipc_Event_Client_Data *e) { E_Volume *v; - v = eet_data_descriptor_decode(_e_volume_edd, e->data, e->size); + v = _e_fm_shared_codec_volume_decode(e->data, e->size); if (v) { e_fm2_dbus_volume_add(v); diff --git a/src/bin/e_fm.h b/src/bin/e_fm.h index b7fd78ddf..55f61a501 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; typedef struct _E_Fm2_Icon E_Fm2_Icon; typedef struct _E_Fm2_Icon_Info E_Fm2_Icon_Info; -#define E_FM_SHARED_DATATYPES -#include "e_fm_shared.h" -#undef E_FM_SHARED_DATATYPES +#include "e_fm_shared_types.h" #else #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 000000000..385142795 --- /dev/null +++ b/src/bin/e_fm/Makefile.am @@ -0,0 +1,34 @@ +MAINTAINERCLEANFILES = Makefile.in + +INCLUDES = -I$(top_builddir) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src/bin \ + -I$(top_srcdir)/src/lib \ + @e_cflags@ \ + @x_cflags@ \ + @cf_cflags@ \ + @VALGRIND_CFLAGS@ \ + @EDJE_DEF@ \ + -DPACKAGE_BIN_DIR=\"@PACKAGE_BIN_DIR@\" \ + -DPACKAGE_LIB_DIR=\"@PACKAGE_LIB_DIR@\" \ + -DPACKAGE_DATA_DIR=\"@PACKAGE_DATA_DIR@\" \ + -DLOCALE_DIR=\"@LOCALE_DIR@\" \ + -DPACKAGE_SYSCONF_DIR=\"@PACKAGE_SYSCONF_DIR@\" + +internal_bindir = $(libdir)/enlightenment/utils +internal_bin_PROGRAMS = \ +enlightenment_fm + +enlightenment_fm_SOURCES = \ +e_fm_main.c \ +e_fm_main_dbus.c \ +e_fm_ipc.c \ +../e_fm_shared_codec.c \ +../e_fm_shared_dbus.c \ +../e_user.c \ +../e_sha1.c + +enlightenment_fm_LDADD = @E_FM_LIBS@ +enlightenment_fm_CFLAGS = $(INCLUDES) + + diff --git a/src/bin/e_fm/e_fm_ipc.c b/src/bin/e_fm/e_fm_ipc.c index fa0ebda8f..6fb0971b9 100644 --- a/src/bin/e_fm/e_fm_ipc.c +++ b/src/bin/e_fm/e_fm_ipc.c @@ -33,17 +33,12 @@ #include #include #include -#include -#ifdef HAVE_EUKIT -#include -#else -#include -#endif + #include #include "e.h" #include "e_fm_ipc.h" - +//#include "e_fm_shared_c.h" #include "e_fm_op.h" @@ -118,7 +113,7 @@ struct _E_Fm_Task int x,y; }; -#include "e_fm_shared.h" + /* local subsystem globals */ Ecore_Ipc_Server *_e_fm_ipc_server = NULL; diff --git a/src/bin/e_fm/e_fm_ipc.h b/src/bin/e_fm/e_fm_ipc.h index c8570091b..404e66631 100644 --- a/src/bin/e_fm/e_fm_ipc.h +++ b/src/bin/e_fm/e_fm_ipc.h @@ -1,6 +1,8 @@ #ifndef E_FM_IPC_H #define E_FM_IPC_H +#include "e_fm_shared_types.h" + int _e_fm_ipc_init(void); Eina_Bool _e_fm_ipc_slave_data_cb(void *data, int type, void *event); Eina_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 c91d6a9ed..3860de496 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); #include #include #include -#include -#include #include -#include -#ifdef HAVE_EUKIT -#include -#else -#include -#endif -#include +#include #define E_TYPEDEFS #include "e_config_data.h" @@ -60,56 +52,40 @@ void *alloca (size_t); #include "e_config_data.h" #include "e_fm_op.h" +/* if using ehal, functions will point to _e_fm_main_dbus_X + * if using eeze, functions will point to _e_fm_main_eeze_X + */ +#ifndef HAVE_EEZE_MOUNT +#include "e_fm_main_dbus.h" +#include "e_fm_shared_dbus.h" +#define _E_FM(FUNC) _e_fm_main_dbus_##FUNC +#define _E_FM_SHARED(FUNC) _e_fm_shared_dbus_##FUNC +#else +#include "e_fm_main_eeze.h" +#define _E_FM(FUNC) _e_fm_main_eeze_##FUNC +#define _E_FM_SHARED(FUNC) _e_fm_shared_eeze_##FUNC +#endif + /* FIXME: things to add to the slave enlightenment_fm process and ipc to e: * * * reporting results of fop's (current status - what has been don, what failed etc.) - * * dbus removable device monitoring (in e17 itself now via ecore_dbus - move to enlightenment_fm and ipc removable device add/del and anything else) + * * dbus removable device monitoring (in e17 itself now via e_dbus - move to enlightenment_fm and ipc removable device add/del and anything else) * * 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) * */ -static E_DBus_Signal_Handler *_hal_poll = NULL; #ifndef EAPI #define EAPI #endif -#define E_FM_SHARED_DATATYPES -#include "e_fm_shared.h" -#undef E_FM_SHARED_DATATYPES +#include "e_fm_main.h" +#include "e_fm_shared_types.h" +#include "e_fm_shared_codec.h" +#include "e_fm_ipc.h" + static void _e_fm_init(void); static void _e_fm_shutdown(void); -static void _e_dbus_cb_dev_all(void *user_data, void *reply_data, DBusError *error); -static void _e_dbus_cb_dev_store(void *user_data, void *reply_data, DBusError *error); -static void _e_dbus_cb_dev_vol(void *user_data, void *reply_data, DBusError *error); -static void _e_dbus_cb_store_is(void *user_data, void *reply_data, DBusError *error); -static void _e_dbus_cb_vol_is(void *user_data, void *reply_data, DBusError *error); -static void _e_dbus_cb_dev_add(void *data, DBusMessage *msg); -static void _e_dbus_cb_dev_del(void *data, DBusMessage *msg); -static void _e_dbus_cb_cap_add(void *data, DBusMessage *msg); -static void _e_dbus_cb_prop_modified(void *data, DBusMessage *msg); -static void _e_dbus_cb_store_prop(void *data, void *reply_data, DBusError *error); -static void _e_dbus_cb_vol_prop(void *data, void *reply_data, DBusError *error); -static void _e_dbus_cb_vol_prop_mount_modified(void *data, void *reply_data, DBusError *error); -static void _e_dbus_cb_vol_mounted(void *user_data, void *method_return, DBusError *error); -static void _e_dbus_cb_vol_unmounted(void *user_data, void *method_return, DBusError *error); -static void _e_dbus_cb_vol_unmounted_before_eject(void *user_data, void *method_return, DBusError *error); -static Eina_Bool _e_dbus_vb_vol_ejecting_after_unmount(void *data); -static void _e_dbus_cb_vol_ejected(void *user_data, void *method_return, DBusError *error); -static int _e_dbus_format_error_msg(char **buf, E_Volume *v, DBusError *error); -static void _hal_test(void *data, DBusMessage *msg, DBusError *error); -static void _e_hal_poll(void *data, DBusMessage *msg); - -static Eina_Bool _e_dbus_vol_mount_timeout(void *data); -static Eina_Bool _e_dbus_vol_unmount_timeout(void *data); -static Eina_Bool _e_dbus_vol_eject_timeout(void *data); - -#define E_FM_MOUNT_TIMEOUT 30.0 -#define E_FM_UNMOUNT_TIMEOUT 60.0 -#define E_FM_EJECT_TIMEOUT 15.0 - -static E_DBus_Connection *_e_dbus_conn = NULL; -extern Ecore_Ipc_Server *_e_fm_ipc_server; /* contains: * _e_volume_edd @@ -121,10 +97,7 @@ extern Ecore_Ipc_Server *_e_fm_ipc_server; * _e_storage_volume_edd_init() * _e_storage_volume_edd_shutdown() */ -#define E_FM_SHARED_CODEC -#include "e_fm_shared.h" -#undef E_FM_SHARED_CODEC -#include "e_fm_ipc.h" + /* externally accessible functions */ int main(int argc, char **argv) @@ -169,6 +142,7 @@ main(int argc, char **argv) } _e_fm_shutdown(); + _e_storage_volume_edd_shutdown(); ecore_ipc_shutdown(); ecore_file_shutdown(); ecore_shutdown(); @@ -178,917 +152,60 @@ main(int argc, char **argv) static void _e_fm_init(void) { - e_dbus_init(); - e_hal_init(); - _e_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM); - /* previously, this assumed that if dbus was running, hal was running. */ - if (_e_dbus_conn) - e_dbus_get_name_owner(_e_dbus_conn, E_HAL_SENDER, _hal_test, NULL); + _E_FM(init)(); } static void _e_fm_shutdown(void) { - if (_e_dbus_conn) - e_dbus_connection_close(_e_dbus_conn); - _e_storage_volume_edd_shutdown(); - e_hal_shutdown(); - e_dbus_shutdown(); -} - -static void -_e_hal_poll(void *data __UNUSED__, DBusMessage *msg) -{ - DBusError err; - const char *name, *from, *to; - - dbus_error_init(&err); - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_STRING, &from, - DBUS_TYPE_STRING, &to, - DBUS_TYPE_INVALID)) - dbus_error_free(&err); - - printf("name: %s\nfrom: %s\nto: %s\n", name, from, to); - if ((name) && !strcmp(name, E_HAL_SENDER)) - _hal_test(NULL, NULL, NULL); -} - -static void -_hal_test(void *data __UNUSED__, DBusMessage *msg __UNUSED__, DBusError *error) -{ - if ((error) && (dbus_error_is_set(error))) - { - dbus_error_free(error); - if (!_hal_poll) - _hal_poll = - e_dbus_signal_handler_add(_e_dbus_conn, - E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, - E_DBUS_FDO_INTERFACE, - "NameOwnerChanged", _e_hal_poll, NULL); - return; - } - if (_hal_poll) - e_dbus_signal_handler_del(_e_dbus_conn, _hal_poll); - - e_hal_manager_get_all_devices(_e_dbus_conn, _e_dbus_cb_dev_all, NULL); - e_hal_manager_find_device_by_capability(_e_dbus_conn, "storage", - _e_dbus_cb_dev_store, NULL); - e_hal_manager_find_device_by_capability(_e_dbus_conn, "volume", - _e_dbus_cb_dev_vol, NULL); - - e_dbus_signal_handler_add(_e_dbus_conn, E_HAL_SENDER, - E_HAL_MANAGER_PATH, - E_HAL_MANAGER_INTERFACE, - "DeviceAdded", _e_dbus_cb_dev_add, NULL); - e_dbus_signal_handler_add(_e_dbus_conn, E_HAL_SENDER, - E_HAL_MANAGER_PATH, - E_HAL_MANAGER_INTERFACE, - "DeviceRemoved", _e_dbus_cb_dev_del, NULL); - e_dbus_signal_handler_add(_e_dbus_conn, E_HAL_SENDER, - E_HAL_MANAGER_PATH, - E_HAL_MANAGER_INTERFACE, - "NewCapability", _e_dbus_cb_cap_add, NULL); -} - -static void -_e_dbus_cb_dev_all(void *user_data __UNUSED__, void *reply_data, DBusError *error) -{ - E_Hal_Manager_Get_All_Devices_Return *ret = reply_data; - Eina_List *l; - char *udi; - - if (!ret || !ret->strings) return; - - if (dbus_error_is_set(error)) - { - dbus_error_free(error); - return; - } - - EINA_LIST_FOREACH(ret->strings, l, udi) - { -// printf("DB INIT DEV+: %s\n", udi); - e_hal_device_query_capability(_e_dbus_conn, udi, "storage", - _e_dbus_cb_store_is, (void*)eina_stringshare_add(udi)); - e_hal_device_query_capability(_e_dbus_conn, udi, "volume", - _e_dbus_cb_vol_is, (void*)eina_stringshare_add(udi)); - } -} - -static void -_e_dbus_cb_dev_store(void *user_data __UNUSED__, void *reply_data, DBusError *error) -{ - E_Hal_Manager_Find_Device_By_Capability_Return *ret = reply_data; - Eina_List *l; - char *device; - - if (!ret || !ret->strings) return; - - if (dbus_error_is_set(error)) - { - dbus_error_free(error); - return; - } - - EINA_LIST_FOREACH(ret->strings, l, device) - { -// printf("DB STORE+: %s\n", device); - e_storage_add(device); - } -} - -static void -_e_dbus_cb_dev_vol(void *user_data __UNUSED__, void *reply_data, DBusError *error) -{ - E_Hal_Manager_Find_Device_By_Capability_Return *ret = reply_data; - Eina_List *l; - char *device; - - if (!ret || !ret->strings) return; - - if (dbus_error_is_set(error)) - { - dbus_error_free(error); - return; - } - - EINA_LIST_FOREACH(ret->strings, l, device) - { -// printf("DB VOL+: %s\n", device); - e_volume_add(device, 1); - } -} - -static void -_e_dbus_cb_store_is(void *user_data, void *reply_data, DBusError *error) -{ - char *udi = user_data; - E_Hal_Device_Query_Capability_Return *ret = reply_data; - - if (dbus_error_is_set(error)) - { - dbus_error_free(error); - goto error; - } - - if (ret && ret->boolean) - { -// printf("DB STORE IS+: %s\n", udi); - e_storage_add(udi); - } - - error: - eina_stringshare_del(udi); -} - -static void -_e_dbus_cb_vol_is(void *user_data, void *reply_data, DBusError *error) -{ - char *udi = user_data; - E_Hal_Device_Query_Capability_Return *ret = reply_data; - - if (dbus_error_is_set(error)) - { - dbus_error_free(error); - goto error; - } - - if (ret && ret->boolean) - { -// printf("DB VOL IS+: %s\n", udi); - e_volume_add(udi, 0); - } - - error: - eina_stringshare_del(udi); -} - -static void -_e_dbus_cb_dev_add(void *data __UNUSED__, DBusMessage *msg) -{ - DBusError err; - char *udi = NULL; - - dbus_error_init(&err); - dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID); - if (!udi) return; - e_hal_device_query_capability(_e_dbus_conn, udi, "storage", - _e_dbus_cb_store_is, (void*)eina_stringshare_add(udi)); - e_hal_device_query_capability(_e_dbus_conn, udi, "volume", - _e_dbus_cb_vol_is, (void*)eina_stringshare_add(udi)); -} - -static void -_e_dbus_cb_dev_del(void *data __UNUSED__, DBusMessage *msg) -{ - DBusError err; - char *udi; - - dbus_error_init(&err); - - dbus_message_get_args(msg, - &err, DBUS_TYPE_STRING, - &udi, DBUS_TYPE_INVALID); -// printf("DB DEV-: %s\n", udi); - e_storage_del(udi); - e_volume_del(udi); -} - -static void -_e_dbus_cb_cap_add(void *data __UNUSED__, DBusMessage *msg) -{ - DBusError err; - char *udi, *capability; - - dbus_error_init(&err); - - dbus_message_get_args(msg, - &err, DBUS_TYPE_STRING, - &udi, DBUS_TYPE_STRING, - &capability, DBUS_TYPE_INVALID); - if (!strcmp(capability, "storage")) - { -// printf("DB STORE CAP+: %s\n", udi); - e_storage_add(udi); - } -} - -static void -_e_dbus_cb_prop_modified(void *data, DBusMessage *msg) -{ - E_Volume *v; - DBusMessageIter iter, sub, subsub; - struct { - const char *name; - int added; - int removed; - } prop; - int num_changes = 0, i; - - if (!(v = data)) return; - - if (dbus_message_get_error_name(msg)) - { - printf("DBUS ERROR: %s\n", dbus_message_get_error_name(msg)); - return; - } - if (!dbus_message_iter_init(msg, &iter)) return; - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) return; - dbus_message_iter_get_basic(&iter, &num_changes); - if (num_changes == 0) return; - - dbus_message_iter_next(&iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) return; - dbus_message_iter_recurse(&iter, &sub); - - for (i = 0; i < num_changes; i++, dbus_message_iter_next(&sub)) - { - dbus_message_iter_recurse(&sub, &subsub); - - if (dbus_message_iter_get_arg_type(&subsub) != DBUS_TYPE_STRING) break; - dbus_message_iter_get_basic(&subsub, &(prop.name)); - if (!strcmp(prop.name, "volume.mount_point")) - { - e_hal_device_get_all_properties(_e_dbus_conn, v->udi, - _e_dbus_cb_vol_prop_mount_modified, - v); - return; - } - - dbus_message_iter_next(&subsub); - dbus_message_iter_next(&subsub); - } -} - -static void -_e_dbus_cb_store_prop(void *data, void *reply_data, DBusError *error) -{ - E_Storage *s = data; - E_Hal_Properties *ret = reply_data; - int err = 0; - - if (!ret) goto error; - - if (dbus_error_is_set(error)) - { - dbus_error_free(error); - goto error; - } - - s->bus = e_hal_property_string_get(ret, "storage.bus", &err); - if (err) goto error; - s->bus = eina_stringshare_add(s->bus); - s->drive_type = e_hal_property_string_get(ret, "storage.drive_type", &err); - if (err) goto error; - s->drive_type = eina_stringshare_add(s->drive_type); - s->model = e_hal_property_string_get(ret, "storage.model", &err); - if (err) goto error; - s->model = eina_stringshare_add(s->model); - s->vendor = e_hal_property_string_get(ret, "storage.vendor", &err); - if (err) goto error; - s->vendor = eina_stringshare_add(s->vendor); - s->serial = e_hal_property_string_get(ret, "storage.serial", &err); -// if (err) goto error; - if (err) printf("Error getting serial for %s\n", s->udi); - s->serial = eina_stringshare_add(s->serial); - - s->removable = e_hal_property_bool_get(ret, "storage.removable", &err); - - if (s->removable) - { - s->media_available = e_hal_property_bool_get(ret, "storage.removable.media_available", &err); - s->media_size = e_hal_property_uint64_get(ret, "storage.removable.media_size", &err); - } - - s->requires_eject = e_hal_property_bool_get(ret, "storage.requires_eject", &err); - s->hotpluggable = e_hal_property_bool_get(ret, "storage.hotpluggable", &err); - s->media_check_enabled = e_hal_property_bool_get(ret, "storage.media_check_enabled", &err); - - s->icon.drive = e_hal_property_string_get(ret, "storage.icon.drive", &err); - s->icon.drive = eina_stringshare_add(s->icon.drive); - s->icon.volume = e_hal_property_string_get(ret, "storage.icon.volume", &err); - s->icon.volume = eina_stringshare_add(s->icon.volume); - -// 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); - s->validated = EINA_TRUE; - { - void *msg_data; - int msg_size; - - msg_data = eet_data_descriptor_encode(_e_storage_edd, s, &msg_size); - if (msg_data) - { - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_STORAGE_ADD, - 0, 0, 0, msg_data, msg_size); - free(msg_data); - } - } - return; - - error: -// printf("ERR %s\n", s->udi); - e_storage_del(s->udi); -} - -static Eina_List *_e_stores = NULL; - -EAPI E_Storage * -e_storage_add(const char *udi) -{ - E_Storage *s; - - if (!udi) return NULL; - if (e_storage_find(udi)) return NULL; - s = calloc(1, sizeof(E_Storage)); - if (!s) return NULL; - s->udi = eina_stringshare_add(udi); - _e_stores = eina_list_append(_e_stores, s); - e_hal_device_get_all_properties(_e_dbus_conn, s->udi, - _e_dbus_cb_store_prop, s); - return s; -} - -EAPI void -e_storage_del(const char *udi) -{ - E_Storage *s; - - s = e_storage_find(udi); - if (!s) return; - if (s->validated) - { -// printf("--STO %s\n", s->udi); - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_STORAGE_DEL, - 0, 0, 0, s->udi, strlen(s->udi) + 1); - } - _e_stores = eina_list_remove(_e_stores, s); - _e_storage_free(s); -} - -E_Storage * -e_storage_find(const char *udi) -{ - Eina_List *l; - E_Storage *s; - - EINA_LIST_FOREACH(_e_stores, l, s) - { - if (!strcmp(udi, s->udi)) return s; - } - return NULL; -} - -static void -_e_dbus_cb_vol_prop(void *data, void *reply_data, DBusError *error) -{ - E_Volume *v = data; - E_Storage *s = NULL; - E_Hal_Device_Get_All_Properties_Return *ret = reply_data; - int err = 0; - const char *str = NULL; - - if (!ret) goto error; - if (dbus_error_is_set(error)) - { - dbus_error_free(error); - goto error; - } - - /* skip volumes with volume.ignore set */ - if (e_hal_property_bool_get(ret, "volume.ignore", &err) || err) - goto error; - - /* skip volumes that aren't filesystems */ - str = e_hal_property_string_get(ret, "volume.fsusage", &err); - if (err || !str) goto error; - if (strcmp(str, "filesystem")) goto error; - str = NULL; - - v->uuid = e_hal_property_string_get(ret, "volume.uuid", &err); - if (err) goto error; - v->uuid = eina_stringshare_add(v->uuid); - - v->label = e_hal_property_string_get(ret, "volume.label", &err); -// if (err) goto error; - v->label = eina_stringshare_add(v->label); - - v->fstype = e_hal_property_string_get(ret, "volume.fstype", &err); -// if (err) goto error; - v->fstype = eina_stringshare_add(v->fstype); - - v->size = e_hal_property_uint64_get(ret, "volume.size", &err); - - v->mounted = e_hal_property_bool_get(ret, "volume.is_mounted", &err); - if (err) goto error; - - v->partition = e_hal_property_bool_get(ret, "volume.is_partition", &err); - if (err) goto error; - - v->mount_point = e_hal_property_string_get(ret, "volume.mount_point", &err); - if (err) goto error; - v->mount_point = eina_stringshare_add(v->mount_point); - - if (v->partition) - { - v->partition_number = e_hal_property_int_get(ret, "volume.partition.number", NULL); - v->partition_label = e_hal_property_string_get(ret, "volume.partition.label", NULL); - v->partition_label = eina_stringshare_add(v->partition_label); - } - - v->parent = e_hal_property_string_get(ret, "info.parent", &err); - if ((!err) && (v->parent)) - { - s = e_storage_find(v->parent); - if (s) - { - v->storage = s; - s->volumes = eina_list_append(s->volumes, v); - } - } - v->parent = eina_stringshare_add(v->parent); - -// 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); -// if (s) printf(" for storage: %s\n", s->udi); -// else printf(" storage unknown\n"); - v->validated = EINA_TRUE; - { - void *msg_data; - int msg_size; - - msg_data = eet_data_descriptor_encode(_e_volume_edd, v, &msg_size); - if (msg_data) - { - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_VOLUME_ADD, - 0, 0, 0, msg_data, msg_size); - free(msg_data); - } - } - return; - - error: - e_volume_del(v->udi); - return; -} - -static int -_e_dbus_format_error_msg(char **buf, E_Volume *v, DBusError *error) -{ - int size, vu, vm, en; - char *tmp; - - vu = strlen(v->udi) + 1; - vm = strlen(v->mount_point) + 1; - en = strlen(error->name) + 1; - size = vu + vm + en + strlen(error->message) + 1; - tmp = *buf = malloc(size); - - strcpy(tmp, v->udi); - tmp += vu; - strcpy(tmp, v->mount_point); - tmp += vm; - strcpy(tmp, error->name); - tmp += en; - strcpy(tmp, error->message); - - return size; -} - -static void -_e_dbus_cb_vol_prop_mount_modified(void *data, void *reply_data, DBusError *error) -{ - E_Volume *v = data; - E_Hal_Device_Get_All_Properties_Return *ret = reply_data; - int err = 0; - - if (!ret) return; - if (dbus_error_is_set(error)) - { - char *buf; - int size; - - size = _e_dbus_format_error_msg(&buf, v, error); - if (v->mounted) - ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR, - 0, 0, 0, buf, size); - else - ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR, - 0, 0, 0, buf, size); - dbus_error_free(error); - free(buf); - return; - } - - v->mounted = e_hal_property_bool_get(ret, "volume.is_mounted", &err); - if (err) printf("HAL Error : can't get volume.is_mounted property"); - - if (v->mount_point) eina_stringshare_del(v->mount_point); - v->mount_point = e_hal_property_string_get(ret, "volume.mount_point", &err); - if (err) printf("HAL Error : can't get volume.is_mount_point property"); - v->mount_point = eina_stringshare_add(v->mount_point); - -// printf("**VOL udi: %s mount_point: %s mounted: %d\n", v->udi, v->mount_point, v->mounted); - { - char *buf; - int size; - - size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1; - buf = alloca(size); - strcpy(buf, v->udi); - strcpy(buf + strlen(buf) + 1, v->mount_point); - if (v->mounted) - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_MOUNT_DONE, - 0, 0, 0, buf, size); - else - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_UNMOUNT_DONE, - 0, 0, 0, buf, size); - } - return; -} - -static Eina_List *_e_vols = NULL; - -EAPI E_Volume * -e_volume_add(const char *udi, char first_time) -{ - E_Volume *v; - - if (!udi) return NULL; - if (e_volume_find(udi)) return NULL; - v = calloc(1, sizeof(E_Volume)); - if (!v) return NULL; -// printf("VOL+ %s\n", udi); - v->udi = eina_stringshare_add(udi); - v->icon = NULL; - v->first_time = first_time; - _e_vols = eina_list_append(_e_vols, v); - e_hal_device_get_all_properties(_e_dbus_conn, v->udi, - _e_dbus_cb_vol_prop, v); - v->prop_handler = e_dbus_signal_handler_add(_e_dbus_conn, E_HAL_SENDER, - udi, - E_HAL_DEVICE_INTERFACE, - "PropertyModified", _e_dbus_cb_prop_modified, v); - v->guard = NULL; - - return v; -} - -EAPI void -e_volume_del(const char *udi) -{ - E_Volume *v; - - v = e_volume_find(udi); - if (!v) return; - if (v->guard) - { - ecore_timer_del(v->guard); - v->guard = NULL; - } - if (v->prop_handler) e_dbus_signal_handler_del(_e_dbus_conn, v->prop_handler); - if (v->validated) - { -// printf("--VOL %s\n", v->udi); - /* FIXME: send event of storage volume (disk) removed */ - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_VOLUME_DEL, - 0, 0, 0, v->udi, strlen(v->udi) + 1); - } - _e_vols = eina_list_remove(_e_vols, v); - _e_volume_free(v); -} - -EAPI E_Volume * -e_volume_find(const char *udi) -{ - Eina_List *l; - E_Volume *v; - - EINA_LIST_FOREACH(_e_vols, l, v) - { - if (!strcmp(udi, v->udi)) return v; - } - return NULL; -} - -static Eina_Bool -_e_dbus_vol_mount_timeout(void *data) -{ - E_Volume *v = data; - DBusError error; - char *buf; - int size; - - v->guard = NULL; - dbus_pending_call_cancel(v->op); - error.name = "org.enlightenment.fm2.MountTimeout"; - error.message = "Unable to mount the volume with specified time-out."; - size = _e_dbus_format_error_msg(&buf, v, &error); - ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR, - 0, 0, 0, buf, size); - free(buf); - - return ECORE_CALLBACK_CANCEL; -} - -static void -_e_dbus_cb_vol_mounted(void *user_data, void *method_return __UNUSED__, DBusError *error) -{ - E_Volume *v = user_data; - char *buf; - int size; - - if (v->guard) - { - ecore_timer_del(v->guard); - v->guard = NULL; - } - - if (dbus_error_is_set(error)) - { - size = _e_dbus_format_error_msg(&buf, v, error); - ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR, - 0, 0, 0, buf, size); - dbus_error_free(error); - free(buf); - return; - } - -#if 0 - v->mounted = EINA_TRUE; -// printf("MOUNT: %s from %s\n", v->udi, v->mount_point); - size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1; - buf = alloca(size); - strcpy(buf, v->udi); - strcpy(buf + strlen(buf) + 1, v->mount_point); - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_MOUNT_DONE, - 0, 0, 0, buf, size); -#endif + _E_FM(shutdown)(); } EAPI void e_volume_mount(E_Volume *v) { - char buf[256]; - char buf2[256]; - const char *mount_point; - Eina_List *opt = NULL; - - if (!v || v->guard || !v->mount_point || strncmp(v->mount_point, "/media/", 7)) - return; - - mount_point = v->mount_point + 7; -// printf("mount %s %s [fs type = %s]\n", v->udi, v->mount_point, v->fstype); - - if ((!strcmp(v->fstype, "vfat")) || - (!strcmp(v->fstype, "ntfs")) - ) - { -#if !defined(__FreeBSD__) - snprintf(buf, sizeof(buf), "uid=%i", (int)getuid()); - opt = eina_list_append(opt, buf); -#endif - } - - if ((!strcmp(v->fstype, "vfat")) || - (!strcmp(v->fstype, "ntfs")) || - (!strcmp(v->fstype, "iso9660")) - ) - { - snprintf(buf2, sizeof(buf2), "utf8"); - opt = eina_list_append(opt, buf2); - } - else if ((!strcmp(v->fstype, "fat")) || - (!strcmp(v->fstype, "jfs")) -// (!strcmp(v->fstype, "udf")) - ) - { - snprintf(buf2, sizeof(buf2), "iocharset=utf8"); - opt = eina_list_append(opt, buf2); - } - - v->guard = ecore_timer_add(E_FM_MOUNT_TIMEOUT, _e_dbus_vol_mount_timeout, v); - v->op = e_hal_device_volume_mount(_e_dbus_conn, v->udi, mount_point, - v->fstype, opt, _e_dbus_cb_vol_mounted, v); - eina_list_free(opt); + _E_FM(volume_mount)(v); } -static Eina_Bool -_e_dbus_vol_unmount_timeout(void *data) -{ - E_Volume *v = data; - DBusError error; - char *buf; - int size; - - v->guard = NULL; - dbus_pending_call_cancel(v->op); - error.name = "org.enlightenment.fm2.UnmountTimeout"; - error.message = "Unable to unmount the volume with specified time-out."; - size = _e_dbus_format_error_msg(&buf, v, &error); - ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR, - 0, 0, 0, buf, size); - free(buf); - - return ECORE_CALLBACK_CANCEL; -} - -static void -_e_dbus_cb_vol_unmounted(void *user_data, void *method_return __UNUSED__, DBusError *error) -{ - E_Volume *v = user_data; - char *buf; - int size; - - if (v->guard) - { - ecore_timer_del(v->guard); - v->guard = NULL; - } - - if (dbus_error_is_set(error)) - { - size = _e_dbus_format_error_msg(&buf, v, error); - ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR, - 0, 0, 0, buf, size); - dbus_error_free(error); - free(buf); - return; - } - -#if 0 - v->mounted = EINA_FALSE; -// printf("UNMOUNT: %s from %s\n", v->udi, v->mount_point); - size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1; - buf = alloca(size); - strcpy(buf, v->udi); - strcpy(buf + strlen(buf) + 1, v->mount_point); - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_UNMOUNT_DONE, - 0, 0, 0, buf, size); -#endif -} EAPI void e_volume_unmount(E_Volume *v) { -// printf("unmount %s %s\n", v->udi, v->mount_point); - if (!v || v->guard) return; - - v->guard = ecore_timer_add(E_FM_UNMOUNT_TIMEOUT, _e_dbus_vol_unmount_timeout, v); - v->op = e_hal_device_volume_unmount(_e_dbus_conn, v->udi, NULL, - _e_dbus_cb_vol_unmounted, v); -} - -static Eina_Bool -_e_dbus_vol_eject_timeout(void *data) -{ - E_Volume *v = data; - DBusError error; - char *buf; - int size; - - v->guard = NULL; - dbus_pending_call_cancel(v->op); - error.name = "org.enlightenment.fm2.EjectTimeout"; - error.message = "Unable to eject the media with specified time-out."; - size = _e_dbus_format_error_msg(&buf, v, &error); - ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_EJECT_ERROR, - 0, 0, 0, buf, size); - free(buf); - - return ECORE_CALLBACK_CANCEL; -} - -static Eina_Bool -_e_dbus_vb_vol_ejecting_after_unmount(void *data) -{ - E_Volume *v = data; - - v->guard = ecore_timer_add(E_FM_EJECT_TIMEOUT, _e_dbus_vol_eject_timeout, v); - v->op = e_hal_device_volume_eject(_e_dbus_conn, v->udi, NULL, - _e_dbus_cb_vol_ejected, v); - - return ECORE_CALLBACK_CANCEL; -} - -static void -_e_dbus_cb_vol_unmounted_before_eject(void *user_data, void *method_return, DBusError *error) -{ - E_Volume *v = user_data; - char err; - - err = dbus_error_is_set(error) ? 1 : 0; - _e_dbus_cb_vol_unmounted(user_data, method_return, error); - - // delay is required for all message handlers were executed after unmount - if (!err) - ecore_timer_add(1.0, _e_dbus_vb_vol_ejecting_after_unmount, v); -} - -static void -_e_dbus_cb_vol_ejected(void *user_data, void *method_return __UNUSED__, DBusError *error) -{ - E_Volume *v = user_data; - char *buf; - int size; - - if (v->guard) - { - ecore_timer_del(v->guard); - v->guard = NULL; - } - - if (dbus_error_is_set(error)) - { - size = _e_dbus_format_error_msg(&buf, v, error); - ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_EJECT_ERROR, - 0, 0, 0, buf, size); - dbus_error_free(error); - free(buf); - return; - } - - size = strlen(v->udi) + 1; - buf = alloca(size); - strcpy(buf, v->udi); - ecore_ipc_server_send(_e_fm_ipc_server, - 6/*E_IPC_DOMAIN_FM*/, - E_FM_OP_EJECT_DONE, - 0, 0, 0, buf, size); + _E_FM(volume_unmount)(v); } EAPI void e_volume_eject(E_Volume *v) { - if (!v || v->guard) return; - - if (v->mounted) - { - v->guard = ecore_timer_add(E_FM_UNMOUNT_TIMEOUT, _e_dbus_vol_unmount_timeout, v); - v->op = e_hal_device_volume_unmount(_e_dbus_conn, v->udi, NULL, - _e_dbus_cb_vol_unmounted_before_eject, v); - } - else - { - v->guard = ecore_timer_add(E_FM_EJECT_TIMEOUT, _e_dbus_vol_eject_timeout, v); - v->op = e_hal_device_volume_eject(_e_dbus_conn, v->udi, NULL, - _e_dbus_cb_vol_ejected, v); - } + _E_FM(volume_eject)(v); +} + +EAPI E_Volume * +e_volume_find(const char *udi) +{ + return _E_FM(volume_find)(udi); +} + +EAPI void +e_storage_del(const char *udi) +{ + _E_FM(storage_del)(udi); +} + +EAPI E_Storage * +e_storage_find(const char *udi) +{ + return _E_FM(storage_find)(udi); +} + +void +_e_storage_free(E_Storage *s) +{ + _E_FM_SHARED(storage_free)(s); +} + +void +_e_volume_free(E_Volume *v) +{ + _E_FM_SHARED(volume_free)(v); } 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 000000000..102257652 --- /dev/null +++ b/src/bin/e_fm/e_fm_main.h @@ -0,0 +1,10 @@ +#ifndef E_FM_MAIN_H +#define E_FM_MAIN_H + +extern Ecore_Ipc_Server *_e_fm_ipc_server; + +#define E_FM_MOUNT_TIMEOUT 30.0 +#define E_FM_UNMOUNT_TIMEOUT 60.0 +#define E_FM_EJECT_TIMEOUT 15.0 + +#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 000000000..5438933cc --- /dev/null +++ b/src/bin/e_fm/e_fm_main_dbus.c @@ -0,0 +1,1002 @@ +#include "config.h" + +#ifdef HAVE_ALLOCA_H +# include +#elif defined __GNUC__ +# define alloca __builtin_alloca +#elif defined _AIX +# define alloca __alloca +#elif defined _MSC_VER +# include +# define alloca _alloca +#else +# include +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); +#endif + +#ifdef __linux__ +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "e_fm_main.h" +#include "e_fm_main_dbus.h" + +#include "e_fm_shared_codec.h" +#include "e_fm_shared_dbus.h" +#include "e_fm_ipc.h" +#include "e_fm_dbus.h" + +static E_DBus_Signal_Handler *_hal_poll = NULL; +static E_DBus_Connection *_e_fm_main_dbus_conn = NULL; + +static void _e_fm_main_dbus_cb_dev_all(void *user_data, void *reply_data, DBusError *error); +static void _e_fm_main_dbus_cb_dev_store(void *user_data, void *reply_data, DBusError *error); +static void _e_fm_main_dbus_cb_dev_vol(void *user_data, void *reply_data, DBusError *error); +static void _e_fm_main_dbus_cb_store_is(void *user_data, void *reply_data, DBusError *error); +static void _e_fm_main_dbus_cb_vol_is(void *user_data, void *reply_data, DBusError *error); +static void _e_fm_main_dbus_cb_dev_add(void *data, DBusMessage *msg); +static void _e_fm_main_dbus_cb_dev_del(void *data, DBusMessage *msg); +static void _e_fm_main_dbus_cb_cap_add(void *data, DBusMessage *msg); +static void _e_fm_main_dbus_cb_prop_modified(void *data, DBusMessage *msg); +static void _e_fm_main_dbus_cb_store_prop(void *data, void *reply_data, DBusError *error); +static void _e_fm_main_dbus_cb_vol_prop(void *data, void *reply_data, DBusError *error); +static void _e_fm_main_dbus_cb_vol_prop_mount_modified(void *data, void *reply_data, DBusError *error); +static void _e_fm_main_dbus_cb_vol_mounted(void *user_data, void *method_return, DBusError *error); +static void _e_fm_main_dbus_cb_vol_unmounted(void *user_data, void *method_return, DBusError *error); +static void _e_fm_main_dbus_cb_vol_unmounted_before_eject(void *user_data, void *method_return, DBusError *error); + +static Eina_Bool _e_fm_main_dbus_vb_vol_ejecting_after_unmount(void *data); +static void _e_fm_main_dbus_cb_vol_ejected(void *user_data, void *method_return, DBusError *error); +static int _e_fm_main_dbus_format_error_msg(char **buf, E_Volume *v, DBusError *error); +static void _e_fm_main_dbus_hal_test(void *data, DBusMessage *msg, DBusError *error); +static void _e_fm_main_dbus_hal_poll(void *data, DBusMessage *msg); + +static Eina_Bool _e_fm_main_dbus_vol_mount_timeout(void *data); +static Eina_Bool _e_fm_main_dbus_vol_unmount_timeout(void *data); +static Eina_Bool _e_fm_main_dbus_vol_eject_timeout(void *data); + +static void +_e_fm_main_dbus_hal_poll(void *data __UNUSED__, DBusMessage *msg) +{ + DBusError err; + const char *name, *from, *to; + + dbus_error_init(&err); + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &from, + DBUS_TYPE_STRING, &to, + DBUS_TYPE_INVALID)) + dbus_error_free(&err); + + printf("name: %s\nfrom: %s\nto: %s\n", name, from, to); + if ((name) && !strcmp(name, E_HAL_SENDER)) + _e_fm_main_dbus_hal_test(NULL, NULL, NULL); +} + +static void +_e_fm_main_dbus_hal_test(void *data __UNUSED__, DBusMessage *msg __UNUSED__, DBusError *error) +{ + if ((error) && (dbus_error_is_set(error))) + { + dbus_error_free(error); + if (!_hal_poll) + _hal_poll = + e_dbus_signal_handler_add(_e_fm_main_dbus_conn, + E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, + E_DBUS_FDO_INTERFACE, + "NameOwnerChanged", _e_fm_main_dbus_hal_poll, NULL); + return; + } + if (_hal_poll) + e_dbus_signal_handler_del(_e_fm_main_dbus_conn, _hal_poll); + + e_hal_manager_get_all_devices(_e_fm_main_dbus_conn, _e_fm_main_dbus_cb_dev_all, NULL); + e_hal_manager_find_device_by_capability(_e_fm_main_dbus_conn, "storage", + _e_fm_main_dbus_cb_dev_store, NULL); + e_hal_manager_find_device_by_capability(_e_fm_main_dbus_conn, "volume", + _e_fm_main_dbus_cb_dev_vol, NULL); + + e_dbus_signal_handler_add(_e_fm_main_dbus_conn, E_HAL_SENDER, + E_HAL_MANAGER_PATH, + E_HAL_MANAGER_INTERFACE, + "DeviceAdded", _e_fm_main_dbus_cb_dev_add, NULL); + e_dbus_signal_handler_add(_e_fm_main_dbus_conn, E_HAL_SENDER, + E_HAL_MANAGER_PATH, + E_HAL_MANAGER_INTERFACE, + "DeviceRemoved", _e_fm_main_dbus_cb_dev_del, NULL); + e_dbus_signal_handler_add(_e_fm_main_dbus_conn, E_HAL_SENDER, + E_HAL_MANAGER_PATH, + E_HAL_MANAGER_INTERFACE, + "NewCapability", _e_fm_main_dbus_cb_cap_add, NULL); +} + +static void +_e_fm_main_dbus_cb_dev_all(void *user_data __UNUSED__, void *reply_data, DBusError *error) +{ + E_Hal_Manager_Get_All_Devices_Return *ret = reply_data; + Eina_List *l; + char *udi; + + if (!ret || !ret->strings) return; + + if (dbus_error_is_set(error)) + { + dbus_error_free(error); + return; + } + + EINA_LIST_FOREACH(ret->strings, l, udi) + { +// printf("DB INIT DEV+: %s\n", udi); + e_hal_device_query_capability(_e_fm_main_dbus_conn, udi, "storage", + _e_fm_main_dbus_cb_store_is, (void*)eina_stringshare_add(udi)); + e_hal_device_query_capability(_e_fm_main_dbus_conn, udi, "volume", + _e_fm_main_dbus_cb_vol_is, (void*)eina_stringshare_add(udi)); + } +} + +static void +_e_fm_main_dbus_cb_dev_store(void *user_data __UNUSED__, void *reply_data, DBusError *error) +{ + E_Hal_Manager_Find_Device_By_Capability_Return *ret = reply_data; + Eina_List *l; + char *device; + + if (!ret || !ret->strings) return; + + if (dbus_error_is_set(error)) + { + dbus_error_free(error); + return; + } + + EINA_LIST_FOREACH(ret->strings, l, device) + { +// printf("DB STORE+: %s\n", device); + _e_fm_main_dbus_storage_add(device); + } +} + +static void +_e_fm_main_dbus_cb_dev_vol(void *user_data __UNUSED__, void *reply_data, DBusError *error) +{ + E_Hal_Manager_Find_Device_By_Capability_Return *ret = reply_data; + Eina_List *l; + char *device; + + if (!ret || !ret->strings) return; + + if (dbus_error_is_set(error)) + { + dbus_error_free(error); + return; + } + + EINA_LIST_FOREACH(ret->strings, l, device) + { +// printf("DB VOL+: %s\n", device); + _e_fm_main_dbus_volume_add(device, 1); + } +} + +static void +_e_fm_main_dbus_cb_store_is(void *user_data, void *reply_data, DBusError *error) +{ + char *udi = user_data; + E_Hal_Device_Query_Capability_Return *ret = reply_data; + + if (dbus_error_is_set(error)) + { + dbus_error_free(error); + goto error; + } + + if (ret && ret->boolean) + { +// printf("DB STORE IS+: %s\n", udi); + _e_fm_main_dbus_storage_add(udi); + } + + error: + eina_stringshare_del(udi); +} + +static void +_e_fm_main_dbus_cb_vol_is(void *user_data, void *reply_data, DBusError *error) +{ + char *udi = user_data; + E_Hal_Device_Query_Capability_Return *ret = reply_data; + + if (dbus_error_is_set(error)) + { + dbus_error_free(error); + goto error; + } + + if (ret && ret->boolean) + { +// printf("DB VOL IS+: %s\n", udi); + _e_fm_main_dbus_volume_add(udi, 0); + } + + error: + eina_stringshare_del(udi); +} + +static void +_e_fm_main_dbus_cb_dev_add(void *data __UNUSED__, DBusMessage *msg) +{ + DBusError err; + char *udi = NULL; + + dbus_error_init(&err); + dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID); + if (!udi) return; + e_hal_device_query_capability(_e_fm_main_dbus_conn, udi, "storage", + _e_fm_main_dbus_cb_store_is, (void*)eina_stringshare_add(udi)); + e_hal_device_query_capability(_e_fm_main_dbus_conn, udi, "volume", + _e_fm_main_dbus_cb_vol_is, (void*)eina_stringshare_add(udi)); +} + +static void +_e_fm_main_dbus_cb_dev_del(void *data __UNUSED__, DBusMessage *msg) +{ + DBusError err; + char *udi; + + dbus_error_init(&err); + + dbus_message_get_args(msg, + &err, DBUS_TYPE_STRING, + &udi, DBUS_TYPE_INVALID); +// printf("DB DEV-: %s\n", udi); + _e_fm_main_dbus_storage_del(udi); + _e_fm_main_dbus_volume_del(udi); +} + +static void +_e_fm_main_dbus_cb_cap_add(void *data __UNUSED__, DBusMessage *msg) +{ + DBusError err; + char *udi, *capability; + + dbus_error_init(&err); + + dbus_message_get_args(msg, + &err, DBUS_TYPE_STRING, + &udi, DBUS_TYPE_STRING, + &capability, DBUS_TYPE_INVALID); + if (!strcmp(capability, "storage")) + { +// printf("DB STORE CAP+: %s\n", udi); + _e_fm_main_dbus_storage_add(udi); + } +} + +static void +_e_fm_main_dbus_cb_prop_modified(void *data, DBusMessage *msg) +{ + E_Volume *v; + DBusMessageIter iter, sub, subsub; + struct { + const char *name; + int added; + int removed; + } prop; + int num_changes = 0, i; + + if (!(v = data)) return; + + if (dbus_message_get_error_name(msg)) + { + printf("DBUS ERROR: %s\n", dbus_message_get_error_name(msg)); + return; + } + if (!dbus_message_iter_init(msg, &iter)) return; + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) return; + dbus_message_iter_get_basic(&iter, &num_changes); + if (num_changes == 0) return; + + dbus_message_iter_next(&iter); + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) return; + dbus_message_iter_recurse(&iter, &sub); + + for (i = 0; i < num_changes; i++, dbus_message_iter_next(&sub)) + { + dbus_message_iter_recurse(&sub, &subsub); + + if (dbus_message_iter_get_arg_type(&subsub) != DBUS_TYPE_STRING) break; + dbus_message_iter_get_basic(&subsub, &(prop.name)); + if (!strcmp(prop.name, "volume.mount_point")) + { + e_hal_device_get_all_properties(_e_fm_main_dbus_conn, v->udi, + _e_fm_main_dbus_cb_vol_prop_mount_modified, + v); + return; + } + + dbus_message_iter_next(&subsub); + dbus_message_iter_next(&subsub); + } +} + +static void +_e_fm_main_dbus_cb_store_prop(void *data, void *reply_data, DBusError *error) +{ + E_Storage *s = data; + E_Hal_Properties *ret = reply_data; + int err = 0; + + if (!ret) goto error; + + if (dbus_error_is_set(error)) + { + dbus_error_free(error); + goto error; + } + + s->bus = e_hal_property_string_get(ret, "storage.bus", &err); + if (err) goto error; + s->bus = eina_stringshare_add(s->bus); + s->drive_type = e_hal_property_string_get(ret, "storage.drive_type", &err); + if (err) goto error; + s->drive_type = eina_stringshare_add(s->drive_type); + s->model = e_hal_property_string_get(ret, "storage.model", &err); + if (err) goto error; + s->model = eina_stringshare_add(s->model); + s->vendor = e_hal_property_string_get(ret, "storage.vendor", &err); + if (err) goto error; + s->vendor = eina_stringshare_add(s->vendor); + s->serial = e_hal_property_string_get(ret, "storage.serial", &err); +// if (err) goto error; + if (err) printf("Error getting serial for %s\n", s->udi); + s->serial = eina_stringshare_add(s->serial); + + s->removable = e_hal_property_bool_get(ret, "storage.removable", &err); + + if (s->removable) + { + s->media_available = e_hal_property_bool_get(ret, "storage.removable.media_available", &err); + s->media_size = e_hal_property_uint64_get(ret, "storage.removable.media_size", &err); + } + + s->requires_eject = e_hal_property_bool_get(ret, "storage.requires_eject", &err); + s->hotpluggable = e_hal_property_bool_get(ret, "storage.hotpluggable", &err); + s->media_check_enabled = e_hal_property_bool_get(ret, "storage.media_check_enabled", &err); + + s->icon.drive = e_hal_property_string_get(ret, "storage.icon.drive", &err); + s->icon.drive = eina_stringshare_add(s->icon.drive); + s->icon.volume = e_hal_property_string_get(ret, "storage.icon.volume", &err); + s->icon.volume = eina_stringshare_add(s->icon.volume); + +// 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); + s->validated = EINA_TRUE; + { + void *msg_data; + int msg_size; + + msg_data = _e_fm_shared_codec_storage_encode(s, &msg_size); + if (msg_data) + { + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_STORAGE_ADD, + 0, 0, 0, msg_data, msg_size); + free(msg_data); + } + } + return; + + error: +// printf("ERR %s\n", s->udi); + _e_fm_main_dbus_storage_del(s->udi); +} + +static void +_e_fm_main_dbus_cb_vol_prop(void *data, void *reply_data, DBusError *error) +{ + E_Volume *v = data; + E_Storage *s = NULL; + E_Hal_Device_Get_All_Properties_Return *ret = reply_data; + int err = 0; + const char *str = NULL; + + if (!ret) goto error; + if (dbus_error_is_set(error)) + { + dbus_error_free(error); + goto error; + } + + /* skip volumes with volume.ignore set */ + if (e_hal_property_bool_get(ret, "volume.ignore", &err) || err) + goto error; + + /* skip volumes that aren't filesystems */ + str = e_hal_property_string_get(ret, "volume.fsusage", &err); + if (err || !str) goto error; + if (strcmp(str, "filesystem")) goto error; + str = NULL; + + v->uuid = e_hal_property_string_get(ret, "volume.uuid", &err); + if (err) goto error; + v->uuid = eina_stringshare_add(v->uuid); + + v->label = e_hal_property_string_get(ret, "volume.label", &err); +// if (err) goto error; + v->label = eina_stringshare_add(v->label); + + v->fstype = e_hal_property_string_get(ret, "volume.fstype", &err); +// if (err) goto error; + v->fstype = eina_stringshare_add(v->fstype); + + v->size = e_hal_property_uint64_get(ret, "volume.size", &err); + + v->mounted = e_hal_property_bool_get(ret, "volume.is_mounted", &err); + if (err) goto error; + + v->partition = e_hal_property_bool_get(ret, "volume.is_partition", &err); + if (err) goto error; + + v->mount_point = e_hal_property_string_get(ret, "volume.mount_point", &err); + if (err) goto error; + v->mount_point = eina_stringshare_add(v->mount_point); + + if (v->partition) + { + v->partition_number = e_hal_property_int_get(ret, "volume.partition.number", NULL); + v->partition_label = e_hal_property_string_get(ret, "volume.partition.label", NULL); + v->partition_label = eina_stringshare_add(v->partition_label); + } + + v->parent = e_hal_property_string_get(ret, "info.parent", &err); + if ((!err) && (v->parent)) + { + s = e_storage_find(v->parent); + if (s) + { + v->storage = s; + s->volumes = eina_list_append(s->volumes, v); + } + } + v->parent = eina_stringshare_add(v->parent); + +// 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); +// if (s) printf(" for storage: %s\n", s->udi); +// else printf(" storage unknown\n"); + v->validated = EINA_TRUE; + { + void *msg_data; + int msg_size; + + msg_data = _e_fm_shared_codec_volume_encode(v, &msg_size); + if (msg_data) + { + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_VOLUME_ADD, + 0, 0, 0, msg_data, msg_size); + free(msg_data); + } + } + return; + + error: + _e_fm_main_dbus_volume_del(v->udi); + return; +} + +static int +_e_fm_main_dbus_format_error_msg(char **buf, E_Volume *v, DBusError *error) +{ + int size, vu, vm, en; + char *tmp; + + vu = strlen(v->udi) + 1; + vm = strlen(v->mount_point) + 1; + en = strlen(error->name) + 1; + size = vu + vm + en + strlen(error->message) + 1; + tmp = *buf = malloc(size); + + strcpy(tmp, v->udi); + tmp += vu; + strcpy(tmp, v->mount_point); + tmp += vm; + strcpy(tmp, error->name); + tmp += en; + strcpy(tmp, error->message); + + return size; +} + +static void +_e_fm_main_dbus_cb_vol_prop_mount_modified(void *data, void *reply_data, DBusError *error) +{ + E_Volume *v = data; + E_Hal_Device_Get_All_Properties_Return *ret = reply_data; + int err = 0; + + if (!ret) return; + if (dbus_error_is_set(error)) + { + char *buf; + int size; + + size = _e_fm_main_dbus_format_error_msg(&buf, v, error); + if (v->mounted) + ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR, + 0, 0, 0, buf, size); + else + ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR, + 0, 0, 0, buf, size); + dbus_error_free(error); + free(buf); + return; + } + + v->mounted = e_hal_property_bool_get(ret, "volume.is_mounted", &err); + if (err) printf("HAL Error : can't get volume.is_mounted property"); + + if (v->mount_point) eina_stringshare_del(v->mount_point); + v->mount_point = e_hal_property_string_get(ret, "volume.mount_point", &err); + if (err) printf("HAL Error : can't get volume.is_mount_point property"); + v->mount_point = eina_stringshare_add(v->mount_point); + +// printf("**VOL udi: %s mount_point: %s mounted: %d\n", v->udi, v->mount_point, v->mounted); + { + char *buf; + int size; + + size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1; + buf = alloca(size); + strcpy(buf, v->udi); + strcpy(buf + strlen(buf) + 1, v->mount_point); + if (v->mounted) + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_MOUNT_DONE, + 0, 0, 0, buf, size); + else + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_UNMOUNT_DONE, + 0, 0, 0, buf, size); + } + return; +} + +static Eina_Bool +_e_fm_main_dbus_vol_mount_timeout(void *data) +{ + E_Volume *v = data; + DBusError error; + char *buf; + int size; + + v->guard = NULL; + dbus_pending_call_cancel(v->op); + error.name = "org.enlightenment.fm2.MountTimeout"; + error.message = "Unable to mount the volume with specified time-out."; + size = _e_fm_main_dbus_format_error_msg(&buf, v, &error); + ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR, + 0, 0, 0, buf, size); + free(buf); + + return ECORE_CALLBACK_CANCEL; +} + +static void +_e_fm_main_dbus_cb_vol_mounted(void *user_data, void *method_return __UNUSED__, DBusError *error) +{ + E_Volume *v = user_data; + char *buf; + int size; + + if (v->guard) + { + ecore_timer_del(v->guard); + v->guard = NULL; + } + + if (dbus_error_is_set(error)) + { + size = _e_fm_main_dbus_format_error_msg(&buf, v, error); + ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_MOUNT_ERROR, + 0, 0, 0, buf, size); + dbus_error_free(error); + free(buf); + return; + } + +#if 0 + v->mounted = EINA_TRUE; +// printf("MOUNT: %s from %s\n", v->udi, v->mount_point); + size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1; + buf = alloca(size); + strcpy(buf, v->udi); + strcpy(buf + strlen(buf) + 1, v->mount_point); + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_MOUNT_DONE, + 0, 0, 0, buf, size); +#endif +} + + +static Eina_Bool +_e_fm_main_dbus_vol_unmount_timeout(void *data) +{ + E_Volume *v = data; + DBusError error; + char *buf; + int size; + + v->guard = NULL; + dbus_pending_call_cancel(v->op); + error.name = "org.enlightenment.fm2.UnmountTimeout"; + error.message = "Unable to unmount the volume with specified time-out."; + size = _e_fm_main_dbus_format_error_msg(&buf, v, &error); + ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR, + 0, 0, 0, buf, size); + free(buf); + + return ECORE_CALLBACK_CANCEL; +} + +static void +_e_fm_main_dbus_cb_vol_unmounted(void *user_data, void *method_return __UNUSED__, DBusError *error) +{ + E_Volume *v = user_data; + char *buf; + int size; + + if (v->guard) + { + ecore_timer_del(v->guard); + v->guard = NULL; + } + + if (dbus_error_is_set(error)) + { + size = _e_fm_main_dbus_format_error_msg(&buf, v, error); + ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_UNMOUNT_ERROR, + 0, 0, 0, buf, size); + dbus_error_free(error); + free(buf); + return; + } + +#if 0 + v->mounted = EINA_FALSE; +// printf("UNMOUNT: %s from %s\n", v->udi, v->mount_point); + size = strlen(v->udi) + 1 + strlen(v->mount_point) + 1; + buf = alloca(size); + strcpy(buf, v->udi); + strcpy(buf + strlen(buf) + 1, v->mount_point); + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_UNMOUNT_DONE, + 0, 0, 0, buf, size); +#endif +} + + +static Eina_Bool +_e_fm_main_dbus_vol_eject_timeout(void *data) +{ + E_Volume *v = data; + DBusError error; + char *buf; + int size; + + v->guard = NULL; + dbus_pending_call_cancel(v->op); + error.name = "org.enlightenment.fm2.EjectTimeout"; + error.message = "Unable to eject the media with specified time-out."; + size = _e_fm_main_dbus_format_error_msg(&buf, v, &error); + ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_EJECT_ERROR, + 0, 0, 0, buf, size); + free(buf); + + return ECORE_CALLBACK_CANCEL; +} + +static Eina_Bool +_e_fm_main_dbus_vb_vol_ejecting_after_unmount(void *data) +{ + E_Volume *v = data; + + v->guard = ecore_timer_add(E_FM_EJECT_TIMEOUT, _e_fm_main_dbus_vol_eject_timeout, v); + v->op = e_hal_device_volume_eject(_e_fm_main_dbus_conn, v->udi, NULL, + _e_fm_main_dbus_cb_vol_ejected, v); + + return ECORE_CALLBACK_CANCEL; +} + +static void +_e_fm_main_dbus_cb_vol_unmounted_before_eject(void *user_data, void *method_return, DBusError *error) +{ + E_Volume *v = user_data; + char err; + + err = dbus_error_is_set(error) ? 1 : 0; + _e_fm_main_dbus_cb_vol_unmounted(user_data, method_return, error); + + // delay is required for all message handlers were executed after unmount + if (!err) + ecore_timer_add(1.0, _e_fm_main_dbus_vb_vol_ejecting_after_unmount, v); +} + +static void +_e_fm_main_dbus_cb_vol_ejected(void *user_data, void *method_return __UNUSED__, DBusError *error) +{ + E_Volume *v = user_data; + char *buf; + int size; + + if (v->guard) + { + ecore_timer_del(v->guard); + v->guard = NULL; + } + + if (dbus_error_is_set(error)) + { + size = _e_fm_main_dbus_format_error_msg(&buf, v, error); + ecore_ipc_server_send(_e_fm_ipc_server, 6/*E_IPC_DOMAIN_FM*/, E_FM_OP_EJECT_ERROR, + 0, 0, 0, buf, size); + dbus_error_free(error); + free(buf); + return; + } + + size = strlen(v->udi) + 1; + buf = alloca(size); + strcpy(buf, v->udi); + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_EJECT_DONE, + 0, 0, 0, buf, size); +} + +static Eina_List *_e_vols = NULL; + +E_Volume * +_e_fm_main_dbus_volume_add(const char *udi, Eina_Bool first_time) +{ + E_Volume *v; + + if (!udi) return NULL; + if (e_volume_find(udi)) return NULL; + v = calloc(1, sizeof(E_Volume)); + if (!v) return NULL; +// printf("VOL+ %s\n", udi); + v->udi = eina_stringshare_add(udi); + v->icon = NULL; + v->first_time = first_time; + _e_vols = eina_list_append(_e_vols, v); + e_hal_device_get_all_properties(_e_fm_main_dbus_conn, v->udi, + _e_fm_main_dbus_cb_vol_prop, v); + v->prop_handler = e_dbus_signal_handler_add(_e_fm_main_dbus_conn, + E_HAL_SENDER, + udi, + E_HAL_DEVICE_INTERFACE, + "PropertyModified", + _e_fm_main_dbus_cb_prop_modified, v); + v->guard = NULL; + + return v; +} + +void +_e_fm_main_dbus_volume_del(const char *udi) +{ + E_Volume *v; + + v = e_volume_find(udi); + if (!v) return; + if (v->guard) + { + ecore_timer_del(v->guard); + v->guard = NULL; + } + if (v->prop_handler) e_dbus_signal_handler_del(_e_fm_main_dbus_conn, v->prop_handler); + if (v->validated) + { + // printf("--VOL %s\n", v->udi); + /* FIXME: send event of storage volume (disk) removed */ + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_VOLUME_DEL, + 0, 0, 0, v->udi, eina_stringshare_strlen(v->udi) + 1); + } + _e_vols = eina_list_remove(_e_vols, v); + _e_fm_shared_dbus_volume_free(v); +} + +E_Volume * +_e_fm_main_dbus_volume_find(const char *udi) +{ + Eina_List *l; + E_Volume *v; + + EINA_LIST_FOREACH(_e_vols, l, v) + { + if (udi == v->udi) return v; + } + return NULL; +} + +void +_e_fm_main_dbus_volume_eject(E_Volume *v) +{ + if (!v || v->guard) return; + if (v->mounted) + { + v->guard = ecore_timer_add(E_FM_UNMOUNT_TIMEOUT, _e_fm_main_dbus_vol_unmount_timeout, v); + v->op = e_hal_device_volume_unmount(_e_fm_main_dbus_conn, v->udi, NULL, + _e_fm_main_dbus_cb_vol_unmounted_before_eject, v); + } + else + { + v->guard = ecore_timer_add(E_FM_EJECT_TIMEOUT, _e_fm_main_dbus_vol_eject_timeout, v); + v->op = e_hal_device_volume_eject(_e_fm_main_dbus_conn, v->udi, NULL, + _e_fm_main_dbus_cb_vol_ejected, v); + } +} + +void +_e_fm_main_dbus_volume_unmount(E_Volume *v) +{ +// printf("unmount %s %s\n", v->udi, v->mount_point); + if (!v || v->guard) return; + + v->guard = ecore_timer_add(E_FM_UNMOUNT_TIMEOUT, _e_fm_main_dbus_vol_unmount_timeout, v); + v->op = e_hal_device_volume_unmount(_e_fm_main_dbus_conn, v->udi, NULL, + _e_fm_main_dbus_cb_vol_unmounted, v); +} + +void +_e_fm_main_dbus_volume_mount(E_Volume *v) +{ + char buf[256]; + char buf2[256]; + const char *mount_point; + Eina_List *opt = NULL; + + if (!v || v->guard || !v->mount_point || strncmp(v->mount_point, "/media/", 7)) + return; + + mount_point = v->mount_point + 7; +// printf("mount %s %s [fs type = %s]\n", v->udi, v->mount_point, v->fstype); + + if ((!strcmp(v->fstype, "vfat")) || + (!strcmp(v->fstype, "ntfs")) + ) + { + snprintf(buf, sizeof(buf), "uid=%i", (int)getuid()); + opt = eina_list_append(opt, buf); + } + + if ((!strcmp(v->fstype, "vfat")) || + (!strcmp(v->fstype, "ntfs")) || + (!strcmp(v->fstype, "iso9660")) + ) + { + snprintf(buf2, sizeof(buf2), "utf8"); + opt = eina_list_append(opt, buf2); + } + else if ((!strcmp(v->fstype, "fat")) || + (!strcmp(v->fstype, "jfs")) +// (!strcmp(v->fstype, "udf")) + ) + { + snprintf(buf2, sizeof(buf2), "iocharset=utf8"); + opt = eina_list_append(opt, buf2); + } + + v->guard = ecore_timer_add(E_FM_MOUNT_TIMEOUT, _e_fm_main_dbus_vol_mount_timeout, v); + v->op = e_hal_device_volume_mount(_e_fm_main_dbus_conn, v->udi, mount_point, + v->fstype, opt, _e_fm_main_dbus_cb_vol_mounted, v); + eina_list_free(opt); +} + +void +_e_fm_main_dbus_init(void) +{ + e_dbus_init(); + e_hal_init(); + _e_fm_main_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM); + /* previously, this assumed that if dbus was running, hal was running. */ + if (_e_fm_main_dbus_conn) + e_dbus_get_name_owner(_e_fm_main_dbus_conn, E_HAL_SENDER, _e_fm_main_dbus_hal_test, NULL); +} + +void +_e_fm_main_dbus_shutdown(void) +{ + if (_e_fm_main_dbus_conn) + e_dbus_connection_close(_e_fm_main_dbus_conn); + e_hal_shutdown(); + e_dbus_shutdown(); +} + +static Eina_List *_e_stores = NULL; + +E_Storage * +_e_fm_main_dbus_storage_add(const char *udi) +{ + E_Storage *s; + + if (!udi) return NULL; + if (e_storage_find(udi)) return NULL; + s = calloc(1, sizeof(E_Storage)); + if (!s) return NULL; + s->udi = eina_stringshare_add(udi); + _e_stores = eina_list_append(_e_stores, s); + e_hal_device_get_all_properties(_e_fm_main_dbus_conn, s->udi, + _e_fm_main_dbus_cb_store_prop, s); + return s; +} + +void +_e_fm_main_dbus_storage_del(const char *udi) +{ + E_Storage *s; + + s = e_storage_find(udi); + if (!s) return; + if (s->validated) + { + // printf("--STO %s\n", s->udi); + ecore_ipc_server_send(_e_fm_ipc_server, + 6/*E_IPC_DOMAIN_FM*/, + E_FM_OP_STORAGE_DEL, + 0, 0, 0, s->udi, strlen(s->udi) + 1); + } + _e_stores = eina_list_remove(_e_stores, s); + _e_fm_shared_dbus_storage_free(s); +} + +E_Storage * +_e_fm_main_dbus_storage_find(const char *udi) +{ + Eina_List *l; + E_Storage *s; + + EINA_LIST_FOREACH(_e_stores, l, s) + { + if (udi == s->udi) return s; + } + return NULL; +} 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 000000000..52a1618f0 --- /dev/null +++ b/src/bin/e_fm/e_fm_main_dbus.h @@ -0,0 +1,25 @@ +#ifndef E_FM_MAIN_DBUS_H +#define E_FM_MAIN_DBUS_H + +#include +#include + +#include "e_fm_shared_types.h" + +E_Volume *_e_fm_main_dbus_volume_add(const char *udi, Eina_Bool first_time); +void _e_fm_main_dbus_volume_del(const char *udi); +E_Volume *_e_fm_main_dbus_volume_find(const char *udi); + +void _e_fm_main_dbus_volume_eject(E_Volume *v); +void _e_fm_main_dbus_volume_unmount(E_Volume *v); +void _e_fm_main_dbus_volume_mount(E_Volume *v); + +E_Storage *_e_fm_main_dbus_storage_add(const char *udi); +void _e_fm_main_dbus_storage_del(const char *udi); +E_Storage *_e_fm_main_dbus_storage_find(const char *udi); + + +void _e_fm_main_dbus_init(void); +void _e_fm_main_dbus_shutdown(void); + +#endif diff --git a/src/bin/e_fm_dbus.c b/src/bin/e_fm_dbus.c index fe7718774..914fdb008 100644 --- a/src/bin/e_fm_dbus.c +++ b/src/bin/e_fm_dbus.c @@ -1,8 +1,6 @@ #include "e_fm_dbus.h" - -#define E_FM_SHARED_CODEC -#include "e_fm_shared.h" -#undef E_FM_SHARED_CODEC +#include "e_fm_shared_codec.h" +#include "e_fm_shared_dbus.h" static void _e_fm2_volume_write(E_Volume *v) EINA_ARG_NONNULL(1); static void _e_fm2_volume_erase(E_Volume *v) EINA_ARG_NONNULL(1); @@ -74,7 +72,7 @@ e_fm2_dbus_storage_del(E_Storage *s) { // printf("STO- %s\n", s->udi); _e_stores = eina_list_remove(_e_stores, s); - _e_storage_free(s); + _e_fm_shared_dbus_storage_free(s); } EAPI E_Storage * @@ -279,7 +277,7 @@ e_fm2_dbus_volume_del(E_Volume *v) _e_fm2_dbus_unmount_ok(m); _e_fm2_dbus_mount_free(m); } - _e_volume_free(v); + _e_fm_shared_dbus_volume_free(v); } static void diff --git a/src/bin/e_fm_shared.h b/src/bin/e_fm_shared.h deleted file mode 100644 index 2617834fa..000000000 --- a/src/bin/e_fm_shared.h +++ /dev/null @@ -1,209 +0,0 @@ -#ifdef E_FM_SHARED_DATATYPES - -# define E_DEVICE_TYPE_STORAGE 1 -# define E_DEVICE_TYPE_VOLUME 2 -typedef struct _E_Storage E_Storage; -typedef struct _E_Volume E_Volume; -typedef struct _E_Fm2_Mount E_Fm2_Mount; - -struct _E_Storage -{ - int type; - const char *udi, *bus; - const char *drive_type; - - const char *model, *vendor, *serial; - - Eina_Bool removable; - Eina_Bool media_available; - unsigned long long media_size; - - Eina_Bool requires_eject; - Eina_Bool hotpluggable; - Eina_Bool media_check_enabled; - - struct - { - const char *drive, *volume; - } icon; - - Eina_List *volumes; - - Eina_Bool validated : 1; - Eina_Bool trackable : 1; -}; - -struct _E_Volume -{ - int type; - const char *udi, *uuid; - const char *label, *icon, *fstype; - unsigned long long size; - - Eina_Bool partition; - int partition_number; - const char *partition_label; - Eina_Bool mounted; - const char *mount_point; - - const char *parent; - E_Storage *storage; - void *prop_handler; - Eina_List *mounts; - - Eina_Bool validated : 1; - - Eina_Bool auto_unmount : 1; // unmount, when last associated fm window closed - Eina_Bool first_time; // volume discovery in init sequence - Ecore_Timer *guard; // operation guard timer - DBusPendingCall *op; // d-bus call handle -}; - -struct _E_Fm2_Mount -{ - const char *udi; - const char *mount_point; - - Ecore_Cb mount_ok; - Ecore_Cb mount_fail; - Ecore_Cb unmount_ok; - Ecore_Cb unmount_fail; - void *data; - - E_Volume *volume; - - Eina_Bool mounted : 1; -}; - -#endif - -#ifdef E_FM_SHARED_CODEC -static Eet_Data_Descriptor *_e_volume_edd = NULL; -static Eet_Data_Descriptor *_e_storage_edd = NULL; - -static void -_e_volume_free(E_Volume *v) -{ - if (v->storage) - { - v->storage->volumes = eina_list_remove(v->storage->volumes, v); - v->storage = NULL; - } - if (v->udi) eina_stringshare_del(v->udi); - if (v->uuid) eina_stringshare_del(v->uuid); - if (v->label) eina_stringshare_del(v->label); - if (v->icon) eina_stringshare_del(v->icon); - if (v->fstype) eina_stringshare_del(v->fstype); - if (v->partition_label) eina_stringshare_del(v->partition_label); - if (v->mount_point) eina_stringshare_del(v->mount_point); - if (v->parent) eina_stringshare_del(v->parent); - free(v); -} - -static void -_e_storage_free(E_Storage *s) -{ - E_Volume *v; - EINA_LIST_FREE(s->volumes, v) - { - v->storage = NULL; - _e_volume_free(v); - } - if (s->udi) eina_stringshare_del(s->udi); - if (s->bus) eina_stringshare_del(s->bus); - if (s->drive_type) eina_stringshare_del(s->drive_type); - if (s->model) eina_stringshare_del(s->model); - if (s->vendor) eina_stringshare_del(s->vendor); - if (s->serial) eina_stringshare_del(s->serial); - if (s->icon.drive) eina_stringshare_del(s->icon.drive); - if (s->icon.volume) eina_stringshare_del(s->icon.volume); - free(s); -} - -static Eet_Data_Descriptor * -_e_volume_edd_new(void) -{ - Eet_Data_Descriptor *edd; - Eet_Data_Descriptor_Class eddc; - - if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc), "e_volume", sizeof(E_Volume))) - return NULL; - -// eddc.func.str_alloc = (char *(*)(const char *)) strdup; -// eddc.func.str_free = (void (*)(const char *)) free; - - edd = eet_data_descriptor_stream_new(&eddc); -#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, E_Volume, #MEMBER, MEMBER, EET_T_##TYPE) - DAT(type, INT); - DAT(udi, STRING); - DAT(uuid, STRING); - DAT(label, STRING); - DAT(fstype, STRING); - DAT(size, ULONG_LONG); - DAT(partition, CHAR); - DAT(partition_number, INT); - DAT(partition_label, STRING); - DAT(mounted, CHAR); - DAT(mount_point, STRING); - DAT(parent, STRING); - DAT(first_time, CHAR); -#undef DAT - return edd; -} - -static Eet_Data_Descriptor * -_e_storage_edd_new(void) -{ - Eet_Data_Descriptor *edd; - Eet_Data_Descriptor_Class eddc; - - if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "e_storage", sizeof (E_Storage))) - return NULL; - -// eddc.func.str_alloc = (char *(*)(const char *)) strdup; -// eddc.func.str_free = (void (*)(const char *)) free; - - edd = eet_data_descriptor_stream_new(&eddc); -#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, E_Storage, #MEMBER, MEMBER, EET_T_##TYPE) - DAT(type, INT); - DAT(udi, STRING); - DAT(bus, STRING); - DAT(drive_type, STRING); - DAT(model, STRING); - DAT(vendor, STRING); - DAT(serial, STRING); - DAT(removable, CHAR); - DAT(media_available, CHAR); - DAT(media_size, ULONG_LONG); - DAT(requires_eject, CHAR); - DAT(hotpluggable, CHAR); - DAT(media_check_enabled, CHAR); - DAT(icon.drive, STRING); - DAT(icon.volume, STRING); -#undef DAT - return edd; -} - -static void -_e_storage_volume_edd_init(void) -{ - _e_volume_edd = _e_volume_edd_new(); - _e_storage_edd = _e_storage_edd_new(); -} - -static void -_e_storage_volume_edd_shutdown(void) -{ - if (_e_volume_edd) - { - eet_data_descriptor_free(_e_volume_edd); - _e_volume_edd = NULL; - } - if (_e_storage_edd) - { - eet_data_descriptor_free(_e_storage_edd); - _e_storage_edd = NULL; - } -} - -#endif diff --git a/src/bin/e_fm_shared_codec.c b/src/bin/e_fm_shared_codec.c new file mode 100644 index 000000000..dd32424da --- /dev/null +++ b/src/bin/e_fm_shared_codec.c @@ -0,0 +1,116 @@ +#include "e_fm_shared_types.h" +#include "e_fm_shared_codec.h" + +static Eet_Data_Descriptor *_e_volume_edd = NULL; +static Eet_Data_Descriptor *_e_storage_edd = NULL; + +Eet_Data_Descriptor * +_e_volume_edd_new(void) +{ + Eet_Data_Descriptor *edd; + Eet_Data_Descriptor_Class eddc; + + if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc), "e_volume", sizeof(E_Volume))) + return NULL; + +// eddc.func.str_alloc = (char *(*)(const char *)) strdup; +// eddc.func.str_free = (void (*)(const char *)) free; + + edd = eet_data_descriptor_stream_new(&eddc); +#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, E_Volume, #MEMBER, MEMBER, EET_T_##TYPE) + DAT(type, INT); + DAT(udi, STRING); + DAT(uuid, STRING); + DAT(label, STRING); + DAT(fstype, STRING); + DAT(size, ULONG_LONG); + DAT(partition, CHAR); + DAT(partition_number, INT); + DAT(partition_label, STRING); + DAT(mounted, CHAR); + DAT(mount_point, STRING); + DAT(parent, STRING); + DAT(first_time, CHAR); +#undef DAT + return edd; +} + +Eet_Data_Descriptor * +_e_storage_edd_new(void) +{ + Eet_Data_Descriptor *edd; + Eet_Data_Descriptor_Class eddc; + + if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "e_storage", sizeof (E_Storage))) + return NULL; + +// eddc.func.str_alloc = (char *(*)(const char *)) strdup; +// eddc.func.str_free = (void (*)(const char *)) free; + + edd = eet_data_descriptor_stream_new(&eddc); +#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, E_Storage, #MEMBER, MEMBER, EET_T_##TYPE) + DAT(type, INT); + DAT(udi, STRING); + DAT(bus, STRING); + DAT(drive_type, STRING); + DAT(model, STRING); + DAT(vendor, STRING); + DAT(serial, STRING); + DAT(removable, CHAR); + DAT(media_available, CHAR); + DAT(media_size, ULONG_LONG); + DAT(requires_eject, CHAR); + DAT(hotpluggable, CHAR); + DAT(media_check_enabled, CHAR); + DAT(icon.drive, STRING); + DAT(icon.volume, STRING); +#undef DAT + return edd; +} + +void * +_e_fm_shared_codec_storage_encode(E_Storage *s, int *size) +{ + return eet_data_descriptor_encode(_e_storage_edd, s, size); +} + +E_Storage * +_e_fm_shared_codec_storage_decode(void *s, int size) +{ + return eet_data_descriptor_decode(_e_storage_edd, s, size); +} + + +void * +_e_fm_shared_codec_volume_encode(E_Volume *v, int *size) +{ + return eet_data_descriptor_encode(_e_volume_edd, v, size); +} + +E_Volume * +_e_fm_shared_codec_volume_decode(void *v, int size) +{ + return eet_data_descriptor_decode(_e_volume_edd, v, size); +} + +void +_e_storage_volume_edd_init(void) +{ + _e_volume_edd = _e_volume_edd_new(); + _e_storage_edd = _e_storage_edd_new(); +} + +void +_e_storage_volume_edd_shutdown(void) +{ + if (_e_volume_edd) + { + eet_data_descriptor_free(_e_volume_edd); + _e_volume_edd = NULL; + } + if (_e_storage_edd) + { + eet_data_descriptor_free(_e_storage_edd); + _e_storage_edd = NULL; + } +} diff --git a/src/bin/e_fm_shared_codec.h b/src/bin/e_fm_shared_codec.h new file mode 100644 index 000000000..79cb4af7d --- /dev/null +++ b/src/bin/e_fm_shared_codec.h @@ -0,0 +1,17 @@ +#ifndef E_FM_SHARED_CODEC +#define E_FM_SHARED_CODEC + +#include + +void *_e_fm_shared_codec_storage_encode(E_Storage *s, int *size); +E_Storage *_e_fm_shared_codec_storage_decode(void *s, int size); +void *_e_fm_shared_codec_volume_encode(E_Volume *v, int *size); +E_Volume *_e_fm_shared_codec_volume_decode(void *v, int size); + +Eet_Data_Descriptor *_e_volume_edd_new(void); +Eet_Data_Descriptor *_e_storage_edd_new(void); +void _e_storage_volume_edd_init(void); +void _e_storage_volume_edd_shutdown(void); + + +#endif diff --git a/src/bin/e_fm_shared_dbus.c b/src/bin/e_fm_shared_dbus.c new file mode 100644 index 000000000..ee0e2ffaf --- /dev/null +++ b/src/bin/e_fm_shared_dbus.c @@ -0,0 +1,42 @@ +#include "e_fm_shared_types.h" +#include "e_fm_shared_dbus.h" + +void +_e_fm_shared_dbus_storage_free(E_Storage *s) +{ + E_Volume *v; + EINA_LIST_FREE(s->volumes, v) + { + v->storage = NULL; + _e_fm_shared_dbus_volume_free(v); + } + if (s->udi) eina_stringshare_del(s->udi); + if (s->bus) eina_stringshare_del(s->bus); + if (s->drive_type) eina_stringshare_del(s->drive_type); + if (s->model) eina_stringshare_del(s->model); + if (s->vendor) eina_stringshare_del(s->vendor); + if (s->serial) eina_stringshare_del(s->serial); + if (s->icon.drive) eina_stringshare_del(s->icon.drive); + if (s->icon.volume) eina_stringshare_del(s->icon.volume); + free(s); +} + + +void +_e_fm_shared_dbus_volume_free(E_Volume *v) +{ + if (v->storage) + { + v->storage->volumes = eina_list_remove(v->storage->volumes, v); + v->storage = NULL; + } + if (v->udi) eina_stringshare_del(v->udi); + if (v->uuid) eina_stringshare_del(v->uuid); + if (v->label) eina_stringshare_del(v->label); + if (v->icon) eina_stringshare_del(v->icon); + if (v->fstype) eina_stringshare_del(v->fstype); + if (v->partition_label) eina_stringshare_del(v->partition_label); + if (v->mount_point) eina_stringshare_del(v->mount_point); + if (v->parent) eina_stringshare_del(v->parent); + free(v); +} diff --git a/src/bin/e_fm_shared_dbus.h b/src/bin/e_fm_shared_dbus.h new file mode 100644 index 000000000..e056bee9f --- /dev/null +++ b/src/bin/e_fm_shared_dbus.h @@ -0,0 +1,9 @@ +#ifndef E_FM_SHARED_DBUS_H +#define E_FM_SHARED_DBUS_H + +#include "e_fm_shared_types.h" + +void _e_fm_shared_dbus_storage_free(E_Storage *s); +void _e_fm_shared_dbus_volume_free(E_Volume *v); + +#endif diff --git a/src/bin/e_fm_shared_types.h b/src/bin/e_fm_shared_types.h new file mode 100644 index 000000000..ee927dc34 --- /dev/null +++ b/src/bin/e_fm_shared_types.h @@ -0,0 +1,85 @@ +#ifndef E_FM_SHARED_TYPES +#define E_FM_SHARED_TYPES + +#include +#include +#include + +# define E_DEVICE_TYPE_STORAGE 1 +# define E_DEVICE_TYPE_VOLUME 2 +typedef struct _E_Storage E_Storage; +typedef struct _E_Volume E_Volume; +typedef struct _E_Fm2_Mount E_Fm2_Mount; + +#ifndef HAVE_EEZE_MOUNT +struct _E_Storage +{ + int type; + const char *udi, *bus; + const char *drive_type; + + const char *model, *vendor, *serial; + + Eina_Bool removable; + Eina_Bool media_available; + unsigned long long media_size; + + Eina_Bool requires_eject; + Eina_Bool hotpluggable; + Eina_Bool media_check_enabled; + + struct + { + const char *drive, *volume; + } icon; + + Eina_List *volumes; + + Eina_Bool validated : 1; + Eina_Bool trackable : 1; +}; + +struct _E_Volume +{ + int type; + const char *udi, *uuid; + const char *label, *icon, *fstype; + unsigned long long size; + + Eina_Bool partition; + int partition_number; + const char *partition_label; + Eina_Bool mounted; + const char *mount_point; + + const char *parent; + E_Storage *storage; + void *prop_handler; + Eina_List *mounts; + + Eina_Bool validated : 1; + + Eina_Bool auto_unmount : 1; // unmount, when last associated fm window closed + Eina_Bool first_time; // volume discovery in init sequence + Ecore_Timer *guard; // operation guard timer + DBusPendingCall *op; // d-bus call handle +}; + +struct _E_Fm2_Mount +{ + const char *udi; + const char *mount_point; + + Ecore_Cb mount_ok; + Ecore_Cb mount_fail; + Ecore_Cb unmount_ok; + Ecore_Cb unmount_fail; + void *data; + + E_Volume *volume; + + Eina_Bool mounted : 1; +}; + +#endif +#endif