configure.ac: Move OggVorbis Encoder to Encoder Plugins.
[mpd-mk.git] / src / directory.h
blob4a137b3a59eb7319f86d75bedcf55148f59936fa
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef MPD_DIRECTORY_H
21 #define MPD_DIRECTORY_H
23 #include "check.h"
24 #include "dirvec.h"
25 #include "songvec.h"
27 #include <stdbool.h>
28 #include <sys/types.h>
30 #define DIRECTORY_DIR "directory: "
32 #define DEVICE_INARCHIVE (unsigned)(-1)
33 #define DEVICE_CONTAINER (unsigned)(-2)
35 struct directory {
36 struct dirvec children;
37 struct songvec songs;
38 struct directory *parent;
39 time_t mtime;
40 ino_t inode;
41 dev_t device;
42 unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */
43 char path[sizeof(long)];
46 static inline bool
47 isRootDirectory(const char *name)
49 return name[0] == 0 || (name[0] == '/' && name[1] == 0);
52 struct directory *
53 directory_new(const char *dirname, struct directory *parent);
55 void
56 directory_free(struct directory *directory);
58 static inline bool
59 directory_is_empty(const struct directory *directory)
61 return directory->children.nr == 0 && directory->songs.nr == 0;
64 static inline const char *
65 directory_get_path(const struct directory *directory)
67 return directory->path;
70 /**
71 * Is this the root directory of the music database?
73 static inline bool
74 directory_is_root(const struct directory *directory)
76 return directory->parent == NULL;
79 /**
80 * Returns the base name of the directory.
82 const char *
83 directory_get_name(const struct directory *directory);
85 static inline struct directory *
86 directory_get_child(const struct directory *directory, const char *name)
88 return dirvec_find(&directory->children, name);
91 static inline struct directory *
92 directory_new_child(struct directory *directory, const char *name)
94 struct directory *subdir = directory_new(name, directory);
95 dirvec_add(&directory->children, subdir);
96 return subdir;
99 void
100 directory_prune_empty(struct directory *directory);
103 * Looks up a directory by its relative URI.
105 * @param directory the parent (or grandparent, ...) directory
106 * @param uri the relative URI
107 * @return the directory, or NULL if none was found
109 struct directory *
110 directory_lookup_directory(struct directory *directory, const char *uri);
113 * Looks up a song by its relative URI.
115 * @param directory the parent (or grandparent, ...) directory
116 * @param uri the relative URI
117 * @return the song, or NULL if none was found
119 struct song *
120 directory_lookup_song(struct directory *directory, const char *uri);
122 void
123 directory_sort(struct directory *directory);
126 directory_walk(struct directory *directory,
127 int (*forEachSong)(struct song *, void *),
128 int (*forEachDir)(struct directory *, void *),
129 void *data);
131 #endif