Add a slot to set the progress bar value and a member to hide it.
[Rockbox.git] / apps / tagcache.h
blobb9d6a2911b0ea209edd0bc127252d845f764966a
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_comment, tag_albumartist, tag_grouping, tag_year,
27 tag_discnumber, tag_tracknumber, tag_bitrate, tag_length, tag_playcount, tag_rating,
28 tag_playtime, tag_lastplayed, tag_commitid, tag_mtime,
29 /* Virtual tags */
30 tag_virt_length_min, tag_virt_length_sec,
31 tag_virt_playtime_min, tag_virt_playtime_sec,
32 tag_virt_entryage, tag_virt_autoscore };
34 #define TAG_COUNT 20
36 /* Maximum length of a single tag. */
37 #define TAG_MAXLEN (MAX_PATH*2)
39 /* Allow a little drift to the filename ordering (should not be too high/low). */
40 #define POS_HISTORY_COUNT 4
42 /* How much to pre-load entries while committing to prevent seeking. */
43 #define IDX_BUF_DEPTH 64
45 /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */
46 #define TAGCACHE_MAGIC 0x5443480c
48 /* How much to allocate extra space for ramcache. */
49 #define TAGCACHE_RESERVE 32768
51 /**
52 * Define how long one entry must be at least (longer -> less memory at commit).
53 * Must be at least 4 bytes in length for correct alignment.
55 #define TAGFILE_ENTRY_CHUNK_LENGTH 8
57 /* Used to guess the necessary buffer size at commit. */
58 #define TAGFILE_ENTRY_AVG_LENGTH 16
60 /* How many entries to fetch to the seek table at once while searching. */
61 #define SEEK_LIST_SIZE 32
63 /* Always strict align entries for best performance and binary compatibility. */
64 #define TAGCACHE_STRICT_ALIGN 1
66 /* Max events in the internal tagcache command queue. */
67 #define TAGCACHE_COMMAND_QUEUE_LENGTH 32
68 /* Idle time before committing events in the command queue. */
69 #define TAGCACHE_COMMAND_QUEUE_COMMIT_DELAY HZ*2
71 #define TAGCACHE_MAX_FILTERS 4
72 #define TAGCACHE_MAX_CLAUSES 32
74 /* Tag database files. */
76 /* Temporary database containing new tags to be committed to the main db. */
77 #define TAGCACHE_FILE_TEMP ROCKBOX_DIR "/database_tmp.tcd"
79 /* The main database master index and numeric data. */
80 #define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/database_idx.tcd"
82 /* The main database string data. */
83 #define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/database_%d.tcd"
85 /* ASCII dumpfile of the DB contents. */
86 #define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/database_changelog.txt"
88 /* Serialized DB. */
89 #define TAGCACHE_STATEFILE ROCKBOX_DIR "/database_state.tcd"
91 /* Flags */
92 #define FLAG_DELETED 0x0001 /* Entry has been removed from db */
93 #define FLAG_DIRCACHE 0x0002 /* Filename is a dircache pointer */
94 #define FLAG_DIRTYNUM 0x0004 /* Numeric data has been modified */
95 #define FLAG_TRKNUMGEN 0x0008 /* Track number has been generated */
96 #define FLAG_RESURRECTED 0x0010 /* Statistics data has been resurrected */
97 #define FLAG_GET_ATTR(flag) ((flag >> 16) & 0x0000ffff)
98 #define FLAG_SET_ATTR(flag,attr) flag = (flag & 0x0000ffff) | (attr << 16)
100 enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq,
101 clause_lt, clause_lteq, clause_contains, clause_not_contains,
102 clause_begins_with, clause_not_begins_with, clause_ends_with,
103 clause_not_ends_with, clause_oneof };
105 struct tagcache_stat {
106 bool initialized; /* Is tagcache currently busy? */
107 bool readyvalid; /* Has tagcache ready status been ascertained */
108 bool ready; /* Is tagcache ready to be used? */
109 bool ramcache; /* Is tagcache loaded in ram? */
110 bool commit_delayed; /* Has commit been delayed until next reboot? */
111 bool econ; /* Is endianess correction enabled? */
112 int commit_step; /* Commit progress */
113 int ramcache_allocated; /* Has ram been allocated for ramcache? */
114 int ramcache_used; /* How much ram has been really used */
115 int progress; /* Current progress of disk scan */
116 int processed_entries; /* Scanned disk entries so far */
117 int queue_length; /* Command queue length */
118 volatile const char
119 *curentry; /* Path of the current entry being scanned. */
120 volatile bool syncscreen;/* Synchronous operation with debug screen? */
121 // const char *uimessage; /* Pending error message. Implement soon. */
124 enum source_type {source_constant,
125 source_runtime,
126 source_current_path /* dont add items after this.
127 it is used as an index
128 into id3_to_search_mapping */
131 struct tagcache_search_clause
133 int tag;
134 int type;
135 bool numeric;
136 int source;
137 long numeric_data;
138 char *str;
141 struct tagcache_search {
142 /* For internal use only. */
143 int fd, masterfd;
144 int idxfd[TAG_COUNT];
145 long seek_list[SEEK_LIST_SIZE];
146 long seek_flags[SEEK_LIST_SIZE];
147 long filter_tag[TAGCACHE_MAX_FILTERS];
148 long filter_seek[TAGCACHE_MAX_FILTERS];
149 int filter_count;
150 struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES];
151 int clause_count;
152 int seek_list_count;
153 int seek_pos;
154 long position;
155 int entry_count;
156 bool valid;
157 bool initialized;
158 unsigned long *unique_list;
159 int unique_list_capacity;
160 int unique_list_count;
162 /* Exported variables. */
163 bool ramsearch;
164 bool ramresult;
165 int type;
166 char *result;
167 int result_len;
168 long result_seek;
169 int idx_id;
172 void tagcache_build(const char *path);
174 #ifdef __PCTOOL__
175 void tagcache_reverse_scan(void);
176 #endif
178 const char* tagcache_tag_to_str(int tag);
180 bool tagcache_is_numeric_tag(int type);
181 bool tagcache_is_unique_tag(int type);
182 bool tagcache_is_sorted_tag(int type);
183 bool tagcache_find_index(struct tagcache_search *tcs, const char *filename);
184 bool tagcache_check_clauses(struct tagcache_search *tcs,
185 struct tagcache_search_clause **clause, int count);
186 bool tagcache_search(struct tagcache_search *tcs, int tag);
187 void tagcache_search_set_uniqbuf(struct tagcache_search *tcs,
188 void *buffer, long length);
189 bool tagcache_search_add_filter(struct tagcache_search *tcs,
190 int tag, int seek);
191 bool tagcache_search_add_clause(struct tagcache_search *tcs,
192 struct tagcache_search_clause *clause);
193 bool tagcache_get_next(struct tagcache_search *tcs);
194 bool tagcache_retrieve(struct tagcache_search *tcs, int idxid,
195 int tag, char *buf, long size);
196 void tagcache_search_finish(struct tagcache_search *tcs);
197 long tagcache_get_numeric(const struct tagcache_search *tcs, int tag);
198 long tagcache_increase_serial(void);
199 long tagcache_get_serial(void);
200 bool tagcache_import_changelog(void);
201 bool tagcache_create_changelog(struct tagcache_search *tcs);
202 void tagcache_update_numeric(int idx_id, int tag, long data);
203 bool tagcache_modify_numeric_entry(struct tagcache_search *tcs,
204 int tag, long data);
206 struct tagcache_stat* tagcache_get_stat(void);
207 int tagcache_get_commit_step(void);
208 bool tagcache_prepare_shutdown(void);
209 void tagcache_shutdown(void);
211 void tagcache_screensync_event(void);
212 void tagcache_screensync_enable(bool state);
214 #ifdef HAVE_TC_RAMCACHE
215 bool tagcache_is_ramcache(void);
216 bool tagcache_fill_tags(struct mp3entry *id3, const char *filename);
217 void tagcache_unload_ramcache(void);
218 #endif
219 void tagcache_init(void);
220 bool tagcache_is_initialized(void);
221 bool tagcache_is_usable(void);
222 void tagcache_start_scan(void);
223 void tagcache_stop_scan(void);
224 bool tagcache_update(void);
225 bool tagcache_rebuild(void);
226 int tagcache_get_max_commit_step(void);
227 #endif
228 #endif