test/run_input: add frontend for InputPlugin::scan_tags()
This commit is contained in:
parent
3e9c3c8ae8
commit
3ecf5fd442
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user