Add a new internal API 46/294246/8
authorChanggyu Choi <changyu.choi@samsung.com>
Fri, 16 Jun 2023 04:09:55 +0000 (13:09 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 19 Jun 2023 01:12:38 +0000 (10:12 +0900)
This is for receiving app dead event with exit status.

Adds:
 - aul_listen_app_dead_signal_v2()

Change-Id: I29e1614c63d71ee35e31ca66b3ac9930e900b48c
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
include/aul.h
src/app_signal.cc

index 9366e13..6482c75 100644 (file)
@@ -1698,6 +1698,53 @@ typedef int (*aul_app_launch_event_cb_v2)(int pid, const char *appid, void *user
 int aul_listen_app_launch_signal_v2(aul_app_launch_event_cb_v2 callback, void *user_data);
 
 /**
+ * @brief Called when an application is terminated.
+ * @details This function is called when an application is terminated, after you register this callback using aul_listen_app_dead_signal_v2().
+ * @param[in]   pid             The process ID
+ * @param[in]   status          The exit status
+ * @param[in]   user_data       The user data passed from the registeration function
+ *
+ * @see aul_listen_app_dead_signal_v2()
+ */
+typedef void (*aul_app_dead_event_cb_v2)(int pid, int status, void* user_data);
+
+/**
+ * @breif Registers a callback function to be invoked when the application is terminated.
+ * @remarks If the callback function is nullptr, the registered event will be deregistered.
+ * @param[in]   callback        The callback function
+ * @param[in]   user_data       The user data to be passed to the callback function
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ * @retval      #AUL_R_OK       Successful
+ * @retval      #AUL_R_ERROR    Internal I/O error
+ * @see aul_app_dead_event_cb_v2()
+ *
+ * @remarks This function is only available for App Framework internally.
+ *
+ * @code
+ * #include <aul.h>
+ *
+ * static void app_dead_event_cb(int pid, int status, void *user_data)
+ * {
+ *     dlog_print(DLOG_INFO, LOG_TAG, "application(%s) is terminated. status(%d)", pid, status);
+ * }
+ *
+ * int listen_app_dead_signal(void)
+ * {
+ *     int ret;
+ *
+ *     ret = aul_listen_app_dead_signal_v2(app_dead_event_cb, NULL);
+ *     if (ret != AUL_R_OK) {
+ *         dlog_print(DLOG_ERROR, LOG_TAG, "aul_listen_app_dead_signal_v2() is failed. error(%d)", ret);
+ *         return -1;
+ *     }
+ *
+ *     return 0;
+ * }
+ */
+int aul_listen_app_dead_signal_v2(aul_app_dead_event_cb_v2 callback, void *user_data);
+
+/**
  * @par Description:
  *     This API gets status of specified application process id.
  * @par Purpose:
index 0f40e5a..ae44e7b 100644 (file)
@@ -169,8 +169,9 @@ class AppDeadEvent : public Event<aul_app_dead_event_cb> {
   }
 
   void Invoke(GVariant* parameters) override {
-    guint pid;
-    g_variant_get(parameters, "(u)", &pid);
+    gint pid;
+    gint dummy;
+    g_variant_get(parameters, "(ii)", &pid, &dummy);
 
     auto cb = GetCallback();
     if (cb != nullptr)
@@ -178,6 +179,23 @@ class AppDeadEvent : public Event<aul_app_dead_event_cb> {
   }
 };
 
+class AppDeadEvent2 : public Event<aul_app_dead_event_cb_v2> {
+ public:
+  AppDeadEvent2() : Event<aul_app_dead_event_cb_v2>(AUL_DBUS_PATH,
+      AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPDEAD_SIGNAL) {
+  }
+
+  void Invoke(GVariant* parameters) override {
+    gint pid;
+    gint status;
+    g_variant_get(parameters, "(ii)", &pid, &status);
+
+    auto cb = GetCallback();
+    if (cb != nullptr)
+      cb(static_cast<int>(pid), static_cast<int>(status), GetUserData());
+  }
+};
+
 class AppLaunchEvent : public Event<aul_app_launch_event_cb> {
  public:
   AppLaunchEvent() : Event<aul_app_launch_event_cb>(AUL_DBUS_PATH,
@@ -273,6 +291,15 @@ class AppSignalContext {
     return app_dead_event_->SetCallback(cb, user_data);
   }
 
+  bool AppDeadEvent2Subscribe(
+      aul_app_dead_event_cb_v2 cb, void* user_data) {
+    std::lock_guard<std::recursive_mutex> lock(mutex_);
+    if (app_dead_event2_ == nullptr)
+      app_dead_event2_ = std::make_unique<AppDeadEvent2>();
+
+    return app_dead_event2_->SetCallback(cb, user_data);
+  }
+
   bool AppLaunchEventSubscribe(aul_app_launch_event_cb cb, void* user_data) {
     std::lock_guard<std::recursive_mutex> lock(mutex_);
     if (app_launch_event_ == nullptr)
@@ -319,6 +346,7 @@ class AppSignalContext {
  private:
   std::recursive_mutex mutex_;
   std::unique_ptr<AppDeadEvent> app_dead_event_;
+  std::unique_ptr<AppDeadEvent2> app_dead_event2_;
   std::unique_ptr<AppLaunchEvent> app_launch_event_;
   std::unique_ptr<AppLaunchEvent2> app_launch_event2_;
   std::unique_ptr<BootingDoneEvent> booting_done_event_;
@@ -418,6 +446,14 @@ extern "C" API int aul_listen_app_dead_signal(aul_app_dead_event_cb callback,
   return AUL_R_OK;
 }
 
+extern "C" API int aul_listen_app_dead_signal_v2(
+    aul_app_dead_event_cb_v2 callback, void* user_data) {
+  if (!context.AppDeadEvent2Subscribe(callback, user_data))
+    return AUL_R_ERROR;
+
+  return AUL_R_OK;
+}
+
 extern "C" API int aul_listen_app_launch_signal(
     aul_app_launch_event_cb callback, void* user_data) {
   if (!context.AppLaunchEventSubscribe(callback, user_data))