<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Comic Sans MS";
        panose-1:3 15 7 2 3 3 2 2 2 4;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Comic Sans MS";
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>Hi, Dear developers<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>I’m new to DBUS world, and I’m
trying to get the NameOwnerChanged Signal from org.freedesktop.Dbus<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>But It seems I can’t get my callback
be invoked.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>Could you please help? Below is the code
that I’m using.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>Thanks a lot!!!!!<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>#include <memory.h><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>#include <stdio.h><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>#include <stdlib.h><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>#include <stdio.h><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>#include <unistd.h><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>#include <glib.h><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>#include <dbus/dbus.h><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>#include <dbus/dbus-glib.h><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>GError *error;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>DBusGConnection *fdb_connection;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>DBusGProxy *fdb_proxy = NULL;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>/* Connect to am dbus server<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> * return 0 means failed<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> * return 1 means succeeded<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> * */<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>gint dbus_init() {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> char *fdb_name = "org.freedesktop.Dbus";<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> char *fdb_path = "/org/freedesktop/Dbus";<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> char *fdb_interface = "org.freedesktop.Dbus";<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> fdb_connection = dbus_g_bus_get(DBUS_BUS_SESSION,
&error);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> if (fdb_connection == NULL) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_printerr("Failed to open
connection to bus: %s\n",<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> error->message);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_error_free(error);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> return 0;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> fdb_proxy = dbus_g_proxy_new_for_name(fdb_connection,
fdb_name,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> fdb_path,
fdb_interface);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> if (fdb_proxy == NULL) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_print("connect to
freedesktop dbus server failed\n");<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> return 0;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> } <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> else {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_print("connect to
freedesktop dbus server succeeded\n");<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> return 1;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>}<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>static void fdb_signal_handler (DBusGProxy*
p, const gchar* str, const gchar* str1, const gchar* str2, gpointer userData) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_print("fdb_signal_handler\n");<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_print("Got signal %s\n", str);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_print("Got signal %s\n", str1);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_print("Got signal %s\n", str2);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>}<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>/* Signal connection initialization<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> * */<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>void connect_signals() {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> dbus_g_proxy_add_signal(fdb_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> dbus_g_proxy_connect_signal(fdb_proxy, "NameOwnerChanged",
G_CALLBACK(fdb_signal_handler), NULL, NULL);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>}<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>int main(int argc, char* argv[]) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_type_init();<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> if (dbus_init() == 0)<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> return -1; <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> connect_signals();<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> static GMainLoop *loop = NULL;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> loop = g_main_loop_new(NULL, FALSE);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'> g_main_loop_run(loop);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'>}<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Comic Sans MS"><span style='font-size:
10.0pt;font-family:"Comic Sans MS"'><o:p> </o:p></span></font></p>
<p style='margin:0in;margin-bottom:.0001pt'><font size=1 face="Comic Sans MS"><span
style='font-size:7.5pt;font-family:"Comic Sans MS"'>Best Regards, Zheng,
Huan(ZBT)<o:p></o:p></span></font></p>
<p style='margin:0in;margin-bottom:.0001pt'><font size=1 face="Comic Sans MS"><span
style='font-size:7.5pt;font-family:"Comic Sans MS"'>OTC/SSD/SSG</span></font><o:p></o:p></p>
<p style='margin:0in;margin-bottom:.0001pt'><font size=1 face="Comic Sans MS"><span
style='font-size:7.5pt;font-family:"Comic Sans MS"'>Intel Aisa-Pacific Research
& Developement Ltd</span></font><o:p></o:p></p>
<p style='margin:0in;margin-bottom:.0001pt'><font size=1 face="Comic Sans MS"><span
style='font-size:7.5pt;font-family:"Comic Sans MS"'>Tel: 021-6116 6435</span></font><o:p></o:p></p>
<p style='margin:0in;margin-bottom:.0001pt'><font size=1 face="Comic Sans MS"><span
style='font-size:7.5pt;font-family:"Comic Sans MS"'>Inet: 8821 6435</span></font><o:p></o:p></p>
<p style='margin:0in;margin-bottom:.0001pt'><font size=1 face="Comic Sans MS"><span
style='font-size:7.5pt;font-family:"Comic Sans MS"'>Cub: 3W035</span></font><o:p></o:p></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
</div>
</body>
</html>