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:
}
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)
}
};
+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,
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)
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_;
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))