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