#ifndef __Timer_h__
#define __Timer_h__

#include "EPoll.h"
#include "Socket.h"

namespace core
{

  ///
  /// Timer
  ///
  /// Set and trigger callback upon specified timeout.
  ///
  /// The Timer is used to establish a timer using the timer socket
  /// interface. It cannot be instantiated directly but must be extended.
  ///

  class Timer : Socket
  {

  public:
      Timer(EPoll &ePoll);
    Timer(EPoll &ePoll, double delay);
    ~Timer();

    ///
    /// Use the setTimer() method to set the time out value for timer. Setting the timer
    /// also starts the timer countdown. The clearTimer() method can be used to reset
    /// the timer without triggering the onTimeout() callback.
    ///
    /// @param delay the amount of time in seconds to wait before trigering the onTimeout function.
    ///

    void setTimer(double delay);

    ///
    /// Use the clearTimer() to unset the timer and return the timer to an idle state.
    ///

    void clearTimer();

    ///
    /// Use the getElapsed() method to obtain the amount of time that has elapsed since
    /// the timer was set.
    ///

    double getElapsed();

    double getEpoch();

  protected:
    ///
    /// This method is called when the time out occurs.
    ///

    virtual void onTimeout() = 0;

  private:
    void onDataReceived(std::string data) override;
    double delayValue;
  };

}

#endif
