/* 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_OPMGR_H
#define BLINKER_OPMGR_H

#include <map>
#include <string>

#include "OpConn.h"
#include "OpConnIf.h"
#include "OpReqIf.h"

namespace Blinker {

/// operator connection manager
class OpMgr
{
protected:
  /// map of open operator interfaces
  typedef std::map<std::string, OpReqIf *> ReqIfMap;

public:
  /// constructor
  OpMgr();

  /// destructor
  ~OpMgr();

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

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

public:
  /**
   * @brief open operator interface
   * @param[in] name operator interface name
   * @param[in] pOpReqIf interface to call on incoming operator request
   * @return if operator interface could be opened
   */
  bool open(const std::string &name, OpReqIf *pOpReqIf);

  /**
   * @brief close operator interface
   * @param[in] name operator interface name
   * @return if interface name was open before
   */
  bool close(const std::string &name);

  /**
   * @brief check if operator interface will accept new connection
   * @param[in] name operator interface to connect to
   * @return if a new connection would be accepted
   */
  bool canConnect(const std::string &name);

  /**
   * @brief connect to operator interface
   * @param[in] name operator interface to connect to
   * @param[in] pOpConnIf interface to call on connection events
   * @return operator connection object (or NULL on error)
   */
  OpConn * connect(const std::string &name, OpConnIf *pOpConnIf);

protected:
  /// map of open operator interfaces
  ReqIfMap m_reqIfs;
}; // class OpMgr

} // namespace Blinker

#endif // #ifndef BLINKER_OPMGR_H

