Mercurial > audlegacy
annotate src/audacious/tuple.c @ 3476:9152829f3c19 trunk
Allow non-active playlist to be saved to file
| author | Kieran Clancy <clancy.kieran+audacious@gmail.com> |
|---|---|
| date | Mon, 10 Sep 2007 13:47:16 +0930 |
| parents | 004f822505b0 |
| children | b413aa0c939c |
| 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 | |
|
3448
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
30 #define TUPLE_LOCKING |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
31 //#define TUPLE_DEBUG |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
32 |
|
3448
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
33 #ifdef TUPLE_LOCKING |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
34 static GStaticRWLock tuple_rwlock = G_STATIC_RW_LOCK_INIT; |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
35 # ifdef TUPLE_DEBUG |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
36 # define TUPDEB(X) fprintf(stderr, "TUPLE_" X "(%s:%d)\n", __FUNCTION__, __LINE__) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
37 # define TUPLE_LOCK_WRITE(XX) { TUPDEB("LOCK_WRITE"); g_static_rw_lock_writer_lock(&tuple_rwlock); } |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
38 # define TUPLE_UNLOCK_WRITE(XX) { TUPDEB("UNLOCK_WRITE"); g_static_rw_lock_writer_unlock(&tuple_rwlock); } |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
39 # define TUPLE_LOCK_READ(XX) { TUPDEB("LOCK_READ"); g_static_rw_lock_reader_lock(&tuple_rwlock); } |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
40 # define TUPLE_UNLOCK_READ(XX) { TUPDEB("UNLOCK_READ"); g_static_rw_lock_reader_unlock(&tuple_rwlock); } |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
41 # undef TUPDEP |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
42 # else |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
43 # define TUPLE_LOCK_WRITE(XX) g_static_rw_lock_writer_lock(&tuple_rwlock) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
44 # define TUPLE_UNLOCK_WRITE(XX) g_static_rw_lock_writer_unlock(&tuple_rwlock) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
45 # define TUPLE_LOCK_READ(XX) g_static_rw_lock_reader_lock(&tuple_rwlock) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
46 # define TUPLE_UNLOCK_READ(XX) g_static_rw_lock_reader_unlock(&tuple_rwlock) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
47 # endif |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
48 #else |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
49 # define TUPLE_LOCK_WRITE(XX) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
50 # define TUPLE_UNLOCK_WRITE(XX) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
51 # define TUPLE_LOCK_READ(XX) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
52 # define TUPLE_UNLOCK_READ(XX) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
53 #endif |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
54 |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
55 /* iterative destructor of tuple values. */ |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
56 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
57 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
|
58 { |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
59 TupleValue *value = (TupleValue *) delem->data; |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
60 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
61 if (value->type == TUPLE_STRING) |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
62 g_free(value->value.string); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
63 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
64 mowgli_heap_free(tuple_value_heap, value); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
65 } |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
66 |
| 3278 | 67 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
68 tuple_destroy(gpointer data) |
| 3278 | 69 { |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
70 Tuple *tuple = (Tuple *) data; |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
71 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
72 TUPLE_LOCK_WRITE(); |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
73 mowgli_dictionary_destroy(tuple->dict, tuple_value_destroy, NULL); |
| 3278 | 74 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
|
75 TUPLE_UNLOCK_WRITE(); |
| 3278 | 76 } |
| 77 | |
| 78 Tuple * | |
| 79 tuple_new(void) | |
| 80 { | |
| 81 Tuple *tuple; | |
| 82 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
83 TUPLE_LOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
84 |
| 3278 | 85 if (tuple_heap == NULL) |
| 86 { | |
| 3281 | 87 tuple_heap = mowgli_heap_create(sizeof(Tuple), 256, BH_NOW); |
| 88 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW); | |
| 3278 | 89 mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE); |
| 90 } | |
| 91 | |
| 92 /* FIXME: use mowgli_object_bless_from_class() in mowgli 0.4 | |
| 93 when it is released --nenolod */ | |
| 94 tuple = mowgli_heap_alloc(tuple_heap); | |
| 95 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL); | |
| 96 | |
| 97 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp); | |
| 98 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
99 TUPLE_UNLOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
100 |
| 3278 | 101 return tuple; |
| 102 } | |
| 103 | |
|
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
|
104 Tuple * |
|
3304
00286cde2485
Make filename a const
Christian Birchinger <joker@netswarm.net>
parents:
3303
diff
changeset
|
105 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
|
106 { |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
107 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
|
108 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
|
109 |
|
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 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
|
111 |
|
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 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
|
113 |
|
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 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
|
115 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
116 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
|
117 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
122 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
|
123 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
|
124 g_free(scratch); |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
125 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
126 g_free(realfn); realfn = NULL; |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
127 |
|
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
|
128 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
|
129 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
|
130 ++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
|
131 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
|
132 } |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
133 |
|
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
|
134 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
|
135 } |
|
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
|
136 |
| 3278 | 137 gboolean |
| 138 tuple_associate_string(Tuple *tuple, const gchar *field, const gchar *string) | |
| 139 { | |
| 140 TupleValue *value; | |
| 141 | |
| 142 g_return_val_if_fail(tuple != NULL, FALSE); | |
| 143 g_return_val_if_fail(field != NULL, FALSE); | |
| 144 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
149 if (string == NULL) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
150 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
|
151 return TRUE; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
152 } |
|
3329
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
153 |
| 3278 | 154 value = mowgli_heap_alloc(tuple_value_heap); |
| 155 value->type = TUPLE_STRING; | |
| 156 value->value.string = g_strdup(string); | |
| 157 | |
| 158 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
|
159 TUPLE_UNLOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
160 |
| 3278 | 161 return TRUE; |
| 162 } | |
| 163 | |
| 164 gboolean | |
| 165 tuple_associate_int(Tuple *tuple, const gchar *field, gint integer) | |
| 166 { | |
| 167 TupleValue *value; | |
| 168 | |
| 169 g_return_val_if_fail(tuple != NULL, FALSE); | |
| 170 g_return_val_if_fail(field != NULL, FALSE); | |
| 171 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
172 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
|
173 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
|
174 tuple_disassociate_now(value); |
| 3278 | 175 |
| 176 value = mowgli_heap_alloc(tuple_value_heap); | |
| 177 value->type = TUPLE_INT; | |
| 178 value->value.integer = integer; | |
| 179 | |
| 180 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
|
181 TUPLE_UNLOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
182 |
| 3278 | 183 return TRUE; |
| 184 } | |
| 185 | |
| 186 void | |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
187 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
|
188 { |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
189 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
|
190 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
|
191 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
192 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
|
193 } |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
194 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
195 void |
| 3278 | 196 tuple_disassociate(Tuple *tuple, const gchar *field) |
| 197 { | |
| 198 TupleValue *value; | |
| 199 | |
| 200 g_return_if_fail(tuple != NULL); | |
| 201 g_return_if_fail(field != NULL); | |
| 202 | |
| 203 /* 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
|
204 TUPLE_LOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
205 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
|
206 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
207 if (value == NULL) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
208 TUPLE_UNLOCK_WRITE(); |
| 3278 | 209 return; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
210 } |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
211 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
212 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
|
213 TUPLE_UNLOCK_WRITE(); |
| 3278 | 214 } |
| 215 | |
| 216 TupleValueType | |
| 217 tuple_get_value_type(Tuple *tuple, const gchar *field) | |
| 218 { | |
| 219 TupleValue *value; | |
| 220 | |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
221 g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
222 g_return_val_if_fail(field != NULL, TUPLE_UNKNOWN); |
| 3278 | 223 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
224 TUPLE_LOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
225 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
|
226 TUPLE_UNLOCK_READ(); |
|
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) |
| 3278 | 229 return TUPLE_UNKNOWN; |
| 230 | |
| 231 return value->type; | |
| 232 } | |
| 233 | |
| 234 const gchar * | |
| 235 tuple_get_string(Tuple *tuple, const gchar *field) | |
| 236 { | |
| 237 TupleValue *value; | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
238 gchar *val; |
| 3278 | 239 |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
240 g_return_val_if_fail(tuple != NULL, NULL); |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
241 g_return_val_if_fail(field != NULL, NULL); |
| 3278 | 242 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
243 TUPLE_LOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
244 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
|
245 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
246 if (value == NULL) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
247 TUPLE_UNLOCK_READ(); |
| 3278 | 248 return NULL; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
249 } |
| 3278 | 250 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
251 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
|
252 TUPLE_UNLOCK_READ(); |
| 3278 | 253 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
|
254 } |
| 3278 | 255 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
256 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
|
257 TUPLE_UNLOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
258 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
259 return val; |
| 3278 | 260 } |
| 261 | |
| 262 int | |
| 263 tuple_get_int(Tuple *tuple, const gchar *field) | |
| 264 { | |
| 265 TupleValue *value; | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
266 gint val; |
| 3278 | 267 |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
268 g_return_val_if_fail(tuple != NULL, 0); |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
269 g_return_val_if_fail(field != NULL, 0); |
| 3278 | 270 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
271 TUPLE_LOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
272 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
|
273 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
274 if (value == NULL) { |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
275 TUPLE_UNLOCK_READ(); |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
276 return 0; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
277 } |
| 3278 | 278 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
279 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
|
280 TUPLE_UNLOCK_READ(); |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
281 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
|
282 } |
| 3278 | 283 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
284 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
|
285 TUPLE_UNLOCK_READ(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
286 |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
287 return val; |
| 3278 | 288 } |
