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