b27606605333be47d3450d42aff327ec1f723b6d
[reactos.git] / base / shell / rshell / wraplog.cpp
1 #include "precomp.h"
2 #include "wraplog.h"
3 #include <stdio.h>
4
5 static INT openCount = 0;
6 static INT callLevel;
7 static FILE*log;
8
9 static INT nTemps;
10 static CHAR strTemp[10][256];
11
12 void WrapLogOpen()
13 {
14 if (openCount == 0)
15 {
16 log = fopen("RShellWrap.log", "w");
17 nTemps = 0;
18 callLevel = 0;
19 }
20 openCount++;
21 }
22
23 void WrapLogClose()
24 {
25 openCount--;
26 if (openCount == 0)
27 {
28 fclose(log);
29 log = NULL;
30 }
31 }
32
33 void __cdecl WrapLogPrint(_Printf_format_string_ const char* msg, ...)
34 {
35 va_list args;
36 for (int i = 0; i < callLevel; i++)
37 fputs(" ", log);
38 va_start(args, msg);
39 vfprintf(log, msg, args);
40 va_end(args);
41 fflush(log);
42 nTemps = 0;
43 }
44
45 void __cdecl WrapLogPre(_Printf_format_string_ const char* msg, ...)
46 {
47 va_list args;
48 for (int i = 0; i < callLevel; i++)
49 fputs(" ", log);
50 fputs("pre: ", log);
51 va_start(args, msg);
52 vfprintf(log, msg, args);
53 va_end(args);
54 fflush(log);
55 nTemps = 0;
56 }
57
58 void __cdecl WrapLogPost(_Printf_format_string_ const char* msg, ...)
59 {
60 va_list args;
61 for (int i = 0; i < callLevel; i++)
62 fputs(" ", log);
63 fputs("post: ", log);
64 va_start(args, msg);
65 vfprintf(log, msg, args);
66 va_end(args);
67 fflush(log);
68 nTemps = 0;
69 }
70
71 void __cdecl WrapLogEnter(_Printf_format_string_ const char* msg, ...)
72 {
73 va_list args;
74 for (int i = 0; i < callLevel; i++)
75 fputs(" ", log);
76 fputs("CALL ", log);
77 va_start(args, msg);
78 vfprintf(log, msg, args);
79 va_end(args);
80 fflush(log);
81 callLevel++;
82 nTemps = 0;
83 }
84
85 void __cdecl WrapLogExit(const char* msg, HRESULT code)
86 {
87 //if (FAILED(code))
88 // WrapLogPrint("RETURN %s = %08x\n", msg, code);
89 //else if (code == S_OK)
90 // WrapLogPrint("RETURN %s = S_OK\n", msg);
91 //else if (code == S_FALSE)
92 // WrapLogPrint("RETURN %s = S_FALSE\n", msg);
93 //else
94 // WrapLogPrint("RETURN %s = %d\n", msg, code);
95 if (FAILED(code))
96 WrapLogPrint("RETURN %08x\n", code);
97 else if (code == S_OK)
98 WrapLogPrint("RETURN S_OK\n");
99 else if (code == S_FALSE)
100 WrapLogPrint("RETURN S_FALSE\n");
101 else
102 WrapLogPrint("RETURN %d\n", code);
103 callLevel--;
104 }
105
106 template <class T>
107 LPSTR Wrap(const T& value);
108
109 template <>
110 LPSTR Wrap<GUID>(REFGUID guid)
111 {
112 LPSTR cStr = strTemp[nTemps++];
113 StringCchPrintfA(cStr, _countof(strTemp[0]),
114 "{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}",
115 guid.Data1, guid.Data2, guid.Data3,
116 guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
117 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
118 return cStr;
119 }
120
121 template <>
122 LPSTR Wrap<RECT>(const RECT& rect)
123 {
124 LPSTR cStr = strTemp[nTemps++];
125 StringCchPrintfA(cStr, _countof(strTemp[0]),
126 "{L: %d, T: %d, R: %d, B: %d}",
127 rect.left, rect.top, rect.right, rect.bottom);
128 return cStr;
129 }
130
131 template <>
132 LPSTR Wrap<OLECMD>(const OLECMD& cmd)
133 {
134 LPSTR cStr = strTemp[nTemps++];
135 StringCchPrintfA(cStr, _countof(strTemp[0]),
136 "{ID: %d, F: %d}",
137 cmd.cmdID, cmd.cmdf);
138 return cStr;
139 }
140
141 template <>
142 LPSTR Wrap<MSG>(const MSG& msg)
143 {
144 LPSTR cStr = strTemp[nTemps++];
145 StringCchPrintfA(cStr, _countof(strTemp[0]),
146 "{HWND: %d, Code: %d, W: %p, L: %p, T: %d, P.X: %d, P.Y: %d}",
147 msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.time, msg.pt.x, msg.pt.y);
148 return cStr;
149 }
150
151 template <>
152 LPSTR Wrap<BANDSITEINFO>(const BANDSITEINFO& bsi)
153 {
154 LPSTR cStr = strTemp[nTemps++];
155 StringCchPrintfA(cStr, _countof(strTemp[0]),
156 "{dwMask: %08x, dwState: %08x, dwStyle: %08x}",
157 bsi.dwMask, bsi.dwState, bsi.dwStyle);
158 return cStr;
159 }