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 
00179         Pathname localRoot() const;
00180 
00187         Pathname localPath( const Pathname & pathname ) const;
00188 
00202         void disconnect();
00203 
00211         void release( bool eject = false );
00212 
00230         void provideFile( const Pathname & filename, bool cached = false, bool checkonly = false ) const;
00231 
00239         void releaseFile( const Pathname & filename ) const;
00240 
00250         void provideDir( const Pathname & dirname ) const;
00251 
00261         void provideDirTree( const Pathname & dirname ) const;
00262 
00270         void releaseDir( const Pathname & dirname ) const;
00271 
00283         void releasePath( const Pathname & pathname ) const;
00284 
00285     public:
00286 
00300         void dirInfo( std::list<std::string> & retlist,
00301                          const Pathname & dirname, bool dots = true ) const;
00302 
00315         void dirInfo( filesystem::DirContent & retlist,
00316                       const Pathname & dirname, bool dots = true ) const;
00317 
00321         virtual ~MediaAccess();
00322 
00323     public:
00324 
00325         virtual std::ostream & dumpOn( std::ostream & str ) const;
00326 
00327     public:
00338         void getFile( const Url &from, const Pathname &to );
00339 
00340     public:
00341 
00362       class FileProvider {
00363         FileProvider( const FileProvider & );             // no copy
00364         FileProvider & operator=( const FileProvider & ); // no assign
00365         private:
00366           MediaAccess::constPtr _media;
00367           Pathname              _file;
00368           Pathname              _local_file;
00369         public:
00373           FileProvider( MediaAccess::constPtr media_r, const Pathname & file_r )
00374             : _media( media_r )
00375             , _file( file_r )
00376             , _local_file( "" )
00377           {
00378             if ( _file.empty() ) {
00379               ZYPP_THROW(MediaBadFilenameException(_file.asString()));
00380             } else if ( _media ) {
00381               try {
00382                 _media->provideFile( _file );
00383                 _local_file = _media->localPath( _file );
00384               }
00385               catch (const MediaException & excpt_r)
00386               {
00387                 ZYPP_CAUGHT(excpt_r);
00388                 _media = NULL;
00389                 ZYPP_RETHROW(excpt_r);
00390               }
00391             }
00392           }
00393 
00394           ~FileProvider() {
00395             if ( _media )
00396             {
00397               try {
00398                 _media->releaseFile( _file );
00399               }
00400               catch (const MediaException &excpt_r)
00401               {
00402                 ZYPP_CAUGHT(excpt_r);
00403               }
00404               catch(...) {} // No exception from dtor!
00405             }
00406           }
00407 
00408         public:
00409 
00414           Pathname localFile() const { return _local_file; }
00415 
00420           Pathname operator()() const {
00421             if ( _media )
00422               return _media->localPath( _file );
00423             return Pathname();
00424           }
00425       };
00426     };
00427 
00428     std::ostream & operator<<( std::ostream & str, const MediaAccess & obj );
00429 
00431 
00432   } // namespace media
00433 } // namespace zypp
00434 
00435 #endif // ZYPP_MEDIA_MEDIAACCESS_H
00436 

Generated on Thu Jul 6 00:07:21 2006 for zypp by  doxygen 1.4.6