summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-01-26 16:22:28 +0100
committerMax Kellermann <max@musicpd.org>2018-01-26 20:08:01 +0100
commit3ecf5fd442f020e892e4bfb237aac8894d67c391 (patch)
treeda2da6e4a2ec3e9911717c9b3be7ffe0446d4dd4 /test
parent3e9c3c8ae8bd7a661bedbc20f5ba6b86c289fe77 (diff)
test/run_input: add frontend for InputPlugin::scan_tags()
Diffstat (limited to 'test')
-rw-r--r--test/run_input.cxx72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/run_input.cxx b/test/run_input.cxx
index 288df57e6..0933f4f12 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -23,6 +23,9 @@
#include "config/ConfigGlobal.hxx"
#include "input/InputStream.hxx"
#include "input/Init.hxx"
+#include "input/Registry.hxx"
+#include "input/InputPlugin.hxx"
+#include "input/RemoteTagScanner.hxx"
#include "event/Thread.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
@@ -49,16 +52,20 @@ struct CommandLine {
Path config_path = nullptr;
bool verbose = false;
+
+ bool scan = false;
};
enum Option {
OPTION_CONFIG,
OPTION_VERBOSE,
+ OPTION_SCAN,
};
static constexpr OptionDef option_defs[] = {
{"config", 0, true, "Load a MPD configuration file"},
{"verbose", 'v', false, "Verbose logging"},
+ {"scan", 0, false, "Scan tags instead of reading raw data"},
};
static CommandLine
@@ -76,6 +83,10 @@ ParseCommandLine(int argc, char **argv)
case OPTION_VERBOSE:
c.verbose = true;
break;
+
+ case OPTION_SCAN:
+ c.scan = true;
+ break;
}
}
@@ -160,6 +171,64 @@ dump_input_stream(InputStream *is)
return 0;
}
+class DumpRemoteTagHandler final : public RemoteTagHandler {
+ Mutex mutex;
+ Cond cond;
+
+ Tag tag;
+ std::exception_ptr error;
+
+ bool done = false;
+
+public:
+ Tag Wait() {
+ const std::lock_guard<Mutex> lock(mutex);
+ while (!done)
+ cond.wait(mutex);
+
+ if (error)
+ std::rethrow_exception(error);
+
+ return std::move(tag);
+ }
+
+ /* virtual methods from RemoteTagHandler */
+ void OnRemoteTag(Tag &&_tag) noexcept override {
+ const std::lock_guard<Mutex> lock(mutex);
+ tag = std::move(_tag);
+ done = true;
+ cond.broadcast();
+ }
+
+ void OnRemoteTagError(std::exception_ptr e) noexcept override {
+ const std::lock_guard<Mutex> lock(mutex);
+ error = std::move(e);
+ done = true;
+ cond.broadcast();
+ }
+};
+
+static int
+Scan(const char *uri)
+{
+ DumpRemoteTagHandler handler;
+
+ input_plugins_for_each_enabled(plugin) {
+ if (plugin->scan_tags == nullptr)
+ continue;
+
+ auto scanner = plugin->scan_tags(uri, handler);
+ if (scanner) {
+ scanner->Start();
+ tag_save(stdout, handler.Wait());
+ return EXIT_SUCCESS;
+ }
+ }
+
+ fprintf(stderr, "Unsupported URI\n");
+ return EXIT_FAILURE;
+}
+
int main(int argc, char **argv)
try {
const auto c = ParseCommandLine(argc, argv);
@@ -168,6 +237,9 @@ try {
const GlobalInit init(c.config_path, c.verbose);
+ if (c.scan)
+ return Scan(c.uri);
+
/* open the stream and dump it */
Mutex mutex;