MediaHandler.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_MEDIA_MEDIAHANDLERL_H
00013 #define ZYPP_MEDIA_MEDIAHANDLERL_H
00014 
00015 #include <iosfwd>
00016 #include <string>
00017 #include <list>
00018 
00019 #include "zypp/Pathname.h"
00020 #include "zypp/PathInfo.h"
00021 #include "zypp/base/PtrTypes.h"
00022 
00023 #include "zypp/Url.h"
00024 
00025 #include "zypp/media/MediaSource.h"
00026 #include "zypp/media/MediaException.h"
00027 
00028 namespace zypp {
00029   namespace media {
00030 
00031 
00033 //
00034 //      CLASS NAME : MediaHandler
00043 class MediaHandler {
00044     friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
00045 
00046     public:
00047         typedef shared_ptr<MediaHandler> Ptr;
00048         typedef shared_ptr<const MediaHandler> constPtr;
00049 
00050         static bool setAttachPrefix(const Pathname &attach_prefix);
00051 
00052     private:
00056         static Pathname _attachPrefix;
00057 
00061         mutable
00062         MediaSourceRef  _mediaSource;
00063 
00068         AttachPointRef  _attachPoint;
00069 
00080         AttachPoint     _AttachPointHint;
00081 
00087         Pathname        _relativeRoot;
00088 
00093         bool            _does_download;
00094 
00096         mutable time_t  _attach_mtime;
00097 
00098     protected:
00102         const Url        _url;
00103 
00107         MediaAccessId    _parentId;
00108 
00116         friend class MediaAccess;
00117 
00124         bool             dependsOnParent(MediaAccessId parentId,
00125                                          bool exactIdMatch);
00126         bool             dependsOnParent();
00127 
00133         void             resetParentId();
00134 
00138         Pathname         attachPoint() const;
00139 
00145         void             setAttachPoint(const Pathname &path, bool temp);
00146 
00151         void             setAttachPoint(const AttachPointRef &ref);
00152 
00156         AttachPoint      attachPointHint() const;
00157 
00163         void             attachPointHint(const Pathname &path, bool temp);
00164 
00171         Pathname         createAttachPoint() const;
00178         Pathname         createAttachPoint(const Pathname &attach_root) const;
00179 
00184         void             removeAttachPoint();
00185 
00192         virtual bool     checkAttachPoint(const Pathname &apoint) const;
00193 
00202         static bool      checkAttachPoint(const Pathname &apoint,
00203                                           bool            empty_dir,
00204                                           bool            writeable);
00205 
00214         bool             isUseableAttachPoint(const Pathname &path,
00215                                               bool            mtab=true) const;
00216 
00221         std::string      mediaSourceName() const
00222         {
00223           return _mediaSource ? _mediaSource->name : "";
00224         }
00225 
00230         void             setMediaSource(const MediaSourceRef &ref);
00231 
00236         AttachedMedia
00237         findAttachedMedia(const MediaSourceRef &media) const;
00238 
00250         AttachedMedia    attachedMedia() const;
00251 
00256         bool             isSharedMedia() const;
00257 
00266         bool             checkAttached(bool matchMountFs) const;
00267 
00276         void             forceRelaseAllMedia(bool matchMountFs,
00277                                              bool autoMountedOny=true);
00278         void             forceRelaseAllMedia(const MediaSourceRef &ref,
00279                                              bool matchMountFs,
00280                                              bool autoMountedOnly=true);
00281         virtual bool     isAutoMountedMedia(const AttachedMedia &media);
00282 
00283     protected:
00284 
00286         //
00287         // Real action interface to be overloaded by concrete handler.
00288         //
00290 
00303         virtual void attachTo(bool next = false) = 0;
00304 
00320         virtual void disconnectFrom() { return; }
00321 
00333         virtual void releaseFrom( bool eject ) = 0;
00334 
00341         virtual void forceEject() {}
00342 
00354         virtual void getFile( const Pathname & filename ) const = 0;
00355 
00367         virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename ) const;
00368 
00369 
00385         virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
00386 
00402         virtual void getDirInfo( std::list<std::string> & retlist,
00403                                  const Pathname & dirname, bool dots = true ) const = 0;
00404 
00416         virtual void getDirInfo( filesystem::DirContent & retlist,
00417                                  const Pathname & dirname, bool dots = true ) const = 0;
00418 
00419   protected:
00420 
00429         void getDirectoryYast( std::list<std::string> & retlist,
00430                                const Pathname & dirname, bool dots = true ) const;
00431 
00440         void getDirectoryYast( filesystem::DirContent & retlist,
00441                                const Pathname & dirname, bool dots = true ) const;
00442 
00443   public:
00444 
00456         MediaHandler ( const Url&       url_r,
00457                        const Pathname & attach_point_r,
00458                        const Pathname & urlpath_below_attachpoint_r,
00459                        const bool       does_download_r );
00460 
00465         virtual ~MediaHandler();
00466 
00467     public:
00468 
00469 
00471         //
00472         // MediaAccess interface. Does common checks and logging.
00473         // Invokes real action if necessary.
00474         //
00476 
00480         bool        downloads() const { return _does_download; }
00481 
00485         std::string protocol() const { return _url.getScheme(); }
00486 
00490         Url url() const { return _url; }
00491 
00502         void attach(bool next);
00503 
00507         virtual bool isAttached() const { return _mediaSource; }
00508 
00517         Pathname localRoot() const;
00518 
00524          Pathname localPath( const Pathname & pathname ) const;
00525 
00539         void disconnect();
00540 
00548         void release( bool eject = false );
00549 
00558         void provideFile( Pathname filename ) const;
00559 
00571         void provideFileCopy( Pathname srcFilename, Pathname targetFilename) const;
00572 
00582         void provideDir( Pathname dirname ) const;
00583 
00593         void provideDirTree( Pathname dirname ) const;
00594 
00602         void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
00603 
00611         void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
00612 
00625         void releasePath( Pathname pathname ) const;
00626 
00627     public:
00628 
00642         void dirInfo( std::list<std::string> & retlist,
00643                       const Pathname & dirname, bool dots = true ) const;
00644 
00657         void dirInfo( filesystem::DirContent & retlist,
00658                       const Pathname & dirname, bool dots = true ) const;
00659 };
00660 
00662 
00663 #define MEDIA_HANDLER_API                                               \
00664     protected:                                                          \
00665         virtual void attachTo (bool next = false);                      \
00666         virtual void releaseFrom( bool eject );                 \
00667         virtual void getFile( const Pathname & filename ) const;        \
00668         virtual void getDir( const Pathname & dirname, bool recurse_r ) const;  \
00669         virtual void getDirInfo( std::list<std::string> & retlist,      \
00670                                     const Pathname & dirname, bool dots = true ) const; \
00671         virtual void getDirInfo( filesystem::DirContent & retlist,      \
00672                                     const Pathname & dirname, bool dots = true ) const;
00673 
00674   } // namespace media
00675 } // namespace zypp
00676 
00677 
00678 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
00679 
00680 

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