1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-06-28 14:49:30 +00:00

DummyPlugin: fix events emits for call-removed, origin-*

This fixes this two issues:
- Emit the events origin-removed, origin-added when required.

- Remove call immediately when disconnected and emit events:
  By using `g_idle_add ()` we can't be sure when the call is actually
  removed and could stay potentionaly for evere, as long the main loop is
  busy. This can lead to unexpected behavior. If the calls shouldn't be
  freed then it's required to increase the ref count. This is similar how
  the `remove` event works in a `GtkContainer`.
This commit is contained in:
Julian Sparber 2020-03-20 18:28:52 +01:00 committed by Julian Sparber
parent 113dbbba88
commit 389e772069
2 changed files with 28 additions and 34 deletions

View file

@ -87,9 +87,10 @@ remove_call (CallsDummyOrigin *self,
CallsOrigin *origin;
origin = CALLS_ORIGIN (self);
self->calls = g_list_remove (self->calls, call);
g_signal_emit_by_name (origin, "call-removed", call, reason);
self->calls = g_list_remove (self->calls, call);
g_object_unref (G_OBJECT (call));
}
@ -97,14 +98,18 @@ remove_call (CallsDummyOrigin *self,
static void
remove_calls (CallsDummyOrigin *self, const gchar *reason)
{
GList *node, *next;
gpointer call;
GList *next;
for (node = self->calls; node; node = next)
{
next = node->next;
while (self->calls != NULL) {
call = self->calls->data;
next = self->calls->next;
g_list_free_1 (self->calls);
self->calls = next;
remove_call (self, CALLS_CALL (node->data), reason);
}
g_signal_emit_by_name (self, "call-removed", call, reason);
g_object_unref (call);
}
}
@ -115,25 +120,12 @@ struct DisconnectedData
};
static gboolean
disconnected_cb (struct DisconnectedData *data)
{
remove_call (data->self, data->call, "Disconnected");
g_object_unref (G_OBJECT (data->call));
g_object_unref (G_OBJECT (data->self));
g_free (data);
return FALSE;
}
static void
call_state_changed_cb (CallsDummyOrigin *self,
CallsCallState new_state,
CallsCallState old_state,
CallsCall *call)
{
struct DisconnectedData *data;
if (new_state != CALLS_CALL_STATE_DISCONNECTED)
{
return;
@ -142,16 +134,7 @@ call_state_changed_cb (CallsDummyOrigin *self,
g_return_if_fail (CALLS_IS_DUMMY_ORIGIN (self));
g_return_if_fail (CALLS_IS_CALL (call));
// We add an idle callback so that all of the state change handlers
// are dealt with before the removal
data = g_new (struct DisconnectedData, 1);
data->self = self;
data->call = call;
g_object_ref (G_OBJECT (self));
g_object_ref (G_OBJECT (call));
g_idle_add ((GSourceFunc)disconnected_cb, data);
remove_call (self, call, "Disconnected");
}

View file

@ -135,10 +135,19 @@ get_property (GObject *object,
static void
dispose (GObject *object)
{
gpointer origin;
GList *next;
CallsDummyProvider *self = CALLS_DUMMY_PROVIDER (object);
g_list_free_full (self->origins, g_object_unref);
self->origins = NULL;
while (self->origins != NULL) {
origin = self->origins->data;
next = self->origins->next;
g_list_free_1 (self->origins);
self->origins = next;
g_signal_emit_by_name (self, "origin-removed", origin);
g_object_unref (origin);
}
G_OBJECT_CLASS (calls_dummy_provider_parent_class)->dispose (object);
}
@ -181,8 +190,10 @@ void
calls_dummy_provider_add_origin (CallsDummyProvider *self,
const gchar *name)
{
self->origins = g_list_append (self->origins,
calls_dummy_origin_new (name));
CallsDummyOrigin *origin = calls_dummy_origin_new (name);
self->origins = g_list_append (self->origins, origin);
g_signal_emit_by_name (CALLS_PROVIDER (self), "origin-added", CALLS_ORIGIN (origin));
}