GDBusProxy::g-properties-changed emitted under private main context on initialisation
Submitted by Stephen Kennedy
Assigned to David Zeuthen
Link to original bug (#637737)
Description
Created attachment 176819 example code which exhibits behaviour
While implementing a GDBusProxy subclass I came across some strange behaviour which I believe to be a bug.
In my custom subclass, I implemented a class handler for the g-properties-changed signal, which (for some object-path properties) created sub-proxies using the new object-path. However, these sub-proxies were not working as expected, particularly they were not emitting g-properties-changed when their properties were definitely being changed.
Trawling throught the innards of GDBusProxy, I found out that part of its initialisation uses a private GMainContext by calling g_main_context_push_thread_default (). Further testing revealed that when GDBusProxy first initialises its property cache, it emits a g-properties-changed (as you would expect). However, this signal was emitted while we were under the private main context, so creating sub-proxies while under this main context meant signal's were never returned to my main loop (they were returned to a main loop that was now destroyed).
I solved my problem by wrapping my signal handler code in:
g_main_context_push_thread_default (NULL); .....my code..... g_main_context_pop_thread_default (NULL);
Please find attached a simple example program that exhibits the behaviour.
Attachment 176819, "example code which exhibits behaviour":
main.c