diff options
Diffstat (limited to 'test/DumpDatabase.cxx')
-rw-r--r-- | test/DumpDatabase.cxx | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx index 21a12d294..07f342319 100644 --- a/test/DumpDatabase.cxx +++ b/test/DumpDatabase.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,19 +18,24 @@ */ #include "config.h" -#include "DatabaseRegistry.hxx" -#include "DatabasePlugin.hxx" -#include "DatabaseSelection.hxx" -#include "Directory.hxx" -#include "Song.hxx" -#include "PlaylistVector.hxx" -#include "ConfigGlobal.hxx" -#include "ConfigData.hxx" +#include "db/Registry.hxx" +#include "db/DatabasePlugin.hxx" +#include "db/Interface.hxx" +#include "db/Selection.hxx" +#include "db/DatabaseListener.hxx" +#include "db/LightDirectory.hxx" +#include "db/LightSong.hxx" +#include "db/PlaylistVector.hxx" +#include "config/ConfigGlobal.hxx" +#include "config/ConfigData.hxx" #include "tag/TagConfig.hxx" #include "fs/Path.hxx" +#include "event/Loop.hxx" #include "util/Error.hxx" +#ifdef HAVE_GLIB #include <glib.h> +#endif #include <iostream> using std::cout; @@ -39,35 +44,49 @@ using std::endl; #include <stdlib.h> -static void -my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level, - const gchar *message, gcc_unused gpointer user_data) +#ifdef HAVE_LIBUPNP +#include "input/InputStream.hxx" +size_t +InputStream::LockRead(void *, size_t, Error &) { - if (log_domain != NULL) - g_printerr("%s: %s\n", log_domain, message); - else - g_printerr("%s\n", message); + return 0; } +#endif + +class MyDatabaseListener final : public DatabaseListener { +public: + virtual void OnDatabaseModified() override { + cout << "DatabaseModified" << endl; + } + + virtual void OnDatabaseSongRemoved(const LightSong &song) override { + cout << "SongRemoved " << song.GetURI() << endl; + } +}; static bool -DumpDirectory(const Directory &directory, Error &) +DumpDirectory(const LightDirectory &directory, Error &) { - cout << "D " << directory.path << endl; + cout << "D " << directory.GetPath() << endl; return true; } static bool -DumpSong(Song &song, Error &) +DumpSong(const LightSong &song, Error &) { - cout << "S " << song.parent->path << "/" << song.uri << endl; + cout << "S "; + if (song.directory != nullptr) + cout << song.directory << "/"; + cout << song.uri << endl; return true; } static bool DumpPlaylist(const PlaylistInfo &playlist, - const Directory &directory, Error &) + const LightDirectory &directory, Error &) { - cout << "P " << directory.path << "/" << playlist.name.c_str() << endl; + cout << "P " << directory.GetPath() + << "/" << playlist.name.c_str() << endl; return true; } @@ -90,11 +109,11 @@ main(int argc, char **argv) /* initialize GLib */ +#ifdef HAVE_GLIB #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init(nullptr); #endif - - g_log_set_default_handler(my_log_func, nullptr); +#endif /* initialize MPD */ @@ -108,14 +127,18 @@ main(int argc, char **argv) TagLoadConfig(); + EventLoop event_loop; + MyDatabaseListener database_listener; + /* do it */ const struct config_param *path = config_get_param(CONF_DB_FILE); - config_param param("database", path->line); + config_param param("database", path != nullptr ? path->line : -1); if (path != nullptr) param.AddBlockParam("path", path->value.c_str(), path->line); - Database *db = plugin->create(param, error); + Database *db = plugin->create(event_loop, database_listener, + param, error); if (db == nullptr) { cerr << error.GetMessage() << endl; |