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