2 * This file is part of DisOrder
3 * Copyright (C) 2005, 2006, 2007 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 /* Database version string */
27 #define DBVERSION "2.0"
29 extern const struct cache_type cache_files_type
;
30 extern unsigned long cache_files_hits
, cache_files_misses
;
31 /* Cache entry type and tracking for regexp-based lookups */
33 void trackdb_init(int recover
);
34 #define TRACKDB_NO_RECOVER 0
35 #define TRACKDB_NORMAL_RECOVER 1
36 #define TRACKDB_FATAL_RECOVER 2
37 void trackdb_deinit(void);
38 /* close/close environment */
40 void trackdb_master(struct ev_source
*ev
);
41 /* start deadlock manager */
43 void trackdb_open(void);
44 void trackdb_close(void);
45 /* open/close track databases */
47 char **trackdb_stats(int *nstatsp
);
48 /* return a list of database stats */
50 void trackdb_stats_subprocess(struct ev_source
*ev
,
51 void (*done
)(char *data
, void *u
),
53 /* collect stats in background and call done() with results */
55 int trackdb_set(const char *track
,
58 /* set a pref (remove if value=0). Return 0 t */
60 const char *trackdb_get(const char *track
,
64 struct kvp
*trackdb_get_all(const char *track
);
67 const char *trackdb_resolve(const char *track
);
68 /* resolve alias - returns a null pointer if not found */
70 int trackdb_isalias(const char *track
);
71 /* return true if TRACK is an alias */
73 int trackdb_exists(const char *track
);
74 /* test whether a track exists (perhaps an alias) */
76 const char *trackdb_random(int tries
);
77 /* Pick a random non-alias track, making at most TRIES attempts. Returns a
78 * null pointer on failure. */
80 char **trackdb_alltags(void);
81 /* Return the list of all tags */
83 const char *trackdb_getpart(const char *track
,
86 /* get a track name part, like trackname_part(), but taking the database into
89 const char *trackdb_rawpath(const char *track
);
90 /* get the raw path name for TRACK (might be an alias); returns a null pointer
93 enum trackdb_listable
{
95 trackdb_directories
= 2
98 char **trackdb_list(const char *dir
, int *np
, enum trackdb_listable what
,
100 /* Return the directories and/or files below DIR. If DIR is a null pointer
101 * then concatenate the listing of all collections.
103 * If REC is not a null pointer then only names where the basename matches the
104 * regexp are returned.
107 char **trackdb_search(char **wordlist
, int nwordlist
, int *ntracks
);
108 /* return a list of tracks containing all of the words given. If you
109 * ask for only stopwords you get no tracks. */
111 void trackdb_rescan(struct ev_source
*ev
);
112 /* Start a rescan, if one is not running already */
114 int trackdb_rescan_cancel(void);
115 /* interrupt any running rescan. Return 1 if one was running, else 0. */
117 void trackdb_gc(void);
118 /* tidy up old database log files */
120 void trackdb_set_global(const char *name
,
123 /* set a global pref (remove if value=0). */
125 const char *trackdb_get_global(const char *name
);
126 /* get a global pref */
128 char **trackdb_new(int *ntracksp
, int maxtracks
);
130 void trackdb_expire_noticed(time_t when
);
132 #endif /* TRACKDB_H */