/* 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_WAVWRITENODE_HPP
#define NMM_WAVWRITENODE_HPP NMM_WAVWRITENODE_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/multimedia/GenericSinkNode.hpp"

#include "nmm/plugins/file/interfaces/ISinkFileHandlerImpl.hpp"
#include "nmm/multimedia/interfaces/ITrackImpl.hpp"

#include <fstream>

namespace NMM {

  class WavWriteNode :
    public GenericSinkNode,
    public ISinkFileHandlerImpl,
    public ITrackImpl
  {
    private:
      enum localstates { START, DATA };
      localstates state;

      ofstream out_fstream; /* File object */
      long int bytes_receive;
      string filename;
      bool ready;

      string file_extension;
      string working_directory;
      bool override_default_filename;

      //! misc functions 
      long int getBuffers();
      bool isReady();

    protected:
      virtual Result doInit();
      virtual Result doActivate();
      virtual Result doStop();

      virtual Message* processBuffer(Buffer *in_buffer);

      // ITrack interface
      virtual Result started(const Interval& overall_time);
      virtual Result startTrack(const string& filename);
      virtual Result endTrack();
      virtual Result finished();

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

      // ISinkFileHandler interface
      virtual void setWorkingDirectory(const string& directory);
      virtual string getWorkingDirectory();
      virtual void setFileExtension(const string& extension);
      virtual string getFileExtension();

      // IFileHandler interface
      virtual void setFilename(const string& filename);
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
