Hi Mr. Ando:<br>Thank you so much for your help. <br>Your example is very clear. <br><br>I will give it a try and ask again if I come across any problem !<br><br>Thanks<br>Tony<br><br><div class="gmail_quote">On 8 October 2010 05:22, Ando Noriaki <span dir="ltr"><<a href="mailto:n-ando@aist.go.jp">n-ando@aist.go.jp</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hello Tony<br>
<div><div></div><div class="h5"><br>
> Hi all,<br>
> I found a timer class in the coil library and am interested to use it for my<br>
> components in timing my outputs.<br>
> I have looked through the website and information I have, but still couldn't<br>
> really figure out how to declare a listener function and use it with the<br>
> timer class.<br>
> I was wondering if any of you can point me in the right direction or give me<br>
> a simple example?<br>
><br>
> Thanks heaps in advance.<br>
> Tony<br>
<br>
</div></div>See the following simple example.<br>
You can add a listener object of a class which inherits ListenerBase<br>
pure-virtual class -> (1).<br>
And you can also add any kind of listener objects by using template<br>
function -> (2)<br>
<br>
#include <iostream><br>
#include <coil/Timer.h><br>
#include <coil/Listener.h><br>
#include <coil/TimeValue.h><br>
<br>
class MyListener<br>
 : public ListenerBase<br>
{<br>
public:<br>
  virtual void invoke()<br>
  {<br>
    std::cout << "Hello" << std::endl;<br>
  }<br>
};<br>
<br>
class MyClass<br>
{<br>
public:<br>
  void hoge()<br>
  {<br>
    std::cout << "HOGE" << std::endl;<br>
  }<br>
};<br>
<br>
int main(void)<br>
{<br>
  coil::TimeValue timerinterval(0, 10000);<br>
  coil::Timer timer(timerinterval); // Timer interval is 0.01sec<br>
  MyListener listener;<br>
  MyClass myobj;<br>
<br>
  coil::TimeValue interval(1, 0);<br>
  timer.registerListener(&listener, interval); // (1) listener is<br>
ListenerBase's subclass<br>
  timer.registerListenerObj(&myobj, &MyClass::hoge, interval/10); //<br>
(2) any kind class member function can be added by this template<br>
function<br>
  timer.start();<br>
<br>
  while (1) ;<br>
<br>
}<br>
<br>
Then, you will get<br>
<br>
HOGE<br>
HOGE<br>
HOGE<br>
HOGE<br>
HOGE<br>
HOGE<br>
HOGE<br>
HOGE<br>
HOGE<br>
HOGE<br>
Hello<br>
HOGE<br>
HOGE<br>
<br>
Best Regards,<br>
Noriaki Ando<br>
<font color="#888888"><br>
<br>
<br>
<br>
<br>
<br>
--<br>
Noriaki Ando, Ph.D.<br>
    Senior Research Scientist, RT-Synthesis R.G., ISRI, AIST<br>
    AIST Tsukuba Central 2, Tsukuba, Ibaraki 305-8568 JAPAN<br>
    e-mail: <a href="mailto:n-ando@aist.go.jp">n-ando@aist.go.jp</a>, web: <a href="http://staff.aist.go.jp/n-ando" target="_blank">http://staff.aist.go.jp/n-ando</a><br>
    OpenRTM-aist: <a href="http://www.openrtm.org" target="_blank">http://www.openrtm.org</a><br>
<br>
<br>
</font></blockquote></div><br>