/* 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_RAWNODE_HPP
#define NMM_RAWNODE_HPP NMM_RAWNODE_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/multimedia/GenericSourceNode.hpp"

#include "IBuffersPassedEventReceiverImpl.hpp"
#include "IBufferCounterImpl.hpp"

#include "nmm/plugins/interfaces/IBufferSizeImpl.hpp"
#include "visibility_RawNode.hpp"

namespace NMM {

  /** RawNode is a Node which creates a raw stream of Buffers.
   *
   * RawNode is a Node which creates a raw stream of Buffers
   * with random or undetermined content. Its only use is for
   * statistical purposes.
   */
  class RawNode 
    : public GenericSourceNode,
      public IBuffersPassedEventReceiverImpl,
      public IBufferCounterImpl,
      public IBufferSizeImpl
  {
  private:
    long buffers_passed;  ///< buffers received
    long upstream_passed; ///< buffers received in following nodes.
    size_t buffer_size;   ///< size of buffers currently generated
    
  protected:
    /** Returns number of buffers processed.
     * 
     * Returns the current value of the buffer counter.
     *
     * @return Number of buffers processed.
     */
    virtual nmm_int32 getBuffersPassed() const;

    /** Resets the buffer counter.
     * 
     * Resets the buffer counter to zero buffers processed.
     */
    virtual void resetBufferCounter();
    
    /**
     *  @brief Sets buffer size to use.
     *  
     *  @param value Buffer size to be used.
     *
     *  Sets buffer size to be used by the node.
     */
    virtual void setBufferSize(const nmm_int32& value);

    /**
     *  @brief Requests buffer size node is currently using.
     *  
     *  @return Buffer size used by node.
     */
    virtual nmm_int32 getBufferSize();
    
    /**
     * Receive number of buffers processed recently.
     * This is an upstream event. The value is the number of buffers processed since the last event.
     *
     * @param buffers Number of buffers processed recently.
     */
    virtual Result buffersPassed(const nmm_int32& buffers);

    /**
     * Get number of buffers processed below.
     * Returns the number of buffers processed below in the graph, according to the upstream events
     * we received.
     *
     * @return Number of buffers processed below.
     */
    virtual nmm_int32 getUpstreamBuffersPassed() const;

    /**
     * Reset number of buffers processed below.
     */
    virtual void resetUpstreamBufferCounter();
    
    /** The doInit method from Node.
     *
     * Sets output property.
     *
     * @return SUCCESS
     */
    virtual Result doInit();

    /** The doInitOutput method from Node.
     *
     * Sets working output property.
     *
     * @return SUCCESS
     */
    virtual Result doInitOutput();
    
    /** The processBuffer method from GenericNode.
     *
     * Generates buffers with random or undetermined content.
     *
     * @param in_buffer pointer to incoming buffer (always NULL for this node)
     * @return pointer to created buffer
     */
    virtual Message *processBuffer(Buffer* in_buffer);
    
  public:  
    /** Node constructor.
     *
     * @param name Node name
     * @param queue_mode Stream queue mode
     * @param size Stream queue size (in buffers)
     */
    RawNode(const char* name = "RawNode",
	    StreamQueue::Mode queue_mode = StreamQueue::MODE_SUSPEND,
	    int size = StreamQueue::DEFAULT_SIZE);

    /** Destructor
     */
    virtual ~RawNode() {};
  };
}

#include "nmm/nmm_suffix.hpp"

#endif //NMM_RAWNODE_HPP
