SourceImpl.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_SOURCE_SOURCEIMPL_H
00013 #define ZYPP_SOURCE_SOURCEIMPL_H
00014 
00015 #include <iosfwd>
00016 #include <string>
00017 
00018 #include "zypp/base/ReferenceCounted.h"
00019 #include "zypp/base/NonCopyable.h"
00020 #include "zypp/base/PtrTypes.h"
00021 #include "zypp/base/ProvideNumericId.h"
00022 
00023 #include "zypp/Source.h"
00024 #include "zypp/ResStore.h"
00025 #include "zypp/Pathname.h"
00026 #include "zypp/media/MediaManager.h"
00027 #include "zypp/source/MediaSet.h"
00028 
00030 namespace zypp
00031 { 
00032 
00033   namespace source
00034   { 
00035 
00036     DEFINE_PTR_TYPE(SourceImpl);
00037 
00039     //
00040     //  CLASS NAME : SourceImpl
00041     //
00055     class SourceImpl : public base::ReferenceCounted
00056                      , public base::ProvideNumericId<SourceImpl,Source_Ref::NumericId>
00057                      , private base::NonCopyable
00058     {
00059       media::MediaManager media_mgr;
00060 
00061       friend std::ostream & operator<<( std::ostream & str, const SourceImpl & obj );
00062 
00063     public:
00075       void factoryCtor( const media::MediaId & media_r,
00076                         const Pathname & path_r = "/",
00077                         const std::string & alias_r = "",
00078                         const Pathname cache_dir_r = "",
00079                         const bool base_source = false);
00080 
00082       class Verifier;
00083 
00084     public:
00085 
00087       const ResStore & resolvables(Source_Ref) const
00088       { return resolvables(); }
00089       const ResStore & resolvables() const;
00090       const ResStore resolvables(zypp::Resolvable::Kind kind) const;
00091 
00098       const Pathname provideFile(const Pathname & file,
00099                                  const unsigned media_nr = 1,
00100                                  bool cached = false,
00101                                  bool checkonly = false);
00111       const Pathname tryToProvideFile( const Pathname & file, const unsigned media_nr = 1 );
00112 
00119       const Pathname provideDirTree(const Pathname & path,
00120                                 const unsigned media_nr = 1);
00121 
00122       const void releaseFile(const Pathname & file_r,
00123                              const unsigned media_nr = 1);
00124 
00125       const void releaseDir(const Pathname & path_r,
00126                             const unsigned media_nr = 1,
00127                             const bool recursive = false);
00128 
00129       const Pathname providePackage( Package::constPtr package );
00130       const Pathname providePackageInteractive( Package::constPtr package );
00131       
00138       void dirInfo( const unsigned media_nr,
00139                     std::list<std::string> &retlist,
00140                     const Pathname         &path_r,
00141                     bool                    dots = true) const;
00142 
00143       void changeMedia(const media::MediaId & media_r, const Pathname & path_r);
00144 
00145       const bool enabled() const
00146       { return _enabled; }
00147 
00148       void enable();
00149 
00150       void disable()
00151       { _enabled = false; }
00152 
00153       const bool autorefresh() const
00154       { return _autorefresh; }
00155 
00156       void setAutorefresh( const bool enable_r )
00157       { _autorefresh = enable_r; }
00158 
00159       void refresh();
00160 
00161       virtual void storeMetadata(const Pathname & cache_dir_r);
00162       
00167       virtual Date timestamp() const;
00168 
00169       std::string alias (void) const
00170       { return _alias; }
00171 
00172       void setAlias (const std::string & alias)
00173       { _alias = alias; }
00174 
00175       virtual std::string id (void) const;
00176       virtual void setId (const std::string id_r);
00177       virtual unsigned priority (void) const;
00178       virtual void setPriority (unsigned p);
00179       virtual unsigned priorityUnsubscribed (void) const;
00180       virtual void setPriorityUnsubscribed (unsigned p);
00181       virtual bool subscribed (void) const;
00182       virtual void setSubscribed (bool s);
00183       virtual const Pathname & cacheDir (void);
00184       virtual const std::list<Pathname> publicKeys();
00185 
00186       virtual std::string type(void) const;
00187 
00188       Url url (void) const;
00189       void setUrl( const Url & url );
00190       bool remote () const;
00191       bool baseSource () const
00192       { return _base_source; }
00193 
00194       const Pathname & path (void) const;
00195 
00196       virtual unsigned numberOfMedia(void) const;
00197 
00198       virtual std::string vendor (void) const;
00199 
00200       virtual std::string unique_id (void) const;
00201 
00206       virtual std::string zmdName (void) const;
00207       virtual void setZmdName (const std::string name_r);
00208       virtual std::string zmdDescription (void) const;
00209       virtual void setZmdDescription (const std::string desc_r);
00210 
00211       virtual void redirect(unsigned media_nr, const Url & new_url);
00218       void reattach(const Pathname &attach_point);
00222       void release();
00223 
00234       virtual media::MediaVerifierRef verifier(unsigned media_nr);
00235 
00237       Source_Ref selfSourceRef()
00238       { return Source_Ref( this ); }
00239     protected:
00240       
00241 
00259       const Pathname provideJustFile(const Pathname & path,
00260                                  const unsigned media_nr = 1,
00261                                  bool cached = false,
00262                                  bool checkonly = false);
00263 
00264       void copyLocalMetadata(const Pathname &src, const Pathname &dst) const;
00265     protected:
00267       ResStore _store;
00269       Url _url;
00271       Pathname _path;
00273       bool _enabled;
00275       bool _autorefresh;
00277       std::string _alias;
00279       Pathname _cache_dir;
00282       std::string _id;
00284       unsigned _priority;
00286       unsigned _priority_unsubscribed;
00288       bool _subscribed;
00290       bool _base_source;
00291 
00293       // no playground below this line ;)
00295     protected:
00300       SourceImpl();
00301 
00311       virtual void factoryInit();
00312 
00314       virtual ~SourceImpl();
00315 
00317       virtual std::ostream & dumpOn( std::ostream & str ) const;
00318 
00320       intrusive_ptr<MediaSet> _media_set;
00321 
00322     private:
00324       virtual void createResolvables(Source_Ref source_r);
00325 
00327       virtual ResStore provideResolvables(Source_Ref source_r, zypp::Resolvable::Kind kind);
00328 
00330       bool _res_store_initialized;
00331 
00332     public:
00337       bool resStoreInitialized () const
00338       { return _res_store_initialized; }
00339 
00340     private:
00342       struct null {};
00343 
00347       SourceImpl( const null & )
00348       : base::ProvideNumericId<SourceImpl,Source_Ref::NumericId>( NULL )
00349       , _res_store_initialized(true)
00350       {}
00351 
00352     public:
00354       static SourceImpl_Ptr nullimpl()
00355       {
00356         static SourceImpl_Ptr _nullimpl( new SourceImpl( null() ) );
00357         return _nullimpl;
00358       }
00359 
00360     };
00362 
00364     inline std::ostream & operator<<( std::ostream & str, const SourceImpl & obj )
00365     { return obj.dumpOn( str ); }
00366 
00368 
00371     class SourceImpl::Verifier : public media::MediaVerifierBase
00372       {
00373       public:
00375         Verifier (const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1);
00376         /*
00377          ** Check if the specified attached media contains
00378          ** the desired media number (e.g. SLES10 CD1).
00379          */
00380         virtual bool
00381         isDesiredMedia(const media::MediaAccessRef &ref);
00382 
00383       private:
00384         std::string _media_vendor;
00385         std::string _media_id;
00386         media::MediaNr _media_nr;
00387         SourceImpl_Ptr _source;
00388       };
00389 
00391   } // namespace source
00394 } // namespace zypp
00396 #endif // ZYPP_SOURCE_SOURCEIMPL_H

Generated on Mon Jun 5 19:10:36 2006 for zypp by  doxygen 1.4.6