/*
 * The contents of this file are subject to the Netscape Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/NPL/

 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.

 * The Original Code is Rhino code, released
 * May 6, 1999.

 * The Initial Developer of the Original Code is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
 * Rights Reserved.

 * Contributor(s): 

 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Public License (the "GPL"), in which case the
 * provisions of the GPL are applicable instead of those above.
 * If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use your
 * version of this file under the NPL, indicate your decision by
 * deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this
 * file under either the NPL or the GPL.
 */
/*
File:       ewb-dbg.h
Contents:   for Debug
12.May.00:  Created by N.Enomoto
				Prime) DPC CP&S STD

*/

#ifndef _JS_DBG_H_
#define _JS_DBG_H_

#include <stdio.h>
#include <string.h>

extern int ewbConsoleOn;
extern int ewbWithScan;
extern int ewbGifOff;
extern int ewbTimeTrace;
extern int ewbJsOn;
extern int ewbRamDisk;
extern int ewbCookie;
extern int ewbFileCache;
extern int ewbJsErrorOn;
extern int ewbBootTime;
extern int ewbPrintOn;

#ifdef __cplusplus
extern "C" {
#endif
extern   char   EwbDebugString[256];
extern   void   EwbWriteDebugBuff(char *str);
extern   void   EwbWritePfRingBuff(char std_out);
#ifdef __cplusplus
}
#endif

/*
**      "EWB_PRINTF()" is to show general debug messages in all functions.
*/

#define         EWB_PRINTF(args...)     if (ewbPrintOn)  {      \
										memset(EwbDebugString, 0, 256);         \
										sprintf(EwbDebugString, "[ewb]" args);  \
										EwbWritePfRingBuff(1);}


/*
**      "EWBLCK_PRN()" is to show debug messages in terms of "Screen Lock"
**      funtions for web UI.
*/

#if 0
#define         EWBLCK_PRN(args...)     printf("[ewb]" args)
#else
#define         EWBLCK_PRN(args...)
#endif

/*
**      "EWBSRC_PRN()" is to show debug messages in terms of argument of
**      network module task.
*/

#if 0
#define         EWBSRC_PRN(args...)     printf("[src]" args)
#else
#define         EWBSRC_PRN(args...)
#endif

/*
**      "EWBJSI_PRN" is to show debug message in JavaScript.
*/

#if 1
#define         EWBJSI_PRN(args...) ((ewbJsOn) ? printf("[jsi]" args) : NULL )
#else
#define         EWBJSI_PRN(args...)
#endif

/*
**      "EWBBOOT_PRN" is to show debug message for booting.
*/

#if 0
#define         EWBBOOT_PRN(args...) ((ewbBootTime) ? printf("[ewb]" args) : NULL )
#else
#define         EWBBOOT_PRN(args...) if (ewbBootTime)  {        \
										memset(EwbDebugString, 0, 256); \
										sprintf(EwbDebugString, "[ewb:boot] " args);    \
										EwbWriteDebugBuff(EwbDebugString);              \
										EwbWritePfRingBuff(1);}
#endif

/*
**      "EWBPRN_DBG" is to show debug message in others.
*/

#if     0
#define         EWBPRN_DBG(_str)        printf("[ewb]" _str "\n")
#else
#define         EWBPRN_DBG(args...)     {       \
										memset(EwbDebugString, 0, 256); \
										sprintf(EwbDebugString, "[ewb:dbg] " args);     \
										EwbWriteDebugBuff(EwbDebugString); }
#endif

/*
**      Followings Macro's is to show error message in EWB.
**      (Never delete these two Macro's even if product is launched.)
*/
#if 0
#define         EWBPRN_ERR(_str)        printf("[ewb]" _str "\n")
#define         EWBPRN_MEM(_str)        \
						printf("[ewb]" _str " memory allocation failure!\n");
#else

#ifdef  __cplusplus
extern "C" {
#endif

extern          void    EwbSetLog( char *msg );
extern          void    EwbSetServerLog(int id, void *data);
#define         EWB_LOG_INFO    3
#define         EWB_LOG_ERROR   5

#ifdef VX
#define         EWBPRN_ERR(_str)        EwbSetServerLog(EWB_LOG_ERROR,(void*)(_str "\n"))
#define         EWBPRN_INFO(_str)       EwbSetServerLog(EWB_LOG_INFO,(void*)(_str "\n"))
#else
#define         EWBPRN_ERR(_str)        EwbSetLog(_str "\n")
#define         EWBPRN_INFO(_str)       EwbSetLog(_str "\n")
#endif

#define         EWBPRN_MEM(_str)        EwbSetLog(_str " memory allocation failure!\n")

/*
**      "EWBBOOT_LOG" is to log debug message to SysLog.
*/
#define         EWBPRN_LOG(args...)     {       \
										memset(EwbDebugString, 0, 256); \
										sprintf(EwbDebugString, "[ewb] " args); \
										EwbWritePfRingBuff(0);}


#if defined CONF_WPAD
void ApdJsErrorNotify(jsContext_t ctx, const char *fmt, ...);
void ApdJsCompileErrorNotify(jsContext_t ctx, jsString_t msg);
void ApdJsExecuteErrorNotify(jsContext_t ctx, jsString_t msg);
#if defined CONF_WPAD_DEBUG
void ApdJsShowMemPart(jsContext_t ctx, jsString_t str);
#endif
#endif

#ifdef  __cplusplus
}
#endif

#endif

#endif  /* _JS_DBG_H_ */
