SignalTimeout, TimeoutSource questions



I need to use several timers in my application.  I have searched the glibmm
reference
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classes.html
and tutorial
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/
and have been able to learn enough to actually use timers in my app.
Still, there are a few questions about timers and I have not been able
to learn the answers from the above reference material or from this list.

There are two things I want to do:
1. enable/disable a timer on demand.
2. change the timeout period while running.

For the enable/disable I see from the tutorial and this list that I can
do something like my_connection.disconnect()  or have the timer
handler return false.  That leave me with one question.  Somewhere
in this list I saw a post that suggested just repeating the timer creation
to re-enable.  so, if I have this from the example
sigc::connection conn = Glib::signal_timeout().connect(my_slot, timeout_value);


I just use this to disconnect with this
conn.disconnect();

but, do the SignalTimeout resources go away when I disconnect?
If I then reconnect by calling again

sigc::connection conn = Glib::signal_timeout().connect(my_slot, timeout_value);

will I have a resource leak?  I see the doc 
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1SignalTimeout.html
says that 

 Glib::signal_timeout().connect(sigc::ptr_fun(&timeout_handler), 1000);
is equivalent to:
 const Glib::RefPtr<Glib::TimeoutSource> timeout_source = Glib::TimeoutSource::create(1000);
 timeout_source->connect(sigc::ptr_fun(&timeout_handler));
 timeout_source->attach(Glib::MainContext::get_default());
Does the RefPtr mean there won't be a resource leak?  Is there
any value in using the 3 line method and just connecting and 
disconnecting with timeout_source?


For my second question about changing the timeout period, I
don't find any information that helps me to know how to do this.
Any suggestions.

Damon Register



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]