[dali_2.3.22] Merge branch 'devel/master'
[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) 2021 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 <dali/public-api/signals/callback.h>
23 #include <signal.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  * Class to listen to system signals and trigger an abort callback
40  * when they occur.
41  *
42  * This class maintains a process wide singleton, as the signal(2) system
43  * call is process specific, not thread specific.
44  *
45  * Currently, this precludes having multiple DALi instances in the same process.
46  */
47 class AbortHandler
48 {
49 public:
50   /**
51    * Constructor
52    * @param[in] callback The function to call when abort signals occur
53    * @note The ownership of callback is passed onto this class.
54    */
55   AbortHandler(CallbackBase* callback);
56
57   /**
58    * Destructor
59    */
60   ~AbortHandler();
61
62   /**
63    * Add a signal you want to be handled by this abort handler.
64    * @param[in] signum The signal number (from signum.h)
65    * @return true if the signal handler was installed ok
66    */
67   bool AbortOnSignal(int signum);
68
69 private:
70   /**
71    * Signal handler - Called when signal is received.
72    * Stops the application.
73    */
74   static void SignalHandler(int signum);
75
76   /**
77    * Default constructor - undefined
78    */
79   AbortHandler();
80
81   /**
82    * Copy constructor - undefined
83    */
84   AbortHandler(const AbortHandler& rhs);
85
86   /**
87    * Assignment operator - undefined
88    */
89   AbortHandler& operator=(const AbortHandler& rhs);
90
91 private:
92   using SignalHandlerFuncPtr = void (*)(int);
93
94   // _NSIG comes from the signal.h linux system header, defining the number of signals.
95   SignalHandlerFuncPtr mSignalOldHandlers[_NSIG - 1];
96   unsigned long long   mSignalMask;
97
98   CallbackBase* mCallback;
99
100   static AbortHandler* gInstance;
101 };
102
103 } // Namespace Adaptor
104 } // Namespace Internal
105 } // Namespace Dali
106
107 #endif //  DALI_INTERNAL_ADAPTOR_ABORT_HANDLER_H