RE: SigC++ callback question



I have used a simple sigc++ timeout and I can confirm that it is called once.
Maybe your code somewhere/somehow calls 10 times the "timeoutObj = Glib::signal_timeout().connect(tslot,CHECK_INTERVAL);" command

also something that I can't understand: why do you use the for loop in
checkNewDay()?


Date: Mon, 13 Jul 2009 03:21:35 +0300
Subject: SigC++ callback question
From: vlzoltan gmail com
To: gtkmm-list gnome org

Hello!

I'm working on a plugin for a smaller application using gtkmm. The plugin I'm working on checks certain conditions (the date had changed and a new day started) after every minute and starts some actions if the conditions are true. In the initialization part of the plugin I have the following piece of code that uses Glib::SignalTimeout and sigc++:
        testCounter = 0;
        sigc::slot<bool> tslot = sigc::mem_fun(*this, &NoteOfDayFactory::checkNewDay);
        timeoutObj = Glib::signal_timeout().connect(tslot,CHECK_INTERVAL);

where testCounter is an attribute defined in the class that contains the initialization method and CHECK_INTERVAL is a constant equal to 1 minute. All the other variables present are defined in the class that contains the initialization code and the callback method.
The checkNewDay method is where the condition is tested and action taken if the day had changed:
    bool NoteOfDayFactory::checkNewDay() {
        std::cout << "Checking for new day every minute or so" << std::endl;
        std::cout << "Before incrementing" << std::endl;
        for(int i = 0; i < 100000; i++);
        counter++;
        std::cout << counter << " minutes elapsed" << std::endl;
        return true;
    }

I put the small test code, presented above, before I used the real action, to test if everything goes well and the checkNewDay isn't called more than once every minute.
What I found puzzle me. After every minute elapses I get a number of let say 10 messages (at least) printed on the stdout but the variable increases only once every minute.
**** snip ****
Checking for new day every minute or so
Before incrementing
1 minutes elapsed
Checking for new day every minute or so
Before incrementing
1minutes elapsed
**** snip ****
Checking for new day every minute or so
Before incrementing
2 minutes elapsed
Checking for new day every minute or so
Before incrementing
2 minutes elapsed
**** snip ****

It behaves like the text was sent to 10 (or so) different buffers and printed out at once after every minute. Could somebody enlighten me and satisfy my curiosity why is this happening, because I'm pretty sure that the callback is called only once every minute. Thank you!

Cheers!

--
Lege, lege, relege, ora, labora et invenies.


Μοιραστείτε τις αναμνήσεις σας μέσω Internet με τους φίλους σας με τους φίλους σας.


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