aboutsummaryrefslogtreecommitdiffstats
path: root/test/dump_text_file.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/dump_text_file.cxx71
1 files changed, 22 insertions, 49 deletions
diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx
index bb84f5cce..5bfd316a5 100644
--- a/test/dump_text_file.cxx
+++ b/test/dump_text_file.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 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,64 +18,39 @@
*/
#include "config.h"
-#include "IOThread.hxx"
-#include "InputInit.hxx"
-#include "InputStream.hxx"
-#include "ConfigGlobal.hxx"
+#include "ScopeIOThread.hxx"
+#include "input/Init.hxx"
+#include "input/InputStream.hxx"
+#include "input/TextInputStream.hxx"
+#include "config/ConfigGlobal.hxx"
#include "stdbin.h"
-#include "TextInputStream.hxx"
#include "util/Error.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
#ifdef ENABLE_ARCHIVE
-#include "ArchiveList.hxx"
+#include "archive/ArchiveList.hxx"
#endif
+#ifdef HAVE_GLIB
#include <glib.h>
+#endif
#include <unistd.h>
#include <stdio.h>
#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)
-{
- if (log_domain != NULL)
- g_printerr("%s: %s\n", log_domain, message);
- else
- g_printerr("%s\n", message);
-}
-
-static void
dump_text_file(TextInputStream &is)
{
- std::string line;
- while (is.ReadLine(line))
- printf("'%s'\n", line.c_str());
+ const char *line;
+ while ((line = is.ReadLine()) != nullptr)
+ printf("'%s'\n", line);
}
static int
dump_input_stream(InputStream &is)
{
- Error error;
-
- is.Lock();
-
- /* wait until the stream becomes ready */
-
- is.WaitReady();
-
- if (!is.Check(error)) {
- LogError(error);
- is.Unlock();
- return EXIT_FAILURE;
- }
-
- /* read data and tags from the stream */
-
- is.Unlock();
{
TextInputStream tis(is);
dump_text_file(tis);
@@ -83,6 +58,7 @@ dump_input_stream(InputStream &is)
is.Lock();
+ Error error;
if (!is.Check(error)) {
LogError(error);
is.Unlock();
@@ -99,24 +75,23 @@ int main(int argc, char **argv)
int ret;
if (argc != 2) {
- g_printerr("Usage: run_input URI\n");
- return 1;
+ fprintf(stderr, "Usage: run_input URI\n");
+ return EXIT_FAILURE;
}
/* initialize GLib */
+#ifdef HAVE_GLIB
#if !GLIB_CHECK_VERSION(2,32,0)
g_thread_init(NULL);
#endif
-
- g_log_set_default_handler(my_log_func, NULL);
+#endif
/* initialize MPD */
config_global_init();
- io_thread_init();
- io_thread_start();
+ const ScopeIOThread io_thread;
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all();
@@ -133,16 +108,16 @@ int main(int argc, char **argv)
Mutex mutex;
Cond cond;
- InputStream *is = InputStream::Open(argv[1], mutex, cond, error);
+ InputStream *is = InputStream::OpenReady(argv[1], mutex, cond, error);
if (is != NULL) {
ret = dump_input_stream(*is);
- is->Close();
+ delete is;
} else {
if (error.IsDefined())
LogError(error);
else
- g_printerr("input_stream::Open() failed\n");
- ret = 2;
+ fprintf(stderr, "input_stream::Open() failed\n");
+ ret = EXIT_FAILURE;
}
/* deinitialize everything */
@@ -153,8 +128,6 @@ int main(int argc, char **argv)
archive_plugin_deinit_all();
#endif
- io_thread_deinit();
-
config_global_finish();
return ret;