annotate src/audacious/tuple.c @ 4411:628926f505f8

BmpConfig -> AudConfig, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 31 Mar 2008 06:25:09 +0300
parents 9e24c8746d99
children 8399067f9b1a
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"
3830
10053e99d90f add strings.h include to remove a warning
William Pitcock <nenolod@atheme.org>
parents: 3828
diff changeset
25 #include "strings.h"
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
26
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
27 const TupleBasicType tuple_fields[FIELD_LAST] = {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
28 { "artist", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
29 { "title", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
30 { "album", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
31 { "comment", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
32 { "genre", TUPLE_STRING },
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
33
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
34 { "track", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
35 { "track-number", TUPLE_INT },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
36 { "length", TUPLE_INT },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
37 { "year", TUPLE_INT },
4064
7ecdb78a051e some indenting (should make it easier to clean up the code afterwards ;-)
mf0102 <0102@gmx.at>
parents: 4061
diff changeset
38 { "quality", TUPLE_STRING },
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
39
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
40 { "codec", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
41 { "file-name", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
42 { "file-path", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
43 { "file-ext", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
44 { "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
45
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
46 { "mtime", TUPLE_INT },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
47 { "formatter", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
48 { "performer", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
49 { "copyright", TUPLE_STRING },
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
50 { "date", TUPLE_STRING },
3550
6b0be1d088e6 - subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents: 3529
diff changeset
51
6b0be1d088e6 - subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents: 3529
diff changeset
52 { "subsong-id", TUPLE_INT },
6b0be1d088e6 - subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents: 3529
diff changeset
53 { "subsong-num", TUPLE_INT },
4009
ba6258a39662 icon, codec and quality info added to file info box. Added new tuple field FIELD_MIMETYPE used for icon resolving
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 3834
diff changeset
54 { "mime-type", TUPLE_STRING },
4061
450581e58761 added new tuple field FIELD_BITRATE
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 4009
diff changeset
55 { "bitrate", TUPLE_INT },
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
56 };
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
57
3504
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
58 static mowgli_heap_t *tuple_heap = NULL;
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
59 static mowgli_heap_t *tuple_value_heap = NULL;
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
60 static mowgli_object_class_t tuple_klass;
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
61
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
62
3448
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
63 #define TUPLE_LOCKING
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
64 //#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
65
3448
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
66 #ifdef TUPLE_LOCKING
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
67 static GStaticRWLock tuple_rwlock = G_STATIC_RW_LOCK_INIT;
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
68 # ifdef TUPLE_DEBUG
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
69 # 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
70 # 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
71 # 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
72 # 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
73 # 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
74 # else
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
75 # 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
76 # 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
77 # 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
78 # 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
79 # endif
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
80 #else
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
81 # define TUPLE_LOCK_WRITE(XX)
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
82 # define TUPLE_UNLOCK_WRITE(XX)
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
83 # define TUPLE_LOCK_READ(XX)
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
84 # define TUPLE_UNLOCK_READ(XX)
004f822505b0 Added Tuple RW-lock debugging.
Matti Hamalainen <ccr@tnsp.org>
parents: 3427
diff changeset
85 #endif
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
86
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
87 /* iterative destructor of tuple values. */
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
88 static void
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
89 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
90 {
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
91 TupleValue *value = (TupleValue *) delem->data;
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 if (value->type == TUPLE_STRING)
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
94 g_free(value->value.string);
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
95
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
96 mowgli_heap_free(tuple_value_heap, value);
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
97 }
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
98
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
99 static void
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
100 tuple_destroy(gpointer data)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
101 {
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
102 Tuple *tuple = (Tuple *) data;
3528
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
103 gint i;
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
104
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
105 TUPLE_LOCK_WRITE();
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
106 mowgli_dictionary_destroy(tuple->dict, tuple_value_destroy, NULL);
3528
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
107
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
108 for (i = 0; i < FIELD_LAST; i++)
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
109 if (tuple->values[i]) {
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
110 TupleValue *value = tuple->values[i];
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
111
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
112 if (value->type == TUPLE_STRING)
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
113 g_free(value->value.string);
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
114
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
115 mowgli_heap_free(tuple_value_heap, value);
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
116 }
9cc39a38fdfe Oops, static field values were not being freed, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3527
diff changeset
117
3633
8c4633438785 Implement selective adding of subtunes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3568
diff changeset
118 g_free(tuple->subtunes);
8c4633438785 Implement selective adding of subtunes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3568
diff changeset
119
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
120 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
121 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
122 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
123
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
124 Tuple *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
125 tuple_new(void)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
126 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
127 Tuple *tuple;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
128
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
129 TUPLE_LOCK_WRITE();
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
130
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
131 if (tuple_heap == NULL)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
132 {
3529
7e8c4aadfc32 Make the default allocation values bigger.
Matti Hamalainen <ccr@tnsp.org>
parents: 3528
diff changeset
133 tuple_heap = mowgli_heap_create(sizeof(Tuple), 512, BH_NOW);
7e8c4aadfc32 Make the default allocation values bigger.
Matti Hamalainen <ccr@tnsp.org>
parents: 3528
diff changeset
134 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 1024, BH_NOW);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
135 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
136 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
137
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
138 /* 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
139 when it is released --nenolod */
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
140 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
141 memset(tuple, 0, sizeof(Tuple));
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
142 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
143
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
144 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
145
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
146 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
147 return tuple;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
148 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
149
3834
d087573f54fd Compilation fix.
Eugene Paskevich <eugene@raptor.kiev.ua>
parents: 3833
diff changeset
150 static TupleValue *
d087573f54fd Compilation fix.
Eugene Paskevich <eugene@raptor.kiev.ua>
parents: 3833
diff changeset
151 tuple_associate_data(Tuple *tuple, const gint cnfield, const gchar *field, TupleValueType ftype);
d087573f54fd Compilation fix.
Eugene Paskevich <eugene@raptor.kiev.ua>
parents: 3833
diff changeset
152
3833
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
153 static gboolean
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
154 _tuple_associate_raw_string(Tuple *tuple, const gint nfield, const gchar *field, const gchar *string)
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
155 {
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
156 TupleValue *value;
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
157
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
158 TUPLE_LOCK_WRITE();
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
159 if ((value = tuple_associate_data(tuple, nfield, field, TUPLE_STRING)) == NULL)
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
160 return FALSE;
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
161
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
162 if (string == NULL)
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
163 value->value.string = NULL;
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
164 else
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
165 value->value.string = g_strdup(string);
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
166
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
167 TUPLE_UNLOCK_WRITE();
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
168 return TRUE;
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
169 }
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
170
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
171 Tuple *
3304
00286cde2485 Make filename a const
Christian Birchinger <joker@netswarm.net>
parents: 3303
diff changeset
172 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
173 {
4089
9e24c8746d99 - introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4064
diff changeset
174 gchar *scratch, *ext;
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
175 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
176
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
177 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
178
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
179 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
180 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
181
4089
9e24c8746d99 - introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4064
diff changeset
182 scratch = uri_to_display_basename(filename);
3833
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
183 _tuple_associate_raw_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
184 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
185
4089
9e24c8746d99 - introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4064
diff changeset
186 scratch = uri_to_display_dirname(filename);
3833
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
187 _tuple_associate_raw_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
188 g_free(scratch);
4089
9e24c8746d99 - introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4064
diff changeset
189
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
190 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
191 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
192 ++ext;
4089
9e24c8746d99 - introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4064
diff changeset
193 _tuple_associate_raw_string(tuple, FIELD_FILE_EXT, NULL, ext);
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
194 }
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
195
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
196 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
197 }
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
198
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
199
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
200 static gint tuple_get_nfield(const gchar *field)
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
201 {
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
202 gint i;
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
203 for (i = 0; i < FIELD_LAST; i++)
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
204 if (!strcmp(field, tuple_fields[i].name))
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
205 return i;
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
206 return -1;
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
207 }
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
208
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
209
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
210 static TupleValue *
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
211 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
212 {
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
213 const gchar *tfield = field;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
214 gint nfield = cnfield;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
215 TupleValue *value = NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
216
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
217 g_return_val_if_fail(tuple != NULL, NULL);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
218 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
219
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
220 /* Check for known fields */
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
221 if (nfield < 0) {
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
222 nfield = tuple_get_nfield(field);
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
223 if (nfield >= 0) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
224 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
225 }
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
226 }
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
227
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
228 /* Check if field was known */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
229 if (nfield >= 0) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
230 tfield = tuple_fields[nfield].name;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
231 value = tuple->values[nfield];
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
232
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
233 if (ftype != tuple_fields[nfield].type) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
234 /* FIXME! Convert values perhaps .. or not? */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
235 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
236 //mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0);
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
237 TUPLE_UNLOCK_WRITE();
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
238 return NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
239 }
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
240 } else {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
241 value = mowgli_dictionary_retrieve(tuple->dict, tfield);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
242 }
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
243
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
244 if (value != NULL) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
245 /* Value exists, just delete old associated data */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
246 if (value->type == TUPLE_STRING) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
247 g_free(value->value.string);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
248 value->value.string = NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
249 }
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
250 } else {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
251 /* Allocate a new value */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
252 value = mowgli_heap_alloc(tuple_value_heap);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
253 value->type = ftype;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
254 if (nfield >= 0)
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
255 tuple->values[nfield] = value;
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
256 else
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
257 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
258 }
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
259
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
260 return value;
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
261 }
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
262
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
263 gboolean
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
264 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
265 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
266 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
267
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
268 TUPLE_LOCK_WRITE();
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
269 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
270 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
271
70149c3555f4 For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents: 3304
diff changeset
272 if (string == NULL)
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
273 value->value.string = NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
274 else
3833
f4f30254833b better fix
William Pitcock <nenolod@atheme.org>
parents: 3832
diff changeset
275 value->value.string = str_to_utf8(string);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
276
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
277 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
278 return TRUE;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
279 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
280
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
281 gboolean
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
282 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
283 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
284 TupleValue *value;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
285
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
286 TUPLE_LOCK_WRITE();
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
287 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
288 return FALSE;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
289
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
290 value->value.integer = integer;
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
291
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
292 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
293 return TRUE;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
294 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
295
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
296 void
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
297 tuple_disassociate(Tuple *tuple, const gint cnfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
298 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
299 TupleValue *value;
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
300 gint nfield = cnfield;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
301
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
302 g_return_if_fail(tuple != NULL);
3509
08085ecc7e91 Reverting stupidness.
Matti Hamalainen <ccr@tnsp.org>
parents: 3506
diff changeset
303 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
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
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
308 TUPLE_LOCK_WRITE();
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)
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
310 /* 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
311 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
312 else {
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
313 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
314 tuple->values[nfield] = NULL;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
315 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
316
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
317 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
318 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
319 return;
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
320 }
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
321
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
322 /* Free associated data */
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
323 if (value->type == TUPLE_STRING) {
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
324 g_free(value->value.string);
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
325 value->value.string = NULL;
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
326 }
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
327
3498
9fcb90613e4f Added types to base tuples.
Matti Hamalainen <ccr@tnsp.org>
parents: 3497
diff changeset
328 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
329 TUPLE_UNLOCK_WRITE();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
330 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
331
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
332 TupleValueType
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
333 tuple_get_value_type(Tuple *tuple, const gint cnfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
334 {
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
335 TupleValueType type = TUPLE_UNKNOWN;
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
336 gint nfield = cnfield;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
337
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
338 g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN);
3509
08085ecc7e91 Reverting stupidness.
Matti Hamalainen <ccr@tnsp.org>
parents: 3506
diff changeset
339 g_return_val_if_fail(nfield < FIELD_LAST, TUPLE_UNKNOWN);
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
340
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
341 if (nfield < 0)
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
342 nfield = tuple_get_nfield(field);
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
343
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
344 TUPLE_LOCK_READ();
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
345 if (nfield < 0) {
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
346 TupleValue *value;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
347 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) != NULL)
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
348 type = value->type;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
349 } else {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
350 if (tuple->values[nfield])
3504
Matti Hamalainen <ccr@tnsp.org>
parents: 3502
diff changeset
351 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
352 }
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
353
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
354 TUPLE_UNLOCK_READ();
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
355 return type;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
356 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
357
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
358 const gchar *
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
359 tuple_get_string(Tuple *tuple, const gint cnfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
360 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
361 TupleValue *value;
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
362 gint nfield = cnfield;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
363
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
364 g_return_val_if_fail(tuple != NULL, NULL);
3509
08085ecc7e91 Reverting stupidness.
Matti Hamalainen <ccr@tnsp.org>
parents: 3506
diff changeset
365 g_return_val_if_fail(nfield < FIELD_LAST, NULL);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
366
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
367 if (nfield < 0)
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
368 nfield = tuple_get_nfield(field);
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
369
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
370 TUPLE_LOCK_READ();
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
371 if (nfield < 0)
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
372 value = mowgli_dictionary_retrieve(tuple->dict, field);
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
373 else
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
374 value = tuple->values[nfield];
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
375
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
376 if (value) {
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
377 if (value->type != TUPLE_STRING)
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
378 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL);
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
379
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
380 TUPLE_UNLOCK_READ();
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
381 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
382 } else {
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
383 TUPLE_UNLOCK_READ();
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
384 return NULL;
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
385 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
386 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
387
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
388 gint
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
389 tuple_get_int(Tuple *tuple, const gint cnfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
390 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
391 TupleValue *value;
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
392 gint nfield = cnfield;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
393
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
394 g_return_val_if_fail(tuple != NULL, 0);
3509
08085ecc7e91 Reverting stupidness.
Matti Hamalainen <ccr@tnsp.org>
parents: 3506
diff changeset
395 g_return_val_if_fail(nfield < FIELD_LAST, 0);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
396
3510
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
397 if (nfield < 0)
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
398 nfield = tuple_get_nfield(field);
b2a82a73a788 Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents: 3509
diff changeset
399
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
400 TUPLE_LOCK_READ();
3499
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
401 if (nfield < 0)
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
402 value = mowgli_dictionary_retrieve(tuple->dict, field);
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
403 else
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
404 value = tuple->values[nfield];
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
405
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
406 if (value) {
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
407 if (value->type != TUPLE_INT)
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
408 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0);
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
409
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
410 TUPLE_UNLOCK_READ();
890326d0898b Branch merge.
Matti Hamalainen <ccr@tnsp.org>
parents: 3498 3427
diff changeset
411 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
412 } else {
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
413 TUPLE_UNLOCK_READ();
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
414 return 0;
3427
7c2e63c5a001 Add a global GStaticRWLock to Tuple handling code. This should prevent
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
415 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
416 }