f012cdd8dcb7d19ff30c8a58e4ba942ffa6e39b7
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / abort-handler.h
1 #ifndef DALI_INTERNAL_ADAPTOR_ABORT_HANDLER_H
2 #define DALI_INTERNAL_ADAPTOR_ABORT_HANDLER_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <signal.h>
23 #include <dali/public-api/signals/callback.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/adaptor-framework/application.h>
27
28 #if !defined(_NSIG) && defined(NSIG)
29 #define _NSIG NSIG
30 #endif
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace Adaptor
37 {
38
39 /**
40  * Class to listen to system signals and trigger an abort callback
41  * when they occur.
42  *
43  * This class maintains a process wide singleton, as the signal(2) system
44  * call is process specific, not thread specific.
45  *
46  * Currently, this precludes having multiple DALi instances in the same process.
47  */
48 class AbortHandler
49 {
50 public:
51   /**
52    * Constructor
53    * @param[in] callback The function to call when abort signals occur
54    * @note The ownership of callback is passed onto this class.
55    */
56   AbortHandler( CallbackBase* callback );
57
58   /**
59    * Destructor
60    */
61   ~AbortHandler();
62
63   /**
64    * Add a signal you want to be handled by this abort handler.
65    * @param[in] signum The signal number (from signum.h)
66    * @return true if the signal handler was installed ok
67    */
68   bool AbortOnSignal( int signum );
69
70 private:
71   /**
72    * Signal handler - Called when signal is received.
73    * Stops the application.
74    */
75   static void SignalHandler( int signum );
76
77   /**
78    * Default constructor - undefined
79    */
80   AbortHandler();
81
82   /**
83    * Copy constructor - undefined
84    */
85   AbortHandler(const AbortHandler& rhs);
86
87   /**
88    * Assignment operator - undefined
89    */
90   AbortHandler& operator=(const AbortHandler& rhs);
91
92 private:
93   using SignalHandlerFuncPtr = void( * )( int );
94
95   // _NSIG comes from the signal.h linux system header, defining the number of signals.
96   SignalHandlerFuncPtr        mSignalOldHandlers[_NSIG-1];
97   unsigned long long          mSignalMask;
98
99   CallbackBase*               mCallback;
100
101   static AbortHandler*        gInstance;
102 };
103
104 } // Namespace Adaptor
105 } // Namespace Internal
106 } // Namespace Dali
107
108 #endif //  DALI_INTERNAL_ADAPTOR_ABORT_HANDLER_H