swift
crashhandler.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_CRASHHANDLER_H
7 #define SWIFT_MISC_CRASHHANDLER_H
8 
9 #include <memory>
10 
11 #include "misc/crashinfo.h"
12 #include "misc/digestsignal.h"
13 #include "misc/swiftmiscexport.h"
14 
15 namespace crashpad
16 {
17  class CrashpadClient;
18  class CrashReportDatabase;
19 } // namespace crashpad
20 
21 namespace swift::misc
22 {
24  class SWIFT_MISC_EXPORT CCrashHandler : public QObject
25  {
26  Q_OBJECT
27 
28  public:
30  static CCrashHandler *instance();
31 
33  virtual ~CCrashHandler();
34 
36  void init();
37 
39  void setUploadsEnabled(bool enable);
40 
42  bool isCrashDumpUploadEnabled() const;
43 
44  // ----------------------- Crash info ---------------------------------
45 
47  void setCrashInfo(const swift::misc::CCrashInfo &info);
48 
50  void crashAndLogInfoUserName(const QString &name);
51 
53  void crashAndLogInfoSimulator(const QString &simulator);
54 
56  void crashAndLogInfoFlightNetwork(const QString &flightNetwork);
57 
59  void crashAndLogAppendInfo(const QString &info);
60 
62  const swift::misc::CCrashInfo &getCrashInfo() const { return m_crashAndLogInfo; }
63 
65  void simulateCrash();
66 
68  void simulateAssert();
69 
70  private:
71  CCrashHandler(QObject *parent = nullptr);
72 
73  // crash info
74  void triggerCrashInfoWrite();
75 
76  swift::misc::CCrashInfo m_crashAndLogInfo;
77  CDigestSignal m_dsCrashAndLogInfo { this, &CCrashHandler::triggerCrashInfoWrite,
78  std::chrono::milliseconds(10000), 5 };
79 
80 #ifdef SWIFT_USE_CRASHPAD
81  std::unique_ptr<crashpad::CrashpadClient> m_crashpadClient;
82  std::unique_ptr<crashpad::CrashReportDatabase> m_crashReportDatabase;
83 #endif
84  };
85 } // namespace swift::misc
86 
87 #endif // SWIFT_MISC_CRASHHANDLER_H
const swift::misc::CCrashInfo & getCrashInfo() const
Get crash info.
Definition: crashhandler.h:62
Receive 1..n signals, collect them over time, and resend afer n milliseconds.
Definition: digestsignal.h:18
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.