/* 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_SYNCFILE_H
#define BLINKER_SYNCFILE_H

#include "File.h"
#include "NameFile.h"
#include "Sync.h"
#include "SyncMgr.h"

namespace Blinker {

/// setting file containting a name of a sync stream
class SyncFile: public NameFile
{
public:
  /**
   * @brief constructor from path
   * @param[in] path path to file
   * @param[in] syncMgr sync stream manager
   */
  SyncFile(const std::string &path, SyncMgr &syncMgr);

  /**
   * @brief constructor from basic file
   * @param[in] file basic file object
   * @param[in] syncMgr sync stream manager
   */
  SyncFile(const File &file, SyncMgr &syncMgr);

  /// destructor
  ~SyncFile();

  /**
   * @brief assignment operator
   * @param[in] file basic file object
   */
  const SyncFile & operator=(const File &file);

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

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

public:
  /// update, i.e. (re-)read file and reference new sync stream
  void update();

protected:
  /// unreference sync stream
  void unref();

  /// reference sync stream
  void ref();

protected:
  SyncMgr &m_syncMgr; ///< sync stream manager
  Sync    *m_pSync;   ///< sync stream
}; // class SyncFile

} // namespace Blinker

#endif // #ifndef BLINKER_SYNCFILE_H

