<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Hello "DBUS-People",<BR>
<BR>
it is my first post about smth. new for me, so please be patient :)<BR>
<BR>
1- I took an example from the web, and I began to experiment a little. And I found smth. that I do not understand, and I found nowhere help.<BR>
2- The following code is a client application ( the server source code Iīm going to ignore for the moment). The problem is in the "<FONT color=#ff0000>g_main_context_new"</FONT> line.<BR>
<BR>
Problem:<BR>
If I comment this line, this client application receive the signals from the server. I mean, I work with the default context.<BR>
If I leave this line, this client application receive the signals no more. I mean, I define a new context.<BR>
<BR>
Questions:<BR>
Why the proxy stop to receive the signals from the server, when a new context (NOT the dafault one) is created and attached to the main loop?<BR>
<BR>
Thanks a lot in advance, and if this is the wrong place to post this... sorry and please tell me where can I find help about this topic.<BR>
<BR>
Thanks again<BR>
Bart<BR>
<BR>
#include <dbus/dbus-glib.h><BR>
...<BR>
<BR>
// Timer callback function to call every second the setvalue1 serverīs method. Until localValue > 10.<BR>
gboolean timerCallback(gpointer data)<BR>{<BR> static gint localValue = -80;<BR> GError* error = NULL;<BR> TimerData* timerData = (TimerData*)data;<BR>
org_maemo_Value_setvalue1(timerData->pProxy, localValue , &error);<BR>
.....<BR>
<BR>
localValue += 10;<BR>
if(10 < localValue)<BR> {<BR> g_print("timerCallback quit:%d.\n", quit);<BR> quit = 1;<BR> return FALSE;<BR> }<BR>
return TRUE;<BR>}<BR>
<BR>
// Signal handler that receive the signals from server with a string parameter.<BR>
static void valueChangedSignalHandler(DBusGProxy* proxy, const char* valueName, gpointer userData)<BR>{<BR> g_print("valueChangedSignalHandler - changed (%s).\n", valueName);<BR> if(quit)<BR> {<BR> g_print("valueChangedSignalHandler quit:%d.\n", quit);<BR> g_main_loop_quit((GMainLoop*)userData);<BR> }<BR>}<BR>
<BR>
int main(int argc , char ** argv)<BR>{<BR> GMainLoop* mainloop = NULL;<BR> GMainContext* context = NULL; <BR> GError* gerror = NULL;<BR> DBusGConnection* pGConnection = NULL;<BR> DBusGProxy* pGProxy = NULL;<BR> GSource* source = NULL;<BR> int id;<BR>
g_type_init();<BR>
<BR>
// Create connection / proxy.<BR> g_print("Creating a GConnection\n");<BR> pGConnection = dbus_g_bus_get(DBUS_BUS_SESSION, &gerror);<BR>
if(gerror != NULL)<BR> {<BR> g_printerr("could not open connection: %s\n", gerror->message);<BR> return 1;<BR> }<BR>
g_print("Creating a GProxy\n");<BR> pGProxy = dbus_g_proxy_new_for_name( pGConnection,<BR> "org.maemo.Platdev_ex", // name<BR> "/GlobalValue", // obj path<BR> "org.maemo.Value"); // interface<BR> if(pGProxy == NULL)<BR> {<BR> g_printerr("Couldn t create the proxy object ");<BR> return NULL;<BR> }<BR>
<BR>
//create a new time-out source<BR> source = g_timeout_source_new(1000);<BR> <BR> //create a main loop with context<BR> <FONT color=#ff0000>context = g_main_context_new(); <=== Problematic line :):) Not Commented: Stop receive signals</FONT><BR>
// <FONT color=#ff0000>context = g_main_context_new(); <=== Problematic line :):) Commented : Receive signals</FONT><BR>
<FONT color=#ff0000></FONT> <BR>
//attach source to context<BR> id = g_source_attach(source, context);<BR> <BR> mainloop = g_main_loop_new(context, FALSE);<BR>
if(mainloop == NULL)<BR> {<BR> g_printerr("Failed to create the mainloop.\n");<BR> return 0;<BR> }<BR> <BR> //set the callback for this source<BR> TimerData timerData;<BR> timerData.mainLoop = mainloop;<BR> timerData.pProxy = pGProxy;<BR>
g_source_set_callback(source, timerCallback, (gpointer)&timerData, NULL);<BR>
<BR>
g_print("Registering signal handler signatures.\n");<BR>
dbus_g_proxy_add_signal(pGProxy, SIGNAL_CHANGED_VALUE1, G_TYPE_STRING, G_TYPE_INVALID);<BR>
<BR>
g_print("Registering D-Bus signal handlers. Thd %p\n");<BR>
dbus_g_proxy_connect_signal(pGProxy, SIGNAL_CHANGED_VALUE1,<BR> G_CALLBACK(valueChangedSignalHandler),<BR> (gpointer)mainloop, NULL);<BR>
<BR>
g_main_loop_run(mainloop);<BR> <BR>
g_source_destroy(source);<BR> <BR> g_source_unref(source);<BR> <BR> g_print("Exiting main loop\n");<BR> g_main_loop_unref(mainloop);<BR> g_print("Bye ...\n");<BR>
return 0;<BR>}<BR><BR>
<BR>                                            </body>
</html>