[folks] individual: Clean up how Personas are transferred between Individuals



commit f00534294d7d52ac7e37dfaa075e3465b7755483
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Wed Nov 20 13:12:11 2013 +0000

    individual: Clean up how Personas are transferred between Individuals
    
    Slightly improve it so that (theoretically) it’s now impossible for two
    Individuals to be connected to the same Persona simultaneously. Now, the
    old Individual will be automatically disconnected when the new
    Individual is connected.

 folks/individual.vala |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/folks/individual.vala b/folks/individual.vala
index 305a80c..01004c2 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -1230,6 +1230,10 @@ public class Folks.Individual : Object,
     {
       var persona = (Persona) obj;  /* will abort on failure */
 
+      /* It should not be possible for two Individuals to be simultaneously
+       * connected to the same Persona (as _connect_to_persona() will disconnect
+       * any previous Persona.individual), but warn (rather than asserting) just
+       * in case, since this is a critical code path. */
       if (ps.name != "individual" &&
           persona.individual != this &&
           persona.individual != null)
@@ -2122,6 +2126,13 @@ public class Folks.Individual : Object,
 
   private void _connect_to_persona (Persona persona)
     {
+      if (persona.individual != null)
+        {
+          /* Disconnect the previous Individual. This atomically avoids having
+           * two Individuals connected to the same Persona simultaneously. */
+          persona.individual._disconnect_from_persona (persona, this);
+        }
+
       persona.individual = this;
 
       /* We're interested in most, if not all, signals from a persona,


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