1 | // %pacpus:license{
|
---|
2 | // This file is part of the PACPUS framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %pacpus:license}
|
---|
5 | /// @file
|
---|
6 | /// @author Marek Kurdej <firstname.surname@utc.fr>
|
---|
7 | /// @date March, 2013
|
---|
8 | /// @version $Id$
|
---|
9 | /// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
|
---|
10 |
|
---|
11 | #include <boost/exception/diagnostic_information.hpp>
|
---|
12 | #include <boost/exception/exception.hpp>
|
---|
13 | #include <csignal>
|
---|
14 | #include <Pacpus/kernel/Log.h>
|
---|
15 | #include <Pacpus/kernel/PacpusApplication.h>
|
---|
16 | #include <Pacpus/kernel/PacpusException.h>
|
---|
17 | #include <sstream>
|
---|
18 | #include <string>
|
---|
19 |
|
---|
20 | using namespace pacpus;
|
---|
21 |
|
---|
22 | DECLARE_STATIC_LOGGER("pacpus.core.PacpusApplication");
|
---|
23 |
|
---|
24 | PacpusApplication::PacpusApplication(int& argc, char** argv
|
---|
25 | #ifndef Q_QDOC
|
---|
26 | , int _internal
|
---|
27 | #endif
|
---|
28 | )
|
---|
29 | : QApplication(argc, argv, _internal)
|
---|
30 | {
|
---|
31 | //installSignalHandler();
|
---|
32 | }
|
---|
33 |
|
---|
34 | //PacpusApplication::PacpusApplication(int& argc, char** argv, bool GUIenabled
|
---|
35 | //#ifndef Q_QDOC
|
---|
36 | // , int _internal
|
---|
37 | //#endif
|
---|
38 | // )
|
---|
39 | // : QApplication(argc, argv, GUIenabled, _internal)
|
---|
40 | //{
|
---|
41 | //}
|
---|
42 |
|
---|
43 | //PacpusApplication::PacpusApplication(int& argc, char** argv, Type type
|
---|
44 | //#ifndef Q_QDOC
|
---|
45 | // , int _internal
|
---|
46 | //#endif
|
---|
47 | // )
|
---|
48 | // : QApplication(argc, argv, type, _internal)
|
---|
49 | //{
|
---|
50 | //}
|
---|
51 |
|
---|
52 | #if defined(Q_WS_X11)
|
---|
53 | PacpusApplication::PacpusApplication(Display* display, Qt::HANDLE visual, Qt::HANDLE colormap
|
---|
54 | #ifndef Q_QDOC
|
---|
55 | , int _internal
|
---|
56 | #endif
|
---|
57 | )
|
---|
58 | : QApplication(display, visual, colormap, _internal)
|
---|
59 | {
|
---|
60 | }
|
---|
61 |
|
---|
62 | PacpusApplication::PacpusApplication(Display* display, int& argc, char** argv, Qt::HANDLE visual, Qt::HANDLE colormap
|
---|
63 | #ifndef Q_QDOC
|
---|
64 | , int _internal
|
---|
65 | #endif
|
---|
66 | )
|
---|
67 | : QApplication(display, argc, argv, visual, colormap, _internal)
|
---|
68 | {
|
---|
69 | }
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | #if defined(Q_OS_SYMBIAN)
|
---|
73 | PacpusApplication::PacpusApplication(QApplication::QS60MainApplicationFactory factory, int& argc, char** argv
|
---|
74 | #ifndef Q_QDOC
|
---|
75 | , int _internal
|
---|
76 | #endif
|
---|
77 | )
|
---|
78 | : QApplication(factory, argc, argv, _internal)
|
---|
79 | {
|
---|
80 | }
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | PacpusApplication::~PacpusApplication()
|
---|
84 | {
|
---|
85 | }
|
---|
86 |
|
---|
87 | bool PacpusApplication::notify(QObject* receiver, QEvent* ev)
|
---|
88 | {
|
---|
89 | try {
|
---|
90 | return QApplication::notify(receiver, ev);
|
---|
91 | } catch (PacpusException& e) {
|
---|
92 | (void)e; // unused
|
---|
93 | LOG_ERROR("PacpusException caught:" << e.what() << "\n" << boost::diagnostic_information(e));
|
---|
94 | } catch (boost::exception& e) {
|
---|
95 | (void)e; // unused
|
---|
96 | LOG_ERROR("boost::exception caught:" << boost::diagnostic_information(e));
|
---|
97 | } catch (std::exception& e) {
|
---|
98 | (void)e; // unused
|
---|
99 | LOG_ERROR("std::exception caught:" << e.what());
|
---|
100 | }
|
---|
101 | return false;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void signalHandler(int signal);
|
---|
105 |
|
---|
106 | void PacpusApplication::installSignalHandler()
|
---|
107 | {
|
---|
108 | LOG_INFO("installing signal handler...");
|
---|
109 |
|
---|
110 | typedef void (*SignalHandlerType)(int);
|
---|
111 |
|
---|
112 | //std::signal(SIGABRT, &signalHandler);
|
---|
113 | //std::signal(SIGFPE, &signalHandler);
|
---|
114 | //std::signal(SIGILL, &signalHandler);
|
---|
115 | std::signal(SIGINT, &signalHandler); // interrupt (CTRL-C)
|
---|
116 | //std::signal(SIGSEGV, &signalHandler);
|
---|
117 | //std::signal(SIGTERM, &signalHandler);
|
---|
118 |
|
---|
119 | LOG_INFO("successfully installed signal handler");
|
---|
120 | }
|
---|
121 |
|
---|
122 | void signalHandler(int signal)
|
---|
123 | {
|
---|
124 | LOG_FATAL("signal received: sig = " << signal);
|
---|
125 | std::stringstream errorMessage;
|
---|
126 | errorMessage << "received signal number " << signal;
|
---|
127 | BOOST_THROW_EXCEPTION(PacpusException(errorMessage.str())
|
---|
128 | << errinfo_signal(signal)
|
---|
129 | );
|
---|
130 | }
|
---|