Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / cc / privatebcbmap.c
1 /* $Id$
2  * reactos Cache Manager (Cc*) PrivateBcb Map type structure of libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program 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
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "privatebcbmap.h"      /* self */
23 #include "privatebcb.h"
24 #include "privatebcb-priv.h"
25 #include "sharedcachemap-priv.h"
26 #include <glib-object.h>
27
28
29 struct _CaptivePrivateBcbMapObject {
30         CaptivePrivateBcbObject parent_instance;
31         };
32 struct _CaptivePrivateBcbMapObjectClass {
33         CaptivePrivateBcbObjectClass parent_class;
34         };
35
36
37 static gpointer captive_private_bcb_map_object_parent_class=NULL;
38
39
40 static void captive_private_bcb_map_object_finalize(CaptivePrivateBcbMapObject *captive_private_bcb_map_object)
41 {
42 CaptivePrivateBcbObject *captive_private_bcb_object;
43 CaptiveSharedCacheMapObject *captive_shared_cache_map_object;
44
45         g_return_if_fail(captive_private_bcb_map_object!=NULL);
46
47         captive_private_bcb_object=CAPTIVE_PRIVATE_BCB_OBJECT(captive_private_bcb_map_object);
48
49         if ((captive_shared_cache_map_object=captive_private_bcb_object->SharedCacheMap)) {
50                 g_assert(captive_shared_cache_map_object->map==captive_private_bcb_map_object);
51                 captive_shared_cache_map_object->map=NULL;
52                 g_object_unref(captive_shared_cache_map_object);        /* 'map' disconnected. */
53                 }
54
55         G_OBJECT_CLASS(captive_private_bcb_map_object_parent_class)->finalize((GObject *)captive_private_bcb_map_object);
56 }
57
58
59 static void captive_private_bcb_map_object_class_init(CaptivePrivateBcbMapObjectClass *class)
60 {
61 GObjectClass *gobject_class=G_OBJECT_CLASS(class);
62
63         captive_private_bcb_map_object_parent_class=g_type_class_ref(g_type_parent(G_TYPE_FROM_CLASS(class)));
64         gobject_class->finalize=(void (*)(GObject *object))captive_private_bcb_map_object_finalize;
65 }
66
67
68 static void captive_private_bcb_map_object_init(CaptivePrivateBcbMapObject *captive_private_bcb_map_object)
69 {
70 }
71
72
73 GType captive_private_bcb_map_object_get_type(void)
74 {
75 static GType captive_private_bcb_map_object_type=0;
76
77         if (!captive_private_bcb_map_object_type) {
78 static const GTypeInfo captive_private_bcb_map_object_info={
79                                 sizeof(CaptivePrivateBcbMapObjectClass),
80                                 NULL,   /* base_init */
81                                 NULL,   /* base_finalize */
82                                 (GClassInitFunc)captive_private_bcb_map_object_class_init,
83                                 NULL,   /* class_finalize */
84                                 NULL,   /* class_data */
85                                 sizeof(CaptivePrivateBcbMapObject),
86                                 5,      /* n_preallocs */
87                                 (GInstanceInitFunc)captive_private_bcb_map_object_init,
88                                 };
89
90                 captive_private_bcb_map_object_type=g_type_register_static(CAPTIVE_PRIVATE_BCB_TYPE_OBJECT,
91                                 "CaptivePrivateBcbMapObject",&captive_private_bcb_map_object_info,0);
92                 }
93
94         return captive_private_bcb_map_object_type;
95 }
96
97 CaptivePrivateBcbMapObject *captive_private_bcb_map_object_new(CaptiveSharedCacheMapObject *captive_shared_cache_map_object)
98 {
99 CaptivePrivateBcbMapObject *captive_private_bcb_map_object;
100
101         g_return_val_if_fail(CAPTIVE_SHARED_CACHE_MAP_IS_OBJECT(captive_shared_cache_map_object),NULL);
102
103         captive_private_bcb_map_object=g_object_new(
104                         CAPTIVE_PRIVATE_BCB_MAP_TYPE_OBJECT,    /* object_type */
105                         NULL);  /* first_property_name; FIXME: support properties */
106
107         _captive_private_bcb_object_connect_SharedCacheMap(CAPTIVE_PRIVATE_BCB_OBJECT(captive_private_bcb_map_object),
108                         captive_shared_cache_map_object);
109
110         g_assert(captive_shared_cache_map_object->map==NULL);
111         captive_shared_cache_map_object->map=captive_private_bcb_map_object;
112         g_object_ref(captive_shared_cache_map_object);  /* 'map' connected. */
113
114         return captive_private_bcb_map_object;
115 }
116
117 CaptivePrivateBcbMapObject *captive_private_bcb_map_object_get_ref
118                 (CaptiveSharedCacheMapObject *captive_shared_cache_map_object)
119 {
120         g_return_val_if_fail(CAPTIVE_SHARED_CACHE_MAP_IS_OBJECT(captive_shared_cache_map_object),NULL);
121
122         if (captive_shared_cache_map_object->map) {
123                 g_object_ref(captive_shared_cache_map_object->map);
124                 return captive_shared_cache_map_object->map;
125                 }
126         return captive_private_bcb_map_object_new(captive_shared_cache_map_object);
127 }