00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_TARGET_COMMITPACKAGECACHEREADAHEAD_H
00013 #define ZYPP_TARGET_COMMITPACKAGECACHEREADAHEAD_H
00014
00015 #include <map>
00016
00017 #include "zypp/base/Logger.h"
00018 #include "zypp/base/Exception.h"
00019 #include "zypp/base/DefaultIntegral.h"
00020
00021 #include "zypp/Repository.h"
00022 #include "zypp/TmpPath.h"
00023 #include "zypp/target/CommitPackageCacheImpl.h"
00024
00026 namespace zypp
00027 {
00028
00029 namespace target
00030 {
00031
00033
00034
00035
00037 struct IMediaKey
00038 {
00039 IMediaKey()
00040 {}
00041
00042 explicit
00043 IMediaKey( const ResObject::constPtr & obj_r )
00044 : _repository( obj_r->repository() )
00045 , _mediaNr( obj_r->mediaNr() )
00046 {}
00047
00048 IMediaKey( const Repository & repo, unsigned mediaNr_r )
00049 : _repository( repo )
00050 , _mediaNr( mediaNr_r )
00051 {}
00052
00053 bool operator==( const IMediaKey & rhs ) const
00054 { return( _repository == rhs._repository && _mediaNr == rhs._mediaNr ); }
00055
00056 bool operator!=( const IMediaKey & rhs ) const
00057 { return ! operator==( rhs ); }
00058
00059 bool operator<( const IMediaKey & rhs ) const
00060 {
00061 return( _repository.numericId() < rhs._repository.numericId()
00062 || ( _repository.numericId() == rhs._repository.numericId()
00063 && _mediaNr < rhs._mediaNr ) );
00064 }
00065
00066 Repository _repository;
00067 DefaultIntegral<unsigned,0> _mediaNr;
00068 };
00070
00071 std::ostream & operator<<( std::ostream & str, const IMediaKey & obj );
00072
00074
00075
00076
00078 class CommitPackageCacheReadAhead : public CommitPackageCache::Impl
00079 {
00080 typedef std::map<PoolItem,ManagedFile> CacheMap;
00081
00082 public:
00083 CommitPackageCacheReadAhead( const_iterator begin_r,
00084 const_iterator end_r,
00085 const Pathname & rootDir_r,
00086 const PackageProvider & packageProvider_r );
00087
00088 public:
00090 virtual ManagedFile get( const_iterator citem_r );
00091
00092 private:
00094 bool onInteractiveMedia( const PoolItem & pi ) const;
00095
00096 private:
00102 void cacheLastInteractive( const_iterator citem_r );
00103
00105 void doCacheLastInteractive( const_iterator citem_r );
00106
00107 private:
00108 DefaultIntegral<unsigned,0> _dbgChanges;
00109
00110 const_iterator _commitListEnd;
00111 IMediaKey _lastInteractive;
00112
00113 Pathname _rootDir;
00114 shared_ptr<filesystem::TmpDir> _cacheDir;
00115 CacheMap _cacheMap;
00116 };
00118
00120 }
00123 }
00125 #endif // ZYPP_TARGET_COMMITPACKAGECACHEREADAHEAD_H