/* 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_OPPRINTER_H
#define BLINKER_OPPRINTER_H

#include <set>
#include <string>

#include "Directory.h"
#include "File.h"
#include "Mgrs.h"
#include "Module.h"
#include "OpConn.h"
#include "OpConnIf.h"
#include "OpReqIf.h"
#include "TimeCallee.h"

namespace Blinker {

/// a operator connection printer
class OpPrinter: public Module, public OpReqIf, public TimeCallee
{
public:
  /// type for set of open operator connections
  typedef std::set<OpConn *> OpConns;

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

  /// virtual destructor
  virtual ~OpPrinter();

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

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

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

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

  /**
   * @brief check if accepting new operator connection is possible
   * @param[in] name operator interface name
   * @return if accepting new connection is possible
   */
  virtual bool acceptNewOpConn(const std::string &name);

  /**
   * @brief new operator connection
   * @param[in] name operator interface name
   * @param[in] pConn operator connection object
   *
   * The new connection may not yet be used for sending inside this callback.
   */
  virtual void newOpConn(const std::string &name, OpConn *pConn);

  /**
   * @brief key command received on operator connection
   * @param[in] pConn operator connection object
   * @param[in] key key that was pressed
   */
  virtual void opConnRecvKey(OpConn *pConn, char key);

  /**
   * @brief play command received on operator connection
   * @param[in] pConn operator connection object
   * @param[in] sound name of sound to play
   */
  virtual void opConnRecvPlay(OpConn *pConn, const std::string &sound);

  /**
   * @brief operator connection is closed
   * @param[in] pConn operator connection object
   *
   * The connection may not be used for sending any more in this callback.
   */
  virtual void opConnClose(OpConn *pConn);

protected:
  OpConns m_opConns;  ///< open operator connections
  OpConns m_sendPlay; ///< connections to send play request on
}; // class OpPrinter

} // namespace Blinker

#endif // #ifndef BLINKER_OPPRINTER_H

