[Vala] Signals not being called back
Hello! I'm having issues getting signals to callback in my Vala application and I'm kind of at a loss. I'm fairly confident that this is a setup issue relating to Gtk.Appplication.run() and Gtk.main() but I cannot be sure. Here's my basic setup: main () creates and runs a Gtk.Application which creates a Gtk.Window (MainWindow) containing basic buttons and a search entry. The signals related to these widgets work just fine and will merrily call back. However, I have a Gtk.TreeView with a Gtk.TreeStore that is contained within a class called ApplicationProcessModel which inherits from GLib.Object -- these are all created in the MainWindow constructor. The ApplicationProcessModel is supposed to update the Gtk.TreeStore with information relating to running applications and processes. To do this, I'm using libbamf-3.0 which has a number of signals relating to when an application or window is launched and a custom /proc/ parser which I am writing. In ApplicationProcessModel's constructor, I do a connect() to the signals from libbamf just fine and the compiler doesn't complain at all, however, the callbacks never run. I actually get a list of running applications from libbamf and it works just fine. Now, initially, my thought was that I didn't understand how libbamf's signals worked and I was just doing it wrong. So I looked at Plank's (another Vala application using libbamf) source code and it was doing nearly the same thing that I was doing, and it was obviously working. So I tried a couple other signals and callbacks that I knew worked. None of them worked from within ApplicationProcessModel. Then, in desperation to get anything to callback, I went ahead and tried putting a Glib.Timeout that would trigger a callback every second in the ApplicationProcessModel. You can imagine my surprise when, not only is the callback from the Timeout called properly, suddenly my libbamf signal handlers are called, and not just when the timer triggers, but whenever a window is created or closed (like is the intended behavior of the signals). Now, this is great, because it now kind of works -- but I have no idea what exactly putting in the Timeout did to make it work! Moving the Timeout to MainWindow from ApplicationProcessModel causes the fix to not work. I suspect that there is some setup that I'm missing that creating a Timeout does, perhaps related to how the signal is checked and dispatched from the main loop in Gtk.Application.run() or Gtk.main(). I've tried moving to a simpler setup without Gtk.Application with MainWindow created by main() with calls to Gtk.init() at the beginning and Gtk.main() at the end, but that didn't actually change any behavior at all, it still doesn't work normally and works with the Timeout. I'm sure that I'm just missing out on some vital piece of information regarding callbacks. I can provide code if that is needed. Any ideas? Michael P. Starkweather ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Signals not being called back
I suspect your connect was done before a main loop was created and libbamf doesn't automatically create one. Timeout, on the other hand, will cause a default main loop to be created. Nice day Nor Jaidi Tuah PRIVILEGED/CONFIDENTIAL information may be contained in this message. If you are neither the addressee (intended recipient) nor an authorised recipient of the addressee, and have received this message in error, please destroy this message (including attachments) and notify the sender immediately. STRICT PROHIBITION: This message, whether in part or in whole, should not be reviewed, retained, copied, reused, disclosed, distributed or used for any purpose whatsoever. Such unauthorised use may be unlawful and may contain material protected by the Official Secrets Act (Cap 153) of the Laws of Brunei Darussalam. DISCLAIMER: We/This Department/The Government of Brunei Darussalam, accept[s] no responsibility for loss or damage arising from the use of this message in any manner whatsoever. Our messages are checked for viruses but we do not accept liability for any viruses which may be transmitted in or with this message. ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Signals not being called back
I noticed after your response (thank you for that when I canceled the Timeout by returning false from the callback that the libbamf signal callbacks also stopped, which I found curious, because if it was a setup thing and if the Timeout was doing some sort of setup, then surely after the Timeout ended, the setup would remain. So I was typing up a confused email containing a simple diagram with the relationships and call order of everything because I was sure more than ever that I was doing it right. In creating this diagram, I noticed that my object containing the callbacks (ApplicationProcessModel) was created locally (by accidentally including the keyword var in front of it) and the reference was never held causing the object to be destroyed when it dropped out of scope. When I created the Timeout in the constructor, it was holding a reference to the locally created object that it needed to callback to, causing it to live until the Timeout was canceled. My Gtk.TreeView still held a reference to the Gtk.TreeStore that had been stored in this object, so it never occurred to me that the rest of the object was simply going away. What an odd problem. Thanks for your time! Michael P. Starkweather On Wed, Sep 3, 2014 at 6:51 PM, Nor Jaidi Tuah wrote: > I suspect your connect was done before a > main loop was created and libbamf doesn't > automatically create one. Timeout, on the > other hand, will cause a default main loop > to be created. > > Nice day > Nor Jaidi Tuah > > > > > > PRIVILEGED/CONFIDENTIAL information may be contained in this message. If > you are neither the addressee (intended recipient) nor an authorised > recipient of the addressee, and have received this message in error, please > destroy this message (including attachments) and notify the sender > immediately. STRICT PROHIBITION: This message, whether in part or in whole, > should not be reviewed, retained, copied, reused, disclosed, distributed or > used for any purpose whatsoever. Such unauthorised use may be unlawful and > may contain material protected by the Official Secrets Act (Cap 153) of the > Laws of Brunei Darussalam. DISCLAIMER: We/This Department/The Government of > Brunei Darussalam, accept[s] no responsibility for loss or damage arising > from the use of this message in any manner whatsoever. Our messages are > checked for viruses but we do not accept liability for any viruses which > may be transmitted in or with this message. > ___ > vala-list mailing list > vala-list@gnome.org > https://mail.gnome.org/mailman/listinfo/vala-list > ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list