2010-01-24 100 views
3

我试图通过会话消息总线发送信号。我可以使用d-feet dbus调试器正确调用方法,没有任何问题。不幸的是,d-feet不允许你连接信号来调试这些信号。作为替代,我使用dbus-monitor "type='signal'"来查看是否发送了任何内容。到目前为止,除了我发送的任何东西外,它都可以使用DBus Glib发送信号 - 没有信号被发射

我的假设是,当我们调用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的应用,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

我将不胜感激任何帮助。

+0

请勿将链接添加到其他网站,特别是像pastebin.com这样的网站会自动过期。相反,请创建一个小例子,并在问题本身中包含所有代码。 – 2010-02-02 22:12:31

+0

我最初并没有想过把信息弄乱。无论我将来能否做到这一点。 – Mask 2010-02-03 21:13:44

+0

如果可能,在将来使用'dbus-monitor'工具进行验证。它在Linux上很好地工作 – enthusiasticgeek 2013-11-14 23:43:50

回答

0

我发现问题的根源。在powerview-application-presence.gob,signal last NONE (POINTER)必须是signal last NONE (STRING)