/* 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_ID_NODE_HPP
#define NMM_ID_NODE_HPP NMM_ID_NODE_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/multimedia/GenericFilterNode.hpp"

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

#include "visibility_IdNode.hpp"

namespace NMM {
  
  /** IdNode is a Node which performs the identity function.
   *
   * IdNode is a Node which performs the identity function, i.e.
   * passes on any buffers unaltered. Its only use is for
   * statistical purposes.
   */
  class IdNode
    : public GenericFilterNode,
      public IBufferCounterImpl,
      public ISleepImpl,
      public IBuffersPassedEventReceiverImpl
  {
  private:
    unsigned int sleep_time;  ///< if set simulates processing time 
    long buffers_passed;      ///< buffers received
    long upstream_passed;     ///< buffers received in following node
    
  protected:
    /** Set the sleep time.
     * 
     * Set the time the node will wait after receiving a buffer, in seconds.
     *
     * @param value Time to sleep.
     */
    virtual void setSleepTime(const nmm_int32& value);

    /** Returns the sleep time.
     * 
     * Get the time the node will wait after receiving a buffer, in seconds.
     *
     * @return Time to sleep.
     */
    virtual nmm_int32 getSleepTime() const;
    
    /** 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();
    
    /** 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);

    /** Returns 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;

    /** Resets number of buffers processed below.
     */
    virtual void resetUpstreamBufferCounter();
    
    /** The doInit method from Node.
     * 
     * Sets input property.
     *
     * @return SUCCESS
     */
    virtual Result doInit();
    
    /** The doInitOutput method from Node.
     * 
     * Sets working input property.
     *
     * @return SUCCESS
     */
    virtual Result doInitOutput();
    
    /** The processBuffer method from Node.
     *
     * Processes incoming buffers and forward them to next buffer.
     *
     * @param in_buffer incoming buffer
     * @return pointer to processed 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)
     */
    IdNode(const char* name = "IdNode",
           const StreamQueue::Mode queue_mode = StreamQueue::DEFAULT_MODE,
           const int size = StreamQueue::DEFAULT_SIZE);

    /** Destructor.
     */
    virtual ~IdNode() {};
  };
}

#include "nmm/nmm_suffix.hpp"

#endif
