00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef MediaAccess_h
00022 #define MediaAccess_h
00023
00024 #include <iosfwd>
00025 #include <map>
00026 #include <list>
00027 #include <string>
00028
00029 #include <y2util/Pathname.h>
00030 #include <y2util/PathInfo.h>
00031 #include <y2util/Url.h>
00032
00033 #include <y2pm/MediaAccessPtr.h>
00034 #include <y2pm/MediaError.h>
00035
00036 class MediaHandler;
00037
00039
00040
00050 class MediaAccess : public CountedRep {
00051 REP_BODY(MediaAccess);
00052
00053 public:
00054
00058 typedef MediaError Error;
00059
00060 private:
00061
00062 static const Pathname _noPath;
00063
00068 MediaHandler * _handler;
00069
00070 public:
00071
00075 MediaAccess();
00076
00084 PMError open( const Url& url, const Pathname & preferred_attach_point = "" );
00085
00089 bool isOpen() const { return( _handler != 0 ); }
00090
00094 Url::Protocol protocol() const;
00095
00099 Url url() const;
00100
00104 PMError close();
00105
00106 public:
00107
00115 PMError attach(bool next = false);
00116
00120 bool isAttached() const;
00121
00130 const Pathname & localRoot() const;
00131
00138 Pathname localPath( const Pathname & pathname ) const;
00139
00150 PMError disconnect();
00151
00156 PMError release( bool eject = false );
00157
00172 PMError provideFile( const Pathname & filename, bool cached = false, bool checkonly = false ) const;
00173
00178 PMError releaseFile( const Pathname & filename ) const;
00179
00186 PMError provideDir( const Pathname & dirname ) const;
00187
00194 PMError provideDirTree( const Pathname & dirname ) const;
00195
00200 PMError releaseDir( const Pathname & dirname ) const;
00201
00210 PMError releasePath( const Pathname & pathname ) const;
00211
00212 public:
00213
00224 PMError dirInfo( std::list<std::string> & retlist,
00225 const Pathname & dirname, bool dots = true ) const;
00226
00236 PMError dirInfo( PathInfo::dircontent & retlist,
00237 const Pathname & dirname, bool dots = true ) const;
00238
00242 virtual ~MediaAccess();
00243
00244 public:
00245
00246 virtual std::ostream & dumpOn( std::ostream & str ) const;
00247
00248 public:
00256 static PMError getFile( const Url &from, const Pathname &to );
00257
00258 public:
00259
00277 class FileProvider {
00278 FileProvider( const FileProvider & );
00279 FileProvider & operator=( const FileProvider & );
00280 private:
00281 constMediaAccessPtr _media;
00282 Pathname _file;
00283 PMError _lasterr;
00284 public:
00288 typedef MediaError Error;
00289
00290 FileProvider( constMediaAccessPtr media_r, const Pathname & file_r )
00291 : _media( media_r )
00292 , _file( file_r )
00293 , _lasterr( Error::E_error )
00294 {
00295 if ( _file.empty() ) {
00296 _lasterr = Error::E_bad_filename;
00297 } else if ( _media ) {
00298 _lasterr = _media->provideFile( _file );
00299 }
00300 if ( _lasterr )
00301 _media = 0;
00302 }
00303
00304 ~FileProvider() {
00305 if ( _media )
00306 _media->releaseFile( _file );
00307 }
00308
00309 public:
00310
00315 PMError error() const { return _lasterr; }
00316
00321 Pathname operator()() const {
00322 if ( _media )
00323 return _media->localPath( _file );
00324 return Pathname();
00325 }
00326 };
00327 };
00328
00330
00331 #endif // MediaAccess_h
00332