libfeedback: Cancel all running feedbacks on uninit
We keep track of the active ids and end them on uninit. This make sure feedbacks don't continue to run if the application quits and forgets to end a feedback.
This commit is contained in:
committed by
Guido Gunther
parent
ceef33c6a0
commit
49dab605c2
@@ -160,6 +160,7 @@ on_trigger_feedback_finished (LfbGdbusFeedback *proxy,
|
|||||||
} else {
|
} else {
|
||||||
g_task_return_boolean (task, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
state = LFB_EVENT_STATE_RUNNING;
|
state = LFB_EVENT_STATE_RUNNING;
|
||||||
|
_lfb_active_add_id (self->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
lfb_event_set_state (self, state);
|
lfb_event_set_state (self, state);
|
||||||
@@ -363,6 +364,7 @@ on_feedback_ended (LfbEvent *self,
|
|||||||
lfb_event_set_end_reason (self, reason);
|
lfb_event_set_end_reason (self, reason);
|
||||||
lfb_event_set_state (self, LFB_EVENT_STATE_ENDED);
|
lfb_event_set_state (self, LFB_EVENT_STATE_ENDED);
|
||||||
g_signal_emit (self, signals[SIGNAL_FEEDBACK_ENDED], 0);
|
g_signal_emit (self, signals[SIGNAL_FEEDBACK_ENDED], 0);
|
||||||
|
_lfb_active_remove_id (self->id);
|
||||||
self->id = 0;
|
self->id = 0;
|
||||||
g_signal_handler_disconnect (proxy, self->handler_id);
|
g_signal_handler_disconnect (proxy, self->handler_id);
|
||||||
self->handler_id = 0;
|
self->handler_id = 0;
|
||||||
@@ -412,6 +414,8 @@ lfb_event_trigger_feedback (LfbEvent *self, GError **error)
|
|||||||
&self->id,
|
&self->id,
|
||||||
NULL,
|
NULL,
|
||||||
error);
|
error);
|
||||||
|
if (success)
|
||||||
|
_lfb_active_add_id (self->id);
|
||||||
lfb_event_set_state (self, success ? LFB_EVENT_STATE_RUNNING : LFB_EVENT_STATE_ERRORED);
|
lfb_event_set_state (self, success ? LFB_EVENT_STATE_RUNNING : LFB_EVENT_STATE_ERRORED);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,7 @@
|
|||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
LfbGdbusFeedback *_lfb_get_proxy (void);
|
LfbGdbusFeedback *_lfb_get_proxy (void);
|
||||||
|
void _lfb_active_add_id (guint id);
|
||||||
|
void _lfb_active_remove_id (guint id);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@@ -40,6 +40,51 @@
|
|||||||
static LfbGdbusFeedback *_proxy;
|
static LfbGdbusFeedback *_proxy;
|
||||||
static char *_app_id;
|
static char *_app_id;
|
||||||
static gboolean _initted;
|
static gboolean _initted;
|
||||||
|
static GHashTable *_active_ids;
|
||||||
|
|
||||||
|
static void
|
||||||
|
lfb_cancel_feedbacks (void)
|
||||||
|
{
|
||||||
|
gpointer key, value;
|
||||||
|
GHashTableIter iter;
|
||||||
|
|
||||||
|
g_hash_table_iter_init (&iter, _active_ids);
|
||||||
|
|
||||||
|
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
||||||
|
guint id = GPOINTER_TO_UINT(key);
|
||||||
|
g_hash_table_iter_remove (&iter);
|
||||||
|
g_debug ("Cancellling feedback on shutdown %d", id);
|
||||||
|
/* Need to use a sync call here since there might not be a main loop anymore */
|
||||||
|
lfb_gdbus_feedback_call_end_feedback_sync (_proxy, id, NULL, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_lfb_active_add_id (guint id)
|
||||||
|
{
|
||||||
|
g_return_if_fail (id > 0);
|
||||||
|
|
||||||
|
if (!_initted)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_hash_table_add (_active_ids, GUINT_TO_POINTER (id));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_lfb_active_remove_id (guint id)
|
||||||
|
{
|
||||||
|
gboolean success;
|
||||||
|
|
||||||
|
g_return_if_fail (id > 0);
|
||||||
|
|
||||||
|
if (!_initted)
|
||||||
|
return;
|
||||||
|
|
||||||
|
success = g_hash_table_remove (_active_ids, GUINT_TO_POINTER(id));
|
||||||
|
if (!success)
|
||||||
|
g_warning ("Event id %d not known", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LfbGdbusFeedback *
|
LfbGdbusFeedback *
|
||||||
_lfb_get_proxy (void)
|
_lfb_get_proxy (void)
|
||||||
@@ -73,6 +118,7 @@ lfb_init (const gchar *app_id, GError **error)
|
|||||||
if (!_proxy)
|
if (!_proxy)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
_active_ids = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
g_object_add_weak_pointer (G_OBJECT (_proxy), (gpointer *) &_proxy);
|
g_object_add_weak_pointer (G_OBJECT (_proxy), (gpointer *) &_proxy);
|
||||||
|
|
||||||
_initted = TRUE;
|
_initted = TRUE;
|
||||||
@@ -90,6 +136,9 @@ lfb_uninit (void)
|
|||||||
{
|
{
|
||||||
_initted = FALSE;
|
_initted = FALSE;
|
||||||
|
|
||||||
|
/* Cancel all feedbacks that the client forgot to clean up */
|
||||||
|
lfb_cancel_feedbacks ();
|
||||||
|
g_clear_pointer (&_active_ids, g_hash_table_destroy);
|
||||||
g_clear_pointer (&_app_id, g_free);
|
g_clear_pointer (&_app_id, g_free);
|
||||||
g_clear_object (&_proxy);
|
g_clear_object (&_proxy);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user