#ifndef n_nudpcImageSource_H
#define n_nudpcImageSource_H

/*
 *
 * nucleo/image/source/nudpcImageSource.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/core/URL.H>
#include <nucleo/network/http/HttpMessage.H>
#include <nucleo/network/tcp/TcpConnection.H>
#include <nucleo/network/udp/UdpReceiver.H>

#include <nucleo/image/encoding/Conversion.H>

namespace nucleo {

  // ------------------------------------------------------------------

  class nudpcImageSource : public ImageSource {

  private:

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

    std::string _hostname ;
    int _port ;
    std::string _request ;

    TcpConnection *_connection ;

    UdpReceiver *_udp ;
    unsigned char *_data ;
    unsigned int _dataSize ;

    enum {CLOSED, OPEN, READY} _state ;

  protected:

    void react(Observable*) ;

  public:

    nudpcImageSource(Image::Encoding encoding, const URL &url) ;
    ~nudpcImageSource() { stop() ; }

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

  } ;

  // ------------------------------------------------------------------

}

#endif
