Separate internal classes from base code
[platform/core/appfw/app-core.git] / tizen-cpp / app-core-cpp / anr_monitor_private.cc
1 /*
2  * Copyright (c) 2023 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 #include "app-core-cpp/anr_monitor_private.hh"
18
19 #include <errno.h>
20 #include <stdio.h>
21
22 #include "app-core-cpp/backtrace_private.hh"
23 #include "common/log_private.hh"
24
25 namespace tizen_cpp {
26 namespace internal {
27 namespace {
28
29 const int SIGRTANR = SIGRTMIN + 3;
30
31 }  // namespace
32
33 AnrMonitor::AnrMonitor() {
34   struct sigaction action;
35   memset(&action, '\0', sizeof(action));
36   sigemptyset(&action.sa_mask);
37   action.sa_flags = SA_RESTART;
38   action.sa_handler = SignalHandler;
39
40   if (sigaction(SIGRTANR, &action, &old_action_) != 0)
41     _E("sigaction() is failed. errno(%d)", errno);
42 }
43
44 AnrMonitor::~AnrMonitor() {
45   if (sigaction(SIGRTANR, &old_action_, nullptr) != 0)
46     _W("sigaction() is failed. errno(%d)", errno);
47 }
48
49 void AnrMonitor::SignalHandler(int signo) {
50   static unsigned int count;
51   STDERR("===================================================================");
52   STDERR("=================== Application Not Responding ====================");
53   PRINT_BACKTRACE();
54   STDERR("============== Application did not respond %d times ===============",
55       ++count);
56   STDERR("===================================================================");
57 }
58
59 }  // namespace internal
60 }  // namespace tizen_cpp