Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / addressbook / libedata-book / e-book-backend-factory.h
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* e-book-backend-factory.h
3  *
4  * Copyright (C) 2004  Novell, Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  * Author: Chris Toshok <toshok@ximian.com>
21  */
22
23 #ifndef _E_BOOK_BACKEND_FACTORY_H_
24 #define _E_BOOK_BACKEND_FACTORY_H_
25
26 #include <glib-object.h>
27 #include "e-book-backend.h"
28
29 G_BEGIN_DECLS
30
31 #define E_TYPE_BOOK_BACKEND_FACTORY        (e_book_backend_factory_get_type ())
32 #define E_BOOK_BACKEND_FACTORY(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), E_TYPE_BOOK_BACKEND_FACTORY, EBookBackendFactory))
33 #define E_BOOK_BACKEND_FACTORY_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), E_TYPE_BOOK_BACKEND_FACTORY, EBookBackendFactoryClass))
34 #define E_IS_BOOK_BACKEND_FACTORY(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_TYPE_BOOK_BACKEND_FACTORY))
35 #define E_IS_BOOK_BACKEND_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), E_TYPE_BOOK_BACKEND_FACTORY))
36 #define E_BOOK_BACKEND_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), E_TYPE_BOOK_BACKEND_FACTORY, EBookBackendFactoryClass))
37
38 typedef struct _EBookBackendFactoryPrivate EBookBackendFactoryPrivate;
39
40 typedef struct {
41         GObject            parent_object;
42 } EBookBackendFactory;
43
44 typedef struct {
45         GObjectClass parent_class;
46
47         const char*   (*get_protocol) (EBookBackendFactory *factory);
48         EBookBackend* (*new_backend)  (EBookBackendFactory *factory);
49 } EBookBackendFactoryClass;
50
51 GType                e_book_backend_factory_get_type             (void);
52
53 const char*          e_book_backend_factory_get_protocol         (EBookBackendFactory *factory);
54 EBookBackend*        e_book_backend_factory_new_backend          (EBookBackendFactory *factory);
55
56
57 /* use this macro for simple, 1 factory modules */
58 #define E_BOOK_BACKEND_FACTORY_SIMPLE(p,t,f) \
59 typedef struct { \
60         EBookBackendFactory      parent_object; \
61 } EBookBackend##t##Factory; \
62 \
63 typedef struct { \
64         EBookBackendFactoryClass parent_class; \
65 } EBookBackend##t##FactoryClass; \
66 \
67 static void \
68 _ ## p ##_factory_instance_init (EBookBackend## t ##Factory *factory) \
69 { \
70 } \
71 \
72 static const char * \
73 _ ## p ##_get_protocol (EBookBackendFactory *factory) \
74 { \
75         return #p; \
76 } \
77 \
78 static EBookBackend* \
79 _ ## p ##_new_backend (EBookBackendFactory *factory) \
80 { \
81         return (f) (); \
82 } \
83 \
84 static void \
85 _ ## p ##_factory_class_init (EBookBackend## t ##FactoryClass *klass) \
86 { \
87         E_BOOK_BACKEND_FACTORY_CLASS (klass)->get_protocol = _ ## p ##_get_protocol; \
88         E_BOOK_BACKEND_FACTORY_CLASS (klass)->new_backend = _ ## p ##_new_backend; \
89 } \
90 \
91 static GType \
92 _ ## p ##_factory_get_type (GTypeModule *module) \
93 { \
94         GType type; \
95 \
96         GTypeInfo info = { \
97                 sizeof (EBookBackend##t##FactoryClass), \
98                 NULL, /* base_class_init */ \
99                 NULL, /* base_class_finalize */ \
100                 (GClassInitFunc)  _ ## p ##_factory_class_init, \
101                 NULL, /* class_finalize */ \
102                 NULL, /* class_data */ \
103                 sizeof (EBookBackend##t##Factory), \
104                 0,    /* n_preallocs */ \
105                 (GInstanceInitFunc) _ ## p ##_factory_instance_init \
106         }; \
107 \
108         type = g_type_module_register_type (module, \
109                                             E_TYPE_BOOK_BACKEND_FACTORY, \
110                                             "EBookBackend" #t "Factory", \
111                                             &info, 0); \
112 \
113         return type; \
114 }
115
116 G_END_DECLS
117
118 #endif /* _E_BOOK_BACKEND_FACTORY_H_ */