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