//*****************************************************************************
//* FILE NAME:       DiagMsg.h
//* FILE CONTAINS:
//* DESCRIPTION:     .
//* NOTES:           .
//*****************************************************************************
//*                   INTEL CORPORATION PROPRIETARY INFORMATION
//*     This software is supplied under the terms of a license agreement or
//*     nondisclosure agreement with Intel Corporation and may not be copied
//*     or disclosed except in accordance with the terms of that agreement.
//*           Copyright (c) 1995-2000 Intel Corporation.  All Rights Reserved.
//*****************************************************************************

#ifndef D_DiagMsg_HeaderFile
#define D_DiagMsg_HeaderFile

#include "CompDiag.h"

#ifdef D_CompilerDiagnostics
   #pragma D_CompDiagMsg("\"D_CompilerDiagnostics\" defined")
#endif

#ifdef D_CompilerDiagnostics
   #pragma D_CompDiagMsg("Include")
#endif

//*****************************************************************************
//* INCLUDEs
//*****************************************************************************

//-----------------------------------------------------------------------------
// System Includes
//-----------------------------------------------------------------------------

#ifdef D_CompilerDiagnostics
   #pragma D_CompDiagMsg("#include <windef.h>")
#endif

#include <windef.h>

//-----------------------------------------------------------------------------
// PHD Computer Consultants Ltd. Includes
//-----------------------------------------------------------------------------

#include "DebugPrint.h"          // Debug print monitor

//-----------------------------------------------------------------------------
// Local Includes
//-----------------------------------------------------------------------------

#include "DiagCodes.h"

//*****************************************************************************
//* DEFINEs
//*****************************************************************************

//=============================================================================
// Diagnostic message error types.
//=============================================================================

#define D_Error   "ERROR"
#define D_Warn    "WARN"
#define D_Info    "INFO"

//=============================================================================
// Macros for printing diagnostic messages.
//=============================================================================

//-----------------------------------------------------------------------------

#if DBG

   #ifdef D_CompilerDiagnostics
      #pragma D_CompDiagMsg("Checked build")
   #endif

   #define D_BuildType  "Checked"

#endif

#if DEBUGPRINT

   #ifdef D_CompilerDiagnostics
      #pragma D_CompDiagMsg("Free build")
   #endif

   #define D_BuildType  "Free"

#endif

#if DBG || DEBUGPRINT                     // Kernel Mode?

   #ifdef D_CompilerDiagnostics
      #pragma D_CompDiagMsg("Debug print enabled for kernel mode")
   #endif

   #define DebugPrintInitMsg  D_Info"("__FILE__") Win 2000 "D_BuildType" Build."

   #define D_DiagPrint     DebugPrint

   #define D_KernelMode    TRUE

#else                                     // User Mode

   #ifdef D_CompilerDiagnostics
      #pragma D_CompDiagMsg("Diagnostic message enabled for user mode")
   #endif

   #define D_KernelMode    FALSE          // I.e. User Mode

   #define D_DiagPrint     printf

#endif

//-----------------------------------------------------------------------------

#ifdef D_DiagMsgEnable

   #ifdef D_CompilerDiagnostics
      #pragma D_CompDiagMsg("Diagnostic messages being defined")
   #endif

   #define D_DiagTestMsg                                             \
           {                                                         \
            if (D_KernelMode && !gbDebugPrintInit)                   \
              {                                                      \
               DebugPrintInit(DebugPrintInitMsg);                    \
               gbDebugPrintInit = TRUE;                              \
               }                                                     \
            if (gbDiagCodeSet)                                       \
               D_DiagPrint("TEST:(%s,%d).",__FILE__,__LINE__);    \
            else                                                     \
               D_DiagPrint("TEST:NDC(%s,%d).",__FILE__,__LINE__); \
            }                                                        \

   #define D_DiagMsg(MsgType,DiagCode)                               \
           {                                                         \
            if (D_KernelMode && !gbDebugPrintInit)                   \
              {                                                      \
               DebugPrintInit(DebugPrintInitMsg);                    \
               gbDebugPrintInit = TRUE;                              \
               }                                                     \
            if (   gbDiagCodeSet                                     \
                && (DiagCode != D_DC_Unconditional)                  \
                )                                                    \
              {                                                      \
               if (gulDiagCode & DiagCode)                           \
                  D_DiagPrint(MsgType":(%s,%d).",__FILE__,__LINE__); \
               }                                                     \
            else                                                     \
               D_DiagPrint(MsgType":NDC(%s,%d).",__FILE__,__LINE__); \
            }                                                        \

   #define D_DiagMsg0(MsgType,DiagCode,ArgFmt)                       \
           {                                                         \
            if (D_KernelMode && !gbDebugPrintInit)                   \
              {                                                      \
               DebugPrintInit(DebugPrintInitMsg);                    \
               gbDebugPrintInit = TRUE;                              \
               }                                                     \
            if (   gbDiagCodeSet                                     \
                && (DiagCode != D_DC_Unconditional)                  \
                )                                                    \
              {                                                      \
               if (gulDiagCode & DiagCode)                           \
                  D_DiagPrint(MsgType":(%s,%d) "ArgFmt".",__FILE__,__LINE__); \
               }                                                     \
            else                                                     \
               D_DiagPrint(MsgType":NDC(%s,%d) "ArgFmt".",__FILE__,__LINE__); \
            }                                                        \

   #define D_DiagMsg1(MsgType,DiagCode,ArgFmt,Arg1)                  \
           {                                                         \
            if (D_KernelMode && !gbDebugPrintInit)                   \
              {                                                      \
               DebugPrintInit(DebugPrintInitMsg);                    \
               gbDebugPrintInit = TRUE;                              \
               }                                                     \
            if (   gbDiagCodeSet                                     \
                && (DiagCode != D_DC_Unconditional)                  \
                )                                                    \
              {                                                      \
               if (gulDiagCode & DiagCode)                           \
                  D_DiagPrint(MsgType":(%s,%d) "ArgFmt".",__FILE__,__LINE__,Arg1); \
               }                                                     \
            else                                                     \
               D_DiagPrint(MsgType":NDC(%s,%d) "ArgFmt".",__FILE__,__LINE__,Arg1); \
            }                                                        \

   #define D_DiagMsg2(MsgType,DiagCode,ArgFmt,Arg1,Arg2)             \
           {                                                         \
            if (D_KernelMode && !gbDebugPrintInit)                   \
              {                                                      \
               DebugPrintInit(DebugPrintInitMsg);                    \
               gbDebugPrintInit = TRUE;                              \
               }                                                     \
            if (   gbDiagCodeSet                                     \
                && (DiagCode != D_DC_Unconditional)                  \
                )                                                    \
              {                                                      \
               if (gulDiagCode & DiagCode)                           \
                  D_DiagPrint(MsgType":(%s,%d) "ArgFmt".",__FILE__,__LINE__,Arg1,Arg2); \
               }                                                     \
            else                                                     \
               D_DiagPrint(MsgType":NDC(%s,%d) "ArgFmt".",__FILE__,__LINE__,Arg1,Arg2); \
            }                                                        \

   #define D_DiagMsg3(MsgType,DiagCode,ArgFmt,Arg1,Arg2,Arg3)        \
           {                                                         \
            if (D_KernelMode && !gbDebugPrintInit)                   \
              {                                                      \
               DebugPrintInit(DebugPrintInitMsg);                    \
               gbDebugPrintInit = TRUE;                              \
               }                                                     \
            if (   gbDiagCodeSet                                     \
                && (DiagCode != D_DC_Unconditional)                  \
                )                                                    \
              {                                                      \
               if (gulDiagCode & DiagCode)                           \
                  D_DiagPrint(MsgType":(%s,%d) "ArgFmt".",__FILE__,__LINE__,Arg1,Arg2,Arg3); \
               }                                                     \
            else                                                     \
               D_DiagPrint(MsgType":NDC(%s,%d) "ArgFmt".",__FILE__,__LINE__,Arg1,Arg2,Arg3); \
            }                                                        \

#else

   #ifdef D_CompilerDiagnostics
      #pragma D_CompDiagMsg("Diagnostic messages not defined")
   #endif

   #define D_DiagMsg(MsgType,DiagCode)                         {}

   #define D_DiagMsg0(MsgType,DiagCode,ArgFmt)                 {}

   #define D_DiagMsg1(MsgType,DiagCode,ArgFmt,Arg1)            {}

   #define D_DiagMsg2(MsgType,DiagCode,ArgFmt,Arg1,Arg2)       {}

   #define D_DiagMsg3(MsgType,DiagCode,ArgFmt,Arg1,Arg2,Arg3)  {}

#endif

//=============================================================================
// "#define D_DiagMsgInit" must be speced in at least one module in the build.
//=============================================================================

#ifdef D_DiagMsgInit

   #ifdef D_CompilerDiagnostics
      #pragma D_CompDiagMsg("Declaring and initializing diagnostic message variables in this module")
   #endif

   unsigned long        gulDiagCode       = D_DiagCodeInit;  // "DiagCodes.h"
   BOOL                 gbDiagCodeSet     = FALSE;
   BOOL                 gbDebugPrintInit  = FALSE;

#else

   extern unsigned long gulDiagCode;
   extern BOOL          gbDiagCodeSet;
   extern BOOL          gbDebugPrintInit;

#endif

//-----------------------------------------------------------------------------

#ifdef D_DiagMsgEnable

   #define D_DiagMsgClose  DebugPrintClose();

#else

   #define D_DiagMsgClose

#endif

//-----------------------------------------------------------------------------

#endif