if (cms == NULL)
return -1;
cms->ec = ec;
+
+ if (!weston_compositor_add_destroy_listener_once(ec,
+ &cms->destroy_listener,
+ colord_notifier_destroy)) {
+ free(cms);
+ return 0;
+ }
+
#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init();
#endif
cms->devices = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, colord_cms_output_destroy);
- /* destroy */
- cms->destroy_listener.notify = colord_notifier_destroy;
- wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
-
/* devices added */
cms->output_created_listener.notify = colord_notifier_output_created;
wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
return -1;
cms->ec = ec;
- cms->destroy_listener.notify = cms_notifier_destroy;
- wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
+
+ if (!weston_compositor_add_destroy_listener_once(ec,
+ &cms->destroy_listener,
+ cms_notifier_destroy)) {
+ free(cms);
+ return 0;
+ }
cms->output_created_listener.notify = cms_notifier_output_created;
wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
struct screen_share {
struct weston_compositor *compositor;
+ /* XXX: missing compositor destroy listener
+ * https://gitlab.freedesktop.org/wayland/weston/issues/298
+ */
char *command;
};
if (notifier == NULL)
return -1;
- notifier->compositor_destroy_listener.notify =
- weston_compositor_destroy_listener;
- wl_signal_add(&compositor->destroy_signal,
- ¬ifier->compositor_destroy_listener);
+ if (!weston_compositor_add_destroy_listener_once(compositor,
+ ¬ifier->compositor_destroy_listener,
+ weston_compositor_destroy_listener)) {
+ free(notifier);
+ return 0;
+ }
if (add_systemd_sockets(compositor) < 0)
return -1;
shell->compositor = ec;
- shell->destroy_listener.notify = shell_destroy;
- wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
+ if (!weston_compositor_add_destroy_listener_once(ec,
+ &shell->destroy_listener,
+ shell_destroy)) {
+ free(shell);
+ return 0;
+ }
+
shell->idle_listener.notify = idle_handler;
wl_signal_add(&ec->idle_signal, &shell->idle_listener);
shell->wake_listener.notify = wake_handler;
struct wl_client *client;
struct wl_listener client_destroyed;
struct weston_compositor *compositor;
+ /* XXX: missing compositor destroy listener
+ * https://gitlab.freedesktop.org/wayland/weston/issues/299
+ */
struct weston_layer layer;
struct wl_list output_list;
weston_compositor_create(struct wl_display *display,
struct weston_log_context *log_ctx, void *user_data);
+bool
+weston_compositor_add_destroy_listener_once(struct weston_compositor *compositor,
+ struct wl_listener *listener,
+ wl_notify_func_t destroy_handler);
+
enum weston_compositor_backend {
WESTON_BACKEND_DRM,
WESTON_BACKEND_FBDEV,
struct hmi_controller *hmi_ctrl = NULL;
struct wl_event_loop *loop = NULL;
+ /* ad hoc weston_compositor_add_destroy_listener_once() */
+ if (wl_signal_get(&ec->destroy_signal, hmi_controller_destroy))
+ return 0;
+
hmi_ctrl = hmi_controller_create(ec);
if (hmi_ctrl == NULL)
return -1;
if (shell == NULL)
return -1;
- init_ivi_shell(compositor, shell);
+ if (!weston_compositor_add_destroy_listener_once(compositor,
+ &shell->destroy_listener,
+ shell_destroy)) {
+ free(shell);
+ return 0;
+ }
- shell->destroy_listener.notify = shell_destroy;
- wl_signal_add(&compositor->destroy_signal, &shell->destroy_listener);
+ init_ivi_shell(compositor, shell);
shell->wake_listener.notify = wake_handler;
wl_signal_add(&compositor->wake_signal, &shell->wake_listener);
return init;
}
+/** Add a compositor destroy listener only once
+ *
+ * \param compositor The compositor whose destroy to watch for.
+ * \param listener The listener struct to initialize.
+ * \param destroy_handler The callback when compositor is destroyed.
+ * \return True if listener is added, or false if there already is a listener
+ * with the given \c destroy_handler.
+ *
+ * This function does nothing and returns false if the given callback function
+ * is already present in the weston_compositor destroy callbacks list.
+ * Otherwise, this function initializes the given listener with the given
+ * callback pointer and adds it to the compositor's destroy callbacks list.
+ *
+ * This can be used to ensure that plugin initialization is done only once
+ * in case the same plugin is loaded multiple times. If this function returns
+ * false, the plugin should be already initialized successfully.
+ *
+ * All plugins should register a destroy listener for cleaning up. Note, that
+ * the plugin destruction order is not guaranteed: plugins that depend on other
+ * plugins must be able to be torn down in arbitrary order.
+ *
+ * \sa weston_compositor_tear_down, weston_compositor_destroy
+ */
+WL_EXPORT bool
+weston_compositor_add_destroy_listener_once(struct weston_compositor *compositor,
+ struct wl_listener *listener,
+ wl_notify_func_t destroy_handler)
+{
+ if (wl_signal_get(&compositor->destroy_signal, destroy_handler))
+ return false;
+
+ listener->notify = destroy_handler;
+ wl_signal_add(&compositor->destroy_signal, listener);
+ return true;
+}
/** Tear down the compositor.
*
if (!pipewire)
return -1;
+ if (!weston_compositor_add_destroy_listener_once(compositor,
+ &pipewire->destroy_listener,
+ weston_pipewire_destroy)) {
+ free(pipewire);
+ return 0;
+ }
+
pipewire->virtual_output_api = api;
pipewire->compositor = compositor;
wl_list_init(&pipewire->output_list);
"Debug messages from pipewire plugin\n",
NULL, NULL, NULL);
- pipewire->destroy_listener.notify = weston_pipewire_destroy;
- wl_signal_add(&compositor->destroy_signal, &pipewire->destroy_listener);
return 0;
failed:
+ wl_list_remove(&pipewire->destroy_listener.link);
free(pipewire);
return -1;
}
if (!remoting)
return -1;
+ if (!weston_compositor_add_destroy_listener_once(compositor,
+ &remoting->destroy_listener,
+ weston_remoting_destroy)) {
+ free(remoting);
+ return 0;
+ }
+
remoting->virtual_output_api = api;
remoting->compositor = compositor;
wl_list_init(&remoting->output_list);
goto failed;
}
- remoting->destroy_listener.notify = weston_remoting_destroy;
- wl_signal_add(&compositor->destroy_signal, &remoting->destroy_listener);
return 0;
failed:
+ wl_list_remove(&remoting->destroy_listener.link);
free(remoting);
return -1;
}
if (!dts)
return -1;
- dts->compositor_destroy_listener.notify = shell_destroy;
- wl_signal_add(&ec->destroy_signal, &dts->compositor_destroy_listener);
+ if (!weston_compositor_add_destroy_listener_once(ec,
+ &dts->compositor_destroy_listener,
+ shell_destroy)) {
+ free(dts);
+ return 0;
+ }
weston_layer_init(&dts->layer, ec);
weston_layer_init(&dts->background_layer, ec);
struct weston_test {
struct weston_compositor *compositor;
+ /* XXX: missing compositor destroy listener
+ * https://gitlab.freedesktop.org/wayland/weston/issues/300
+ */
struct weston_layer layer;
struct weston_process process;
struct weston_seat seat;
wxs->wl_display = display;
wxs->compositor = compositor;
+ if (!weston_compositor_add_destroy_listener_once(compositor,
+ &wxs->destroy_listener,
+ weston_xserver_destroy)) {
+ free(wxs);
+ return 0;
+ }
+
if (weston_xwayland_get_api(compositor) != NULL ||
weston_xwayland_surface_get_api(compositor) != NULL) {
weston_log("The xwayland module APIs are already loaded.\n");
- free(wxs);
- return -1;
+ goto out_free;
}
ret = weston_plugin_api_register(compositor, WESTON_XWAYLAND_API_NAME,
&api, sizeof(api));
if (ret < 0) {
weston_log("Failed to register the xwayland module API.\n");
- free(wxs);
- return -1;
+ goto out_free;
}
ret = weston_plugin_api_register(compositor,
&surface_api, sizeof(surface_api));
if (ret < 0) {
weston_log("Failed to register the xwayland surface API.\n");
- free(wxs);
- return -1;
+ goto out_free;
}
- wxs->destroy_listener.notify = weston_xserver_destroy;
- wl_signal_add(&compositor->destroy_signal, &wxs->destroy_listener);
-
wxs->wm_debug =
weston_compositor_add_log_scope(wxs->compositor->weston_log_ctx,
"xwm-wm-x11",
NULL, NULL, NULL);
return 0;
+
+out_free:
+ wl_list_remove(&wxs->destroy_listener.link);
+ free(wxs);
+ return -1;
}