MediaAccess.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
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 
00024 #include "zypp/Pathname.h"
00025 #include "zypp/PathInfo.h"
00026 
00027 #include "zypp/media/MediaException.h"
00028 #include "zypp/media/MediaSource.h"
00029 
00030 #include "zypp/Url.h"
00031 
00032 namespace zypp {
00033   namespace media {
00034 
00035     class MediaHandler;
00036 
00038     //
00039     //  CLASS NAME : MediaAccess
00049     class MediaAccess : public base::ReferenceCounted, private base::NonCopyable
00050     {
00051     public:
00052         typedef intrusive_ptr<MediaAccess> Ptr;
00053         typedef intrusive_ptr<const MediaAccess> constPtr;
00054 
00055     private:
00056 
00057         static const Pathname _noPath;
00058 
00063         MediaHandler * _handler;
00064 
00065         friend class MediaManager;
00066         friend class MediaManager_Impl;
00067 
00068         AttachedMedia        attachedMedia() const;
00069 
00070         bool                 isSharedMedia() const;
00071 
00072         void                 resetParentId();
00073         bool                 dependsOnParent() const;
00074         bool                 dependsOnParent(MediaAccessId parentId,
00075                                              bool exactIdMatch) const;
00076 
00077     public:
00078 
00082         MediaAccess();
00083 
00094         void open( const Url& url, const Pathname & preferred_attach_point = "" );
00095 
00099         bool isOpen() const { return( _handler != 0 ); }
00100 
00105         bool        downloads() const;
00106 
00117         static
00118         bool        downloads(const Url &url);
00128         static
00129         bool        canBeVolatile(const Url &url);
00130 
00134         std::string protocol() const;
00135 
00139         Url url() const;
00140 
00147         void close();
00148 
00149     public:
00150 
00161         void attach(bool next = false);
00162 
00169         bool isAttached() const;
00170         
00171         bool hasMoreDevices() const;
00172 
00181         Pathname localRoot() const;
00182 
00189         Pathname localPath( const Pathname & pathname ) const;
00190 
00204         void disconnect();
00205 
00213         void release( bool eject = false );
00214 
00232         void provideFile( const Pathname & filename, bool cached = false, bool checkonly = false ) 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 & );             // no copy
00376         FileProvider & operator=( const FileProvider & ); // no assign
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(...) {} // No exception from dtor!
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   } // namespace media
00445 } // namespace zypp
00446 
00447 #endif // ZYPP_MEDIA_MEDIAACCESS_H
00448 

Generated on Tue Sep 25 19:23:01 2007 for libzypp by  doxygen 1.5.3