Use macro instead of const keyword
[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 #define SIGRTANR (SIGRTMIN + 3)
26
27 namespace tizen_cpp {
28 namespace internal {
29
30 AnrMonitor::AnrMonitor() {
31   struct sigaction action;
32   memset(&action, '\0', sizeof(action));
33   sigemptyset(&action.sa_mask);
34   action.sa_flags = SA_RESTART;
35   action.sa_handler = SignalHandler;
36
37   if (sigaction(SIGRTANR, &action, &old_action_) != 0)
38     _E("sigaction() is failed. errno(%d)", errno);
39 }
40
41 AnrMonitor::~AnrMonitor() {
42   if (sigaction(SIGRTANR, &old_action_, nullptr) != 0)
43     _W("sigaction() is failed. errno(%d)", errno);
44 }
45
46 void AnrMonitor::SignalHandler(int signo) {
47   static unsigned int count;
48   STDERR("===================================================================");
49   STDERR("=================== Application Not Responding ====================");
50   PRINT_BACKTRACE();
51   STDERR("============== Application did not respond %d times ===============",
52       ++count);
53   STDERR("===================================================================");
54 }
55
56 }  // namespace internal
57 }  // namespace tizen_cpp