Greek language update by Ioannis Koutoulakis - needs an increase of the language...
[Rockbox.git] / apps / tagcache.h
blobf1819855db7eadada7d40faf4c0499a342117dd2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Miika Pekkarinen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #ifdef HAVE_TAGCACHE
20 #ifndef _TAGCACHE_H
21 #define _TAGCACHE_H
23 #include "id3.h"
25 enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
26 tag_filename, tag_composer, tag_year, tag_tracknumber,
27 tag_bitrate, tag_length, tag_playcount, tag_playtime, tag_lastplayed,
28 /* Virtual tags */
29 tag_virt_autoscore };
31 #define TAG_COUNT 13
33 /* Allow a little drift to the filename ordering (should not be too high/low). */
34 #define POS_HISTORY_COUNT 4
36 /* How much to pre-load entries while committing to prevent seeking. */
37 #define IDX_BUF_DEPTH 64
39 /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */
40 #define TAGCACHE_MAGIC 0x54434806
42 /* How much to allocate extra space for ramcache. */
43 #define TAGCACHE_RESERVE 32768
45 /**
46 * Define how long one entry must be at least (longer -> less memory at commit).
47 * Must be at least 4 bytes in length for correct alignment.
49 #define TAGFILE_ENTRY_CHUNK_LENGTH 8
51 /* Used to guess the necessary buffer size at commit. */
52 #define TAGFILE_ENTRY_AVG_LENGTH 16
54 /* How many entries to fetch to the seek table at once while searching. */
55 #define SEEK_LIST_SIZE 32
57 /* Always strict align entries for best performance and binary compatability. */
58 #define TAGCACHE_STRICT_ALIGN 1
60 #define TAGCACHE_MAX_FILTERS 4
61 #define TAGCACHE_MAX_CLAUSES 32
63 /* Tag database files. */
64 #define TAGCACHE_FILE_TEMP ROCKBOX_DIR "/tagcache_tmp.tcd"
65 #define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/tagcache_idx.tcd"
66 #define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/tagcache_%d.tcd"
67 #define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/tagcache_changelog.txt"
68 #define TAGCACHE_STATEFILE ROCKBOX_DIR "/tagcache_state.tcd"
70 /* Flags */
71 #define FLAG_DELETED 0x0001 /* Entry has been removed from db */
72 #define FLAG_DIRCACHE 0x0002 /* Filename is a dircache pointer */
73 #define FLAG_DIRTYNUM 0x0004 /* Numeric data has been modified */
74 #define FLAG_TRKNUMGEN 0x0008 /* Track number has been generated */
75 #define FLAG_GET_ATTR(flag) ((flag >> 16) & 0x0000ffff)
76 #define FLAG_SET_ATTR(flag,attr) flag = (flag & 0x0000ffff) | (attr << 16)
78 enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq,
79 clause_lt, clause_lteq, clause_contains, clause_not_contains,
80 clause_begins_with, clause_not_begins_with, clause_ends_with,
81 clause_not_ends_with, clause_oneof };
83 struct tagcache_stat {
84 bool initialized; /* Is tagcache currently busy? */
85 bool ready; /* Is tagcache ready to be used? */
86 bool ramcache; /* Is tagcache loaded in ram? */
87 bool commit_delayed; /* Has commit been delayed until next reboot? */
88 int commit_step; /* Commit progress */
89 int ramcache_allocated; /* Has ram been allocated for ramcache? */
90 int ramcache_used; /* How much ram has been really used */
91 int progress; /* Current progress of disk scan */
92 int processed_entries; /* Scanned disk entries so far */
95 struct tagcache_search_clause
97 int tag;
98 int type;
99 bool numeric;
100 bool input;
101 long numeric_data;
102 char *str;
105 struct tagcache_search {
106 /* For internal use only. */
107 int fd, masterfd;
108 int idxfd[TAG_COUNT];
109 long seek_list[SEEK_LIST_SIZE];
110 long seek_flags[SEEK_LIST_SIZE];
111 long filter_tag[TAGCACHE_MAX_FILTERS];
112 long filter_seek[TAGCACHE_MAX_FILTERS];
113 int filter_count;
114 struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES];
115 int clause_count;
116 int seek_list_count;
117 int seek_pos;
118 long position;
119 int entry_count;
120 bool valid;
121 bool initialized;
122 long *unique_list;
123 int unique_list_capacity;
124 int unique_list_count;
126 /* Exported variables. */
127 bool ramsearch;
128 bool ramresult;
129 int type;
130 char *result;
131 int result_len;
132 long result_seek;
133 int idx_id;
136 int tagcache_str_to_tag(const char *str);
137 const char* tagcache_tag_to_str(int tag);
139 bool tagcache_is_numeric_tag(int type);
140 bool tagcache_is_unique_tag(int type);
141 bool tagcache_is_sorted_tag(int type);
142 bool tagcache_find_index(struct tagcache_search *tcs, const char *filename);
143 bool tagcache_check_clauses(struct tagcache_search *tcs,
144 struct tagcache_search_clause **clause, int count);
145 bool tagcache_search(struct tagcache_search *tcs, int tag);
146 void tagcache_search_set_uniqbuf(struct tagcache_search *tcs,
147 void *buffer, long length);
148 bool tagcache_search_add_filter(struct tagcache_search *tcs,
149 int tag, int seek);
150 bool tagcache_search_add_clause(struct tagcache_search *tcs,
151 struct tagcache_search_clause *clause);
152 bool tagcache_get_next(struct tagcache_search *tcs);
153 bool tagcache_retrieve(struct tagcache_search *tcs, int idxid,
154 int tag, char *buf, long size);
155 void tagcache_search_finish(struct tagcache_search *tcs);
156 long tagcache_get_numeric(const struct tagcache_search *tcs, int tag);
157 long tagcache_increase_serial(void);
158 long tagcache_get_serial(void);
159 bool tagcache_import_changelog(void);
160 bool tagcache_create_changelog(struct tagcache_search *tcs);
161 bool tagcache_modify_numeric_entry(struct tagcache_search *tcs,
162 int tag, long data);
164 struct tagcache_stat* tagcache_get_stat(void);
165 int tagcache_get_commit_step(void);
166 bool tagcache_prepare_shutdown(void);
167 void tagcache_shutdown(void);
169 #ifdef HAVE_TC_RAMCACHE
170 bool tagcache_is_ramcache(void);
171 bool tagcache_fill_tags(struct mp3entry *id3, const char *filename);
172 void tagcache_unload_ramcache(void);
173 #endif
174 void tagcache_init(void);
175 bool tagcache_is_initialized(void);
176 void tagcache_start_scan(void);
177 void tagcache_stop_scan(void);
178 bool tagcache_update(void);
179 bool tagcache_rebuild(void);
181 #endif
182 #endif