Debian Codegraph @

include/toolsignal.h

raw symbols SCIP
1 // ****************************************************************************
2 // Project: libguytools
3 // ****************************************************************************
4 // Programmer: Guy Voncken
5 // Police Grand-Ducale
6 // Service de Police Judiciaire
7 // Section Nouvelles Technologies
8 // ****************************************************************************
9 // Module: Signal handler with backtrace
10 // ****************************************************************************
11
12 // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
13 // 2018, 2019
14 // Guy Voncken
15 //
16 // This file is part of libguytools.
17 //
18 // libguytools is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // libguytools is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with libguytools. If not, see <http://www.gnu.org/licenses/>.
30
31 #ifndef __TOOLSIGNAL_H__
32 #define __TOOLSIGNAL_H__
33
34
35 // Description of module ToolSignal
36 // --------------------------------
37 // This module does all the standard signal handling work for an application. When catching a standard
38 // signal (Kill, Hup, Break...) it calls the function that has been indicated in param pFnLog.
39 // If ever a segment violation occurs, a stack trace is done in order to log the function call sequence
40 // before exiting the program.
41 //
42 // All logging is done via the function indicated in param pFnLog. If that one is NULL, the module writes
43 // its log outputs to stdout. Its first parameter (Error) indicates whether a normal log output (info) or
44 // whether an error log entry should be done.
45 //
46 // It might be important to know for the application, that ToolSignalInit starts a new thread. The function
47 // indicated in param pFnSig is called from that thread, if pFnSig is not NULL. The ID of the new thread is
48 // written to where pThreadId points, if pThreadId is not NULL.
49
50 typedef void (* t_pToolSignalLogFn )(bool Error, unsigned long long ThreadId, const char *pFileName, const char *pFunction, int LineNr, const char *pFormat, va_list pArguments);
51 typedef void (* t_pToolSignalHandler)(int Signal);
52
53 int ToolSignalInit (t_pToolSignalLogFn pFnLog, t_pToolSignalHandler pFnSig, unsigned long long *pThreadId);
54 int ToolSignalDeInit (void);
55
56
57 // class t_ToolSignal: public QThread
58 // {
59 // public:
60 // t_ToolSignal (int Err, int *pThreadId);
61 // ~t_ToolSignal();
62 // void run();
63 // static void BacktraceSignalHandler (int signalHandled, siginfo_t *signalInfo, void *secret);
64 //
65 // static APIRET SetLogFn (t_pToolSignalLogFn pFn);
66 // static APIRET SetSignalHandlerFn (t_pToolSignalHandler pFn);
67 // };
68 // typedef t_ToolSignal *t_pToolSignal;
69
70
71 // -------------------------------
72 // Error codes
73 // -------------------------------
74
75 enum
76 {
77 ERROR_TOOLSIGNAL_ALREADY_INITIALISED = ERROR_BASE_TOOL_SIGNAL + 1,
78 ERROR_TOOLSIGNAL_NOT_INITIALISED,
79 ERROR_TOOLSIGNAL_STARTTHREAD_FAILED
80 };
81
82 #endif