/* 
** 
** file name: debug.h
**
** The debug information defination.
**
*/

#ifndef DEBUG__H
#define DEBUG__H
#include "config.h"

void 
DebugMsg(void *ptr, const char *fmt, ...);
void 
DebugRet(void *ptr, const char *fmt, ...);
void
DebugMsgDelimiter();
BOOL
WriteDebugMsg(void *dest, const void *src);
#define DebugFlag(shmp) \
		DebugMsg(shmp, "%s: %s: %d", FILE_MACRO, FUNCTION_MACRO, LINE_MACRO)

#define WriteContentToDebugBuffer(shmp, buf, bcd_buf, nbytes) \
    	BcdToAscii(buf, bcd_buf, 2 * nbytes); \
    	DebugMsg(shmp, "packets contains (%s):\n%s", FUNCTION_MACRO, buf);

#define WriteSendMessageToDebugBuffer(shmp, pbuf) \
		DebugMsg(shmp, "=================================================="); \
		DebugMsg(shmp,"Send packet to %s %d Length=%d", \
					Inet_ntoa(pbuf->msgDstIP), pbuf->msgDstPort, \
					pbuf->msgLength); \
		gettimeofday(&tv, NULL); \
		DebugMsg(shmp,"Current time: %s (%ld.%06ld)", \
						CharTime(buf, &tv.tv_sec), tv.tv_sec, tv.tv_usec); \
    	DebugMsg(shmp, "packets contains (%s):", FUNCTION_MACRO); \
    	BcdToAscii(buf, pbuf->msgContent, 2*pbuf->msgLength); \
		FormatOutput(buf, 2*pbuf->msgLength, 2, ' '); \
		DebugMsg(shmp, "%s", buf); \
		DebugMsg(shmp,"=========04==========08==========12==========16==========20==========24========="); \

#define WriteRecvMessageToDebugBuffer(shmp, pbuf) \
		DebugMsg(shmp,"=================================================="); \
		DebugMsg(shmp,"Got packet from %s %d Length=%d", \
					Inet_ntoa(pbuf->msgSrcIP), pbuf->msgSrcPort, \
					pbuf->msgLength); \
		gettimeofday(&tv, NULL); \
		DebugMsg(shmp,"Current time: %s (%ld.%06ld)", \
						CharTime(buf, &tv.tv_sec), tv.tv_sec, tv.tv_usec); \
    	DebugMsg(shmp, "packets contains (%s):", FUNCTION_MACRO); \
    	BcdToAscii(buf, pbuf->msgContent, 2*pbuf->msgLength); \
		FormatOutput(buf, 2*pbuf->msgLength, 2, ' '); \
		DebugMsg(shmp, "%s", buf); \
		DebugMsg(shmp,"=========04==========08==========12==========16==========20==========24========="); \
	
#define UNDER_DEVELOP   0   
#define DEBUG           1 

#define D_NO_DEBUG      0
#define D_CONSOLE_ONLY  1
#define D_LOG_ONLY      2
#define D_CONSOLE_LOG   3
#define D_SYSLOG_MODE   4

#define SCAN_IT_INTERVAL_SEC    0
#define SCAN_IT_INTERVAL_USEC   (20*1000)
#define SCAN_IT_VALUE_SEC       0
#define SCAN_IT_VALUE_USEC      (20*1000)

/* If we have these macros, we can add additional info to the header. */
#ifdef HAVE_FILE_MACRO
#define FILE_MACRO (__FILE__)
#else
#define FILE_MACRO ("")
#endif

#ifdef HAVE_FUNCTION_MACRO
#define FUNCTION_MACRO  (__FUNCTION__)
#else
#define FUNCTION_MACRO  ("")
#endif

#ifdef HAVE_DATE_MACRO
#define DATE_MACRO  (__DATE__)
#else
#define DATE_MACRO  ("")
#endif

#ifdef HAVE_TIME_MACRO
#define TIME_MACRO  (__TIME__)
#else
#define TIME_MACRO  ("")
#endif

#ifdef HAVE_LINE_MACRO
#define LINE_MACRO  (__LINE__)
#else
#define LINE_MACRO  ("")
#endif

// Buffer stored by debug information
#define DEBUG_BUFFER_LINE        (25*16)
#define DEBUG_LINE_LEN           (80)
typedef struct {
		u_short     subRead;
		u_short     subWrite;
		u_char      infoDebug[DEBUG_BUFFER_LINE][DEBUG_LINE_LEN];
} _debug_info;

#endif  /* DEBUG__H */
