Mercurial > audlegacy
annotate src/audacious/tuple.c @ 3527:fb5bc40d0b86 trunk
Remove useless #undef
| author | Matti Hamalainen <ccr@tnsp.org> |
|---|---|
| date | Fri, 14 Sep 2007 08:07:56 +0300 |
| parents | b2a82a73a788 |
| children | 9cc39a38fdfe |
| 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 | |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
26 const TupleBasicType tuple_fields[FIELD_LAST] = { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
27 { "artist", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
28 { "title", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
29 { "album", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
30 { "comment", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
31 { "genre", TUPLE_STRING }, |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
32 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
33 { "track", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
34 { "track-number", TUPLE_INT }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
35 { "length", TUPLE_INT }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
36 { "year", TUPLE_INT }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
37 { "quality", TUPLE_STRING }, |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
38 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
39 { "codec", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
40 { "file-name", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
41 { "file-path", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
42 { "file-ext", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
43 { "song-artist", TUPLE_STRING }, |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
44 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
45 { "mtime", TUPLE_INT }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
46 { "formatter", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
47 { "performer", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
48 { "copyright", TUPLE_STRING }, |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
49 { "date", TUPLE_STRING }, |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
50 }; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
51 |
| 3504 | 52 static mowgli_heap_t *tuple_heap = NULL; |
| 53 static mowgli_heap_t *tuple_value_heap = NULL; | |
| 54 static mowgli_object_class_t tuple_klass; | |
| 55 | |
| 3278 | 56 |
|
3448
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
57 #define TUPLE_LOCKING |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
58 //#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
|
59 |
|
3448
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
60 #ifdef TUPLE_LOCKING |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
61 static GStaticRWLock tuple_rwlock = G_STATIC_RW_LOCK_INIT; |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
62 # ifdef TUPLE_DEBUG |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
63 # 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
|
64 # 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
|
65 # 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
|
66 # 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
|
67 # 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
|
68 # else |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
69 # 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
|
70 # 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
|
71 # 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
|
72 # 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
|
73 # endif |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
74 #else |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
75 # define TUPLE_LOCK_WRITE(XX) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
76 # define TUPLE_UNLOCK_WRITE(XX) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
77 # define TUPLE_LOCK_READ(XX) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
78 # define TUPLE_UNLOCK_READ(XX) |
|
004f822505b0
Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents:
3427
diff
changeset
|
79 #endif |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
80 |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
81 /* iterative destructor of tuple values. */ |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
82 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
83 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
|
84 { |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
85 TupleValue *value = (TupleValue *) delem->data; |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
86 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
87 if (value->type == TUPLE_STRING) |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
88 g_free(value->value.string); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
89 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
90 mowgli_heap_free(tuple_value_heap, value); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
91 } |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
92 |
| 3278 | 93 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
94 tuple_destroy(gpointer data) |
| 3278 | 95 { |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
96 Tuple *tuple = (Tuple *) data; |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
97 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
98 TUPLE_LOCK_WRITE(); |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
99 mowgli_dictionary_destroy(tuple->dict, tuple_value_destroy, NULL); |
| 3278 | 100 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
|
101 TUPLE_UNLOCK_WRITE(); |
| 3278 | 102 } |
| 103 | |
| 104 Tuple * | |
| 105 tuple_new(void) | |
| 106 { | |
| 107 Tuple *tuple; | |
| 108 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
109 TUPLE_LOCK_WRITE(); |
|
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
110 |
| 3278 | 111 if (tuple_heap == NULL) |
| 112 { | |
| 3281 | 113 tuple_heap = mowgli_heap_create(sizeof(Tuple), 256, BH_NOW); |
| 114 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW); | |
| 3278 | 115 mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE); |
| 116 } | |
| 117 | |
| 118 /* FIXME: use mowgli_object_bless_from_class() in mowgli 0.4 | |
| 119 when it is released --nenolod */ | |
| 120 tuple = mowgli_heap_alloc(tuple_heap); | |
|
3505
7d865b5f5a04
Oops, previous merge had removed an important memset(), fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
3504
diff
changeset
|
121 memset(tuple, 0, sizeof(Tuple)); |
| 3278 | 122 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL); |
| 123 | |
| 124 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp); | |
| 125 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
126 TUPLE_UNLOCK_WRITE(); |
| 3278 | 127 return tuple; |
| 128 } | |
| 129 | |
|
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
|
130 Tuple * |
|
3304
00286cde2485
Make filename a const
Christian Birchinger <joker@netswarm.net>
parents:
3303
diff
changeset
|
131 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
|
132 { |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
133 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
|
134 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
|
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 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
|
137 |
|
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
|
138 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
|
139 |
|
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
|
140 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
|
141 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
142 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
|
143 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
144 scratch = g_path_get_basename(realfn ? realfn : filename); |
| 3504 | 145 tuple_associate_string(tuple, FIELD_FILE_NAME, NULL, scratch); |
|
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
|
146 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
|
147 |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
148 scratch = g_path_get_dirname(realfn ? realfn : filename); |
| 3504 | 149 tuple_associate_string(tuple, FIELD_FILE_PATH, NULL, scratch); |
|
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
|
150 g_free(scratch); |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
151 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
152 g_free(realfn); realfn = NULL; |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
153 |
|
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
|
154 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
|
155 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
|
156 ++ext; |
| 3504 | 157 tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, scratch); |
|
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
|
158 } |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
159 |
|
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
|
160 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
|
161 } |
|
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
|
162 |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
163 |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
164 static gint tuple_get_nfield(const gchar *field) |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
165 { |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
166 gint i; |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
167 for (i = 0; i < FIELD_LAST; i++) |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
168 if (!strcmp(field, tuple_fields[i].name)) |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
169 return i; |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
170 return -1; |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
171 } |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
172 |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
173 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
174 static TupleValue * |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
175 tuple_associate_data(Tuple *tuple, const gint cnfield, const gchar *field, TupleValueType ftype) |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
176 { |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
177 const gchar *tfield = field; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
178 gint nfield = cnfield; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
179 TupleValue *value = NULL; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
180 |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
181 g_return_val_if_fail(tuple != NULL, NULL); |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
182 g_return_val_if_fail(cnfield < FIELD_LAST, NULL); |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
183 |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
184 /* Check for known fields */ |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
185 if (nfield < 0) { |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
186 nfield = tuple_get_nfield(field); |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
187 if (nfield >= 0) { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
188 fprintf(stderr, "WARNING! FIELD_* not used for '%s'!\n", field); |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
189 } |
|
3494
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
190 } |
|
7d1dee4f660a
Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents:
3491
diff
changeset
|
191 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
192 /* Check if field was known */ |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
193 if (nfield >= 0) { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
194 tfield = tuple_fields[nfield].name; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
195 value = tuple->values[nfield]; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
196 |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
197 if (ftype != tuple_fields[nfield].type) { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
198 /* FIXME! Convert values perhaps .. or not? */ |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
199 fprintf(stderr, "Invalid type for [%s](%d->%d), %d != %d\n", tfield, cnfield, nfield, ftype, tuple_fields[nfield].type); |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
200 //mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0); |
| 3499 | 201 TUPLE_UNLOCK_WRITE(); |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
202 return NULL; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
203 } |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
204 } else { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
205 value = mowgli_dictionary_retrieve(tuple->dict, tfield); |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
206 } |
| 3499 | 207 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
208 if (value != NULL) { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
209 /* Value exists, just delete old associated data */ |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
210 if (value->type == TUPLE_STRING) { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
211 g_free(value->value.string); |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
212 value->value.string = NULL; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
213 } |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
214 } else { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
215 /* Allocate a new value */ |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
216 value = mowgli_heap_alloc(tuple_value_heap); |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
217 value->type = ftype; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
218 if (nfield >= 0) |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
219 tuple->values[nfield] = value; |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
220 else |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
221 mowgli_dictionary_add(tuple->dict, tfield, value); |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
222 } |
| 3499 | 223 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
224 return value; |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
225 } |
|
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
226 |
| 3278 | 227 gboolean |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
228 tuple_associate_string(Tuple *tuple, const gint nfield, const gchar *field, const gchar *string) |
| 3278 | 229 { |
| 230 TupleValue *value; | |
| 231 | |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
232 TUPLE_LOCK_WRITE(); |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
233 if ((value = tuple_associate_data(tuple, nfield, field, TUPLE_STRING)) == NULL) |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
234 return FALSE; |
|
3329
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
235 |
|
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
236 if (string == NULL) |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
237 value->value.string = NULL; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
238 else |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
239 value->value.string = g_strdup(string); |
| 3278 | 240 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
241 TUPLE_UNLOCK_WRITE(); |
| 3278 | 242 return TRUE; |
| 243 } | |
| 244 | |
| 245 gboolean | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
246 tuple_associate_int(Tuple *tuple, const gint nfield, const gchar *field, gint integer) |
| 3278 | 247 { |
| 248 TupleValue *value; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
249 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
250 TUPLE_LOCK_WRITE(); |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
251 if ((value = tuple_associate_data(tuple, nfield, field, TUPLE_INT)) == NULL) |
|
3491
899a7ed37a70
Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
3489
diff
changeset
|
252 return FALSE; |
| 3278 | 253 |
| 254 value->value.integer = integer; | |
| 3499 | 255 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
256 TUPLE_UNLOCK_WRITE(); |
| 3278 | 257 return TRUE; |
| 258 } | |
| 259 | |
| 260 void | |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
261 tuple_disassociate(Tuple *tuple, const gint cnfield, const gchar *field) |
| 3278 | 262 { |
| 263 TupleValue *value; | |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
264 gint nfield = cnfield; |
| 3278 | 265 |
| 266 g_return_if_fail(tuple != NULL); | |
| 3509 | 267 g_return_if_fail(nfield < FIELD_LAST); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
268 |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
269 if (nfield < 0) |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
270 nfield = tuple_get_nfield(field); |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
271 |
| 3499 | 272 TUPLE_LOCK_WRITE(); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
273 if (nfield < 0) |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
274 /* why _delete()? because _delete() returns the dictnode's data on success */ |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
275 value = mowgli_dictionary_delete(tuple->dict, field); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
276 else { |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
277 value = tuple->values[nfield]; |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
278 tuple->values[nfield] = NULL; |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
279 } |
| 3278 | 280 |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
281 if (value == NULL) { |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
282 TUPLE_UNLOCK_WRITE(); |
| 3278 | 283 return; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
284 } |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
285 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
286 /* Free associated data */ |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
287 if (value->type == TUPLE_STRING) { |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
288 g_free(value->value.string); |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
289 value->value.string = NULL; |
|
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
290 } |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
291 |
|
3498
9fcb90613e4f
Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents:
3497
diff
changeset
|
292 mowgli_heap_free(tuple_value_heap, value); |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
293 TUPLE_UNLOCK_WRITE(); |
| 3278 | 294 } |
| 295 | |
| 296 TupleValueType | |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
297 tuple_get_value_type(Tuple *tuple, const gint cnfield, const gchar *field) |
| 3278 | 298 { |
| 3499 | 299 TupleValueType type = TUPLE_UNKNOWN; |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
300 gint nfield = cnfield; |
| 3278 | 301 |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
302 g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN); |
| 3509 | 303 g_return_val_if_fail(nfield < FIELD_LAST, TUPLE_UNKNOWN); |
| 3499 | 304 |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
305 if (nfield < 0) |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
306 nfield = tuple_get_nfield(field); |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
307 |
| 3499 | 308 TUPLE_LOCK_READ(); |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
309 if (nfield < 0) { |
| 3499 | 310 TupleValue *value; |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
311 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) != NULL) |
| 3499 | 312 type = value->type; |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
313 } else { |
|
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
314 if (tuple->values[nfield]) |
| 3504 | 315 type = tuple->values[nfield]->type; |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
316 } |
| 3499 | 317 |
| 318 TUPLE_UNLOCK_READ(); | |
| 319 return type; | |
| 3278 | 320 } |
| 321 | |
| 322 const gchar * | |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
323 tuple_get_string(Tuple *tuple, const gint cnfield, const gchar *field) |
| 3278 | 324 { |
| 325 TupleValue *value; | |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
326 gint nfield = cnfield; |
| 3278 | 327 |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
328 g_return_val_if_fail(tuple != NULL, NULL); |
| 3509 | 329 g_return_val_if_fail(nfield < FIELD_LAST, NULL); |
| 3278 | 330 |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
331 if (nfield < 0) |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
332 nfield = tuple_get_nfield(field); |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
333 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
334 TUPLE_LOCK_READ(); |
| 3499 | 335 if (nfield < 0) |
| 336 value = mowgli_dictionary_retrieve(tuple->dict, field); | |
| 337 else | |
| 338 value = tuple->values[nfield]; | |
| 3278 | 339 |
| 3499 | 340 if (value) { |
| 341 if (value->type != TUPLE_STRING) | |
| 342 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL); | |
| 343 | |
| 344 TUPLE_UNLOCK_READ(); | |
| 345 return value->value.string; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
346 } else { |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
347 TUPLE_UNLOCK_READ(); |
| 3278 | 348 return NULL; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
349 } |
| 3278 | 350 } |
| 351 | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
352 gint |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
353 tuple_get_int(Tuple *tuple, const gint cnfield, const gchar *field) |
| 3278 | 354 { |
| 355 TupleValue *value; | |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
356 gint nfield = cnfield; |
| 3278 | 357 |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
358 g_return_val_if_fail(tuple != NULL, 0); |
| 3509 | 359 g_return_val_if_fail(nfield < FIELD_LAST, 0); |
| 3278 | 360 |
|
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
361 if (nfield < 0) |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
362 nfield = tuple_get_nfield(field); |
|
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3509
diff
changeset
|
363 |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
364 TUPLE_LOCK_READ(); |
| 3499 | 365 if (nfield < 0) |
| 366 value = mowgli_dictionary_retrieve(tuple->dict, field); | |
| 367 else | |
| 368 value = tuple->values[nfield]; | |
| 369 | |
| 370 if (value) { | |
| 371 if (value->type != TUPLE_INT) | |
| 372 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0); | |
| 373 | |
| 374 TUPLE_UNLOCK_READ(); | |
| 375 return value->value.integer; | |
|
3489
9580bb3e58fa
Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
376 } else { |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
377 TUPLE_UNLOCK_READ(); |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
378 return 0; |
|
3427
7c2e63c5a001
Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
379 } |
| 3278 | 380 } |
