/*
 * TestTimerComponent.cpp
 *
 *  Created on: Feb 4, 2010
 *      Author: kgad
 */


#include <rtt/TaskContext.hpp>
#include <rtt/Method.hpp>
#include <rtt/TimeService.hpp>
#include <ocl/ComponentLoader.hpp>
#include <rtt/Logger.hpp>
using namespace std;
using namespace RTT;
using namespace Orocos;

namespace TestSpace
{
  class TestTimerComponent
  : public TaskContext
    {
    private:
      typedef long long ticks;
      ticks startTime;

    public:
      TestTimerComponent(const std::string & name) : startTime(0), TaskContext(name){
        this->methods()->addMethod( method( "log", &TestTimerComponent::log, this),
                                    "msg", "The message",
                                    "Log");
      }

      virtual ~TestTimerComponent(){};

      void log(std::string msg)
        {
          Logger::In In("TestTimer");
          RTT::log(Warning) << msg << endlog();
        }

      bool startHook()
      {
        startTime = TimeService::Instance()->ticksGet();
        if (this->scripting()->loadStateMachines("TimerTest.osd") == true)
          {
            if ( this->engine()->states()->getStateMachine("TimerTest")->activate() == true )
              {
                return this->engine()->states()->getStateMachine("TimerTest")->start();
              }
            return false;
          }
        return false;

      }

      void stopHook()
      {
        this->engine()->states()->getStateMachine("TimerTest")->stop();
        this->engine()->states()->getStateMachine("TimerTest")->deactivate();
      }

    };

}
ORO_CREATE_COMPONENT( TestSpace::TestTimerComponent );

