VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBugReport/VBoxBugReport.h@ 59527

Last change on this file since 59527 was 59494, checked in by vboxsync, 9 years ago

make VBoxBugReport public

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/* $Id: VBoxBugReport.h 59494 2016-01-27 15:52:01Z vboxsync $ */
2/** @file
3 * VBoxBugReport - VirtualBox command-line diagnostics tool, internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___H_VBOXBUGREPORT
19#define ___H_VBOXBUGREPORT
20
21/*
22 * Introduction.
23 *
24 * In the most general sense a bug report is a collection of data obtained from
25 * the user's host system. It may include files common for all VMs, like the
26 * VBoxSVC.log file, as well as files related to particular machines. It may
27 * also contain the output of commands executed on the host, as well as data
28 * collected via OS APIs.
29 */
30
31/* @todo not sure if using a separate namespace would be beneficial */
32
33#include <iprt/path.h>
34#include <iprt/stream.h>
35#include <iprt/tar.h>
36#include <iprt/vfs.h>
37
38#ifdef RT_OS_WINDOWS
39#define VBOXMANAGE "VBoxManage.exe"
40#else /* !RT_OS_WINDOWS */
41#define VBOXMANAGE "VBoxManage"
42#endif /* !RT_OS_WINDOWS */
43
44/* Base */
45
46inline void handleRtError(int rc, const char *pszMsgFmt, ...)
47{
48 if (RT_FAILURE(rc))
49 {
50 va_list va;
51 va_start(va, pszMsgFmt);
52 RTCString msgArgs(pszMsgFmt, va);
53 va_end(va);
54 RTCStringFmt msg("%s (rc=%d)\n", msgArgs.c_str(), rc);
55 throw RTCError(msg.c_str());
56 }
57}
58
59inline void handleComError(HRESULT hr, const char *pszMsgFmt, ...)
60{
61 if (FAILED(hr))
62 {
63 va_list va;
64 va_start(va, pszMsgFmt);
65 RTCString msgArgs(pszMsgFmt, va);
66 va_end(va);
67 RTCStringFmt msg("%s (hr=0x%x)\n", msgArgs.c_str(), hr);
68 throw RTCError(msg.c_str());
69 }
70}
71
72/*
73 * An abstract class serving as the root of the bug report item tree.
74 */
75class BugReportItem
76{
77public:
78 BugReportItem(const char *pszTitle);
79 virtual ~BugReportItem();
80 virtual const char *getTitle(void);
81 virtual PRTSTREAM getStream(void) = 0;
82private:
83 char *m_pszTitle;
84};
85
86/*
87 * An abstract class to serve as a base class for all report types.
88 */
89class BugReport
90{
91public:
92 BugReport(const char *pszFileName);
93 virtual ~BugReport();
94 virtual int addItem(BugReportItem* item) = 0;
95 virtual void complete(void) = 0;
96protected:
97 char *m_pszFileName;
98};
99
100/*
101 * An auxiliary class providing formatted output into a temporary file for item
102 * classes that obtain data via host OS APIs.
103 */
104class BugReportStream : public BugReportItem
105{
106public:
107 BugReportStream(const char *pszTitle);
108 virtual ~BugReportStream();
109 virtual PRTSTREAM getStream(void);
110protected:
111 int printf(const char *pszFmt, ...);
112 int putStr(const char *pszString);
113private:
114 PRTSTREAM m_Strm;
115 char m_szFileName[RTPATH_MAX];
116};
117
118
119/*
120 * This class provides a platform-agnostic way to create platform-specific item
121 * objects.
122 *
123 * @todo At the moment it is capable of creating a single object, the one
124 * intended to collect network adapter data. There will be more later.
125 *
126 * @todo Make an abstract class if enough platform-specific factories implemented.
127 */
128class BugReportItemFactory
129{
130public:
131 virtual BugReportItem *createNetworkAdapterReport(void) { return NULL; };
132};
133
134
135
136/* Generic */
137
138/*
139 * This class reports everything into a single text file.
140 */
141class BugReportText : public BugReport
142{
143public:
144 BugReportText(const char *pszFileName);
145 virtual ~BugReportText();
146 virtual int addItem(BugReportItem* item);
147 virtual void complete(void) {};
148private:
149 PRTSTREAM m_StrmTxt;
150};
151
152/*
153 * This class reports items as individual files archived into a single compressed TAR file.
154 */
155class BugReportTarGzip : public BugReport
156{
157public:
158 BugReportTarGzip(const char *pszFileName);
159 virtual ~BugReportTarGzip();
160 virtual int addItem(BugReportItem* item);
161 virtual void complete(void);
162private:
163 /*
164 * Helper class to release handles going out of scope.
165 */
166 class VfsIoStreamHandle
167 {
168 public:
169 VfsIoStreamHandle() : m_hVfsStream(NIL_RTVFSIOSTREAM) {};
170 ~VfsIoStreamHandle() { release(); }
171 PRTVFSIOSTREAM getPtr(void) { return &m_hVfsStream; };
172 RTVFSIOSTREAM get(void) { return m_hVfsStream; };
173 void release(void)
174 {
175 if (m_hVfsStream != NIL_RTVFSIOSTREAM)
176 RTVfsIoStrmRelease(m_hVfsStream);
177 m_hVfsStream = NIL_RTVFSIOSTREAM;
178 };
179 private:
180 RTVFSIOSTREAM m_hVfsStream;
181 };
182
183 VfsIoStreamHandle m_hVfsGzip;
184
185 RTTAR m_hTar;
186 RTTARFILE m_hTarFile;
187 char m_szTarName[RTPATH_MAX];
188};
189
190/*
191 * BugReportFile adds a file as an item to a report.
192 */
193class BugReportFile : public BugReportItem
194{
195public:
196 BugReportFile(const char *pszPath, const char *pcszName);
197 virtual ~BugReportFile();
198 virtual PRTSTREAM getStream(void);
199
200private:
201 char *m_pszPath;
202 PRTSTREAM m_Strm;
203};
204
205/*
206 * A base class for item classes that collect CLI output.
207 */
208class BugReportCommand : public BugReportItem
209{
210public:
211 BugReportCommand(const char *pszTitle, const char *pszExec, ...);
212 virtual ~BugReportCommand();
213 virtual PRTSTREAM getStream(void);
214private:
215 PRTSTREAM m_Strm;
216 char m_szFileName[RTPATH_MAX];
217 char *m_papszArgs[32];
218};
219
220
221/* Platform-specific */
222
223BugReportItemFactory *createBugReportItemFactory(void);
224
225#endif /* !___H_VBOXBUGREPORT */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette