/* 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_DVBSIMULATORNODE_HPP
#define NMM_DVBSIMULATORNODE_HPP NMM_DVBSIMULATORNODE_HPP

#include "nmm/nmm_prefix.hpp"

#include <fstream>

#include "nmm/plugins/interfaces/IFileHandlerImpl.hpp"
#include "IDVBSimulatorImpl.hpp"
#include "nmm/plugins/video/tv/interfaces/IChannelInfoImpl.hpp"
#include "nmm/multimedia/GenericSourceNode.hpp"
#include "nmm/utils/time/TimedElement.hpp"

namespace NMM {

  /**
   * DVBSimulatorNode 
   */
  class DVBSimulatorNode :
    public GenericSourceNode,
    public IFileHandlerImpl,
    public IDVBSimulatorImpl,
    public IChannelInfoImpl
  {
  private:
    string          file_name;
    ifstream        file_stream;
    ThreadMutex     file_name_mutex;
    
    bool            send_event;
    size_t          frame_size;
    
    Time old_ts;
    Time old_pt;
    bool have_to_sleep;
    TimedElement te;

    int channel;
  protected:
    virtual Result doInit();
    virtual Result doActivate();
    virtual Result doInitOutput();
    virtual Result doDeinitOutput();
    
    // IFileHandler interface
    virtual void setFilename(const string& name);
    
    // ITVCard interface
    virtual void setDevice(const string& device) throw(const DeviceNotFoundException&) /* limited(INode::CONSTRUCTED) */;
    virtual string getDevice() const;
    virtual void setResolution(const nmm_int32& x, const nmm_int32& y) /* limited(INode::CONSTRUCTED) */ /* limited(INode::INITIALIZED) */;
    virtual void getResolution(nmm_int32& x, nmm_int32& y);
    virtual Result setChannel(const nmm_int32& channel) /* limited(INode::INITIALIZED) */ /* limited(INode::ACTIVATED) */ /* limited(INode::STARTED) */ /* limited(INode::OUTPUT_INITIALIZED) */;
    virtual Result getChannel(nmm_int32& c1, string& c2);

    // IDVBSimulator interface
    virtual void setWorkingDirectory(const string& dir) /* limited(INode::CONSTRUCTED) */;

    virtual Message *processBuffer(Buffer *);
    
    //IChannelInfo interface
    virtual Result hasChannel(nmm_int32& , const string& ){return FAILURE;}
    virtual TVChannelList getChannelList();
    virtual void setChannelConfigFile(const string &filename);

  public:
    DVBSimulatorNode(const char* name = "DVBSimulatorNode",
                     StreamQueue::Mode = StreamQueue::MODE_SUSPEND,
                     int = StreamQueue::DEFAULT_SIZE);
    
    virtual ~DVBSimulatorNode();
  private:
    TVChannelList channels;
    string channelConfigFile;
  };
  
}

#include "nmm/nmm_suffix.hpp"

#endif //NMM_DVBSIMULATORNODE_HPP

