/* 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_TS_ADDRESS_HPP
#define NMM_TS_ADDRESS_HPP NMM_TS_ADDRESS_HPP

#include "nmm/nmm_prefix.hpp"

#include "TSDescription.hpp"
#include "NMMReference.hpp"

#include "visibility.hpp"

namespace NMM {
  
  /** Transport strategy address.
   *
   * This abstract superclass specifies an address wich can be used to
   * connect a TransportStrategy with a corresponding partner. It
   * stores the NMMReference of the object that should be connected.
   * A concrete implementation of this class adds the
   * TransportStrategy specific parameter, like an IP-address and a
   * port which is needed for a tcp connection. It also stores the
   * binding type which specifies if the corresponding
   * TransportStrategy is a local, a system or a network binding. A
   * TransportStrategy can support all binding types.
   */
  class DLLEXPORT TSAddress : public SerializedValue {
  public:
    enum BindingType { LOCAL = 1, SYSTEM = 2, NETWORK = 4};
    
    /** @name Constructor & Destructor
     */
    //@{
    /** Default Constructor.
     * @param reference NMMReference of the object that should be connected
     * @param strategy_type type of TransportStrategy
     * @param t_info TypeInfo of this TSAddress
     * @param binding_type BindingType of this TSAddress
     */
    TSAddress(const NMMReference& reference = 0, const std::string& strategy_type = "",
              const TypeInfo& t_info = TypeInfo("TSAddress", "NMM"), int binding_type = 0);
    
    /** Copy Constructor.
     *
     * @param address TSAddress to copy
     */
    TSAddress(const TSAddress& address);

    /** Virtual Copy Constructor.
     *
     * @return pointer to copy of this TSAddress
     */
    TSAddress* copy() const;
    //@}
    
    /** @name Access information
     */
    //@{
    /** This method sets the NMMReference to reference.
     *
     * @param reference NMMReference to set
     */
    void                 setNMMReference(const NMMReference& reference)       { __reference.setValue(reference); }

    /** This method returns the current NMMReference.
     *
     * @return reference to NMMReference of this TSAddress
     */
    const NMMReference&  getNMMReference()                              const { return __reference.getRValue(); }

    /** This method returns the type name of the TransportStrategy.
     *
     * @return type name of the TransportStrategy
     */
    const std::string&        getStrategyType()                         const { return __ts_desc.getStrategyType(); }

    /** This method tests if the given binding type is supported by the TransportStrategy.
     *
     * @param binding_type BindingType to check
     * @return true if given BindingType is supported by the TransportStrategy, false otherwise
     */
    bool isBindingType(const BindingType& binding_type)                 const { return ((__binding_type.getRValue() & binding_type) != 0); }
    
    /** This method returns the binding types of this address.
     *
     * @return binding types of this address
     */
    int  getBindingType()                                               const { return __binding_type.getRValue(); }
    
    /** This method returns the host name.
     *
     * @return hostname
     */
    virtual const std::string& getHostname()                            const { return __host_name.getRValue(); }
    
    /** This method sets the host name.
     *
     * @param hostname host name
     */
    virtual void setHostname(const std::string& hostname)                     { __host_name.setValue(hostname); }

    /** This method returns the port.
     *
     * @return port
     */
    virtual int  getPort()                                              const { return __port.getRValue(); }
    
    /** This method sets the port.
     *
     * @param port port to set
     */
    virtual void setPort(int port)                                            { __port.setValue(port);}
    
    /** This method returns the interfaces supported by the %TransportStrategy.
     *
     * @return interfaces supported by the %TransportStrategy
     */
    unsigned int getStrategyInterfaces()                                const { return __ts_desc.getInterfaces(); }
    
    /** This method sets the interfaces supported by the %TransportStrategy.
     *
     * @param interfaces interfaces supported by the %TransportStrategy
     */
    void         setStrategyInterfaces(unsigned int interfaces)               { __ts_desc.setInterfaces(interfaces); }
  
    /** This method returns the capabilities of the %TransportStrategy.
     *
     * @return capabilities of the %TransportStrategy
     */
    unsigned int getStrategyCapabilities()                              const { return __ts_desc.getCapabilities(); }
    
    /** This method sets the capabilities of the %TransportStrategy.
     *
     * @param capabilities capabilities of the %TransportStrategy
     */
    void         setStrategyCapabilities(unsigned int capabilities)           { __ts_desc.setCapabilities(capabilities); }

    /** This method returns the full description of the %TransportStrategy.
     *
     * @return full description of the %TransportStrategy
     */
    const TSDescription& getTSDescription()                             const { return __ts_desc; }
    
    /** This method sets the full description of the %TransportStrategy.
     *
     * @param ts_desc full description of the %TransportStrategy
     */
    void         setTSDescription(const TSDescription& ts_desc)               { __ts_desc = ts_desc; }
    //@}
    
  protected:
    /** This method sets BindingType.
     *
     * @param binding_type BindingType to set
     */
    void setBindingType(int binding_type)                                     { __binding_type = binding_type; }
    
  private:
    /** Register attributes for serialization/deserialization.
     */
    void registerAttributes();
    
  private:
    TValue<NMMReference> __reference;               ///< stores the NMMReference
    TSDescription        __ts_desc;                 ///< stores the description of the %TransportStrategy
    TValue<nmm_int32>          __binding_type;            ///< stores the supported binding types
    TValue<std::string>  __host_name;               ///< stores the host name
    TValue<nmm_int32>          __port;                    ///< stores the port
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
