[pulseaudio-commits] r1190 - in /trunk/src/modules: dbus-util.c module-hal-detect.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Mon Aug 7 13:29:32 PDT 2006


Author: shahms
Date: Mon Aug  7 22:29:31 2006
New Revision: 1190

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1190&root=pulseaudio&view=rev
Log:
clean up hal patch to use pa_xnew and timeval compatibility wrappers

Modified:
    trunk/src/modules/dbus-util.c
    trunk/src/modules/module-hal-detect.c

Modified: trunk/src/modules/dbus-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/dbus-util.c?rev=1190&root=pulseaudio&r1=1189&r2=1190&view=diff
==============================================================================
--- trunk/src/modules/dbus-util.c (original)
+++ trunk/src/modules/dbus-util.c Mon Aug  7 22:29:31 2006
@@ -27,6 +27,7 @@
 #include <pulsecore/log.h>
 #include <pulsecore/props.h>
 #include <pulse/xmalloc.h>
+#include <pulse/timeval.h>
 
 #include "dbus-util.h"
 
@@ -80,14 +81,6 @@
         events |= PA_IO_EVENT_OUTPUT;
 
     return events;
-}
-
-static void timeval_next(struct timeval *tv, int millint)
-{
-    /* number of seconds in the milli-second interval */
-    tv->tv_sec += (millint / 1000);
-    /* milliseconds minus the seconds portion, converted to microseconds */
-    tv->tv_usec += (millint - tv->tv_sec * 1000) * 1000;
 }
 
 /* pa_io_event_cb_t IO event handler */
@@ -128,7 +121,7 @@
         dbus_timeout_handle(timeout);
 
         /* restart it for the next scheduled time */
-        timeval_next(&next, dbus_timeout_get_interval(timeout));
+        pa_timeval_add(&next, dbus_timeout_get_interval(timeout) * 1000);
         ea->time_restart(e, &next);
     }
 }
@@ -182,10 +175,10 @@
     if (!dbus_timeout_get_enabled(timeout))
         return FALSE;
 
-    if (gettimeofday(&tv, NULL) < 0)
+    if (pa_gettimeofday(&tv) < 0)
         return -1;
 
-    timeval_next(&tv, dbus_timeout_get_interval(timeout));
+    pa_timeval_add(&tv, dbus_timeout_get_interval(timeout) * 1000);
 
     ev = c->mainloop->time_new(c->mainloop, &tv, handle_time_event,
                                (void*) timeout);
@@ -216,14 +209,13 @@
     pa_core *c = (pa_core*) data;
     pa_time_event *ev = (pa_time_event*) dbus_timeout_get_data(timeout);
 
-    gettimeofday(&tv, NULL);
     if (dbus_timeout_get_enabled(timeout)) {
-        timeval_next(&tv, dbus_timeout_get_interval(timeout));
+        pa_gettimeofday(&tv);
+        pa_timeval_add(&tv, dbus_timeout_get_interval(timeout) * 1000);
         c->mainloop->time_restart(ev, &tv);
     } else {
-        /* set it to expire one second ago */
-        tv.tv_sec -= 1;
-        c->mainloop->time_restart(ev, &tv);
+        /* disable the timeout */
+        c->mainloop->time_restart(ev, NULL);
     }
 }
 
@@ -251,7 +243,7 @@
 
 static pa_dbus_connection* pa_dbus_connection_new(pa_core* c, DBusConnection *conn, const char* name)
 {
-    pa_dbus_connection *pconn = pa_xmalloc(sizeof(pa_dbus_connection));
+    pa_dbus_connection *pconn = pa_xnew(pa_dbus_connection, 1);
 
     pconn->refcount = 1;
     pconn->core = c;
@@ -305,19 +297,16 @@
     const char* name;
     DBusConnection *conn;
     pa_dbus_connection *pconn;
-    static const char sysname[] = "dbus-connection-system";
-    static const char sessname[] = "dbus-connection-session";
-    static const char startname[] = "dbus-connection-starter";
 
     switch (type) {
         case DBUS_BUS_SYSTEM:
-            name = sysname;
+            name = "dbus-connection-system";
             break;
         case DBUS_BUS_SESSION:
-            name = sessname;
+            name = "dbus-connection-session";
             break;
         case DBUS_BUS_STARTER:
-            name = startname;
+            name = "dbus-connection-starter";
             break;
         default:
             assert(0); /* never reached */

Modified: trunk/src/modules/module-hal-detect.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-hal-detect.c?rev=1190&root=pulseaudio&r1=1189&r2=1190&view=diff
==============================================================================
--- trunk/src/modules/module-hal-detect.c (original)
+++ trunk/src/modules/module-hal-detect.c Mon Aug  7 22:29:31 2006
@@ -34,11 +34,11 @@
 #include <sys/stat.h>
 
 #include <pulse/xmalloc.h>
+#include <pulse/timeval.h>
 
 #include <pulsecore/core-error.h>
 #include <pulsecore/module.h>
 #include <pulsecore/log.h>
-#include <pulsecore/core-subscribe.h>
 #include <pulsecore/hashmap.h>
 #include <pulsecore/idxset.h>
 #include <pulsecore/core-util.h>
@@ -68,18 +68,16 @@
 } alsa_type_t;
 
 struct device {
+    uint32_t index;
     char *udi;
-    pa_module *module;
 };
 
 struct userdata {
     pa_core *core;
-    pa_subscription *sub;
     LibHalContext *ctx;
     capability_t capability;
     pa_dbus_connection *conn;
-    pa_hashmap *by_udi;
-    pa_hashmap *by_module;
+    pa_hashmap *devices;
 };
 
 struct timerdata {
@@ -159,12 +157,11 @@
     if (!(m = pa_module_load(u->core, module_name, args)))
         return FALSE;
 
-    d = pa_xmalloc(sizeof(struct device));
+    d = pa_xnew(struct device, 1);
     d->udi = pa_xstrdup(udi);
-    d->module = m;
-
-    pa_hashmap_put(u->by_module, m, d);
-    pa_hashmap_put(u->by_udi, udi, d);
+    d->index = m->index;
+
+    pa_hashmap_put(u->devices, udi, d);
 
     return TRUE;
 }
@@ -291,13 +288,13 @@
     if (!has_cap)
         return;
 
-    /* actually add the device one second later */
-    t = pa_xmalloc(sizeof(struct timerdata));
+    /* actually add the device 1/2 second later */
+    t = pa_xnew(struct timerdata, 1);
     t->u = u;
     t->udi = pa_xstrdup(udi);
 
-    gettimeofday(&tv, NULL);
-    tv.tv_sec += 1;
+    pa_gettimeofday(&tv);
+    pa_timeval_add(&tv, 500000);
     u->core->mainloop->time_new(u->core->mainloop, &tv,
                                 device_added_time_cb, t);
 }
@@ -308,10 +305,8 @@
     struct userdata *u = (struct userdata*) libhal_ctx_get_user_data(ctx);
 
     pa_log_debug(__FILE__": Device removed: %s", udi);
-    if ((d = pa_hashmap_remove(u->by_udi, udi))) {
-        d = pa_hashmap_remove(u->by_module, d->module);
-        pa_log_debug(__FILE__": Unloading: %s <%s>", d->module->name, d->module->argument);
-        pa_module_unload_request(d->module);
+    if ((d = pa_hashmap_remove(u->devices, udi))) {
+        pa_module_unload_by_index(u->core, d->index);
         hal_device_free(d);
     }
 }
@@ -335,30 +330,6 @@
 }
 #endif
 
-static void subscribe_notify_cb(pa_core *c, pa_subscription_event_type_t type,
-                                uint32_t idx, void *userdata)
-{
-    pa_module *m;
-    struct device *d;
-    struct userdata *u = (struct userdata*) userdata;
-
-    /* only listen for module remove events */
-    if (type != (PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_REMOVE))
-        return;
-
-    if (!(m = pa_idxset_get_by_index(c->modules, idx)))
-        return;
-
-    /* we found the module, see if it's one we care about */
-    if ((d = pa_hashmap_remove(u->by_module, m))) {
-        pa_log_debug(__FILE__": Removing module #%u %s: %s",
-                     m->index, m->name, d->udi);
-        d = pa_hashmap_remove(u->by_udi, d->udi);
-        hal_device_free(d);
-    }
-}
-
-
 static void pa_hal_context_free(LibHalContext* hal_ctx)
 {
     DBusError error;
@@ -374,11 +345,8 @@
 
 static void userdata_free(struct userdata *u) {
     pa_hal_context_free(u->ctx);
-    pa_subscription_free(u->sub);
-    /* free the hashmap */
-    pa_hashmap_free(u->by_module, NULL, NULL);
     /* free the devices with the hashmap */
-    pa_hashmap_free(u->by_udi, hal_device_free_cb, NULL);
+    pa_hashmap_free(u->devices, hal_device_free_cb, NULL);
     pa_dbus_connection_unref(u->conn);
     pa_xfree(u);
 }
@@ -441,15 +409,12 @@
         return -1;
     }
 
-    u = pa_xmalloc(sizeof(struct userdata));
+    u = pa_xnew(struct userdata, 1);
     u->core = c;
     u->ctx = hal_ctx;
     u->conn = conn;
-    u->by_module = pa_hashmap_new(NULL, NULL);
-    u->by_udi = pa_hashmap_new(pa_idxset_string_hash_func,
-                               pa_idxset_string_compare_func);
-    u->sub = pa_subscription_new(c, PA_SUBSCRIPTION_MASK_MODULE,
-                                 subscribe_notify_cb, (void*) u);
+    u->devices = pa_hashmap_new(pa_idxset_string_hash_func,
+                                pa_idxset_string_compare_func);
     m->userdata = (void*) u;
 
 #if HAVE_ALSA




More information about the pulseaudio-commits mailing list