/* 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_DEV_NULL_NODE_HPP
#define NMM_DEV_NULL_NODE_HPP NMM_DEV_NULL_NODE_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/multimedia/GenericSinkNode.hpp"

#include "IBufferCounterImpl.hpp"
#include "ISleepImpl.hpp"
#include "IBuffersPassedEventSenderImpl.hpp"
#include "visibility_DevNullNode.hpp"

namespace NMM {

  /** DevNullNode is a Node which consumes any Buffers passed to it.
   *
   * Its only use is for statistical purposes.
   */
  class DevNullNode
    : public GenericSinkNode,
      public IBufferCounterImpl,
      public ISleepImpl,
      public IBuffersPassedEventSenderImpl
  {
  private:
    unsigned int sleep_time; ///< used to simulate a blocking device
    long buffers_passed;     ///< buffers received
    long upstream_passed;    ///< buffers received since last interval reset
    long interval;           ///< after this number of buffers send buffersPassed event upstream
    
  protected:
    /** Sets the sleep time.
     * 
     * Sets 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.
     *
     * Returns 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();
    
    /** Sets buffer count interval.
     * 
     * Sets the number of buffers after which to send the upstream event.
     * Setting it to zero disables sending the event. Buffers processed while the interval is zero
     * are not counted in upstream events.
     *
     * @param value Buffer count interval.
     */
    virtual void setBufferCountInterval(const nmm_int32& value);

    /** Returns buffer count interval.
     *  
     * Gets the number of buffers after which to send the upstream event.
     * Zero means no upstream events are sent.
     *
     * @return buffer count interval.
     */
    virtual nmm_int32 getBufferCountInterval() const;
    
    /** The doInit method from Node.
     *
     * Sets input property.
     *
     * @return SUCCESS
     */
    virtual Result doInit();

    /** The doInitOutput property from Node.
     *
     * Sets working input property.
     *
     * @return SUCCESS
     */
    virtual Result doInitOutput();
    
    /** The processBuffer method from GenericNode.
     * 
     * Processes incoming buffers.
     *
     * @param in_buffer pointer to incoming buffer
     * @return pointer to processed buffer (always NULL for this node)
     */
    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)
     */
    DevNullNode(const char* name = "DevNullNode",
		const StreamQueue::Mode queue_mode = StreamQueue::DEFAULT_MODE,
		const int size = StreamQueue::DEFAULT_SIZE);

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

#include "nmm/nmm_suffix.hpp"

#endif
