4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) version 3.
9
* This program 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 GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with the program; if not, see <http://www.gnu.org/licenses/>
21
* @short_description: an abstract base class for backends
22
* @include: libebackend/e-backend.h
24
* An #EBackend is paired with an #ESource to facilitate performing
25
* actions on the local or remote resource described by the #ESource.
27
* In other words, whereas a certain backend type knows how to talk to a
28
* certain type of server or data store, the #ESource fills in configuration
29
* details such as host name, user name, resource path, etc.
31
* All #EBackend instances are created by an #EBackendFactory.
34
#include "e-backend.h"
38
#define E_BACKEND_GET_PRIVATE(obj) \
39
(G_TYPE_INSTANCE_GET_PRIVATE \
40
((obj), E_TYPE_BACKEND, EBackendPrivate))
42
struct _EBackendPrivate {
58
static guint signals[LAST_SIGNAL];
60
G_DEFINE_ABSTRACT_TYPE (EBackend, e_backend, G_TYPE_OBJECT)
63
backend_set_source (EBackend *backend,
66
g_return_if_fail (E_IS_SOURCE (source));
67
g_return_if_fail (backend->priv->source == NULL);
69
backend->priv->source = g_object_ref (source);
73
backend_set_property (GObject *object,
78
switch (property_id) {
80
e_backend_set_online (
82
g_value_get_boolean (value));
88
g_value_get_object (value));
92
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
96
backend_get_property (GObject *object,
101
switch (property_id) {
103
g_value_set_boolean (
104
value, e_backend_get_online (
105
E_BACKEND (object)));
110
value, e_backend_get_source (
111
E_BACKEND (object)));
115
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
119
backend_dispose (GObject *object)
121
EBackendPrivate *priv;
123
priv = E_BACKEND_GET_PRIVATE (object);
125
if (priv->source != NULL) {
126
g_object_unref (priv->source);
130
/* Chain up to parent's dispose() method. */
131
G_OBJECT_CLASS (e_backend_parent_class)->dispose (object);
135
e_backend_class_init (EBackendClass *class)
137
GObjectClass *object_class;
139
g_type_class_add_private (class, sizeof (EBackendPrivate));
141
object_class = G_OBJECT_CLASS (class);
142
object_class->set_property = backend_set_property;
143
object_class->get_property = backend_get_property;
144
object_class->dispose = backend_dispose;
146
g_object_class_install_property (
149
g_param_spec_boolean (
152
"Whether the backend is online",
156
G_PARAM_STATIC_STRINGS));
158
g_object_class_install_property (
161
g_param_spec_object (
164
"The data source being acted upon",
167
G_PARAM_CONSTRUCT_ONLY |
168
G_PARAM_STATIC_STRINGS));
170
signals[LAST_CLIENT_GONE] = g_signal_new (
172
G_OBJECT_CLASS_TYPE (object_class),
174
G_STRUCT_OFFSET (EBackendClass, last_client_gone),
176
g_cclosure_marshal_VOID__VOID,
181
e_backend_init (EBackend *backend)
183
backend->priv = E_BACKEND_GET_PRIVATE (backend);
187
* e_backend_get_online:
188
* @backend: an #EBackend
190
* Returns the online state of @backend: %TRUE if @backend is online,
191
* %FALSE if offline. The online state of each backend is bound to the
192
* online state of the #EDataFactory that created it.
194
* Returns: the online state
199
e_backend_get_online (EBackend *backend)
201
g_return_val_if_fail (E_IS_BACKEND (backend), FALSE);
203
return backend->priv->online;
207
* e_backend_set_online:
208
* @backend: an #EBackend
209
* @online: the online state
211
* Sets the online state of @backend: %TRUE if @backend is online,
212
* @FALSE if offline. The online state of each backend is bound to
213
* the online state of the #EDataFactory that created it.
218
e_backend_set_online (EBackend *backend,
221
g_return_if_fail (E_IS_BACKEND (backend));
223
/* Avoid unnecessary "notify" signals. */
224
if (online == backend->priv->online)
227
backend->priv->online = online;
229
g_object_notify (G_OBJECT (backend), "online");
233
* e_backend_get_source:
234
* @backend: an #EBackend
236
* Returns the #ESource to which @backend is paired.
238
* Returns: the #ESource to which @backend is paired
243
e_backend_get_source (EBackend *backend)
245
g_return_val_if_fail (E_IS_BACKEND (backend), NULL);
247
return backend->priv->source;
251
* e_backend_last_client_gone:
252
* @backend: an #EBackend
254
* Emits the #EBackend::last-client-gone signal to indicate the last
255
* client connection to @backend has been closed. The @backend may be
256
* finalized after a short period to reclaim resources if no new client
257
* connections are established.
262
e_backend_last_client_gone (EBackend *backend)
264
g_return_if_fail (E_IS_BACKEND (backend));
266
g_signal_emit (backend, signals[LAST_CLIENT_GONE], 0);