From edc330631536a48f48ad95bd3df819d6fcb01eae Mon Sep 17 00:00:00 2001 From: Jaime Thomas Date: Sun, 19 Apr 2009 01:54:14 +0000 Subject: [PATCH] More work with dbus. --- experimental/ecdb/trunk/src/ecdb.h | 3 + experimental/ecdb/trunk/src/ecdb_common.h | 16 +- experimental/ecdb/trunk/src/ecdb_drives.c | 50 +++--- experimental/ecdb/trunk/src/ecdb_hal.c | 194 +++++++++++++++------- 4 files changed, 178 insertions(+), 85 deletions(-) diff --git a/experimental/ecdb/trunk/src/ecdb.h b/experimental/ecdb/trunk/src/ecdb.h index fe5f1716..4a6dd75a 100644 --- a/experimental/ecdb/trunk/src/ecdb.h +++ b/experimental/ecdb/trunk/src/ecdb.h @@ -72,6 +72,9 @@ struct _Ecdb_Main /* E_DBus signal handlers */ E_DBus_Signal_Handler *dev_added; E_DBus_Signal_Handler *dev_removed; + + /* Used to help with initialization */ + unsigned int init_count; }; extern Ecdb_Main *em; diff --git a/experimental/ecdb/trunk/src/ecdb_common.h b/experimental/ecdb/trunk/src/ecdb_common.h index 1f05621c..c2858847 100644 --- a/experimental/ecdb/trunk/src/ecdb_common.h +++ b/experimental/ecdb/trunk/src/ecdb_common.h @@ -24,6 +24,14 @@ typedef struct burn_progress BurnProgress; typedef struct burn_drive_info BurnDriveInfo; typedef enum burn_drive_status BurnDriveStatus; +typedef enum _Ecdb_Disc_Status Ecdb_Disc_Status; +enum _Ecdb_Disc_Status +{ + ECDB_DISC_BLANK = 0x1, + ECDB_DISC_REWRITABLE = 0x2, + ECDB_DISC_APPENDABLE = 0x4 +}; + typedef enum _Ecdb_Project_Type Ecdb_Project_Type; enum _Ecdb_Project_Type { @@ -80,7 +88,13 @@ struct _Ecdb_Drive_Info unsigned char fresh_info:1; /* Capacity */ - long long capacity; + unsigned long long capacity; + + /* Disc status */ + unsigned int status; + + /* Disc type */ + char *type; BurnDriveInfo *tangible; }; diff --git a/experimental/ecdb/trunk/src/ecdb_drives.c b/experimental/ecdb/trunk/src/ecdb_drives.c index 996e3a3a..aa9f4902 100644 --- a/experimental/ecdb/trunk/src/ecdb_drives.c +++ b/experimental/ecdb/trunk/src/ecdb_drives.c @@ -9,30 +9,6 @@ _ecdb_drive_set_capabilities(Ecdb_Drive_Info *drive, char *val; int i; - /* Drive Capabilities */ - drive->write_cdr = e_hal_property_bool_get(ret, "storage.cdrom.cdr", NULL); - drive->write_cdrw = e_hal_property_bool_get(ret, "storage.cdrom.cdrw", NULL); - drive->write_dvdr = e_hal_property_bool_get(ret, "storage.cdrom.dvdr", NULL); - drive->write_dvdrw = e_hal_property_bool_get(ret, - "storage.cdrom.dvdrw", NULL); - drive->write_dvdram = e_hal_property_bool_get(ret, - "storage.cdrom.dvdram", NULL); - drive->write_dvdplusrw = e_hal_property_bool_get(ret, - "storage.cdrom.dvdplusrw", NULL); - drive->write_dvdplusrwdl = e_hal_property_bool_get(ret, - "storage.cdrom.dvdplusrwdl", NULL); - drive->write_dvdplusrdl = e_hal_property_bool_get(ret, - "storage.cdrom.dvdplusrdl", NULL); - drive->write_bdr = e_hal_property_bool_get(ret, "storage.cdrom.bdr", NULL); - drive->write_bdre = e_hal_property_bool_get(ret, "storage.cdrom.bdre", NULL); - drive->write_hddvdr = e_hal_property_bool_get(ret, - "storage.cdrom.hddvdr", NULL); - drive->write_hddvdrw = e_hal_property_bool_get(ret, - "storage.cdrom.hddvdrw", NULL); - drive->support_multisession = e_hal_property_bool_get(ret, - "storage.cdrom.support_multisession", - NULL); - /* Write speeds */ write_speeds = e_hal_property_strlist_get(ret, "storage.cdrom.write_speeds", NULL); @@ -82,7 +58,30 @@ ecdb_aquire_drive_info(E_Hal_Device_Get_All_Properties_Return *ret, drive->location = mnt; drive->udi = udi; - /* Update current directories */ + /* Drive Capabilities */ + drive->write_cdr = e_hal_property_bool_get(ret, "storage.cdrom.cdr", NULL); + drive->write_cdrw = e_hal_property_bool_get(ret, "storage.cdrom.cdrw", NULL); + drive->write_dvdr = e_hal_property_bool_get(ret, "storage.cdrom.dvdr", NULL); + drive->write_dvdrw = e_hal_property_bool_get(ret, + "storage.cdrom.dvdrw", NULL); + drive->write_dvdram = e_hal_property_bool_get(ret, + "storage.cdrom.dvdram", NULL); + drive->write_dvdplusrw = e_hal_property_bool_get(ret, + "storage.cdrom.dvdplusrw", NULL); + drive->write_dvdplusrwdl = e_hal_property_bool_get(ret, + "storage.cdrom.dvdplusrwdl", NULL); + drive->write_dvdplusrdl = e_hal_property_bool_get(ret, + "storage.cdrom.dvdplusrdl", NULL); + drive->write_bdr = e_hal_property_bool_get(ret, "storage.cdrom.bdr", NULL); + drive->write_bdre = e_hal_property_bool_get(ret, "storage.cdrom.bdre", NULL); + drive->write_hddvdr = e_hal_property_bool_get(ret, + "storage.cdrom.hddvdr", NULL); + drive->write_hddvdrw = e_hal_property_bool_get(ret, + "storage.cdrom.hddvdrw", NULL); + drive->support_multisession = e_hal_property_bool_get(ret, + "storage.cdrom.support_multisession", + NULL); + /* Update generic write speeds */ _ecdb_drive_set_capabilities(drive, ret); em->drives = eina_list_append(em->drives, drive); @@ -106,6 +105,7 @@ ecdb_drive_info_list_free(Eina_List *list) FREE(info->revision); FREE(info->location); FREE(info->udi); + FREE(info->type); free(info); } } diff --git a/experimental/ecdb/trunk/src/ecdb_hal.c b/experimental/ecdb/trunk/src/ecdb_hal.c index f07d8aad..aac01411 100644 --- a/experimental/ecdb/trunk/src/ecdb_hal.c +++ b/experimental/ecdb/trunk/src/ecdb_hal.c @@ -2,48 +2,15 @@ #include "ecdb.h" void _ecdb_hal_device_all_cb(void *data, void *reply_data, DBusError *error); +void _ecdb_hal_volume_all_cb(void *data, void *reply_data, DBusError *error); void _ecdb_hal_device_handle(void *data, void *reply_data, DBusError *error); void _ecdb_hal_volume_removed_cb(void *data, DBusMessage *msg); void _ecdb_hal_volume_added_cb(void *data, DBusMessage *msg); +void _ecdb_hal_volume_handle(void *data, void *reply_data, DBusError *error); void _ecdb_hal_volume_cb(void *data, void *reply_data, DBusError *error); void _ecdb_hal_volume_handle(void *data, void *reply_data, DBusError *error); void _ecdb_hal_unmount_cb(void *data, void *reply_data, DBusError *error); - -void -_ecdb_hal_volume_handle(void *data, void *reply_data, DBusError *error) -{ - E_Hal_Device_Get_All_Properties_Return *ret; - char *udi, *str; - int err; - - ret = reply_data; - udi = data; - - if ((!ret) || (!udi)) - { - EINA_ERROR_PWARN("NULL udi or reply!\n"); - return; - } - - if (dbus_error_is_set(error)) - { - /* XXX Handle this error here */ - dbus_error_free(error); - return; - } - - if ((e_hal_property_bool_get(ret, "volume.is_disc", &err)) && (!err)) - { - str = e_hal_property_string_get(ret, "info.parent", &err); - if ((str) && (!err)) - { - e_hal_device_get_all_properties(em->conn, str, _ecdb_hal_device_handle, - str); - } - } - - FREE(udi); -} +void _ecdb_hal_volumes_init(void); void _ecdb_hal_device_handle(void *data, void *reply_data, DBusError *error) @@ -82,7 +49,9 @@ _ecdb_hal_device_handle(void *data, void *reply_data, DBusError *error) if (!strcmp(drive->location, str)) { if (!ecdb_update_drive_info(drive, ret, udi)) + { EINA_ERROR_PWARN("Couldn't update old drive info!\n"); + } printf("Recreating old...\n"); ecdb_print_drive_info(); @@ -102,11 +71,18 @@ _ecdb_hal_device_handle(void *data, void *reply_data, DBusError *error) printf("Creating new...\n"); ecdb_print_drive_info(); + + /* Check to see if we have acquired all of the drives */ + if (eina_list_count(em->drives) >= em->init_count) + { + em->init_count = 0; + _ecdb_hal_volumes_init(); + } } } void -_ecdb_hal_device_removed_cb(void *data __UNUSED__, DBusMessage *msg) +_ecdb_hal_volume_removed_cb(void *data __UNUSED__, DBusMessage *msg) { DBusError err; Eina_List *l; @@ -118,14 +94,19 @@ _ecdb_hal_device_removed_cb(void *data __UNUSED__, DBusMessage *msg) DBUS_TYPE_INVALID); printf("Removed: %s\n", udi); - /* - * 1. Find the drive that has been removed. - * 2. Update it with libburn - */ + EINA_LIST_FOREACH(em->drives, l, drive) + { + if (!strcmp(drive->udi, udi)) + { + drive->fresh_info = FALSE; + drive->status = 0; + FREE(drive->type); + } + } } void -_ecdb_hal_device_added_cb(void *data __UNUSED__, DBusMessage *msg) +_ecdb_hal_volume_added_cb(void *data __UNUSED__, DBusMessage *msg) { DBusError err; char *udi; @@ -161,19 +142,19 @@ _ecdb_hal_volume_cb(void *data, void *reply_data, DBusError *error) if (ret->boolean) { - e_hal_device_get_all_properties(em->conn, udi, _ecdb_hal_device_handle, + e_hal_device_get_all_properties(em->conn, udi, _ecdb_hal_volume_handle, udi); } } void -_ecdb_hal_device_all_cb(void *data, void *reply_data, DBusError *error) +_ecdb_hal_device_all_cb(void *data __UNUSED__, void *reply_data, + DBusError *error) { char *udi; Eina_List *l; E_Hal_Manager_Find_Device_By_Capability_Return *ret; - udi = data; ret = reply_data; if ((!ret) || (!ret->strings)) @@ -186,6 +167,7 @@ _ecdb_hal_device_all_cb(void *data, void *reply_data, DBusError *error) return; } + em->init_count = eina_list_count(ret->strings); EINA_LIST_FOREACH(ret->strings, l, udi) { e_hal_device_get_all_properties(em->conn, udi, _ecdb_hal_device_handle, @@ -203,20 +185,6 @@ ecdb_hal_init(void) return 0; } - em->dev_added = e_dbus_signal_handler_add(em->conn, "org.freedesktop.Hal", - "/org/freedesktop/Hal/Manager", - "org.freedesktop.Hal.Manager", - "DeviceAdded", - _ecdb_hal_device_added_cb, NULL); - - - em->dev_removed = e_dbus_signal_handler_add(em->conn, - "org.freedesktop.Hal", - "/org/freedesktop/Hal/Manager", - "org.freedesktop.Hal.Manager", - "DeviceRemoved", - _ecdb_hal_device_removed_cb, NULL); - e_hal_manager_find_device_by_capability(em->conn, "storage.cdrom", _ecdb_hal_device_all_cb, NULL); @@ -251,3 +219,111 @@ _ecdb_hal_unmount_cb(void *data, void *reply_data __UNUSED__, DBusError *error) dbus_error_free(error); } } + +void +_ecdb_hal_volumes_init() +{ + + em->dev_added = e_dbus_signal_handler_add(em->conn, "org.freedesktop.Hal", + "/org/freedesktop/Hal/Manager", + "org.freedesktop.Hal.Manager", + "DeviceAdded", + _ecdb_hal_volume_added_cb, NULL); + + em->dev_removed = e_dbus_signal_handler_add(em->conn, + "org.freedesktop.Hal", + "/org/freedesktop/Hal/Manager", + "org.freedesktop.Hal.Manager", + "DeviceRemoved", + _ecdb_hal_volume_removed_cb, NULL); + + e_hal_manager_find_device_by_capability(em->conn, "volume.disc", + _ecdb_hal_volume_all_cb, NULL); +} + +void +_ecdb_hal_volume_all_cb(void *data __UNUSED__, void *reply_data, + DBusError *error) +{ + char *udi; + Eina_List *l; + E_Hal_Manager_Find_Device_By_Capability_Return *ret; + + ret = reply_data; + + if ((!ret) || (!ret->strings)) + return; + + if (dbus_error_is_set(error)) + { + /* XXX Handle this here */ + dbus_error_free(error); + return; + } + + EINA_LIST_FOREACH(ret->strings, l, udi) + { + e_hal_device_get_all_properties(em->conn, udi, _ecdb_hal_volume_handle, + NULL); + } +} + +void +_ecdb_hal_volume_handle(void *data, void *reply_data, DBusError *error) +{ + E_Hal_Device_Get_All_Properties_Return *ret; + Ecdb_Drive_Info *drive; + Eina_List *l; + char *udi; + int err; + + ret = reply_data; + + if (!ret) + return; + + if (dbus_error_is_set(error)) + { + /* XXX Handle this better */ + dbus_error_free(error); + return; + } + + /* Ignore volumes that are not discs */ + if ((!e_hal_property_bool_get(ret, "volume.is_disc", &err)) || (err)) + return; + + /* Get the parent udi */ + udi = e_hal_property_string_get(ret, "info.parent", NULL); + + /* Find the drive this volume belongs to */ + EINA_LIST_FOREACH(em->drives, l, drive) + { + if (!strcmp(udi, drive->udi)) + { + drive->capacity = e_hal_property_uint64_get(ret, + "volume.disc.capacity", NULL); + + if (e_hal_property_bool_get(ret, "volume.disc.is_blank", NULL)) + drive->status |= ECDB_DISC_BLANK; + + if (e_hal_property_bool_get(ret, "volume.disc.is_appendable", NULL)) + drive->status |= ECDB_DISC_APPENDABLE; + + if (e_hal_property_bool_get(ret, "volume.disc.is_rewritable", NULL)) + drive->status |= ECDB_DISC_REWRITABLE; + + drive->type = e_hal_property_string_get(ret, "volume.disc.type", NULL); + + /* Also refresh the drive, for write speeds */ + e_hal_device_get_all_properties(em->conn, udi, + _ecdb_hal_device_handle, udi); + + break; + } + } + + FREE(data); + FREE(udi); +} +