root/trunk/libtinymail-gpe/tny-gpe-platform-factory.c

Revision 3666 (checked in by jdapena, 7 months ago)

* Use GOnce registering all types in tinymail to make

registering thread-safe.

Line 
1 /* libtinymail-camel - The Tiny Mail base library for Camel
2  * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
3  *
4  * This library 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) any later version.
8  *
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 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 self library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #include <config.h>
20
21 #include <tny-gpe-platform-factory.h>
22 #include <tny-gpe-account-store.h>
23 #include <tny-gpe-device.h>
24 #include <tny-gtk-msg-view.h>
25 #include <tny-gtk-password-dialog.h>
26 #include <tny-camel-mime-part.h>
27 #include <tny-camel-msg.h>
28
29 static GObjectClass *parent_class = NULL;
30
31 static void
32 tny_gpe_platform_factory_instance_init (GTypeInstance *instance, gpointer g_class)
33 {
34         return;
35 }
36
37
38
39 static TnyMsg*
40 tny_gpe_platform_factory_new_msg (TnyPlatformFactory *self)
41 {
42         return tny_camel_msg_new ();
43 }
44
45
46 static TnyMimePart*
47 tny_gpe_platform_factory_new_mime_part (TnyPlatformFactory *self)
48 {
49         return tny_camel_mime_part_new ();
50 }
51
52
53 static TnyAccountStore*
54 tny_gpe_platform_factory_new_account_store (TnyPlatformFactory *self)
55 {
56         return tny_gpe_account_store_new ();
57 }
58
59 static TnyDevice*
60 tny_gpe_platform_factory_new_device (TnyPlatformFactory *self)
61 {
62         return tny_gpe_device_new ();
63 }
64
65 static TnyMsgView*
66 tny_gpe_platform_factory_new_msg_view (TnyPlatformFactory *self)
67 {
68         return tny_gtk_msg_view_new ();   
69 }
70
71 static TnyPasswordGetter*
72 tny_gpe_platform_factory_new_password_getter (TnyPlatformFactory *self)
73 {
74         return tny_gtk_password_dialog_new ();
75 }
76
77 /**
78  * tny_gpe_platform_factory_get_instance:
79  *
80  *
81  * Return value: The #TnyPlatformFactory singleton instance
82  **/
83 TnyPlatformFactory*
84 tny_gpe_platform_factory_get_instance (void)
85 {
86         TnyGpePlatformFactory *self = g_object_new (TNY_TYPE_GPE_PLATFORM_FACTORY, NULL);
87
88         return TNY_PLATFORM_FACTORY (self);
89 }
90
91
92 static void
93 tny_gpe_platform_factory_finalize (GObject *object)
94 {
95         (*parent_class->finalize) (object);
96
97         return;
98 }
99
100
101 static void
102 tny_platform_factory_init (gpointer g, gpointer iface_data)
103 {
104         TnyPlatformFactoryIface *klass = (TnyPlatformFactoryIface *)g;
105
106         klass->new_account_store= tny_gpe_platform_factory_new_account_store;
107         klass->new_device= tny_gpe_platform_factory_new_device;
108         klass->new_msg_view= tny_gpe_platform_factory_new_msg_view;
109         klass->new_msg= tny_gpe_platform_factory_new_msg;
110         klass->new_mime_part= tny_gpe_platform_factory_new_mime_part;
111         klass->new_password_getter= tny_gpe_platform_factory_new_password_getter;
112
113         return;
114 }
115
116
117 static TnyGpePlatformFactory *the_singleton = NULL;
118
119
120 static GObject*
121 tny_gpe_platform_factory_constructor (GType type, guint n_construct_params,
122                         GObjectConstructParam *construct_params)
123 {
124         GObject *object;
125
126         /* TODO: potential problem: singleton without lock */
127
128         if (G_UNLIKELY (!the_singleton))
129         {
130                 object = G_OBJECT_CLASS (parent_class)->constructor (type,
131                                 n_construct_params, construct_params);
132
133                 the_singleton = TNY_GPE_PLATFORM_FACTORY (object);
134         }
135         else
136         {
137                 /* refdbg killed bug!
138                 object = g_object_ref (G_OBJECT (the_singleton)); */
139
140                 object = G_OBJECT (the_singleton);
141                 g_object_freeze_notify (G_OBJECT(the_singleton));
142         }
143
144         return object;
145 }
146
147 static void
148 tny_gpe_platform_factory_class_init (TnyGpePlatformFactoryClass *class)
149 {
150         GObjectClass *object_class;
151
152         parent_class = g_type_class_peek_parent (class);
153         object_class = (GObjectClass*) class;
154
155         object_class->finalize = tny_gpe_platform_factory_finalize;
156         object_class->constructor = tny_gpe_platform_factory_constructor;
157
158         return;
159 }
160
161 static gpointer
162 tny_gpe_platform_factory_register_type (gpointer notused)
163 {
164         GType type = 0;
165
166         static const GTypeInfo info =
167                 {
168                         sizeof (TnyGpePlatformFactoryClass),
169                         NULL,   /* base_init */
170                         NULL,   /* base_finalize */
171                         (GClassInitFunc) tny_gpe_platform_factory_class_init,   /* class_init */
172                         NULL,   /* class_finalize */
173                         NULL,   /* class_data */
174                         sizeof (TnyGpePlatformFactory),
175                         0,      /* n_preallocs */
176                         tny_gpe_platform_factory_instance_init    /* instance_init */
177                 };
178        
179         static const GInterfaceInfo tny_platform_factory_info =
180                 {
181                         (GInterfaceInitFunc) tny_platform_factory_init, /* interface_init */
182                         NULL,         /* interface_finalize */
183                         NULL          /* interface_data */
184                 };
185        
186         type = g_type_register_static (G_TYPE_OBJECT,
187                                        "TnyGpePlatformFactory",
188                                        &info, 0);
189        
190         g_type_add_interface_static (type, TNY_TYPE_PLATFORM_FACTORY,
191                                      &tny_platform_factory_info);
192        
193         return GUINT_TO_POINTER (type);
194 }
195
196 GType
197 tny_gpe_platform_factory_get_type (void)
198 {
199         static GOnce once = G_ONCE_INIT;
200         g_once (&once, tny_gpe_platform_factory_register_type, NULL);
201         return GPOINTER_TO_UINT (once.retval);
202 }
Note: See TracBrowser for help on using the browser.