fix jsut committed crasher by rewriting startDrag action
[swfdec.git] / libswfdec / swfdec_cached.c
blob37b5737b2e0edd903d85cdf68ff8829c5c33f511
1 /* Swfdec
2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
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.1 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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "swfdec_cached.h"
25 #include "swfdec_debug.h"
28 G_DEFINE_ABSTRACT_TYPE (SwfdecCached, swfdec_cached, SWFDEC_TYPE_CHARACTER)
30 static void
31 swfdec_cached_dispose (GObject *object)
33 SwfdecCached * cached = SWFDEC_CACHED (object);
35 swfdec_cached_set_cache (cached, NULL);
37 G_OBJECT_CLASS (swfdec_cached_parent_class)->dispose (object);
40 static void
41 swfdec_cached_class_init (SwfdecCachedClass * g_class)
43 GObjectClass *object_class = G_OBJECT_CLASS (g_class);
45 object_class->dispose = swfdec_cached_dispose;
48 static void
49 swfdec_cached_init (SwfdecCached * cached)
53 void
54 swfdec_cached_set_cache (SwfdecCached *cached, SwfdecCache *cache)
56 g_return_if_fail (SWFDEC_IS_CACHED (cached));
58 if (cached->cache) {
59 if (cached->handle.unload)
60 swfdec_cache_remove_handle (cached->cache, &cached->handle);
61 swfdec_cache_unref (cached->cache);
63 cached->cache = cache;
64 if (cache) {
65 swfdec_cache_ref (cache);
66 if (cached->handle.unload)
67 swfdec_cache_add_handle (cached->cache, &cached->handle);
71 static void
72 swfdec_cached_unload_func (gpointer data)
74 SwfdecCached *cached = SWFDEC_CACHED ((guint8 *) data - G_STRUCT_OFFSET (SwfdecCached, handle));
76 cached->handle.unload = NULL;
77 swfdec_cached_unload (cached);
80 void
81 swfdec_cached_load (SwfdecCached *cached, guint size)
83 g_return_if_fail (SWFDEC_IS_CACHED (cached));
84 g_return_if_fail (cached->handle.unload == NULL);
85 g_return_if_fail (size > 0);
87 cached->handle.unload = swfdec_cached_unload_func;
88 cached->handle.size = size;
89 if (cached->cache)
90 swfdec_cache_add_handle (cached->cache, &cached->handle);
93 void
94 swfdec_cached_use (SwfdecCached *cached)
96 g_return_if_fail (SWFDEC_IS_CACHED (cached));
97 g_return_if_fail (cached->handle.unload != NULL);
99 if (cached->cache)
100 swfdec_cache_add_handle (cached->cache, &cached->handle);
103 void
104 swfdec_cached_unload (SwfdecCached *cached)
106 g_return_if_fail (SWFDEC_IS_CACHED (cached));
108 if (cached->handle.unload) {
109 if (cached->cache)
110 swfdec_cache_remove_handle (cached->cache, &cached->handle);
111 cached->handle.unload = NULL;
113 if (cached->handle.size) {
114 SwfdecCachedClass *klass;
116 klass = SWFDEC_CACHED_GET_CLASS (cached);
117 cached->handle.size = 0;
118 g_return_if_fail (klass->unload != NULL);
119 klass->unload (cached);