/**
@file log_appender.c
@brief Data appender.
*/

/********************************************************************************************
Multi-Inlcude-Prevent Section
********************************************************************************************/

#ifndef _APPENDER_H_
#define _APPENDER_H_
/********************************************************************************************
Include File Section
********************************************************************************************/

#include "log_priority.h"
#include "log_event.h"
#include "log_filter.h"
#include "log_simplefilter.h"
#include "log_layout.h"
#include "log_simplelayout.h"
#include "log_bufferappender.h"
/********************************************************************************************
Macro Definition Section
********************************************************************************************/
#define SIMPLE_ADDENDER                  "simpleappender"


typedef struct append Appender;

#define MK_APPENDER(szname, filterq, slayout, brequiresLayout, fcdoappend) \
Appender xAppender = \
{\
	.name = (uint8_t *)(szname),\
	.FilterList = &(filterq),\
	.layout = &(slayout),\
	.requiresLayout = (brequiresLayout),\
	._doappend = (fcdoappend),\
	.open = ucAppenderOpen,\
	.reopen = ucAppenderReopen,\
	.close = vAppenderClose,\
	.doappend = vAppenderDoappend,\
	.setLayout = vAppenderSetLayout,\
	.setFilter = vAppenderSetFilter,\
	.getName = pxAppenderGetName,\
};
/********************************************************************************************
Structure Type Declaration Section
********************************************************************************************/
struct append
{
    /*attribute*/
    const uint8_t *name;
    FilterQueue	*FilterList;
    Layout	*layout;        /*pointer to base type*/
    uint8_t requiresLayout;

    /*function*/
    uint8_t (* open)(Appender *appender);
    uint8_t (* reopen)(Appender *appender);
    void (* close)(Appender *appender);
    void (* doappend)(Appender *appender, LoggingEvent *event);
    void (* setLayout)(Appender *appender, Layout *layout);
    const uint8_t *(* getName)(Appender *appender);
    void (* setFilter)(Appender *appender, Filter *filter);

    /*virtual*/
    boolean (* _doappend)(const uint8_t *log, Value priority,const uint8_t *logname);
};

/********************************************************************************************
Prototype Declaration Section                                   
********************************************************************************************/
uint8_t ucBufferAppenderAppend(const uint8_t *logstr, Value priority,const uint8_t *logname);
uint8_t ucAppenderOpen(Appender *appender);
uint8_t ucAppenderReopen(Appender *appender);
void vAppenderClose(Appender *appender);
void vAppenderDoappend(Appender *appender, LoggingEvent *event);
void vAppenderSetLayout(Appender *appender, Layout *layout);
void vAppenderSetFilter(Appender *appender, Filter *filter);
const uint8_t *pxAppenderGetName(Appender *appender);
extern Appender xAppender;

#endif


