From b19a713bdfc3561b304c106e757b2ad82b7189f5 Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Mon, 8 Oct 2012 15:40:25 +0000 Subject: [PATCH] Use str_hash(). Some cleanup. --- emountd/emountd.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/emountd/emountd.cpp b/emountd/emountd.cpp index 0f7e99c..c20353e 100644 --- a/emountd/emountd.cpp +++ b/emountd/emountd.cpp @@ -29,6 +29,7 @@ #include #include #include +#include /* HAL can return NULL as error message if not checked */ #define CHECK_STR(s) ((s != NULL) ? s : "") @@ -39,6 +40,9 @@ #define EDE_SHUTDOWN_INTERFACE "org.equinoxproject.Shutdown" #define EDE_SHUTDOWN_MEMBER "Shutdown" +EDELIB_NS_USING(list) +EDELIB_NS_USING(str_hash) + struct DeviceInfo { unsigned int udi_hash; const char* label; @@ -58,8 +62,8 @@ struct DeviceAudioInfo { const char* device_file; }; -typedef edelib::list UIntList; -typedef edelib::list::iterator UIntListIter; +typedef list UIntList; +typedef list::iterator UIntListIter; static int quit_signaled = 0; static DBusConnection* bus_connection = NULL; @@ -69,24 +73,6 @@ void quit_signal(int sig) { quit_signaled = 1; } -/* A hash function from Dr.Dobbs Journal. */ -unsigned int do_hash(const char* key, int keylen) { - unsigned hash ; - int i; - - for (i = 0, hash = 0; i < keylen ;i++) { - hash += (long)key[i] ; - hash += (hash<<10); - hash ^= (hash>>6) ; - } - - hash += (hash <<3); - hash ^= (hash >>11); - hash += (hash <<15); - - return hash ; -} - void send_dbus_signal_mounted(DeviceInfo* info) { int vi; dbus_bool_t vb; @@ -217,7 +203,7 @@ void device_info_send(LibHalContext* ctx, const char* udi) { if(drive) { const char* label = libhal_device_get_property_string(ctx, udi, "volume.label", 0); const char* dev = libhal_drive_get_device_file(drive); - unsigned int udi_hash = do_hash(udi, strlen(udi)); + unsigned int udi_hash = str_hash(udi); /* for audio CD's we send special signals */ if(libhal_volume_disc_has_audio(vol) && !libhal_volume_disc_has_data(vol)) { @@ -280,7 +266,7 @@ void device_added(LibHalContext* ctx, const char* udi) { } void device_removed(LibHalContext* ctx, const char* udi) { - unsigned int udi_hash = do_hash(udi, strlen(udi)); + unsigned int udi_hash = str_hash(udi); /* signal audio CD removal if udi match ours */ UIntListIter it = known_audio_udis.begin(), it_end = known_audio_udis.end();