summaryrefslogtreecommitdiff
path: root/print/OEM Printer Customization Plug-in Samples/C++/oemprean/debug.h
blob: 2b488890dbc22c8ad37687724a69b80002eb3628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
//  Copyright  1996 - 2003  Microsoft Corporation.  All Rights Reserved.
//
//  FILE:   Debug.H
//
//
//  PURPOSE:    Define common data types, and external function prototypes
//          for debugging functions. Also defines the various debug macros.
//
//
//  History:
//          06/28/03    xxx created.
//
//

#pragma once 

#include "devmode.h"

// VC and Build use different debug defines.
// The following makes it so either will
// cause the inclusion of debugging code.
#if !defined(_DEBUG) && defined(DBG)
    #define _DEBUG      DBG
#elif defined(_DEBUG) && !defined(DBG)
    #define DBG         _DEBUG
#endif



/////////////////////////////////////////////////////////
//      Macros
/////////////////////////////////////////////////////////
//
// These macros are used for debugging purposes. They expand
// to white spaces on a free build. Here is a brief description
// of what they do and how they are used:
//
// giDebugLevel
// Global variable which set the current debug level to control
// the amount of debug messages emitted.
//
// VERBOSE(msg)
// Display a message if the current debug level is <= DBG_VERBOSE.
//
// TERSE(msg)
// Display a message if the current debug level is <= DBG_TERSE.
//
// WARNING(msg)
// Display a message if the current debug level is <= DBG_WARNING.
// The message format is: WRN filename (linenumber): message
//
// ERR(msg)
// Similiar to WARNING macro above - displays a message
// if the current debug level is <= DBG_ERROR.
//
// ASSERT(cond)
// Verify a condition is true. If not, force a breakpoint.
//
// ASSERTMSG(cond, msg)
// Verify a condition is true. If not, display a message and
// force a breakpoint.
//
// RIP(msg)
// Display a message and force a breakpoint.
//
// Usage:
// These macros require extra parantheses for the msg argument
// example, ASSERTMSG(x > 0, ("x is less than 0\n"));
//           WARNING(("App passed NULL pointer, ignoring...\n"));
//

#define DBG_VERBOSE     1
#define DBG_TERSE       2
#define DBG_WARNING 3
#define DBG_ERROR       4
#define DBG_RIP         5
#define DBG_NONE        6

//
// Determine what level of debugging messages to emit.
// This can be set in the sources file, or omitted 
// completely
//
#ifdef VERBOSE_MSG
    #define DEBUG_LEVEL     DBG_VERBOSE
#elif TERSE_MSG
    #define DEBUG_LEVEL     DBG_TERSE
#elif WARNING_MSG
    #define DEBUG_LEVEL     DBG_WARNING
#elif ERROR_MSG
    #define DEBUG_LEVEL     DBG_ERROR
#elif RIP_MSG
    #define DEBUG_LEVEL     DBG_RIP
#elif NO_DBG_MSG
    #define DEBUG_LEVEL     DBG_NONE
#else
    #define DEBUG_LEVEL     DBG_WARNING
#endif


#if DBG

    extern INT giDebugLevel;

    #define DBGMSG(level, prefix, msg) { \
        if (giDebugLevel <= (level)) { \
            OEMDebugMessage(L"%s %s (%d): ", prefix, StripDirPrefixA(__FILE__), __LINE__); \
            OEMDebugMessage(msg); \
        } \
    }

    #define VERBOSE     if(giDebugLevel <= DBG_VERBOSE) OEMDebugMessage
    #define TERSE       if(giDebugLevel <= DBG_TERSE) OEMDebugMessage
    #define WARNING     if(giDebugLevel <= DBG_WARNING) OEMDebugMessage
    #define ERR         if(giDebugLevel <= DBG_ERROR) OEMDebugMessage

    #define DBG_OEMDMPARAM(iDbgLvl, szLabel, pobj)              {vDumpOemDMParam(iDbgLvl, szLabel, pobj);}
    #define DBG_SURFOBJ(iDbgLvl, szLabel, pobj)                 {vDumpSURFOBJ(iDbgLvl, szLabel, pobj);}
    #define DBG_STROBJ(iDbgLvl, szLabel, pobj)                  {vDumpSTROBJ(iDbgLvl, szLabel, pobj);}
    #define DBG_FONTOBJ(iDbgLvl, szLabel, pobj)                 {vDumpFONTOBJ(iDbgLvl, szLabel, pobj);}
    #define DBG_CLIPOBJ(iDbgLvl, szLabel, pobj)                 {vDumpCLIPOBJ(iDbgLvl, szLabel, pobj);}
    #define DBG_BRUSHOBJ(iDbgLvl, szLabel, pobj)                {vDumpBRUSHOBJ(iDbgLvl, szLabel, pobj);}
    #define DBG_GDIINFO(iDbgLvl, szLabel, pobj)                 {vDumpGDIINFO(iDbgLvl, szLabel, pobj);}
    #define DBG_DEVINFO(iDbgLvl, szLabel, pobj)                 {vDumpDEVINFO(iDbgLvl, szLabel, pobj);}
    #define DBG_BMPINFO(iDbgLvl, szLabel, pobj)                 {vDumpBitmapInfoHeader(iDbgLvl, szLabel, pobj);}
    #define DBG_POINTL(iDbgLvl, szLabel, pobj)                  {vDumpPOINTL(iDbgLvl, szLabel, pobj);}
    #define DBG_RECTL(iDbgLvl, szLabel, pobj)                   {vDumpRECTL(iDbgLvl, szLabel, pobj);}
    #define DBG_XLATEOBJ(iDbgLvl, szLabel, pobj)                {vDumpXLATEOBJ(iDbgLvl, szLabel, pobj);}
    #define DBG_COLORADJUSTMENT(iDbgLvl, szLabel, pobj)         {vDumpCOLORADJUSTMENT(iDbgLvl, szLabel, pobj);}

    #define ASSERT(cond) \
    { \
        if (! (cond)) \
        { \
            RIP((L"\n")); \
        } \
    }

    #define ASSERTMSG(cond, msg) \
    { \
        if (! (cond)) { \
            RIP(msg); \
        } \
    }

    #define RIP(msg) \
    { \
        DBGMSG(DBG_RIP, L"RIP", msg); \
        DebugBreak(); \
    }

    typedef struct DBG_FLAGS {
        LPWSTR pszFlag;
        DWORD dwFlag;
    } *PDBG_FLAGS;

    BOOL OEMDebugMessage(LPCWSTR, ...);
    void vDumpOemDMParam(INT iDebugLevel, _In_ PWSTR pszInLabel, POEMDMPARAM pOemDMParam);
    void vDumpSURFOBJ(INT iDebugLevel, _In_ PWSTR pszInLabel, SURFOBJ *pso);
    void vDumpSTROBJ(INT iDebugLevel, _In_ PWSTR pszInLabel, STROBJ *pstro);
    void vDumpFONTOBJ(INT iDebugLevel, _In_ PWSTR pszInLabel, FONTOBJ *pfo);
    void vDumpCLIPOBJ(INT iDebugLevel, _In_ PWSTR pszInLabel, CLIPOBJ *pco);
    void vDumpBRUSHOBJ(INT iDebugLevel, _In_ PWSTR pszInLabel, BRUSHOBJ *pbo);
    void vDumpGDIINFO(INT iDebugLevel, _In_ PWSTR pszInLabel, GDIINFO *pGdiInfo);
    void vDumpDEVINFO(INT iDebugLevel, _In_ PWSTR pszInLabel, DEVINFO *pDevInfo);
    void vDumpBitmapInfoHeader(INT iDebugLevel, _In_ PWSTR pszInLabel, PBITMAPINFOHEADER pBitmapInfoHeader);
    void vDumpPOINTL(INT iDebugLevel, _In_ PWSTR pszInLabel, POINTL *pptl);
    void vDumpRECTL(INT iDebugLevel, _In_ PWSTR pszInLabel, RECTL *prcl);
    void vDumpXLATEOBJ(INT iDebugLevel, _In_ PWSTR pszInLabel, XLATEOBJ *pxlo);
    void vDumpCOLORADJUSTMENT(INT iDebugLevel, _In_ PWSTR pszInLabel, COLORADJUSTMENT *pca);

    BOOL OEMRealDebugMessage(DWORD dwSize, LPCWSTR lpszMessage, va_list arglist);
    PCSTR StripDirPrefixA(IN PCSTR    pstrFilename);
    void vDumpFlags(DWORD dwFlags, PDBG_FLAGS pDebugFlags);

#else // !DBG

    #define DebugMsg    NOP_FUNCTION

    #define VERBOSE     NOP_FUNCTION
    #define TERSE       NOP_FUNCTION
    #define WARNING     NOP_FUNCTION
    #define ERR         NOP_FUNCTION

    #define DBG_OEMDMPARAM(iDbgLvl, szLabel, pobj)          NOP_FUNCTION
    #define DBG_OEMDEVMODE(iDbgLvl, szLabel, pobj)          NOP_FUNCTION
    #define DBG_SURFOBJ(iDbgLvl, szLabel, pobj)             NOP_FUNCTION
    #define DBG_STROBJ(iDbgLvl, szLabel, pobj)              NOP_FUNCTION
    #define DBG_FONTOBJ(iDbgLvl, szLabel, pobj)             NOP_FUNCTION
    #define DBG_CLIPOBJ(iDbgLvl, szLabel, pobj)             NOP_FUNCTION
    #define DBG_BRUSHOBJ(iDbgLvl, szLabel, pobj)                NOP_FUNCTION
    #define DBG_GDIINFO(iDbgLvl, szLabel, pobj)             NOP_FUNCTION
    #define DBG_DEVINFO(iDbgLvl, szLabel, pobj)             NOP_FUNCTION
    #define DBG_BMPINFO(iDbgLvl, szLabel, pobj)             NOP_FUNCTION
    #define DBG_POINTL(iDbgLvl, szLabel, pobj)              NOP_FUNCTION
    #define DBG_RECTL(iDbgLvl, szLabel, pobj)                   NOP_FUNCTION
    #define DBG_XLATEOBJ(iDbgLvl, szLabel, pobj)                NOP_FUNCTION
    #define DBG_COLORADJUSTMENT(iDbgLvl, szLabel, pobj)     NOP_FUNCTION

    #define ASSERT(cond)

    #define ASSERTMSG(cond, msg)
    #define RIP(msg)

#endif