diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kdecore/kcrash.h | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdecore/kcrash.h')
-rw-r--r-- | kdecore/kcrash.h | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/kdecore/kcrash.h b/kdecore/kcrash.h new file mode 100644 index 000000000..a2fe969ea --- /dev/null +++ b/kdecore/kcrash.h @@ -0,0 +1,127 @@ +/* + * This file is part of the KDE Libraries + * Copyright (C) 2000 Timo Hummel <timo.hummel@sap.com> + * Tom Braun <braunt@fh-konstanz.de> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KCRASH_H +#define __KCRASH_H + +#include <qstring.h> +#include "kdelibs_export.h" + +/** + * This class handles segmentation-faults. + * By default it displays a message-box saying the application crashed. + * This default can be overridden by setting a custom crash handler with + * setCrashHandler(). + * If a function is specified with setEmergencySaveFunction() it will + * be called by the default crash handler, giving the application a chance + * to save its data. + */ +class KDECORE_EXPORT KCrash +{ + private: // ;o) + static const char *appName; + static const char *appPath; + static bool safer; + + public: + /** + * The default crash handler. + * @param signal the signal number + */ + static void defaultCrashHandler (int signal); + + /** + * This function type is a pointer to a crash handler function. + * The function's argument is the number of the signal. + */ + typedef void (*HandlerType)(int); + + /** + * Install a function to be called in case a SIGSEGV is caught. + * @param handler HandlerType handler can be one of + * @li null in which case signal-catching is disabled + * (by calling signal(SIGSEGV, SIG_DFL)) + * @li if handler is omitted the default crash handler is installed. + * @li an user defined function in the form: + * static (if in a class) void myCrashHandler(int); + * @param handler the crash handler + */ + + static void setCrashHandler (HandlerType handler = defaultCrashHandler); + + /** + * Returns the installed crash handler. + * @return the crash handler + */ + static HandlerType crashHandler() { return _crashHandler; } + + /** + * Installs a function which should try to save the applications data. + * It is the crash handler´s responsibility to call this function. + * Therefore, if no crash handler is set, the default crash handler + * is installed to ensure the save function is called. + * @param saveFunction the handler to install + */ + static void setEmergencySaveFunction (HandlerType saveFunction = (HandlerType)0); + /** + * Return the currently set emergency save function. + * @return the emergency save function + */ + static HandlerType emergencySaveFunction() { return _emergencySaveFunction; } + + /** + * Set whether to start drkonqi without arbitrary disk access + */ + static void setSafer( bool on ) { safer = on; } + + /** + * Sets the application @p path which should be passed to + * Dr. Konqi, our nice crash display application. + * @param path the application path. + */ + static void setApplicationPath (QString path) { appPath = qstrdup(path.local8Bit().data()); } + /* KDE 4: Make it const QString & */ + + /** + * Sets the application name @p name which should be passed to + * Dr. Konqi, our nice crash display application. + * @param name the name of the application, as shown in Dr. Konqi + */ + static void setApplicationName (QString name) { appName = qstrdup(name.local8Bit().data()); } + /* KDE 4: Make it const QString & */ + + protected: + /** + * Pointer to the crash handler. + */ + static HandlerType _crashHandler; + /** + * Pointer to the emergency save function. + */ + static HandlerType _emergencySaveFunction; + + private: + static void startDrKonqi( const char* argv[], int argc ); + static void startDirectly( const char* argv[], int argc ); +}; + +#endif + |