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
00168 PMError provideFile( const Pathname & filename, bool cached = false ) const;
00169
00174 PMError releaseFile( const Pathname & filename ) const;
00175
00182 PMError provideDir( const Pathname & dirname ) const;
00183
00188 PMError releaseDir( const Pathname & dirname ) const;
00189
00198 PMError releasePath( const Pathname & pathname ) const;
00199
00200 public:
00201
00212 PMError dirInfo( std::list<std::string> & retlist,
00213 const Pathname & dirname, bool dots = true ) const;
00214
00224 PMError dirInfo( PathInfo::dircontent & retlist,
00225 const Pathname & dirname, bool dots = true ) const;
00226
00230 virtual ~MediaAccess();
00231
00232 public:
00233
00234 virtual std::ostream & dumpOn( std::ostream & str ) const;
00235
00236 public:
00244 static PMError getFile( const Url &from, const Pathname &to );
00245
00246 public:
00247
00265 class FileProvider {
00266 FileProvider( const FileProvider & );
00267 FileProvider & operator=( const FileProvider & );
00268 private:
00269 constMediaAccessPtr _media;
00270 Pathname _file;
00271 PMError _lasterr;
00272 public:
00276 typedef MediaError Error;
00277
00278 FileProvider( constMediaAccessPtr media_r, const Pathname & file_r )
00279 : _media( media_r )
00280 , _file( file_r )
00281 , _lasterr( Error::E_error )
00282 {
00283 if ( _file.empty() ) {
00284 _lasterr = Error::E_bad_filename;
00285 } else if ( _media ) {
00286 _lasterr = _media->provideFile( _file );
00287 }
00288 if ( _lasterr )
00289 _media = 0;
00290 }
00291
00292 ~FileProvider() {
00293 if ( _media )
00294 _media->releaseFile( _file );
00295 }
00296
00297 public:
00298
00303 PMError error() const { return _lasterr; }
00304
00309 Pathname operator()() const {
00310 if ( _media )
00311 return _media->localPath( _file );
00312 return Pathname();
00313 }
00314 };
00315 };
00316
00318
00319 #endif // MediaAccess_h
00320