/* Blinker
   Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org>
   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
   a blinkenarea.org project */

#ifndef BLINKER_CANVAS_H
#define BLINKER_CANVAS_H

#include <list>
#include <string>

#include <BlinkenLib/BlinkenFrame.h>

#include "Directory.h"
#include "File.h"
#include "Format.h"
#include "FormatFile.h"
#include "ListTracker.h"
#include "Mgrs.h"
#include "Module.h"
#include "OutStreamFile.h"

namespace Blinker {

/// a canvas to merge and split streams
class Canvas: public Module
{
protected:
  /// input to canvas
  class Input;

  /// input list tracker
  typedef ListTracker<Canvas, Input, Directory> InListTracker;

public:
  /**
   * @brief constructor
   * @param[in] name module name
   * @param[in] mgrs managers
   * @param[in] dirBase base directory
   */
  Canvas(const std::string &name, Mgrs &mgrs, const Directory &dirBase);

  /// virtual destructor
  virtual ~Canvas();

private:
  /// copy constructor disabled
  Canvas(const Canvas &that);

  /// assignment operator disabled
  const Canvas & operator=(const Canvas &that);

public:
  /// check for update of configuration
  virtual void updateConfig();

protected:
  /// (re-)create canvas
  void createCanvas();

  /// tear down canvas
  void destroyCanvas();

  /// notfication to redraw (called by inputs)
  void redraw();

  /// send current frame to output stream
  void sendFrame();

protected:
  FormatFile     m_fileFormat;     ///< canvas format file
  OutStreamFile  m_fileOutStream;  ///< output stream name file
  stBlinkenFrame *m_pCanvas;       ///< canvas to put streams on
  bool           m_canvasHasFrame; ///< if there is >= 1 frame on canvas
  InListTracker  m_inListTracker;  ///< input list tracker
}; // class Canvas

} // namespace Blinker

#endif // #ifndef BLINKER_CANVAS_H

