00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MediaHandler_h
00023 #define MediaHandler_h
00024
00025 #include <iosfwd>
00026 #include <string>
00027 #include <list>
00028
00029 #include <y2util/Pathname.h>
00030 #include <y2util/PathInfo.h>
00031 #include <y2util/Url.h>
00032
00033 #include <y2pm/MediaAccess.h>
00034
00036
00037
00046 class MediaHandler {
00047 friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
00048
00049 public:
00050
00054 typedef MediaError Error;
00055
00056 private:
00057
00062 Pathname _attachPoint;
00063
00068 bool _tmp_attachPoint;
00069
00076 bool _attachPoint_is_mediaroot;
00077
00082 Pathname _localRoot;
00083
00088 bool _does_download;
00089
00093 bool _isAttached;
00094
00095 protected:
00096
00100 const Url _url;
00101
00105 const Pathname & attachPoint() const { return _attachPoint; }
00106
00107 protected:
00108
00110
00111
00112
00114
00124 virtual PMError attachTo(bool next = false) = 0;
00125
00138 virtual PMError disconnectFrom() { return Error::E_ok; }
00139
00146 virtual PMError releaseFrom( bool eject ) = 0;
00147
00154 virtual void forceEject() {}
00155
00164 virtual PMError getFile( const Pathname & filename ) const = 0;
00165
00174 virtual PMError getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename ) const;
00175
00188 virtual PMError getDir( const Pathname & dirname ) const = 0;
00189
00202 virtual PMError getDirInfo( std::list<std::string> & retlist,
00203 const Pathname & dirname, bool dots = true ) const = 0;
00204
00213 virtual PMError getDirInfo( PathInfo::dircontent & retlist,
00214 const Pathname & dirname, bool dots = true ) const = 0;
00215
00216 protected:
00217
00223 PMError getDirectoryYast( std::list<std::string> & retlist,
00224 const Pathname & dirname, bool dots = true ) const;
00225
00231 PMError getDirectoryYast( PathInfo::dircontent & retlist,
00232 const Pathname & dirname, bool dots = true ) const;
00233
00234 public:
00235
00247 MediaHandler ( const Url& url_r,
00248 const Pathname & attach_point_r,
00249 const bool attachPoint_is_mediaroot_r,
00250 const bool does_download_r );
00251
00256 virtual ~MediaHandler();
00257
00258 public:
00259
00261
00262
00263
00264
00266
00270 Url::Protocol protocol() const { return _url.protocol(); }
00271
00275 Url url() const { return _url; }
00276
00284 PMError attach(bool next);
00285
00289 bool isAttached() const { return _isAttached; }
00290
00299 const Pathname & localRoot() const { return _localRoot; }
00300
00306 Pathname localPath( const Pathname & pathname ) const {
00307 if ( _localRoot.empty() )
00308 return _localRoot;
00309 return _localRoot + pathname.absolutename();
00310 }
00311
00322 PMError disconnect();
00323
00328 PMError release( bool eject = false );
00329
00335 PMError provideFile( Pathname filename ) const;
00336
00345 PMError provideFileCopy( Pathname srcFilename, Pathname targetFilename) const;
00346
00353 PMError provideDir( Pathname dirname ) const;
00354
00359 PMError releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
00360
00365 PMError releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
00366
00376 PMError releasePath( Pathname pathname ) const;
00377
00378 public:
00379
00390 PMError dirInfo( std::list<std::string> & retlist,
00391 const Pathname & dirname, bool dots = true ) const;
00392
00402 PMError dirInfo( PathInfo::dircontent & retlist,
00403 const Pathname & dirname, bool dots = true ) const;
00404 };
00405
00407
00408 #define MEDIA_HANDLER_API \
00409 protected: \
00410 virtual PMError attachTo (bool next = false); \
00411 virtual PMError releaseFrom( bool eject ); \
00412 virtual PMError getFile( const Pathname & filename ) const; \
00413 virtual PMError getDir( const Pathname & dirname ) const; \
00414 virtual PMError getDirInfo( std::list<std::string> & retlist, \
00415 const Pathname & dirname, bool dots = true ) const; \
00416 virtual PMError getDirInfo( PathInfo::dircontent & retlist, \
00417 const Pathname & dirname, bool dots = true ) const;
00418
00419
00420 #endif // MediaHandler_h
00421