/* 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 <iostream>
#include <stdlib.h>
#include <string>
#include <string.h>

#include "Directory.h"
#include "File.h"
#include "InSyncFile.h"
#include "Mgrs.h"
#include "Module.h"
#include "SyncPrinter.h"
#include "SyncRecv.h"

namespace Blinker {

/**
 * @brief constructor
 * @param[in] name module name
 * @param[in] mgrs managers
 * @param[in] dirBase base directory
 */
SyncPrinter::SyncPrinter(const std::string &name, Mgrs &mgrs,
                 const Directory &dirBase):
  Module(name, mgrs, dirBase),
  m_fileInSync(dirBase.getFile("insync"), mgrs.m_syncMgr)
{
  // set up
  m_fileInSync.setSyncRecv(this);
}

/// virtual destructor
SyncPrinter::~SyncPrinter()
{
  // clean up
  m_fileInSync.setSyncRecv(NULL);
}

/// check for update of configuration
void SyncPrinter::updateConfig()
{
  // input sync stream name file was modified -> re-get input sync stream
  if (m_fileInSync.checkModified())
    m_fileInSync.update();
}

/**
 * @brief send synchronization information
 * @param[in] sync sync stream name
 * @param[in] pInfo synchronization information
 */
void SyncPrinter::sendInfo(const std::string &sync, Info &info)
{
  std::cout << "sync pause=" << (info.pause ? "true" : "false") <<
               " name=\"" << info.name << "\"" <<
               " pos=" << info.pos.toFloatSec() << "s" <<
               std::endl;
  (void)sync; // unused
}

} // namespace Blinker

