diff options
author | Shahms E. King <shahms@shahms.com> | 2006-08-07 20:29:31 +0000 |
---|---|---|
committer | Shahms E. King <shahms@shahms.com> | 2006-08-07 20:29:31 +0000 |
commit | b382df5868db14628bed2d7445706dab5a4bdf58 (patch) | |
tree | a24ca96873cb6c5132fe53a7c4f5e6278c724ce3 /src | |
parent | 5d8ccfd83984c6b0559857e6a0bf13037818ca95 (diff) |
clean up hal patch to use pa_xnew and timeval compatibility wrappers
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1190 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/dbus-util.c | 35 | ||||
-rw-r--r-- | src/modules/module-hal-detect.c | 67 |
2 files changed, 28 insertions, 74 deletions
diff --git a/src/modules/dbus-util.c b/src/modules/dbus-util.c index b5c61337..c9cdf114 100644 --- a/src/modules/dbus-util.c +++ b/src/modules/dbus-util.c @@ -27,6 +27,7 @@ #include <pulsecore/log.h> #include <pulsecore/props.h> #include <pulse/xmalloc.h> +#include <pulse/timeval.h> #include "dbus-util.h" @@ -82,14 +83,6 @@ get_watch_flags(DBusWatch *watch) 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 */ static void handle_io_event(PA_GCC_UNUSED pa_mainloop_api *ea, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) @@ -128,7 +121,7 @@ static void handle_time_event(pa_mainloop_api *ea, pa_time_event* e, 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 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) 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 @@ static void toggle_timeout(DBusTimeout *timeout, void *data) 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 @@ wakeup_main(void *userdata) 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 @@ pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, 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 */ diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c index adcb866c..a35144b0 100644 --- a/src/modules/module-hal-detect.c +++ b/src/modules/module-hal-detect.c @@ -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 @@ typedef enum { } 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 @@ static dbus_bool_t hal_device_add_alsa(struct userdata *u, const char *udi, 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; + d->index = m->index; - pa_hashmap_put(u->by_module, m, d); - pa_hashmap_put(u->by_udi, udi, d); + pa_hashmap_put(u->devices, udi, d); return TRUE; } @@ -291,13 +288,13 @@ static void device_added_cb(LibHalContext *ctx, const char *udi) 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 @@ static void device_removed_cb(LibHalContext* ctx, const char *udi) 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 @@ static void property_modified_cb(LibHalContext *ctx, const char *udi, } #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 pa_hal_context_free(LibHalContext* hal_ctx) 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 @@ int pa__init(pa_core *c, pa_module*m) { 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 |