From 6f43d71628db3c9acb9e0693216885685566b7d3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 10:48:48 +0200 Subject: 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. --- src/update.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/update.h (limited to 'src/update.h') diff --git a/src/update.h b/src/update.h new file mode 100644 index 000000000..132ef175d --- /dev/null +++ b/src/update.h @@ -0,0 +1,44 @@ +/* the Music Player Daemon (MPD) + * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) + * Copyright (C) 2008 Max Kellermann + * This project's homepage is: http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef UPDATE_H +#define UPDATE_H + +#include "directory.h" + +enum update_return { + UPDATE_RETURN_ERROR = -1, + UPDATE_RETURN_NOUPDATE = 0, + UPDATE_RETURN_UPDATED = 1 +}; + +int isUpdatingDB(void); + +enum update_return exploreDirectory(Directory * directory); + +/* + * returns the non-negative update job ID on success, + * returns -1 if busy + * @path will be freed by this function and should not be reused + */ +int directory_update_init(char *path); + +void reap_update_task(void); + +#endif -- cgit v1.2.3 From b5d3970c075987d7439e2b60ea043606f46a3bab Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 10:48:55 +0200 Subject: update: merged exploreDirectory() into updateDirectory() exploreDirectory() duplicates some code in updateDirectory(). Merge both functions, and use directory_is_empty() to determine whether update or explore mode should be used. --- src/update.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/update.h') diff --git a/src/update.h b/src/update.h index 132ef175d..4e59e39b1 100644 --- a/src/update.h +++ b/src/update.h @@ -30,7 +30,7 @@ enum update_return { int isUpdatingDB(void); -enum update_return exploreDirectory(Directory * directory); +enum update_return updateDirectory(Directory * directory); /* * returns the non-negative update job ID on success, -- cgit v1.2.3 From c84c73df00e5e1710d84fdb4be6352d849da8f2b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 10:49:05 +0200 Subject: directory: converted typedef Directory to struct directory The struct can be forward-declared by other headers, which relaxes the header dependencies. --- src/update.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/update.h') diff --git a/src/update.h b/src/update.h index 4e59e39b1..65ffdc3bf 100644 --- a/src/update.h +++ b/src/update.h @@ -20,7 +20,7 @@ #ifndef UPDATE_H #define UPDATE_H -#include "directory.h" +struct directory; enum update_return { UPDATE_RETURN_ERROR = -1, @@ -30,7 +30,7 @@ enum update_return { int isUpdatingDB(void); -enum update_return updateDirectory(Directory * directory); +enum update_return updateDirectory(struct directory *directory); /* * returns the non-negative update job ID on success, -- cgit v1.2.3 From 6fd08bc8fad5d6c4be37ce751d53ef80b756b292 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 9 Oct 2008 19:11:54 +0200 Subject: update: don't export updateDirectory() If the user requests database update during startup, call directory_update_init(). This should be changed to fully asynchronous update later. For this to work, main_notify has to be initialized before db_init(). --- src/update.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/update.h') diff --git a/src/update.h b/src/update.h index 65ffdc3bf..0c0d74416 100644 --- a/src/update.h +++ b/src/update.h @@ -20,18 +20,8 @@ #ifndef UPDATE_H #define UPDATE_H -struct directory; - -enum update_return { - UPDATE_RETURN_ERROR = -1, - UPDATE_RETURN_NOUPDATE = 0, - UPDATE_RETURN_UPDATED = 1 -}; - int isUpdatingDB(void); -enum update_return updateDirectory(struct directory *directory); - /* * returns the non-negative update job ID on success, * returns -1 if busy -- cgit v1.2.3 From 1d59716731f3ed8569d60ae84c291bd93eb7d582 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 9 Oct 2008 19:17:44 +0200 Subject: update: job ID must be positive The documentation for directory_update_init() was incorrect: a job ID must be positive, not non-negative. If the update queue is full and no job was created, it makes more sense to return 0 instead of -1, because it is more consistent with the return value of isUpdatingDB(). --- src/update.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/update.h') diff --git a/src/update.h b/src/update.h index 0c0d74416..5c7277e32 100644 --- a/src/update.h +++ b/src/update.h @@ -23,8 +23,8 @@ int isUpdatingDB(void); /* - * returns the non-negative update job ID on success, - * returns -1 if busy + * returns the positive update job ID on success, + * returns 0 if busy * @path will be freed by this function and should not be reused */ int directory_update_init(char *path); -- cgit v1.2.3 From e3ac6a123a442cf9d1f9147b122f21a1f3f1ebb2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 9 Oct 2008 19:20:05 +0200 Subject: update: make the job id unsigned Since the return value cannot be -1 anymore, we can make it unsigned. --- src/update.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/update.h') diff --git a/src/update.h b/src/update.h index 5c7277e32..0842c0df0 100644 --- a/src/update.h +++ b/src/update.h @@ -20,14 +20,14 @@ #ifndef UPDATE_H #define UPDATE_H -int isUpdatingDB(void); +unsigned isUpdatingDB(void); /* * returns the positive update job ID on success, * returns 0 if busy * @path will be freed by this function and should not be reused */ -int directory_update_init(char *path); +unsigned directory_update_init(char *path); void reap_update_task(void); -- cgit v1.2.3