MPD 0.17~git
src/directory.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2011 The Music Player Daemon Project
00003  * http://www.musicpd.org
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #ifndef MPD_DIRECTORY_H
00021 #define MPD_DIRECTORY_H
00022 
00023 #include "check.h"
00024 #include "util/list.h"
00025 #include "playlist_vector.h"
00026 
00027 #include <glib.h>
00028 #include <stdbool.h>
00029 #include <sys/types.h>
00030 
00031 #define DIRECTORY_DIR           "directory: "
00032 
00033 #define DEVICE_INARCHIVE (dev_t)(-1)
00034 #define DEVICE_CONTAINER (dev_t)(-2)
00035 
00036 #define directory_for_each_child(pos, directory) \
00037         list_for_each_entry(pos, &directory->children, siblings)
00038 
00039 #define directory_for_each_child_safe(pos, n, directory) \
00040         list_for_each_entry_safe(pos, n, &directory->children, siblings)
00041 
00042 #define directory_for_each_song(pos, directory) \
00043         list_for_each_entry(pos, &directory->songs, siblings)
00044 
00045 #define directory_for_each_song_safe(pos, n, directory) \
00046         list_for_each_entry_safe(pos, n, &directory->songs, siblings)
00047 
00048 struct song;
00049 struct db_visitor;
00050 
00051 struct directory {
00060         struct list_head siblings;
00061 
00068         struct list_head children;
00069 
00076         struct list_head songs;
00077 
00078         struct playlist_vector playlists;
00079 
00080         struct directory *parent;
00081         time_t mtime;
00082         ino_t inode;
00083         dev_t device;
00084         bool have_stat; /* not needed if ino_t == dev_t == 0 is impossible */
00085         char path[sizeof(long)];
00086 };
00087 
00088 static inline bool
00089 isRootDirectory(const char *name)
00090 {
00091         return name[0] == 0 || (name[0] == '/' && name[1] == 0);
00092 }
00093 
00097 G_GNUC_MALLOC
00098 struct directory *
00099 directory_new(const char *dirname, struct directory *parent);
00100 
00104 G_GNUC_MALLOC
00105 static inline struct directory *
00106 directory_new_root(void)
00107 {
00108         return directory_new("", NULL);
00109 }
00110 
00115 void
00116 directory_free(struct directory *directory);
00117 
00124 void
00125 directory_delete(struct directory *directory);
00126 
00127 static inline bool
00128 directory_is_empty(const struct directory *directory)
00129 {
00130         return list_empty(&directory->children) &&
00131                 list_empty(&directory->songs) &&
00132                 playlist_vector_is_empty(&directory->playlists);
00133 }
00134 
00135 static inline const char *
00136 directory_get_path(const struct directory *directory)
00137 {
00138         return directory->path;
00139 }
00140 
00144 static inline bool
00145 directory_is_root(const struct directory *directory)
00146 {
00147         return directory->parent == NULL;
00148 }
00149 
00153 G_GNUC_PURE
00154 const char *
00155 directory_get_name(const struct directory *directory);
00156 
00160 G_GNUC_PURE
00161 struct directory *
00162 directory_get_child(const struct directory *directory, const char *name);
00163 
00172 G_GNUC_MALLOC
00173 struct directory *
00174 directory_new_child(struct directory *parent, const char *name_utf8);
00175 
00182 static inline struct directory *
00183 directory_make_child(struct directory *directory, const char *name_utf8)
00184 {
00185         struct directory *child = directory_get_child(directory, name_utf8);
00186         if (child == NULL)
00187                 child = directory_new_child(directory, name_utf8);
00188         return child;
00189 }
00190 
00194 void
00195 directory_prune_empty(struct directory *directory);
00196 
00204 struct directory *
00205 directory_lookup_directory(struct directory *directory, const char *uri);
00206 
00211 void
00212 directory_add_song(struct directory *directory, struct song *song);
00213 
00219 void
00220 directory_remove_song(struct directory *directory, struct song *song);
00221 
00227 G_GNUC_PURE
00228 struct song *
00229 directory_get_song(const struct directory *directory, const char *name_utf8);
00230 
00240 struct song *
00241 directory_lookup_song(struct directory *directory, const char *uri);
00242 
00248 void
00249 directory_sort(struct directory *directory);
00250 
00254 bool
00255 directory_walk(const struct directory *directory, bool recursive,
00256                const struct db_visitor *visitor, void *ctx,
00257                GError **error_r);
00258 
00259 #endif