Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/installer-ca/dutil/dutil.h

Issue 11521026: initial custom action library, "hello, world" quality (Closed)
Patch Set: Created Sept. 3, 2013, 12:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #pragma once
2 //------------------------------------------------------------------------------ -------------------
3 // <copyright file="dutil.h" company="Outercurve Foundation">
4 // Copyright (c) 2004, Outercurve Foundation.
5 // This software is released under Microsoft Reciprocal License (MS-RL).
6 // The license and further copyright text can be found in the file
7 // LICENSE.TXT at the root directory of the distribution.
8 // </copyright>
9 //
10 // <summary>
11 // Header for utility layer that provides standard support for asserts, exit macros
12 // </summary>
13 //------------------------------------------------------------------------------ -------------------
14
15 #define DAPI __stdcall
16 #define DAPIV __cdecl // used only for functions taking variable length argument s
17
18
19 // enums
20 enum REPORT_LEVEL
21 {
22 REPORT_NONE, // turns off report (only valid for XXXSetLevel())
23 REPORT_WARNING, // written if want only warnings or reporting is on in gen eral
24 REPORT_STANDARD, // written if reporting is on
25 REPORT_VERBOSE, // written only if verbose reporting is on
26 REPORT_DEBUG, // reporting useful when debugging code
27 REPORT_ERROR, // always gets reported, but can never be specified
28 };
29
30 // asserts and traces
31 typedef BOOL (DAPI *DUTIL_ASSERTDISPLAYFUNCTION)(__in_z LPCSTR sz);
32
33 extern "C" void DAPI Dutil_SetAssertModule(__in HMODULE hAssertModule);
34 extern "C" void DAPI Dutil_SetAssertDisplayFunction(__in DUTIL_ASSERTDISPLAYFUNC TION pfn);
35 extern "C" void DAPI Dutil_Assert(__in_z LPCSTR szFile, __in int iLine);
36 extern "C" void DAPI Dutil_AssertSz(__in_z LPCSTR szFile, __in int iLine, __in_z LPCSTR szMsg);
37
38 extern "C" void DAPI Dutil_TraceSetLevel(__in REPORT_LEVEL ll, __in BOOL fTraceF ilenames);
39 extern "C" REPORT_LEVEL DAPI Dutil_TraceGetLevel();
40 extern "C" void __cdecl Dutil_Trace(__in_z LPCSTR szFile, __in int iLine, __in R EPORT_LEVEL rl, __in_z __format_string LPCSTR szMessage, ...);
41 extern "C" void __cdecl Dutil_TraceError(__in_z LPCSTR szFile, __in int iLine, _ _in REPORT_LEVEL rl, __in HRESULT hr, __in_z __format_string LPCSTR szMessage, . ..);
42 extern "C" void DAPI Dutil_RootFailure(__in_z LPCSTR szFile, __in int iLine, __i n HRESULT hrError);
43
44 #ifdef DEBUG
45
46 #define AssertSetModule(m) (void)Dutil_SetAssertModule(m)
47 #define AssertSetDisplayFunction(pfn) (void)Dutil_SetAssertDisplayFunction(pfn)
48 #define Assert(f) ((f) ? (void)0 : (void)Dutil_Assert(__FILE__, __LI NE__))
49 #define AssertSz(f, sz) ((f) ? (void)0 : (void)Dutil_AssertSz(__FILE__, __ LINE__, sz))
50
51 #define TraceSetLevel(l, f) (void)Dutil_TraceSetLevel(l, f)
52 #define TraceGetLevel() (REPORT_LEVEL)Dutil_TraceGetLevel()
53 #define Trace(l, f) (void)Dutil_Trace(__FILE__, __LINE__, l, f, NULL)
54 #define Trace1(l, f, s) (void)Dutil_Trace(__FILE__, __LINE__, l, f, s)
55 #define Trace2(l, f, s, t) (void)Dutil_Trace(__FILE__, __LINE__, l, f, s, t)
56 #define Trace3(l, f, s, t, u) (void)Dutil_Trace(__FILE__, __LINE__, l, f, s, t, u)
57
58 #define TraceError(x, f) (void)Dutil_TraceError(__FILE__, __LINE__, REPORT_ERROR , x, f, NULL)
59 #define TraceError1(x, f, s) (void)Dutil_TraceError(__FILE__, __LINE__, REPORT_E RROR, x, f, s)
60 #define TraceError2(x, f, s, t) (void)Dutil_TraceError(__FILE__, __LINE__, REPOR T_ERROR, x, f, s, t)
61 #define TraceError3(x, f, s, t, u) (void)Dutil_TraceError(__FILE__, __LINE__, RE PORT_ERROR, x, f, s, t, u)
62
63 #define TraceErrorDebug(x, f) (void)Dutil_TraceError(__FILE__, __LINE__, REPORT_ DEBUG, x, f, NULL)
64 #define TraceErrorDebug1(x, f, s) (void)Dutil_TraceError(__FILE__, __LINE__, REP ORT_DEBUG, x, f, s)
65 #define TraceErrorDebug2(x, f, s, t) (void)Dutil_TraceError(__FILE__, __LINE__, REPORT_DEBUG, x, f, s, t)
66 #define TraceErrorDebug3(x, f, s, t, u) (void)Dutil_TraceError(__FILE__, __LINE_ _, REPORT_DEBUG, x, f, s, t, u)
67
68 #else // !DEBUG
69
70 #define AssertSetModule(m)
71 #define AssertSetDisplayFunction(pfn)
72 #define Assert(f)
73 #define AssertSz(f, sz)
74
75 #define TraceSetLevel(l, f)
76 #define Trace(l, f)
77 #define Trace1(l, f, s)
78 #define Trace2(l, f, s, t)
79 #define Trace3(l, f, s, t, u)
80
81 #define TraceError(x, f)
82 #define TraceError1(x, f, s)
83 #define TraceError2(x, f, s, t)
84 #define TraceError3(x, f, s, t, u)
85
86 #define TraceErrorDebug(x, f)
87 #define TraceErrorDebug1(x, f, s)
88 #define TraceErrorDebug2(x, f, s, t)
89 #define TraceErrorDebug3(x, f, s, t, u)
90
91 #endif // DEBUG
92
93
94 // ExitTrace can be overriden
95 #ifndef ExitTrace
96 #define ExitTrace TraceError
97 #endif
98 #ifndef ExitTrace1
99 #define ExitTrace1 TraceError1
100 #endif
101 #ifndef ExitTrace2
102 #define ExitTrace2 TraceError2
103 #endif
104 #ifndef ExitTrace3
105 #define ExitTrace3 TraceError3
106 #endif
107
108 // Exit macros
109 #define ExitFunction() { goto LExit; }
110 #define ExitFunction1(x) { x; goto LExit; }
111
112 #define ExitOnLastError(x, s) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_F ROM_WIN32(Dutil_er); if (FAILED(x)) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTrace(x, s); goto LExit; } }
113 #define ExitOnLastError1(x, f, s) { DWORD Dutil_er = ::GetLastError(); x = HRESU LT_FROM_WIN32(Dutil_er); if (FAILED(x)) { Dutil_RootFailure(__FILE__, __LINE__, x); ExitTrace1(x, f, s); goto LExit; } }
114 #define ExitOnLastError2(x, f, s, t) { DWORD Dutil_er = ::GetLastError(); x = HR ESULT_FROM_WIN32(Dutil_er); if (FAILED(x)) { Dutil_RootFailure(__FILE__, __LINE_ _, x); ExitTrace2(x, f, s, t); goto LExit; } }
115
116 #define ExitOnLastErrorDebugTrace(x, s) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (FAILED(x)) { Dutil_RootFailure(__FILE__, __LI NE__, x); TraceErrorDebug(x, s); goto LExit; } }
117 #define ExitOnLastErrorDebugTrace1(x, f, s) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (FAILED(x)) { Dutil_RootFailure(__FILE__, __LINE__, x); TraceErrorDebug1(x, f, s); goto LExit; } }
118 #define ExitOnLastErrorDebugTrace2(x, f, s, t) { DWORD Dutil_er = ::GetLastError (); x = HRESULT_FROM_WIN32(Dutil_er); if (FAILED(x)) { Dutil_RootFailure(__FILE_ _, __LINE__, x); TraceErrorDebug2(x, f, s, t); goto LExit; } }
119
120 #define ExitWithLastError(x, s) { DWORD Dutil_er = ::GetLastError(); x = HRESULT _FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE_ _, __LINE__, x); ExitTrace(x, s); goto LExit; }
121 #define ExitWithLastError1(x, f, s) { DWORD Dutil_er = ::GetLastError(); x = HRE SULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__F ILE__, __LINE__, x); ExitTrace1(x, f, s); goto LExit; }
122 #define ExitWithLastError2(x, f, s, t) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure( __FILE__, __LINE__, x); ExitTrace2(x, f, s, t); goto LExit; }
123 #define ExitWithLastError3(x, f, s, t, u) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailu re(__FILE__, __LINE__, x); ExitTrace3(x, f, s, t, u); goto LExit; }
124
125 #define ExitOnFailure(x, s) if (FAILED(x)) { ExitTrace(x, s); goto LExit; }
126 #define ExitOnFailure1(x, f, s) if (FAILED(x)) { ExitTrace1(x, f, s); goto LE xit; }
127 #define ExitOnFailure2(x, f, s, t) if (FAILED(x)) { ExitTrace2(x, f, s, t); g oto LExit; }
128 #define ExitOnFailure3(x, f, s, t, u) if (FAILED(x)) { ExitTrace3(x, f, s, t, u) ; goto LExit; }
129
130 #define ExitOnRootFailure(x, s) if (FAILED(x)) { Dutil_RootFailure(__FILE__, _ _LINE__, x); ExitTrace(x, s); goto LExit; }
131 #define ExitOnRootFailure1(x, f, s) if (FAILED(x)) { Dutil_RootFailure(__FILE_ _, __LINE__, x); ExitTrace1(x, f, s); goto LExit; }
132 #define ExitOnRootFailure2(x, f, s, t) if (FAILED(x)) { Dutil_RootFailure(__FI LE__, __LINE__, x); ExitTrace2(x, f, s, t); goto LExit; }
133 #define ExitOnRootFailure3(x, f, s, t, u) if (FAILED(x)) { Dutil_RootFailure(__F ILE__, __LINE__, x); ExitTrace3(x, f, s, t, u); goto LExit; }
134
135 #define ExitOnFailureDebugTrace(x, s) if (FAILED(x)) { TraceErrorDebug(x, s); goto LExit; }
136 #define ExitOnFailureDebugTrace1(x, f, s) if (FAILED(x)) { TraceErrorDebug1(x, f, s); goto LExit; }
137 #define ExitOnFailureDebugTrace2(x, f, s, t) if (FAILED(x)) { TraceErrorDebug2 (x, f, s, t); goto LExit; }
138 #define ExitOnFailureDebugTrace3(x, f, s, t, u) if (FAILED(x)) { TraceErrorDebug 3(x, f, s, t, u); goto LExit; }
139
140 #define ExitOnNull(p, x, e, s) if (NULL == p) { x = e; Dutil_RootFailure(__FIL E__, __LINE__, x); ExitTrace(x, s); goto LExit; }
141 #define ExitOnNull1(p, x, e, f, s) if (NULL == p) { x = e; Dutil_RootFailure(_ _FILE__, __LINE__, x); ExitTrace1(x, f, s); goto LExit; }
142 #define ExitOnNull2(p, x, e, f, s, t) if (NULL == p) { x = e; Dutil_RootFailur e(__FILE__, __LINE__, x); ExitTrace2(x, f, s, t); goto LExit; }
143
144 #define ExitOnNullWithLastError(p, x, s) if (NULL == p) { DWORD Dutil_er = ::Get LastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } D util_RootFailure(__FILE__, __LINE__, x); ExitTrace(x, s); goto LExit; }
145 #define ExitOnNullWithLastError1(p, x, f, s) if (NULL == p) { DWORD Dutil_er = : :GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTrace1(x, f, s); goto LExit; }
146
147 #define ExitOnNullDebugTrace(p, x, e, s) if (NULL == p) { x = e; Dutil_RootFai lure(__FILE__, __LINE__, x); TraceErrorDebug(x, s); goto LExit; }
148 #define ExitOnNullDebugTrace1(p, x, e, f, s) if (NULL == p) { x = e; Dutil_Roo tFailure(__FILE__, __LINE__, x); TraceErrorDebug1(x, f, s); goto LExit; }
149
150 #define ExitOnInvalidHandleWithLastError(p, x, s) if (INVALID_HANDLE_VALUE == p) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAI LED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTrace(x, s ); goto LExit; }
151 #define ExitOnInvalidHandleWithLastError1(p, x, f, s) if (INVALID_HANDLE_VALUE = = p) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if ( !FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTrace1 (x, f, s); goto LExit; }
152
153 #define ExitOnWin32Error(e, x, s) if (ERROR_SUCCESS != e) { x = HRESULT_FROM_WIN 32(e); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTrace(x, s); goto LExit; }
154 #define ExitOnWin32Error1(e, x, f, s) if (ERROR_SUCCESS != e) { x = HRESULT_FROM _WIN32(e); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE__, x); ExitTrace1(x, f, s); goto LExit; }
155 #define ExitOnWin32Error2(e, x, f, s, t) if (ERROR_SUCCESS != e) { x = HRESULT_F ROM_WIN32(e); if (!FAILED(x)) { x = E_FAIL; } Dutil_RootFailure(__FILE__, __LINE __, x); ExitTrace2(x, f, s, t); goto LExit; }
156
157 // release macros
158 #define ReleaseObject(x) if (x) { x->Release(); }
159 #define ReleaseObjectArray(prg, cel) if (prg) { for (DWORD Dutil_ReleaseObjectAr rayIndex = 0; Dutil_ReleaseObjectArrayIndex < cel; ++Dutil_ReleaseObjectArrayInd ex) { ReleaseObject(prg[Dutil_ReleaseObjectArrayIndex]); } ReleaseMem(prg); }
160 #define ReleaseVariant(x) { ::VariantClear(&x); }
161 #define ReleaseNullObject(x) if (x) { (x)->Release(); x = NULL; }
162 #define ReleaseCertificate(x) if (x) { ::CertFreeCertificateContext(x); x=NULL; }
163 #define ReleaseHandle(x) if (x) { ::CloseHandle(x); x = NULL; }
164
165
166 // useful defines and macros
167 #define Unused(x) ((void)x)
168
169 #ifndef countof
170 #if 1
171 #define countof(ary) (sizeof(ary) / sizeof(ary[0]))
172 #else
173 #ifndef __cplusplus
174 #define countof(ary) (sizeof(ary) / sizeof(ary[0]))
175 #else
176 template<typename T> static char countofVerify(void const *, T) throw() { return 0; }
177 template<typename T> static void countofVerify(T *const, T *const *) throw() {};
178 #define countof(arr) (sizeof(countofVerify(arr,&(arr))) * sizeof(arr)/sizeof(*(a rr)))
179 #endif
180 #endif
181 #endif
182
183 #define roundup(x, n) roundup_typed(x, n, DWORD)
184 #define roundup_typed(x, n, t) (((t)(x) + ((t)(n) - 1)) & ~((t)(n) - 1))
185
186 #define HRESULT_FROM_RPC(x) ((HRESULT) ((x) | FACILITY_RPC))
187
188 #ifndef MAXSIZE_T
189 #define MAXSIZE_T ((SIZE_T)~((SIZE_T)0))
190 #endif
191
192 typedef const BYTE* LPCBYTE;
193
194 #define E_FILENOTFOUND HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
195 #define E_PATHNOTFOUND HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)
196 #define E_INVALIDDATA HRESULT_FROM_WIN32(ERROR_INVALID_DATA)
197 #define E_INVALIDSTATE HRESULT_FROM_WIN32(ERROR_INVALID_STATE)
198 #define E_INSUFFICIENT_BUFFER HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)
199 #define E_MOREDATA HRESULT_FROM_WIN32(ERROR_MORE_DATA)
200 #define E_NOMOREITEMS HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS)
201 #define E_NOTFOUND HRESULT_FROM_WIN32(ERROR_NOT_FOUND)
202 #define E_MODNOTFOUND HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND)
203 #define E_BADCONFIGURATION HRESULT_FROM_WIN32(ERROR_BAD_CONFIGURATION)
204
205 #define AddRefAndRelease(x) { x->AddRef(); x->Release(); }
206
207 #define MAKEDWORD(lo, hi) ((DWORD)MAKELONG(lo, hi))
208 #define MAKEQWORDVERSION(mj, mi, b, r) (((DWORD64)MAKELONG(r, b)) | (((DWORD64)M AKELONG(mi, mj)) << 32))
209
210 // other functions
211 extern "C" HRESULT DAPI LoadSystemLibrary(__in_z LPCWSTR wzModuleName, __out HMO DULE *phModule);
OLDNEW

Powered by Google App Engine
This is Rietveld