OpenShot Library | libopenshot 0.2.7
CrashHandler.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Header file for CrashHandler class
4 * @author Jonathan Thomas <jonathan@openshot.org>
5 *
6 * @ref License
7 */
8
9/* LICENSE
10 *
11 * Copyright (c) 2008-2019 OpenShot Studios, LLC
12 * <http://www.openshotstudios.com/>. This file is part of
13 * OpenShot Library (libopenshot), an open-source project dedicated to
14 * delivering high quality video editing and animation solutions to the
15 * world. For more information visit <http://www.openshot.org/>.
16 *
17 * OpenShot Library (libopenshot) is free software: you can redistribute it
18 * and/or modify it under the terms of the GNU Lesser General Public License
19 * as published by the Free Software Foundation, either version 3 of the
20 * License, or (at your option) any later version.
21 *
22 * OpenShot Library (libopenshot) is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public License
28 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31#ifndef OPENSHOT_CRASH_HANDLER_H
32#define OPENSHOT_CRASH_HANDLER_H
33
34#include <cstdlib>
35#include <stdio.h>
36#include <signal.h>
37#ifdef __MINGW32__
38 #include <winsock2.h>
39 #include <windows.h>
40 #include <DbgHelp.h>
41#else
42 #include <execinfo.h>
43#endif
44#include <errno.h>
45#include <cxxabi.h>
46#include "ZmqLogger.h"
47
48namespace openshot {
49
50 /**
51 * @brief This class is designed to catch exceptions thrown by libc (SIGABRT, SIGSEGV, SIGILL, SIGFPE)
52 *
53 * This class is a singleton which only needs to be instantiated 1 time, and it will register as a signal
54 * handler with libc, and log errors using the ZmqLogger class.
55 */
57 private:
58 /// Default constructor
59 CrashHandler(){return;}; // Don't allow user to create an instance of this singleton
60
61 /// Default copy method
62 //CrashHandler(CrashHandler const&){}; // Don't allow the user to copy this instance
63 CrashHandler(CrashHandler const&) = delete; // Don't allow the user to copy this instance
64
65 /// Default assignment operator
66 CrashHandler & operator=(CrashHandler const&) = delete; // Don't allow the user to assign this instance
67
68 /// Private variable to keep track of singleton instance
69 static CrashHandler *m_pInstance;
70
71 public:
72 /// Create or get an instance of this crash handler singleton (invoke the class with this method). This also
73 /// registers the instance as a signal handler for libc
74 static CrashHandler *Instance();
75
76#ifdef __MINGW32__
77 // TODO: Windows exception handling methods
78 static void abortHandler(int signum);
79#else
80 /// Method which handles crashes and logs error
81 static void abortHandler(int signum, siginfo_t* si, void* unused);
82#endif
83
84 /// Method which prints a stacktrace
85 static void printStackTrace(FILE *out, unsigned int max_frames);
86 };
87
88}
89
90#endif
Header file for ZeroMQ-based Logger class.
This class is designed to catch exceptions thrown by libc (SIGABRT, SIGSEGV, SIGILL,...
Definition: CrashHandler.h:56
static void abortHandler(int signum, siginfo_t *si, void *unused)
Method which handles crashes and logs error.
static void printStackTrace(FILE *out, unsigned int max_frames)
Method which prints a stacktrace.
static CrashHandler * Instance()
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47