我試圖通過會話消息總線發送信號。我可以使用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
我將不勝感激任何幫助。
請勿將鏈接添加到其他網站,特別是像pastebin.com這樣的網站會自動過期。相反,請創建一個小例子,並在問題本身中包含所有代碼。 – 2010-02-02 22:12:31
我最初並沒有想過把信息弄亂。無論我將來能否做到這一點。 – Mask 2010-02-03 21:13:44
如果可能,在將來使用'dbus-monitor'工具進行驗證。它在Linux上很好地工作 – enthusiasticgeek 2013-11-14 23:43:50