/* 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_ADDRESS_HPP
#define NMM_TCP_ADDRESS_HPP NMM_TCP_ADDRESS_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/TSAddress.hpp"

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

#include "SerializeINetAddr.hpp"

#include "visibility.hpp"

namespace NMM {

  /** Transport strategy address for TCPStrategy.
   * This is the type of address which is used by the TCPStrategy to connect to a partner strategy.
   * It can only be used for direct connection setup.
   *
   * A TCP address consists of an IP address and a port number,
   * both represented by an internet address (INetAddr).
   */
  class DLLEXPORT TCPAddress : public TSAddress {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Default constructor.
     *
     * @param nmm_reference NMM reference of partner object
     */
    TCPAddress (const NMMReference& nmm_reference = 0);

    /** Constructor.
     * This constructor creates a TCP address from a host name or IP address in string form.
     *
     * @param name Host name or string representation of an IP address
     * @param port port number
     * @param nmm_reference NMM reference of partner object
     */
    TCPAddress (const string& name, int port, const NMMReference& nmm_reference = 0);

    /** Constructor.
     * This constructor creates a TCP address from an internet address.
     *
     * @param net_addr Internet address
     * @param nmm_reference NMM reference of partner object
     */
    TCPAddress (const INetAddr& net_addr, const NMMReference& nmm_reference = 0);

    /** Copy constructor.
     *
     * @param address Object to copy from
     */
    TCPAddress (const TCPAddress& address);

    /** Virtual copy constructor.
     *
     * @return A copy of this object which has the same type
     */
    TCPAddress* copy()                          const { return new TCPAddress(*this); }
    //@}

    /** @name Attributes
     */
    //@{
    /** Set the port number.
     *
     * @param port Port number
     */
    virtual void setPort(int port);

    /** Set the IP address as a string.
     * This method sets the IP address from a host name or IP address in string form.
     *
     * @param name Host name or string representation of an IP address
     */
    virtual void setHostname(const string& name);

    /** Set the internet address.
     * This method sets the IP address and the port number as an internet address.
     */
    void setINetAddr(const INetAddr& net_addr)        { __net_addr = net_addr; }

    /** Get the internet address.
     *
     * @return The internet address
     */
    const INetAddr& getINetAddr()               const { return __net_addr.getRValue(); }

    /** Get the internet address.
     *
     * @return The internet address
     */
    INetAddr& getINetAddr()                           { return __net_addr.getRValue(); }
    //@}
  private:
    TValue<INetAddr> __net_addr;                      ///< The internet address
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
