[calls/wip/detect-network-changes: 2/3] sip: origin: Recreate sofia handles on network change




commit 22705126a655817be9a6acdf28b335c68a8c6b69
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Sat Jul 31 12:59:03 2021 +0200

    sip: origin: Recreate sofia handles on network change

 plugins/sip/calls-sip-origin.c | 70 +++++++++++++++++++++++++++++-------------
 1 file changed, 49 insertions(+), 21 deletions(-)
---
diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c
index 1fc78308..edeaadba 100644
--- a/plugins/sip/calls-sip-origin.c
+++ b/plugins/sip/calls-sip-origin.c
@@ -33,6 +33,7 @@
 #include "calls-sip-origin.h"
 #include "calls-sip-util.h"
 #include "calls-sip-media-manager.h"
+#include "calls-network-watch.h"
 #include "config.h"
 #include "enum-types.h"
 
@@ -1010,6 +1011,45 @@ init_sip_account (CallsSipOrigin *self,
 }
 
 
+static void
+deinit_sip_account (CallsSipOrigin *self)
+{
+  g_assert (CALLS_IS_SIP_ORIGIN (self));
+
+  if (self->state == CALLS_ACCOUNT_NULL)
+    return;
+
+  remove_calls (self, NULL);
+
+  if (!self->use_direct_connection && self->state == CALLS_ACCOUNT_ONLINE)
+    go_online (CALLS_ACCOUNT (self), FALSE);
+
+  if (self->nua) {
+    g_debug ("Requesting nua_shutdown ()");
+    nua_shutdown (self->nua);
+    // need to wait for nua_r_shutdown event before calling nua_destroy ()
+    while (!self->is_nua_shutdown)
+      su_root_step (self->ctx->root, 100);
+
+    g_debug ("nua_shutdown () complete. Destroying nua handle");
+    nua_destroy (self->nua);
+    self->nua = NULL;
+  }
+
+  self->state = CALLS_ACCOUNT_NULL;
+}
+
+
+static void
+on_network_changed (CallsSipOrigin *self)
+{
+  if (self->auto_connect || self->state == CALLS_ACCOUNT_ONLINE) {
+    deinit_sip_account (self);
+    init_sip_account (self, NULL);
+  }
+}
+
+
 static gboolean
 supports_protocol (CallsOrigin *origin,
                    const char  *protocol)
@@ -1043,6 +1083,7 @@ update_name (CallsSipOrigin *self)
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NAME]);
 }
 
+
 static void
 calls_sip_origin_set_property (GObject      *object,
                                guint         property_id,
@@ -1215,27 +1256,7 @@ calls_sip_origin_dispose (GObject *object)
 {
   CallsSipOrigin *self = CALLS_SIP_ORIGIN (object);
 
-  if (self->state == CALLS_ACCOUNT_NULL)
-    return;
-
-  remove_calls (self, NULL);
-
-  if (!self->use_direct_connection && self->state == CALLS_ACCOUNT_ONLINE)
-    go_online (CALLS_ACCOUNT (self), FALSE);
-
-  if (self->nua) {
-    g_debug ("Requesting nua_shutdown ()");
-    nua_shutdown (self->nua);
-    // need to wait for nua_r_shutdown event before calling nua_destroy ()
-    while (!self->is_nua_shutdown)
-      su_root_step (self->ctx->root, 100);
-
-    g_debug ("nua_shutdown () complete. Destroying nua handle");
-    nua_destroy (self->nua);
-    self->nua = NULL;
-  }
-
-  self->state = CALLS_ACCOUNT_NULL;
+  deinit_sip_account (self);
 
   G_OBJECT_CLASS (calls_sip_origin_parent_class)->dispose (object);
 }
@@ -1385,7 +1406,14 @@ calls_sip_origin_accounts_interface_init (CallsAccountInterface *iface)
 static void
 calls_sip_origin_init (CallsSipOrigin *self)
 {
+  CallsNetworkWatch *nw = calls_network_watch_get_default ();
+
+  if (nw)
+    g_signal_connect_swapped (nw, "network-changed",
+                              G_CALLBACK (on_network_changed), self);
+
   self->call_handles = g_hash_table_new (NULL, NULL);
+
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]