#ifndef n_nspImageSource_H
#define n_nspImageSource_H

/*
 *
 * nucleo/image/source/nspImageSource.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/core/TimeKeeper.H>
#include <nucleo/image/source/ImageSource.H>
#include <nucleo/core/URL.H>
#include <nucleo/network/http/HttpMessage.H>
#include <nucleo/image/encoding/Conversion.H>

namespace nucleo {

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

  class nspImageSource : public ImageSource {

  private:

    unsigned int _quality ;
    Image::Encoding _encoding ;

    std::string _filename ;
    int _fd ;
    HttpMessage _msg ;

    int _nbImages ;
    unsigned long _deltat ;
    TimeKeeper *_tk ;
    bool _syncFromData ;

    enum {CLOSED, OPEN, READY} _state ;

  protected:

    void react(Observable*) ;

  public:

    nspImageSource(Image::Encoding e, const URL &url) ;
    ~nspImageSource(void) { stop() ; }

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

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

}

#endif
