/*
 * LogAssociation.h
 *
 *  Created on: May 6, 2013
 *      Author: godin
 */

#ifndef LOGASSOCIATION_H_
#define LOGASSOCIATION_H_

#include "logger/Logger.h"
#include "utils/FlexArray.h"

class LogEntry;
class LogWriter;
class Rule;

/// Handles one mapping between a set of log entry criteria and an LogWriter
class LogAssociation
{
public:

    /// Constructor
    LogAssociation( LogWriter *writerIn, Rule *ruleIn );

    /// Destructor
    ~LogAssociation();

    /// Reset cached input settings associated with LogWriter
    void resetInputs();

    bool matchAndProcess( LogEntry *entry );

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

    /// Configure logWriter
    void configLogWriter( Logger& sysLogger );

    /// Call logWriter::writeFooter
    void writeFooter();

    Rule* getRule() const
    {
        return rule_;
    }

    LogWriter* getWriter() const
    {
        return writer_;
    }

    void setWriter( LogWriter* writer )
    {
        writer_ = writer;
    }

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

    //LogWriter
    LogWriter *writer_;
    Rule *rule_;
    bool wroteInCycle_;

};

/// Stores all of the associations as a list
class LoggerAssociationDeque : public FlexArray<LogAssociation *>
{
public:
    /// Constructor
    LoggerAssociationDeque();
    /// Destructor
    ~LoggerAssociationDeque();

    /// Add a new association to the deque
    LogAssociation* add( LogWriter *writerIn, Rule *ruleIn );
    void add( LogAssociation *association );
    void remove( LogWriter *writerOut );
};

#endif /* LOGASSOCIATION_H_ */
