/* 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_IConnectionManagerImpl_HPP
#define NMM_IConnectionManagerImpl_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/NMMObject.hpp"
#include "IConnectionManager.hpp"

#include "ITransportStrategyImpl.hpp"

#include "visibility.hpp"

namespace NMM
{
  /** Connection Manager interface.
   *
   *  Connection managers are used to initiate and configure a new connection using an existing
   *  reliable connection.
   */

  class DLLEXPORT IConnectionManagerImpl  : public virtual NMM::NMMObject { 
  public:
    IConnectionManagerImpl() { addInterface(new IConnectionManager(*this)); registerEvents(); };

    virtual ~IConnectionManagerImpl() {};

  protected:
    /** Handles a connection request from a remote host.
     *
     *  This method checks if a %ConnectorAcceptor object exists for the requested transport strategy type
     *  and forwards the request to this Connector.
     *  
     *  @param remote_addr Fully specified address of the remote transport strategy
     *  @param local_addr Returns the fully specified address of the local transport strategy
     *  @exception BindingException if no %ConnectorAcceptor was found or the %ConenctorAcceptor throws a BindingException
     */

    virtual void handleConnect(const TSAddress* remote_addr, TSAddress*& local_addr) const 
      throw(const BindingException&) = 0;
    /**  Sends event to partner object reliably.
     *
     *  This method is used to reliably send a configuration event to a partner object via the %ConnectionManager.
     *  The connection manager pretends that the event was sent via the transport strategy.
     *
     *  @param ts_reference NMM reference of transport strategy which should receive the event
     *  @param e The event
     *  @return The result of the event
     */

    virtual Result sendReliableEvent(const NMMReference& ts_reference, Event& e) const 
      throw(const BindingException&) = 0;
    /** Sends event to partner strategy reliably.
     *
     *  This method is used to reliably send a configuration event to a partner strategy via the %ConnectionManager.
     *
     *  @param receiver NMM Reference of transport strategy which should receive the event
     *  @param e The event
     *  @return The result of the event
     */

    virtual Result sendReliableConfigEvent(const NMMReference& receiver, Event& e) const 
      throw(const BindingException&) = 0;
    /** Sends instream message to partner object reliably. 
     *
     *  This method is used to reliably send an instream to a partner object via the ConnectionManager.
     *  The connection manager pretends that the message was sent via the transport strategy.
     *
     *  This method is only for debugging and should not be used.
     *  
     *  @param receiver NMM Reference of transport strategy which should receive the event
     *  @param message The message
     *  @return The result of the event
     */

    virtual Result sendReliableInstreamMessage(const NMMReference& receiver, CEvent& message) const 
      throw(const BindingException&) = 0;
    /** Returns strategies that support format.
     *
     *  This method returns the list of transport strategies that support the given format.
     *
     *  @param format Format to check
     *  @return List of transport strategies that support the format
     */

    virtual list<TSDescription >  getSupportedStrategies(const Format& format) const = 0;


  private:
    void registerEvents();
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
