#ifndef __MD_CTRL_SUBSCRIBER_H_INCLUDED
#define __MD_CTRL_SUBSCRIBER_H_INCLUDED

#include <ros/ros.h>
#include <boost/thread.hpp>
#include <std_msgs/Float32.h>

namespace MD
{
   class Subscriber
   {
   public:
      /*
       *  @brief Constructor.
       *  @param[in] nh ros::NodeHandle
       *  @param[in] ros_topic topic for ros messages
       *  @param[in] subscribe_queue_size buffer size for ros messages
       *  @param[in] wait_time Time for checking to Wheel stop (1 second)
       */
      Subscriber(ros::NodeHandle & nh, const std::string & ros_topic, int subscribe_queue_size = 1, double schedule_delay = 0.05, double schedule_delay_lastest = 0.5);

      Subscriber(ros::NodeHandle & nh, XmlRpc::XmlRpcValue::iterator object);

      /**
      * @brief returns true, if publishing of a wheel topic is publishing
      * 
      */
      bool isWheelTriggered(void);

      /**
      *  @brief returns true, if not subcribe wheel
      */
      bool isWheelLastestTriggered(void);

      /**
      * @brief schedules WheelController function 
      * @param[in] schedule if true, publishing is scheduled, otherwise a possibly pending schedule is removed.
      */
      void scheduleWheelController(bool schedule);

      /*
       * @brief Destructor.
       */
      virtual ~Subscriber();

      boost::mutex m_measurement_mutex;
      int16_t speed;
      uint8_t slave_id;
      double ratio;

   protected:
      /*
       * @brief Callbacks for ros messages from wheel topic. 
       */
      virtual void wheelCallback(const std_msgs::Float32::Ptr & msg);

      ros::NodeHandle nh_;
      std::string topic_name_;
      int m_subscribe_queue_size_;
      ros::Subscriber control_wheel_sub_;  

      ros::Time publish_time_;
      ros::Time publish_lastest_time_;
      ros::Duration schedule_delay_;
      ros::Duration schedule_lastest_delay_;
      boost::mutex publish_mutex_;                  
   };
}

#endif // __MD_CTRL_SUBSCRIBER_H_INCLUDED