fuzeplus: update radio keymap
[maemo-rb.git] / apps / tagcache.h
blobdbe1c92d39d0828ba199592e93aef4b3f64cdd6e
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 "config.h"
26 #include "system.h"
27 #include "metadata.h"
29 /**
30 Note: When adding new tags, make sure to update index_entry_ec and tags_str in
31 tagcache.c and bump up the header version too.
33 enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
34 tag_filename, tag_composer, tag_comment, tag_albumartist, tag_grouping, tag_year,
35 tag_discnumber, tag_tracknumber, tag_bitrate, tag_length, tag_playcount, tag_rating,
36 tag_playtime, tag_lastplayed, tag_commitid, tag_mtime, tag_lastoffset,
37 /* Real tags end here, count them. */
38 TAG_COUNT,
39 /* Virtual tags */
40 tag_virt_basename, tag_virt_length_min, tag_virt_length_sec,
41 tag_virt_playtime_min, tag_virt_playtime_sec,
42 tag_virt_entryage, tag_virt_autoscore };
44 /* Maximum length of a single tag. */
45 #define TAG_MAXLEN (MAX_PATH*2)
47 /* Allow a little drift to the filename ordering (should not be too high/low). */
48 #define POS_HISTORY_COUNT 4
50 /* How much to pre-load entries while committing to prevent seeking. */
51 #define IDX_BUF_DEPTH 64
53 /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */
54 #define TAGCACHE_MAGIC 0x5443480e
56 /* Dump store/restore header version 'TCSxx'. */
57 #define TAGCACHE_STATEFILE_MAGIC 0x54435301
59 /* How much to allocate extra space for ramcache. */
60 #define TAGCACHE_RESERVE 32768
62 /**
63 * Define how long one entry must be at least (longer -> less memory at commit).
64 * Must be at least 4 bytes in length for correct alignment.
66 #define TAGFILE_ENTRY_CHUNK_LENGTH 8
68 /* Used to guess the necessary buffer size at commit. */
69 #define TAGFILE_ENTRY_AVG_LENGTH 16
71 /* How many entries to fetch to the seek table at once while searching. */
72 #define SEEK_LIST_SIZE 32
74 /* Always strict align entries for best performance and binary compatibility. */
75 #define TAGCACHE_STRICT_ALIGN 1
77 /* Max events in the internal tagcache command queue. */
78 #define TAGCACHE_COMMAND_QUEUE_LENGTH 32
79 /* Idle time before committing events in the command queue. */
80 #define TAGCACHE_COMMAND_QUEUE_COMMIT_DELAY HZ*2
82 #define TAGCACHE_MAX_FILTERS 4
83 #define TAGCACHE_MAX_CLAUSES 32
85 /* Tag database files. */
87 /* Temporary database containing new tags to be committed to the main db. */
88 #define TAGCACHE_FILE_TEMP ROCKBOX_DIR "/database_tmp.tcd"
90 /* The main database master index and numeric data. */
91 #define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/database_idx.tcd"
93 /* The main database string data. */
94 #define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/database_%d.tcd"
96 /* ASCII dumpfile of the DB contents. */
97 #define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/database_changelog.txt"
99 /* Serialized DB. */
100 #define TAGCACHE_STATEFILE ROCKBOX_DIR "/database_state.tcd"
102 /* Tag to be used on untagged files. */
103 #define UNTAGGED "<Untagged>"
105 /* Numeric tags (we can use these tags with conditional clauses). */
106 #define TAGCACHE_NUMERIC_TAGS ((1LU << tag_year) | (1LU << tag_discnumber) | \
107 (1LU << tag_tracknumber) | (1LU << tag_length) | (1LU << tag_bitrate) | \
108 (1LU << tag_playcount) | (1LU << tag_rating) | (1LU << tag_playtime) | \
109 (1LU << tag_lastplayed) | (1LU << tag_commitid) | (1LU << tag_mtime) | \
110 (1LU << tag_lastoffset) | (1LU << tag_virt_basename) | \
111 (1LU << tag_virt_length_min) | (1LU << tag_virt_length_sec) | \
112 (1LU << tag_virt_playtime_min) | (1LU << tag_virt_playtime_sec) | \
113 (1LU << tag_virt_entryage) | (1LU << tag_virt_autoscore))
115 #define TAGCACHE_IS_NUMERIC(tag) (BIT_N(tag) & TAGCACHE_NUMERIC_TAGS)
117 /* Flags */
118 #define FLAG_DELETED 0x0001 /* Entry has been removed from db */
119 #define FLAG_DIRCACHE 0x0002 /* Filename is a dircache pointer */
120 #define FLAG_DIRTYNUM 0x0004 /* Numeric data has been modified */
121 #define FLAG_TRKNUMGEN 0x0008 /* Track number has been generated */
122 #define FLAG_RESURRECTED 0x0010 /* Statistics data has been resurrected */
124 enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq,
125 clause_lt, clause_lteq, clause_contains, clause_not_contains,
126 clause_begins_with, clause_not_begins_with, clause_ends_with,
127 clause_not_ends_with, clause_oneof, clause_logical_or };
129 struct tagcache_stat {
130 bool initialized; /* Is tagcache currently busy? */
131 bool readyvalid; /* Has tagcache ready status been ascertained */
132 bool ready; /* Is tagcache ready to be used? */
133 bool ramcache; /* Is tagcache loaded in ram? */
134 bool commit_delayed; /* Has commit been delayed until next reboot? */
135 bool econ; /* Is endianess correction enabled? */
136 int commit_step; /* Commit progress */
137 int ramcache_allocated; /* Has ram been allocated for ramcache? */
138 int ramcache_used; /* How much ram has been really used */
139 int progress; /* Current progress of disk scan */
140 int processed_entries; /* Scanned disk entries so far */
141 int queue_length; /* Command queue length */
142 volatile const char
143 *curentry; /* Path of the current entry being scanned. */
144 volatile bool syncscreen;/* Synchronous operation with debug screen? */
145 // const char *uimessage; /* Pending error message. Implement soon. */
148 enum source_type {source_constant,
149 source_runtime,
150 source_current_path /* dont add items after this.
151 it is used as an index
152 into id3_to_search_mapping */
155 struct tagcache_search_clause
157 int tag;
158 int type;
159 bool numeric;
160 int source;
161 long numeric_data;
162 char *str;
165 struct tagcache_seeklist_entry {
166 int32_t seek;
167 int32_t flag;
168 int32_t idx_id;
171 struct tagcache_search {
172 /* For internal use only. */
173 int fd, masterfd;
174 int idxfd[TAG_COUNT];
175 struct tagcache_seeklist_entry seeklist[SEEK_LIST_SIZE];
176 int seek_list_count;
177 int32_t filter_tag[TAGCACHE_MAX_FILTERS];
178 int32_t filter_seek[TAGCACHE_MAX_FILTERS];
179 int filter_count;
180 struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES];
181 int clause_count;
182 int list_position;
183 int seek_pos;
184 long position;
185 int entry_count;
186 bool valid;
187 bool initialized;
188 unsigned long *unique_list;
189 int unique_list_capacity;
190 int unique_list_count;
192 /* Exported variables. */
193 bool ramsearch; /* Is ram copy of the tagcache being used. */
194 bool ramresult; /* False if result is not static, and must be copied.
195 Currently always false since ramresult buffer is
196 movable */
197 int type; /* The tag type to be searched. Only nonvirtual tags */
198 char *result; /* The result data for all tags. */
199 int result_len; /* Length of the result including \0 */
200 int32_t result_seek; /* Current position in the tag data. */
201 int32_t idx_id; /* Entry number in the master index. */
204 #ifdef __PCTOOL__
205 void tagcache_reverse_scan(void);
206 /* call this directly instead of tagcache_build in order to not pull
207 * on global_settings */
208 void do_tagcache_build(const char *path[]);
209 #endif
211 const char* tagcache_tag_to_str(int tag);
213 bool tagcache_find_index(struct tagcache_search *tcs, const char *filename);
214 bool tagcache_check_clauses(struct tagcache_search *tcs,
215 struct tagcache_search_clause **clause, int count);
216 bool tagcache_search(struct tagcache_search *tcs, int tag);
217 void tagcache_search_set_uniqbuf(struct tagcache_search *tcs,
218 void *buffer, long length);
219 bool tagcache_search_add_filter(struct tagcache_search *tcs,
220 int tag, int seek);
221 bool tagcache_search_add_clause(struct tagcache_search *tcs,
222 struct tagcache_search_clause *clause);
223 bool tagcache_get_next(struct tagcache_search *tcs);
224 bool tagcache_retrieve(struct tagcache_search *tcs, int idxid,
225 int tag, char *buf, long size);
226 void tagcache_search_finish(struct tagcache_search *tcs);
227 long tagcache_get_numeric(const struct tagcache_search *tcs, int tag);
228 long tagcache_increase_serial(void);
229 bool tagcache_import_changelog(void);
230 bool tagcache_create_changelog(struct tagcache_search *tcs);
231 void tagcache_update_numeric(int idx_id, int tag, long data);
232 bool tagcache_modify_numeric_entry(struct tagcache_search *tcs,
233 int tag, long data);
235 struct tagcache_stat* tagcache_get_stat(void);
236 int tagcache_get_commit_step(void);
237 bool tagcache_prepare_shutdown(void);
238 void tagcache_shutdown(void);
240 void tagcache_screensync_event(void);
241 void tagcache_screensync_enable(bool state);
243 #ifdef HAVE_TC_RAMCACHE
244 #ifdef HAVE_DIRCACHE
245 bool tagcache_fill_tags(struct mp3entry *id3, const char *filename);
246 #endif
247 void tagcache_unload_ramcache(void);
248 #endif
249 void tagcache_init(void) INIT_ATTR;
250 bool tagcache_is_initialized(void);
251 bool tagcache_is_fully_initialized(void);
252 bool tagcache_is_usable(void);
253 void tagcache_start_scan(void);
254 void tagcache_stop_scan(void);
255 bool tagcache_update(void);
256 bool tagcache_rebuild(void);
257 int tagcache_get_max_commit_step(void);
258 #endif
259 #endif