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

#ifndef MOSTRECENTLOGWRITER_H_
#define MOSTRECENTLOGWRITER_H_

#include "DecimationLogWriter.h"

class DataAccess;

/// Only writes a the most recent value when flush() or writeFooter() is called.
///
/// \ingroup logging
class MostRecentLogWriter : public DecimationLogWriter
{
public:

    /// Constructor
    MostRecentLogWriter( LogWriter& outputTo );

    /// Destructor
    virtual ~MostRecentLogWriter();

    /// Write the log header, if any
    virtual unsigned int writeHeader();

    /// Write the given LogEntry - should lock the writeMutex_
    virtual unsigned int write( const LogEntry* entry, const Unit* unit = NULL );

    /// Do what needs to be done at the end of the cycle.
    virtual void endCycle();

    /// Write the log footer, if any
    virtual unsigned int writeFooter();

    /// Flush data to output if any
    virtual unsigned int flush()
    {
        return writeFooter();
    }

private:
    // Note that the copy constructor below is private and not given a body.
    // Any attempt to call it will return a compiler error.
    MostRecentLogWriter( const MostRecentLogWriter& old ); // disallow copy constructor
    void wipe();

    Mutex MostRecentLogWriterMutex_;
    Timestamp timestamp_;
    const Unit* unit_;
    LogEntry::Type type_;

    // If type == DATA_LOG_ENTRY
    DataAccess* dataAccess_;
    DataValue* dataValue_;
    bool best_;

    // If type == SYSLOG_LOG_ENTRY
    Str message_;
    Syslog::Severity severity_;
    const CodedStr* loggerFacility_;




};

#endif /*MOSTRECENTLOGWRITER_H_*/
