/** \file
 *
 *  Contains the DataWriter class definition.
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 *
 */

#ifndef DATAWRITER_H_
#define DATAWRITER_H_

#include "data/DataAccessor.h"
#include "data/DataValue.h"
#include "utils/Timestamp.h"

class Unit;
class UniversalDataElement;
template < typename T > class FlexArray;

/**
 *  A DataAccessor that writes values to the Slate
 *  via its associated DataElement.
 *
 *  \ingroup data
 */
class DataWriter : public DataAccessor
{
public:

    DataWriter( Component* owner,
                DataElement& element,
                UniversalDataElement* universal,
                Logger::TimePrecisionType timePrecisionType );
    virtual ~DataWriter();

    //===============================================================
    ///
    bool setUnavailable( bool unavailable = true );
    bool isUnavailable(); // Normally called on a reader, but can also be called on a writer
    bool setInvalid( bool invalid = true );
    bool isInvalid();
    void registerChange( void );

    /**
     *  Sets the Component's DataValue, with an optional timestamp
     *  - Meets reqiurement \ref req_timing_timeStamp
     */
    virtual bool write( const Unit& unit, const unsigned char value, const Timestamp& timestamp = Timestamp::NOT_SET_TIME );
    virtual bool write( const Unit& unit, const double value, const Timestamp& timestamp = Timestamp::NOT_SET_TIME );
    virtual bool write( const Unit& unit, const int value, const Timestamp& timestamp = Timestamp::NOT_SET_TIME );
    virtual bool write( const DataValue& value, const Timestamp& timestamp = Timestamp::NOT_SET_TIME );

    /**
     * Virtual interface methods for messeging DataWriters.
     */
    virtual void setChannelName( const Str& channel );

    virtual const Str& getChannelName( void ) const;

    /**
     * Returns the Timestamp of the last write
     * - Meets requirement \ref req_timing_lastUpdate
     */
    const Timestamp& getTimestamp();

    /// Returns true if one of the readers registered with this
    /// writer's dataElement is requesting data
    bool isDataRequested();

    /// Returns true if there is a non-failed "implementor" reader of this writer
    bool isImplemented();

    void componentRequestData( bool requestingData )
    {
        componentRequestingData_ = requestingData;
    }

protected:
    bool componentRequestingData_;

};

#endif /*DATAWRITER_H_*/
