/* 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_ETHERPIX_H
#define BLINKER_ETHERPIX_H

#include <string>

#include <BlinkenLib/BlinkenFrame.h>

#include "Directory.h"
#include "File.h"
#include "InStreamFile.h"
#include "Mgrs.h"
#include "Module.h"
#include "Size.h"
#include "StreamRecv.h"
#include "Time.h"
#include "TimeCallee.h"

namespace Blinker {

/// EtherPix output module
class EtherPix: public Module, public StreamRecv, public TimeCallee
{
public:
  /**
   * @brief constructor
   * @param[in] name module name
   * @param[in] mgrs managers
   * @param[in] dirBase base directory
   */
  EtherPix(const std::string &name, Mgrs &mgrs, const Directory &dirBase);

  /// virtual destructor
  virtual ~EtherPix();

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

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

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

  /**
   * @brief set current frame
   * @param[in] stream stream name
   * @param[in] pFrame current frame (NULL for none)
   */
  virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame);

  /// callback when requested time reached
  virtual void timeCall();

protected:
  /// (re-)create EtherPix display
  void createDisplay();

  /// destroy EtherPix display
  void destroyDisplay();

  /**
   * @brief display frame on EtherPix
   * @param[in] pFrame frame to display (or NULL)
   */
  void displayFrame(stBlinkenFrame *pFrame);

  /// (re-)send frame to EtherPix
  void sendFrame();

protected:
  InStreamFile         m_fileInStream; ///< input stream name file
  File                 m_fileConfig;   ///< EtherPix config file
  struct etp_display_s *m_pDisplay;    ///< EtherPix display
  Size                 m_size;         ///< size of EtherPix display
}; // class EtherPix

} // namespace Blinker

#endif // #ifndef BLINKER_ETHERPIX_H

