Debian Codegraph @

pkcs11/gkm/gkm-serializable.c

raw
1 /*
2 * gnome-keyring
3 *
4 * Copyright (C) 2008 Stefan Walter
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
21 #include "config.h"
22
23 #include "gkm-serializable.h"
24
25 static void
26 gkm_serializable_base_init (gpointer gobject_class)
27 {
28 static gboolean initialized = FALSE;
29 if (!initialized) {
30 /* Add properties and signals to the interface */
31
32
33 initialized = TRUE;
34 }
35 }
36
37 GType
38 gkm_serializable_get_type (void)
39 {
40 static gsize type_inited = 0;
41
42 if (g_once_init_enter (&type_inited)) {
43 static const GTypeInfo info = {
44 sizeof (GkmSerializableIface),
45 gkm_serializable_base_init, /* base init */
46 NULL, /* base finalize */
47 NULL, /* class_init */
48 NULL, /* class finalize */
49 NULL, /* class data */
50 0,
51 0, /* n_preallocs */
52 NULL, /* instance init */
53 };
54
55 GType type_id = g_type_register_static (G_TYPE_INTERFACE, "GkmSerializableIface", &info, 0);
56 g_type_interface_add_prerequisite (type_id, G_TYPE_OBJECT);
57
58 g_once_init_leave (&type_inited, type_id);
59 }
60
61 return type_inited;
62 }
63
64 gboolean
65 gkm_serializable_load (GkmSerializable *self, GkmSecret *login, GBytes *data)
66 {
67 g_return_val_if_fail (GKM_IS_SERIALIZABLE (self), FALSE);
68 g_return_val_if_fail (data != NULL, FALSE);
69 g_return_val_if_fail (GKM_SERIALIZABLE_GET_INTERFACE (self)->load, FALSE);
70 return GKM_SERIALIZABLE_GET_INTERFACE (self)->load (self, login, data);
71 }
72
73 GBytes *
74 gkm_serializable_save (GkmSerializable *self, GkmSecret *login)
75 {
76 g_return_val_if_fail (GKM_IS_SERIALIZABLE (self), FALSE);
77 g_return_val_if_fail (GKM_SERIALIZABLE_GET_INTERFACE (self)->save, FALSE);
78 return GKM_SERIALIZABLE_GET_INTERFACE (self)->save (self, login);
79 }