[glom] Fixed initial records not being shown when creating from example



commit e67f260c93e73c4f8fb9319edee9c98a4cbc3b35
Author: Armin Burgmeier <armin arbur net>
Date:   Fri May 29 19:58:19 2009 +0200

    Fixed initial records not being shown when creating from example
    
    	* glom/libglom/connectionpool.cc: After invalidating a cached
    	connection, disconnect from the cached connection's "finished" signal,
    	to prevent the signal handler from being called later (other code
    	might still have a reference to the connection at the
    	invalidate_connection point). Also added a TODO comment, because this
    	can still happen in rare cases. This fixes initial records not being
    	shown after creating a database from an example file.
---
 ChangeLog                      |   10 ++++++++++
 glom/libglom/connectionpool.cc |   24 +++++++++++++++++-------
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6fc6da7..4c0efe9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-05-29  Armin Burgmeier  <armin openismus com>
+
+	* glom/libglom/connectionpool.cc: After invalidating a cached
+	connection, disconnect from the cached connection's "finished" signal,
+	to prevent the signal handler from being called later (other code
+	might still have a reference to the connection at the
+	invalidate_connection point). Also added a TODO comment, because this
+	can still happen in rare cases. This fixes initial records not being
+	shown after creating a database from an example file.
+
 2009-05-27  Armin Burgmeier  <armin openismus com>
 
 	* glom/mode_data/notebook_data.cc: Added an accessible name for the
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index 5b63c5c..7455639 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -310,8 +310,10 @@ sharedptr<SharedConnection> ConnectionPool::get_and_connect(std::auto_ptr<Except
 // Store the connection for a few seconds in case it 
 // is immediately requested again, to avoid making a new connection 
 // and introspecting again, which is slow. 
+// TODO: Why aren't these member variables?
 static sharedptr<SharedConnection> connection_cached;
 static sigc::connection connection_cached_timeout_connection;
+static sigc::connection connection_cached_finished_connection;
 
 static bool on_connection_pool_cache_timeout()
 {
@@ -335,13 +337,24 @@ sharedptr<SharedConnection> ConnectionPool::connect(std::auto_ptr<ExceptionConne
 
   if(get_ready_to_connect())
   {
+    if(connection_cached)
+    {
+      //Avoid a reconnection immediately after disconnecting:
+      return connection_cached;
+    }
     //If the connection is already open (because it is being used by somebody):
-    if(m_refGdaConnection)
+    else if(m_refGdaConnection)
     {
       sharedptr<SharedConnection> sharedConnection( new SharedConnection(m_refGdaConnection) );
 
       //Ask for notification when the SharedConnection has been finished with:
-      sharedConnection->signal_finished().connect( sigc::mem_fun(*this, &ConnectionPool::on_sharedconnection_finished) );
+      //TODO: Note that we are overwriting the connection to a signal of a
+      //previous sharedconnection here. This can be problematic when
+      //invalidate_connection() is called, because then we don't disconnect
+      //from the signal of the previous instance, and when the signal
+      //handler is called later we might decrement the reference count for
+      //a completely different shared connection.
+      connection_cached_finished_connection = sharedConnection->signal_finished().connect( sigc::mem_fun(*this, &ConnectionPool::on_sharedconnection_finished) );
 
       //Remember that somebody is using it:
       m_sharedconnection_refcount++;
@@ -354,11 +367,6 @@ sharedptr<SharedConnection> ConnectionPool::connect(std::auto_ptr<ExceptionConne
 
       return sharedConnection;
     }
-    else if(connection_cached)
-    {
-      //Avoid a reconnection immediately after disconnecting:
-      return connection_cached;
-    }
     else
     {
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -513,6 +521,8 @@ Glib::ustring ConnectionPool::get_string_find_operator() const
 void ConnectionPool::invalidate_connection()
 {
   connection_cached.clear();
+  connection_cached_timeout_connection.disconnect();
+  connection_cached_finished_connection.disconnect();
   m_refGdaConnection.reset();
   m_sharedconnection_refcount = 0;
 }



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