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