annotate src/audacious/tuple.c @ 3505:7d865b5f5a04 trunk

Oops, previous merge had removed an important memset(), fixed.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 08 Sep 2007 20:58:26 +0300
parents 04ecdd1b0e12
children 65502ec17b75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
1 /*
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
2 * Audacious
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
3 * Copyright (c) 2006-2007 Audacious team
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
4 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
7 * the Free Software Foundation; under version 3 of the License.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
8 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
12 * GNU General Public License for more details.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
13 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses>.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
16 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
17 * The Audacious team does not consider modular code linking to
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
18 * Audacious or using our public API to be a derived work.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
19 */
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
20
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
21 #include <glib.h>
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
22 #include <mowgli.h>
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
23
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
24 #include "tuple.h"
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
52 static mowgli_heap_t *tuple_heap = NULL;
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
53 static mowgli_heap_t *tuple_value_heap = NULL;
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
54 static mowgli_object_class_t tuple_klass;
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
55
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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 # undef TUPDEP
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
69 # else
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
70 # 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
71 # 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
72 # 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
73 # 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
74 # endif
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
75 #else
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
76 # define TUPLE_LOCK_WRITE(XX)
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
77 # define TUPLE_UNLOCK_WRITE(XX)
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
78 # define TUPLE_LOCK_READ(XX)
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
79 # define TUPLE_UNLOCK_READ(XX)
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
80 #endif
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
81
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
82 /* iterative destructor of tuple values. */
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
83 static void
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
84 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
85 {
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
86 TupleValue *value = (TupleValue *) delem->data;
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
87
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
88 if (value->type == TUPLE_STRING)
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
89 g_free(value->value.string);
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
90
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
91 mowgli_heap_free(tuple_value_heap, value);
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
92 }
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
93
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
94 static void
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
95 tuple_destroy(gpointer data)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
96 {
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
97 Tuple *tuple = (Tuple *) data;
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
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_LOCK_WRITE();
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
100 mowgli_dictionary_destroy(tuple->dict, tuple_value_destroy, NULL);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
101 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
102 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
103 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
104
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
105 Tuple *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
106 tuple_new(void)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
107 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
108 Tuple *tuple;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
109
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
110 TUPLE_LOCK_WRITE();
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
111
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
112 if (tuple_heap == NULL)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
113 {
3281
be80d9b2c9ef Error fixes.
William Pitcock <nenolod@atheme-project.org>
parents: 3280
diff changeset
114 tuple_heap = mowgli_heap_create(sizeof(Tuple), 256, BH_NOW);
be80d9b2c9ef Error fixes.
William Pitcock <nenolod@atheme-project.org>
parents: 3280
diff changeset
115 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
116 mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
117 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
118
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
119 /* FIXME: use mowgli_object_bless_from_class() in mowgli 0.4
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
120 when it is released --nenolod */
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
121 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
122 memset(tuple, 0, sizeof(Tuple));
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
123 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
124
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
125 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
128 return tuple;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
129 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
130
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
131 Tuple *
3304
00286cde2485 Make filename a const
Christian Birchinger <joker@netswarm.net>
parents: 3303
diff changeset
132 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
133 {
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
134 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
135 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
136
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 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
138
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 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
140
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
141 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
142
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
143 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
144
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
145 scratch = g_path_get_basename(realfn ? realfn : filename);
3504
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
146 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
147 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
148
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
149 scratch = g_path_get_dirname(realfn ? realfn : filename);
3504
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
150 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
151 g_free(scratch);
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
152
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
153 g_free(realfn); realfn = NULL;
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
154
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
155 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
156 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
157 ++ext;
3504
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
158 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
159 }
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
160
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
161 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
162 }
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
163
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
164 static TupleValue *
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
165 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
166 {
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
167 const gchar *tfield = field;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
168 gint nfield = cnfield;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
169 TupleValue *value = NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
170
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
171 g_return_val_if_fail(tuple != NULL, NULL);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
172 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
173
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
174 /* Check for known fields */
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
175 if (nfield < 0) {
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
176 gint i;
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
177 for (i = 0; i < FIELD_LAST && nfield < 0; i++)
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
178 if (!strcmp(field, tuple_fields[i].name))
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
179 nfield = i;
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 if (nfield >= 0) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
182 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
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 }
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
185
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
186 /* Check if field was known */
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 tfield = tuple_fields[nfield].name;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
189 value = tuple->values[nfield];
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
190
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
191 if (ftype != tuple_fields[nfield].type) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
192 /* FIXME! Convert values perhaps .. or not? */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
193 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
194 //mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0);
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
195 TUPLE_UNLOCK_WRITE();
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
196 return NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
197 }
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
198 } else {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
199 value = mowgli_dictionary_retrieve(tuple->dict, tfield);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
200 }
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
201
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
202 if (value != NULL) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
203 /* Value exists, just delete old associated data */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
204 if (value->type == TUPLE_STRING) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
205 g_free(value->value.string);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
206 value->value.string = NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
207 }
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
208 } else {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
209 /* Allocate a new value */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
210 value = mowgli_heap_alloc(tuple_value_heap);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
211 value->type = ftype;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
212 mowgli_dictionary_add(tuple->dict, tfield, value);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
213 if (nfield >= 0)
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
214 tuple->values[nfield] = value;
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
215 }
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
216
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
217 return value;
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
218 }
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
219
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
220 gboolean
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
221 tuple_associate_string(Tuple *tuple, const gint nfield, const gchar *field, const gchar *string)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
222 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
223 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
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_WRITE();
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
226
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
227 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
228 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
229
70149c3555f4 For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents: 3304
diff changeset
230 if (string == NULL)
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
231 value->value.string = NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
232 else
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
233 value->value.string = g_strdup(string);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
234
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
235 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
236 return TRUE;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
237 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
238
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
239 gboolean
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
240 tuple_associate_int(Tuple *tuple, const gint nfield, const gchar *field, gint integer)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
241 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
242 TupleValue *value;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
243
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
244 TUPLE_LOCK_WRITE();
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
245 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
246 return FALSE;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
247
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
248 value->value.integer = integer;
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
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_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
251 return TRUE;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
252 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
253
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
254 void
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
255 tuple_disassociate(Tuple *tuple, const gint nfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
256 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
257 TupleValue *value;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
258 const gchar *tfield;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
259
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
260 g_return_if_fail(tuple != NULL);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
261 g_return_if_fail(nfield < FIELD_LAST);
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
262
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
263 TUPLE_LOCK_WRITE();
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
264 if (nfield < 0)
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
265 tfield = field;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
266 else {
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
267 tfield = tuple_fields[nfield].name;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
268 tuple->values[nfield] = NULL;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
269 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
270
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
271 /* why _delete()? because _delete() returns the dictnode's data on success */
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
272 if ((value = mowgli_dictionary_delete(tuple->dict, tfield)) == NULL) {
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
273 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
274 return;
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
275 }
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
276
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
277 /* Free associated data */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
278 if (value->type == TUPLE_STRING) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
279 g_free(value->value.string);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
280 value->value.string = NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
281 }
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
282
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
283 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
284 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
285 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
286
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
287 TupleValueType
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
288 tuple_get_value_type(Tuple *tuple, const gint nfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
289 {
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
290 TupleValueType type = TUPLE_UNKNOWN;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
291
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
292 g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
293 g_return_val_if_fail(nfield < FIELD_LAST, TUPLE_UNKNOWN);
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
294
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
295 TUPLE_LOCK_READ();
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
296 if (nfield < 0) {
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
297 TupleValue *value;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
298 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) != NULL)
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
299 type = value->type;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
300 } else {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
301 if (tuple->values[nfield])
3504
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
302 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
303 }
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
304
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
305 TUPLE_UNLOCK_READ();
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
306 return type;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
307 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
308
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
309 const gchar *
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
310 tuple_get_string(Tuple *tuple, const gint nfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
311 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
312 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
313
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
314 g_return_val_if_fail(tuple != NULL, NULL);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
315 g_return_val_if_fail(nfield < FIELD_LAST, NULL);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
316
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
317 TUPLE_LOCK_READ();
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
318 if (nfield < 0)
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
319 value = mowgli_dictionary_retrieve(tuple->dict, field);
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
320 else
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
321 value = tuple->values[nfield];
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
322
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
323 if (value) {
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
324 if (value->type != TUPLE_STRING)
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
325 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL);
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
326
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
327 TUPLE_UNLOCK_READ();
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
328 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
329 } else {
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
330 TUPLE_UNLOCK_READ();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
331 return NULL;
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
332 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
333 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
334
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
335 gint
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
336 tuple_get_int(Tuple *tuple, const gint nfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
337 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
338 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
339
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
340 g_return_val_if_fail(tuple != NULL, 0);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
341 g_return_val_if_fail(nfield < FIELD_LAST, 0);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
342
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
343 TUPLE_LOCK_READ();
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
344 if (nfield < 0)
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
345 value = mowgli_dictionary_retrieve(tuple->dict, field);
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
346 else
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
347 value = tuple->values[nfield];
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
348
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
349 if (value) {
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
350 if (value->type != TUPLE_INT)
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
351 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0);
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
352
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
353 TUPLE_UNLOCK_READ();
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
354 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
355 } else {
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
356 TUPLE_UNLOCK_READ();
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
357 return 0;
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
358 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
359 }