MediaAccess.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_MEDIA_MEDIAACCESS_H
00013 #define ZYPP_MEDIA_MEDIAACCESS_H
00014
00015 #include <iosfwd>
00016 #include <map>
00017 #include <list>
00018 #include <string>
00019
00020 #include "zypp/base/ReferenceCounted.h"
00021 #include "zypp/base/NonCopyable.h"
00022 #include "zypp/base/PtrTypes.h"
00023 #include "zypp/base/Deprecated.h"
00024
00025 #include "zypp/Pathname.h"
00026 #include "zypp/PathInfo.h"
00027
00028 #include "zypp/media/MediaException.h"
00029 #include "zypp/media/MediaSource.h"
00030
00031 #include "zypp/Url.h"
00032
00033 namespace zypp {
00034 namespace media {
00035
00036 class MediaHandler;
00037
00039
00040
00050 class MediaAccess : public base::ReferenceCounted, private base::NonCopyable
00051 {
00052 public:
00053 typedef intrusive_ptr<MediaAccess> Ptr;
00054 typedef intrusive_ptr<const MediaAccess> constPtr;
00055
00056 private:
00057
00058 static const Pathname _noPath;
00059
00064 MediaHandler * _handler;
00065
00066 friend class MediaManager;
00067 friend class MediaManager_Impl;
00068
00069 AttachedMedia attachedMedia() const;
00070
00071 bool isSharedMedia() const;
00072
00073 void resetParentId();
00074 bool dependsOnParent() const;
00075
00076 bool dependsOnParent(MediaAccessId parentId,
00077 bool exactIdMatch) const;
00078 public:
00079
00083 MediaAccess();
00084
00095 void open( const Url& url, const Pathname & preferred_attach_point = "" );
00096
00100 bool isOpen() const { return( _handler != 0 ); }
00101
00106 bool downloads() const;
00107
00109 static
00110 ZYPP_DEPRECATED bool downloads(const Url &url)
00111 { return url.schemeIsDownloading(); }
00112
00114 static
00115 ZYPP_DEPRECATED bool canBeVolatile(const Url &url)
00116 { return url.schemeIsVolatile(); }
00117
00121 std::string protocol() const;
00122
00126 Url url() const;
00127
00134 void close();
00135
00136 public:
00137
00148 void attach(bool next = false);
00149
00156 bool isAttached() const;
00157
00158 bool hasMoreDevices() const;
00159
00168 virtual void
00169 getDetectedDevices(std::vector<std::string> & devices,
00170 unsigned int & index) const;
00171
00172
00181 Pathname localRoot() const;
00182
00189 Pathname localPath( const Pathname & pathname ) const;
00190
00204 void disconnect();
00205
00213 void release( const std::string & ejectDev = "" );
00214
00232 void provideFile( const Pathname & filename ) const;
00233
00241 void releaseFile( const Pathname & filename ) const;
00242
00252 void provideDir( const Pathname & dirname ) const;
00253
00263 void provideDirTree( const Pathname & dirname ) const;
00264
00272 void releaseDir( const Pathname & dirname ) const;
00273
00285 void releasePath( const Pathname & pathname ) const;
00286
00287 public:
00288
00302 void dirInfo( std::list<std::string> & retlist,
00303 const Pathname & dirname, bool dots = true ) const;
00304
00317 void dirInfo( filesystem::DirContent & retlist,
00318 const Pathname & dirname, bool dots = true ) const;
00319
00328 bool doesFileExist( const Pathname & filename ) const;
00329
00333 virtual ~MediaAccess();
00334
00335 public:
00336
00337 virtual std::ostream & dumpOn( std::ostream & str ) const;
00338
00339 public:
00350 void getFile( const Url &from, const Pathname &to );
00351
00352 public:
00353
00374 class FileProvider {
00375 FileProvider( const FileProvider & );
00376 FileProvider & operator=( const FileProvider & );
00377 private:
00378 MediaAccess::constPtr _media;
00379 Pathname _file;
00380 Pathname _local_file;
00381 public:
00385 FileProvider( MediaAccess::constPtr media_r, const Pathname & file_r )
00386 : _media( media_r )
00387 , _file( file_r )
00388 , _local_file( "" )
00389 {
00390 if ( _file.empty() ) {
00391 ZYPP_THROW(MediaBadFilenameException(_file.asString()));
00392 } else if ( _media ) {
00393 try {
00394 _media->provideFile( _file );
00395 _local_file = _media->localPath( _file );
00396 }
00397 catch (const MediaException & excpt_r)
00398 {
00399 ZYPP_CAUGHT(excpt_r);
00400 _media = NULL;
00401 ZYPP_RETHROW(excpt_r);
00402 }
00403 }
00404 }
00405
00406 ~FileProvider() {
00407 if ( _media )
00408 {
00409 try {
00410 _media->releaseFile( _file );
00411 }
00412 catch (const MediaException &excpt_r)
00413 {
00414 ZYPP_CAUGHT(excpt_r);
00415 }
00416 catch(...) {}
00417 }
00418 }
00419
00420 public:
00421
00426 Pathname localFile() const { return _local_file; }
00427
00432 Pathname operator()() const {
00433 if ( _media )
00434 return _media->localPath( _file );
00435 return Pathname();
00436 }
00437 };
00438 };
00439
00440 std::ostream & operator<<( std::ostream & str, const MediaAccess & obj );
00441
00443
00444 }
00445 }
00446
00447 #endif // ZYPP_MEDIA_MEDIAACCESS_H
00448