/*************************************************************************
*** Copyright (c) 2006, Video Surveillance,Inc.
***
*** File name  : slog.h
***
*** Module	 : Surveillance Log
***
*** Author	 : Cham Li
***
*** Version	: 1.0
***
*** Created On : 09/05/2006
***
*** Description:
***			This header file provides prototypes of APIs and other
***			common definitions for Surveillance Log.
***
*** Modification histroy:
***
**************************************************************************/



#ifndef __SLOG_H_
#define __SLOG_H_

#ifdef __cplusplus
extern "C" {
#endif



/**************************************************************************
 **					 common macros and data types					 **
 **************************************************************************/



/* log levels */

#define SLOG_LVL_FATAL	 16  /* 1<<4 */
#define SLOG_LVL_ERROR	 8   /* 1<<3 */
#define SLOG_LVL_WARNING   4   /* 1<<2 */
#define SLOG_LVL_INFO	  2   /* 1<<1 */
#define SLOG_LVL_TRACE	 1

#define SLOG_NUM_OF_LEVELS	  5
#define SLOG_FULL_LEVEL_MASK	0x1F  /* in binary: 11111 */
#define SLOG_DEFAULT_LEVEL_MASK 0x1E  /* in binary: 11110 */



/* common API return values */

#define SLOG_OK	0
#define SLOG_ERROR (-1)



/* special return value for slogInit() */
#define SLOG_ALREADY_INITED	 1

/* special return value for slogGetMask() */
#define SLOG_GET_MASK_ERR	   0xF0000000

/* input vaules for printSwitch parameter of slogInit() */
#define SLOG_PRINT_ON		   1
#define SLOG_PRINT_OFF		  0

/* special input value for mod parameter of slogSetMask() */
#define SLOG_MOD_ALL			0xFFFFFFFF



/**************************************************************************
 **								 APIs								 **
 **************************************************************************/



/* initializes Surveillance Log for the process.
 * returns SLOG_ALREADY_INITED when already initialized */
int slogInit(
	const char *remoteIp,	  /* log server IP address, NULL for not sending to remote server */
	const char *localFile,	 /* local filename (without extension), NULL for not writing to local file */
	int   printSwitch);		/* SLOG_PRINT_ON or SLOG_PRINT_OFF: whether printf() entries */



/* writes a log entry */
void slog(
	unsigned int  level,	   /* SLOG_LVL_XXX */
	unsigned int  mod,		 /* module Id defined in modules.h */
	const char   *para, ...);  /* printf-like parameters, please do not include "\n" */



/* sets print switch */
int slogSetPrint(
	int printSwitch);		  /* SLOG_PRINT_ON or SLOG_PRINT_OFF: whether printf() entries */



/* sets a new log grade for specified module(s) */
int slogSetGrade(
	unsigned int  mod,		 /* module Id defined in modules.h, SLOG_MOD_ALL for all modules */
	unsigned int  grade);	  /* 0 to SLOG_NUM_OF_LEVELS */



/* sets a new level mask for specified module(s) */
int slogSetMask(
	unsigned int  mod,		 /* module Id defined in modules.h, SLOG_MOD_ALL for all modules */
	unsigned int  levelMask); 



/* gets level mask for specified module.
 * returns SLOG_GET_MASK_ERR when error occured */
unsigned int slogGetMask(
	unsigned int  mod);		/* module Id defined in modules.h */



/* forces a flush to local log files */
void slogFlush();



/* set local log file rotation parameters */
int slogSetRot(
	unsigned int maxBackups,   /* number of backups to keep at most */
	long		 maxFileSize); /* local log file is rotated when exceeding this size */



/* shows modules, levels and other help info (commonly used at command-lines) */
void slogHelp();

//dump buffer to screen
void slogDumpBuffer(unsigned int ModID, unsigned int level, unsigned char *data, int length);

#ifdef __cplusplus
}
#endif

#endif /* __SLOG_H_ */

