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

#include "File.h"
#include "OutStreamFile.h"
#include "Stream.h"
#include "StreamFile.h"
#include "StreamMgr.h"

namespace Blinker {

/**
 * @brief constructor from path
 * @param[in] path path to file
 * @param[in] streamMgr stream manager
 */
OutStreamFile::OutStreamFile(const std::string &path, StreamMgr &streamMgr):
  StreamFile(path, streamMgr)
{
  update();
}

/**
 * @brief constructor from basic file
 * @param[in] file basic file object
 * @param[in] streamMgr stream manager
 */
OutStreamFile::OutStreamFile(const File &file, StreamMgr &streamMgr):
  StreamFile(file, streamMgr)
{
  update();
}

/// destructor
OutStreamFile::~OutStreamFile()
{
  setFrame(NULL); // set empty frame (stream is ending)
  // unreferencing stream happens in destructor of StreamFile
}

/**
 * @brief assignment operator
 * @param[in] file basic file object
 */
const OutStreamFile & OutStreamFile::operator=(const File &file)
{
  setFrame(NULL); // set empty frame (stream is ending)
  StreamFile::operator=(file);
  return *this;
}

/// update, i.e. (re-)read file and reference new stream
void OutStreamFile::update()
{
  setFrame(NULL); // set empty frame (stream is ending)
  StreamFile::update();
}

/**
 * @brief set current frame
 * @param[in] pFrame current frame (NULL for none)
 */
void OutStreamFile::setFrame(stBlinkenFrame *pFrame)
{
  if (m_pStream)
    m_pStream->setFrame(pFrame);
}

} // namespace Blinker

