From cba1e223768678f6fa6e070d74251b33801414c7 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 3 Jul 2011 04:29:33 +0200 Subject: [PATCH] Move PackageWriterListener to separate file --- src/bin/package/Jamfile | 1 + src/bin/package/PackageWriterListener.cpp | 87 +++++++++++++++++++++++ src/bin/package/PackageWriterListener.h | 41 +++++++++++ src/bin/package/command_create.cpp | 70 +----------------- src/tools/package/Jamfile | 1 + 5 files changed, 131 insertions(+), 69 deletions(-) create mode 100644 src/bin/package/PackageWriterListener.cpp create mode 100644 src/bin/package/PackageWriterListener.h diff --git a/src/bin/package/Jamfile b/src/bin/package/Jamfile index f15ae3f7f3..ec5150666c 100644 --- a/src/bin/package/Jamfile +++ b/src/bin/package/Jamfile @@ -8,6 +8,7 @@ BinCommand package : command_extract.cpp command_list.cpp package.cpp + PackageWriterListener.cpp StandardErrorOutput.cpp : diff --git a/src/bin/package/PackageWriterListener.cpp b/src/bin/package/PackageWriterListener.cpp new file mode 100644 index 0000000000..0ab1374955 --- /dev/null +++ b/src/bin/package/PackageWriterListener.cpp @@ -0,0 +1,87 @@ +/* + * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2011, Oliver Tappe + * Distributed under the terms of the MIT License. + */ + + +#include "PackageWriterListener.h" + +#include + + +using BPackageKit::BHPKG::BPackageWriterListener; +using BPackageKit::BHPKG::BPackageWriter; + + +PackageWriterListener::PackageWriterListener(bool verbose, bool quiet) + : + fVerbose(verbose), fQuiet(quiet) +{ +} + + +void +PackageWriterListener::PrintErrorVarArgs(const char* format, va_list args) +{ + vfprintf(stderr, format, args); +} + + +void +PackageWriterListener::OnEntryAdded(const char* path) +{ + if (fQuiet || !fVerbose) + return; + + printf("\t%s\n", path); +} + + +void +PackageWriterListener::OnTOCSizeInfo(uint64 uncompressedStringsSize, + uint64 uncompressedMainSize, uint64 uncompressedTOCSize) +{ + if (fQuiet || !fVerbose) + return; + + printf("----- TOC Info -----------------------------------\n"); + printf("cached strings size: %10" B_PRIu64 " (uncompressed)\n", + uncompressedStringsSize); + printf("TOC main size: %10" B_PRIu64 " (uncompressed)\n", + uncompressedMainSize); + printf("total TOC size: %10" B_PRIu64 " (uncompressed)\n", + uncompressedTOCSize); +} + + +void +PackageWriterListener::OnPackageAttributesSizeInfo(uint32 stringCount, + uint32 uncompressedSize) +{ + if (fQuiet || !fVerbose) + return; + + printf("----- Package Attribute Info ---------------------\n"); + printf("string count: %10" B_PRIu32 "\n", stringCount); + printf("package attributes size: %10" B_PRIu32 " (uncompressed)\n", + uncompressedSize); +} + + +void +PackageWriterListener::OnPackageSizeInfo(uint32 headerSize, uint64 heapSize, + uint64 tocSize, uint32 packageAttributesSize, uint64 totalSize) +{ + if (fQuiet) + return; + + printf("----- Package Info ----------------\n"); + printf("header size: %10" B_PRIu32 "\n", headerSize); + printf("heap size: %10" B_PRIu64 "\n", heapSize); + printf("TOC size: %10" B_PRIu64 "\n", tocSize); + printf("package attributes size: %10" B_PRIu32 "\n", + packageAttributesSize); + printf("total size: %10" B_PRIu64 "\n", totalSize); + printf("-----------------------------------\n"); +} diff --git a/src/bin/package/PackageWriterListener.h b/src/bin/package/PackageWriterListener.h new file mode 100644 index 0000000000..efe57817e3 --- /dev/null +++ b/src/bin/package/PackageWriterListener.h @@ -0,0 +1,41 @@ +/* + * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2011, Oliver Tappe + * Distributed under the terms of the MIT License. + */ +#ifndef PACKAGE_WRITER_LISTENER_H +#define PACKAGE_WRITER_LISTENER_H + + +#include + + +using BPackageKit::BHPKG::BPackageWriterListener; +using BPackageKit::BHPKG::BPackageWriter; + + +class PackageWriterListener : public BPackageWriterListener { +public: + PackageWriterListener(bool verbose, bool quiet); + + virtual void PrintErrorVarArgs(const char* format, + va_list args); + + virtual void OnEntryAdded(const char* path); + virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize, + uint64 uncompressedMainSize, + uint64 uncompressedTOCSize); + virtual void OnPackageAttributesSizeInfo(uint32 stringCount, + uint32 uncompressedSize); + virtual void OnPackageSizeInfo(uint32 headerSize, + uint64 heapSize, uint64 tocSize, + uint32 packageAttributesSize, + uint64 totalSize); + +private: + bool fVerbose; + bool fQuiet; +}; + + +#endif // PACKAGE_WRITER_LISTENER_H diff --git a/src/bin/package/command_create.cpp b/src/bin/package/command_create.cpp index 7e7af90676..23d7fe97dd 100644 --- a/src/bin/package/command_create.cpp +++ b/src/bin/package/command_create.cpp @@ -21,6 +21,7 @@ #include #include "package.h" +#include "PackageWriterListener.h" #include "StandardErrorOutput.h" @@ -28,75 +29,6 @@ using BPackageKit::BHPKG::BPackageWriterListener; using BPackageKit::BHPKG::BPackageWriter; -class PackageWriterListener : public BPackageWriterListener { -public: - PackageWriterListener(bool verbose, bool quiet) - : fVerbose(verbose), fQuiet(quiet) - { - } - - virtual void PrintErrorVarArgs(const char* format, va_list args) - { - vfprintf(stderr, format, args); - } - - virtual void OnEntryAdded(const char* path) - { - if (fQuiet || !fVerbose) - return; - - printf("\t%s\n", path); - } - - virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize, - uint64 uncompressedMainSize, uint64 uncompressedTOCSize) - { - if (fQuiet || !fVerbose) - return; - - printf("----- TOC Info -----------------------------------\n"); - printf("cached strings size: %10" B_PRIu64 " (uncompressed)\n", - uncompressedStringsSize); - printf("TOC main size: %10" B_PRIu64 " (uncompressed)\n", - uncompressedMainSize); - printf("total TOC size: %10" B_PRIu64 " (uncompressed)\n", - uncompressedTOCSize); - } - - virtual void OnPackageAttributesSizeInfo(uint32 stringCount, - uint32 uncompressedSize) - { - if (fQuiet || !fVerbose) - return; - - printf("----- Package Attribute Info ---------------------\n"); - printf("string count: %10" B_PRIu32 "\n", stringCount); - printf("package attributes size: %10" B_PRIu32 " (uncompressed)\n", - uncompressedSize); - } - - virtual void OnPackageSizeInfo(uint32 headerSize, uint64 heapSize, - uint64 tocSize, uint32 packageAttributesSize, uint64 totalSize) - { - if (fQuiet) - return; - - printf("----- Package Info ----------------\n"); - printf("header size: %10" B_PRIu32 "\n", headerSize); - printf("heap size: %10" B_PRIu64 "\n", heapSize); - printf("TOC size: %10" B_PRIu64 "\n", tocSize); - printf("package attributes size: %10" B_PRIu32 "\n", - packageAttributesSize); - printf("total size: %10" B_PRIu64 "\n", totalSize); - printf("-----------------------------------\n"); - } - -private: - bool fVerbose; - bool fQuiet; -}; - - int command_create(int argc, const char* const* argv) { diff --git a/src/tools/package/Jamfile b/src/tools/package/Jamfile index 92baf1fe33..650ad04910 100644 --- a/src/tools/package/Jamfile +++ b/src/tools/package/Jamfile @@ -12,6 +12,7 @@ BuildPlatformMain package : command_extract.cpp command_list.cpp package.cpp + PackageWriterListener.cpp StandardErrorOutput.cpp :