~ubuntu-branches/ubuntu/quantal/evolution-data-server/quantal

« back to all changes in this revision

Viewing changes to libebackend/e-backend.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-18 19:32:20 UTC
  • mfrom: (1.1.98) (1.6.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120518193220-v4re47nsbqy2ko3t
Tags: 3.4.2-1
* New upstream version.
* Add list-missing target.
* Install gsettings schemas and gconf conversion scripts.
* Include buildflags.mk, and adjust rules to use all hardening flags.
* Move all gtk-doc API documentation to a new evolution-data-server-doc
  binary, and let it break/replace obsolete libedataserverui1.2-dev
  (closes: #672253).
* Build-Depend on libglib2.0-doc and libdbus-glib-1-doc to ensure
  proper cross-reference links in generated gtk-doc API documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * e-backend.c
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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/>
 
16
 *
 
17
 */
 
18
 
 
19
/**
 
20
 * SECTION: e-backend
 
21
 * @short_description: an abstract base class for backends
 
22
 * @include: libebackend/e-backend.h
 
23
 *
 
24
 * An #EBackend is paired with an #ESource to facilitate performing
 
25
 * actions on the local or remote resource described by the #ESource.
 
26
 *
 
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.
 
30
 *
 
31
 * All #EBackend instances are created by an #EBackendFactory.
 
32
 **/
 
33
 
 
34
#include "e-backend.h"
 
35
 
 
36
#include <config.h>
 
37
 
 
38
#define E_BACKEND_GET_PRIVATE(obj) \
 
39
        (G_TYPE_INSTANCE_GET_PRIVATE \
 
40
        ((obj), E_TYPE_BACKEND, EBackendPrivate))
 
41
 
 
42
struct _EBackendPrivate {
 
43
        ESource *source;
 
44
        gboolean online;
 
45
};
 
46
 
 
47
enum {
 
48
        PROP_0,
 
49
        PROP_ONLINE,
 
50
        PROP_SOURCE
 
51
};
 
52
 
 
53
enum {
 
54
        LAST_CLIENT_GONE,
 
55
        LAST_SIGNAL
 
56
};
 
57
 
 
58
static guint signals[LAST_SIGNAL];
 
59
 
 
60
G_DEFINE_ABSTRACT_TYPE (EBackend, e_backend, G_TYPE_OBJECT)
 
61
 
 
62
static void
 
63
backend_set_source (EBackend *backend,
 
64
                    ESource *source)
 
65
{
 
66
        g_return_if_fail (E_IS_SOURCE (source));
 
67
        g_return_if_fail (backend->priv->source == NULL);
 
68
 
 
69
        backend->priv->source = g_object_ref (source);
 
70
}
 
71
 
 
72
static void
 
73
backend_set_property (GObject *object,
 
74
                      guint property_id,
 
75
                      const GValue *value,
 
76
                      GParamSpec *pspec)
 
77
{
 
78
        switch (property_id) {
 
79
                case PROP_ONLINE:
 
80
                        e_backend_set_online (
 
81
                                E_BACKEND (object),
 
82
                                g_value_get_boolean (value));
 
83
                        return;
 
84
 
 
85
                case PROP_SOURCE:
 
86
                        backend_set_source (
 
87
                                E_BACKEND (object),
 
88
                                g_value_get_object (value));
 
89
                        return;
 
90
        }
 
91
 
 
92
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
93
}
 
94
 
 
95
static void
 
96
backend_get_property (GObject *object,
 
97
                      guint property_id,
 
98
                      GValue *value,
 
99
                      GParamSpec *pspec)
 
100
{
 
101
        switch (property_id) {
 
102
                case PROP_ONLINE:
 
103
                        g_value_set_boolean (
 
104
                                value, e_backend_get_online (
 
105
                                E_BACKEND (object)));
 
106
                        return;
 
107
 
 
108
                case PROP_SOURCE:
 
109
                        g_value_set_object (
 
110
                                value, e_backend_get_source (
 
111
                                E_BACKEND (object)));
 
112
                        return;
 
113
        }
 
114
 
 
115
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
116
}
 
117
 
 
118
static void
 
119
backend_dispose (GObject *object)
 
120
{
 
121
        EBackendPrivate *priv;
 
122
 
 
123
        priv = E_BACKEND_GET_PRIVATE (object);
 
124
 
 
125
        if (priv->source != NULL) {
 
126
                g_object_unref (priv->source);
 
127
                priv->source = NULL;
 
128
        }
 
129
 
 
130
        /* Chain up to parent's dispose() method. */
 
131
        G_OBJECT_CLASS (e_backend_parent_class)->dispose (object);
 
132
}
 
133
 
 
134
static void
 
135
e_backend_class_init (EBackendClass *class)
 
136
{
 
137
        GObjectClass *object_class;
 
138
 
 
139
        g_type_class_add_private (class, sizeof (EBackendPrivate));
 
140
 
 
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;
 
145
 
 
146
        g_object_class_install_property (
 
147
                object_class,
 
148
                PROP_ONLINE,
 
149
                g_param_spec_boolean (
 
150
                        "online",
 
151
                        "Online",
 
152
                        "Whether the backend is online",
 
153
                        TRUE,
 
154
                        G_PARAM_READWRITE |
 
155
                        G_PARAM_CONSTRUCT |
 
156
                        G_PARAM_STATIC_STRINGS));
 
157
 
 
158
        g_object_class_install_property (
 
159
                object_class,
 
160
                PROP_SOURCE,
 
161
                g_param_spec_object (
 
162
                        "source",
 
163
                        "Source",
 
164
                        "The data source being acted upon",
 
165
                        E_TYPE_SOURCE,
 
166
                        G_PARAM_READWRITE |
 
167
                        G_PARAM_CONSTRUCT_ONLY |
 
168
                        G_PARAM_STATIC_STRINGS));
 
169
 
 
170
        signals[LAST_CLIENT_GONE] = g_signal_new (
 
171
                "last-client-gone",
 
172
                G_OBJECT_CLASS_TYPE (object_class),
 
173
                G_SIGNAL_RUN_LAST,
 
174
                G_STRUCT_OFFSET (EBackendClass, last_client_gone),
 
175
                NULL, NULL,
 
176
                g_cclosure_marshal_VOID__VOID,
 
177
                G_TYPE_NONE, 0);
 
178
}
 
179
 
 
180
static void
 
181
e_backend_init (EBackend *backend)
 
182
{
 
183
        backend->priv = E_BACKEND_GET_PRIVATE (backend);
 
184
}
 
185
 
 
186
/**
 
187
 * e_backend_get_online:
 
188
 * @backend: an #EBackend
 
189
 *
 
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.
 
193
 *
 
194
 * Returns: the online state
 
195
 *
 
196
 * Since: 3.4
 
197
 **/
 
198
gboolean
 
199
e_backend_get_online (EBackend *backend)
 
200
{
 
201
        g_return_val_if_fail (E_IS_BACKEND (backend), FALSE);
 
202
 
 
203
        return backend->priv->online;
 
204
}
 
205
 
 
206
/**
 
207
 * e_backend_set_online:
 
208
 * @backend: an #EBackend
 
209
 * @online: the online state
 
210
 *
 
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.
 
214
 *
 
215
 * Since: 3.4
 
216
 **/
 
217
void
 
218
e_backend_set_online (EBackend *backend,
 
219
                      gboolean online)
 
220
{
 
221
        g_return_if_fail (E_IS_BACKEND (backend));
 
222
 
 
223
        /* Avoid unnecessary "notify" signals. */
 
224
        if (online == backend->priv->online)
 
225
                return;
 
226
 
 
227
        backend->priv->online = online;
 
228
 
 
229
        g_object_notify (G_OBJECT (backend), "online");
 
230
}
 
231
 
 
232
/**
 
233
 * e_backend_get_source:
 
234
 * @backend: an #EBackend
 
235
 *
 
236
 * Returns the #ESource to which @backend is paired.
 
237
 *
 
238
 * Returns: the #ESource to which @backend is paired
 
239
 *
 
240
 * Since: 3.4
 
241
 **/
 
242
ESource *
 
243
e_backend_get_source (EBackend *backend)
 
244
{
 
245
        g_return_val_if_fail (E_IS_BACKEND (backend), NULL);
 
246
 
 
247
        return backend->priv->source;
 
248
}
 
249
 
 
250
/**
 
251
 * e_backend_last_client_gone:
 
252
 * @backend: an #EBackend
 
253
 *
 
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.
 
258
 *
 
259
 * Since: 3.4
 
260
 **/
 
261
void
 
262
e_backend_last_client_gone (EBackend *backend)
 
263
{
 
264
        g_return_if_fail (E_IS_BACKEND (backend));
 
265
 
 
266
        g_signal_emit (backend, signals[LAST_CLIENT_GONE], 0);
 
267
}