LDMud的Python dbus包
ldmud-dbus的Python项目详细描述
LDMud的Python D-Bus包
这些是用于ldmud3.6.2和更高版本的python efun,用于通过D-Bus进行通信。
它提供了一个非常简单的接口来执行和接收方法调用和信号。
本模块不提供任何对内省的支持。支持
内省可以通过提供
org.freedesktop.DBus.Introspectable
接口。在
此软件包包含以下EFUN:
void dbus_call_method(closure callback, string bus, string path, string interface, string method, string signature, mixed args...)
void dbus_register_signal_listener(closure callback, string bus, string path, string interface, string signal)
void dbus_unregister_signal_listener(closure callback, string bus, string path, string interface, string signal)
void dbus_publish_object(object|string ob, string path, string|string*|mapping interfaces)
void dbus_emit_signal(string interface, string name, string signature, mixed args...)
所有EFUN都有特权,每个调用都用master->privilege_violation()
进行检查。在
此包支持以下LDMud类型及其对应的D-Bus。 D-Bus列中的第一个条目是未指定签名时选择的类型。在
LDMud | D-Bus | Notes |
---|---|---|
^{ | ^{ | |
^{ | ^{ | |
^{ | ^{ | |
^{ | ^{ | |
^{ | ^{ | |
^{ | ^{ | The key type is determined by looking at the mapping and must be int, float or string. |
使用
先决条件
此包还需要ldmud-asyncio包。在
从python包索引
安装可以从python包索引下载efun包:
pip3 install --user ldmud-dbus
自行构建和安装软件包
您可以自己构建包。在
首先克隆存储库
^{pr2}$安装程序包
cd python-dbus
python3 setup.py install --user
启动时自动加载模块
使用startup.py作为LDMud的Python启动脚本。 它将自动检测已安装的python efun并加载它们。在
您可以使用配置文件.ldmud-efuns
停用单个EFUN
在您的主目录中,包含以下内容
[efuns]
name_of_the_efun = off
启动时手动加载模块
要添加脚本的启动行:
import ldmud_dbus
ldmud_dbus.register()
配置
主目录中的配置文件.ldmud-efuns
可能指定要使用的总线和连接名。在
[dbus]
# The bus might be 'session', 'system' or an address like 'unix:path=/var/run/dbus/system_bus_socket'.
# Default is 'session'.
bus = session
# The connection name must be composed of at least two elements consisting of alphanumeric characters
# and separated by a period character. Default is none.
name = net.ldmud.mud
示例
通知
此包旨在与单独的D-Bus守护程序一起使用,用于与MUD特定工具通信。 但如果要连接到会话守护程序,则可以显示一些通知:
dbus_call_method(
function void(string error, varargs mixed* result)
{
// This is called with the result (notification id).
},
"org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify", "sisssasa{sv}i",
"LDMud", 0, "dialog-information", "Greetings!", "This is a message from your running LDMud.", ({}), ([]), 5000);
外部呼叫
创建要从外部调用的对象:
void create()
{
// This call can also by made by another object, for example at MUD startup.
// It routes external calls for "/my/object" to this object.
// The "my.mud.interface" interface will be implemented by the dbus_* functions.
dbus_publish_object(object_name(), "/my/object", ([ "my.mud.interface": "dbus_"]));
}
void dbus_message(string str)
{
shout(str);
}
string dbus_get_version()
{
return __VERSION__;
}
您可以使用dbus-send
实用程序来测试:
dbus-send --session --type=method_call --print-reply --dest=net.ldmud.mud "/my/object" my.mud.interface.message string:'Hello, World!'
dbus-send --session --type=method_call --print-reply --dest=net.ldmud.mud "/my/object" my.mud.interface.get_version
玩得开心!在
- 项目
标签: