/* 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_OUTOFBAND_BINDING_DESCRIPTION_HPP_
#define _NMM_OUTOFBAND_BINDING_DESCRIPTION_HPP_

#include "nmm/nmm_prefix.hpp"

#include "BindingDescription.hpp" 
#include "OutOfBandStrategyDescription.hpp" 

#include "nmm/comm/OutOfBandChannel.hpp"

#include <cassert>

#include "visibility.hpp"

namespace NMM {
 
  /** This class describes an out-of-band binding.
   * An out-of-band binding consists of a sequence of out-of-band transport strategy descriptions.
   */
  class DLLEXPORT OutOfBandBindingDescription
    : public BindingDescription
  {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Default constructor.
     * - The strategy list is empty
     */
    OutOfBandBindingDescription();
    
    /** Copy constructor.
     *
     * @param obbd OutOfBandBindingDescription to copy
     */
    OutOfBandBindingDescription(const OutOfBandBindingDescription& obbd);
    
    /** Virtual copy constructor.
     *
     * @return pointer to copy of this OutOfBandBindingDescription
     */
    virtual OutOfBandBindingDescription* copy() const { return new OutOfBandBindingDescription(*this); }
    //@}
    
    /** @name Transport Strategies
     */
    //@{
    /** Returns number of strategies.
     *
     * @return number of strategies
     */
    inline unsigned int getNumberOfTransportStrategies() const { return __strategies.size(); }
    
    /** Returns the description of the strategy with the given index.
     *
     * @param index Index of requested TransportStrategy
     * @return reference to OutOfBandStrategyDescription
     */
    inline const OutOfBandStrategyDescription& getTransportStrategy(unsigned int index) const {
      assert(index < __strategies.size());
      return *__strategies[index];
    }
    
    /** Returns the description of the strategy with the given index.
     *
     * @param index Index of requested TransportStrategy
     * @return reference to OutOfBandStrategyDescription
     */
    inline OutOfBandStrategyDescription& getTransportStrategy(unsigned int index) {
      assert(index < __strategies.size());
      return *__strategies[index];
    }
    
    /** Adds a transport strategy.
     *
     * @param strategy_type Type name of transport strategy
     * @param roles Set of roles for which the strategy is used.
     * @return number of TransportStrategies without the new one
     */
    unsigned int addTransportStrategy(const string& strategy_type, unsigned int roles);
    
    /** Adds a transport strategy which is used exclusively for the given roles.
     *
     * @param strategy_type Type name of transport strategy
     * @param roles Set of roles for which the strategy is used.
     * @return number of TransportStrategies without the new one
     */
    unsigned int addExclusiveTransportStrategy(const string& strategy_type, unsigned int roles);
    //@}
    
    /** @name Configuration Events
     */
    //@{
    /** Returns top-level configuration of the request side.
     *
     * @return top-level configuration of the request side
     */
    inline const CEvent& getRequestTopLevelConfig()   const { return __request_top_level_config; }
    
    /** Returns top-level configuration of the reply side.
     *
     * @return top-level configuration of the reply side
     */
    inline const CEvent& getReplyTopLevelConfig() const { return __reply_top_level_config; }
    
    /** Adds a top-level configuration event on the request side.
     *
     * @param event top-level configuration event to add
     */
    void addRequestTopLevelConfigEvent(const Event& event);
    
    /** Adds a top-level configuration event on the reply side.
     *
     * @param event top-level configuration event to add
     */
    void addReplyTopLevelConfigEvent(const Event& event);
    
    /** Adds a configuration event on the request side.
     *
     * This is a convenience method for adding configuration events by communication role.
     *
     * @param event Event to add to strategy configuration
     * @param role Communication role which identifies the transport strategy
     */
    void addRequestConfigEvent(const Event& event, OutOfBandChannel::CommunicationRole role);
    
    /** Adds a configuration event on the reply side.
     *
     * This is a convenience method for adding configuration events by communication role.
     *
     * @param event Event to add to strategy configuration
     * @param role Communication role which identifies the transport strategy
     */
    void addReplyConfigEvent(const Event& event, OutOfBandChannel::CommunicationRole role);
    //@}
    
    /** Checks if binding is implicit.  
     *
     * A binding is implicit if no sub-bindings and no configuration 
     * options are specified. An implicit binding is configured completely 
     * automatically.
     *
     * @return @c true iff the binding is implicit
     */
    bool isImplicit();
    
  private:
    /** Register attributes for serialization/deserialization.
     */
    void registerAttributes();
    
  private:
    SequenceValue<OutOfBandStrategyDescription> __strategies; ///< OutOfBandStrategyDescriptions of this OutOfBandBindingDescription
    CEvent __request_top_level_config;          ///< Top-level configuration of the request side
    CEvent __reply_top_level_config;            ///< Top-level configuration of the reply side
  };
}

#include "nmm/nmm_suffix.hpp"

#endif
