OtherFileReader.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include "zypp/base/Logger.h"
00013 #include "zypp/parser/xml/Reader.h"
00014 #include "zypp/data/ResolvableData.h"
00015 #include "zypp/Changelog.h"
00016 #include "zypp/base/UserRequestException.h"
00017 
00018 #include "zypp/parser/yum/OtherFileReader.h"
00019 
00020 #undef ZYPP_BASE_LOGGER_LOGGROUP
00021 #define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
00022 
00023 using namespace std;
00024 using namespace zypp::xml;
00025 
00026 namespace zypp
00027 {
00028   namespace parser
00029   {
00030     namespace yum
00031     {
00032 
00033 
00035   //
00036   //  CLASS NAME : OtherFileReader::Impl
00037   //
00038   class OtherFileReader::Impl : private base::NonCopyable
00039   {
00040   public:
00041     Impl(
00042     const Pathname & other_file,
00043     const ProcessPackage & callback,
00044     const ProgressData::ReceiverFnc & progress);
00045 
00046   public:
00047 
00051     bool consumeNode(xml::Reader & reader_r);
00052 
00058     data::Resolvable_Ptr handoutResolvable();
00059 
00060   private:
00061 
00066     zypp::data::Resolvable_Ptr _resolvable;
00067 
00071     Changelog _changelog;
00072 
00076     ProcessPackage _callback;
00077 
00081     ProgressData _ticks;
00082   };
00084 
00085   OtherFileReader::Impl::Impl(
00086       const Pathname & other_file,
00087       const ProcessPackage & callback,
00088       const ProgressData::ReceiverFnc & progress)
00089     :
00090       _callback(callback)
00091   {
00092     _ticks.sendTo(progress);
00093     _ticks.name("other.xml.gz");
00094 
00095     Reader reader(other_file);
00096     MIL << "Reading " << other_file << endl;
00097     reader.foreachNode(bind(&OtherFileReader::Impl::consumeNode, this, _1));
00098   }
00099 
00100   // --------------------------------------------------------------------------
00101 
00102   /*
00103    * xpath and multiplicity of processed nodes are included in the code
00104    * for convenience:
00105    *
00106    * // xpath: <xpath> (?|*|+)
00107    *
00108    * if multiplicity is ommited, then the node has multiplicity 'one'.
00109    */
00110 
00111   // --------------------------------------------------------------------------
00112 
00113   bool OtherFileReader::Impl::consumeNode(Reader & reader_r)
00114   {
00115     if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
00116     {
00117       // xpath: /otherdata
00118       if (reader_r->name() == "otherdata")
00119       {
00120         unsigned total_packages;
00121         zypp::str::strtonum(reader_r->getAttribute("packages").asString(), total_packages);
00122         _ticks.range(total_packages);
00123         _ticks.toMin();
00124         return true;
00125       }
00126 
00127       // xpath: /otherdata/package (+)
00128       if (reader_r->name() == "package")
00129       {
00130         _resolvable = new data::Resolvable;
00131         _changelog.clear();
00132 
00133         _resolvable->name = reader_r->getAttribute("name").asString();
00134         _resolvable->arch = Arch(reader_r->getAttribute("arch").asString());
00135 
00136         return true;
00137       }
00138 
00139       // xpath: /otherdata/package/version
00140       if (reader_r->name() == "version")
00141       {
00142         _resolvable->edition = Edition(reader_r->getAttribute("ver").asString(),
00143                                     reader_r->getAttribute("rel").asString(),
00144                                     reader_r->getAttribute("epoch").asString());
00145         return true;
00146       }
00147 
00148       // xpath: /otherdata/package/changelog (*)
00149       if (reader_r->name() == "changelog")
00150       {
00151         ChangelogEntry entry(
00152               Date(reader_r->getAttribute("date").asString()),
00153               reader_r->getAttribute("author").asString(),
00154               reader_r.nodeText().asString());
00155         _changelog.push_back(entry);
00156         return true;
00157       }
00158     }
00159 
00160     else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
00161     {
00162       // xpath: /otherdata/package
00163       if (reader_r->name() == "package")
00164       {
00165         if (_callback && !_changelog.empty())
00166           _callback(handoutResolvable(), _changelog);
00167 
00168         if (!_ticks.incr())
00169           ZYPP_THROW(AbortRequestException());
00170 
00171         return true;
00172       }
00173 
00174       // xpath: /otherdata
00175       if (reader_r->name() == "otherdata")
00176       {
00177         _ticks.toMax();
00178         return true;
00179       }
00180     }
00181 
00182     return true;
00183   }
00184 
00185   // --------------------------------------------------------------------------
00186 
00187   data::Resolvable_Ptr OtherFileReader::Impl::handoutResolvable()
00188   {
00189     data::Resolvable_Ptr ret;
00190     ret.swap(_resolvable);
00191     return ret;
00192   }
00193 
00194 
00196   //
00197   //  CLASS NAME : OtherFileReader
00198   //
00200 
00201   OtherFileReader::OtherFileReader(
00202       const Pathname & other_file,
00203       const ProcessPackage & callback,
00204       const ProgressData::ReceiverFnc & progress)
00205     :
00206       _pimpl(new Impl(other_file, callback, progress))
00207   {}
00208 
00209   OtherFileReader::~OtherFileReader()
00210   {}
00211 
00212 
00213     } // ns yum
00214   } // ns parser
00215 } // ns zypp
00216 
00217 // vim: set ts=2 sts=2 sw=2 et ai:

Generated on Tue Sep 25 19:23:04 2007 for libzypp by  doxygen 1.5.3