1/*
2 * Copyright (C) 2009 Martin Robinson
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 this library; if not, write to the Free Software
16 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19#include "config.h"
20#include "GRefPtr.h"
21
22#if USE(GLIB)
23
24#include <glib-object.h>
25#include <glib.h>
26
27namespace WTF {
28
29template <> GHashTable* refGPtr(GHashTable* ptr)
30{
31    if (ptr)
32        g_hash_table_ref(ptr);
33    return ptr;
34}
35
36template <> void derefGPtr(GHashTable* ptr)
37{
38    g_hash_table_unref(ptr);
39}
40
41template <> GMainContext* refGPtr(GMainContext* ptr)
42{
43    if (ptr)
44        g_main_context_ref(ptr);
45    return ptr;
46}
47
48template <> void derefGPtr(GMainContext* ptr)
49{
50    if (ptr)
51        g_main_context_unref(ptr);
52}
53
54template <> GMainLoop* refGPtr(GMainLoop* ptr)
55{
56    if (ptr)
57        g_main_loop_ref(ptr);
58    return ptr;
59}
60
61template <> void derefGPtr(GMainLoop* ptr)
62{
63    if (ptr)
64        g_main_loop_unref(ptr);
65}
66
67template <> GBytes* refGPtr(GBytes* ptr)
68{
69    if (ptr)
70        g_bytes_ref(ptr);
71    return ptr;
72}
73
74template <> void derefGPtr(GBytes* ptr)
75{
76    if (ptr)
77        g_bytes_unref(ptr);
78}
79
80template <> GVariant* refGPtr(GVariant* ptr)
81{
82    if (ptr)
83        g_variant_ref_sink(ptr);
84    return ptr;
85}
86
87template <> void derefGPtr(GVariant* ptr)
88{
89    g_variant_unref(ptr);
90}
91
92template <> GSource* refGPtr(GSource* ptr)
93{
94    if (ptr)
95        g_source_ref(ptr);
96    return ptr;
97}
98
99template <> void derefGPtr(GSource* ptr)
100{
101    if (ptr)
102        g_source_unref(ptr);
103}
104
105template <> GPtrArray* refGPtr(GPtrArray* ptr)
106{
107    if (ptr)
108        g_ptr_array_ref(ptr);
109    return ptr;
110}
111
112template <> void derefGPtr(GPtrArray* ptr)
113{
114    if (ptr)
115        g_ptr_array_unref(ptr);
116}
117
118template <> GByteArray* refGPtr(GByteArray* ptr)
119{
120    if (ptr)
121        g_byte_array_ref(ptr);
122    return ptr;
123}
124
125template <> void derefGPtr(GByteArray* ptr)
126{
127    if (ptr)
128        g_byte_array_unref(ptr);
129}
130
131template <> GClosure* refGPtr(GClosure* ptr)
132{
133    if (ptr)
134        g_closure_ref(ptr);
135    return ptr;
136}
137
138template <> void derefGPtr(GClosure* ptr)
139{
140    if (ptr)
141        g_closure_unref(ptr);
142}
143
144} // namespace WTF
145
146#endif // USE(GLIB)
147