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 
00163       std::string alias (void) const
00164       { return _alias; }
00165 
00166       void setAlias (const std::string & alias)
00167       { _alias = alias; }
00168 
00169       virtual std::string id (void) const;
00170       virtual void setId (const std::string id_r);
00171       virtual unsigned priority (void) const;
00172       virtual void setPriority (unsigned p);
00173       virtual unsigned priorityUnsubscribed (void) const;
00174       virtual void setPriorityUnsubscribed (unsigned p);
00175       virtual bool subscribed (void) const;
00176       virtual void setSubscribed (bool s);
00177       virtual const Pathname & cacheDir (void);
00178       virtual const std::list<Pathname> publicKeys();
00179 
00180       virtual std::string type(void) const;
00181 
00182       Url url (void) const;
00183       void setUrl( const Url & url );
00184       bool remote () const;
00185       bool baseSource () const
00186       { return _base_source; }
00187 
00188       const Pathname & path (void) const;
00189 
00190       virtual unsigned numberOfMedia(void) const;
00191 
00192       virtual std::string vendor (void) const;
00193 
00194       virtual std::string unique_id (void) const;
00195 
00200       virtual std::string zmdName (void) const;
00201       virtual void setZmdName (const std::string name_r);
00202       virtual std::string zmdDescription (void) const;
00203       virtual void setZmdDescription (const std::string desc_r);
00204 
00205       virtual void redirect(unsigned media_nr, const Url & new_url);
00212       void reattach(const Pathname &attach_point);
00216       void release();
00217 
00228       virtual media::MediaVerifierRef verifier(unsigned media_nr);
00229 
00230     protected:
00232       Source_Ref selfSourceRef()
00233       { return Source_Ref( this ); }
00234 
00252       const Pathname provideJustFile(const Pathname & path,
00253                                  const unsigned media_nr = 1,
00254                                  bool cached = false,
00255                                  bool checkonly = false);
00256 
00257 
00258     protected:
00260       ResStore _store;
00262       Url _url;
00264       Pathname _path;
00266       bool _enabled;
00268       bool _autorefresh;
00270       std::string _alias;
00272       Pathname _cache_dir;
00275       std::string _id;
00277       unsigned _priority;
00279       unsigned _priority_unsubscribed;
00281       bool _subscribed;
00283       bool _base_source;
00284 
00286       // no playground below this line ;)
00288     protected:
00293       SourceImpl();
00294 
00304       virtual void factoryInit();
00305 
00307       virtual ~SourceImpl();
00308 
00310       virtual std::ostream & dumpOn( std::ostream & str ) const;
00311 
00313       intrusive_ptr<MediaSet> _media_set;
00314 
00315     private:
00317       virtual void createResolvables(Source_Ref source_r);
00318 
00320       virtual ResStore provideResolvables(Source_Ref source_r, zypp::Resolvable::Kind kind);
00321 
00323       bool _res_store_initialized;
00324 
00325     private:
00327       struct null {};
00328 
00332       SourceImpl( const null & )
00333       : base::ProvideNumericId<SourceImpl,Source_Ref::NumericId>( NULL )
00334       , _res_store_initialized(true)
00335       {}
00336 
00337     public:
00339       static SourceImpl_Ptr nullimpl()
00340       {
00341         static SourceImpl_Ptr _nullimpl( new SourceImpl( null() ) );
00342         return _nullimpl;
00343       }
00344 
00345     };
00347 
00349     inline std::ostream & operator<<( std::ostream & str, const SourceImpl & obj )
00350     { return obj.dumpOn( str ); }
00351 
00353 
00356     class SourceImpl::Verifier : public media::MediaVerifierBase
00357       {
00358       public:
00360         Verifier (const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1);
00361         /*
00362          ** Check if the specified attached media contains
00363          ** the desired media number (e.g. SLES10 CD1).
00364          */
00365         virtual bool
00366         isDesiredMedia(const media::MediaAccessRef &ref);
00367 
00368       private:
00369         std::string _media_vendor;
00370         std::string _media_id;
00371         media::MediaNr _media_nr;
00372         SourceImpl_Ptr _source;
00373       };
00374 
00376   } // namespace source
00379 } // namespace zypp
00381 #endif // ZYPP_SOURCE_SOURCEIMPL_H

Generated on Thu May 4 16:03:26 2006 for zypp by  doxygen 1.4.6