gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:03:09 26 4
gpt4 key购买 nike

我正在尝试通过 session 消息总线发送信号。我可以使用 d-feet dbus 调试器调用方法,没有问题。不幸的是,d-feet 不允许您连接到信号来调试它们。作为替代,我使用 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 监视器中什么也没有出现。我一定是遗漏了一些简单的东西。

这里是涉及到的文件:
主.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>

项目压缩包:https://www.slello.com/tmp/PowerviewTestApp.tar.gz

如有任何帮助,我将不胜感激。

最佳答案

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

关于c - DBus Glib 发送信号 - 没有发出信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2125321/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com