Author: jkupec Date: Mon May 28 16:17:38 2007 New Revision: 5636 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5636&view=rev Log: Hiding YUMParser implementation. Added: trunk/libzypp/devel/devel.jkupec/bridge/ trunk/libzypp/devel/devel.jkupec/bridge/Base.h trunk/libzypp/devel/devel.jkupec/bridge/BaseImpl.cc trunk/libzypp/devel/devel.jkupec/bridge/BaseImpl.h trunk/libzypp/devel/devel.jkupec/bridge/Derived.cc trunk/libzypp/devel/devel.jkupec/bridge/Derived.h trunk/libzypp/devel/devel.jkupec/bridge/bridge.cc trunk/libzypp/zypp/parser/yum/FileReaderBaseImpl.cc trunk/libzypp/zypp/parser/yum/FileReaderBaseImpl.h Removed: trunk/libzypp/zypp/parser/yum/FileReaderBase.cc Modified: trunk/libzypp/devel/devel.jkupec/CMakeLists.txt trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc trunk/libzypp/devel/devel.jkupec/yum/products-example.xml trunk/libzypp/zypp/CMakeLists.txt trunk/libzypp/zypp/parser/yum/FileReaderBase.h trunk/libzypp/zypp/parser/yum/PatchFileReader.cc trunk/libzypp/zypp/parser/yum/PatchFileReader.h trunk/libzypp/zypp/parser/yum/PatternFileReader.cc trunk/libzypp/zypp/parser/yum/PatternFileReader.h trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h trunk/libzypp/zypp/parser/yum/ProductFileReader.cc trunk/libzypp/zypp/parser/yum/ProductFileReader.h trunk/libzypp/zypp2/parser/yum/YUMParser.cc trunk/libzypp/zypp2/parser/yum/YUMParser.h Modified: trunk/libzypp/devel/devel.jkupec/CMakeLists.txt URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/CMakeL... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/CMakeLists.txt (original) +++ trunk/libzypp/devel/devel.jkupec/CMakeLists.txt Mon May 28 16:17:38 2007 @@ -5,5 +5,23 @@ #ADD_EXECUTABLE(sourcedownload sourcedownload.cc) #TARGET_LINK_LIBRARIES(sourcedownload zypp zypp2) + + +SET( bridge_SRCS + bridge/bridge.cc + bridge/BaseImpl.cc + bridge/Derived.cc +) + +SET( bridge_HEADERS + bridge/Base.h + bridge/BaseImpl.h + bridge/Derived.h +) + ADD_EXECUTABLE( yumparsertest YUMParser_test.cc ) TARGET_LINK_LIBRARIES(yumparsertest zypp zypp2) + +ADD_EXECUTABLE( bridge ${bridge_SRCS} ) +TARGET_LINK_LIBRARIES( bridge zypp zypp2) + Modified: trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/YUMPar... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc (original) +++ trunk/libzypp/devel/devel.jkupec/YUMParser_test.cc Mon May 28 16:17:38 2007 @@ -6,7 +6,6 @@ #include "zypp2/cache/CacheStore.h" #include "zypp2/parser/yum/YUMParser.h" - #undef ZYPP_BASE_LOGGER_LOGGROUP #define ZYPP_BASE_LOGGER_LOGGROUP "yumparsertest" @@ -47,7 +46,8 @@ Measure parse_primary_timer("primary.xml.gz parsing"); parser::yum::YUMParser parser( repository_id, store, &progress_function); - parser.start(argv[1]); + parser.parse(argv[1]); + store.commit(); parse_primary_timer.stop(); Added: trunk/libzypp/devel/devel.jkupec/bridge/Base.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/bridge... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/bridge/Base.h (added) +++ trunk/libzypp/devel/devel.jkupec/bridge/Base.h Mon May 28 16:17:38 2007 @@ -0,0 +1,23 @@ +#ifndef JK_BASE_H_ +#define JK_BASE_H_ + +#include "zypp/base/NonCopyable.h" + +namespace jk +{ + + + class Base : private zypp::base::NonCopyable + { + protected: + class BaseImpl; + }; + + +} // ns jk + + +#endif /*JK_BASE_H_*/ + +// vim: set ts=2 sts=2 sw=2 et ai: + Added: trunk/libzypp/devel/devel.jkupec/bridge/BaseImpl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/bridge... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/bridge/BaseImpl.cc (added) +++ trunk/libzypp/devel/devel.jkupec/bridge/BaseImpl.cc Mon May 28 16:17:38 2007 @@ -0,0 +1,16 @@ +#include "BaseImpl.h" + +using namespace std; + +namespace jk +{ + + + Base::BaseImpl::BaseImpl() + {} + + +} // ns zypp + +// vim: set ts=2 sts=2 sw=2 et ai: + Added: trunk/libzypp/devel/devel.jkupec/bridge/BaseImpl.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/bridge... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/bridge/BaseImpl.h (added) +++ trunk/libzypp/devel/devel.jkupec/bridge/BaseImpl.h Mon May 28 16:17:38 2007 @@ -0,0 +1,23 @@ +#ifndef JK_BASEIMPL_H_ +#define JK_BASEIMPL_H_ + +#include "zypp/base/NonCopyable.h" +#include "Base.h" + +namespace jk +{ + + + class Base::BaseImpl : private zypp::base::NonCopyable + { + public: + BaseImpl(); + }; + + +} // ns jk + +#endif /*JK_BASEIMPL_H_*/ + +// vim: set ts=2 sts=2 sw=2 et ai: + Added: trunk/libzypp/devel/devel.jkupec/bridge/Derived.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/bridge... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/bridge/Derived.cc (added) +++ trunk/libzypp/devel/devel.jkupec/bridge/Derived.cc Mon May 28 16:17:38 2007 @@ -0,0 +1,28 @@ +#include "BaseImpl.h" +#include "Derived.h" + +namespace jk +{ + + + class Derived::Impl : public BaseImpl + { + public: + Impl(); + }; + + Derived::Impl::Impl() + {} + + + Derived::Derived() : _pimpl(new Impl()) + {} + + Derived::~Derived() + {} + + +} // ns jk + +// vim: set ts=2 sts=2 sw=2 et ai: + Added: trunk/libzypp/devel/devel.jkupec/bridge/Derived.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/bridge... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/bridge/Derived.h (added) +++ trunk/libzypp/devel/devel.jkupec/bridge/Derived.h Mon May 28 16:17:38 2007 @@ -0,0 +1,26 @@ +#ifndef JK_DERIVED_H_ +#define JK_DERIVED_H_ + +#include "zypp/base/PtrTypes.h" +#include "Base.h" + +namespace jk +{ + + + class Derived : public Base + { + public: + Derived(); + ~Derived(); + + private: + class Impl; + zypp::RW_pointer<Impl,zypp::rw_pointer::Scoped<Impl> > _pimpl; + }; + + + +} // ns jk + +#endif /*JK_DERIVED_H_*/ Added: trunk/libzypp/devel/devel.jkupec/bridge/bridge.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/bridge... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/bridge/bridge.cc (added) +++ trunk/libzypp/devel/devel.jkupec/bridge/bridge.cc Mon May 28 16:17:38 2007 @@ -0,0 +1,26 @@ +#include<iostream> + +#include "zypp/base/Exception.h" + +#include "Derived.h" + + +using namespace std; +using namespace jk; +using namespace zypp; + +int main(int argc, char **argv) +{ + try + { + Derived d; + } + catch ( const Exception &e ) + { + cout << "Oops! " << e.msg() << std::endl; + } + + return 0; +} + +// vim: set ts=2 sts=2 sw=2 et ai: Modified: trunk/libzypp/devel/devel.jkupec/yum/products-example.xml URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/yum/pr... ============================================================================== --- trunk/libzypp/devel/devel.jkupec/yum/products-example.xml (original) +++ trunk/libzypp/devel/devel.jkupec/yum/products-example.xml Mon May 28 16:17:38 2007 @@ -12,7 +12,7 @@ <description lang="en">The best server OS so far</description> <description lang="sk">Doposiaľ najlepšà OS pre servery</description> rpm:requires - <rpm:entry kind="package" name="pikaball" epoch="0" ver="3.0" rel="3" flags="GE" pre="1"/> + <rpm:entry kind="ackage" name="pikaball" epoch="0" ver="3.0" rel="3" flags="GE" pre="1"/> <rpm:entry kind="package" name="base" epoch="0" ver="3.0" rel="3" flags="GE"/> </rpm:requires> rpm:provides Modified: trunk/libzypp/zypp/CMakeLists.txt URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=5... ============================================================================== --- trunk/libzypp/zypp/CMakeLists.txt (original) +++ trunk/libzypp/zypp/CMakeLists.txt Mon May 28 16:17:38 2007 @@ -552,7 +552,7 @@ parser/yum/YUMPrimaryParser.cc parser/yum/YUMProductParser.cc parser/yum/YUMRepomdParser.cc - parser/yum/FileReaderBase.cc + parser/yum/FileReaderBaseImpl.cc parser/yum/RepomdFileReader.cc parser/yum/PatchesFileReader.cc parser/yum/PrimaryFileReader.cc @@ -576,6 +576,7 @@ parser/yum/YUMProductParser.h parser/yum/YUMRepomdParser.h parser/yum/FileReaderBase.h + parser/yum/FileReaderBaseImpl.h parser/yum/RepomdFileReader.h parser/yum/PatchesFileReader.h parser/yum/PrimaryFileReader.h Modified: trunk/libzypp/zypp/parser/yum/FileReaderBase.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/FileReade... ============================================================================== --- trunk/libzypp/zypp/parser/yum/FileReaderBase.h (original) +++ trunk/libzypp/zypp/parser/yum/FileReaderBase.h Mon May 28 16:17:38 2007 @@ -6,14 +6,14 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp/parser/yum/FileReaderBase.h + * + */ #ifndef ZYPP_PARSER_YUM_FILEREADERBASE_H_ #define ZYPP_PARSER_YUM_FILEREADERBASE_H_ +#include "zypp/base/PtrTypes.h" #include "zypp/base/NonCopyable.h" -#include "zypp/parser/xml/Reader.h" -#include "zypp/data/ResolvableData.h" - namespace zypp { @@ -24,130 +24,14 @@ /** - * Class implementing parsing methods for common metadata. + * Base for yum::*FileReaders. Implements parsing methods for common metadata. */ class FileReaderBase : private base::NonCopyable { - public: - - /** - * Enumeration of some YUM metadata xml tags. - */ - enum Tag - { - tag_NONE, - tag_package, - tag_format, - tag_patch, - tag_atoms, - tag_script, - tag_message, - tag_pkgfiles, - tag_deltarpm, - tag_patchrpm, - tag_pattern, - tag_product - }; - - /** - * Lightweight object for remembering currently processed tag. - * - * Usage: - * - * - call \ref append() on opening tag - * - use \ref contains() to check if the given tag is being processed - * - call \ref remove() on closing tag - * - * \note the above works only if the path elements are unique. To support - * also non-unique elements, an equals() method will need to be implemented - * and used instead of \ref contains(). - * - * \note tags you want to use with TagPath must be enumerated in \ref Tag - * enum. - */ - struct TagPath - { - typedef std::list<Tag> TagList; - - void append(const Tag tag) { path.push_back(tag); } - void remove() { if (!path.empty()) path.pop_back(); } - unsigned depth() const { return path.size(); } - Tag currentTag() const - { - if (!path.empty()) return path.back(); - return tag_NONE; - } - bool contains(const Tag tag) const - { - TagList::const_iterator result = find(path.begin(), path.end(), tag); - return result != path.end(); - } - - TagList path; - }; - - public: - - FileReaderBase(); - - /** - * Process package node and its subtree. - * This method can be extended for specific implementations. - * - * \return true if the package node or current subnode has been consumed - * (no further processing is required), false otherwise. - */ - bool consumePackageNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr); - - /** - * Function for processing all <code>format</code> tag subtree nodes. - * - * \return true if the package node or current subnode has been consumed - * (no further processing is required), false otherwise. - */ - bool consumeFormatNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr); - - /** - * Processes RPM dependency tags (rpm:entry, rpm:requires, ...). - * - * \return true if a dependency tag has been encountered, false otherwise. - */ - bool consumeDependency(xml::Reader & reader_r, data::Dependencies & deps_r); - - - public: - /** Appends \a tag to \ref _tagpath. */ - void tag(const Tag tag) { _tagpath.append(tag); } - - /** Check whether we are currently processing given \a tag. */ - bool isBeingProcessed(Tag tag) const { return _tagpath.contains(tag); } - - /** Move to parent tag in the \ref _tagpath. */ - void toParentTag() { _tagpath.remove(); } - - const TagPath & tagPath() const { return _tagpath; } - - - private: - - /** Used to remember the tag beeing currently processed. */ - TagPath _tagpath; - - /** - * Used to remember whether we are expecting an rpm:entry tag - * e.g. for rpm:requires - */ - bool _expect_rpm_entry; - - /** - * Type of dependecy beeing processed. - */ - Dep _dtype; + protected: + class BaseImpl; }; - /** \relates FileReaderBase::TagPath */ - std::ostream & operator << (std::ostream & out, const FileReaderBase::TagPath & obj); - } // ns yum } // ns parser @@ -155,3 +39,5 @@ #endif /*ZYPP_PARSER_YUM_FILEREADERBASE_H_*/ + +// vim: set ts=2 sts=2 sw=2 et ai: Added: trunk/libzypp/zypp/parser/yum/FileReaderBaseImpl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/FileReade... ============================================================================== --- trunk/libzypp/zypp/parser/yum/FileReaderBaseImpl.cc (added) +++ trunk/libzypp/zypp/parser/yum/FileReaderBaseImpl.cc Mon May 28 16:17:38 2007 @@ -0,0 +1,372 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +---------------------------------------------------------------------*/ +/** \file zypp/parser/yum/FileReaderBaseImpl.cc + * Implementation of shared code for yum::*FileReaders. + */ +//#include <iostream> +#include <sstream> + +#include "zypp/base/Logger.h" +#include "zypp/base/Function.h" +#include "zypp/Arch.h" +#include "zypp/Edition.h" +#include "zypp/TranslatedText.h" +#include "zypp/ByteCount.h" + +#include "zypp/parser/yum/FileReaderBaseImpl.h" + +using namespace std; +using namespace zypp::xml; + +namespace zypp +{ + namespace parser + { + namespace yum + { + + + FileReaderBase::BaseImpl::BaseImpl() + : _expect_rpm_entry(false), _dtype(zypp::Dep::REQUIRES) + {} + + // -------------------------------------------------------------------------- + + bool FileReaderBase::BaseImpl::consumePackageNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr) + { + //DBG << "**node: " << reader_r->name() << " (" << reader_r->nodeType() << ") tagpath = " << _tagpath << endl; + if (isBeingProcessed(tag_format) && consumeFormatNode(reader_r, package_ptr)) + return true; + + if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) + { + if (reader_r->name() == "name") + { + package_ptr->name = reader_r.nodeText().asString(); + return true; + } + + if (reader_r->name() == "arch") + { + //if (arch == "src" || arch == "nosrc") arch = "noarch"; + package_ptr->arch = Arch(reader_r.nodeText().asString()); + return true; + } + + if (reader_r->name() == "version") + { + package_ptr->edition = Edition(reader_r->getAttribute("ver").asString(), + reader_r->getAttribute("rel").asString(), + reader_r->getAttribute("epoch").asString()); + return true; + } + + if (reader_r->name() == "checksum") + { + package_ptr->repositoryLocation.fileChecksum = CheckSum( + reader_r->getAttribute("type").asString(), + reader_r.nodeText().asString()); + // ignoring pkgid attribute + return true; + } + + if (reader_r->name() == "summary") + { + package_ptr->summary.setText( + reader_r.nodeText().asString(), + Locale(reader_r->getAttribute("lang").asString())); + return true; + } + + if (reader_r->name() == "description") + { + package_ptr->description.setText( + reader_r.nodeText().asString(), + Locale(reader_r->getAttribute("lang").asString())); + return true; + } + + if (reader_r->name() == "packager") + { + package_ptr->packager = reader_r.nodeText().asString(); +// DBG << "packager: " << package_ptr->packager << endl; + return true; + } + + if (reader_r->name() == "url") + { +// DBG << "url: " << reader_r.nodeText().asString() << endl; + package_ptr->url = reader_r.nodeText().asString(); + return true; + } + + if (reader_r->name() == "time") + { + package_ptr->buildTime = reader_r->getAttribute("build").asString(); + // ignoring reader_r->getAttribute("file").asString(); (rpm file timestamp) + return true; + } + + if (reader_r->name() == "size") + { + // ??? + // reader_r->getAttribute("archive").asString(); + + // installed size + package_ptr->installedSize = str::strtonumByteCount::SizeType( reader_r->getAttribute("installed").asString() ); + + // rpm package size + package_ptr->repositoryLocation.fileSize = str::strtonumByteCount::SizeType( reader_r->getAttribute("package").asString() ); + + return true; + } + + if (reader_r->name() == "location") + { + package_ptr->repositoryLocation.filePath = reader_r->getAttribute("href").asString(); + return true; + } + + if (reader_r->name() == "format") + { + tag(tag_format); + return true; + } + } + + else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT ) + { + if (reader_r->name() == "package") + { + // indicate that further processing is required + return false; + } + } + + return true; + } + + + // --------------( consume <format> tag )------------------------------------ + + bool FileReaderBase::BaseImpl::consumeFormatNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr) + { + if (consumeDependency(reader_r, package_ptr->deps)) + // this node has been a dependency, which has been handled by + // consumeDependency(), so return right away. + return true; + +// DBG << "format subtag: " << reader_r->name() << endl; + if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) + { + if (reader_r->name() == "rpm:license") + { + package_ptr->license = reader_r.nodeText().asString(); + return true; + } + + if (reader_r->name() == "rpm:vendor") + { + package_ptr->vendor = reader_r.nodeText().asString(); + return true; + } + + if (reader_r->name() == "rpm:group") + { + package_ptr->group = reader_r.nodeText().asString(); + return true; + } + + if (reader_r->name() == "rpm:buildhost") + { + package_ptr->buildhost = reader_r.nodeText().asString(); + return true; + } + + if (reader_r->name() == "rpm:sourcerpm") + { + //package->source = reader_r.nodeText().asString(); + return true; + } + + if (reader_r->name() == "rpm:header-range") + { + //reader_r->getAttribute("start").asString(), + //reader_r->getAttribute("end").asString(), + return true; + } + + if (reader_r->name() == "file") + { + // TODO figure out how to read files + // file = reader_r.nodeText().asString(); + // type = reader_r->getAttribute("type").asString(); + return true; + } + } + else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT) + { + if (reader_r->name() == "format") + { + toParentTag(); + return true; + } + } + + return true; + } + + // -------------------------------------------------------------------------- + + bool FileReaderBase::BaseImpl::consumeDependency(xml::Reader & reader_r, data::Dependencies & deps_r) + { + if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) + { + if (reader_r->name() == "rpm:entry") + { + if (!_expect_rpm_entry) + { + // TODO make this a ParseException (once created/taken out of tagfile ns?) + ZYPP_THROW(Exception("rpm:entry found when not expected")); + } + + Edition edition( + reader_r->getAttribute("ver").asString(), + reader_r->getAttribute("rel").asString(), + reader_r->getAttribute("epoch").asString() + ); + + string kind_str = reader_r->getAttribute("kind").asString(); + Resolvable::Kind kind; + if (kind_str.empty()) + kind = ResTraits<Package>::kind; + else + kind = Resolvable::Kind(kind_str); + +/* + DBG << "got rpm:entry for " << _dtype << ": " + << reader_r->getAttribute("name").asString() + << " " << edition << " (" << kind << ")" << endl; +*/ + deps_r[_dtype].insert( + zypp::capability::parse( + kind, + reader_r->getAttribute("name").asString(), + Rel(reader_r->getAttribute("flags").asString()), + edition + ) + ); + } + + if (reader_r->name() == "rpm:provides") + { + _dtype = zypp::Dep::PROVIDES; + _expect_rpm_entry = true; + return true; + } + if (reader_r->name() == "rpm:conflicts") + { + _dtype = zypp::Dep::CONFLICTS; + _expect_rpm_entry = true; + return true; + } + if (reader_r->name() == "rpm:obsoletes") + { + _dtype = zypp::Dep::OBSOLETES; + _expect_rpm_entry = true; + return true; + } + if (reader_r->name() == "rpm:requires") + { + _dtype = zypp::Dep::REQUIRES; + _expect_rpm_entry = true; + return true; + } + if (reader_r->name() == "rpm:recommends") + { + _dtype = zypp::Dep::RECOMMENDS; + _expect_rpm_entry = true; + return true; + } + if (reader_r->name() == "rpm:enhances") + { + _dtype = zypp::Dep::ENHANCES; + _expect_rpm_entry = true; + return true; + } + if (reader_r->name() == "rpm:supplements") + { + _dtype = zypp::Dep::SUPPLEMENTS; + _expect_rpm_entry = true; + return true; + } + if (reader_r->name() == "rpm:suggests") + { + _dtype = zypp::Dep::SUGGESTS; + _expect_rpm_entry = true; + return true; + } + if (reader_r->name() == "rpm:suggests") + { + _dtype = zypp::Dep::SUGGESTS; + _expect_rpm_entry = true; + return true; + } + } + else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT) + { + if (reader_r->name() == "rpm:requires" + || reader_r->name() == "rpm:provides" + || reader_r->name() == "rpm:conflicts" + || reader_r->name() == "rpm:obsoletes" + || reader_r->name() == "rpm:recommends" + || reader_r->name() == "rpm:enhances" + || reader_r->name() == "rpm:supplements" + || reader_r->name() == "rpm:suggests") + { + _expect_rpm_entry = false; + return true; + } + } + + // tell the caller this has not been a dependency tag (i.e. not processed) + return false; + } + + // -------------------------------------------------------------------------- + + string FileReaderBase::BaseImpl::TagPath::asString() + { + ostringstream s; + + s << "("; + + if (depth()) + { + TagList::const_iterator p = path.begin(); + s << *p; + ++p; + + for (; p != path.end(); ++p) + s << "," << *p; + } + else + s << "empty"; + + s << ")"; + + return s.str(); + } + + + } // ns yum + } // ns parser +} // ns zypp + +// vim: set ts=2 sts=2 sw=2 et ai: Added: trunk/libzypp/zypp/parser/yum/FileReaderBaseImpl.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/FileReade... ============================================================================== --- trunk/libzypp/zypp/parser/yum/FileReaderBaseImpl.h (added) +++ trunk/libzypp/zypp/parser/yum/FileReaderBaseImpl.h Mon May 28 16:17:38 2007 @@ -0,0 +1,156 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +---------------------------------------------------------------------*/ +/** \file zypp/parser/yum/FileReaderBaseImpl.h + * Implementation interface of shared code for yum::*FileReaders. + */ +#ifndef ZYPP_PARSER_YUM_FILEREADERBASEIMPL_H_ +#define ZYPP_PARSER_YUM_FILEREADERBASEIMPL_H_ + +#include "zypp/data/ResolvableData.h" +#include "zypp/parser/xml/Reader.h" + +#include "zypp/parser/yum/FileReaderBase.h" + +namespace zypp +{ + namespace parser + { + namespace yum + { + + + class FileReaderBase::BaseImpl : private base::NonCopyable + { + public: + + /** + * Enumeration of some YUM metadata xml tags. + */ + enum Tag + { + tag_NONE, + tag_package, + tag_format, + tag_patch, + tag_atoms, + tag_script, + tag_message, + tag_pkgfiles, + tag_deltarpm, + tag_patchrpm, + tag_pattern, + tag_product + }; + + /** + * Lightweight object for remembering currently processed tag. + * + * Usage: + * + * - call \ref append() on opening tag + * - use \ref contains() to check if the given tag is being processed + * - call \ref remove() on closing tag + * + * \note the above works only if the path elements are unique. To support + * also non-unique elements, an equals() method will need to be implemented + * and used instead of \ref contains(). + * + * \note tags you want to use with TagPath must be enumerated in \ref Tag + * enum. + */ + struct TagPath + { + typedef std::list<Tag> TagList; + + void append(const Tag tag) { path.push_back(tag); } + void remove() { if (!path.empty()) path.pop_back(); } + unsigned depth() const { return path.size(); } + Tag currentTag() const + { + if (!path.empty()) return path.back(); + return tag_NONE; + } + bool contains(const Tag tag) const + { + TagList::const_iterator result = find(path.begin(), path.end(), tag); + return result != path.end(); + } + std::string asString(); + + TagList path; + }; + + + public: + /** CTOR */ + BaseImpl(); + + /** + * Process package node and its subtree. + * This method can be extended for specific implementations. + * + * \return true if the package node or current subnode has been consumed + * (no further processing is required), false otherwise. + */ + bool consumePackageNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr); + + /** + * Function for processing all <code>format</code> tag subtree nodes. + * + * \return true if the package node or current subnode has been consumed + * (no further processing is required), false otherwise. + */ + bool consumeFormatNode(xml::Reader & reader_r, data::Package_Ptr & package_ptr); + + /** + * Processes RPM dependency tags (rpm:entry, rpm:requires, ...). + * + * \return true if a dependency tag has been encountered, false otherwise. + */ + bool consumeDependency(xml::Reader & reader_r, data::Dependencies & deps_r); + + + public: + /** Appends \a tag to \ref _tagpath. */ + void tag(const Tag tag) { _tagpath.append(tag); } + + /** Check whether we are currently processing given \a tag. */ + bool isBeingProcessed(Tag tag) const { return _tagpath.contains(tag); } + + /** Move to parent tag in the \ref _tagpath. */ + void toParentTag() { _tagpath.remove(); } + + /** Getter of the tagpath object. */ + const TagPath & tagPath() const { return _tagpath; } + + + private: + /** Used to remember the tag beeing currently processed. */ + TagPath _tagpath; + + /** + * Used to remember whether we are expecting an rpm:entry tag + * e.g. for rpm:requires + */ + bool _expect_rpm_entry; + + /** + * Type of dependecy beeing processed. + */ + Dep _dtype; + }; + + + } // ns yum + } // ns parser +} // ns zypp + +#endif /*ZYPP_PARSER_YUM_FILEREADERBASEIMPL_H_*/ + +// vim: set ts=2 sts=2 sw=2 et ai: Modified: trunk/libzypp/zypp/parser/yum/PatchFileReader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PatchFile... ============================================================================== --- trunk/libzypp/zypp/parser/yum/PatchFileReader.cc (original) +++ trunk/libzypp/zypp/parser/yum/PatchFileReader.cc Mon May 28 16:17:38 2007 @@ -6,9 +6,16 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp/parser/yum/PatchFileReader.cc + * Implementation of patch XML file reader. + */ #include "zypp/base/Logger.h" +#include "zypp/parser/xml/Reader.h" +#include "zypp/data/ResolvableData.h" + #include "zypp/parser/yum/PatchFileReader.h" +#include "zypp/parser/yum/FileReaderBaseImpl.h" + #undef ZYPP_BASE_LOGGER_LOGGROUP #define ZYPP_BASE_LOGGER_LOGGROUP "parser" @@ -24,12 +31,139 @@ { - PatchFileReader::PatchFileReader(const Pathname & patch_file, ProcessPatch callback) - : _callback(callback) + /////////////////////////////////////////////////////////////////////////// + // + // CLASS NAME : PatchFileReader::Impl + // + class PatchFileReader::Impl : public BaseImpl + { + public: + /** CTOR */ + Impl(const Pathname & patch_file, + const ProcessPatch & callback); + + /** + * Callback provided to the XML reader. + * + * \param the xml reader object reading the file + * \return true to tell the reader to continue, false to tell it to stop + * + * \see PrimaryFileReader::consumeNode(xml::Reader) + */ + bool consumeNode(xml::Reader & reader_r); + + /** + * Process <tt>atoms</tt> node and all of its children. + * + * \param reader_r XML file reader reading the patch file. + * \return true if current node has been completely processed, false + * if additional processing is required outside of the method. + */ + bool consumeAtomsNode(xml::Reader & reader_r); + + /** + * Process <tt>package</tt> node and all of its children. This method + * uses \ref FileReaderBase::consumePackageNode(xml::Reader,data::Package_Ptr) + * method and adds <tt>pkgfiles</tt> element processing. + * + * \param reader_r XML file reader reading the patch file. + * \return true if current node has been completely processed, false + * if additional processing is required outside of the method. + */ + bool consumePackageNode(xml::Reader & reader_r); + + /** + * Process <tt>patchrpm</tt> node and all of its children. + * + * \param reader_r XML file reader reading the patch file. + * \return true if current node has been completely processed, false + * if additional processing is required outside of the method. + */ + bool consumePatchrpmNode(xml::Reader & reader_r); + + /** + * Process <tt>deltarpm</tt> node and all of its children. + * + * \param reader_r XML file reader reading the patch file. + * \return true if current node has been completely processed, false + * if additional processing is required outside of the method. + */ + bool consumeDeltarpmNode(xml::Reader & reader_r); + + /** + * Process <tt>message</tt> node and all of its children. + * + * \param reader_r XML file reader reading the patch file. + * \return true if current node has been completely processed, false + * if additional processing is required outside of the method. + */ + bool consumeMessageNode(xml::Reader & reader_r); + + /** + * Process <tt>script</tt> node and all of its children. + * + * \param reader_r XML file reader reading the patch file. + * \return true if current node has been completely processed, false + * if additional processing is required outside of the method. + */ + bool consumeScriptNode(xml::Reader & reader_r); + + /** + * Creates a new \ref data::Patch_Ptr, swaps its contents with \ref _patch + * and returns it. Used to hand-out the data object to its consumer + * (a \ref ProcessPatch function) after it has been read. + */ + data::Patch_Ptr handoutPatch(); + + /** + * Creates a new \ref data::ResObject_Ptr, swap its contents with + * \ref _tmpResObj and inserts it into <tt>_patch.atoms</tt>. Used + * after an atom is read. + */ + void saveAtomInPatch(); + + /** + * + */ + void copyPackageAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const; + + private: + /** + * Callback for processing patch metadata passed in through constructor. + */ + ProcessPatch _callback; + + /** + * Pointer to the \ref zypp::data::Patch object for storing the patch + * metada (except of depencencies). + */ + data::Patch_Ptr _patch; + + /** + * Pointer to an atom currently being read. This can be either + * a \ref data::PackageAtom, \ref data::Message, or \ref data::Script. + * + * \see data::Patch::atoms + */ + data::ResObject_Ptr _tmpResObj; + + /** Data object for storing patchrpm data */ + data::PatchRpm_Ptr _patchrpm; + + /** Data object for storing deltarpm data */ + data::DeltaRpm_Ptr _deltarpm; + }; + /////////////////////////////////////////////////////////////////////////// + + PatchFileReader::Impl::Impl( + const Pathname & patch_file, + const ProcessPatch & callback) + : + _callback(callback) { Reader reader(patch_file); MIL << "Reading " << patch_file << endl; - reader.foreachNode(bind(&PatchFileReader::consumeNode, this, _1)); + reader.foreachNode(bind(&PatchFileReader::Impl::consumeNode, this, _1)); } // -------------------------------------------------------------------------- @@ -45,7 +179,7 @@ // -------------------------------------------------------------------------- - bool PatchFileReader::consumeNode(Reader & reader_r) + bool PatchFileReader::Impl::consumeNode(Reader & reader_r) { if (isBeingProcessed(tag_atoms) && consumeAtomsNode(reader_r)) return true; @@ -170,7 +304,7 @@ // -------------------------------------------------------------------------- - bool PatchFileReader::consumeAtomsNode(Reader & reader_r) + bool PatchFileReader::Impl::consumeAtomsNode(Reader & reader_r) { // consumePackageNode if (isBeingProcessed(tag_package) && consumePackageNode(reader_r)) @@ -265,7 +399,7 @@ // -------------------------------------------------------------------------- - bool PatchFileReader::consumePackageNode(Reader & reader_r) + bool PatchFileReader::Impl::consumePackageNode(Reader & reader_r) { if (isBeingProcessed(tag_patchrpm) && consumePatchrpmNode(reader_r)) return true; @@ -357,7 +491,7 @@ { // xpath: /patch/atoms/package/* (except pkgfiles/* and license-to-confirm) (*) if (isBeingProcessed(tag_package)) - return FileReaderBase::consumePackageNode(reader_r, package_ptr); + return FileReaderBase::BaseImpl::consumePackageNode(reader_r, package_ptr); } else { @@ -369,7 +503,7 @@ // -------------------------------------------------------------------------- - bool PatchFileReader::consumePatchrpmNode(Reader & reader_r) + bool PatchFileReader::Impl::consumePatchrpmNode(Reader & reader_r) { if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) { @@ -445,7 +579,7 @@ // -------------------------------------------------------------------------- - bool PatchFileReader::consumeDeltarpmNode(Reader & reader_r) + bool PatchFileReader::Impl::consumeDeltarpmNode(Reader & reader_r) { if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT) { @@ -529,7 +663,7 @@ // -------------------------------------------------------------------------- - bool PatchFileReader::consumeMessageNode(Reader & reader_r) + bool PatchFileReader::Impl::consumeMessageNode(Reader & reader_r) { if (consumeDependency(reader_r, _tmpResObj->deps)) return true; @@ -578,7 +712,7 @@ // -------------------------------------------------------------------------- - bool PatchFileReader::consumeScriptNode(Reader & reader_r) + bool PatchFileReader::Impl::consumeScriptNode(Reader & reader_r) { if (consumeDependency(reader_r, _tmpResObj->deps)) return true; @@ -677,7 +811,7 @@ // -------------------------------------------------------------------------- - data::Patch_Ptr PatchFileReader::handoutPatch() + data::Patch_Ptr PatchFileReader::Impl::handoutPatch() { data::Patch_Ptr ret; ret.swap(_patch); @@ -686,7 +820,7 @@ // -------------------------------------------------------------------------- - void PatchFileReader::saveAtomInPatch() + void PatchFileReader::Impl::saveAtomInPatch() { data::ResObject_Ptr tmp; tmp.swap(_tmpResObj); @@ -694,6 +828,20 @@ } + /////////////////////////////////////////////////////////////////////////// + // + // CLASS NAME : PatchFileReader::Impl + // + /////////////////////////////////////////////////////////////////////////// + + PatchFileReader::PatchFileReader(const Pathname & patch_file, ProcessPatch callback) + : _pimpl(new PatchFileReader::Impl(patch_file, callback)) + {} + + PatchFileReader::~PatchFileReader() + {} + + } // ns yum } // ns parser } // ns zypp Modified: trunk/libzypp/zypp/parser/yum/PatchFileReader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PatchFile... ============================================================================== --- trunk/libzypp/zypp/parser/yum/PatchFileReader.h (original) +++ trunk/libzypp/zypp/parser/yum/PatchFileReader.h Mon May 28 16:17:38 2007 @@ -6,17 +6,25 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp/parser/yum/PatchFileReader.h + * Interface definition of patch XML file reader. + */ #ifndef PATCHFILEREADER_H_ #define PATCHFILEREADER_H_ #include "zypp/base/Function.h" -#include "zypp/parser/xml/Reader.h" #include "zypp/parser/yum/FileReaderBase.h" -#include "zypp/data/ResolvableData.h" namespace zypp { + + namespace data + { + class Patch; + DEFINE_PTR_TYPE(Patch); + } // ns data + + namespace parser { namespace yum @@ -24,8 +32,8 @@ /** - * Reader of patch.xml files conforming to RNC/RNG definition located - * in zypp/parser/yum/schema/patch.rn(c|g). + * Reader of patch.xml files conforming to schema definition located + * at zypp/parser/yum/schema/patch.rnc. * * \see zypp::data::Patch * \see zypp::parser::xml::Reader @@ -48,118 +56,14 @@ */ PatchFileReader(const Pathname & patch_file, ProcessPatch callback); - private: - - /** - * Callback provided to the XML reader. - * - * \param the xml reader object reading the file - * \return true to tell the reader to continue, false to tell it to stop - * - * \see PrimaryFileReader::consumeNode(xml::Reader) - */ - bool consumeNode(xml::Reader & reader_r); - - /** - * Process <tt>atoms</tt> node and all of its children. - * - * \param reader_r XML file reader reading the patch file. - * \return true if current node has been completely processed, false - * if additional processing is required outside of the method. - */ - bool consumeAtomsNode(xml::Reader & reader_r); - - /** - * Process <tt>package</tt> node and all of its children. This method - * uses \ref FileReaderBase::consumePackageNode(xml::Reader,data::Package_Ptr) - * method and adds <tt>pkgfiles</tt> element processing. - * - * \param reader_r XML file reader reading the patch file. - * \return true if current node has been completely processed, false - * if additional processing is required outside of the method. - */ - bool consumePackageNode(xml::Reader & reader_r); - - /** - * Process <tt>patchrpm</tt> node and all of its children. - * - * \param reader_r XML file reader reading the patch file. - * \return true if current node has been completely processed, false - * if additional processing is required outside of the method. - */ - bool consumePatchrpmNode(xml::Reader & reader_r); - - /** - * Process <tt>deltarpm</tt> node and all of its children. - * - * \param reader_r XML file reader reading the patch file. - * \return true if current node has been completely processed, false - * if additional processing is required outside of the method. - */ - bool consumeDeltarpmNode(xml::Reader & reader_r); - /** - * Process <tt>message</tt> node and all of its children. - * - * \param reader_r XML file reader reading the patch file. - * \return true if current node has been completely processed, false - * if additional processing is required outside of the method. + * DTOR. */ - bool consumeMessageNode(xml::Reader & reader_r); - - /** - * Process <tt>script</tt> node and all of its children. - * - * \param reader_r XML file reader reading the patch file. - * \return true if current node has been completely processed, false - * if additional processing is required outside of the method. - */ - bool consumeScriptNode(xml::Reader & reader_r); - - /** - * Creates a new \ref data::Patch_Ptr, swaps its contents with \ref _patch - * and returns it. Used to hand-out the data object to its consumer - * (a \ref ProcessPatch function) after it has been read. - */ - data::Patch_Ptr handoutPatch(); - - /** - * Creates a new \ref data::ResObject_Ptr, swap its contents with - * \ref _tmpResObj and inserts it into <tt>_patch.atoms</tt>. Used - * after an atom is read. - */ - void saveAtomInPatch(); - - /** - * - */ - void copyPackageAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const; + ~PatchFileReader(); private: - /** - * Callback for processing patch metadata passed in through constructor. - */ - ProcessPatch _callback; - - /** - * Pointer to the \ref zypp::data::Patch object for storing the patch - * metada (except of depencencies). - */ - data::Patch_Ptr _patch; - - /** - * Pointer to an atom currently being read. This can be either - * a \ref data::PackageAtom, \ref data::Message, or \ref data::Script. - * - * \see data::Patch::atoms - */ - data::ResObject_Ptr _tmpResObj; - - /** Data object for storing patchrpm data */ - data::PatchRpm_Ptr _patchrpm; - - /** Data object for storing deltarpm data */ - data::DeltaRpm_Ptr _deltarpm; + class Impl; + RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl; }; Modified: trunk/libzypp/zypp/parser/yum/PatternFileReader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PatternFi... ============================================================================== --- trunk/libzypp/zypp/parser/yum/PatternFileReader.cc (original) +++ trunk/libzypp/zypp/parser/yum/PatternFileReader.cc Mon May 28 16:17:38 2007 @@ -6,8 +6,14 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp/parser/yum/PatternFileReader.cc + * Implementation of patterns.xml file reader. + */ #include "zypp/base/Logger.h" +#include "zypp/data/ResolvableData.h" +#include "zypp/parser/xml/Reader.h" + +#include "zypp/parser/yum/FileReaderBaseImpl.h" #include "zypp/parser/yum/PatternFileReader.h" #undef ZYPP_BASE_LOGGER_LOGGROUP @@ -24,12 +30,56 @@ { - PatternFileReader::PatternFileReader(const Pathname & pattern_file, ProcessPattern callback) - : _callback(callback) + /////////////////////////////////////////////////////////////////////// + // + // CLASS NAME : PatternFileReader::Impl + // + class PatternFileReader::Impl : public BaseImpl + { + public: + Impl(const Pathname & pattern_file, + const ProcessPattern & callback); + + /** + * Callback provided to the XML reader. + * + * \param the xml reader object reading the file + * \return true to tell the reader to continue, false to tell it to stop + * + * \see PrimaryFileReader::consumeNode(xml::Reader) + */ + bool consumeNode(xml::Reader & reader_r); + + /** + * Creates a new \ref data::Pattern_Ptr, swaps its contents with \ref _pattern + * and returns it. Used to hand-out the data object to its consumer + * (a \ref ProcessPattern function) after it has been read. + */ + data::Pattern_Ptr handoutPattern(); + + private: + /** + * Callback for processing pattern metadata. + */ + ProcessPattern _callback; + + /** + * Pointer to the \ref zypp::data::Pattern object for storing the pattern + * metada. + */ + data::Pattern_Ptr _pattern; + }; + ////////////////////////////////////////////////////////////////////////// + + PatternFileReader::Impl::Impl( + const Pathname & pattern_file, + const ProcessPattern & callback) + : + _callback(callback) { Reader reader(pattern_file); MIL << "Reading " << pattern_file << endl; - reader.foreachNode(bind(&PatternFileReader::consumeNode, this, _1)); + reader.foreachNode(bind(&PatternFileReader::Impl::consumeNode, this, _1)); } // -------------------------------------------------------------------------- @@ -45,7 +95,7 @@ // -------------------------------------------------------------------------- - bool PatternFileReader::consumeNode(Reader & reader_r) + bool PatternFileReader::Impl::consumeNode(Reader & reader_r) { // dependency block nodes if (consumeDependency(reader_r, _pattern->deps)) @@ -139,13 +189,27 @@ // -------------------------------------------------------------------------- - data::Pattern_Ptr PatternFileReader::handoutPattern() + data::Pattern_Ptr PatternFileReader::Impl::handoutPattern() { data::Pattern_Ptr ret; ret.swap(_pattern); return ret; } + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : PatternFileReader + // + /////////////////////////////////////////////////////////////////// + + PatternFileReader::PatternFileReader(const Pathname & pattern_file, ProcessPattern callback) + : _pimpl(new PatternFileReader::Impl(pattern_file, callback)) + {} + + + PatternFileReader::~PatternFileReader() + {} + } // ns yum } // ns parser Modified: trunk/libzypp/zypp/parser/yum/PatternFileReader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PatternFi... ============================================================================== --- trunk/libzypp/zypp/parser/yum/PatternFileReader.h (original) +++ trunk/libzypp/zypp/parser/yum/PatternFileReader.h Mon May 28 16:17:38 2007 @@ -6,17 +6,24 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp/parser/yum/PatternFileReader.h + * + */ #ifndef PATTERNFILEREADER_H_ #define PATTERNFILEREADER_H_ -#include "zypp/base/Function.h" -#include "zypp/parser/xml/Reader.h" #include "zypp/parser/yum/FileReaderBase.h" -#include "zypp/data/ResolvableData.h" namespace zypp { + + namespace data + { + class Pattern; + DEFINE_PTR_TYPE(Pattern); + } // ns data + + namespace parser { namespace yum @@ -24,8 +31,8 @@ /** - * Reader of pattern.xml files conforming to RNC/RNG definition located - * in zypp/parser/yum/schema/pattern.rn(c|g). + * Reader of patterns.xml file conforming to schema definition located + * at zypp/parser/yum/schema/patterns.rnc. * * \see zypp::data::Pattern * \see zypp::parser::xml::Reader @@ -47,37 +54,15 @@ * \param callback Function which will process read data. */ PatternFileReader(const Pathname & pattern_file, ProcessPattern callback); - - private: - + /** - * Callback provided to the XML reader. - * - * \param the xml reader object reading the file - * \return true to tell the reader to continue, false to tell it to stop - * - * \see PrimaryFileReader::consumeNode(xml::Reader) + * DTOR. */ - bool consumeNode(xml::Reader & reader_r); - - /** - * Creates a new \ref data::Pattern_Ptr, swaps its contents with \ref _pattern - * and returns it. Used to hand-out the data object to its consumer - * (a \ref ProcessPattern function) after it has been read. - */ - data::Pattern_Ptr handoutPattern(); + ~PatternFileReader(); private: - /** - * Callback for processing pattern metadata. - */ - ProcessPattern _callback; - - /** - * Pointer to the \ref zypp::data::Pattern object for storing the pattern - * metada. - */ - data::Pattern_Ptr _pattern; + class Impl; + RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl; }; Modified: trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PrimaryFi... ============================================================================== --- trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc (original) +++ trunk/libzypp/zypp/parser/yum/PrimaryFileReader.cc Mon May 28 16:17:38 2007 @@ -6,9 +6,15 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp/parser/yum/PrimaryFileReader.cc + * Implementation of primary.xml.gz file reader. + */ #include "zypp/base/Logger.h" +#include "zypp/parser/xml/Reader.h" +#include "zypp/data/ResolvableData.h" + +#include "zypp/parser/yum/FileReaderBaseImpl.h" #include "zypp/parser/yum/PrimaryFileReader.h" #undef ZYPP_BASE_LOGGER_LOGGROUP @@ -25,7 +31,63 @@ { - PrimaryFileReader::PrimaryFileReader( + /////////////////////////////////////////////////////////////////////////// + // + // CLASS NAME : PrimaryFileReader::Impl + // + class PrimaryFileReader::Impl : public BaseImpl + { + public: + /** CTOR */ + Impl(const Pathname & primary_file, + const ProcessPackage & callback, + const ProgressData::ReceiverFnc & progress); + + /** + * Callback provided to the XML reader. + * + * This is the main parsing method which gets envoked by the \ref xml::Reader + * to process each node, one at a time. It is responsible for parsing the + * node and calling all other consume* methods. + * + * \param the xml reader object reading the file + * \return true to tell the reader to continue, false to tell it to stop + * + * \note Semantics of this method's return value also differs from other + * consume* methods. While this method's return value tells the the + * xml reader to continue or stop, return value of the rest tells + * their callers if further + */ + bool consumeNode(xml::Reader & reader_r); + + private: + /** + * Creates a new \ref data::Package_Ptr, swaps its contents with \ref + * _package and returns it. Used to hand-out the data object to its consumer + * (a \ref ProcessPackage function) after it has been read. + */ + data::Package_Ptr handoutPackage(); + + private: + /** + * Callback for processing package metadata passed in through constructor. + */ + ProcessPackage _callback; + + /** + * \ref zypp::data::Package object for storing the package metada + */ + data::Package_Ptr _package; + + /** + * Progress reporting object. + */ + ProgressData _ticks; + }; + /////////////////////////////////////////////////////////////////////////// + + + PrimaryFileReader::Impl::Impl( const Pathname & primary_file, const ProcessPackage & callback, const ProgressData::ReceiverFnc & progress) @@ -36,12 +98,12 @@ Reader reader(primary_file); MIL << "Reading " << primary_file << endl; - reader.foreachNode(bind( &PrimaryFileReader::consumeNode, this, _1 )); + reader.foreachNode(bind( &PrimaryFileReader::Impl::consumeNode, this, _1 )); } // -------------------------------------------------------------------------- - bool PrimaryFileReader::consumeNode(Reader & reader_r) + bool PrimaryFileReader::Impl::consumeNode(Reader & reader_r) { // DBG << "**node: " << reader_r->name() << " (" << reader_r->nodeType() << ")" << endl; if (isBeingProcessed(tag_package) && consumePackageNode(reader_r, _package)) @@ -94,13 +156,30 @@ // -------------------------------------------------------------------------- - data::Package_Ptr PrimaryFileReader::handoutPackage() + data::Package_Ptr PrimaryFileReader::Impl::handoutPackage() { data::Package_Ptr ret; ret.swap(_package); return ret; } + /////////////////////////////////////////////////////////////////////////// + // + // CLASS NAME : PrimaryFileReader + // + /////////////////////////////////////////////////////////////////////////// + + PrimaryFileReader::PrimaryFileReader( + const Pathname & primary_file, + const ProcessPackage & callback, + const ProgressData::ReceiverFnc & progress) + : _pimpl(new PrimaryFileReader::Impl(primary_file, callback, progress)) + {} + + + PrimaryFileReader::~PrimaryFileReader() + {} + } // ns yum } // ns parser Modified: trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/PrimaryFi... ============================================================================== --- trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h (original) +++ trunk/libzypp/zypp/parser/yum/PrimaryFileReader.h Mon May 28 16:17:38 2007 @@ -6,26 +6,33 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp/parser/yum/PrimaryFileReader.h + * Interface definition of primary.xml.gz file reader. + */ #ifndef ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H #define ZYPP_PARSER_YUM_PRIMARYFILEPARSER_H -#include "zypp/base/Function.h" -#include "zypp/parser/xml/Reader.h" -#include "zypp/parser/yum/FileReaderBase.h" -#include "zypp/data/ResolvableData.h" #include "zypp/ProgressData.h" +#include "zypp/parser/yum/FileReaderBase.h" namespace zypp { + + namespace data + { + class Package; + DEFINE_PTR_TYPE(Package); + } // ns data + + namespace parser { namespace yum { /** - * Reads through a primary.xml file and collects package data including + * Reads through a primary.xml.gz file and collects package data including * dependencies. * * After a package is read, a \ref zypp::data::Package object is prepared @@ -47,7 +54,8 @@ typedef function<bool(const data::Package_Ptr &)> ProcessPackage; /** - * Constructor + * CTOR. Creates also \ref xml::Reader and starts reading. + * * \param primary_file the primary.xml.gz file you want to read * \param callback function to process \ref _package data. * \param progress progress reporting function @@ -60,45 +68,13 @@ const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc()); /** - * Callback provided to the XML reader. - * - * This is the main parsing method which gets envoked by the \ref xml::Reader - * to process each node, one at a time. It is responsible for parsing the - * node and calling all other consume* methods. - * - * \param the xml reader object reading the file - * \return true to tell the reader to continue, false to tell it to stop - * - * \note Semantics of this method's return value also differs from other - * consume* methods. While this method's return value tells the the - * xml reader to continue or stop, return value of the rest tells - * their callers if further + * DTOR. */ - bool consumeNode(xml::Reader & reader_r); + ~PrimaryFileReader(); private: - /** - * Creates a new \ref data::Package_Ptr, swaps its contents with \ref - * _package and returns it. Used to hand-out the data object to its consumer - * (a \ref ProcessPackage function) after it has been read. - */ - data::Package_Ptr handoutPackage(); - - private: - /** - * Callback for processing package metadata passed in through constructor. - */ - ProcessPackage _callback; - - /** - * \ref zypp::data::Package object for storing the package metada - */ - data::Package_Ptr _package; - - /** - * Progress reporting object. - */ - ProgressData _ticks; + class Impl; + RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl; }; Modified: trunk/libzypp/zypp/parser/yum/ProductFileReader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/ProductFi... ============================================================================== --- trunk/libzypp/zypp/parser/yum/ProductFileReader.cc (original) +++ trunk/libzypp/zypp/parser/yum/ProductFileReader.cc Mon May 28 16:17:38 2007 @@ -8,6 +8,10 @@ ---------------------------------------------------------------------*/ #include "zypp/base/Logger.h" +#include "zypp/parser/xml/Reader.h" +#include "zypp/data/ResolvableData.h" + +#include "zypp/parser/yum/FileReaderBaseImpl.h" #include "zypp/parser/yum/ProductFileReader.h" #undef ZYPP_BASE_LOGGER_LOGGROUP @@ -24,12 +28,56 @@ { - ProductFileReader::ProductFileReader(const Pathname & product_file, ProcessProduct callback) - : _callback(callback) + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : ProductFileReader::Impl + // + class ProductFileReader::Impl : public BaseImpl { - Reader reader(product_file); - MIL << "Reading " << product_file << endl; - reader.foreachNode(bind(&ProductFileReader::consumeNode, this, _1)); + public: + Impl(const Pathname & products_file, + const ProcessProduct & callback); + + /** + * Callback provided to the XML reader. + * + * \param the xml reader object reading the file + * \return true to tell the reader to continue, false to tell it to stop + * + * \see PrimaryFileReader::consumeNode(xml::Reader) + */ + bool consumeNode(xml::Reader & reader_r); + + /** + * Creates a new \ref data::Product_Ptr, swaps its contents with \ref _product + * and returns it. Used to hand-out the data object to its consumer + * (a \ref ProcessProduct function) after it has been read. + */ + data::Product_Ptr handoutProduct(); + + private: + /** + * Callback for processing product metadata. + */ + ProcessProduct _callback; + + /** + * Pointer to the \ref zypp::data::Product object for storing the product + * metada. + */ + data::Product_Ptr _product; + }; + /////////////////////////////////////////////////////////////////// + + ProductFileReader::Impl::Impl( + const Pathname & products_file, + const ProcessProduct & callback) + : + _callback(callback) + { + Reader reader(products_file); + MIL << "Reading " << products_file << endl; + reader.foreachNode(bind(&ProductFileReader::Impl::consumeNode, this, _1)); } // -------------------------------------------------------------------------- @@ -45,7 +93,7 @@ // -------------------------------------------------------------------------- - bool ProductFileReader::consumeNode(Reader & reader_r) + bool ProductFileReader::Impl::consumeNode(Reader & reader_r) { // dependency block nodes if (_product && consumeDependency(reader_r, _product->deps)) @@ -128,13 +176,27 @@ // -------------------------------------------------------------------------- - data::Product_Ptr ProductFileReader::handoutProduct() + data::Product_Ptr ProductFileReader::Impl::handoutProduct() { data::Product_Ptr ret; ret.swap(_product); return ret; } + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : ProductFileReader + // + /////////////////////////////////////////////////////////////////// + + ProductFileReader::ProductFileReader(const Pathname & product_file, ProcessProduct callback) + : _pimpl(new ProductFileReader::Impl(product_file, callback)) + {} + + + ProductFileReader::~ProductFileReader() + {} + } // ns yum } // ns parser Modified: trunk/libzypp/zypp/parser/yum/ProductFileReader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/ProductFi... ============================================================================== --- trunk/libzypp/zypp/parser/yum/ProductFileReader.h (original) +++ trunk/libzypp/zypp/parser/yum/ProductFileReader.h Mon May 28 16:17:38 2007 @@ -10,13 +10,18 @@ #ifndef ZYPP_PARSER_YUM_PRODUCTFILEREADER_H_ #define ZYPP_PARSER_YUM_PRODUCTFILEREADER_H_ -#include "zypp/base/Function.h" -#include "zypp/parser/xml/Reader.h" #include "zypp/parser/yum/FileReaderBase.h" -#include "zypp/data/ResolvableData.h" namespace zypp { + + namespace data + { + class Product; + DEFINE_PTR_TYPE(Product); + } // ns data + + namespace parser { namespace yum @@ -25,7 +30,7 @@ /** * Reader of products.xml file conforming to RNC definition located - * in zypp/parser/yum/schema/products.rnc + * at zypp/parser/yum/schema/products.rnc. * * \see zypp::data::Product * \see zypp::parser::xml::Reader @@ -47,37 +52,15 @@ * \param callback Function which will process read data. */ ProductFileReader(const Pathname & products_file, ProcessProduct callback); - - private: - - /** - * Callback provided to the XML reader. - * - * \param the xml reader object reading the file - * \return true to tell the reader to continue, false to tell it to stop - * - * \see PrimaryFileReader::consumeNode(xml::Reader) - */ - bool consumeNode(xml::Reader & reader_r); - + /** - * Creates a new \ref data::Product_Ptr, swaps its contents with \ref _product - * and returns it. Used to hand-out the data object to its consumer - * (a \ref ProcessProduct function) after it has been read. + * DTOR. */ - data::Product_Ptr handoutProduct(); + ~ProductFileReader(); private: - /** - * Callback for processing product metadata. - */ - ProcessProduct _callback; - - /** - * Pointer to the \ref zypp::data::Product object for storing the product - * metada. - */ - data::Product_Ptr _product; + class Impl; + RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl; }; Modified: trunk/libzypp/zypp2/parser/yum/YUMParser.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/parser/yum/YUMParse... ============================================================================== --- trunk/libzypp/zypp2/parser/yum/YUMParser.cc (original) +++ trunk/libzypp/zypp2/parser/yum/YUMParser.cc Mon May 28 16:17:38 2007 @@ -6,10 +6,16 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp2/parser/yum/YUMParser.cc + * YUM parser implementation. + */ #include <iostream> + +#include "zypp/ZConfig.h" #include "zypp/base/Logger.h" +#include "zypp/source/yum/YUMResourceType.h" + #include "zypp/parser/yum/RepomdFileReader.h" #include "zypp/parser/yum/PrimaryFileReader.h" #include "zypp/parser/yum/PatchesFileReader.h" @@ -25,6 +31,8 @@ #undef ZYPP_BASE_LOGGER_LOGGROUP #define ZYPP_BASE_LOGGER_LOGGROUP "parser" +using zypp::source::yum::YUMResourceType; + namespace zypp { namespace parser @@ -32,7 +40,8 @@ namespace yum { - // TODO make this through ZYppCallbacks.h + + /** \todo make this through ZYppCallbacks.h */ bool progress_function(ProgressData::value_type p) { std::cout << "Parsing $name_would_come_in_handy [" << p << "%]" << endl; @@ -41,12 +50,140 @@ } - YUMParser::YUMParser( + /** + * Structure encapsulating YUM parser data type and filename. + */ + struct YUMParserJob + { + YUMParserJob(const Pathname & filename, const YUMResourceType & type) + : _filename(filename), _type(type) {} + + const Pathname & filename() const { return _filename; } + const YUMResourceType & type() const { return _type; } + + private: + /** File to be processed */ + Pathname _filename; + /** Type of YUM file */ + YUMResourceType _type; + }; + + + /////////////////////////////////////////////////////////////////////////// + // + // CLASS NAME : YUMParser::Impl + // + class YUMParser::Impl : private base::NonCopyable + { + public: + /** CTOR */ + Impl( + const data::RecordId & repository_id, + data::ResolvableDataConsumer & consumer, + const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() + ); + + /** Implementation of \ref YUMParser::parse(Pathname) */ + void parse(const Pathname &cache_dir); + + /** + * Iterates through parser \ref _jobs and executes them using + * *FileReader classes. + * + * \param path location of the raw repository cache + */ + void doJobs(const Pathname & path); + + /** + * Callback for processing data returned from \ref RepomdFileReader. + * Adds returned files to parser job list (\ref _jobs). + * + * \param loc location of discovered data file + * \param dtype YUM data type + */ + bool repomd_CB(const OnMediaLocation & loc, const YUMResourceType & dtype); + + /** + * Callback for processing packages returned from \ref PrimaryFileReader. + * Uses \ref _consumer to process read package data. + * + * \param package_r pointer to package data + */ + bool primary_CB(const data::Package_Ptr & package_r); + + /** + * Callback for processing data returned from \ref PatchesFileReader. + * Adds discovered patch*.xml files to parser \ref _jobs. + * + * \param loc location of discovered patch file + * \param patch_id (not used so far) + */ + bool patches_CB(const OnMediaLocation &loc, const std::string & patch_id); + + /** + * Callback for processing data returned from \ref PatchFileReader. + * Uses \ref _consumer to process read patch data. + * + * \param patch pointer to patch data + */ + bool patch_CB(const data::Patch_Ptr & patch); + + /** + * Callback for processing data returned from \ref OtherFileReader. + * Uses \ref _consumer to process read changelog data. + * + * \param res_ptr resolvable to which the changelog belongs + * \param changelog read changelog + */ + bool other_CB(const data::Resolvable_Ptr & res_ptr, const Changelog & changelog); + + /** + * Callback for processing data returned from \ref FilelistsFileReader. + * Uses \ref _consumer to process read filelist. + * + * \param res_ptr resolvable to which the filelist belongs. + * \param filenames the read filelist + */ + bool filelist_CB(const data::Resolvable_Ptr & res_ptr, const data::Filenames & filenames); + + /** + * Callback for processing data returned from \ref PatternFileReader. + * Uses \ref _consumer to process read pattern. + * + * \param pattern_ptr pointer to pattern data object + */ + bool pattern_CB(const data::Pattern_Ptr & pattern_ptr); + + /** + * Callback for processing data returned from \ref ProductFileReader. + * Uses \ref _consumer to process read product. + * + * \param product_ptr pointer to product data object + */ + bool product_CB(const data::Product_Ptr & product_ptr); + + private: + /** ID of the repository record in the DB (repositories.id) */ + data::RecordId _repository_id; + + /** Object for processing the read data */ + data::ResolvableDataConsumer & _consumer; + + /** List of parser jobs read from repomd.xml and patches.xml files. */ + std::list<YUMParserJob> _jobs; + + /** Progress reporting object for overall YUM parser progress. */ + ProgressData _ticks; + }; + /////////////////////////////////////////////////////////////////////////// + + + YUMParser::Impl::Impl( const data::RecordId & repository_id, data::ResolvableDataConsumer & consumer, const ProgressData::ReceiverFnc & progress) : - _consumer(consumer), _repository_id(repository_id) + _repository_id(repository_id), _consumer(consumer) { _ticks.name("YUMParser"); _ticks.sendTo(progress); @@ -54,7 +191,7 @@ // ------------------------------------------------------------------------- - bool YUMParser::repomd_CB( + bool YUMParser::Impl::repomd_CB( const OnMediaLocation & loc, const YUMResourceType & dtype) { DBG << "Adding " << dtype @@ -67,7 +204,7 @@ // ------------------------------------------------------------------------- - bool YUMParser::primary_CB(const data::Package_Ptr & package_r) + bool YUMParser::Impl::primary_CB(const data::Package_Ptr & package_r) { _consumer.consumePackage( _repository_id, package_r ); @@ -83,11 +220,11 @@ // ------------------------------------------------------------------------- - bool YUMParser::patches_CB( + bool YUMParser::Impl::patches_CB( const OnMediaLocation & loc, const string & patch_id) { DBG << "Adding patch " << loc.filename() << " to YUMParser jobs " << endl; - + _jobs.push_back(YUMParserJob(loc.filename(), YUMResourceType::PATCH)); return true; @@ -95,7 +232,7 @@ // ------------------------------------------------------------------------- - bool YUMParser::patch_CB(const data::Patch_Ptr & patch) + bool YUMParser::Impl::patch_CB(const data::Patch_Ptr & patch) { _consumer.consumePatch( _repository_id, patch ); @@ -109,7 +246,7 @@ // ------------------------------------------------------------------------- - bool YUMParser::other_CB( + bool YUMParser::Impl::other_CB( const data::Resolvable_Ptr & res_ptr, const Changelog & changelog) { _consumer.consumeChangelog(_repository_id, res_ptr, changelog); @@ -126,7 +263,7 @@ // ------------------------------------------------------------------------- - bool YUMParser::filelist_CB( + bool YUMParser::Impl::filelist_CB( const data::Resolvable_Ptr & res_ptr, const data::Filenames & filenames) { _consumer.consumeFilelist(_repository_id, res_ptr, filenames); @@ -141,9 +278,9 @@ return true; } - // ------------------------------------------------------------------------- + // -------------------------------------------------------------------------- - bool YUMParser::pattern_CB(const data::Pattern_Ptr & product_ptr) + bool YUMParser::Impl::pattern_CB(const data::Pattern_Ptr & product_ptr) { _consumer.consumePattern(_repository_id, product_ptr); @@ -152,9 +289,9 @@ return true; } - // ------------------------------------------------------------------------- + // -------------------------------------------------------------------------- - bool YUMParser::product_CB(const data::Product_Ptr & product_ptr) + bool YUMParser::Impl::product_CB(const data::Product_Ptr & product_ptr) { _consumer.consumeProduct(_repository_id, product_ptr); @@ -164,13 +301,13 @@ return true; } - // ------------------------------------------------------------------------- + // -------------------------------------------------------------------------- - void YUMParser::start(const Pathname &cache_dir) + void YUMParser::Impl::parse(const Pathname &cache_dir) { zypp::parser::yum::RepomdFileReader( cache_dir + "/repodata/repomd.xml", - bind(&YUMParser::repomd_CB, this, _1, _2)); + bind(&YUMParser::Impl::repomd_CB, this, _1, _2)); _ticks.range(_jobs.size()); @@ -181,9 +318,9 @@ _ticks.toMax(); } - // ------------------------------------------------------------------------- + // -------------------------------------------------------------------------- - void YUMParser::doJobs(const Pathname &cache_dir) + void YUMParser::Impl::doJobs(const Pathname &cache_dir) { for(list<YUMParserJob>::const_iterator it = _jobs.begin(); it != _jobs.end(); ++it) @@ -199,7 +336,7 @@ { zypp::parser::yum::PrimaryFileReader( cache_dir + job.filename(), - bind(&YUMParser::primary_CB, this, _1), + bind(&YUMParser::Impl::primary_CB, this, _1), &progress_function); break; } @@ -208,7 +345,7 @@ { zypp::source::yum::PatchesFileReader( cache_dir + job.filename(), - bind(&YUMParser::patches_CB, this, _1, _2)); + bind(&YUMParser::Impl::patches_CB, this, _1, _2)); // reset progress reporter max value (number of jobs changed if // there are patches to parse) _ticks.range(_jobs.size()); @@ -219,7 +356,7 @@ { zypp::parser::yum::PatchFileReader( cache_dir + job.filename(), - bind(&YUMParser::patch_CB, this, _1)); + bind(&YUMParser::Impl::patch_CB, this, _1)); break; } @@ -227,7 +364,7 @@ { WAR << "ignoring other.xml.gz for now..." << endl; /* - zypp::parser::yum::OtherFileReader( + zypp::parser::yum::Impl::OtherFileReader( cache_dir + job.filename(), bind(&YUMParser::other_CB, this, _1, _2), &progress_function); @@ -239,7 +376,7 @@ { zypp::parser::yum::FilelistsFileReader( cache_dir + job.filename(), - bind(&YUMParser::filelist_CB, this, _1, _2), + bind(&YUMParser::Impl::filelist_CB, this, _1, _2), &progress_function); break; } @@ -248,7 +385,7 @@ { zypp::parser::yum::PatternFileReader( cache_dir + job.filename(), - bind(&YUMParser::pattern_CB, this, _1)); + bind(&YUMParser::Impl::pattern_CB, this, _1)); break; } @@ -256,7 +393,7 @@ { zypp::parser::yum::ProductFileReader( cache_dir + job.filename(), - bind(&YUMParser::product_CB, this, _1)); + bind(&YUMParser::Impl::product_CB, this, _1)); break; } @@ -273,9 +410,33 @@ } + /////////////////////////////////////////////////////////////////// + // + // CLASS : YUMParser + // + /////////////////////////////////////////////////////////////////// + + YUMParser::YUMParser( + const data::RecordId & repository_id, + data::ResolvableDataConsumer & consumer, + const ProgressData::ReceiverFnc & progress) + : + _pimpl(new Impl(repository_id, consumer, progress)) + {} + + + YUMParser::~YUMParser() + {} + + + void YUMParser::parse(const Pathname & cache_dir) + { + _pimpl->parse(cache_dir); + } + + } // ns yum } // ns parser } // ns zypp // vim: set ts=2 sts=2 sw=2 et ai: - Modified: trunk/libzypp/zypp2/parser/yum/YUMParser.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/parser/yum/YUMParse... ============================================================================== --- trunk/libzypp/zypp2/parser/yum/YUMParser.h (original) +++ trunk/libzypp/zypp2/parser/yum/YUMParser.h Mon May 28 16:17:38 2007 @@ -6,19 +6,21 @@ | /_____||_| |_| |_| | | | ---------------------------------------------------------------------*/ - +/** \file zypp2/parser/yum/YUMParser.h + * + * YUM parser public API definition. + */ #ifndef YUMPARSER_H_ #define YUMPARSER_H_ -#include "zypp/base/Logger.h" +#include "zypp/base/PtrTypes.h" +#include "zypp/base/NonCopyable.h" + +#include "zypp/data/RecordId.h" #include "zypp/data/ResolvableDataConsumer.h" -#include "zypp/data/ResolvableData.h" -#include "zypp/source/yum/YUMResourceType.h" -#include "zypp/ProgressData.h" -#include "zypp/Changelog.h" +#include "zypp/ProgressData.h" -using zypp::source::yum::YUMResourceType; namespace zypp { @@ -29,25 +31,6 @@ /** - * Structure encapsulating YUM parser data type and filename. - */ - struct YUMParserJob - { - YUMParserJob(const Pathname & filename, const YUMResourceType & type) - : _filename(filename), _type(type) {} - - const Pathname & filename() const { return _filename; } - const YUMResourceType & type() const { return _type; } - - private: - /** File to be processed */ - Pathname _filename; - /** Type of YUM file */ - YUMResourceType _type; - }; - - - /** * YUM metada parser. * * Reads repomd.xml file to get the list of files to parse and enques them @@ -57,24 +40,24 @@ * * * \code - * + * * cache::CacheStore store(dbdir); * data::RecordId repository_id = store.lookupOrAppendRepository(sourceurl, "/"); * * YUMParser parser(repository_id, store, &progress_function); - * parser.start(source_cache_dir); + * parser.parse(source_cache_dir); * * store.commit(); * * \code * - * TODO make the parser configurable, e.g. exclude(FILELISTS_e)? + * \todo make the parser configurable, e.g. exclude(FILELISTS_e)? * * \see RepomdFileReader, PrimaryFileReader, OtherFileReader * \see FilelistsFileReader, PatchesFileReader, PatchFileReader * \see PatternFileReader, ProductFileReader */ - class YUMParser + class YUMParser : private base::NonCopyable { public: @@ -90,106 +73,25 @@ data::ResolvableDataConsumer & consumer, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() ); + + /** + * DTOR + */ + ~YUMParser(); /** * Starts parsing of repository cache dir located at \a path. * * This method uses RepomdFileReader to get a list of parser jobs - * and calls \ref doJobs(Pathname) to do them. - * - * \param path location of the raw repository cache - */ - void start(const Pathname & path); - - private: - /** - * Iterates through parser \ref _jobs and executes them using - * *FileReader classes. + * and calls \ref Impl::doJobs(Pathname) to do them. * * \param path location of the raw repository cache */ - void doJobs(const Pathname & path); - - /** - * Callback for processing data returned from \ref RepomdFileReader. - * Adds returned files to parser job list (\ref _jobs). - * - * \param loc location of discovered data file - * \param dtype YUM data type - */ - bool repomd_CB(const OnMediaLocation & loc, const YUMResourceType & dtype); - - /** - * Callback for processing packages returned from \ref PrimaryFileReader. - * Uses \ref _consumer to process read package data. - * - * \param package_r pointer to package data - */ - bool primary_CB(const data::Package_Ptr & package_r); - - /** - * Callback for processing data returned from \ref PatchesFileReader. - * Adds discovered patch*.xml files to parser \ref _jobs. - * - * \param loc location of discovered patch file - * \param patch_id (not used so far) - */ - bool patches_CB(const OnMediaLocation &loc, const std::string & patch_id); - - /** - * Callback for processing data returned from \ref PatchFileReader. - * Uses \ref _consumer to process read patch data. - * - * \param patch pointer to patch data - */ - bool patch_CB(const data::Patch_Ptr & patch); - - /** - * Callback for processing data returned from \ref OtherFileReader. - * Uses \ref _consumer to process read changelog data. - * - * \param res_ptr resolvable to which the changelog belongs - * \param changelog read changelog - */ - bool other_CB(const data::Resolvable_Ptr & res_ptr, const Changelog & changelog); - - /** - * Callback for processing data returned from \ref FilelistsFileReader. - * Uses \ref _consumer to process read filelist. - * - * \param res_ptr resolvable to which the filelist belongs. - * \param filenames the read filelist - */ - bool filelist_CB(const data::Resolvable_Ptr & res_ptr, const data::Filenames & filenames); - - /** - * Callback for processing data returned from \ref PatternFileReader. - * Uses \ref _consumer to process read pattern. - * - * \param pattern_ptr pointer to pattern data object - */ - bool pattern_CB(const data::Pattern_Ptr & pattern_ptr); - - /** - * Callback for processing data returned from \ref ProductFileReader. - * Uses \ref _consumer to process read product. - * - * \param product_ptr pointer to product data object - */ - bool product_CB(const data::Product_Ptr & product_ptr); + void parse(const Pathname & path); private: - /** Object for processing the read data */ - data::ResolvableDataConsumer & _consumer; - - /** ID of the repository record in the DB (repositories.id) */ - data::RecordId _repository_id; - - /** List of parser jobs read from repomd.xml and patches.xml files. */ - std::list<YUMParserJob> _jobs; - - /** Progress reporting object for overall YUM parser progress. */ - ProgressData _ticks; + class Impl; + RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl; }; @@ -200,4 +102,3 @@ #endif /*YUMPARSER_H_*/ // vim: set ts=2 sts=2 sw=2 et ai: - -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org