self.format = format
def dump(self, instance):
- print ' g_pLog->TextF("%s", %s);' % (self.format, instance)
+ print ' Log::TextF("%s", %s);' % (self.format, instance)
class Const(Type):
try:
self.type.dump("*" + instance)
except NotImplementedError:
- print ' g_pLog->TextF("%%p", %s);' % instance
+ print ' Log::TextF("%%p", %s);' % instance
print ' }'
print ' else'
- print ' g_pLog->Text("NULL");'
+ print ' Log::Text("NULL");'
def wrap_instance(self, instance):
self.type.wrap_instance("*" + instance)
print ' switch(%s) {' % instance
for value in self.values:
print ' case %s:' % value
- print ' g_pLog->Text("%s");' % value
+ print ' Log::Text("%s");' % value
print ' break;'
print ' default:'
- print ' g_pLog->TextF("%%i", %s);' % instance
+ print ' Log::TextF("%%i", %s);' % instance
print ' break;'
print ' }'
print ' %s l_Value = %s;' % (self.type, instance)
for value in self.values:
print ' if((l_Value & %s) == %s) {' % (value, value)
- print ' g_pLog->Text("%s | ");' % value
+ print ' Log::Text("%s | ");' % value
print ' l_Value &= ~%s;' % value
print ' }'
self.type.dump("l_Value");
self.members = members
def dump(self, instance):
- print ' g_pLog->Text("{");'
+ print ' Log::Text("{");'
first = True
for type, name in self.members:
if first:
first = False
else:
- print ' g_pLog->Text(", ");'
+ print ' Log::Text(", ");'
type.dump('(%s).%s' % (instance, name))
- print ' g_pLog->Text("}");'
+ print ' Log::Text("}");'
class Alias(Type):
else:
print ' %s result;' % method.type
result = 'result = '
- print ' g_pLog->BeginCall("%s");' % (self.name + '::' + method.name)
- print ' g_pLog->BeginParam("this", "%s *");' % self.name
- print ' g_pLog->TextF("%p", m_pInstance);'
- print ' g_pLog->EndParam();'
+ print ' Log::BeginCall("%s");' % (self.name + '::' + method.name)
+ print ' Log::BeginParam("this", "%s *");' % self.name
+ print ' Log::TextF("%p", m_pInstance);'
+ print ' Log::EndParam();'
for type, name in method.args:
if not type.isoutput():
type.unwrap_instance(name)
- print ' g_pLog->BeginParam("%s", "%s");' % (name, type)
+ print ' Log::BeginParam("%s", "%s");' % (name, type)
type.dump(name)
- print ' g_pLog->EndParam();'
+ print ' Log::EndParam();'
print ' %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(name) for type, name in method.args]))
for type, name in method.args:
if type.isoutput():
- print ' g_pLog->BeginParam("%s", "%s");' % (name, type)
+ print ' Log::BeginParam("%s", "%s");' % (name, type)
type.dump(name)
- print ' g_pLog->EndParam();'
+ print ' Log::EndParam();'
type.wrap_instance(name)
if method.type is not Void:
- print ' g_pLog->BeginReturn("%s");' % method.type
+ print ' Log::BeginReturn("%s");' % method.type
method.type.dump("result")
- print ' g_pLog->EndReturn();'
+ print ' Log::EndReturn();'
method.type.wrap_instance('result')
- print ' g_pLog->EndCall();'
+ print ' Log::EndCall();'
if method.name == 'QueryInterface':
print ' if(*ppvObj == m_pInstance)'
print ' *ppvObj = this;'
****************************************************************************/
+#include <stdio.h>
+
#include "log.hpp"
-File::File(const TCHAR *szName, const TCHAR *szExtension) {
- m_hFile = INVALID_HANDLE_VALUE;
- Open(szName, szExtension);
-}
+namespace Log {
+
-File::~File() {
- Close();
+static HANDLE g_hFile = INVALID_HANDLE_VALUE;
+static TCHAR g_szFileName[MAX_PATH];
+
+static void _Close(void) {
+ if(g_hFile != INVALID_HANDLE_VALUE) {
+ CloseHandle(g_hFile);
+ g_hFile = INVALID_HANDLE_VALUE;
+ }
}
-void File::Open(const TCHAR *szName, const TCHAR *szExtension) {
- Close();
+static void _Open(const TCHAR *szName, const TCHAR *szExtension) {
+ _Close();
DWORD dwCounter = 0;
do {
if(dwCounter)
- _sntprintf(szFileName, MAX_PATH, TEXT("%s.%u.%s"), szName, dwCounter, szExtension);
+ _sntprintf(g_szFileName, MAX_PATH, TEXT("%s.%u.%s"), szName, dwCounter, szExtension);
else
- _sntprintf(szFileName, MAX_PATH, TEXT("%s.%s"), szName, szExtension);
+ _sntprintf(g_szFileName, MAX_PATH, TEXT("%s.%s"), szName, szExtension);
- m_hFile = CreateFile(szFileName,
+ g_hFile = CreateFile(g_szFileName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
FILE_ATTRIBUTE_NORMAL,
NULL);
++dwCounter;
- } while(m_hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS);
+ } while(g_hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS);
}
-void File::ReOpen(void) {
- Close();
+static void _ReOpen(void) {
+ _Close();
- m_hFile = CreateFile(szFileName,
+ g_hFile = CreateFile(g_szFileName,
GENERIC_WRITE,
- 0,
+ FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
}
-void File::Close(void) {
- if(m_hFile != INVALID_HANDLE_VALUE) {
- CloseHandle(m_hFile);
- m_hFile = INVALID_HANDLE_VALUE;
- }
-}
-
-void File::Write(const char *szText) {
- if(m_hFile == INVALID_HANDLE_VALUE)
+static void Write(const char *szText) {
+ if(g_hFile == INVALID_HANDLE_VALUE)
return;
DWORD dwBytesToWrite = (DWORD)strlen(szText);
overlapped.Offset = 0xffffffff;
overlapped.OffsetHigh = 0xffffffff;
- if(WriteFile(m_hFile,
+ if(WriteFile(g_hFile,
szText + dwBytesWritten,
dwBytesToWrite - dwBytesWritten,
&dwBytesWritten,
&overlapped) == FALSE) {
- Close();
- Open(TEXT("extra"), TEXT("xml"));
+ _Close();
+ _Open(TEXT("extra"), TEXT("xml"));
return;
}
}
}
-Log::Log(const TCHAR *szName) : File(szName, TEXT("xml")) {
+void Open(const TCHAR *szName) {
+ _Open(szName, TEXT("xml"));
Write("<?xml version='1.0' encoding='UTF-8'?>");
NewLine();
Write("<?xml-stylesheet type='text/xsl' href='d3dtrace.xsl'?>");
NewLine();
}
-Log::~Log() {
+void ReOpen(void) {
+ _ReOpen();
+}
+
+void Close(void) {
Write("</trace>");
NewLine();
+ _Close();
+}
+
+static void Escape(const char *s) {
+ /* FIXME */
+ Write(s);
}
-void Log::NewLine(void) {
+void NewLine(void) {
Write("\r\n");
}
-void Log::Tag(const char *name) {
+void Tag(const char *name) {
Write("<");
Write(name);
Write("/>");
}
-void Log::BeginTag(const char *name) {
+void BeginTag(const char *name) {
Write("<");
Write(name);
Write(">");
}
-void Log::BeginTag(const char *name,
+void BeginTag(const char *name,
const char *attr1, const char *value1) {
Write("<");
Write(name);
Write("\">");
}
-void Log::BeginTag(const char *name,
+void BeginTag(const char *name,
const char *attr1, const char *value1,
const char *attr2, const char *value2) {
Write("<");
Write("\">");
}
-void Log::EndTag(const char *name) {
+void EndTag(const char *name) {
Write("</");
Write(name);
Write(">");
}
-void Log::Text(const char *text) {
+void Text(const char *text) {
Escape(text);
}
-void Log::TextF(const char *format, ...) {
+void TextF(const char *format, ...) {
char szBuffer[4196];
va_list ap;
va_start(ap, format);
Escape(szBuffer);
}
-void Log::BeginCall(const char *function) {
+void BeginCall(const char *function) {
Write("\t");
BeginTag("call", "name", function);
NewLine();
}
-void Log::EndCall(void) {
+void EndCall(void) {
Write("\t");
EndTag("call");
NewLine();
}
-void Log::BeginParam(const char *name, const char *type) {
+void BeginParam(const char *name, const char *type) {
Write("\t\t");
BeginTag("param", "name", name, "type", type);
}
-void Log::EndParam(void) {
+void EndParam(void) {
EndTag("param");
NewLine();
}
-void Log::BeginReturn(const char *type) {
+void BeginReturn(const char *type) {
Write("\t\t");
BeginTag("return", "type", type);
}
-void Log::EndReturn(void) {
+void EndReturn(void) {
EndTag("return");
NewLine();
}
-void Log::Escape(const char *s) {
- /* FIXME */
- Write(s);
-}
-
-Log * g_pLog = NULL;
+} /* namespace Log */
\ No newline at end of file
#include <windows.h>
#include <tchar.h>
-#include <stdio.h>
-class File
-{
-public:
- File(const TCHAR *szName, const TCHAR *szExtension);
- ~File();
+namespace Log {
- void Open(const TCHAR *szName, const TCHAR *szExtension);
+ void Open(const TCHAR *szName);
void ReOpen(void);
void Close(void);
- void Write(const char *szText);
-
-private:
- HANDLE m_hFile;
- TCHAR szFileName[MAX_PATH];
-};
-
-
-class Log : public File
-{
-public:
- Log(const TCHAR *szName);
- ~Log();
void NewLine(void);
void Tag(const char *name);
void EndParam(void);
void BeginReturn(const char *type);
void EndReturn(void);
-
-protected:
- void Escape(const char *s);
-};
-
-
-extern Log * g_pLog;
-
+}
#endif /* _LOG_HPP_ */
def wrap_impl(self):
print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
- #print r' Log * pLog;'
print r' switch(fdwReason) {'
print r' case DLL_PROCESS_ATTACH:'
print r' if(!GetSystemDirectory(g_szDll, MAX_PATH))'
print r' return FALSE;'
print r' _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
- #print r' if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)'
- #print r' return FALSE;'
- #print r' if(!g_pLog)'
- #print r' g_pLog = new Log(TEXT("%s"));' % self.name
print r' case DLL_THREAD_ATTACH:'
- #print r' pLog = new Log(TEXT("%s"));' % self.name
- #print r' TlsSetValue(dwTlsIndex, pLog);'
print r' return TRUE;'
print r' case DLL_THREAD_DETACH:'
- #print r' pLog = (Log *)TlsGetValue(dwTlsIndex);'
- #print r' if (pLog != NULL)'
- #print r' delete pLog;'
print r' return TRUE;'
print r' case DLL_PROCESS_DETACH:'
- #print r' pLog = (Log *)TlsGetValue(dwTlsIndex);'
- #print r' if (pLog != NULL)'
- #print r' delete pLog;'
- #print r' TlsFree(dwTlsIndex);'
- print r' if(g_pLog) {'
- print r' delete g_pLog;'
- print r' g_pLog = NULL;'
- print r' }'
+ print r' Log::Close();'
print r' if(g_hDll) {'
print r' FreeLibrary(g_hDll);'
print r' g_hDll = NULL;'
type = 'P' + function.name
print function.prototype() + ' {'
if 1:
- print ' if(g_pLog)'
- print ' delete g_pLog;'
- print ' g_pLog = new Log(TEXT("%s"));' % self.name
- #print ' g_pLog->ReOpen();'
+ print ' Log::Close();'
+ print ' Log::Open(TEXT("%s"));' % self.name
+ #print ' Log::ReOpen();'
print ' typedef ' + function.prototype('* %s' % type) + ';'
print ' %s pFunction;' % type
if function.type is Void:
print ' pFunction = (%s)GetProcAddress( g_hDll, "%s");' % (type, function.name)
print ' if(!pFunction)'
print ' ExitProcess(0);'
- print ' g_pLog->BeginCall("%s");' % (function.name)
+ print ' Log::BeginCall("%s");' % (function.name)
print ' %spFunction(%s);' % (result, ', '.join([str(name) for type, name in function.args]))
- print ' g_pLog->EndCall();'
+ print ' Log::EndCall();'
for type, name in function.args:
if type.isoutput():
type.wrap_instance(name)