/* 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_GENERICREADNODE_HPP
#define NMM_GENERICREADNODE_HPP NMM_GENERICREADNODE_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/multimedia/GenericSourceNode.hpp"

#include "nmm/plugins/file/interfaces/ISourceFileHandlerImpl.hpp"
#include "nmm/plugins/file/interfaces/ISeekableImpl.hpp"
#include "nmm/plugins/interfaces/IProgressImpl.hpp"
#include "nmm/plugins/interfaces/IBufferSizeImpl.hpp"

#include <fstream>
#include "visibility.hpp"


namespace NMM {

  class GenericReadNode :
    public GenericSourceNode,
    public ISourceFileHandlerImpl,
    public ISeekableImpl,
    public IBufferSizeImpl,
    public IProgressImpl
  {

  private:
    bool sendEvent; //status flag whether to send an event
    bool send_format;
    bool end_track;
    bool send_progress; //status flag whether to send progress information
    string filename;
    int             buffers_before_progress;
    int             buffers_progress;

  protected:
    ifstream in_fstream;
    unsigned int buffer_size;

    // seeking & file position
    u_int64_t         filesize;
    u_int64_t         filepos;
    int64_t          seekto;

    virtual Message* processBuffer(Buffer *);
    
    virtual Result doInit();
    virtual Result doDeinit();
    virtual Result doInitOutput();
    virtual Result doDeinitOutput();
    
    // ISeekable interface
    virtual nmm_bool hasPercentSeek() const;
    virtual void seekPercent(const Rational& percent);
    virtual void seekPercentTo(const Rational& percent);
    virtual nmm_bool hasBytesSeek() const;
    virtual void seekBytes(const nmm_int64& offset);
    virtual void seekBytesTo(const nmm_uint64& bytes);
    virtual nmm_bool hasTimeSeek() const;
    virtual void seekTime(const Interval& interval);
    virtual void seekTimeTo(const Time& time);
    
    // ISourceFileHandler interface
    virtual void setFilename(const string& name);
    virtual nmm_uint64 getFilesize();
    
    // IBufferSize interface
    virtual void setBufferSize(const nmm_int32& size);
    virtual nmm_int32 getBufferSize();

    // IProgress interface
    virtual void sendProgressInformation(const nmm_bool& in);
    virtual void setProgressInterval(const nmm_int32& buffers);

  public:
   
    GenericReadNode(const char *name = "GenericReadNode",
		    StreamQueue::Mode = StreamQueue::MODE_SUSPEND,
		    int = StreamQueue::DEFAULT_SIZE);
    virtual ~GenericReadNode();

  };

}

#include "nmm/nmm_suffix.hpp"

#endif //NMM_GENERICREADNODE_HPP
