Question

The PulseAudio DBUS API page says that the arguments to LoadModule are

Arguments: name : String, arguments : {String -> String}

It also states that {String -> String} is a dictionary with a String key and String value.

How do I send this via the c++ API? Normally I would do something like this:

msg = dbus_message_new_method_call(
            "org.PulseAudio1",              //Destination
            "/org/pulseaudio/core1",                    //Object path to call on
            interfaceStr,                               //Interface to call on
            method);                                    //Method

Then create a msg iterator:

//append arguments to the LoadModule() method. (String, {String->String})
dbus_message_iter_init_append(msg, &msgIter);

dbus_message_iter_append_basic(&msgIter, DBUS_TYPE_STRING,&moduleName);

//dict entries
dbus_message_iter_open_container(&msgIter, DBUS_TYPE_DICT_ENTRY, NULL, &subIter);
dbus_message_iter_append_basic(&subIter, DBUS_TYPE_STRING, &sourceStr);
dbus_message_iter_append_basic(&subIter, DBUS_TYPE_STRING, &sourcePath);
dbus_message_iter_close_container(&msgIter, &subIter);

dbus_message_iter_open_container(&msgIter, DBUS_TYPE_DICT_ENTRY, NULL, &subIter);
dbus_message_iter_append_basic(&subIter, DBUS_TYPE_STRING, &sinkStr);
dbus_message_iter_append_basic(&subIter, DBUS_TYPE_STRING, &sinkPath);
dbus_message_iter_close_container(&msgIter, &subIter);

This creates a parameter list like this, I think: LoadModule(String, {String->String}, {String->String})

However, the function does not give a reply. I don't think I'm creating the parameters correctly. In fact, I'm pretty sure I'm not. I've seen others use arrays for different methods, but it does not specify that here. Is there a way to specifically state that something is a key/value?

UPDATE:

I found this line: A dictionary entry must be element of an array, and it must contain only a key-value pair of two elements, with a basic D-Bus type key. on the GNU Using of D-Bus Page, in case it helps. I'll try that and post the results.

Was it helpful?

Solution

As my update said, a dict entry has to be in an array, but it doesn't have to be the only element in the array. For instance, PulseAudio's loopback module takes command line arguments like this:

$pactl load-module module-loopback source="alsa_input.pci-0000_00_1b.0.analog-stereo" sink="bluez_sink.10_B7_F6_02_1B_4A"

In order to send this over DBUS, the loadModule() function requires a string and two dict entries, each containing a string key ("source" or "sink") and a string value ("name of device"). Note that the string value is NOT THE DEVICE'S PULSEAUDIO PATH, as I first suspected. It's the same string as is used with pactl. In order to create the s{ss}{ss} arguments, the dict entries first have to be encapsulated in an array: s[{ss}{ss}]. The iterator commands follow:

//append arguments to the Set() method. (string interface, string property, value)
dbus_message_iter_init_append(msg, &msgIter);

    //string
    dbus_message_iter_append_basic(&msgIter, DBUS_TYPE_STRING,&moduleName);

    //array
    dbus_message_iter_open_container(&msgIter,DBUS_TYPE_ARRAY,"{ss}{ss}",&arrayIter);

        //dict entry
        dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_DICT_ENTRY, NULL, &dictIter1);
            //strings
            dbus_message_iter_append_basic(&dictIter1, DBUS_TYPE_STRING, &sourceStr);
            dbus_message_iter_append_basic(&dictIter1, DBUS_TYPE_STRING, &sourceName);
        //close dict entry
        dbus_message_iter_close_container(&arrayIter, &dictIter1);

        //dict entry
        dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_DICT_ENTRY, NULL, &dictIter2);
            //strings
            dbus_message_iter_append_basic(&dictIter2, DBUS_TYPE_STRING, &sinkStr);
            dbus_message_iter_append_basic(&dictIter2, DBUS_TYPE_STRING, &sinkName);
        //close dict entry
        dbus_message_iter_close_container(&arrayIter, &dictIter2);

    //close array
    dbus_message_iter_close_container(&msgIter, &arrayIter);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top