Overview
Features
Download
Documentation
Community
Add-Ons & Services

AbstractTimerCallback invoke not getting called

A general discussion forum.

AbstractTimerCallback invoke not getting called

Postby nitingiganetics » 29 Jul 2009, 13:23

Here is the code which has some issues, I get a call in the clone() method but the invoke never gets called.

Header has -

class QSearchInterruptCallback : public Poco::AbstractTimerCallback
{
virtual void invoke(Timer& timer) const;
virtual AbstractTimerCallback* clone() const;
};

Implementation has -

void QSearchInterruptCallback::invoke( Timer& timer ) const
{
printf("Calling POM_query_interrupt.\n");

if( called_interrupt() )
{
printf("Interrupting POM Query FAILED!!!\n");
}

printf("Interrupted current POM Query SUCCESSFULLY!!!\n");
}

AbstractTimerCallback* QSearchInterruptCallback::clone() const
{
printf("Calling QSearchInterruptCallback::clone()\n");
return new QSearchInterruptCallback( *this );
}

void interrupt()
{
printf("Calling interrupt()\n");
QSearchInterruptCallback interruptCallback;

Timer newTimer( 500, 0 );
newTimer.start( interruptCallback, Thread::PRIO_HIGH );
printf("Timer's start Interval is set to: %d\n", newTimer.getStartInterval());
}

Here is the output -
Calling interrupt()
Calling QSearchInterruptCallback::clone()
Timer's start Interval is set to: 5

Note: There is no output from invoke()

Please suggest what I am missing that is causing invoke not to be called.
nitingiganetics
 
Posts: 3
Joined: 29 Jul 2009, 13:15

Re: AbstractTimerCallback invoke not getting called

Postby guenter » 29 Jul 2009, 14:58

Your Timer object is destroyed when you leave the interrupt() function, so your callback will never be called.
guenter
 
Posts: 1112
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: AbstractTimerCallback invoke not getting called

Postby nitingiganetics » 03 Aug 2009, 10:53

Thanks for your input.
I have made this pointer global now, still the same result -

QSearchInterruptCallback* interruptCallback;

void interruptQuery( size_t miliSecs )
{
interruptCallback = new QSearchInterruptCallback();
printf("Calling interruptQuery()\n");
Timer newTimer( miliSecs, 0 );
newTimer.start( *interruptCallback, Thread::PRIO_HIGH );
printf("Timer's start Interval is set to: %d\n", newTimer.getStartInterval());
}

Still the Timer doesn't get called. Tried with changing the pointer to the global object, with same results!

From the tests I have done it seems that the cloned object is getting destructed causing the call to fail. Here is the output.

Calling interruptQuery()
Calling QSearchInterruptCallback::clone()
Timer's start Interval is set to: 500
Destructing the QSearchInterruptCallback.
..
.. //some error messages and printfs

Destructing the QSearchInterruptCallback. ....//This shows up right before the program exits.
nitingiganetics
 
Posts: 3
Joined: 29 Jul 2009, 13:15

Re: AbstractTimerCallback invoke not getting called

Postby guenter » 03 Aug 2009, 14:08

Your Poco::Timer object is still allocated on the stack and gets destroyed when you exit interruptQuery(), long before the timer would fire the first time.
guenter
 
Posts: 1112
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: AbstractTimerCallback invoke not getting called

Postby nitingiganetics » 03 Aug 2009, 14:41

Thanks. It works now.
My bad!
I had tried making QSearchInterruptCallback global prior to posting this but never looked at the Timer object!!
Silly one, huh!!!
Thanks Again for your help
nitingiganetics
 
Posts: 3
Joined: 29 Jul 2009, 13:15


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron