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 #include "zypp/TmpPath.h"
00029 
00031 namespace zypp
00032 { 
00033 
00034   namespace source
00035   { 
00036 
00037     DEFINE_PTR_TYPE(SourceImpl);
00038 
00040     //
00041     //  CLASS NAME : SourceImpl
00042     //
00056     class SourceImpl : public base::ReferenceCounted
00057                      , public base::ProvideNumericId<SourceImpl,Source_Ref::NumericId>
00058                      , private base::NonCopyable
00059     {
00060       media::MediaManager media_mgr;
00061 
00062       friend std::ostream & operator<<( std::ostream & str, const SourceImpl & obj );
00063 
00064     public:
00076       void factoryCtor( const media::MediaId & media_r,
00077                         const Pathname & path_r,
00078                         const std::string & alias_r,
00079                         const Pathname cache_dir_r,
00080                         bool base_source,
00081                         bool auto_refresh);
00082 
00084       class Verifier;
00085 
00086     public:
00087 
00089       const ResStore & resolvables(Source_Ref) const
00090       { return resolvables(); }
00091       const ResStore & resolvables() const;
00092       const ResStore resolvables(zypp::Resolvable::Kind kind) const;
00093 
00100       const Pathname provideFile(const Pathname & file,
00101                                  const unsigned media_nr = 1,
00102                                  bool cached = false,
00103                                  bool checkonly = false);
00113       const Pathname tryToProvideFile( const Pathname & file, const unsigned media_nr = 1 );
00114 
00121       const Pathname provideDirTree(const Pathname & path,
00122                                 const unsigned media_nr = 1);
00123 
00124       const void releaseFile(const Pathname & file_r,
00125                              const unsigned media_nr = 1);
00126 
00127       const void releaseDir(const Pathname & path_r,
00128                             const unsigned media_nr = 1,
00129                             const bool recursive = false);
00130 
00131       const Pathname providePackage( Package::constPtr package );
00132 
00139       void dirInfo( const unsigned media_nr,
00140                     std::list<std::string> &retlist,
00141                     const Pathname         &path_r,
00142                     bool                    dots = true) const;
00143 
00144       void changeMedia(const media::MediaId & media_r, const Pathname & path_r);
00145 
00146       const bool enabled() const
00147       { return _enabled; }
00148 
00149       void enable();
00150 
00151       void disable()
00152       { _enabled = false; }
00153 
00154       const bool autorefresh() const
00155       { return _autorefresh; }
00156 
00157       void setAutorefresh( const bool enable_r )
00158       { _autorefresh = enable_r; }
00159 
00160       void refresh();
00161 
00162       virtual void storeMetadata(const Pathname & cache_dir_r);
00163 
00168       virtual Date timestamp() const;
00169 
00170       std::string alias (void) const
00171       { return _alias; }
00172 
00173       void setAlias (const std::string & alias)
00174       { _alias = alias; }
00175 
00176       virtual std::string id (void) const;
00177       virtual void setId (const std::string id_r);
00178       virtual unsigned priority (void) const;
00179       virtual void setPriority (unsigned p);
00180       virtual unsigned priorityUnsubscribed (void) const;
00181       virtual void setPriorityUnsubscribed (unsigned p);
00182       virtual bool subscribed (void) const;
00183       virtual void setSubscribed (bool s);
00184       virtual const Pathname & cacheDir (void);
00185       virtual const std::list<Pathname> publicKeys();
00186 
00187       virtual std::string type(void) const;
00188 
00189       Url url (void) const;
00190       void setUrl( const Url & url );
00191       bool remote () const;
00192       bool baseSource () const
00193       { return _base_source; }
00194 
00195       const Pathname & path (void) const;
00196 
00197       virtual unsigned numberOfMedia(void) const;
00198 
00199       virtual std::string vendor (void) const;
00200 
00201       virtual std::string unique_id (void) const;
00202 
00207       virtual std::string zmdName (void) const;
00208       virtual void setZmdName (const std::string name_r);
00209       virtual std::string zmdDescription (void) const;
00210       virtual void setZmdDescription (const std::string desc_r);
00211 
00212       virtual void redirect(unsigned media_nr, const Url & new_url);
00219       void reattach(const Pathname &attach_point);
00223       void release();
00224 
00235       virtual media::MediaVerifierRef verifier(unsigned media_nr);
00236 
00238       Source_Ref selfSourceRef()
00239       { return Source_Ref( this ); }
00240     protected:
00241 
00242 
00260       const Pathname provideJustFile(const Pathname & path,
00261                                  const unsigned media_nr = 1,
00262                                  bool cached = false,
00263                                  bool checkonly = false);
00264 
00265       void copyLocalMetadata(const Pathname &src, const Pathname &dst) const;
00266 
00270         void resetMediaVerifier();
00271         
00276       Pathname tmpMetadataDir() const;
00277 
00278     protected:
00280       ResStore _store;
00282       Url _url;
00284       Pathname _path;
00286       bool _enabled;
00288       bool _autorefresh;
00290       std::string _alias;
00292       Pathname _cache_dir;
00295       std::string _id;
00297       unsigned _priority;
00299       unsigned _priority_unsubscribed;
00301       bool _subscribed;
00303       bool _base_source;
00304 
00305     private:
00306       mutable shared_ptr<filesystem::TmpDir> _tmp_metadata_dir_ptr;
00308       // no playground below this line ;)
00310     protected:
00315       SourceImpl();
00316 
00326       virtual void factoryInit();
00327 
00329       virtual ~SourceImpl();
00330 
00332       virtual std::ostream & dumpOn( std::ostream & str ) const;
00333 
00335       intrusive_ptr<MediaSet> _media_set;
00336 
00337     private:
00339       virtual void createResolvables(Source_Ref source_r);
00340 
00342       virtual ResStore provideResolvables(Source_Ref source_r, zypp::Resolvable::Kind kind);
00343 
00345       bool _res_store_initialized;
00346 
00347     public:
00352       bool resStoreInitialized () const
00353       { return _res_store_initialized; }
00354 
00355     private:
00357       struct null {};
00358 
00362       SourceImpl( const null & );
00363 
00364     public:
00366       static SourceImpl_Ptr nullimpl()
00367       {
00368         static SourceImpl_Ptr _nullimpl( new SourceImpl( null() ) );
00369         return _nullimpl;
00370       }
00371 
00372     };
00374 
00376     inline std::ostream & operator<<( std::ostream & str, const SourceImpl & obj )
00377     { return obj.dumpOn( str ); }
00378 
00380 
00383     class SourceImpl::Verifier : public media::MediaVerifierBase
00384       {
00385       public:
00387         Verifier (const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1);
00388         /*
00389          ** Check if the specified attached media contains
00390          ** the desired media number (e.g. SLES10 CD1).
00391          */
00392         virtual bool
00393         isDesiredMedia(const media::MediaAccessRef &ref);
00394 
00395       private:
00396         std::string _media_vendor;
00397         std::string _media_id;
00398         media::MediaNr _media_nr;
00399         SourceImpl_Ptr _source;
00400       };
00401 
00403   } // namespace source
00406 } // namespace zypp
00408 #endif // ZYPP_SOURCE_SOURCEIMPL_H

Generated on Thu Jul 6 00:07:24 2006 for zypp by  doxygen 1.4.6