00001
00002
00003
00004
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/CheckSum.h"
00027 #include "zypp/media/MediaManager.h"
00028 #include "zypp/source/MediaSet.h"
00029 #include "zypp/TmpPath.h"
00030
00032 namespace zypp
00033 {
00034
00035 namespace source
00036 {
00037
00038 DEFINE_PTR_TYPE(SourceImpl);
00039
00046 class SourceProber
00047 {
00048 public:
00049 SourceProber( media::MediaAccessId media_id, const Pathname &path )
00050 : _media_id(media_id), _path(path)
00051 {}
00052
00053 virtual ~SourceProber()
00054 {}
00055
00056 virtual bool operator()() = 0;
00057
00058 protected:
00059 media::MediaAccessId _media_id;
00060 Pathname _path;
00061 };
00062
00063 class SourceEventHandler
00064 {
00065 public:
00066 typedef boost::shared_ptr<SourceEventHandler> Ptr;
00067 SourceEventHandler( boost::function<void (int)> fnc )
00068 : _fnc(fnc)
00069 {
00070
00071 };
00072 ~SourceEventHandler()
00073 {};
00074 void progress(int p)
00075 {
00076 if (_fnc)
00077 _fnc(p);
00078 }
00079
00080 private:
00081 boost::function<void (int)> _fnc;
00082 int _file_size;
00083 int no_lines;
00084 };
00085
00087
00088
00089
00103 class SourceImpl : public base::ReferenceCounted
00104 , public base::ProvideNumericId<SourceImpl,Source_Ref::NumericId>
00105 , private base::NonCopyable
00106 {
00107 media::MediaManager media_mgr;
00108
00109 friend std::ostream & operator<<( std::ostream & str, const SourceImpl & obj );
00110
00111 public:
00123 void factoryCtor( const media::MediaId & media_r,
00124 const Pathname & path_r,
00125 const std::string & alias_r,
00126 const Pathname cache_dir_r,
00127 bool base_source, bool auto_refresh);
00128
00130 class Verifier;
00131
00132 public:
00133
00135 const ResStore & resolvables(Source_Ref) const
00136 { return resolvables(); }
00137 const ResStore & resolvables() const;
00138 const ResStore resolvables(zypp::Resolvable::Kind kind) const;
00139
00146 const Pathname provideFile(const Pathname & file,
00147 const unsigned media_nr = 1,
00148 bool cached = false,
00149 bool checkonly = false);
00159 const Pathname tryToProvideFile( const Pathname & file, const unsigned media_nr = 1 );
00160
00167 const Pathname provideDirTree(const Pathname & path,
00168 const unsigned media_nr = 1);
00169
00170 const void releaseFile(const Pathname & file_r,
00171 const unsigned media_nr = 1);
00172
00173 const void releaseDir(const Pathname & path_r,
00174 const unsigned media_nr = 1,
00175 const bool recursive = false);
00176
00177 const Pathname providePackage( Package::constPtr package );
00178
00185 void dirInfo( const unsigned media_nr,
00186 std::list<std::string> &retlist,
00187 const Pathname &path_r,
00188 bool dots = true) const;
00189
00190 void changeMedia(const media::MediaId & media_r, const Pathname & path_r);
00191
00192 bool enabled() const;
00193 void enable();
00194 void disable();
00195 bool autorefresh() const;
00196 void setAutorefresh( bool enable_r );
00197 void refresh();
00198
00199 virtual void storeMetadata(const Pathname & cache_dir_r);
00200
00205 virtual Date timestamp() const;
00206
00207 virtual std::string checksum() const;
00208
00209 std::string alias (void) const
00210 { return _alias; }
00211
00212 void setAlias (const std::string & alias)
00213 { _alias = alias; }
00214
00215 virtual std::string id (void) const;
00216 virtual void setId (const std::string id_r);
00217 virtual unsigned priority (void) const;
00218 virtual void setPriority (unsigned p);
00219 virtual unsigned priorityUnsubscribed (void) const;
00220 virtual void setPriorityUnsubscribed (unsigned p);
00221 virtual bool subscribed (void) const;
00222 virtual void setSubscribed (bool s);
00223 virtual const Pathname & cacheDir (void);
00224 virtual const std::list<Pathname> publicKeys();
00225
00226 virtual std::string type(void) const;
00227
00228 Url url (void) const;
00229 void setUrl( const Url & url );
00230 bool remote () const;
00231 bool baseSource () const
00232 { return _base_source; }
00233
00234 const Pathname & path (void) const;
00235
00236 virtual unsigned numberOfMedia(void) const;
00237
00238 virtual std::string vendor (void) const;
00239
00240 virtual std::string unique_id (void) const;
00241
00246 virtual std::string zmdName (void) const;
00247 virtual void setZmdName (const std::string name_r);
00248 virtual std::string zmdDescription (void) const;
00249 virtual void setZmdDescription (const std::string desc_r);
00250
00251 virtual void redirect(unsigned media_nr, const Url & new_url);
00258 void reattach(const Pathname &attach_point);
00262 void release();
00263
00274 virtual media::MediaVerifierRef verifier(unsigned media_nr);
00275
00276 virtual std::set<zypp::Resolvable::Kind> resolvableKinds() const;
00277
00279 Source_Ref selfSourceRef()
00280 { return Source_Ref( this ); }
00281 protected:
00282
00283
00301 const Pathname provideJustFile(const Pathname & path,
00302 const unsigned media_nr = 1,
00303 bool cached = false,
00304 bool checkonly = false);
00305
00306 void copyLocalMetadata(const Pathname &src, const Pathname &dst) const;
00307
00312 Pathname tmpMetadataDir() const;
00313
00317 void resetMediaVerifier();
00318
00325 void getPossiblyCachedMetadataFile( const Pathname &file_to_download, const Pathname &destination, const Pathname &cached_file, const CheckSum &checksum );
00326
00327 protected:
00329 ResStore _store;
00331 Url _url;
00333 Pathname _path;
00335 bool _enabled;
00337 bool _autorefresh;
00339 std::string _alias;
00341 Pathname _cache_dir;
00344 std::string _id;
00346 unsigned _priority;
00348 unsigned _priority_unsubscribed;
00350 bool _subscribed;
00352 bool _base_source;
00353
00354 private:
00355 mutable shared_ptr<filesystem::TmpDir> _tmp_metadata_dir_ptr;
00357
00359 protected:
00364 SourceImpl();
00365
00375 virtual void factoryInit();
00376
00378 virtual ~SourceImpl();
00379
00381 virtual std::ostream & dumpOn( std::ostream & str ) const;
00382
00384 intrusive_ptr<MediaSet> _media_set;
00385
00386 private:
00388 virtual void createResolvables(Source_Ref source_r);
00389
00391 virtual ResStore provideResolvablesByKind(Source_Ref source_r, zypp::Resolvable::Kind kind);
00392
00394 bool _res_store_initialized;
00395
00396 public:
00401 bool resStoreInitialized () const
00402 { return _res_store_initialized; }
00403
00404 private:
00406 struct null {};
00407
00411 SourceImpl( const null & );
00412
00413 public:
00415 static SourceImpl_Ptr nullimpl()
00416 {
00417 static SourceImpl_Ptr _nullimpl( new SourceImpl( null() ) );
00418 return _nullimpl;
00419 }
00420
00421 };
00423
00425 inline std::ostream & operator<<( std::ostream & str, const SourceImpl & obj )
00426 { return obj.dumpOn( str ); }
00427
00429
00432 class SourceImpl::Verifier : public media::MediaVerifierBase
00433 {
00434 public:
00436 Verifier (const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1);
00437
00438
00439
00440
00441 virtual bool
00442 isDesiredMedia(const media::MediaAccessRef &ref);
00443
00444 private:
00445 std::string _media_vendor;
00446 std::string _media_id;
00447 media::MediaNr _media_nr;
00448 SourceImpl_Ptr _source;
00449 };
00450
00452 }
00455 }
00457 #endif // ZYPP_SOURCE_SOURCEIMPL_H