DBus Glib 发送信号 - 没有信号被发出

3
我试图通过会话消息总线发送信号。我可以使用d-feet dbus调试器正常地调用方法,但无法连接到信号进行调试。因此,我使用 dbus-monitor "type='signal'" 来查看是否有任何信号被发送。到目前为止,这个方法可以工作,除了我发送的内容之外。
我的假设是,当调用 dbus_g_connection_register_g_object (connection, path, object); 时,它会注册在introspection xml文件中找到的所有方法、属性和信号。这似乎是正确的,因为在添加它们之前,dbus会抱怨信号不存在。
我尝试使用 g_signal_emit_by_name(self,"application_identifier_changed","some new crazy aid",NULL); 发送一个信号。这在应用程序本身内部运行,我可以连接到信号并触发它。但是,在dbus监视器中没有任何显示。我一定是漏掉了一些简单的东西。
下面是涉及到的文件:
main.c
int
main (int argc, char *argv[])
{
guint   result;
GError* error = NULL;
GObject * obj = NULL;

gtk_init(&argc,&argv);

gchar* bus_name = g_strdup_printf("org.maskwa.PowerviewApplicationPresence_%d",getpid());

dbus = dbus_g_bus_get(DBUS_BUS_SESSION,&error);
if (NULL != error) {
    g_error("error establishing dbus connection %s",error->message);
    g_error_free(error);
    return 1;
}
    //dbus_connection_setup_with_g_main(dbus_g_connection_get_connection(dbus),NULL);

proxy = dbus_g_proxy_new_for_name(dbus,
    DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);

org_freedesktop_DBus_request_name(proxy,
            bus_name, 
            DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error);

obj = g_object_new (POWERVIEW_TYPE_APPLICATION_PRESENCE, NULL);
dbus_g_connection_register_g_object (dbus, "/org/maskwa/powerview_application_presence", obj);

gtk_main();

if (NULL != bus_name) g_free(bus_name);
return 0;
}

powerview-application-presence.gob:

%headertop{

#include <dbus/dbus-glib.h>
#include "main.h"
%}

%{
#include "powerview-application-presence-glue.h"
%}

class Powerview:Application:Presence from G:Object {

class_init (class)
{
    dbus_g_object_type_install_info (POWERVIEW_TYPE_APPLICATION_PRESENCE,&dbus_glib_powerview_application_presence_object_info);
}

public void
get_application_identifier(self, gchar** OUT_aid, GError** error)
{
    g_print("%p      powerview_application_presence_get_application_identifier()\n",self);
    *OUT_aid = g_strdup("tld.domain.pong");
}

public void
get_display_name(self, gchar** OUT_display_name, GError** error)
{
    g_print("%p powerview_application_presence_get_display_name()\n",self);
    *OUT_display_name = g_strdup("Test Application");

    g_signal_emit_by_name(self,"application_identifier_changed","some new crazy aid",NULL);
}

signal last NONE (POINTER)
void application_identifier_changed (self, gchar** new_aid)
{
    g_print("application_identifier_changed()\n");
}

signal last NONE (POINTER)
void display_name_changed(self, gchar** new_display_name)
{

}
}

powerview-application-presence-instance.xml

<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- 
http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-signatures
-->
<node name="/">
<interface name="org.maskwa.PowerviewApplicationPresence">

    <method name="GetApplicationIdentifier">
        <arg type="s" name="OUT_aid" direction="out" />
    </method>
    <signal name="ApplicationIdentifierChanged">
        <arg type="s" name="new_aid" />
    </signal>

    <method name="GetDisplayName">
        <arg type="s" name="OUT_display_name" direction="out" />
    </method>
    <signal name="DisplayNameChanged">
        <arg type="s" name="new_display_name" />
    </signal>
</interface>
</node>

项目tarball: https://www.slello.com/tmp/PowerviewTestApp.tar.gz

我会非常感激您的任何帮助。


请勿添加到其他网站的链接,特别是像pastebin.com这样自动过期的链接。相反,请创建一个小的示例,并将所有代码包含在问题本身中。 - Johan Dahlin
我最初没有这样做,因为我不想使消息杂乱无章。不过我未来可以这样做。 - Mask
将来如果可能的话,请使用“dbus-monitor”实用程序进行验证。它在Linux上运行得很好。 - enthusiasticgeek
1个回答

0
我找到了问题的源头。在 powerview-application-presence.gob 中,signal last NONE (POINTER) 必须改为 signal last NONE (STRING)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接