#ifndef n_nudppImageSource_H
#define n_nudppImageSource_H

/*
 *
 * nucleo/image/source/nudppImageSource.H --
 *
 * Copyright (C) Nicolas Roussel
 *
 * See the file LICENSE for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include <nucleo/image/source/ImageSource.H>
#include <nucleo/image/sink/nudppImageSink.H>
#include <nucleo/core/FileKeeper.H>

namespace nucleo {

  class nudppImageSource : public ImageSource {

  private:

    int _socket ;
    FileKeeper *_skeeper ;

    Image::Encoding _source_encoding ;
    unsigned int _quality ;
    Image::Encoding _target_encoding ;


    std::string _hostOrGroup ;
    int _port, _realport ;

    nudppImageSink::FragmentInfo _info ;
    uint16_t _inum, _fnum ;
    Image _img ;
    unsigned int _bytesRead ;
    bool _newImage ;

    enum {CLOSED, OUT_OF_SYNC, SYNC} _state ;

    void _receiveFragment(void) ;

  protected:

    void react(Observable *) ;

  public:

    nudppImageSource(Image::Encoding encoding, const URL &url) ;

    ~nudppImageSource() {
	 stop() ;
    }

    bool start(void) ;
    bool isActive(void) { return (_state!=CLOSED) ; }
    bool getNextImage(Image *img) ;
    bool stop(void) ;

    // int getPort(void) { return _realport ; }

  } ;

}

#endif
