Dali 3D User Interface Engine
abort-handler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 // CLASS HEADER
19 #include "abort-handler.h"
20 
21 // EXTERNAL INCLUDES
22 #include <cstring>
23 
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace Adaptor
29 {
30 
31 AbortHandler* AbortHandler::gInstance(NULL);
32 
34 : mSignalMask( 0 ),
35  mCallback( callback )
36 {
37  DALI_ASSERT_ALWAYS( gInstance == NULL && "Only one instance of abort handler allowed" );
38  gInstance = this;
39 
40  memset( mSignalOldHandlers, 0, sizeof(SignalHandlerFuncPtr) * (_NSIG-1));
41 }
42 
44 {
45  delete mCallback;
46 
47  int signum;
48  for ( signum = 1; signum < _NSIG; signum++ )
49  {
50  if ( mSignalMask & (1 << (signum-1) ) )
51  {
52  // set signals back to default handling
53  signal( signum, mSignalOldHandlers[signum-1] );
54  }
55  }
56  gInstance = NULL;
57 }
58 
59 bool AbortHandler::AbortOnSignal( int signum )
60 {
61  bool status = false;
62 
63  if ( signum < _NSIG )
64  {
65  SignalHandlerFuncPtr signalHandlerPrevious = signal( signum, &AbortHandler::SignalHandler );
66 
67  if ( SIG_ERR != signalHandlerPrevious )
68  {
69  mSignalOldHandlers[signum-1] = signalHandlerPrevious;
70  mSignalMask |= ( 1 << (signum-1) );
71  status = true;
72  }
73  }
74  return status;
75 }
76 
77 void AbortHandler::SignalHandler( int signum )
78 {
79  if( gInstance )
80  {
81  if( gInstance->mCallback )
82  {
84  }
85  }
86 }
87 
88 } // Adaptor
89 } // Internal
90 } // Dali
Dali Docs Home
Read more about Dali