#pragma once
#include "../../Scheduler/SchedulerTaskHelper.h"
#include "Process.h"

/**
 * @brief Shorthand for processes which regularly need computation time. As such, they run arbitrary code once
 *        they are started (through Process::onStart()) and additional code at every recurrence
 *        (through SchedulerTaskHelper::run()).
 *        Periodic processes automatically add and remove themselves from the scheduler when they are started
 *        and when they are subsequently terminated.
 */
class PeriodicProcess : public Process,
                        public SchedulerTask,
                        public SchedulerTaskHelper
{
public:
  PeriodicProcess(const Process* parent, unsigned int priority, size_t period, size_t waitingTimeBeforeExecution)
    : Process(parent)
    , SchedulerTaskHelper(this, priority, period, waitingTimeBeforeExecution)
    , SchedulerTask(*parent)
  {
  }

protected:
  virtual void onStart()
  {
    activate();
  }
  virtual void onEnd()
  {
    deactivate();
  }
};
