MPD

src/directory.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2010 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 "dirvec.h"
00025 #include "songvec.h"
00026 #include "playlist_vector.h"
00027 
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 struct directory {
00037         struct dirvec children;
00038         struct songvec songs;
00039 
00040         struct playlist_vector playlists;
00041 
00042         struct directory *parent;
00043         time_t mtime;
00044         ino_t inode;
00045         dev_t device;
00046         unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */
00047         char path[sizeof(long)];
00048 };
00049 
00050 static inline bool
00051 isRootDirectory(const char *name)
00052 {
00053         return name[0] == 0 || (name[0] == '/' && name[1] == 0);
00054 }
00055 
00056 struct directory *
00057 directory_new(const char *dirname, struct directory *parent);
00058 
00059 void
00060 directory_free(struct directory *directory);
00061 
00062 static inline bool
00063 directory_is_empty(const struct directory *directory)
00064 {
00065         return directory->children.nr == 0 && directory->songs.nr == 0;
00066 }
00067 
00068 static inline const char *
00069 directory_get_path(const struct directory *directory)
00070 {
00071         return directory->path;
00072 }
00073 
00077 static inline bool
00078 directory_is_root(const struct directory *directory)
00079 {
00080         return directory->parent == NULL;
00081 }
00082 
00086 const char *
00087 directory_get_name(const struct directory *directory);
00088 
00089 static inline struct directory *
00090 directory_get_child(const struct directory *directory, const char *name)
00091 {
00092         return dirvec_find(&directory->children, name);
00093 }
00094 
00095 static inline struct directory *
00096 directory_new_child(struct directory *directory, const char *name)
00097 {
00098         struct directory *subdir = directory_new(name, directory);
00099         dirvec_add(&directory->children, subdir);
00100         return subdir;
00101 }
00102 
00103 void
00104 directory_prune_empty(struct directory *directory);
00105 
00113 struct directory *
00114 directory_lookup_directory(struct directory *directory, const char *uri);
00115 
00123 struct song *
00124 directory_lookup_song(struct directory *directory, const char *uri);
00125 
00126 void
00127 directory_sort(struct directory *directory);
00128 
00129 int
00130 directory_walk(struct directory *directory,
00131                int (*forEachSong)(struct song *, void *),
00132                int (*forEachDir)(struct directory *, void *),
00133                void *data);
00134 
00135 #endif