/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_TCP_ACCEPTOR_HPP
#define NMM_TCP_ACCEPTOR_HPP NMM_TCP_ACCEPTOR_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/ObjectAcceptor.hpp"
#include "nmm/comm/NMMDefaultPort.hpp"

#include "nmm/utils/net/DispatchedNetHandler.hpp"
#include "nmm/utils/net/SockAcceptor.hpp"
#include "nmm/utils/net/INetAddr.hpp"

#include "visibility.hpp" 

namespace NMM {

  /** A TCP acceptor.
   * This class is an object acceptor which uses the Transport Control Protocol (TCP/IP).
   * It implements direct connection setup for the TCPStrategy.
   *
   * This class uses a SockAcceptor to create a listening TCP socket.
   * It is notified of incoming connections by the NetReactor through the DispatchedNetHandler interface.
   *
   * @see TCPStrategy
   */
  class DLLEXPORT TCPAcceptor : public ObjectAcceptor, public DispatchedNetHandler, protected SockAcceptor {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Create a listener on a specific port.
     * This constructor opens a listening socket on the given port.
     *
     * @param port Port to listen on
     */
    TCPAcceptor(unsigned int port = NMM::default_port);

    /** Create a listener on a port within a port range.
     * This constructor opens a listening socket on a first free port in the given port range.
     *
     * @param begin_port First port of port range
     * @param end_port Last port of port range
     */
    TCPAcceptor(unsigned int begin_port, unsigned int end_port);

    /** Virtual destructor.
     */
    virtual ~TCPAcceptor();
    //@}

    /** @name Connection
     */
    //@{
    /** Incoming data notification.
     * This method is called if the event POLLIN, POLLRDNORM, POLLRDBAND, POLLPRI occurs, which means
     * that normal or priority Data can be read.
     *
     * This method is called if there is an incoming connection request.
     * This method creates a TCPStrategy and assigns the incoming socket to it.
     *
     * @param socket The corresponding socket.
     * @return VOID by default
     */
    virtual NetResult receiveData(SocketHandle socket);
    //@}

  private:
    INetAddr addr;                      ///< The INetAddr, that is listen for new connections 
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
