TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DumpContext.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TDumpContext
 

Macros

#define CASC_DUMP_BUFFER_SIZE   0x10000
 

Functions

TDumpContextCreateDumpContext (struct _TCascStorage *hs, const TCHAR *szNameFormat)
 
int dump_print (TDumpContext *dc, const char *szFormat,...)
 
int dump_close (TDumpContext *dc)
 

Macro Definition Documentation

#define CASC_DUMP_BUFFER_SIZE   0x10000

Function Documentation

TDumpContext* CreateDumpContext ( struct _TCascStorage hs,
const TCHAR szNameFormat 
)
57 {
58  TDumpContext * dc;
59  TCHAR * szFileName;
60 
61  // Validate the storage handle
62  if(hs != NULL)
63  {
64  // Calculate the number of bytes needed for dump context
65  dc = CASC_ALLOC(TDumpContext, 1);
66  if(dc != NULL)
67  {
68  // Initialize the dump context
69  memset(dc, 0, sizeof(TDumpContext));
70 
71  // Format the real file name
72  szFileName = FormatFileName(hs, szNameFormat);
73  if(szFileName != NULL)
74  {
75  // Create the file
76  dc->pStream = FileStream_CreateFile(szFileName, 0);
77  if(dc->pStream != NULL)
78  {
79  // Initialize buffers
80  dc->pbBufferBegin =
81  dc->pbBufferPtr = dc->DumpBuffer;
83 
84  // Success
85  CASC_FREE(szFileName);
86  return dc;
87  }
88 
89  // File create failed --> delete the file name
90  CASC_FREE(szFileName);
91  }
92 
93  // Free the dump context
94  CASC_FREE(dc);
95  }
96  }
97 
98  return NULL;
99 }
TFileStream * FileStream_CreateFile(const TCHAR *szFileName, DWORD dwStreamFlags)
Definition: FileStream.cpp:2328
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
static TCHAR * FormatFileName(TCascStorage *hs, const TCHAR *szNameFormat)
Definition: DumpContext.cpp:18
LPBYTE pbBufferPtr
Definition: DumpContext.h:25
arena_t NULL
Definition: jemalloc_internal.h:624
char TCHAR
Definition: CascPort.h:148
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
Definition: DumpContext.h:21
LPBYTE pbBufferEnd
Definition: DumpContext.h:26
LPBYTE pbBufferBegin
Definition: DumpContext.h:24
BYTE DumpBuffer[CASC_DUMP_BUFFER_SIZE]
Definition: DumpContext.h:28
#define CASC_DUMP_BUFFER_SIZE
Definition: DumpContext.h:18
TFileStream * pStream
Definition: DumpContext.h:23

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int dump_close ( TDumpContext dc)
137 {
138  // Only if the dump context is valid
139  if(dc != NULL)
140  {
141  // Flush the dump context if there are some data
142  if(dc->pbBufferPtr > dc->pbBufferBegin)
144  dc->pbBufferPtr = dc->pbBufferBegin;
145 
146  // Free the file stream and the entire context
147  if(dc->pStream != NULL)
149  CASC_FREE(dc);
150  }
151 
152  return 0;
153 }
LPBYTE pbBufferPtr
Definition: DumpContext.h:25
arena_t NULL
Definition: jemalloc_internal.h:624
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
void FileStream_Close(TFileStream *pStream)
Definition: FileStream.cpp:2707
unsigned int DWORD
Definition: CascPort.h:139
LPBYTE pbBufferBegin
Definition: DumpContext.h:24
bool FileStream_Write(TFileStream *pStream, ULONGLONG *pByteOffset, const void *pvBuffer, DWORD dwBytesToWrite)
Definition: FileStream.cpp:2577
TFileStream * pStream
Definition: DumpContext.h:23

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int dump_print ( TDumpContext dc,
const char *  szFormat,
  ... 
)
102 {
103  va_list argList;
104  char szBuffer[0x200];
105  int nLength = 0;
106 
107  // Only if the dump context is valid
108  if(dc != NULL)
109  {
110  // Print the buffer using sprintf
111  va_start(argList, szFormat);
112  nLength = vsprintf(szBuffer, szFormat, argList);
113  assert(nLength < 0x200);
114  va_end(argList);
115 
116  // Copy the string. Replace "\n" with "\n\r"
117  for(int i = 0; i < nLength; i++)
118  {
119  // Flush the buffer, if needed
120  if((dc->pbBufferPtr + 2) >= dc->pbBufferEnd)
121  {
123  dc->pbBufferPtr = dc->pbBufferBegin;
124  }
125 
126  // Copy the char
127  if(szBuffer[i] == 0x0A)
128  *dc->pbBufferPtr++ = 0x0D;
129  *dc->pbBufferPtr++ = szBuffer[i];
130  }
131  }
132 
133  return nLength;
134 }
LPBYTE pbBufferPtr
Definition: DumpContext.h:25
arena_t NULL
Definition: jemalloc_internal.h:624
LPBYTE pbBufferEnd
Definition: DumpContext.h:26
unsigned int DWORD
Definition: CascPort.h:139
LPBYTE pbBufferBegin
Definition: DumpContext.h:24
bool FileStream_Write(TFileStream *pStream, ULONGLONG *pByteOffset, const void *pvBuffer, DWORD dwBytesToWrite)
Definition: FileStream.cpp:2577
TFileStream * pStream
Definition: DumpContext.h:23

+ Here is the call graph for this function: