#ifndef UPDATER_HPP
#define UPDATER_HPP

#include <cc++/thread.h>

#include "image.hpp"

#include "functor.hpp"

#include <time.h>

#include <list>
#include <string>

class TimeElement
{
public:
  TimeElement(const std::string& n, TimeFi* t, TimeFv* call_back)
    : name(n), active(true)
  {
    time_f = t;
    call_back_f = call_back;
  }
  
  TimeFi *time_f;
  TimeFv *call_back_f;
  std::string name;
  struct timeval next_time;
  bool active;
};

class Updater : public ost::Thread
{
public:
  // singleton
  static Updater& get_instance();

  void activate();
  void deactivate();

  class Timer 
  {
  public:
    void add(TimeElement te);
    void del(std::string name);

    // for individual elements
    void activate(const std::string& name);
    void deactivate(const std::string& name);
    bool status(const std::string& name);

    struct timeval current_time;
    std::list<TimeElement> elements;

    ost::Mutex elements_mut;
  };

  Timer timer;

  Overlay progressbar;
  int status_progressbar;
  int total_progressbar;
  std::string header;

private:
  Updater();

  void run();
  
  bool running;
};

#endif
