VAPOR3 3.9.4
ErrorReporter.h
Go to the documentation of this file.
1//************************************************************************
2// *
3// Copyright (C) 2017 *
4// University Corporation for Atmospheric Research *
5// All Rights Reserved *
6// *
7//************************************************************************
8//
9// File: ErrorReporter.h
10//
11// Author: Stas Jaroszynski (stasj@ucar.edu)
12// National Center for Atmospheric Research
13// PO 3000, Boulder, Colorado
14//
15// Date: July 2017
16//
17// Description: Defines the ErrorReporting class. This is used for
18// posting various messages that can occur during the operation of the Vapor GUI
19// This is a singleton class that registers callbacks with the Vapor error api
20// and keeps tracks of errors that occur. The GUI can then invoke an error message
21// which will display the GUI provided message and provide a details area which
22// contains the full error log accumilated since the last error message which can
23// be saved to a text file.
24// This class also registeres a signal handler for SIGSEGV and displays an error
25// window with the current backtrace.
26
27#ifndef ERRORREPORTER_H
28#define ERRORREPORTER_H
29
30#include <string>
31#include <vector>
32#include "vapor/VAssert.h"
33#include <QMessageBox>
34
41
42class ErrorReporterPopup : public QMessageBox {
43 Q_OBJECT;
44
45public:
46 ErrorReporterPopup(QWidget *parent, int id, bool fatal = false);
47 void setLogText(std::string text);
48 bool isDead() const { return dead; };
49
50private slots:
51 void doAction(QAbstractButton *button);
52
53private:
54 bool dead, fatal;
55 std::string _logText;
56};
57
58#define ERRORREPORTER_DEFAULT_MESSAGE "The action failed"
59
66
69
70#define MSG_ERR(M) (ErrorReporter::GetInstance()->Report(M, ErrorReporter::Error))
71
72#define MSG_WARN(M) (ErrorReporter::GetInstance()->Report(M, ErrorReporter::Warning))
73
74#define MSG_DIAG(M) (ErrorReporter::GetInstance()->Report(M, ErrorReporter::Diagnostic))
75
76#define MSG_FATAL(M) (ErrorReporter::GetInstance()->Report(M, ErrorReporter::Fatal))
77
79public:
80 ErrorReporter(QWidget *parent);
81 enum Type { Diagnostic = 0, Info = 1, Warning = 2, Error = 3, Fatal = 4 };
82
83 struct Message {
85 std::string value;
87
88 Message(Type type_, std::string value_, int err_code_ = 0) : type(type_), value(value_), err_code(err_code_) {}
89 };
90
93 static ErrorReporter *GetInstance() { return (_instance); };
94
96 static void ShowErrors();
97
102 static void Report(std::string msg, Type severity = Diagnostic, std::string details = "");
103
106 static std::string GetSystemInformation();
107
110 static int OpenLogFile(std::string path);
111
112protected:
114
115private:
117 static ErrorReporter * _instance;
118 std::vector<Message> _log;
119 std::vector<Message> _fullLog;
120 std::string _logFilePath;
121 FILE * _logFile;
122 QWidget * _parent;
123 std::vector<ErrorReporterPopup *> _boxes;
124
125 friend void _myBaseErrorCallback(const char *msg, int err_code);
126 friend void _myBaseDiagCallback(const char *msg);
127};
128
129#endif
A helper class for ErrorReporter that is neccessary because the Qt gui is in a separate thread.
Definition: ErrorReporter.h:42
void setLogText(std::string text)
bool isDead() const
Definition: ErrorReporter.h:48
ErrorReporterPopup(QWidget *parent, int id, bool fatal=false)
A utility singleton class that provides error reporting functinality.
Definition: ErrorReporter.h:78
static void Report(std::string msg, Type severity=Diagnostic, std::string details="")
friend void _myBaseErrorCallback(const char *msg, int err_code)
static std::string GetSystemInformation()
ErrorReporter(QWidget *parent)
static int OpenLogFile(std::string path)
static ErrorReporter * GetInstance()
Definition: ErrorReporter.h:93
friend void _myBaseDiagCallback(const char *msg)
static void ShowErrors()
Displays the current log of errors with the default message ERRORREPORTER_DEFAULT_MESSAGE.
Message(Type type_, std::string value_, int err_code_=0)
Definition: ErrorReporter.h:88