/*******************************************************************************
 * (c) Copyright 2015 Microsemi Corporation.  All rights reserved.
 *
 *
 *
 * SVN $Revision: $
 * SVN $Date: $
 */

//VR#error
// Looks suspicious - is this file ok to include?

#ifndef SYSLOG_H_
#define SYSLOG_H_

#include "stdint.h"
#include "egl_log.h"

#define MAX_SYS_LOG_MSG_SIZE	(256)

typedef enum sysLogSeverityEnum {
        SL_EMERGENCY		= 0,
        SL_ALERT		= 1,
        SL_CRITICAL		= 2,
        SL_ERROR		= 3,
        SL_WARNING		= 4,
        SL_NOTICE		= 5,
        SL_INFORMATION	= 6,
        SL_DEBUG		= 7
} sysLogSeverity_t;

typedef struct syslogQMsg_s {
        sysLogSeverity_t severity;
        char msg[MAX_SYS_LOG_MSG_SIZE];
} syslogQMsg_t;

#ifdef CPP
	extern "C" {
#endif

/*
 * @brief	Initialises the
 *
 * @param[i]	taskPriority - the priority to run the syslog task
 *
 * This will launch the syslog task which can be used to send syslog
 * messages to any registered syslog servers. The messages it sent to
 * all registered servers. sysLogAddServer() and sysLogRemoveServer()
 * can be use to add or remove servers to the list. sendSysLog() can
 * be used to send a message string to the syslog task which will
 * send it via UDP to all registered servers.
 * It is safe to call this more than once. Only one syslog service
 * will be run. it will however reset the logging level back to the
 * default level.
 */
void initSysLog(uint8_t taskPriority);

/*
 * @brief	Changes the logging level for this module
 *
 * @param[i]	logLevel - The lowest level severity to log
 *
 * This function is used to change the lowest level severity to log for
 * this module. Values of eLOG_LEVEL_DEBUG (lowest) to eLOG_LEVEL_ERROR
 * can be selected. Levels with greater severity than eLOG_LEVEL_ERROR
 * will default to eLOG_LEVEL_ERROR since severity of eLOG_LEVEL_ERROR
 * and higher are non maskable.
 */
void setSysLogLogLevel(log_level_t logLevel);

/*
 * @brief	Sends a message string to all registered syslog servers
 *
 * @param[i]	severity - the syslog severity of the message
 * @param[i]	sysMsg - A formatted string, uses printf formating
 * @param[i]	... - the parameters, if any, for the formatted string
 *
 * return	0 if successful, 1 if message fails to send (queue full)
 *
 * This sends a string message with the specified severity to
 * all of the syslog server on the syslog recipients list.
 * The Facility number is fixed at 16 ('local0'), the supplied
 * severity number is encoded with the facility number.
 * The servers are identified by their IPv4 address and UDP
 * is used to deliver the message.
 * sysLogAddServer() and sysLogRemoveServer() can be use
 * to add or remove servers to the list.
 */
int sendSysLog(sysLogSeverity_t severity, char *sysMsg, ...);

/*
 * @brief Adds a syslog server to the list of recipients
 *
 * @param[in] ipAddrV4 - The IpV4 address of the server to be added
 *
 * Returns 0 if successful, 1 of recipient list full, -n if an error.
 *
 * This function adds a syslog server to the list of recipients
 * of the syslog service. The servers IPv4 address must be
 * provided as a uint32_t encoded value.
 * use IP4_ADDR_TO_UINT32_T(ipaddr, a,b,c,d) to encode the IPv4 address.
 * e.g. to encode 192.168.1.234:
 *  	uint32_t ipaddr;
 * 		IP4_ADDR_TO_UINT32_T(ipaddr, 192,168,1,234);
 */
int sysLogAddServer(uint32_t ipAddrV4);

/*
 * @brief Removes a syslog server from the list of recipients
 *
 * @param[in] ipAddrV4 - The IpV4 address of the server to be removed
 *
 * Returns 0 if successful, -n if an error.
 *
 * This function removes a syslog server from the list of recipients
 * of the syslog service. The servers IPv4 address must be
 * provided as a uint32_t encoded value.
 * use IP4_ADDR_TO_UINT32_T(ipaddr, a,b,c,d) to encode the IPv4 address.
 * e.g. to encode 192.168.1.234:
 *  	uint32_t ipaddr;
 * 		IP4_ADDR_TO_UINT32_T(ipaddr, 192,168,1,234);
 */
int sysLogRemoveServer(uint32_t ipAddrV4);

#ifdef CPP
	}
#endif
#endif /* SYSLOG_H_ */
