#ifndef CLUSTER_UPDATER_HH
# define CLUSTER_UPDATER_HH

# include "utils/FactoryDeclare.hh"
# include "Device.hh"

/** @brief Updater development helper
 *
 * This class is an abstract implementation of a dummyUpdater oriented to
 * the TaskIF connection.
 *
 * @param DevIF A device interface
 * @param Data data type used to store data provided by DevIF
 *
 * @author Frederic Py <fpy@mbari.org>
 */
template<class DevIF, class Data> 
class AbstractUpdater :public dummyUpdater {
public:
  typedef DevIF device_type;
  typedef Data data_type;

  bool ready() const {
    return m_updated && isDataReady(m_data);
  }

  data_type const &data() const {
    return m_data;
  }

  void operator()(device_type &dev) {
    m_updated = dev.connected() && update(dev, m_data);
  }

protected:
  AbstractUpdater()
    :m_updated(false) {}
  virtual ~AbstractUpdater() {}

  virtual bool isDataReady(data_type const &d) const=0;
  virtual bool update(device_type &dev, data_type &data) =0;
  virtual void initDB(ValDB &db, data_type const &data) =0;
    
private:
  bool m_updated;
  data_type m_data;
  
  void fillDB(ValDB &db) {
    initDB(db, m_data);
  }
}; // AbstractUpdater<>

/** @brief Device declaration
 *
 * @pre Updater a device updater
 *
 * This class is base on FactoryDeclare and helps coder to
 * declare that trhe program can create a new device based on Updater
 * and associates this entry to a symlbolic type name. This information
 * will be then publicly available form DevicesManager class
 */
template<class Updater>
class DevDeclare
  :public FactoryDeclare<Device<Updater>, AbstractDevice, std::pair<Symbol, ArgList const *> > {
public:
  DevDeclare(Symbol const &type)
    :FactoryDeclare<Device<Updater>, AbstractDevice, std::pair<Symbol, ArgList const *> >(type) {}
  ~DevDeclare() {}

}; // DevDeclare<>

#endif // CLUSTER_UPDATER_HH
