]> git.saurik.com Git - wxWidgets.git/blob - include/wx/debugrpt.h
added WM_PRINTCLIENT
[wxWidgets.git] / include / wx / debugrpt.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/debugrpt.h
3 // Purpose: declaration of wxDebugReport class
4 // Author: Vadim Zeitlin
5 // Created: 2005-01-17
6 // RCS-ID: $Id$
7 // Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_DEBUGRPT_H_
12 #define _WX_DEBUGRPT_H_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_DEBUGREPORT
17
18 class WXDLLIMPEXP_XML wxXmlNode;
19
20 // ----------------------------------------------------------------------------
21 // wxDebugReport: generate a debug report, processing is done in derived class
22 // ----------------------------------------------------------------------------
23
24 class WXDLLIMPEXP_QA wxDebugReport
25 {
26 public:
27 // this is used for the functions which may report either the current state
28 // or the state during the last (fatal) exception
29 enum Context { Context_Current, Context_Exception };
30
31
32 // ctor creates a temporary directory where we create the files which will
33 // be included in the report, use IsOk() to check for errors
34 wxDebugReport();
35
36 // dtor normally destroys the temporary directory created in the ctor (with
37 // all the files it contains), call Reset() to prevent this from happening
38 virtual ~wxDebugReport();
39
40 // return the name of the directory used for this report
41 const wxString& GetDirectory() const { return m_dir; }
42
43 // return true if the object was successfully initialized
44 bool IsOk() const { return !GetDirectory().empty(); }
45
46 // reset the directory name we use, the object can't be used any more after
47 // this as it becomes invalid/uninitialized
48 void Reset() { m_dir.clear(); }
49
50
51 // add another file to the report: the file must already exist, its name is
52 // relative to GetDirectory()
53 //
54 // description is shown to the user in the report summary
55 virtual void AddFile(const wxString& name, const wxString& description);
56
57 // convenience function: write the given text to a file with the given name
58 // and then add it to the report (the difference with AddFile() is that the
59 // file will be created by this function and doesn't have to already exist)
60 bool AddText(const wxString& name,
61 const wxString& text,
62 const wxString& description);
63
64 #if wxUSE_STACKWALKER
65 // add an XML file containing the current or exception context and the
66 // stack trace
67 bool AddCurrentContext() { return AddContext(Context_Current); }
68 bool AddExceptionContext() { return AddContext(Context_Exception); }
69 virtual bool AddContext(Context ctx);
70 #endif
71
72 #if wxUSE_CRASHREPORT
73 // add a file with crash report
74 bool AddCurrentDump() { return AddDump(Context_Current); }
75 bool AddExceptionDump() { return AddDump(Context_Exception); }
76 virtual bool AddDump(Context ctx);
77 #endif // wxUSE_CRASHREPORT
78
79 // add all available information to the report
80 void AddAll(Context context = Context_Exception);
81
82
83 // process this report: the base class simply notifies the user that the
84 // report has been generated, this is usually not enough -- instead you
85 // should override this method to do something more useful to you
86 bool Process();
87
88 // get the name used as base name for various files, by default
89 // wxApp::GetName()
90 virtual wxString GetReportName() const;
91
92 // get the files in this report
93 size_t GetFilesCount() const { return m_files.GetCount(); }
94 bool GetFile(size_t n, wxString *name, wxString *desc) const;
95
96 // remove the file from report: this is used by wxDebugReportPreview to
97 // allow the user to remove files potentially containing private
98 // information from the report
99 void RemoveFile(const wxString& name);
100
101 protected:
102 #if wxUSE_STACKWALKER
103 // used by AddContext()
104 virtual bool DoAddSystemInfo(wxXmlNode *nodeSystemInfo);
105 virtual bool DoAddLoadedModules(wxXmlNode *nodeModules);
106 virtual bool DoAddExceptionInfo(wxXmlNode *nodeContext);
107 virtual void DoAddCustomContext(wxXmlNode * WXUNUSED(nodeRoot)) { }
108 #endif
109
110 // used by Process()
111 virtual bool DoProcess();
112
113 private:
114 // name of the report directory
115 wxString m_dir;
116
117 // the arrays of files in this report and their descriptions
118 wxArrayString m_files,
119 m_descriptions;
120 };
121
122 #if wxUSE_ZIPSTREAM
123
124 // ----------------------------------------------------------------------------
125 // wxDebugReportCompress: compress all files of this debug report in a .ZIP
126 // ----------------------------------------------------------------------------
127
128 class WXDLLIMPEXP_QA wxDebugReportCompress : public wxDebugReport
129 {
130 public:
131 wxDebugReportCompress() { }
132
133 // returns the full path of the compressed file (empty if creation failed)
134 const wxString& GetCompressedFileName() const { return m_zipfile; }
135
136 protected:
137 virtual bool DoProcess();
138
139 private:
140 // full path to the ZIP file we created
141 wxString m_zipfile;
142 };
143
144 // ----------------------------------------------------------------------------
145 // wxDebugReportUploader: uploads compressed file using HTTP POST request
146 // ----------------------------------------------------------------------------
147
148 class WXDLLIMPEXP_QA wxDebugReportUpload : public wxDebugReportCompress
149 {
150 public:
151 // this class will upload the compressed file created by its base class to
152 // an HTML multipart/form-data form at the specified address
153 //
154 // the URL is the base address, input is the name of the "type=file"
155 // control on the form used for the file name and action is the value of
156 // the form action field
157 wxDebugReportUpload(const wxString& url,
158 const wxString& input,
159 const wxString& action,
160 const wxString& curl = _T("curl"));
161
162 protected:
163 virtual bool DoProcess();
164
165 // this function may be overridden in a derived class to show the output
166 // from curl: this may be an HTML page or anything else that the server
167 // returned
168 //
169 // return value becomes the return value of Process()
170 virtual bool OnServerReply(const wxArrayString& WXUNUSED(reply))
171 {
172 return true;
173 }
174
175 private:
176 // the full URL to use with HTTP POST request
177 wxString m_uploadURL;
178
179 // the name of the input field containing the file name in the form at
180 // above URL
181 wxString m_inputField;
182
183 // the curl command (by default it is just "curl" but could be full path to
184 // curl or a wrapper script with curl-compatible syntax)
185 wxString m_curlCmd;
186 };
187
188 #endif // wxUSE_ZIPSTREAM
189
190
191 // ----------------------------------------------------------------------------
192 // wxDebugReportPreview: presents the debug report to the user and allows him
193 // to veto report entirely or remove some parts of it
194 // ----------------------------------------------------------------------------
195
196 class WXDLLIMPEXP_QA wxDebugReportPreview
197 {
198 public:
199 // ctor is trivial
200 wxDebugReportPreview() { }
201
202 // present the report to the user and allow him to modify it by removing
203 // some or all of the files and, potentially, adding some notes
204 //
205 // return true if the report should be processed or false if the user chose
206 // to cancel report generation or removed all files from it
207 virtual bool Show(wxDebugReport& dbgrpt) const = 0;
208
209 // dtor is trivial as well but should be virtual for a base class
210 virtual ~wxDebugReportPreview() { }
211 };
212
213 #if wxUSE_GUI
214
215 // ----------------------------------------------------------------------------
216 // wxDebugReportPreviewStd: standard debug report preview window
217 // ----------------------------------------------------------------------------
218
219 class WXDLLIMPEXP_QA wxDebugReportPreviewStd : public wxDebugReportPreview
220 {
221 public:
222 wxDebugReportPreviewStd() { }
223
224 virtual bool Show(wxDebugReport& dbgrpt) const;
225 };
226
227 #endif // wxUSE_GUI
228
229 #endif // wxUSE_DEBUGREPORT
230
231 #endif // _WX_DEBUGRPT_H_
232