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