[folks] Make BackendStore.load_backends() idempotent.
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Make BackendStore.load_backends() idempotent.
- Date: Wed, 22 Sep 2010 16:12:19 +0000 (UTC)
commit 5c035298f3a0fe33f0b53798d66d4f3e73014a25
Author: Travis Reitter <travis reitter collabora co uk>
Date: Wed Sep 8 16:15:02 2010 -0700
Make BackendStore.load_backends() idempotent.
Helps bgo#629331.
folks/backend-store.vala | 92 ++++++++++++++++++++++++++-------------------
1 files changed, 53 insertions(+), 39 deletions(-)
---
diff --git a/folks/backend-store.vala b/folks/backend-store.vala
index 2264e6c..5e34e75 100644
--- a/folks/backend-store.vala
+++ b/folks/backend-store.vala
@@ -40,6 +40,7 @@ public class Folks.BackendStore : Object {
private HashMap<string,Backend> _prepared_backends;
private GLib.List<ModuleFinalizeFunc> finalize_funcs = null;
private static weak BackendStore instance;
+ private static bool _backends_loaded = false;
/**
* Emitted when a backend has been added to the BackendStore.
@@ -112,6 +113,10 @@ public class Folks.BackendStore : Object {
foreach (ModuleFinalizeFunc func in this.finalize_funcs)
func (this);
+ /* reset status of backends */
+ lock (this._backends_loaded)
+ this._backends_loaded = false;
+
/* manually clear the singleton instance */
instance = null;
}
@@ -123,49 +128,58 @@ public class Folks.BackendStore : Object {
* environment variable, if it's set. If it's not set, backends will be
* searched for in a path set at compilation time.
*/
- public async void load_backends () throws GLib.Error {
- assert (Module.supported());
-
- var path = Environment.get_variable ("FOLKS_BACKEND_DIR");
- if (path == null)
- {
- path = BuildConf.BACKEND_DIR;
-
- debug ("Using built-in backend dir '%s' (override with environment "
- + "variable FOLKS_BACKEND_DIR)", path);
- }
- else
- {
- debug ("Using environment variable FOLKS_BACKEND_DIR = '%s' to look "
- + "for backends", path);
- }
-
- File dir = File.new_for_path (path);
- assert (dir != null && yield is_dir (dir));
-
- yield this.load_modules_from_dir (dir);
-
- /* all the found modules should call add_backend() for their backends
- * (adding them to the backend hash) as a consequence of
- * load_modules_from_dir(). */
-
- foreach (var backend in this.backend_hash.values)
+ public async void load_backends () throws GLib.Error
+ {
+ lock (this._backends_loaded)
{
- try
+ if (!this._backends_loaded)
{
- yield backend.prepare ();
-
- debug ("New backend '%s' prepared", backend.name);
- this._prepared_backends.set (backend.name, backend);
- this.backend_available (backend);
- }
- catch (GLib.Error e)
- {
- warning ("Error preparing Backend '%s': %s", backend.name,
- e.message);
+ assert (Module.supported());
+
+ var path = Environment.get_variable ("FOLKS_BACKEND_DIR");
+ if (path == null)
+ {
+ path = BuildConf.BACKEND_DIR;
+
+ debug ("Using built-in backend dir '%s' (override with " +
+ "environment variable FOLKS_BACKEND_DIR)", path);
+ }
+ else
+ {
+ debug ("Using environment variable FOLKS_BACKEND_DIR = " +
+ "'%s' to look for backends", path);
+ }
+
+ File dir = File.new_for_path (path);
+ assert (dir != null && yield is_dir (dir));
+
+ yield this.load_modules_from_dir (dir);
+
+ /* all the found modules should call add_backend() for their
+ * backends (adding them to the backend hash) as a consequence of
+ * load_modules_from_dir(). */
+
+ foreach (var backend in this.backend_hash.values)
+ {
+ try
+ {
+ yield backend.prepare ();
+
+ debug ("New backend '%s' prepared", backend.name);
+ this._prepared_backends.set (backend.name, backend);
+ this.backend_available (backend);
+ }
+ catch (GLib.Error e)
+ {
+ warning ("Error preparing Backend '%s': %s", backend.name,
+ e.message);
+ }
+ }
+
+ this._backends_loaded = true;
}
}
- }
+ }
/**
* Add a new { link Backend} to the BackendStore.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]