implemented Source::resolvables(kind), susetags only for now
authorStanislav Visnovsky <visnov@suse.cz>
Tue, 28 Feb 2006 12:34:09 +0000 (12:34 +0000)
committerStanislav Visnovsky <visnov@suse.cz>
Tue, 28 Feb 2006 12:34:09 +0000 (12:34 +0000)
zypp/Source.cc
zypp/Source.h
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/susetags/SuseTagsImpl.cc
zypp/source/susetags/SuseTagsImpl.h

index de4a1fd..5d04fa6 100644 (file)
@@ -54,7 +54,7 @@ namespace zypp
   const ResStore & Source_Ref::resolvables() const
   { return _pimpl->resolvables(); }
 
-  const ResStore Source_Ref::resolvables(zypp::Resolvable::Kind kind) const
+  const ResStore Source_Ref::resolvables(zypp::Resolvable::Kind kind) const
   { return _pimpl->resolvables(kind); }
 
   const Pathname Source_Ref::provideFile(const Pathname & file_r,
index 28703bc..b1fcaae 100644 (file)
@@ -70,7 +70,7 @@ namespace zypp
     const ResStore & resolvables() const;
 
     /** All resolvables of a given kind provided by this source. */
-    const ResStore resolvables(zypp::Resolvable::Kind kind) const;
+    const ResStore resolvables(zypp::Resolvable::Kind kind) const;
 
     /** Provide a file to local filesystem */
     const Pathname provideFile(const Pathname & file_r,
index 0cc1f06..a898158 100644 (file)
@@ -98,11 +98,10 @@ namespace zypp
       return _store;
      }
 
-    const ResStore SourceImpl::resolvables(zypp::Resolvable::Kind kind) const
+    const ResStore SourceImpl::resolvables(zypp::Resolvable::Kind kind) const
     {
-      static ResStore result;
-      // FIXME      
-      return result;
+      Source_Ref self( const_cast<SourceImpl*>(this)->selfSourceRef() );
+      return const_cast<SourceImpl*>(this)->provideResolvables(self, kind);
     }
 
     const Pathname SourceImpl::provideFile(const Pathname & file_r,
@@ -198,6 +197,12 @@ namespace zypp
     void SourceImpl::createResolvables(Source_Ref source_r)
     {}
 
+    ResStore SourceImpl::provideResolvables(Source_Ref source_r, zypp::Resolvable::Kind kind)
+    {
+       WAR << "provideResolvables not implemented by the source" << endl;
+       return ResStore();
+    }
+
     void SourceImpl::storeMetadata(const Pathname & cache_dir_r)
     {}
 
index ccdcacd..d116b5e 100644 (file)
@@ -81,7 +81,7 @@ namespace zypp
       const ResStore & resolvables(Source_Ref) const
       { return resolvables(); }
       const ResStore & resolvables() const;
-      const ResStore resolvables(zypp::Resolvable::Kind kind) const;
+      const ResStore resolvables(zypp::Resolvable::Kind kind) const;
 
       /**
        * Provide a file to local filesystem
@@ -228,6 +228,10 @@ namespace zypp
     private:
       /** Late initialize the ResStore. */
       virtual void createResolvables(Source_Ref source_r);
+
+      /** Provide only resolvable of a certain kind. */
+      virtual ResStore provideResolvables(Source_Ref source_r, zypp::Resolvable::Kind kind);
+
       /** Whether the ResStore is initialized. */
       bool _res_store_initialized;
 
index d46b3cb..da4b8bb 100644 (file)
@@ -182,9 +182,69 @@ namespace zypp
       void SuseTagsImpl::createResolvables(Source_Ref source_r)
       {
         callback::SendReport<CreateSourceReport> report;
-        Pathname p;
         report->startData( url() );
-        
+
+       provideProducts ( source_r, _store );        
+       providePackages ( source_r, _store );
+       provideSelections ( source_r, _store );
+       providePatterns ( source_r, _store );
+
+        report->finishData( url(), CreateSourceReport::NO_ERROR, "" );
+      }
+
+      ResStore SuseTagsImpl::provideResolvables(Source_Ref source_r, Resolvable::Kind kind)
+      {
+        callback::SendReport<CreateSourceReport> report;
+        report->startData( url() );
+
+       ResStore store;
+       
+       if ( kind == ResTraits<Product>::kind ) 
+           provideProducts ( source_r, store );                
+       else if ( kind == ResTraits<Package>::kind )
+           providePackages ( source_r, store );
+       else if ( kind == ResTraits<Selection>::kind )
+           provideSelections ( source_r, store );
+       else if ( kind == ResTraits<Pattern>::kind )
+           providePatterns ( source_r, store );
+
+        report->finishData( url(), CreateSourceReport::NO_ERROR, "" );
+       
+       return store;
+      }
+
+      ///////////////////////////////////////////////////////////////////
+      //
+      //       METHOD NAME : SuseTagsImpl::~SuseTagsImpl
+      //       METHOD TYPE : Dtor
+      //
+      SuseTagsImpl::~SuseTagsImpl()
+      {}
+
+      Pathname SuseTagsImpl::sourceDir( const NVRAD& nvrad )
+      {
+#warning Not using <DATADIR>
+        return Pathname( "/suse/" + nvrad.arch.asString() + "/");
+      }
+
+      media::MediaVerifierRef SuseTagsImpl::verifier(media::MediaNr media_nr)
+      {
+       return media::MediaVerifierRef(
+           new SourceImpl::Verifier (_vendor, _media_id, media_nr));
+      }
+
+      unsigned SuseTagsImpl::numberOfMedia(void) const
+      { return _media_count; }
+
+      std::string SuseTagsImpl::vendor (void) const
+      { return _vendor; }
+
+      std::string SuseTagsImpl::unique_id (void) const
+      { return _media_id; }
+
+      void SuseTagsImpl::provideProducts(Source_Ref source_r, ResStore &store)
+      {
+        Pathname p;
         bool cache = cacheExists();
 
         if ( cache )
@@ -207,13 +267,18 @@ namespace zypp
           Product::Ptr product = parseContentFile( _content_file, factory.createFrom(this) );
       
           MIL << "Product: " << product->displayName() << endl;
-          _store.insert( product );
+          store.insert( product );
         }
         catch (Exception & excpt_r) {
           ERR << "cannot parse content file" << endl;
         }
+      }
   
-        p = cache ? _data_dir + "packages" : provideFile( _data_dir + "packages");
+      void SuseTagsImpl::providePackages(Source_Ref source_r, ResStore &store)
+      {
+        bool cache = cacheExists();
+
+        Pathname p = cache ? _data_dir + "packages" : provideFile( _data_dir + "packages");
         DBG << "Going to parse " << p << endl;
         PkgContent content( parsePackages( source_r, this, p ) );
 
@@ -243,12 +308,20 @@ namespace zypp
         {
           it->second->_diskusage = du[it->first /* NVRAD */];
           Package::Ptr pkg = detail::makeResolvableFromImpl( it->first, it->second );
-          _store.insert( pkg );
+          store.insert( pkg );
         }
         DBG << "SuseTagsImpl (fake) from " << p << ": "
             << content.size() << " packages" << endl;
+      }
+
+      void SuseTagsImpl::provideSelections(Source_Ref source_r, ResStore &store)
+      {
+        bool cache = cacheExists();
+       
+       Pathname p;
 
         bool file_found = true;
+
         // parse selections
         try {
           p = cache ? _data_dir + "selections" : provideFile( _data_dir + "selections");
@@ -278,14 +351,20 @@ namespace zypp
             DBG << "Selection:" << sel << endl;
       
             if (sel)
-              _store.insert( sel );
+              store.insert( sel );
       
             DBG << "Parsing of " << file << " done" << endl;
           }
         }
+      }
+
+      void SuseTagsImpl::providePatterns(Source_Ref source_r, ResStore &store)
+      {
+        bool cache = cacheExists();
+       Pathname p;
 
         // parse patterns
-        file_found = true;
+        bool file_found = true;
 
         try {
           p = cache ? _data_dir + "patterns" : provideFile( _data_dir + "patterns");
@@ -322,38 +401,8 @@ namespace zypp
             DBG << "Parsing of " << file << " done" << endl;
           }
         }
-      
-        report->finishData( url(), CreateSourceReport::NO_ERROR, "" );
       }
-      ///////////////////////////////////////////////////////////////////
-      //
-      //       METHOD NAME : SuseTagsImpl::~SuseTagsImpl
-      //       METHOD TYPE : Dtor
-      //
-      SuseTagsImpl::~SuseTagsImpl()
-      {}
-
-      Pathname SuseTagsImpl::sourceDir( const NVRAD& nvrad )
-      {
-#warning Not using <DATADIR>
-        return Pathname( "/suse/" + nvrad.arch.asString() + "/");
-      }
-
-      media::MediaVerifierRef SuseTagsImpl::verifier(media::MediaNr media_nr)
-      {
-    return media::MediaVerifierRef(
-      new SourceImpl::Verifier (_vendor, _media_id, media_nr));
-      }
-
-      unsigned SuseTagsImpl::numberOfMedia(void) const
-      { return _media_count; }
-
-      std::string SuseTagsImpl::vendor (void) const
-      { return _vendor; }
-
-      std::string SuseTagsImpl::unique_id (void) const
-      { return _media_id; }
-
+      
       ///////////////////////////////////////////////////////////////////
       //
       //       METHOD NAME : SuseTagsImpl::dumpOn
index f77102b..64bf626 100644 (file)
@@ -50,6 +50,9 @@ namespace zypp
 
       public:
         virtual void createResolvables(Source_Ref source_r);
+
+       /** Provide only resolvables of a certain kind. */
+        virtual ResStore provideResolvables(Source_Ref source_r, zypp::Resolvable::Kind kind);
        
         virtual std::string type(void) const
         { return "YaST"; }
@@ -79,6 +82,11 @@ namespace zypp
         */
         virtual void factoryInit();
        
+       void provideProducts(Source_Ref source_r, ResStore& store);
+       void providePackages(Source_Ref source_r, ResStore& store);
+       void provideSelections(Source_Ref source_r, ResStore& store);
+       void providePatterns(Source_Ref source_r, ResStore& store);
+       
         unsigned _media_count;
        
         Pathname _data_dir;