DBus Glib发送信号 - 不发出信号

时间:2010-01-24 00:12:33

标签: c gtk signals dbus

我试图通过会话消息总线发送信号。我可以使用d-feet dbus调试器调用方法,没有问题。不幸的是,d-feet不允许您连接信号来调试它们。替换我使用dbus-monitor "type='signal'"来查看是否发送了任何内容。到目前为止,除了我发送的任何内容外,

我的假设是,当一个人调用dbus_g_connection_register_g_object (connection, path, object);时,它会记录内省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的应用-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-应用存在-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

我将不胜感激。

1 个答案:

答案 0 :(得分:0)

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