Program Listing for File Leadline.hpp

Return to documentation for file (src/mimir/algorithm/Leadline.hpp)

#pragma once

#include <atomic>
#include <chrono>
#include <cinttypes>
#include <memory>

#include <boost/statechart/detail/memory.hpp>
#include <boost/statechart/fifo_scheduler.hpp>
#include <boost/statechart/event_base.hpp>

#include <yaml-cpp/yaml.h>

#ifdef _MSC_VER
#pragma warning(push, 0)
#endif
#include <dds/pub/Publisher.hpp>
#include <dds/sub/Subscriber.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include <mimir/IAlgorithm.hpp>

namespace mimir
{
  namespace algorithm
  {

    class Leadline : public IAlgorithm
    {
    public:
      explicit Leadline(
          const YAML::Node& config,
          boost::statechart::fifo_scheduler<>& scheduler,
          boost::statechart::fifo_scheduler<>::processor_handle machine,
          dds::pub::Publisher publisher,
          dds::sub::Subscriber subscriber);
      virtual ~Leadline();
      virtual void solve(const std::atomic<bool>& cancel_token);
      virtual void initialize(const std::atomic<bool>& cancel_token);
      virtual void timer(const std::atomic<bool>& cancel_token);
      virtual inline const char* name() { return "Leadline"; }
      void event(boost::statechart::event_base * const event);

    private:
      inline void step_time() { m_next_step += m_time_step; m_now += m_time_step; }
      Leadline() = delete;
      class Impl;
      std::unique_ptr<Impl> m_impl;
      boost::statechart::fifo_scheduler<> & m_scheduler;
      boost::statechart::fifo_scheduler<>::processor_handle m_stateMachine;
      const std::chrono::milliseconds m_time_step;
      std::chrono::steady_clock::time_point m_next_step;
      std::chrono::system_clock::time_point m_now;
      const YAML::Node m_config;
    };

  }
}