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
This commit is contained in:
Tyler Dauwalder 2003-11-23 22:13:14 +00:00
parent eb1cf1f2cc
commit 3078bf3fa5
2 changed files with 89 additions and 0 deletions

View File

@ -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 <stdio.h>
/*! \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);
}

View File

@ -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