1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of wxDebugReport class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_DEBUGRPT_H_
12 #define _WX_DEBUGRPT_H_
18 class WXDLLIMPEXP_XML wxXmlNode
;
20 // ----------------------------------------------------------------------------
21 // wxDebugReport: generate a debug report, processing is done in derived class
22 // ----------------------------------------------------------------------------
24 class WXDLLIMPEXP_QA wxDebugReport
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_Curent
, Context_Exception
};
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
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();
40 // return the name of the directory used for this report
41 const wxString
& GetDirectory() const { return m_dir
; }
43 // return true if the object was successfully initialized
44 bool IsOk() const { return !GetDirectory().empty(); }
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(); }
51 // add another file to the report: the file must already exist, its name is
52 // relative to GetDirectory()
54 // description is shown to the user in the report summary
55 virtual void AddFile(const wxString
& name
, const wxString
& description
);
57 // add an XML file containing the current or exception context and the
59 bool AddCurrentContext() { return AddContext(Context_Curent
); }
60 bool AddExceptionContext() { return AddContext(Context_Exception
); }
61 virtual bool AddContext(Context ctx
);
64 // add a file with crash report
65 bool AddCurrentDump() { return AddDump(Context_Curent
); }
66 bool AddExceptionDump() { return AddDump(Context_Exception
); }
67 virtual bool AddDump(Context ctx
);
68 #endif // wxUSE_CRASHREPORT
70 // add all available information to the report
71 void AddAll(Context context
= Context_Exception
);
74 // process this report: the base class simply notifies the user that the
75 // report has been generated, this is usually not enough -- instead you
76 // should override this method to do something more useful to you
79 // get the name used as base name for various files, by default
81 virtual wxString
GetReportName() const;
83 // get the files in this report
84 size_t GetFilesCount() const { return m_files
.GetCount(); }
85 bool GetFile(size_t n
, wxString
*name
, wxString
*desc
) const;
87 // remove the file from report: this is used by wxDebugReportPreview to
88 // allow the user to remove files potentially containing private
89 // information from the report
90 void RemoveFile(const wxString
& name
);
93 // used by AddContext()
94 virtual bool DoAddSystemInfo(wxXmlNode
*nodeSystemInfo
);
95 virtual bool DoAddLoadedModules(wxXmlNode
*nodeModules
);
96 virtual bool DoAddExceptionInfo(wxXmlNode
*nodeContext
);
97 virtual void DoAddCustomContext(wxXmlNode
* WXUNUSED(nodeRoot
)) { }
100 virtual bool DoProcess();
103 // name of the report directory
106 // the arrays of files in this report and their descriptions
107 wxArrayString m_files
,
113 // ----------------------------------------------------------------------------
114 // wxDebugReportCompress: compress all files of this debug report in a .ZIP
115 // ----------------------------------------------------------------------------
117 class WXDLLIMPEXP_QA wxDebugReportCompress
: public wxDebugReport
120 wxDebugReportCompress() { }
122 // returns the full path of the compressed file (empty if creation failed)
123 const wxString
& GetCompressedFileName() const { return m_zipfile
; }
126 virtual bool DoProcess();
129 // full path to the ZIP file we created
133 // ----------------------------------------------------------------------------
134 // wxDebugReportUploader: uploads compressed file using HTTP POST request
135 // ----------------------------------------------------------------------------
137 class WXDLLIMPEXP_QA wxDebugReportUpload
: public wxDebugReportCompress
140 // this class will upload the compressed file created by its base class to
141 // an HTML multipart/form-data form at the specified address
143 // the URL is the base address, input is the name of the "type=file"
144 // control on the form used for the file name and action is the value of
145 // the form action field
146 wxDebugReportUpload(const wxString
& url
,
147 const wxString
& input
,
148 const wxString
& action
,
149 const wxString
& curl
= _T("curl"));
152 virtual bool DoProcess();
154 // this function may be overridden in a derived class to show the output
155 // from curl: this may be an HTML page or anything else that the server
158 // return value becomes the return value of Process()
159 virtual bool OnServerReply(const wxArrayString
& WXUNUSED(reply
))
165 // the full URL to use with HTTP POST request
166 wxString m_uploadURL
;
168 // the name of the input field containing the file name in the form at
170 wxString m_inputField
;
172 // the curl command (by default it is just "curl" but could be full path to
173 // curl or a wrapper script with curl-compatible syntax)
177 #endif // wxUSE_ZIPSTREAM
180 // ----------------------------------------------------------------------------
181 // wxDebugReportPreview: presents the debug report to the user and allows him
182 // to veto report entirely or remove some parts of it
183 // ----------------------------------------------------------------------------
185 class WXDLLIMPEXP_QA wxDebugReportPreview
189 wxDebugReportPreview() { }
191 // present the report to the user and allow him to modify it by removing
192 // some or all of the files and, potentially, adding some notes
194 // return true if the report should be processed or false if the user chose
195 // to cancel report generation or removed all files from it
196 virtual bool Show(wxDebugReport
& dbgrpt
) const = 0;
198 // dtor is trivial as well but should be virtual for a base class
199 virtual ~wxDebugReportPreview() { }
204 // ----------------------------------------------------------------------------
205 // wxDebugReportPreviewStd: standard debug report preview window
206 // ----------------------------------------------------------------------------
208 class WXDLLIMPEXP_QA wxDebugReportPreviewStd
: public wxDebugReportPreview
211 wxDebugReportPreviewStd() { }
213 virtual bool Show(wxDebugReport
& dbgrpt
) const;
218 #endif // wxUSE_DEBUGREPORT
220 #endif // _WX_DEBUGRPT_H_