1//---------------------------------------------------------------------- 2// This software is part of the OpenBeOS distribution and is covered 3// by the OpenBeOS license. 4// 5// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net 6//---------------------------------------------------------------------- 7 8/*! \file ConsoleListener.cpp 9 10 Console-based implementation of ProgressListener interface. 11*/ 12 13#include "ConsoleListener.h" 14 15#include <stdio.h> 16#include <string.h> 17 18static const char * const kDivider = 19 "----------------------------------------------------------------------"; 20 21/*! \brief Creates a new ConsoleListener object with the given verbosity level. 22 23 All output from said listener is sent to standard output via printf(). 24 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 28 generated. 29*/ 30ConsoleListener::ConsoleListener(VerbosityLevel level) 31 : fLevel(level) 32{ 33} 34 35void 36ConsoleListener::OnStart(const char *sourceDirectory, const char *outputFile, 37 const char *udfVolumeName, uint16 udfRevision) const 38{ 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); 49 } 50} 51 52void 53ConsoleListener::OnError(const char *message) const 54{ 55 if (Level() > VERBOSITY_NONE) 56 printf("ERROR: %s\n", message); 57} 58 59void 60ConsoleListener::OnWarning(const char *message) const 61{ 62 if (Level() > VERBOSITY_NONE) 63 printf("WARNING: %s\n", message); 64} 65 66void 67ConsoleListener::OnUpdate(VerbosityLevel level, const char *message) const 68{ 69 if (Level() > VERBOSITY_NONE && level <= Level()) { 70 switch (level) { 71 case VERBOSITY_MEDIUM: 72 printf(" "); 73 break; 74 case VERBOSITY_HIGH: 75 printf(" "); 76 break; 77 default: 78 break; 79 } 80 printf("%s\n", message); 81 } 82} 83 84void 85ConsoleListener::OnCompletion(status_t result, const Statistics &statistics) const 86{ 87 if (Level() > VERBOSITY_NONE) { 88 if (result == B_OK) { 89 uint64 directories = statistics.Directories(); 90 uint64 files = statistics.Files(); 91 uint64 symlinks = statistics.Symlinks(); 92 printf("Finished\n"); 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()); 100 if (symlinks > 0) 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()); 104 } else { 105 printf("----------------------------------------------------------------------\n"); 106 printf("Build failed with error: 0x%lx, `%s'\n", result, 107 strerror(result)); 108 printf("----------------------------------------------------------------------\n"); 109 } 110 } 111} 112