From 3078bf3fa53c3d55958e2cbc0301f3c10fa12100 Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Sun, 23 Nov 2003 22:13:14 +0000 Subject: [PATCH] Initial checkin. ProgressListener implementation that writes to standard output. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5464 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/makeudfimage/ConsoleListener.cpp | 57 +++++++++++++++++++ src/apps/bin/makeudfimage/ConsoleListener.h | 32 +++++++++++ 2 files changed, 89 insertions(+) create mode 100644 src/apps/bin/makeudfimage/ConsoleListener.cpp create mode 100644 src/apps/bin/makeudfimage/ConsoleListener.h diff --git a/src/apps/bin/makeudfimage/ConsoleListener.cpp b/src/apps/bin/makeudfimage/ConsoleListener.cpp new file mode 100644 index 0000000000..a6cb14e1cd --- /dev/null +++ b/src/apps/bin/makeudfimage/ConsoleListener.cpp @@ -0,0 +1,57 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +//---------------------------------------------------------------------- + +/*! \file ConsoleListener.cpp + + Console-based implementation of ProgressListener interface. +*/ + +#include "ConsoleListener.h" + +#include + +/*! \brief Creates a new ConsoleListener object with the given verbosity level. + + All output from said listener is sent to standard output via printf(). + + \param level All update messages with verbosity levels below this value + will be ignored. If level is \c VERBOSITY_NONE, no output + whatsoever (including errors and warnings) will be + generated. +*/ +ConsoleListener::ConsoleListener(VerbosityLevel level) + : fLevel(level) +{ +} + +void +ConsoleListener::OnError(const char *message) const +{ + if (Level() > VERBOSITY_NONE) + printf("ERROR: %s\n", message); +} + +void +ConsoleListener::OnWarning(const char *message) const +{ + if (Level() > VERBOSITY_NONE) + printf("WARNING: %s\n", message); +} + +void +ConsoleListener::OnUpdate(VerbosityLevel level, const char *message) const +{ + if (Level() > VERBOSITY_NONE && level <= Level()) + printf("%s\n", message); +} + +void +ConsoleListener::OnCompletion(bool successful, const char *message) const +{ + if (Level() > VERBOSITY_NONE) + printf("%s: %s\n", (successful ? "SUCCESS" : "FAILURE"), message); +} diff --git a/src/apps/bin/makeudfimage/ConsoleListener.h b/src/apps/bin/makeudfimage/ConsoleListener.h new file mode 100644 index 0000000000..9bdd50572c --- /dev/null +++ b/src/apps/bin/makeudfimage/ConsoleListener.h @@ -0,0 +1,32 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +//---------------------------------------------------------------------- + +/*! \file ConsoleListener.h + + Declarations for a console-based implementation of ProgressListener + interface. +*/ + +#ifndef _CONSOLE_LISTENER_H +#define _CONSOLE_LISTENER_H + +#include "ProgressListener.h" + +class ConsoleListener : public ProgressListener { +public: + ConsoleListener(VerbosityLevel level); + virtual void OnError(const char *message) const; + virtual void OnWarning(const char *message) const; + virtual void OnUpdate(VerbosityLevel level, const char *message) const; + virtual void OnCompletion(bool successful, const char *message) const; + + VerbosityLevel Level() const { return fLevel; } +private: + VerbosityLevel fLevel; +}; + +#endif // _CONSOLE_LISTENER_H