diff options
Diffstat (limited to 'test/run_input.cxx')
-rw-r--r-- | test/run_input.cxx | 82 |
1 files changed, 34 insertions, 48 deletions
diff --git a/test/run_input.cxx b/test/run_input.cxx index 3817ed418..6864a5d64 100644 --- a/test/run_input.cxx +++ b/test/run_input.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 @@ -21,69 +21,59 @@ #include "TagSave.hxx" #include "stdbin.h" #include "tag/Tag.hxx" -#include "ConfigGlobal.hxx" -#include "InputStream.hxx" -#include "InputInit.hxx" -#include "IOThread.hxx" +#include "config/ConfigGlobal.hxx" +#include "input/InputStream.hxx" +#include "input/Init.hxx" +#include "ScopeIOThread.hxx" #include "util/Error.hxx" #include "thread/Cond.hxx" #include "Log.hxx" +#include "fs/io/BufferedOutputStream.hxx" +#include "fs/io/StdioOutputStream.hxx" #ifdef ENABLE_ARCHIVE -#include "ArchiveList.hxx" +#include "archive/ArchiveList.hxx" #endif +#ifdef HAVE_GLIB #include <glib.h> +#endif #include <unistd.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) +tag_save(FILE *file, const Tag &tag) { - if (log_domain != NULL) - g_printerr("%s: %s\n", log_domain, message); - else - g_printerr("%s\n", message); + StdioOutputStream sos(file); + BufferedOutputStream bos(sos); + tag_save(bos, tag); + bos.Flush(); } static int dump_input_stream(InputStream *is) { - Error error; - char buffer[4096]; - size_t num_read; - ssize_t num_written; - is->Lock(); - /* wait until the stream becomes ready */ - - is->WaitReady(); - - if (!is->Check(error)) { - LogError(error); - is->Unlock(); - return EXIT_FAILURE; - } - /* print meta data */ - if (!is->mime.empty()) - g_printerr("MIME type: %s\n", is->mime.c_str()); + if (is->HasMimeType()) + fprintf(stderr, "MIME type: %s\n", is->GetMimeType()); /* read data and tags from the stream */ while (!is->IsEOF()) { Tag *tag = is->ReadTag(); if (tag != NULL) { - g_printerr("Received a tag:\n"); + fprintf(stderr, "Received a tag:\n"); tag_save(stderr, *tag); delete tag; } - num_read = is->Read(buffer, sizeof(buffer), error); + Error error; + char buffer[4096]; + size_t num_read = is->Read(buffer, sizeof(buffer), error); if (num_read == 0) { if (error.IsDefined()) LogError(error); @@ -91,11 +81,12 @@ dump_input_stream(InputStream *is) break; } - num_written = write(1, buffer, num_read); + ssize_t num_written = write(1, buffer, num_read); if (num_written <= 0) break; } + Error error; if (!is->Check(error)) { LogError(error); is->Unlock(); @@ -109,34 +100,30 @@ dump_input_stream(InputStream *is) int main(int argc, char **argv) { - Error error; - InputStream *is; - 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(); #endif + Error error; if (!input_stream_global_init(error)) { LogError(error); return 2; @@ -147,16 +134,17 @@ int main(int argc, char **argv) Mutex mutex; Cond cond; - is = InputStream::Open(argv[1], mutex, cond, error); + InputStream *is = InputStream::OpenReady(argv[1], mutex, cond, error); + int ret; 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 */ @@ -167,8 +155,6 @@ int main(int argc, char **argv) archive_plugin_deinit_all(); #endif - io_thread_deinit(); - config_global_finish(); return ret; |