Mercurial > audlegacy
annotate src/audacious/tuple.c @ 3436:a630ecae6708 trunk
Add "gboolean enabled;" to PLUGIN_COMMON_FIELDS.
| author | William Pitcock <nenolod@atheme.org> |
|---|---|
| date | Fri, 07 Sep 2007 02:02:53 -0500 |
| parents | 7c2e63c5a001 |
| children | 004f822505b0 890326d0898b |
| rev | line source |
|---|---|
| 3278 | 1 /* |
| 2 * Audacious | |
| 3 * Copyright (c) 2006-2007 Audacious team | |
| 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; under version 3 of the License. | |
| 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, see <http://www.gnu.org/licenses>. | |
| 16 * | |
| 17 * The Audacious team does not consider modular code linking to | |
| 18 * Audacious or using our public API to be a derived work. | |
| 19 */ | |
| 20 | |
| 21 #include <glib.h> | |
| 22 #include <mowgli.h> | |
| 23 | |
| 24 #include "tuple.h" | |
| 25 | |
| 26 static mowgli_heap_t *tuple_heap = NULL; | |
| 27 static mowgli_heap_t *tuple_value_heap = NULL; | |
| 28 static mowgli_object_class_t tuple_klass; | |
| 29 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
30 static GStaticRWLock tuple_rwlock = G_STATIC_RW_LOCK_INIT; |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
31 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
32 #define TUPLE_LOCK_WRITE(XX) g_static_rw_lock_writer_lock(&tuple_rwlock) |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
33 #define TUPLE_UNLOCK_WRITE(XX) g_static_rw_lock_writer_unlock(&tuple_rwlock) |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
34 #define TUPLE_LOCK_READ(XX) g_static_rw_lock_reader_lock(&tuple_rwlock) |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
35 #define TUPLE_UNLOCK_READ(XX) g_static_rw_lock_reader_unlock(&tuple_rwlock) |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
36 |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
37 /* iterative destructor of tuple values. */ |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
38 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
39 tuple_value_destroy(mowgli_dictionary_elem_t *delem, gpointer privdata) |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
40 { |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
41 TupleValue *value = (TupleValue *) delem->data; |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
42 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
43 if (value->type == TUPLE_STRING) |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
44 g_free(value->value.string); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
45 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
46 mowgli_heap_free(tuple_value_heap, value); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
47 } |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
48 |
| 3278 | 49 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
50 tuple_destroy(gpointer data) |
| 3278 | 51 { |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
52 Tuple *tuple = (Tuple *) data; |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
53 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
54 TUPLE_LOCK_WRITE(); |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
55 mowgli_dictionary_destroy(tuple->dict, tuple_value_destroy, NULL); |
| 3278 | 56 mowgli_heap_free(tuple_heap, tuple); |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
57 TUPLE_UNLOCK_WRITE(); |
| 3278 | 58 } |
| 59 | |
| 60 Tuple * | |
| 61 tuple_new(void) | |
| 62 { | |
| 63 Tuple *tuple; | |
| 64 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
65 TUPLE_LOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
66 |
| 3278 | 67 if (tuple_heap == NULL) |
| 68 { | |
| 3281 | 69 tuple_heap = mowgli_heap_create(sizeof(Tuple), 256, BH_NOW); |
| 70 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW); | |
| 3278 | 71 mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE); |
| 72 } | |
| 73 | |
| 74 /* FIXME: use mowgli_object_bless_from_class() in mowgli 0.4 | |
| 75 when it is released --nenolod */ | |
| 76 tuple = mowgli_heap_alloc(tuple_heap); | |
| 77 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL); | |
| 78 | |
| 79 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp); | |
| 80 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
81 TUPLE_UNLOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
82 |
| 3278 | 83 return tuple; |
| 84 } | |
| 85 | |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
86 Tuple * |
|
3304
00286cde2485
Make filename a const
Christian Birchinger <joker@netswarm.net>
parents:
3303
diff
changeset
|
87 tuple_new_from_filename(const gchar *filename) |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
88 { |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
89 gchar *scratch, *ext, *realfn; |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
90 Tuple *tuple; |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
91 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
92 g_return_val_if_fail(filename != NULL, NULL); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
93 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
94 tuple = tuple_new(); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
95 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
96 g_return_val_if_fail(tuple != NULL, NULL); |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
97 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
98 realfn = g_filename_from_uri(filename, NULL, NULL); |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
99 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
100 scratch = g_path_get_basename(realfn ? realfn : filename); |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
101 tuple_associate_string(tuple, "file-name", scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
102 g_free(scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
103 |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
104 scratch = g_path_get_dirname(realfn ? realfn : filename); |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
105 tuple_associate_string(tuple, "file-path", scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
106 g_free(scratch); |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
107 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
108 g_free(realfn); realfn = NULL; |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
109 |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
110 ext = strrchr(filename, '.'); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
111 if (ext != NULL) { |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
112 ++ext; |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
113 tuple_associate_string(tuple, "file-ext", scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
114 } |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
115 |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
116 return tuple; |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
117 } |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
118 |
| 3278 | 119 gboolean |
| 120 tuple_associate_string(Tuple *tuple, const gchar *field, const gchar *string) | |
| 121 { | |
| 122 TupleValue *value; | |
| 123 | |
| 124 g_return_val_if_fail(tuple != NULL, FALSE); | |
| 125 g_return_val_if_fail(field != NULL, FALSE); | |
| 126 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
127 TUPLE_LOCK_WRITE(); |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
128 if ((value = mowgli_dictionary_delete(tuple->dict, field))) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
129 tuple_disassociate_now(value); |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
130 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
131 if (string == NULL) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
132 TUPLE_UNLOCK_WRITE(); |
|
3329
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
133 return TRUE; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
134 } |
|
3329
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
135 |
| 3278 | 136 value = mowgli_heap_alloc(tuple_value_heap); |
| 137 value->type = TUPLE_STRING; | |
| 138 value->value.string = g_strdup(string); | |
| 139 | |
| 140 mowgli_dictionary_add(tuple->dict, field, value); | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
141 TUPLE_UNLOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
142 |
| 3278 | 143 return TRUE; |
| 144 } | |
| 145 | |
| 146 gboolean | |
| 147 tuple_associate_int(Tuple *tuple, const gchar *field, gint integer) | |
| 148 { | |
| 149 TupleValue *value; | |
| 150 | |
| 151 g_return_val_if_fail(tuple != NULL, FALSE); | |
| 152 g_return_val_if_fail(field != NULL, FALSE); | |
| 153 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
154 TUPLE_LOCK_WRITE(); |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
155 if ((value = mowgli_dictionary_delete(tuple->dict, field))) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
156 tuple_disassociate_now(value); |
| 3278 | 157 |
| 158 value = mowgli_heap_alloc(tuple_value_heap); | |
| 159 value->type = TUPLE_INT; | |
| 160 value->value.integer = integer; | |
| 161 | |
| 162 mowgli_dictionary_add(tuple->dict, field, value); | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
163 TUPLE_UNLOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
164 |
| 3278 | 165 return TRUE; |
| 166 } | |
| 167 | |
| 168 void | |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
169 tuple_disassociate_now(TupleValue *value) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
170 { |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
171 if (value->type == TUPLE_STRING) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
172 g_free(value->value.string); |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
173 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
174 mowgli_heap_free(tuple_value_heap, value); |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
175 } |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
176 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
177 void |
| 3278 | 178 tuple_disassociate(Tuple *tuple, const gchar *field) |
| 179 { | |
| 180 TupleValue *value; | |
| 181 | |
| 182 g_return_if_fail(tuple != NULL); | |
| 183 g_return_if_fail(field != NULL); | |
| 184 | |
| 185 /* why _delete()? because _delete() returns the dictnode's data on success */ | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
186 TUPLE_LOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
187 value = mowgli_dictionary_delete(tuple->dict, field); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
188 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
189 if (value == NULL) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
190 TUPLE_UNLOCK_WRITE(); |
| 3278 | 191 return; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
192 } |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
193 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
194 tuple_disassociate_now(value); |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
195 TUPLE_UNLOCK_WRITE(); |
| 3278 | 196 } |
| 197 | |
| 198 TupleValueType | |
| 199 tuple_get_value_type(Tuple *tuple, const gchar *field) | |
| 200 { | |
| 201 TupleValue *value; | |
| 202 | |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
203 g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
204 g_return_val_if_fail(field != NULL, TUPLE_UNKNOWN); |
| 3278 | 205 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
206 TUPLE_LOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
207 value = mowgli_dictionary_retrieve(tuple->dict, field); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
208 TUPLE_UNLOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
209 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
210 if (value == NULL) |
| 3278 | 211 return TUPLE_UNKNOWN; |
| 212 | |
| 213 return value->type; | |
| 214 } | |
| 215 | |
| 216 const gchar * | |
| 217 tuple_get_string(Tuple *tuple, const gchar *field) | |
| 218 { | |
| 219 TupleValue *value; | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
220 gchar *val; |
| 3278 | 221 |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
222 g_return_val_if_fail(tuple != NULL, NULL); |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
223 g_return_val_if_fail(field != NULL, NULL); |
| 3278 | 224 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
225 TUPLE_LOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
226 value = mowgli_dictionary_retrieve(tuple->dict, field); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
227 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
228 if (value == NULL) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
229 TUPLE_UNLOCK_READ(); |
| 3278 | 230 return NULL; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
231 } |
| 3278 | 232 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
233 if (value->type != TUPLE_STRING) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
234 TUPLE_UNLOCK_READ(); |
| 3278 | 235 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL); |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
236 } |
| 3278 | 237 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
238 val = value->value.string; |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
239 TUPLE_UNLOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
240 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
241 return val; |
| 3278 | 242 } |
| 243 | |
| 244 int | |
| 245 tuple_get_int(Tuple *tuple, const gchar *field) | |
| 246 { | |
| 247 TupleValue *value; | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
248 gint val; |
| 3278 | 249 |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
250 g_return_val_if_fail(tuple != NULL, 0); |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
251 g_return_val_if_fail(field != NULL, 0); |
| 3278 | 252 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
253 TUPLE_LOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
254 value = mowgli_dictionary_retrieve(tuple->dict, field); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
255 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
256 if (value == NULL) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
257 TUPLE_UNLOCK_READ(); |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
258 return 0; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
259 } |
| 3278 | 260 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
261 if (value->type != TUPLE_INT) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
262 TUPLE_UNLOCK_READ(); |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
263 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0); |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
264 } |
| 3278 | 265 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
266 val = value->value.integer; |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
267 TUPLE_UNLOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
268 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
269 return val; |
| 3278 | 270 } |
