[pulseaudio-discuss] Receiving signals from server in C

Greg Knoll gregknoll at gmail.com
Fri Jun 13 08:17:16 PDT 2014


I think first it would be good to know that I'm correctly registering
with ListenForSignal.  First I use

   conn = dbus_connection_open(serverAddress, &err);

to get a connection to PulseAudio.  Then I call the message:

    msg = dbus_message_new_method_call(

            "org.PulseAudio1",             //Destination

            "/org/pulseaudio/core1",     //Object path to call on

            "org.PulseAudio.Core1",     //Interface to call on

            "ListenForSignal");             //Method



    //Add arguments: s, []

    dbus_message_iter_init_append(msg, &msgIter);


        //string

        dbus_message_iter_append_basic(&msgIter, DBUS_TYPE_STRING,&signalName);


        //empty array to listen to all

        dbus_message_iter_open_container(&msgIter,DBUS_TYPE_ARRAY,"o",&arrayIter);

        dbus_message_iter_close_container(&msgIter, &arrayIter);


    //call dbus function

    debug_print("   >...Listening for signal %s...\n",signalName);

    dbus_connection_send_with_reply_and_block (conn, msg, -1, &err);

with signalName = "org.PulseAudio.Core1.NewModule"

Is this correct if I want to be notified when all new modules are loaded?

If so, I then call dbus_connection_pop_message on the private
connection in the main loop.

Do I need to add a match?

On Wed, Jun 4, 2014 at 11:06 AM, Tanu Kaskinen
<tanu.kaskinen at linux.intel.com> wrote:
> On Mon, 2014-06-02 at 13:48 +0200, Greg Knoll wrote:
>> On Fri, May 30, 2014 at 3:44 PM, Tanu Kaskinen
>> <tanu.kaskinen at linux.intel.com> wrote:
>> > (Added pulseaudio-discuss back to cc.)
>> >
>> > On Fri, 2014-05-30 at 15:24 +0200, Greg Knoll wrote:
>> >> Thank you for your response,
>> >>
>> >>
>> >> Yes, I did follow that tutorial.  I didn't state it correctly in my
>> >> question, but I do only use the session bus to get the server
>> >> address.  Then I use
>> >>
>> >>
>> >>     *conn = dbus_connection_open(serverAddress, &err);
>> >>
>> >> to get the DBusConnection object and use this to make calls.
>> >
>> > Ok, I suppose this is not the problem then. Back to the original
>> > question:
>> >
>> >> However, where/how do I listen for the signal?  I also tried setting a
>> >> dbus match rule:
>> >>    dbus_bus_add_match(system_bus, "type='signal',interface='org.PulseAudio.Core1'", &err);
>> >
>> > You don't need to add a match rule (trying to do so won't do anything
>> > useful, because the match rules are managed by the bus daemon, and in a
>> > peer-to-peer connection there's no bus daemon involved at all). Do you
>> > register a message filter with dbus_connection_add_filter()? If not,
>> > then that's the problem.
>> >
>> > By the way, please don't top-post on mailing lists, and also plain text
>> > messages are preferred over HTML.
>> >
>> > --
>> > Tanu
>> >
>> >
>>
>> Sorry about the top post.
>>
>> I did not register a dbus_connection_add_filter().  I have added a
>> DBusHandlerResult function based on the examples here:
>> https://kernel.googlesource.com/pub/scm/bluetooth/bluez/+/utils-3.4/hcid/dbus-error.c
>> and
>> http://lists.freedesktop.org/archives/dbus/2003-September/000468.html
>>
>> The second one uses an object DBusMessageHandler, which I think is
>> from glib/dbus-glib.  Maybe I'm wrong there.  My function looks like
>> this:
>>
>> DBusHandlerResult listen_to_core_Handler(DBusConnection *connection,
>> DBusMessage *message, void *user_data)
>>
>> {
>>
>>     debug_print("Message received from Pulse Core.\n");
>>
>>     debug_print("Signature:%s\n", dbus_message_get_signature(message));
>>
>> }
>>
>> and I add a call to dbus_connection_add_filter() in my main thread using:
>>
>> dbus_connection_add_filter(PA_bus, listen_to_core_Handler, NULL, NULL);
>>
>>
>> Still nothing.  I should also say that the signal name string I'm
>> using is "org.PulseAudio.Core1.NewModule".
>>
>> Thanks for all the help so far.
>
> How do you dispatch incoming messages? Do you integrate the D-Bus
> connection with some event loop, or do you manually call
> dbus_connection_read_write_dispatch() in a loop or something similar?
>
> --
> Tanu
>


More information about the pulseaudio-discuss mailing list