Separate internal classes from base code 78/293778/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 5 Jun 2023 00:31:33 +0000 (00:31 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 5 Jun 2023 00:43:29 +0000 (00:43 +0000)
The AnrMonitor class and the ExitHandler class are separated from the
app_core_base.cc file.

Change-Id: I91083fbc529cc8436cf8fe1e2665c59ae105843a
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
tizen-cpp/app-core-cpp/anr_monitor_private.cc [new file with mode: 0644]
tizen-cpp/app-core-cpp/anr_monitor_private.hh [new file with mode: 0644]
tizen-cpp/app-core-cpp/app_core_base.cc
tizen-cpp/app-core-cpp/backtrace_private.hh [new file with mode: 0644]
tizen-cpp/app-core-cpp/exit_handler_private.cc [new file with mode: 0644]
tizen-cpp/app-core-cpp/exit_handler_private.hh [new file with mode: 0644]

diff --git a/tizen-cpp/app-core-cpp/anr_monitor_private.cc b/tizen-cpp/app-core-cpp/anr_monitor_private.cc
new file mode 100644 (file)
index 0000000..9d9f432
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "app-core-cpp/anr_monitor_private.hh"
+
+#include <errno.h>
+#include <stdio.h>
+
+#include "app-core-cpp/backtrace_private.hh"
+#include "common/log_private.hh"
+
+namespace tizen_cpp {
+namespace internal {
+namespace {
+
+const int SIGRTANR = SIGRTMIN + 3;
+
+}  // namespace
+
+AnrMonitor::AnrMonitor() {
+  struct sigaction action;
+  memset(&action, '\0', sizeof(action));
+  sigemptyset(&action.sa_mask);
+  action.sa_flags = SA_RESTART;
+  action.sa_handler = SignalHandler;
+
+  if (sigaction(SIGRTANR, &action, &old_action_) != 0)
+    _E("sigaction() is failed. errno(%d)", errno);
+}
+
+AnrMonitor::~AnrMonitor() {
+  if (sigaction(SIGRTANR, &old_action_, nullptr) != 0)
+    _W("sigaction() is failed. errno(%d)", errno);
+}
+
+void AnrMonitor::SignalHandler(int signo) {
+  static unsigned int count;
+  STDERR("===================================================================");
+  STDERR("=================== Application Not Responding ====================");
+  PRINT_BACKTRACE();
+  STDERR("============== Application did not respond %d times ===============",
+      ++count);
+  STDERR("===================================================================");
+}
+
+}  // namespace internal
+}  // namespace tizen_cpp
diff --git a/tizen-cpp/app-core-cpp/anr_monitor_private.hh b/tizen-cpp/app-core-cpp/anr_monitor_private.hh
new file mode 100644 (file)
index 0000000..3f199ed
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CPP_APP_CORE_CPP_ANR_MONITOR_PRIVATE_HH_
+#define TIZEN_CPP_APP_CORE_CPP_ANR_MONITOR_PRIVATE_HH_
+
+#include <signal.h>
+
+namespace tizen_cpp {
+namespace internal {
+
+class AnrMonitor {
+ public:
+  AnrMonitor();
+  ~AnrMonitor();
+
+  AnrMonitor(const AnrMonitor&) = delete;
+  AnrMonitor& operator = (const AnrMonitor&) = delete;
+  AnrMonitor(AnrMonitor&&) = delete;
+  AnrMonitor& operator = (AnrMonitor&&) = delete;
+
+ private:
+  static void SignalHandler(int signo);
+
+ private:
+  struct sigaction old_action_;
+};
+
+}  // namespace internal
+}  // namespace tizen_cpp
+
+#endif  // TIZEN_CPP_APP_CORE_CPP_ANR_MONITOR_PRIVATE_HH_
index af33a51..057db72 100644 (file)
@@ -22,7 +22,6 @@
 #include <bundle_internal.h>
 #include <dlfcn.h>
 #include <errno.h>
-#include <execinfo.h>
 #include <gio/gio.h>
 #include <glib-unix.h>
 #include <glib.h>
 #include <utility>
 #include <vector>
 
+#include "app-core-cpp/anr_monitor_private.hh"
 #include "app-core-cpp/app_core_plugin_private.hh"
+#include "app-core-cpp/exit_handler_private.hh"
 #include "app-core-cpp/sigterm_handler_private.hh"
 #include "common/glib_private.hh"
 #include "common/log_private.hh"
 
-#define SIGRTANR (SIGRTMIN + 3)
-#undef _ERR
-#define _ERR(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
-
 extern "C" void aul_finalize();
 namespace tizen_cpp {
 
@@ -67,71 +64,8 @@ AppCoreBase* AppCoreBase::context_ = nullptr;
 
 namespace {
 
-constexpr const int BACKTRACE_BUFFER_SIZE = 128;
-
-void PrintBacktrace() {
-  char* buffer[BACKTRACE_BUFFER_SIZE];
-  int nptrs = backtrace(reinterpret_cast<void**>(buffer),
-      BACKTRACE_BUFFER_SIZE);
-  _ERR("backtrace() returned %d addresses", nptrs);
-
-  backtrace_symbols_fd(reinterpret_cast<void**>(buffer), nptrs, STDERR_FILENO);
-}
-
-class ExitHandler {
- public:
-  ExitHandler() {
-    on_exit(OnExit, this);
-  }
-
- private:
-  static void OnExit(int status, void *user_data) {
-    if (status != 127)
-      return;
-
-    PrintBacktrace();
-
-    _ERR("%s(%d) abort()", __FUNCTION__, __LINE__);
-    abort();
-  }
-};
-
-ExitHandler exit_handler;
-
-class AnrMonitor {
- public:
-  AnrMonitor() {
-    struct sigaction action;
-    memset(&action, '\0', sizeof(action));
-    sigemptyset(&action.sa_mask);
-    action.sa_flags = SA_RESTART;
-    action.sa_handler = SignalHandler;
-
-    if (sigaction(SIGRTANR, &action, &old_action_) != 0)
-      _E("sigaction() is failed. errno(%d)", errno);
-  }
-
-  ~AnrMonitor() {
-    if (sigaction(SIGRTANR, &old_action_, nullptr) != 0)
-      _W("sigaction() is failed. errno(%d)", errno);
-  }
-
- private:
-  static void SignalHandler(int signo) {
-    static unsigned int count;
-    _ERR("===================================================================");
-    _ERR("=================== Application Not Responding ====================");
-    PrintBacktrace();
-    _ERR("============== Application did not respond %d times ===============",
-        ++count);
-    _ERR("===================================================================");
-  }
-
- private:
-  struct sigaction old_action_;
-};
-
-AnrMonitor anr_monitor;
+internal::ExitHandler exit_handler;
+internal::AnrMonitor anr_monitor;
 internal::SigtermHandler sigterm_handler;
 
 enum TizenProfile {
diff --git a/tizen-cpp/app-core-cpp/backtrace_private.hh b/tizen-cpp/app-core-cpp/backtrace_private.hh
new file mode 100644 (file)
index 0000000..2d04646
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CPP_APP_CORE_CPP_BACKTRACE_PRIVATE_HH_
+#define TIZEN_CPP_APP_CORE_CPP_BACKTRACE_PRIVATE_HH_
+
+#include <execinfo.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#undef STDERR
+#define STDERR(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
+
+#undef BACKTRACE_BUFFER_SIZE
+#define BACKTRACE_BUFFER_SIZE 128
+
+#undef PRINT_BACKTRACE
+#define PRINT_BACKTRACE() do {                                                 \
+  char* buffer[BACKTRACE_BUFFER_SIZE];                                         \
+  int nptrs = backtrace(reinterpret_cast<void**>(buffer),                      \
+      BACKTRACE_BUFFER_SIZE);                                                  \
+  STDERR("backtrace() returned %d addresses", nptrs);                          \
+  int size = (nptrs > 12) ? 12 : nptrs;                                        \
+  backtrace_symbols_fd(reinterpret_cast<void**>(buffer), size, STDERR_FILENO); \
+} while (0)
+
+#endif  // TIZEN_CPP_APP_CORE_CPP_BACKTRACE_PRIVATE_HH_
diff --git a/tizen-cpp/app-core-cpp/exit_handler_private.cc b/tizen-cpp/app-core-cpp/exit_handler_private.cc
new file mode 100644 (file)
index 0000000..1f7507e
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "app-core-cpp/exit_handler_private.hh"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "app-core-cpp/backtrace_private.hh"
+
+namespace tizen_cpp {
+namespace internal {
+
+ExitHandler::ExitHandler() {
+  on_exit(OnExit, this);
+}
+
+void ExitHandler::OnExit(int status, void* user_data) {
+  if (status != 127)
+    return;
+
+  PRINT_BACKTRACE();
+  STDERR("%s(%d) abort()", __FUNCTION__, __LINE__);
+  abort();
+}
+
+}  // namespace internal
+}  // namespace tizen_cpp
diff --git a/tizen-cpp/app-core-cpp/exit_handler_private.hh b/tizen-cpp/app-core-cpp/exit_handler_private.hh
new file mode 100644 (file)
index 0000000..be5cc53
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CPP_APP_CORE_CPP_EXIT_HANDLER_PRIVATE_HH_
+#define TIZEN_CPP_APP_CORE_CPP_EXIT_HANDLER_PRIVATE_HH_
+
+namespace tizen_cpp {
+namespace internal {
+
+class ExitHandler {
+ public:
+  ExitHandler();
+
+ private:
+  static void OnExit(int status, void* user_data);
+};
+
+}  // namespace internal
+}  // namespace tizen_cpp
+
+#endif  // TIZEN_CPP_APP_CORE_CPP_EXIT_HANDLER_PRIVATE_HH_