aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile.am4
-rw-r--r--src/DatabasePrint.cxx8
-rw-r--r--src/DatabaseVisitor.hxx4
-rw-r--r--src/Directory.cxx2
-rw-r--r--src/PlaylistDatabase.cxx9
-rw-r--r--src/PlaylistInfo.cxx46
-rw-r--r--src/PlaylistInfo.hxx17
-rw-r--r--src/PlaylistVector.cxx30
-rw-r--r--src/PlaylistVector.hxx8
-rw-r--r--src/UpdateWalk.cxx13
-rw-r--r--src/db/ProxyDatabasePlugin.cxx10
-rw-r--r--test/DumpDatabase.cxx4
12 files changed, 53 insertions, 102 deletions
diff --git a/Makefile.am b/Makefile.am
index 28d39cfe7..c5379a31e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -303,7 +303,7 @@ src_mpd_SOURCES = \
src/PlaylistState.cxx src/PlaylistState.hxx \
src/PlaylistQueue.cxx src/PlaylistQueue.hxx \
src/PlaylistVector.cxx src/PlaylistVector.hxx \
- src/PlaylistInfo.cxx src/PlaylistInfo.hxx \
+ src/PlaylistInfo.hxx \
src/PlaylistDatabase.cxx \
src/queue.c \
src/QueuePrint.cxx src/QueuePrint.hxx \
@@ -1072,7 +1072,7 @@ test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \
src/DatabaseRegistry.cxx \
src/DatabaseSelection.cxx \
src/Directory.cxx src/DirectorySave.cxx \
- src/PlaylistVector.cxx src/PlaylistInfo.cxx src/PlaylistDatabase.cxx \
+ src/PlaylistVector.cxx src/PlaylistDatabase.cxx \
src/DatabaseLock.cxx src/DatabaseSave.cxx \
src/Song.cxx src/song_sort.c src/SongSave.cxx \
src/tag.c src/tag_pool.c src/TagSave.cxx \
diff --git a/src/DatabasePrint.cxx b/src/DatabasePrint.cxx
index 87e41be8e..1e2842091 100644
--- a/src/DatabasePrint.cxx
+++ b/src/DatabasePrint.cxx
@@ -91,19 +91,19 @@ PrintSongFull(struct client *client, song &song)
static bool
PrintPlaylistBrief(struct client *client,
- const playlist_metadata &playlist,
+ const PlaylistInfo &playlist,
const directory &directory)
{
- print_playlist_in_directory(client, directory, playlist.name);
+ print_playlist_in_directory(client, directory, playlist.name.c_str());
return true;
}
static bool
PrintPlaylistFull(struct client *client,
- const playlist_metadata &playlist,
+ const PlaylistInfo &playlist,
const directory &directory)
{
- print_playlist_in_directory(client, directory, playlist.name);
+ print_playlist_in_directory(client, directory, playlist.name.c_str());
if (playlist.mtime > 0)
time_print(client, "Last-Modified", playlist.mtime);
diff --git a/src/DatabaseVisitor.hxx b/src/DatabaseVisitor.hxx
index 10f907cef..c10deae19 100644
--- a/src/DatabaseVisitor.hxx
+++ b/src/DatabaseVisitor.hxx
@@ -26,11 +26,11 @@
struct directory;
struct song;
-struct playlist_metadata;
+struct PlaylistInfo;
typedef std::function<bool(const directory &, GError **)> VisitDirectory;
typedef std::function<bool(struct song &, GError **)> VisitSong;
-typedef std::function<bool(const playlist_metadata &, const directory &,
+typedef std::function<bool(const PlaylistInfo &, const directory &,
GError **)> VisitPlaylist;
typedef std::function<bool(const char *, GError **)> VisitString;
diff --git a/src/Directory.cxx b/src/Directory.cxx
index 59859a0fd..84545e54f 100644
--- a/src/Directory.cxx
+++ b/src/Directory.cxx
@@ -307,7 +307,7 @@ directory::Walk(bool recursive, const SongFilter *filter,
}
if (visit_playlist) {
- struct playlist_metadata *i;
+ PlaylistInfo *i;
directory_for_each_playlist(i, this)
if (!visit_playlist(*i, *this, error_r))
return false;
diff --git a/src/PlaylistDatabase.cxx b/src/PlaylistDatabase.cxx
index a2062a517..bbfdf7481 100644
--- a/src/PlaylistDatabase.cxx
+++ b/src/PlaylistDatabase.cxx
@@ -38,20 +38,19 @@ playlist_database_quark(void)
void
playlist_vector_save(FILE *fp, const struct list_head *pv)
{
- struct playlist_metadata *pm;
+ PlaylistInfo *pm;
playlist_vector_for_each(pm, pv)
fprintf(fp, PLAYLIST_META_BEGIN "%s\n"
"mtime: %li\n"
"playlist_end\n",
- pm->name, (long)pm->mtime);
+ pm->name.c_str(), (long)pm->mtime);
}
bool
playlist_metadata_load(FILE *fp, struct list_head *pv, const char *name,
GString *buffer, GError **error_r)
{
- struct playlist_metadata pm;
- pm.mtime = 0;
+ PlaylistInfo pm(name, 0);
char *line, *colon;
const char *value;
@@ -77,6 +76,6 @@ playlist_metadata_load(FILE *fp, struct list_head *pv, const char *name,
}
}
- playlist_vector_update_or_add(pv, name, pm.mtime);
+ playlist_vector_update_or_add(pv, std::move(pm));
return true;
}
diff --git a/src/PlaylistInfo.cxx b/src/PlaylistInfo.cxx
deleted file mode 100644
index 392178795..000000000
--- a/src/PlaylistInfo.cxx
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
- * 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "config.h"
-#include "PlaylistInfo.hxx"
-
-#include <glib.h>
-
-#include <assert.h>
-
-struct playlist_metadata *
-playlist_metadata_new(const char *name, time_t mtime)
-{
- assert(name != NULL);
-
- struct playlist_metadata *pm = g_slice_new(struct playlist_metadata);
- pm->name = g_strdup(name);
- pm->mtime = mtime;
- return pm;
-}
-
-void
-playlist_metadata_free(struct playlist_metadata *pm)
-{
- assert(pm != NULL);
- assert(pm->name != NULL);
-
- g_free(pm->name);
- g_slice_free(struct playlist_metadata, pm);
-}
diff --git a/src/PlaylistInfo.hxx b/src/PlaylistInfo.hxx
index 2d21178ed..fffafd819 100644
--- a/src/PlaylistInfo.hxx
+++ b/src/PlaylistInfo.hxx
@@ -23,26 +23,29 @@
#include "check.h"
#include "util/list.h"
+#include <string>
+
#include <sys/time.h>
/**
* A directory entry pointing to a playlist file.
*/
-struct playlist_metadata {
+struct PlaylistInfo {
struct list_head siblings;
/**
* The UTF-8 encoded name of the playlist file.
*/
- char *name;
+ std::string name;
time_t mtime;
-};
-struct playlist_metadata *
-playlist_metadata_new(const char *name, time_t mtime);
+ template<typename N>
+ PlaylistInfo(N &&_name, time_t _mtime)
+ :name(std::forward<N>(_name)), mtime(_mtime) {}
-void
-playlist_metadata_free(struct playlist_metadata *pm);
+ PlaylistInfo(const PlaylistInfo &other) = delete;
+ PlaylistInfo(PlaylistInfo &&) = default;
+};
#endif
diff --git a/src/PlaylistVector.cxx b/src/PlaylistVector.cxx
index 726a69337..f1f13567f 100644
--- a/src/PlaylistVector.cxx
+++ b/src/PlaylistVector.cxx
@@ -30,50 +30,48 @@ playlist_vector_deinit(struct list_head *pv)
{
assert(pv != NULL);
- struct playlist_metadata *pm, *n;
+ PlaylistInfo *pm, *n;
playlist_vector_for_each_safe(pm, n, pv)
- playlist_metadata_free(pm);
+ delete pm;
}
-struct playlist_metadata *
+PlaylistInfo *
playlist_vector_find(struct list_head *pv, const char *name)
{
assert(holding_db_lock());
assert(pv != NULL);
assert(name != NULL);
- struct playlist_metadata *pm;
+ PlaylistInfo *pm;
playlist_vector_for_each(pm, pv)
- if (strcmp(pm->name, name) == 0)
+ if (pm->name.compare(name) == 0)
return pm;
return NULL;
}
void
-playlist_vector_add(struct list_head *pv,
- const char *name, time_t mtime)
+playlist_vector_add(struct list_head *pv, PlaylistInfo &&pi)
{
assert(holding_db_lock());
- struct playlist_metadata *pm = playlist_metadata_new(name, mtime);
+ PlaylistInfo *pm = new PlaylistInfo(std::move(pi));
list_add_tail(&pm->siblings, pv);
}
bool
-playlist_vector_update_or_add(struct list_head *pv,
- const char *name, time_t mtime)
+playlist_vector_update_or_add(struct list_head *pv, PlaylistInfo &&pi)
{
assert(holding_db_lock());
- struct playlist_metadata *pm = playlist_vector_find(pv, name);
+ PlaylistInfo *pm = playlist_vector_find(pv, pi.name.c_str());
if (pm != NULL) {
- if (mtime == pm->mtime)
+ if (pi.mtime == pm->mtime)
return false;
- pm->mtime = mtime;
+ pm->mtime = pi.mtime;
} else
- playlist_vector_add(pv, name, mtime);
+ playlist_vector_add(pv, std::move(pi));
return true;
}
@@ -83,11 +81,11 @@ playlist_vector_remove(struct list_head *pv, const char *name)
{
assert(holding_db_lock());
- struct playlist_metadata *pm = playlist_vector_find(pv, name);
+ PlaylistInfo *pm = playlist_vector_find(pv, name);
if (pm == NULL)
return false;
list_del(&pm->siblings);
- playlist_metadata_free(pm);
+ delete pm;
return true;
}
diff --git a/src/PlaylistVector.hxx b/src/PlaylistVector.hxx
index 30418131a..14445315c 100644
--- a/src/PlaylistVector.hxx
+++ b/src/PlaylistVector.hxx
@@ -37,15 +37,14 @@ playlist_vector_deinit(struct list_head *pv);
/**
* Caller must lock the #db_mutex.
*/
-struct playlist_metadata *
+PlaylistInfo *
playlist_vector_find(struct list_head *pv, const char *name);
/**
* Caller must lock the #db_mutex.
*/
void
-playlist_vector_add(struct list_head *pv,
- const char *name, time_t mtime);
+playlist_vector_add(struct list_head *pv, PlaylistInfo &&pi);
/**
* Caller must lock the #db_mutex.
@@ -53,8 +52,7 @@ playlist_vector_add(struct list_head *pv,
* @return true if the vector or one of its items was modified
*/
bool
-playlist_vector_update_or_add(struct list_head *pv,
- const char *name, time_t mtime);
+playlist_vector_update_or_add(struct list_head *pv, PlaylistInfo &&pi);
/**
* Caller must lock the #db_mutex.
diff --git a/src/UpdateWalk.cxx b/src/UpdateWalk.cxx
index 860342001..a34e0028d 100644
--- a/src/UpdateWalk.cxx
+++ b/src/UpdateWalk.cxx
@@ -159,11 +159,12 @@ purge_deleted_from_directory(struct directory *directory)
g_free(path);
}
- struct playlist_metadata *pm, *np;
+ PlaylistInfo *pm, *np;
directory_for_each_playlist_safe(pm, np, directory) {
- if (!directory_child_is_regular(directory, pm->name)) {
+ if (!directory_child_is_regular(directory, pm->name.c_str())) {
db_lock();
- playlist_vector_remove(&directory->playlists, pm->name);
+ playlist_vector_remove(&directory->playlists,
+ pm->name.c_str());
db_unlock();
}
}
@@ -214,9 +215,11 @@ update_playlist_file2(struct directory *directory,
if (!playlist_suffix_supported(suffix))
return false;
+ PlaylistInfo pi(name, st->st_mtime);
+
db_lock();
- if (playlist_vector_update_or_add(&directory->playlists, name,
- st->st_mtime))
+ if (playlist_vector_update_or_add(&directory->playlists,
+ std::move(pi)))
modified = true;
db_unlock();
return true;
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx
index db8e56dda..01b36a6e3 100644
--- a/src/db/ProxyDatabasePlugin.cxx
+++ b/src/db/ProxyDatabasePlugin.cxx
@@ -314,14 +314,10 @@ Visit(const struct mpd_playlist *playlist,
if (!visit_playlist)
return true;
- struct playlist_metadata p;
- p.name = g_strdup(mpd_playlist_get_path(playlist));
- p.mtime = mpd_playlist_get_last_modified(playlist);
+ PlaylistInfo p(mpd_playlist_get_path(playlist),
+ mpd_playlist_get_last_modified(playlist));
- bool success = visit_playlist(p, detached_root, error_r);
- g_free(p.name);
-
- return success;
+ return visit_playlist(p, detached_root, error_r);
}
class ProxyEntity {
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
index f262a9808..fc42ba147 100644
--- a/test/DumpDatabase.cxx
+++ b/test/DumpDatabase.cxx
@@ -62,10 +62,10 @@ DumpSong(song &song, GError **)
}
static bool
-DumpPlaylist(const playlist_metadata &playlist,
+DumpPlaylist(const PlaylistInfo &playlist,
const directory &directory, GError **)
{
- cout << "P " << directory.path << "/" << playlist.name << endl;
+ cout << "P " << directory.path << "/" << playlist.name.c_str() << endl;
return true;
}