File: platfact.c

package info (click to toggle)
libtinymail 0.0.9-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,148 kB
  • ctags: 19,175
  • sloc: ansic: 151,565; xml: 20,145; sh: 9,245; makefile: 2,394; cs: 243; cpp: 141; python: 93; perl: 71
file content (196 lines) | stat: -rw-r--r-- 4,790 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* libtinymail-camel - The Tiny Mail base library for Camel
 * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with self library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
#include <config.h>

#include "platfact.h"

#include <tny-account-store.h>
#include "account-store.h"

#include <tny-device.h>
#include "device.h"

#include <tny-msg-view.h>
#include <tny-gtk-msg-view.h>
#include <tny-camel-mime-part.h>
#include <tny-camel-msg.h>


static GObjectClass *parent_class = NULL;
static TnyTestPlatformFactory *the_singleton = NULL;

static void
tny_test_platform_factory_instance_init (GTypeInstance *instance, gpointer g_class)
{
	return;
}



static TnyMsg*
tny_test_platform_factory_new_msg (TnyPlatformFactory *self)
{
	return tny_camel_msg_new ();
}


static TnyMimePart*
tny_test_platform_factory_new_mime_part (TnyPlatformFactory *self)
{
	return tny_camel_mime_part_new ();
}


static TnyAccountStore*
tny_test_platform_factory_new_account_store (TnyPlatformFactory *self)
{
	return tny_test_account_store_new (FALSE, NULL);
}

static TnyDevice*
tny_test_platform_factory_new_device (TnyPlatformFactory *self)
{
	return tny_test_device_new ();
}

static TnyMsgView*
tny_test_platform_factory_new_msg_view (TnyPlatformFactory *self)
{
	return tny_gtk_msg_view_new ();
}

/**
 * tny_platform_factory_get_instance:
 *
 *
 * Return value: The #TnyPlatformFactory singleton instance
 **/
TnyPlatformFactory*
tny_test_platform_factory_get_instance (void)
{
	TnyTestPlatformFactory *self = g_object_new (TNY_TYPE_TEST_PLATFORM_FACTORY, NULL);

	return TNY_PLATFORM_FACTORY (self);
}


static void
tny_test_platform_factory_finalize (GObject *object)
{
	the_singleton = NULL;

	(*parent_class->finalize) (object);

	return;
}


static void
tny_platform_factory_init (gpointer g, gpointer iface_data)
{
	TnyPlatformFactoryIface *klass = (TnyPlatformFactoryIface *)g;

	klass->new_account_store= tny_test_platform_factory_new_account_store;
	klass->new_device= tny_test_platform_factory_new_device;
	klass->new_msg_view= tny_test_platform_factory_new_msg_view;
	klass->new_msg= tny_test_platform_factory_new_msg;
	klass->new_mime_part= tny_test_platform_factory_new_mime_part;

	return;
}


static GObject*
tny_test_platform_factory_constructor (GType type, guint n_construct_params,
			GObjectConstructParam *construct_params)
{
	GObject *object;

	/* TODO: potential problem: singleton without lock */

	if (G_UNLIKELY (!the_singleton))
	{
		object = G_OBJECT_CLASS (parent_class)->constructor (type,
				n_construct_params, construct_params);

		the_singleton = TNY_TEST_PLATFORM_FACTORY (object);
	}
	else
	{
		object = g_object_ref (G_OBJECT (the_singleton));

		object = G_OBJECT (the_singleton);
		g_object_freeze_notify (G_OBJECT(the_singleton));
	}

	return object;
}

static void 
tny_test_platform_factory_class_init (TnyTestPlatformFactoryClass *class)
{
	GObjectClass *object_class;

	parent_class = g_type_class_peek_parent (class);
	object_class = (GObjectClass*) class;

	object_class->finalize = tny_test_platform_factory_finalize;
	object_class->constructor = tny_test_platform_factory_constructor;

	return;
}

GType 
tny_test_platform_factory_get_type (void)
{
	static GType type = 0;

	if (G_UNLIKELY(type == 0))
	{
		static const GTypeInfo info = 
		{
		  sizeof (TnyTestPlatformFactoryClass),
		  NULL,   /* base_init */
		  NULL,   /* base_finalize */
		  (GClassInitFunc) tny_test_platform_factory_class_init,   /* class_init */
		  NULL,   /* class_finalize */
		  NULL,   /* class_data */
		  sizeof (TnyTestPlatformFactory),
		  0,      /* n_preallocs */
		  tny_test_platform_factory_instance_init    /* instance_init */
		};

		static const GInterfaceInfo tny_platform_factory_info = 
		{
		  (GInterfaceInitFunc) tny_platform_factory_init, /* interface_init */
		  NULL,         /* interface_finalize */
		  NULL          /* interface_data */
		};

		type = g_type_register_static (G_TYPE_OBJECT,
			"TnyTestPlatformFactory",
			&info, 0);

		g_type_add_interface_static (type, TNY_TYPE_PLATFORM_FACTORY, 
			&tny_platform_factory_info);

	}

	return type;
}