[英]C++: How do I load a PulseAudio module via DBUS API?
The PulseAudio DBUS API page says that the arguments to LoadModule are PulseAudio DBUS API页面说到LoadModule的参数是
Arguments: name : String, arguments : {String -> String} 参数:name:字符串,参数:{String-> String}
It also states that {String -> String} is a dictionary with a String key and String value. 它还声明{String-> String}是具有String键和String值的字典。
How do I send this via the c++ API? 如何通过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}) 我认为,这样会创建一个这样的参数列表: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. 我找到了这一行: 字典条目必须是数组的元素,并且它必须仅包含两个元素的键值对,并带有基本的D-Bus类型键。 on the GNU Using of D-Bus Page, in case it helps.
如果有帮助,请在GNU使用D-Bus页面上使用 。 I'll try that and post the results.
我会尝试并发布结果。
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:
例如,PulseAudio的回送模块采用如下命令行参数:
$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"). 为了通过DBUS发送此消息,loadModule()函数需要一个字符串和两个dict条目,每个条目都包含一个字符串键(“源”或“接收器”)和一个字符串值(“设备名称”)。 Note that the string value is NOT THE DEVICE'S PULSEAUDIO PATH, as I first suspected.
请注意,该字符串值不是我首先怀疑的设备的PULSEAUDIO PATH。 It's the same string as is used with pactl.
它与pactl使用的字符串相同。 In order to create the s{ss}{ss} arguments, the dict entries first have to be encapsulated in an array: s[{ss}{ss}].
为了创建s {ss} {ss}参数,首先必须将dict条目封装在一个数组中: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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.