[tracker/direct-access: 69/121] libtracker-sparql: Only create single PluginLoader



commit e0863e74b389d9ad7d26e08c82669f9c7c5664d4
Author: Jürg Billeter <j bitron ch>
Date:   Mon Jul 19 13:38:32 2010 +0200

    libtracker-sparql: Only create single PluginLoader

 src/libtracker-sparql/tracker-connection.vala |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index 7bdd902..606b30b 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -18,12 +18,32 @@
  */
 
 public abstract class Tracker.Sparql.Connection : Object {
+	static bool direct_only;
+	static weak Connection? singleton;
+
 	public static Connection get () throws GLib.Error {
-		return new PluginLoader ();
+		if (singleton != null) {
+			assert (!direct_only);
+			return singleton;
+		} else {
+			var result = new PluginLoader ();
+			singleton = result;
+			result.add_weak_pointer ((void**) (&singleton));
+			return result;
+		}
 	}
 
 	public static Connection get_direct () throws GLib.Error {
-		return new PluginLoader (true /* direct_only */);
+		if (singleton != null) {
+			assert (direct_only);
+			return singleton;
+		} else {
+			var result = new PluginLoader (true /* direct_only */);
+			direct_only = true;
+			singleton = result;
+			result.add_weak_pointer ((void**) (&singleton));
+			return result;
+		}
 	}
 
 	// Query



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