00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef MPD_DIRECTORY_H
00021 #define MPD_DIRECTORY_H
00022
00023 #include "check.h"
00024 #include "util/list.h"
00025
00026 #include <glib.h>
00027 #include <stdbool.h>
00028 #include <sys/types.h>
00029
00030 #define DEVICE_INARCHIVE (dev_t)(-1)
00031 #define DEVICE_CONTAINER (dev_t)(-2)
00032
00033 #define directory_for_each_child(pos, directory) \
00034 list_for_each_entry(pos, &directory->children, siblings)
00035
00036 #define directory_for_each_child_safe(pos, n, directory) \
00037 list_for_each_entry_safe(pos, n, &directory->children, siblings)
00038
00039 #define directory_for_each_song(pos, directory) \
00040 list_for_each_entry(pos, &directory->songs, siblings)
00041
00042 #define directory_for_each_song_safe(pos, n, directory) \
00043 list_for_each_entry_safe(pos, n, &directory->songs, siblings)
00044
00045 #define directory_for_each_playlist(pos, directory) \
00046 list_for_each_entry(pos, &directory->playlists, siblings)
00047
00048 #define directory_for_each_playlist_safe(pos, n, directory) \
00049 list_for_each_entry_safe(pos, n, &directory->playlists, siblings)
00050
00051 struct song;
00052 struct db_visitor;
00053
00054 struct directory {
00063 struct list_head siblings;
00064
00071 struct list_head children;
00072
00079 struct list_head songs;
00080
00081 struct list_head playlists;
00082
00083 struct directory *parent;
00084 time_t mtime;
00085 ino_t inode;
00086 dev_t device;
00087 bool have_stat;
00088 char path[sizeof(long)];
00089 };
00090
00091 static inline bool
00092 isRootDirectory(const char *name)
00093 {
00094 return name[0] == 0 || (name[0] == '/' && name[1] == 0);
00095 }
00096
00100 G_GNUC_MALLOC
00101 struct directory *
00102 directory_new(const char *dirname, struct directory *parent);
00103
00107 G_GNUC_MALLOC
00108 static inline struct directory *
00109 directory_new_root(void)
00110 {
00111 return directory_new("", NULL);
00112 }
00113
00118 void
00119 directory_free(struct directory *directory);
00120
00127 void
00128 directory_delete(struct directory *directory);
00129
00130 static inline bool
00131 directory_is_empty(const struct directory *directory)
00132 {
00133 return list_empty(&directory->children) &&
00134 list_empty(&directory->songs) &&
00135 list_empty(&directory->playlists);
00136 }
00137
00138 static inline const char *
00139 directory_get_path(const struct directory *directory)
00140 {
00141 return directory->path;
00142 }
00143
00147 static inline bool
00148 directory_is_root(const struct directory *directory)
00149 {
00150 return directory->parent == NULL;
00151 }
00152
00156 G_GNUC_PURE
00157 const char *
00158 directory_get_name(const struct directory *directory);
00159
00163 G_GNUC_PURE
00164 struct directory *
00165 directory_get_child(const struct directory *directory, const char *name);
00166
00175 G_GNUC_MALLOC
00176 struct directory *
00177 directory_new_child(struct directory *parent, const char *name_utf8);
00178
00185 static inline struct directory *
00186 directory_make_child(struct directory *directory, const char *name_utf8)
00187 {
00188 struct directory *child = directory_get_child(directory, name_utf8);
00189 if (child == NULL)
00190 child = directory_new_child(directory, name_utf8);
00191 return child;
00192 }
00193
00197 void
00198 directory_prune_empty(struct directory *directory);
00199
00207 struct directory *
00208 directory_lookup_directory(struct directory *directory, const char *uri);
00209
00214 void
00215 directory_add_song(struct directory *directory, struct song *song);
00216
00222 void
00223 directory_remove_song(struct directory *directory, struct song *song);
00224
00230 G_GNUC_PURE
00231 struct song *
00232 directory_get_song(const struct directory *directory, const char *name_utf8);
00233
00243 struct song *
00244 directory_lookup_song(struct directory *directory, const char *uri);
00245
00251 void
00252 directory_sort(struct directory *directory);
00253
00257 bool
00258 directory_walk(const struct directory *directory, bool recursive,
00259 const struct db_visitor *visitor, void *ctx,
00260 GError **error_r);
00261
00262 #endif