/* 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_IP_GENERIC_HPP
#define NMM_IP_GENERIC_HPP NMM_IP_GENERIC_HPP

#include "nmm/nmm_prefix.hpp"

#include "IIPControlImpl.hpp"

#include "visibility.hpp"

namespace NMM {

  class Sock;

  /** Generic implementation of IIPControl.
   *
   * This class provides a generic implementation of the IIPControl
   * interface for classes which use a Sock object for representing a socket.
   * If the socket is not represented by a Sock object, this implementation can not be used,
   * and the class must provide its own implementation of IIPControl.
   *
   * @see IIPControl, TCPGeneric, UDPGeneric, Sock
   */
  class DLLEXPORT IPGeneric
    : virtual public IIPControlImpl
  {
  public:
    /** Default constructor.
     * This constructor sets the default values for QoS tags.
     */
    IPGeneric();

    /** @name Socket Access
     */
    //@{
    /** Get the socket object.
     * This method returns a reference to the socket object which represents the socket.
     * It must be implemented in the subclass which actually owns the socket object.
     *
     * @return Reference to socket
     */
    virtual Sock& getSocket() = 0;

    /** Get the socket object.
     * This method returns a reference to the socket object which represents the socket.
     * It must be implemented in the subclass which actually owns the socket object.
     *
     * @return Reference to socket
     */
    virtual const Sock& getSocket() const = 0;
    //@}

    /** @name IIPControl Interface
     */
    //@{
    /** Set the size of the receive buffer.
     *
     * This method sets the size of the internal receive buffer of the socket.
     * This is the maximum amount of data that is queued at the socket after it is received
     * and before it is read.
     *
     * If new data is received, and there is not enough space in the buffer,
     * this data will be lost or delayed, depending on the used protocol.
     *
     * This option corresponds to the SO_RCVBUF socket option on Linux.
     *
     * @param buffer_size Size of the receive buffer in bytes.
     */
    virtual void setRecvBufferSize(const nmm_int32& buffer_size);

    /** Get the size of the receive buffer.
     *
     * This method gets the size of the internal receive buffer of the socket.
     * This is the maximum amount of data that is queued at the socket after it is received
     * and before it is read.
     *
     * If new data is received, and there is not enough space in the buffer,
     * this data will be lost or delayed, depending on the used protocol.
     *
     * This option corresponds to the SO_RCVBUF socket option on Linux.
     *
     * @return Size of the receive buffer in bytes.
     */
    virtual  nmm_int32 getRecvBufferSize() const;

    /** Set the size of the send buffer.
     *
     * This method sets the size of the internal send buffer of the socket.
     * This is the maximum amount of data that is queued at the socket after it was written
     * and before it is sent.
     *
     * If data is written to the socket, and there is not enough space in the buffer,
     * the write operation will block.
     *
     * This option corresponds to the SO_SNDBUF socket option on Linux.
     *
     * @param buffer_size Size of the send buffer in bytes.
     */
    virtual void setSendBufferSize(const nmm_int32& buffer_size);

    /** Get the size of the send buffer.
     *
     * This method gets the size of the internal send buffer of the socket.
     * This is the maximum amount of data that is queued at the socket after it was written
     * and before it is sent.
     *
     * If data is written to the socket, and there is not enough space in the buffer,
     * the write operation will block.
     *
     * This option corresponds to the SO_SNDBUF socket option on Linux.
     *
     * @return Size of the send buffer in bytes.
     */
    virtual  nmm_int32 getSendBufferSize() const;

    /** This method sets the priority of the data.
     *
     * This option corresponds to the SO_PRIORITY socket option on Linux.
     * It sets the priority of the data and the type-of-service (ToS) field for outgoing IP packets.
     *
     * @deprecated This method is obsolete and should not be used for setting the ToS field
     * @note Not implemented on some platforms
     *
     * @param priority The priority
     */
    virtual void setPriority(const nmm_int32& priority);

    /** This method gets the priority of the data.
     *
     * This option corresponds to the SO_PRIORITY socket option on Linux.
     * It sets the priority of the data and the type-of-service (ToS) field for outgoing IP packets.
     *
     * @deprecated This method is obsolete and should not be used for setting the ToS field
     * @note Not implemented on some platforms
     *
     * @return The priority
     */
    virtual nmm_int32 getPriority() const;

    /** Set the quality-of-service (QoS) tag for instream messages.
     * This method sets the quality-of-service (QoS) tag for instream messages.
     * The default value is STREAMING_DATA.
     *
     * @param qos_tag Quality-of-service (QoS) tag
     */
    void setInstreamBufferPriority(const Sock::QOS_TAG& qos_tag) { __instream_buffer = qos_tag; }

    /** Set the quality-of-service (QoS) tag for instream events.
     * This method sets the quality-of-service (QoS) tag for instream events.
     * The default value is INBAND_DATA.
     *
     * @param qos_tag Quality-of-service (QoS) tag
     */
    void setInstreamEventPriority(const Sock::QOS_TAG& qos_tag)  { __instream_event = qos_tag; }

    /** Set the quality-of-service (QoS) tag for out-of-band events.
     * This method sets the quality-of-service (QoS) tag for out-of-band events.
     * The default value is RMI_DATA.
     *
     * @param qos_tag Quality-of-service (QoS) tag
     */
    void setOutOfBandEventPriority(const Sock::QOS_TAG& qos_tag) { __out_of_band_event = qos_tag; }

    /** Get the quality-of-service (QoS) tag for instream messages.
     * This method gets the quality-of-service (QoS) tag for instream messages.
     * The default value is STREAMING_DATA.
     *
     * @return Quality-of-service (QoS) tag
     */
    Sock::QOS_TAG getInstreamBufferPriority() { return __instream_buffer; }

    /** Get the quality-of-service (QoS) tag for instream events.
     * This method gets the quality-of-service (QoS) tag for instream events.
     * The default value is INBAND_DATA.
     *
     * @return Quality-of-service (QoS) tag
     */
    Sock::QOS_TAG getInstreamEventPriority()  { return __instream_event; }

    /** Get the quality-of-service (QoS) tag for out-of-band events.
     * This method gets the quality-of-service (QoS) tag for out-of-band events.
     * The default value is RMI_DATA.
     *
     * @return Quality-of-service (QoS) tag
     */
    Sock::QOS_TAG getOutOfBandEventPriority() { return __out_of_band_event; }

    /** Set the global quality-of-service (QoS) tag for instream messages.
     * This method gets the quality-of-service (QoS) tag for instream messages.
     * The default value is DEFAULT, which means that no QoS tags are set.
     *
     * @param qos_tag Quality-of-service (QoS) tag
     */
    static void setGlobalInstreamBufferPriority(const Sock::QOS_TAG& qos_tag) { __global_instream_buffer = qos_tag; }

    /** Set the global quality-of-service (QoS) tag for instream events.
     * This method gets the quality-of-service (QoS) tag for instream events.
     * The default value is DEFAULT, which means that no QoS tags are set.
     *
     * @param qos_tag Quality-of-service (QoS) tag
     */
    static void setGlobalInstreamEventPriority(const Sock::QOS_TAG& qos_tag)  { __global_instream_event = qos_tag; }

    /** Set the global quality-of-service (QoS) tag for out-of-band events.
     * This method gets the quality-of-service (QoS) tag for out-of-band events.
     * The default value is DEFAULT, which means that no QoS tags are set.
     *
     * @param qos_tag Quality-of-service (QoS) tag
     */
    static void setGlobalOutOfBandPriority(const Sock::QOS_TAG& qos_tag)      { __global_out_of_band_event = qos_tag; }
    //@}
  private:
    static Sock::QOS_TAG __global_out_of_band_event; ///< Global quality-of-service (QoS) tag for instream messages
    static Sock::QOS_TAG __global_instream_event;    ///< Global quality-of-service (QoS) tag for instream events
    static Sock::QOS_TAG __global_instream_buffer;   ///< Global quality-of-service (QoS) tag for out-of-band events

    Sock::QOS_TAG __out_of_band_event;  ///< Quality-of-service (QoS) tag for instream messages
    Sock::QOS_TAG __instream_event;     ///< Quality-of-service (QoS) tag for instream events
    Sock::QOS_TAG __instream_buffer;    ///< Quality-of-service (QoS) tag for out-of-band events
  };

}
#include "nmm/nmm_suffix.hpp"

#endif
