[pulseaudio-commits] r1609 - /branches/lennart/src/modules/module-x11-bell.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Aug 9 16:46:04 PDT 2007


Author: lennart
Date: Fri Aug 10 01:46:03 2007
New Revision: 1609

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1609&root=3Dpulseaudio&vi=
ew=3Drev
Log:
modernize

Modified:
    branches/lennart/src/modules/module-x11-bell.c

Modified: branches/lennart/src/modules/module-x11-bell.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/mo=
dule-x11-bell.c?rev=3D1609&root=3Dpulseaudio&r1=3D1608&r2=3D1609&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/module-x11-bell.c (original)
+++ branches/lennart/src/modules/module-x11-bell.c Fri Aug 10 01:46:03 2007
@@ -26,7 +26,6 @@
 #endif
 =

 #include <stdio.h>
-#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 =

@@ -67,30 +66,21 @@
     NULL
 };
 =

-static int ring_bell(struct userdata *u, int percent) {
-    pa_sink *s;
-    assert(u);
-
-    if (!(s =3D pa_namereg_get(u->core, u->sink_name, PA_NAMEREG_SINK, 1))=
) {
-        pa_log("Invalid sink: %s", u->sink_name);
-        return -1;
-    }
-
-    pa_scache_play_item(u->core, u->scache_item, s, (percent*PA_VOLUME_NOR=
M)/100);
-    return 0;
-}
-
 static int x11_event_callback(pa_x11_wrapper *w, XEvent *e, void *userdata=
) {
     XkbBellNotifyEvent *bne;
     struct userdata *u =3D userdata;
-    assert(w && e && u && u->x11_wrapper =3D=3D w);
+    =

+    pa_assert(w);
+    pa_assert(e);
+    pa_assert(u);
+    pa_assert(u->x11_wrapper =3D=3D w);
 =

     if (((XkbEvent*) e)->any.xkb_type !=3D XkbBellNotify)
         return 0;
 =

     bne =3D (XkbBellNotifyEvent*) e;
 =

-    if (ring_bell(u, bne->percent) < 0) {
+    if (pa_scache_play_item_by_name(u->core, u->scache_item, u->sink_name,=
 (bne->percent*PA_VOLUME_NORM)/100, 1) < 0) {
         pa_log_info("Ringing bell failed, reverting to X11 device bell.");
         XkbForceDeviceBell(pa_x11_wrapper_get_display(w), bne->device, bne=
->bell_class, bne->bell_id, bne->percent);
     }
@@ -99,18 +89,21 @@
 }
 =

 int pa__init(pa_core *c, pa_module*m) {
+
     struct userdata *u =3D NULL;
     pa_modargs *ma =3D NULL;
     int major, minor;
     unsigned int auto_ctrls, auto_values;
-    assert(c && m);
+    =

+    pa_assert(c);
+    pa_assert(m);
 =

     if (!(ma =3D pa_modargs_new(m->argument, valid_modargs))) {
-        pa_log("failed to parse module arguments");
+        pa_log("Failed to parse module arguments");
         goto fail;
     }
 =

-    m->userdata =3D u =3D pa_xmalloc(sizeof(struct userdata));
+    m->userdata =3D u =3D pa_xnew(struct userdata, 1);
     u->core =3D c;
     u->scache_item =3D pa_xstrdup(pa_modargs_get_value(ma, "sample", "x11-=
bell"));
     u->sink_name =3D pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
@@ -129,7 +122,6 @@
 =

     major =3D XkbMajorVersion;
     minor =3D XkbMinorVersion;
-
 =

     if (!XkbQueryExtension(pa_x11_wrapper_get_display(u->x11_wrapper), NUL=
L, &u->xkb_event_base, NULL, &major, &minor)) {
         pa_log("XkbQueryExtension() failed");
@@ -150,14 +142,22 @@
 fail:
     if (ma)
         pa_modargs_free(ma);
-    if (m->userdata)
-        pa__done(c, m);
+
+    pa__done(c, m);
+    =

     return -1;
 }
 =

 void pa__done(pa_core *c, pa_module*m) {
-    struct userdata *u =3D m->userdata;
-    assert(c && m && u);
+    struct userdata *u;
+    =

+    assert(c);
+    assert(m);
+
+    if (!m->userdata)
+        return;
+
+    u =3D m->userdata;
 =

     pa_xfree(u->scache_item);
     pa_xfree(u->sink_name);




More information about the pulseaudio-commits mailing list