MPD
directory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
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.
9  *
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.
14  *
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.
18  */
19 
20 #ifndef MPD_DIRECTORY_H
21 #define MPD_DIRECTORY_H
22 
23 #include "check.h"
24 #include "dirvec.h"
25 #include "songvec.h"
26 #include "playlist_vector.h"
27 
28 #include <stdbool.h>
29 #include <sys/types.h>
30 
31 #define DIRECTORY_DIR "directory: "
32 
33 #define DEVICE_INARCHIVE (dev_t)(-1)
34 #define DEVICE_CONTAINER (dev_t)(-2)
35 
36 struct directory {
37  struct dirvec children;
38  struct songvec songs;
39 
41 
42  struct directory *parent;
43  time_t mtime;
44  ino_t inode;
45  dev_t device;
46  bool have_stat; /* not needed if ino_t == dev_t == 0 is impossible */
47  char path[sizeof(long)];
48 };
49 
50 static inline bool
51 isRootDirectory(const char *name)
52 {
53  return name[0] == 0 || (name[0] == '/' && name[1] == 0);
54 }
55 
56 struct directory *
57 directory_new(const char *dirname, struct directory *parent);
58 
59 void
61 
62 static inline bool
64 {
65  return directory->children.nr == 0 && directory->songs.nr == 0 &&
67 }
68 
69 static inline const char *
71 {
72  return directory->path;
73 }
74 
78 static inline bool
80 {
81  return directory->parent == NULL;
82 }
83 
87 const char *
89 
90 static inline struct directory *
91 directory_get_child(const struct directory *directory, const char *name)
92 {
93  return dirvec_find(&directory->children, name);
94 }
95 
96 static inline struct directory *
97 directory_new_child(struct directory *directory, const char *name)
98 {
99  struct directory *subdir = directory_new(name, directory);
100  dirvec_add(&directory->children, subdir);
101  return subdir;
102 }
103 
104 void
106 
114 struct directory *
115 directory_lookup_directory(struct directory *directory, const char *uri);
116 
124 struct song *
125 directory_lookup_song(struct directory *directory, const char *uri);
126 
127 void
129 
130 int
132  int (*forEachSong)(struct song *, void *),
133  int (*forEachDir)(struct directory *, void *),
134  void *data);
135 
136 #endif