Make the mips compiler not complain when bitwise operations do not have parenthesis.
[kugel-rb.git] / apps / tagcache.h
blobe99578474201b73d13230c886d15853ca222d523
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Miika Pekkarinen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifdef HAVE_TAGCACHE
22 #ifndef _TAGCACHE_H
23 #define _TAGCACHE_H
25 #include "metadata.h"
27 /**
28 Note: When adding new tags, make sure to update index_entry_ec in
29 tagcache.c and bump up the header version too.
31 enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
32 tag_filename, tag_composer, tag_comment, tag_albumartist, tag_grouping, tag_year,
33 tag_discnumber, tag_tracknumber, tag_bitrate, tag_length, tag_playcount, tag_rating,
34 tag_playtime, tag_lastplayed, tag_commitid, tag_mtime,
35 /* Real tags end here, count them. */
36 TAG_COUNT,
37 /* Virtual tags */
38 tag_virt_length_min, tag_virt_length_sec,
39 tag_virt_playtime_min, tag_virt_playtime_sec,
40 tag_virt_entryage, tag_virt_autoscore };
42 /* Maximum length of a single tag. */
43 #define TAG_MAXLEN (MAX_PATH*2)
45 /* Allow a little drift to the filename ordering (should not be too high/low). */
46 #define POS_HISTORY_COUNT 4
48 /* How much to pre-load entries while committing to prevent seeking. */
49 #define IDX_BUF_DEPTH 64
51 /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */
52 #define TAGCACHE_MAGIC 0x5443480d
54 /* How much to allocate extra space for ramcache. */
55 #define TAGCACHE_RESERVE 32768
57 /**
58 * Define how long one entry must be at least (longer -> less memory at commit).
59 * Must be at least 4 bytes in length for correct alignment.
61 #define TAGFILE_ENTRY_CHUNK_LENGTH 8
63 /* Used to guess the necessary buffer size at commit. */
64 #define TAGFILE_ENTRY_AVG_LENGTH 16
66 /* How many entries to fetch to the seek table at once while searching. */
67 #define SEEK_LIST_SIZE 32
69 /* Always strict align entries for best performance and binary compatibility. */
70 #define TAGCACHE_STRICT_ALIGN 1
72 /* Max events in the internal tagcache command queue. */
73 #define TAGCACHE_COMMAND_QUEUE_LENGTH 32
74 /* Idle time before committing events in the command queue. */
75 #define TAGCACHE_COMMAND_QUEUE_COMMIT_DELAY HZ*2
77 #define TAGCACHE_MAX_FILTERS 4
78 #define TAGCACHE_MAX_CLAUSES 32
80 /* Tag database files. */
82 /* Temporary database containing new tags to be committed to the main db. */
83 #define TAGCACHE_FILE_TEMP ROCKBOX_DIR "/database_tmp.tcd"
85 /* The main database master index and numeric data. */
86 #define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/database_idx.tcd"
88 /* The main database string data. */
89 #define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/database_%d.tcd"
91 /* ASCII dumpfile of the DB contents. */
92 #define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/database_changelog.txt"
94 /* Serialized DB. */
95 #define TAGCACHE_STATEFILE ROCKBOX_DIR "/database_state.tcd"
97 /* Flags */
98 #define FLAG_DELETED 0x0001 /* Entry has been removed from db */
99 #define FLAG_DIRCACHE 0x0002 /* Filename is a dircache pointer */
100 #define FLAG_DIRTYNUM 0x0004 /* Numeric data has been modified */
101 #define FLAG_TRKNUMGEN 0x0008 /* Track number has been generated */
102 #define FLAG_RESURRECTED 0x0010 /* Statistics data has been resurrected */
103 #define FLAG_GET_ATTR(flag) ((flag >> 16) & 0x0000ffff)
104 #define FLAG_SET_ATTR(flag,attr) flag = (flag & 0x0000ffff) | (attr << 16)
106 enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq,
107 clause_lt, clause_lteq, clause_contains, clause_not_contains,
108 clause_begins_with, clause_not_begins_with, clause_ends_with,
109 clause_not_ends_with, clause_oneof };
111 struct tagcache_stat {
112 bool initialized; /* Is tagcache currently busy? */
113 bool readyvalid; /* Has tagcache ready status been ascertained */
114 bool ready; /* Is tagcache ready to be used? */
115 bool ramcache; /* Is tagcache loaded in ram? */
116 bool commit_delayed; /* Has commit been delayed until next reboot? */
117 bool econ; /* Is endianess correction enabled? */
118 int commit_step; /* Commit progress */
119 int ramcache_allocated; /* Has ram been allocated for ramcache? */
120 int ramcache_used; /* How much ram has been really used */
121 int progress; /* Current progress of disk scan */
122 int processed_entries; /* Scanned disk entries so far */
123 int queue_length; /* Command queue length */
124 volatile const char
125 *curentry; /* Path of the current entry being scanned. */
126 volatile bool syncscreen;/* Synchronous operation with debug screen? */
127 // const char *uimessage; /* Pending error message. Implement soon. */
130 enum source_type {source_constant,
131 source_runtime,
132 source_current_path /* dont add items after this.
133 it is used as an index
134 into id3_to_search_mapping */
137 struct tagcache_search_clause
139 int tag;
140 int type;
141 bool numeric;
142 int source;
143 long numeric_data;
144 char *str;
147 struct tagcache_search {
148 /* For internal use only. */
149 int fd, masterfd;
150 int idxfd[TAG_COUNT];
151 long seek_list[SEEK_LIST_SIZE];
152 long seek_flags[SEEK_LIST_SIZE];
153 long filter_tag[TAGCACHE_MAX_FILTERS];
154 long filter_seek[TAGCACHE_MAX_FILTERS];
155 int filter_count;
156 struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES];
157 int clause_count;
158 int seek_list_count;
159 int seek_pos;
160 long position;
161 int entry_count;
162 bool valid;
163 bool initialized;
164 unsigned long *unique_list;
165 int unique_list_capacity;
166 int unique_list_count;
168 /* Exported variables. */
169 bool ramsearch;
170 bool ramresult;
171 int type;
172 char *result;
173 int result_len;
174 long result_seek;
175 int idx_id;
178 void tagcache_build(const char *path);
180 #ifdef __PCTOOL__
181 void tagcache_reverse_scan(void);
182 #endif
184 const char* tagcache_tag_to_str(int tag);
186 bool tagcache_is_numeric_tag(int type);
187 bool tagcache_is_unique_tag(int type);
188 bool tagcache_is_sorted_tag(int type);
189 bool tagcache_find_index(struct tagcache_search *tcs, const char *filename);
190 bool tagcache_check_clauses(struct tagcache_search *tcs,
191 struct tagcache_search_clause **clause, int count);
192 bool tagcache_search(struct tagcache_search *tcs, int tag);
193 void tagcache_search_set_uniqbuf(struct tagcache_search *tcs,
194 void *buffer, long length);
195 bool tagcache_search_add_filter(struct tagcache_search *tcs,
196 int tag, int seek);
197 bool tagcache_search_add_clause(struct tagcache_search *tcs,
198 struct tagcache_search_clause *clause);
199 bool tagcache_get_next(struct tagcache_search *tcs);
200 bool tagcache_retrieve(struct tagcache_search *tcs, int idxid,
201 int tag, char *buf, long size);
202 void tagcache_search_finish(struct tagcache_search *tcs);
203 long tagcache_get_numeric(const struct tagcache_search *tcs, int tag);
204 long tagcache_increase_serial(void);
205 long tagcache_get_serial(void);
206 bool tagcache_import_changelog(void);
207 bool tagcache_create_changelog(struct tagcache_search *tcs);
208 void tagcache_update_numeric(int idx_id, int tag, long data);
209 bool tagcache_modify_numeric_entry(struct tagcache_search *tcs,
210 int tag, long data);
212 struct tagcache_stat* tagcache_get_stat(void);
213 int tagcache_get_commit_step(void);
214 bool tagcache_prepare_shutdown(void);
215 void tagcache_shutdown(void);
217 void tagcache_screensync_event(void);
218 void tagcache_screensync_enable(bool state);
220 #ifdef HAVE_TC_RAMCACHE
221 bool tagcache_is_ramcache(void);
222 bool tagcache_fill_tags(struct mp3entry *id3, const char *filename);
223 void tagcache_unload_ramcache(void);
224 #endif
225 void tagcache_init(void);
226 bool tagcache_is_initialized(void);
227 bool tagcache_is_usable(void);
228 void tagcache_start_scan(void);
229 void tagcache_stop_scan(void);
230 bool tagcache_update(void);
231 bool tagcache_rebuild(void);
232 int tagcache_get_max_commit_step(void);
233 #endif
234 #endif