Hello Tony
> Hi all,
> I found a timer class in the coil library and am interested to use it for my
> components in timing my outputs.
> I have looked through the website and information I have, but still couldn't
> really figure out how to declare a listener function and use it with the
> timer class.
> I was wondering if any of you can point me in the right direction or give me
> a simple example?
>
> Thanks heaps in advance.
> Tony
See the following simple example.
You can add a listener object of a class which inherits ListenerBase
pure-virtual class -> (1).
And you can also add any kind of listener objects by using template
function -> (2)
#include
#include
#include
#include
class MyListener
: public ListenerBase
{
public:
virtual void invoke()
{
std::cout << "Hello" << std::endl;
}
};
class MyClass
{
public:
void hoge()
{
std::cout << "HOGE" << std::endl;
}
};
int main(void)
{
coil::TimeValue timerinterval(0, 10000);
coil::Timer timer(timerinterval); // Timer interval is 0.01sec
MyListener listener;
MyClass myobj;
coil::TimeValue interval(1, 0);
timer.registerListener(&listener, interval); // (1) listener is
ListenerBase's subclass
timer.registerListenerObj(&myobj, &MyClass::hoge, interval/10); //
(2) any kind class member function can be added by this template
function
timer.start();
while (1) ;
}
Then, you will get
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
HOGE
Hello
HOGE
HOGE
Best Regards,
Noriaki Ando
Hi all, I found a timer class in the coil library and am interested to use it for my components in timing my outputs. I have looked through the website and information I have, but still couldn't really figure out how to declare a listener function and use it with the timer class.
I was wondering if any of you can point me in the right direction or give me a simple example? Thanks heaps in advance. Tony