2 * Copyright (C) 2010 Collabora Ltd.
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or
7 * (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 * Travis Reitter <travis.reitter@collabora.co.uk>
25 * A single backend to libfolks, such as Telepathy or evolution-data-server.
26 * Each backend provides {@link Persona}s which are aggregated to form
27 * {@link Individual}s.
29 * After creating a Backend instance, you must connect to the
30 * {@link Backend.persona_store_added} and
31 * {@link Backend.persona_store_removed} signals, //then// call
32 * {@link Backend.prepare}, otherwise a race condition may occur between
33 * emission of {@link Backend.persona_store_added} and your code connecting to
36 public abstract class Folks.Backend : Object
40 debug ("Constructing Backend ā%sā (%p)", this.name, this);
45 debug ("Destroying Backend ā%sā (%p)", this.name, this);
49 * Whether {@link Backend.prepare} has successfully completed for this
54 public abstract bool is_prepared { get; default = false; }
57 * Whether the backend has reached a quiescent state. This will happen at some
58 * point after {@link Backend.prepare} has successfully completed for the
59 * backend. A backend is in a quiescent state when all the
60 * {@link PersonaStore}s that it originally knows about have been loaded.
62 * It's guaranteed that this property's value will only ever change after
63 * {@link Backend.is_prepared} has changed to `true`.
65 * When {@link Backend.unprepare} is called, this will be reset to `false`.
69 public abstract bool is_quiescent { get; default = false; }
72 * A unique name for the backend.
74 * This will be used to identify the backend, and should also be used as the
75 * {@link PersonaStore.type_id} of the {@link PersonaStore}s used by the
78 * This is guaranteed to always be available; even before
79 * {@link Backend.prepare} is called.
81 public abstract string name { get; }
84 * The {@link PersonaStore}s in use by the backend.
86 * A backend may expose {@link Persona}s from multiple servers or accounts
87 * (for example), so may have a {@link PersonaStore} for each.
91 public abstract Map<string, PersonaStore> persona_stores { get; }
94 * Emitted when a {@link PersonaStore} is added to the backend.
96 * This will not be emitted until after {@link Backend.prepare} has been
99 * @param store the {@link PersonaStore}
101 public abstract signal void persona_store_added (PersonaStore store);
104 * Emitted when a {@link PersonaStore} is removed from the backend.
106 * This will not be emitted until after {@link Backend.prepare} has been
109 * @param store the {@link PersonaStore}
111 public abstract signal void persona_store_removed (PersonaStore store);
114 * Prepare the Backend for use.
116 * This connects the Backend to whichever backend-specific services it
117 * requires, and causes it to create its {@link PersonaStore}s. This should be
118 * called //after// connecting to the {@link Backend.persona_store_added} and
119 * {@link Backend.persona_store_removed} signals, or a race condition could
120 * occur, with the signals being emitted before your code has connected to
121 * them, and {@link PersonaStore}s getting "lost" as a result.
123 * This is normally handled transparently by the {@link IndividualAggregator}.
125 * If this function throws an error, the Backend will not be functional.
127 * This function is guaranteed to be idempotent (since version 0.3.0).
129 * Concurrent calls to this function from different threads will block until
130 * preparation has completed. However, concurrent calls to this function from
131 * a single thread might not, i.e. the first call will block but subsequent
132 * calls might return before the first one. (Though they will be safe in every
137 public abstract async void prepare () throws GLib.Error;
140 * Revert the Backend to its pre-prepared state.
142 * This will disconnect this Backend and its dependencies from their
143 * respective services and the Backend will issue
144 * {@link Backend.persona_store_removed} for each of its
145 * {@link PersonaStore}s.
147 * Most users won't need to use this function.
149 * If this function throws an error, the Backend will not be functional.
151 * Concurrent calls to this function from different threads will block until
152 * preparation has completed. However, concurrent calls to this function from
153 * a single thread might not, i.e. the first call will block but subsequent
154 * calls might return before the first one. (Though they will be safe in every
159 public abstract async void unprepare () throws GLib.Error;