/* 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_IInstreamCompositeStrategy_HPP
#define NMM_IInstreamCompositeStrategy_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/Interface.hpp"
#include "nmm/comm/messaging/Event.hpp"
#include "nmm/comm/messaging/IllegalStateException.hpp"
#include <memory>

#include "ICompositeStrategy.hpp"

#include "visibility.hpp"

namespace NMM
{
  /** Instream composite transport strategy.  
   *
   * This is an interface for the %InstreamCompositeStrategy. 
   * It provides access to child transport strategies and the 
   * multiplexer/demultiplexer unit. 
   * It also defines internal configuration events.
   */

  class DLLEXPORT IInstreamCompositeStrategy : virtual public ICompositeStrategy { 
  public:    /** Transport roles.
     */
//@{

  enum TransportRole { 
    RECEIVE_ONE_WAY_BUFFER = 1 , ///< Receive one-way %Buffer

    RECEIVE_ONE_WAY_CEVENT = 2 , ///< Receive one-way %CEvent

    SEND_ONE_WAY_BUFFER = 4 , ///< Send one-way %Buffer

    SEND_ONE_WAY_CEVENT = 8 ///< Send one-way %CEvent
 };
//@}
    /** @name Debugging and Benchmarking
     */
//@{
    /** Message multiplexing and demultiplexing strategies.
     */

  enum MuxDemuxStrategy { 
    SIMPLE_MUX_DEMUX = 0 , ///< Strategy for exactly one sub-binding.

    RELIABLE_RELIABLE_MUX_DEMUX = 1 , ///< Strategy for reliable event and buffer sub-bindings.

    RELIABLE_UNRELIABLE_MUX_DEMUX = 2 , ///< Strategy for a reliable event sub-binding and an unreliable buffer sub-binding.

    RELIABLE_MULTIMEDIA_MUX_DEMUX = 3 ///< Strategy for a reliable event sub-binding and a buffer sub-binding which does not preserve headers.
 };

    IInstreamCompositeStrategy() : NMM::Interface(IInstreamCompositeStrategy::IInstreamCompositeStrategy_type, "NMM") { };

    IInstreamCompositeStrategy(NMM::NMMObject& parent) : NMM::Interface (parent, IInstreamCompositeStrategy::IInstreamCompositeStrategy_type, "NMM") { };

    virtual ~IInstreamCompositeStrategy() {};

    static const char* IInstreamCompositeStrategy_type;

    virtual  string getInterfaceType() const { return IInstreamCompositeStrategy_type; }

    NMM::Interface* copy() const { return new IInstreamCompositeStrategy(*this); }
    static void used(); 
    static const char* getOneWayBufferReceiverStrategy_event;
    static const char* getOneWayCEventReceiverStrategy_event;
    static const char* getOneWayBufferSenderStrategy_event;
    static const char* getOneWayCEventSenderStrategy_event;
    static const char* notifyEventReceived_event;
    static NMM::Event* create_notifyEventReceived(const nmm_int32& stream_counter);
    static const char* setInstreamMuxStrategy_event;
    static const char* setInstreamDemuxStrategy_event;
    static const char* setBufferLossInterval_event;
    /** Returns child strategy for receiving one-way Buffers.
     *
     * @return Interface to child strategy for receiving one-way Buffers.
     */

    virtual ITransportStrategy* getOneWayBufferReceiverStrategy() const
      throw(const NMM::SerializedException&);
    /** Returns child strategy for receiving one-way CEvents.
     *
     * @return Interface to child strategy for receiving one-way CEvents.
     */

    virtual ITransportStrategy* getOneWayCEventReceiverStrategy() const
      throw(const NMM::SerializedException&);
    /** Returns child strategy for sending one-way Buffers.
     *
     * @return Interface to child strategy for sending one-way Buffers.
     */

    virtual ITransportStrategy* getOneWayBufferSenderStrategy() const
      throw(const NMM::SerializedException&);
    /** Returns child strategy for sending one-way CEvents.
     *
     * @return Interface to child strategy for sending one-way CEvents.
     */

    virtual ITransportStrategy* getOneWayCEventSenderStrategy() const
      throw(const NMM::SerializedException&);
  /* instream (protected) and non-instream (public) */        /** @name Internal Events
     */
//@{
    /** Event acknowledgement.  This event is sent reliably to the
     * partner strategy that sent an instream event. It is used for
     * synchronization of a reliable event sub-binding and an
     * unreliable buffer sub-binding which doesn't preserve message
     * headers.
     *
     * @param stream_counter Sequence number of the event
     */

    virtual void notifyEventReceived(const nmm_int32& stream_counter) /* in-stream */ 
      throw(const NMM::SerializedException&);
  /* non-instream (public) */        /** Sets message multiplexing strategy.  
     *
     * This method sets the strategy for multiplexing messages 
     * from sub-bindings. Normally, the strategy is chosen automatically 
     * after the composite strategy has been configured. 
     * This method should only be used for debuggung and benchmark purposes.
     *
     * @param strategy Multiplexing strategy
     */

    virtual void setInstreamMuxStrategy(const IInstreamCompositeStrategy::MuxDemuxStrategy& strategy)
      throw(const NMM::SerializedException&);
    /** Sets message demultiplexing strategy.  
     *
     * This method sets the strategy for demultiplexing messages from
     * sub-bindings. Normally, the strategy is chosen automatically
     * after the composite strategy has been configured. This method
     * should only be used for debuggung and benchmark purposes.
     *
     * @param strategy Demultiplexing strategy
     */

    virtual void setInstreamDemuxStrategy(const IInstreamCompositeStrategy::MuxDemuxStrategy& strategy)
      throw(const NMM::SerializedException&);
    /** Sets interval for data loss simulation.  
     *
     * This method sets the interval for simulating data loss. 
     * If the interval is not 0, it specifies the interval of buffers 
     * that should be dropped to simulate an unreliable buffer sub-binding. 
     * Only use this method for debugging and benchmark purposes.
     * 
     * @param loss_interval set interval to drop Buffers
     */

    virtual void setBufferLossInterval(const nmm_uint32& loss_interval)
      throw(const NMM::SerializedException&);

//@}

  };

  typedef auto_ptr<IInstreamCompositeStrategy> IInstreamCompositeStrategy_var;

  DLLEXPORT NMM::OValueStream& operator<<(NMM::OValueStream& ov, const IInstreamCompositeStrategy::TransportRole& t);
  DLLEXPORT NMM::IValueStream& operator>>(NMM::IValueStream& iv, IInstreamCompositeStrategy::TransportRole& t);
  DLLEXPORT NMM::OValueStream& operator<<(NMM::OValueStream& ov, const IInstreamCompositeStrategy::MuxDemuxStrategy& t);
  DLLEXPORT NMM::IValueStream& operator>>(NMM::IValueStream& iv, IInstreamCompositeStrategy::MuxDemuxStrategy& t);



}

#include "nmm/nmm_suffix.hpp"

#endif
