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

#ifndef SPLITFILELOGWRITER_H_
#define SPLITFILELOGWRITER_H_

#include "FileLogWriter.h"

/**
 *  Writes LogEntries to files that are split over time or capacity
 *
 *  \ingroup logging
 */
class SplitFileLogWriter : public FileLogWriter
{
public:
    /** Constructor for manual split
     *
     * \param filebase Basename of file to write to
     * \param logWriter logWriter that provides input for file logging
     * \param fileEncoder If non-NULL, object that encodes the file after saving
     * \param nextFilenum File number to start with, defaults to zero
     */
    SplitFileLogWriter( const Str& filebase, LogWriter* logWriter, FileEncoder* fileEncoder = NULL, int nextFilenum = 0 );

    /** Constructor for capacity split
     *
     * \param filebase Basename of file to write to
     * \param capacity maximum size, in bytes, of each split file.
     * \param logWriter logWriter that provides input for file logging
     * \param fileEncoder If non-NULL, object that encodes the file after saving
     * \param nextFilenum File number to start with, defaults to zero
     */
    SplitFileLogWriter( const Str& filebase, unsigned int capacity, LogWriter* logWriter, FileEncoder* fileEncoder = NULL, int nextFilenum = 0 );

    /** Constructor for Timespan split
     *
     * \param filebase Basename of file to write to
     * \param span timespan to contain within each file split
     * \param logWriter logWriter that provides input for file logging
     * \param fileEncoder If non-NULL, object that encodes the file after saving
     * \param nextFilenum File number to start with, defaults to zero
     */
    SplitFileLogWriter( const Str& filebase, const Timespan& span, LogWriter* logWriter, FileEncoder* fileEncoder = NULL, int nextFilenum = 0 );

    /// Destructor, closes file if open.
    virtual ~SplitFileLogWriter();

    /// Write
    virtual unsigned int write( const LogEntry *entry, const Unit* unit = NULL );

    /*virtual void config( Logger& logger );*/

    /// Split the file.  Normally just closes the file, but
    /// descendant classes may do otherwise.
    virtual void split( bool andReopen = true, int nextFilenum = -1 );

    /// Change file destination.
    virtual void resetFileBase( const Str& filebase, int nextFilenum = 0 );

protected:

    /// Uses nextFilenum_ to determine the next filename
    virtual Str nextFilename( int nextFilenum = -1 );

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

    Str filebase_;

    const unsigned int capacity_;

    unsigned int nextFilenum_;

    const Timespan span_;

    Timestamp splitTime_;

};

#endif /*SPLITFILELOGWRITER_H_*/
