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列中的第一个条目是未指定签名时选择的类型。在

LDMudD-BusNotes
^{}^{} (INT64), ^{} (UINT64), ^{} (INT32), ^{} (UINT32), ^{} (INT16), ^{} (UINT16), ^{} (BYTE), ^{} (BOOLEAN)
^{}^{} (DOUBLE)
^{}^{} (STRING), ^{} (OBJECT_PATH), ^{} (SIGNATURE)
^{}^{} (ARRAY of BYTES)
^{}^{} (ARRAY of VARIANT), ^{} (STRUCT)
^{}^{} (ARRAY of DICT_ENTRY)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

玩得开心!在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java块是一个特定的数字吗?   JavaJavaX DocumentBuilder生成“双UTF8”字符集编码   java如何创建本机查询以使用@query注释连接相关表   apache poi从Excel工作表读取日期值(Java)   java如何创建正则表达式以将“String”“匹配为两个字符串   java这是允许用户进行通配符搜索的正确方法吗?   将javascript变量传递给JavaBean   minecraft如何在另一个java程序中运行java程序   java Gradle任务构建不包括安卓类的Jar   java如何使用ANTLR构建交互式解析器?   springdataelasticsearch基于java注释的审计?   java如何从json获取数据url?   eclipse中服务器项目中的java FileNotFoundException   复制验证文件是否在Java中复制   java使用Jetty限制HTTP持久连接上每秒的事务数