Initial checkin. Main udf image building class.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5461 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,114 @@
|
|||||||
|
//----------------------------------------------------------------------
|
||||||
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
|
// by the OpenBeOS license.
|
||||||
|
//
|
||||||
|
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! \file UdfBuilder.cpp
|
||||||
|
|
||||||
|
Main UDF image building class implementation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UdfBuilder.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "Debug.h"
|
||||||
|
|
||||||
|
UdfBuilder::UdfBuilder(const ProgressListener &listener)
|
||||||
|
: fListener(listener)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
UdfBuilder::InitCheck() const
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
UdfBuilder::Build() const
|
||||||
|
{
|
||||||
|
DEBUG_INIT("UdfBuilder");
|
||||||
|
_PrintError("This is an error.");
|
||||||
|
_PrintWarning("This is a warning.");
|
||||||
|
_PrintUpdate(VERBOSITY_LOW, "This is a VERBOSITY_LOW update.");
|
||||||
|
_PrintUpdate(VERBOSITY_HIGH, "This is a VERBOSITY_HIGH update.");
|
||||||
|
RETURN(B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Uses vsprintf() to output the given format string and arguments
|
||||||
|
into the given message string.
|
||||||
|
|
||||||
|
va_start() must be called prior to calling this function to obtain the
|
||||||
|
\a arguments parameter, but va_end() must *not* be called upon return,
|
||||||
|
as this function takes the liberty of doing so for you.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
UdfBuilder::_FormatString(char *message, const char *formatString, va_list arguments) const
|
||||||
|
{
|
||||||
|
status_t error = message && formatString ? B_OK : B_BAD_VALUE;
|
||||||
|
if (!error) {
|
||||||
|
vsprintf(message, formatString, arguments);
|
||||||
|
va_end(arguments);
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Outputs a printf()-style error message to the listener.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
UdfBuilder::_PrintError(const char *formatString, ...) const
|
||||||
|
{
|
||||||
|
if (!formatString) {
|
||||||
|
DEBUG_INIT_ETC("UdfBuilder", ("formatString: `%s'", formatString));
|
||||||
|
PRINT(("ERROR: _PrintError() called with NULL format string!\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char message[kMaxUpdateStringLength];
|
||||||
|
va_list arguments;
|
||||||
|
va_start(arguments, formatString);
|
||||||
|
status_t error = _FormatString(message, formatString, arguments);
|
||||||
|
if (!error)
|
||||||
|
fListener.OnError(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Outputs a printf()-style warning message to the listener.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
UdfBuilder::_PrintWarning(const char *formatString, ...) const
|
||||||
|
{
|
||||||
|
if (!formatString) {
|
||||||
|
DEBUG_INIT_ETC("UdfBuilder", ("formatString: `%s'", formatString));
|
||||||
|
PRINT(("ERROR: _PrintWarning() called with NULL format string!\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char message[kMaxUpdateStringLength];
|
||||||
|
va_list arguments;
|
||||||
|
va_start(arguments, formatString);
|
||||||
|
status_t error = _FormatString(message, formatString, arguments);
|
||||||
|
if (!error)
|
||||||
|
fListener.OnWarning(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Outputs a printf()-style update message to the listener
|
||||||
|
at the given verbosity level.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
UdfBuilder::_PrintUpdate(VerbosityLevel level, const char *formatString, ...) const
|
||||||
|
{
|
||||||
|
if (!formatString) {
|
||||||
|
DEBUG_INIT_ETC("UdfBuilder", ("level: %d, formatString: `%s'",
|
||||||
|
level, formatString));
|
||||||
|
PRINT(("ERROR: _PrintUpdate() called with NULL format string!\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char message[kMaxUpdateStringLength];
|
||||||
|
va_list arguments;
|
||||||
|
va_start(arguments, formatString);
|
||||||
|
status_t error = _FormatString(message, formatString, arguments);
|
||||||
|
if (!error)
|
||||||
|
fListener.OnUpdate(level, message);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
//----------------------------------------------------------------------
|
||||||
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
|
// by the OpenBeOS license.
|
||||||
|
//
|
||||||
|
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! \file UdfBuilder.h
|
||||||
|
|
||||||
|
Main UDF image building class interface declarations.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _UDF_BUILDER_H
|
||||||
|
#define _UDF_BUILDER_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
#include "ProgressListener.h"
|
||||||
|
|
||||||
|
class UdfBuilder {
|
||||||
|
public:
|
||||||
|
UdfBuilder(const ProgressListener &listener);
|
||||||
|
status_t InitCheck() const;
|
||||||
|
status_t Build() const;
|
||||||
|
private:
|
||||||
|
//! Maximum length of string generated by calls to any _Print*() functions
|
||||||
|
static const int kMaxUpdateStringLength = 1024;
|
||||||
|
|
||||||
|
status_t _FormatString(char *message, const char *formatString, va_list arguments) const;
|
||||||
|
void _PrintError(const char *formatString, ...) const;
|
||||||
|
void _PrintWarning(const char *formatString, ...) const;
|
||||||
|
void _PrintUpdate(VerbosityLevel level, const char *formatString, ...) const;
|
||||||
|
|
||||||
|
const ProgressListener &fListener;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _UDF_BUILDER_H
|
||||||
Reference in New Issue
Block a user