Commit Graph

64 Commits

Author SHA1 Message Date
Max Kellermann
ea8ae68e6f directory: added directory_is_root()
directory_is_root() is cheaper than
isRootDirectory(directory_get_path()).
2009-01-04 19:08:52 +01:00
Viliam Mateicka
455b39fa26 song: adding support for songs in archives 2008-12-16 21:42:42 +01:00
Max Kellermann
ea515494cb added prefix to header macros
"LOG_H" is a macro which is also used by ffmpeg/log.h.  This is
ffmpeg's fault, because short macros should be reserved for
applications, but since it's always a good idea to choose prefixed
macro names, even for applications, we are going to do that in MPD.
2008-10-31 09:19:53 +01:00
Max Kellermann
3b6ff84393 directory: added directory_get_name()
directory_get_name() returns the base name of the directory.
2008-10-13 16:32:39 +02:00
Max Kellermann
5ea2e198f9 directory: pass const pointers to inline functions
The inline functions directory_is_empty() and directory_get_path()
don't modify the object - pass constant object pointers to them.
2008-10-13 09:56:57 +02:00
Eric Wong
8d907fb9fa directory: use mpd_sizeof_str_flex_array for path, too
This way we avoid unnecessary heap allocations.
2008-10-13 09:55:00 +02:00
Max Kellermann
cbc0764613 directory: added inline wrappers for accessing children
Some tiny utilities... wrappers like these may become helpful when we
introduce locking.
2008-10-09 15:34:07 +02:00
Max Kellermann
68f716a28b directory: moved dirvec struct declaration to dirvec.h
No idea why it was created in directory.h, but it should be in
dirvec.h.
2008-10-09 15:24:05 +02:00
Max Kellermann
a0c044df11 diretory: moved code to directory_save.c, directory_print.c
Remove clutter from directory.c.  Everything which saves or loads
to/from the hard disk goes to directory_save.c, and code which sends
directory information to the client is moved into directory_print.c.
2008-10-09 15:23:37 +02:00
Max Kellermann
81220ca206 directory: include sys/types.h
ino_t and dev_t are declared in sys/types.h, not sys/stat.h.
2008-10-08 11:25:33 +02:00
Max Kellermann
0bfe7802d2 directory: path must not be NULL
For the root directory, let's set path to an empty string.  This saves
a few checks.
2008-10-08 11:08:16 +02:00
Max Kellermann
3b6efa99da directory: directory_get_path(NULL) is not allowed
Also convert directory_get_path() to an inline function, which returns
a constant string.
2008-10-08 11:08:04 +02:00
Max Kellermann
68977af6e0 directory: eliminate CamelCase
CamelCase is ugly, rename the functions.
2008-10-08 11:07:58 +02:00
Max Kellermann
8a50e8a266 directory: moved code to database.c
Taming the directory.c monster, part II: move the database management
stuff to database.  directory.c should only contain code which works
on directory objects.
2008-10-08 11:07:35 +02:00
Max Kellermann
ba5c9b0375 directory: converted isRootDirectory() to an inline function
The function isRootDirectory() is tiny and can be converted to an
inline function.  Don't allow name==NULL.
2008-10-08 11:06:44 +02:00
Max Kellermann
71351160b1 don't include os_compat.h
When there are standardized headers, use these instead of the bloated
os_compat.h.
2008-10-08 10:49:29 +02:00
Max Kellermann
d562ba5fbb song: converted typedef Song to struct song
Again, a data type which can be forward-declared.
2008-10-08 10:49:11 +02:00
Max Kellermann
25f67da58c directory: converted typedef Directory to struct directory
The struct can be forward-declared by other headers, which relaxes the
header dependencies.
2008-10-08 10:49:05 +02:00
Max Kellermann
e79aacf1db directory: added directory_is_empty()
directory_is_empty() is a tiny inline function which determine if a
directory has any child objects (sub directories or songs).
2008-10-08 10:48:49 +02:00
Max Kellermann
7b9bed8398 directory: moved code to update.c
The source directory.c mixes several libraries: directory object
management, database management and database update, resulting in a
1000+ line monster.  Move the whole database update code to update.c.
2008-10-08 10:48:48 +02:00
Eric Wong
37a8239f44 directory: simplify list update handling logic
Now the "update" command can be issued multiple times regardless
of whether the client is in list mode or not.

We serialize the update tasks to prevent updates from trampling
over each other and will spawn another update task
once the current one is finished updating and reaped.

Right now we cap the queue size to 32 which is probably enough (I
bet most people usually run update with no argument anyways);
but we can make it grow/shrink dynamically if needed.  There'll
still be a hard-coded limit to prevent DoS attacks, though.
2008-10-06 18:32:27 +02:00
Eric Wong
a0364d38d3 directory: remove "Mp3" references
MPD has supported more audio formats than just MP3
for over five years...
2008-09-29 13:17:42 +02:00
Eric Wong
5c516b8421 directory.h: remove directory_sigChldHandler decl
We no longer fork for directory updates, so we
no longer have children to reap.
2008-09-29 13:16:43 +02:00
Eric Wong
3b8bc33a04 directory: replace DirectoryList with dirvec
Small memory reduction compared to songvec since most users have
much fewer dirs than songs, but still nice to have.
2008-09-29 13:11:40 +02:00
Max Kellermann
323e86489f song: removed type SongList
SongList has been superseded by struct songvec.
2008-09-26 09:54:25 +02:00
Eric Wong
3f0ae13c4b directory: update do its work inside a thread
A lot of the preparation was needed (and done in previous
months) in making update thread-safe, but here it is.

This was the first thing I made work inside a thread when I
started mpd-uclinux many years ago, and also the last thing I've
done in mainline mpd to work inside a thread, go figure.
2008-09-23 22:37:18 +02:00
Eric Wong
0bec1d3807 Replace SongList with struct songvec
Our linked-list implementation is wasteful and the
SongList isn't modified enough to benefit from being a linked
list.  So use a more compact array of song pointers which
saves ~200K on a library with ~9K songs (on x86-32).
2008-09-23 20:48:39 +02:00
Eric Wong
afe6ce7210 directory: remove unused updateMp3Directory() function
It hasn't been used in many years

  commit 3a89afdd80
  Author: Warren Dukes <warren.dukes@gmail.com>
  Date:   Sat Nov 20 20:28:32 2004 +0000

      remove --update-db option

      (SVN r2719)
2008-09-23 20:48:33 +02:00
Eric Wong
d095d52ed4 Directory: don't allocate stat information dynamically
This should save a few thousand ops.  Not worth it to malloc
for such a small (3-words on 32-bit ARM and x86) structures.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
2008-09-23 20:47:45 +02:00
Max Kellermann
dc8b64fdef pass "struct client" to dbUtils.c, song.c, tag_print.c
Don't pass the raw file descriptor around.  This migration patch is
rather large, because all of the sources have inter dependencies - we
have to change all of them at the same time.
2008-09-07 13:53:55 +02:00
Max Kellermann
8e3c40f032 directory: don't pass "fd" to updateInit()
Again, move error handling to command.c.
2008-09-07 13:50:06 +02:00
Max Kellermann
f320c9fa1d directory: don't pass fd to traverseAllIn()
This patch continues the work of the previous patch: don't pass a file
descriptor at all to traverseAllIn().  Since this fd was only used to
report "directory not found" errors, we can easily move that check to
the caller.  This is a great relief, since it removes the dependency
on a client connection from a lot of enumeration functions.
2008-09-07 13:48:37 +02:00
Max Kellermann
528be8a0a9 directory: don't pass fd to traverseAllIn() callbacks
Database traversal should be generic, and not bound to a client
connection.  This is the first step: no file descriptor for the
callback functions forEachSong() and forEachDir().  If a callback
needs the file descriptor, it has to be passed in the void*data
pointer somehow; some callbacks might need a new struct for passing
more than one parameter.  This might look a bit cumbersome right now,
but our goal is to have a clean API.
2008-09-07 13:48:24 +02:00
Max Kellermann
35c0b84f08 dbUtils, playlist, directory: pass constant pointers
The usual bunch of const pointer conversions.
2008-09-06 15:28:31 +02:00
Max Kellermann
c89b358c8a clean up CPP includes
Try to only include headers which are really needed.  We should
particularly check all "headers including other headers".  The
long-term goal is to have a manageable, small API for plugins
(decoders, output) without so many mpd internals cluttering the
namespace.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7319 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:26 +00:00
Max Kellermann
6fbdc721d9 fix -Wconst warnings
[ew: cleaned up the dirty union hack a bit]
Signed-off-by: Eric Wong <normalperson@yhbt.net>

git-svn-id: https://svn.musicpd.org/mpd/trunk@7180 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-02-05 10:17:33 +00:00
J. Alexander Treuman
c408bd5e90 Don't list playlists in lsinfo if the path isn't the root directory (they
can't be loaded anyway).

git-svn-id: https://svn.musicpd.org/mpd/trunk@6244 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-24 17:06:59 +00:00
Avuton Olrich
a061da8fb5 The massive copyright update
git-svn-id: https://svn.musicpd.org/mpd/trunk@5834 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-04-05 03:22:33 +00:00
Avuton Olrich
f79a70d1b9 Fix warnings for -Wmissing-prototypes
Add -Wmissing-prototypes if compiling with gcc
Static where possible

git-svn-id: https://svn.musicpd.org/mpd/trunk@4657 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-20 00:50:44 +00:00
Eric Wong
4cf5d04ca1 interface/connection malloc reductions from mpd-ke
This patch massively reduces the amount of heap allocations at
the interface/command layer.  Most commands with minimal output
should not allocate memory from the heap at all.  Things like
repeatedly polling status, currentsong, and volume changes
should be faster as a result, and more importantly, not a source
of memory fragmentation.

These changes should be safe in that there's no way for a
remote-client to corrupt memory or otherwise do bad stuff to
MPD, but an extra set of eyes to review would be good.  Of
course there's never any warranty :)

No longer do we use FILE * structures in the interface, which means
we don't have to allocate any new memory for most connections.

Now, before you go on about losing the buffering that FILE *
+implies+, remember that myfprintf() never took advantage of
any of the stdio buffering features.

To reduce the diff and make bugs easier to spot in the diff,
I've kept myfprintf in places where we write to files (and not
network interfaces).  Expect myfprintf to go away entirely soon
(we'll use fprintf for writing regular files).

git-svn-id: https://svn.musicpd.org/mpd/trunk@4483 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-30 03:43:38 +00:00
Avuton Olrich
29a25b9933 Add mpd-indent.sh
Indent the entire tree, hopefully we can keep
it indented.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4410 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-20 16:02:40 +00:00
J. Alexander Treuman
2fa7125cce Change shank's email address
git-svn-id: https://svn.musicpd.org/mpd/trunk@4333 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-14 19:37:45 +00:00
Avuton Olrich
75789d1490 [CLEANUP] Remove unused functions from the header
Convert some spaces to tabs
Static what makes sense
Remove unused includes

git-svn-id: https://svn.musicpd.org/mpd/trunk@4328 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-14 19:11:11 +00:00
Avuton Olrich
a37348a74f Huge header update, update the copyright and add
the GPL header where necessary

git-svn-id: https://svn.musicpd.org/mpd/trunk@4317 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-13 19:20:34 +00:00
Qball Cow
66e4379d69 Jat/Q patch for checking permission on database before creating it
git-svn-id: https://svn.musicpd.org/mpd/trunk@4140 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-05-08 21:03:47 +00:00
Warren Dukes
586a21688f config file change! now 'port' is optional and 'db_file' is required!
also, should have better error reporting when failing to open playlist or
music directory's, or writing the db, etc

git-svn-id: https://svn.musicpd.org/mpd/trunk@3027 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2005-03-06 19:00:58 +00:00
Warren Dukes
0473f3ea76 don't store only relative paths in the directory structure, its probably not
worth the savings in memory for the extra cpu it requires

git-svn-id: https://svn.musicpd.org/mpd/trunk@2630 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-11-12 17:38:52 +00:00
Warren Dukes
21b5cde43a ok, optimize memory sage of directorys, by iteratively creating the directories,
this code needs some serious testing:

Note:
The song name optimization i think is worth it, saves about 200k of ram on my syste, however, having to create directory names iteratively each time we print probably isn't worth the cpu.  We only save about 10k of ram for the computer todo alot more work, and the code maybe a little messier

git-svn-id: https://svn.musicpd.org/mpd/trunk@2604 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-11-11 04:34:26 +00:00
Warren Dukes
4ec3df0339 implement saved memory by not storing full path
git-svn-id: https://svn.musicpd.org/mpd/trunk@2601 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-11-11 02:36:25 +00:00
Warren Dukes
c5d27d8eaa merge changes from metadata-rewrite branch
git-svn-id: https://svn.musicpd.org/mpd/trunk@2589 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-11-10 21:58:27 +00:00