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         static std::string getRealPath(const std::string &path);
00053         static Pathname    getRealPath(const Pathname    &path);
00054 
00055     private:
00059         static Pathname _attachPrefix;
00060 
00064         mutable
00065         MediaSourceRef  _mediaSource;
00066 
00071         AttachPointRef  _attachPoint;
00072 
00083         AttachPoint     _AttachPointHint;
00084 
00090         Pathname        _relativeRoot;
00091 
00096         bool            _does_download;
00097 
00099         mutable time_t  _attach_mtime;
00100 
00101     protected:
00105         const Url        _url;
00106 
00110         MediaAccessId    _parentId;
00111 
00119         friend class MediaAccess;
00120 
00127         bool             dependsOnParent(MediaAccessId parentId,
00128                                          bool exactIdMatch);
00129         bool             dependsOnParent();
00130 
00136         void             resetParentId();
00137 
00141         Pathname         attachPoint() const;
00142 
00148         void             setAttachPoint(const Pathname &path, bool temp);
00149 
00154         void             setAttachPoint(const AttachPointRef &ref);
00155 
00159         AttachPoint      attachPointHint() const;
00160 
00166         void             attachPointHint(const Pathname &path, bool temp);
00167 
00174         Pathname         createAttachPoint() const;
00181         Pathname         createAttachPoint(const Pathname &attach_root) const;
00182 
00187         void             removeAttachPoint();
00188 
00195         virtual bool     checkAttachPoint(const Pathname &apoint) const;
00196 
00205         static bool      checkAttachPoint(const Pathname &apoint,
00206                                           bool            empty_dir,
00207                                           bool            writeable);
00208 
00217         bool             isUseableAttachPoint(const Pathname &path,
00218                                               bool            mtab=true) const;
00219 
00224         std::string      mediaSourceName() const
00225         {
00226           return _mediaSource ? _mediaSource->name : "";
00227         }
00228 
00233         void             setMediaSource(const MediaSourceRef &ref);
00234 
00239         AttachedMedia
00240         findAttachedMedia(const MediaSourceRef &media) const;
00241 
00253         AttachedMedia    attachedMedia() const;
00254 
00259         bool             isSharedMedia() const;
00260 
00269         bool             checkAttached(bool matchMountFs) const;
00270 
00279         void             forceRelaseAllMedia(bool matchMountFs,
00280                                              bool autoMountedOny=true);
00281         void             forceRelaseAllMedia(const MediaSourceRef &ref,
00282                                              bool matchMountFs,
00283                                              bool autoMountedOnly=true);
00284         virtual bool     isAutoMountedMedia(const AttachedMedia &media);
00285 
00286     protected:
00287 
00289         //
00290         // Real action interface to be overloaded by concrete handler.
00291         //
00293 
00306         virtual void attachTo(bool next = false) = 0;
00307 
00323         virtual void disconnectFrom() { return; }
00324 
00336         virtual void releaseFrom( bool eject ) = 0;
00337 
00344         virtual void forceEject() {}
00345 
00357         virtual void getFile( const Pathname & filename ) const = 0;
00358 
00370         virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename ) const;
00371 
00372 
00388         virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
00389 
00405         virtual void getDirInfo( std::list<std::string> & retlist,
00406                                  const Pathname & dirname, bool dots = true ) const = 0;
00407 
00419         virtual void getDirInfo( filesystem::DirContent & retlist,
00420                                  const Pathname & dirname, bool dots = true ) const = 0;
00421 
00430         virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
00431 
00432   protected:
00433 
00442         void getDirectoryYast( std::list<std::string> & retlist,
00443                                const Pathname & dirname, bool dots = true ) const;
00444 
00453         void getDirectoryYast( filesystem::DirContent & retlist,
00454                                const Pathname & dirname, bool dots = true ) const;
00455 
00456   public:
00457 
00469         MediaHandler ( const Url&       url_r,
00470                        const Pathname & attach_point_r,
00471                        const Pathname & urlpath_below_attachpoint_r,
00472                        const bool       does_download_r );
00473 
00478         virtual ~MediaHandler();
00479 
00480     public:
00481 
00482 
00484         //
00485         // MediaAccess interface. Does common checks and logging.
00486         // Invokes real action if necessary.
00487         //
00489 
00493         bool        downloads() const { return _does_download; }
00494 
00498         std::string protocol() const { return _url.getScheme(); }
00499 
00503         Url url() const { return _url; }
00504 
00515         void attach(bool next);
00516 
00520         virtual bool isAttached() const { return _mediaSource; }
00521 
00530         Pathname localRoot() const;
00531 
00537          Pathname localPath( const Pathname & pathname ) const;
00538 
00552         void disconnect();
00553 
00561         void release( bool eject = false );
00562 
00571         void provideFile( Pathname filename ) const;
00572 
00584         void provideFileCopy( Pathname srcFilename, Pathname targetFilename) const;
00585 
00595         void provideDir( Pathname dirname ) const;
00596 
00606         void provideDirTree( Pathname dirname ) const;
00607 
00615         void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
00616 
00624         void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
00625 
00638         void releasePath( Pathname pathname ) const;
00639 
00640     public:
00641 
00655         void dirInfo( std::list<std::string> & retlist,
00656                       const Pathname & dirname, bool dots = true ) const;
00657 
00670         void dirInfo( filesystem::DirContent & retlist,
00671                       const Pathname & dirname, bool dots = true ) const;
00672 
00681         bool doesFileExist( const Pathname & filename ) const;
00682 
00686         virtual bool hasMoreDevices();
00687 };
00688 
00690 
00691   } // namespace media
00692 } // namespace zypp
00693 
00694 
00695 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
00696 
00697 

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