#ifndef LCMSLATEWRITER_H
#define LCMSLATEWRITER_H

#include <map>
#include "auv-shared/messaging/DataVectorsMgr.h"
#include "data/DataWriter.h"
#include "component/Component.h"

/**
   Aggregates data within encapsulated LCM DataVectors message, publishes
   the DataVectors message to LCM and writes the data to the LRAUV slate.

   Usage:

   1. Specify data names, units, and types with add() methods
   2. Fill in data values with setValue() methods
   3. Publish data to LCM and write to slate with publish()
 */
class LcmSlateWriter : public DataVectorsMgr
{

public:

    LcmSlateWriter( Component *component, bool enableLcm );

    virtual ~LcmSlateWriter();


    /// Add float scalar item with name and units specified by DataURI
    bool add( const DataURI *uri );

    /// Add Universal scalar item with name and units specified by UniversalURI
    bool add( const UniversalURI *uri, const float accuracy,
              const Unit *accuracyUnit,
              Logger::TimePrecisionType timePrecision );

    /// Time-stamp encapsulated data with epochMillisec, write to encapsulated
    /// slate DataWriters. If LCM is enabled, then increment message sequence
    /// number and publish data to LCM on the specified channel.
    virtual void publish( const char *channelName, lcm::LCM *lcm,
                          int64_t epochMillisec );


    /// Return true if data requested from any encapsulated slate items, else
    /// false.
    bool isDataRequested();

    /// Set all DataWriters valid/invalid
    void setWritersValid( bool valid );

    /// Set DataWriter with specified dataName as valid/invalid; returns true
    /// if dataName is found, else false.
    bool setWriterValid( const char *dataName, bool valid );

    /// Return true if writer with specified name is marked valid, else false. Set nameFound true if
    /// if specified name is found else false.
    bool isValid( const char *dataName, bool *nameFound );

protected:

    /// Return pointer to DataWriter having the specified name
    DataWriter *getDataWriter( const char *name );

    /// Map of data writers corresponding to each vector (or scalar)
    /// in encapsulated DataVectors object
    std::map<const char *, DataWriter *> dataWriters_;

    Component *component_;

    bool lcmEnabled_;
    bool debug_;

    char buf_[128];
};

#endif
