1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the OpenBeOS license.
5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //----------------------------------------------------------------------
8 /*! \file ConsoleListener.cpp
10 Console-based implementation of ProgressListener interface.
13 #include "ConsoleListener.h"
18 static const char * const kDivider
=
19 "----------------------------------------------------------------------";
21 /*! \brief Creates a new ConsoleListener object with the given verbosity level.
23 All output from said listener is sent to standard output via printf().
25 \param level All update messages with verbosity levels below this value
26 will be ignored. If level is \c VERBOSITY_NONE, no output
27 whatsoever (including errors and warnings) will be
30 ConsoleListener::ConsoleListener(VerbosityLevel level
)
36 ConsoleListener::OnStart(const char *sourceDirectory
, const char *outputFile
,
37 const char *udfVolumeName
, uint16 udfRevision
) const
39 if (Level() > VERBOSITY_NONE
) {
40 printf("%s\n", kDivider
);
41 printf("Source directory: `%s'\n", sourceDirectory
);
42 printf("Output file: `%s'\n", outputFile
);
43 printf("UDF Volume Name: `%s'\n", udfVolumeName
);
44 printf("UDF Revision: %01x.%01x%01x\n",
45 (udfRevision
& 0x0f00) >> 8,
46 (udfRevision
& 0x00f0) >> 4,
47 (udfRevision
& 0x000f));
48 printf("%s\n", kDivider
);
53 ConsoleListener::OnError(const char *message
) const
55 if (Level() > VERBOSITY_NONE
)
56 printf("ERROR: %s\n", message
);
60 ConsoleListener::OnWarning(const char *message
) const
62 if (Level() > VERBOSITY_NONE
)
63 printf("WARNING: %s\n", message
);
67 ConsoleListener::OnUpdate(VerbosityLevel level
, const char *message
) const
69 if (Level() > VERBOSITY_NONE
&& level
<= Level()) {
71 case VERBOSITY_MEDIUM
:
80 printf("%s\n", message
);
85 ConsoleListener::OnCompletion(status_t result
, const Statistics
&statistics
) const
87 if (Level() > VERBOSITY_NONE
) {
89 uint64 directories
= statistics
.Directories();
90 uint64 files
= statistics
.Files();
91 uint64 symlinks
= statistics
.Symlinks();
93 printf("- Build time: %s\n", statistics
.ElapsedTimeString().c_str());
94 printf("- Directories: %Ld director%s in %s\n",
95 directories
, directories
== 1 ? "y" : "ies",
96 statistics
.DirectoryBytesString().c_str());
97 printf("- Files: %Ld file%s in %s\n",
98 files
, files
== 1 ? "" : "s",
99 statistics
.FileBytesString().c_str());
101 printf("- Symlinks: No symlink support yet; %Ld symlink%s ommitted\n", symlinks
,
102 symlinks
== 1 ? "" : "s");
103 printf("- Image size: %s\n", statistics
.ImageSizeString().c_str());
105 printf("----------------------------------------------------------------------\n");
106 printf("Build failed with error: 0x%lx, `%s'\n", result
,
108 printf("----------------------------------------------------------------------\n");