简体   繁体   English

C ++:如何通过DBUS API加载PulseAudio模块?

[英]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.

相关问题 如何在C ++中使用Bluez5 DBUS API来配对和连接新设备? - How can I use Bluez5 DBUS API in C++ to pair and connect new devices? 如何将 Qt DBus 调用中的 QDBusMessage 中的数据转换为 QString c++ - How do I convert data from QDBusMessage in a Qt DBus call to a QString c++ 尝试加载内核模块时,如何解决C ++中的malloc()错误? - How do I fix this malloc() error in C++ when I am trying to load a kernel module? 通过包装器从 C 访问 C++ API 时,如何访问枚举类型? - When accessing C++ API from C via a wrapper, how do I access enum types? 如何在C ++中通过网络共享RAM模块? - How can I share RAM module via network in C++? C ++和pulseaudio“未在此范围内声明” - C++ and pulseaudio “not declared in this scope” PyQt程序可以使用DBus接口来公开自定义C ++类型(通过Qt的MetaType系统进行编组)吗? 如果是这样,怎么办? - Can a PyQt program consume a DBus interface that exposes custom C++ types (marhsalled via Qt's MetaType system)? If so, how? 如何导入 C++ 20<format> 模块?</format> - How do I import C++ 20 <format> module? 如何通过Rust FFI调用C ++构造函数? - How do I call a C++ constructor via Rust FFI? 如何在C ++中通过类结构共享代码? - How do I share code via class structure in C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM