libzypp  10.5.0
MediaHandler.h
Go to the documentation of this file.
00001 
00002 /*---------------------------------------------------------------------\
00003 |                          ____ _   __ __ ___                          |
00004 |                         |__  / \ / / . \ . \                         |
00005 |                           / / \ V /|  _/  _/                         |
00006 |                          / /__ | | | | | |                           |
00007 |                         /_____||_| |_| |_|                           |
00008 |                                                                      |
00009 \---------------------------------------------------------------------*/
00013 #ifndef ZYPP_MEDIA_MEDIAHANDLERL_H
00014 #define ZYPP_MEDIA_MEDIAHANDLERL_H
00015 
00016 #include <iosfwd>
00017 #include <string>
00018 #include <list>
00019 
00020 #include "zypp/Pathname.h"
00021 #include "zypp/PathInfo.h"
00022 #include "zypp/base/PtrTypes.h"
00023 
00024 #include "zypp/Url.h"
00025 
00026 #include "zypp/media/MediaSource.h"
00027 #include "zypp/media/MediaException.h"
00028 #include "zypp/base/Deprecated.h"
00029 
00030 namespace zypp {
00031   namespace media {
00032 
00033 
00035 //
00036 //      CLASS NAME : MediaHandler
00045 class MediaHandler {
00046     friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
00047 
00048     public:
00049         typedef shared_ptr<MediaHandler> Ptr;
00050         typedef shared_ptr<const MediaHandler> constPtr;
00051 
00052         static bool setAttachPrefix(const Pathname &attach_prefix);
00053 
00054         static std::string getRealPath(const std::string &path);
00055         static Pathname    getRealPath(const Pathname    &path);
00056 
00057     private:
00061         static Pathname _attachPrefix;
00062 
00066         mutable
00067         MediaSourceRef  _mediaSource;
00068 
00073         AttachPointRef  _attachPoint;
00074 
00085         AttachPoint     _AttachPointHint;
00086 
00092         Pathname        _relativeRoot;
00093 
00098         bool            _does_download;
00099 
00101         mutable time_t  _attach_mtime;
00102 
00104         mutable Pathname _deltafile;
00105 
00106     protected:
00110         const Url        _url;
00111 
00115         MediaAccessId    _parentId;
00116 
00124         friend class MediaAccess;
00125 
00132         bool             dependsOnParent(MediaAccessId parentId,
00133                                          bool exactIdMatch);
00134         bool             dependsOnParent();
00135 
00141         void             resetParentId();
00142 
00146         Pathname         attachPoint() const;
00147 
00153         void             setAttachPoint(const Pathname &path, bool temp);
00154 
00159         void             setAttachPoint(const AttachPointRef &ref);
00160 
00164         AttachPoint      attachPointHint() const;
00165 
00171         void             attachPointHint(const Pathname &path, bool temp);
00172 
00179         Pathname         createAttachPoint() const;
00186         Pathname         createAttachPoint(const Pathname &attach_root) const;
00187 
00192         void             removeAttachPoint();
00193 
00200         virtual bool     checkAttachPoint(const Pathname &apoint) const;
00201 
00210         static bool      checkAttachPoint(const Pathname &apoint,
00211                                           bool            empty_dir,
00212                                           bool            writeable);
00213 
00222         bool             isUseableAttachPoint(const Pathname &path,
00223                                               bool            mtab=true) const;
00224 
00229         std::string      mediaSourceName() const
00230         {
00231           return _mediaSource ? _mediaSource->name : "";
00232         }
00233 
00238         void             setMediaSource(const MediaSourceRef &ref);
00239 
00244         AttachedMedia
00245         findAttachedMedia(const MediaSourceRef &media) const;
00246 
00258         AttachedMedia    attachedMedia() const;
00259 
00264         bool             isSharedMedia() const;
00265 
00274         bool             checkAttached(bool matchMountFs) const;
00275 
00284         void             forceRelaseAllMedia(bool matchMountFs);
00285         void             forceRelaseAllMedia(const MediaSourceRef &ref,
00286                                              bool matchMountFs);
00287 
00288     protected:
00289 
00291         //
00292         // Real action interface to be overloaded by concrete handler.
00293         //
00295 
00308         virtual void attachTo(bool next = false) = 0;
00309 
00325         virtual void disconnectFrom() { return; }
00326 
00339         virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
00340 
00347         virtual void forceEject( const std::string & device ) {}
00348 
00360         virtual void getFile( const Pathname & filename ) const = 0;
00361 
00373         virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename ) const;
00374 
00375 
00391         virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
00392 
00408         virtual void getDirInfo( std::list<std::string> & retlist,
00409                                  const Pathname & dirname, bool dots = true ) const = 0;
00410 
00422         virtual void getDirInfo( filesystem::DirContent & retlist,
00423                                  const Pathname & dirname, bool dots = true ) const = 0;
00424 
00433         virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
00434 
00435   protected:
00436 
00445         void getDirectoryYast( std::list<std::string> & retlist,
00446                                const Pathname & dirname, bool dots = true ) const;
00447 
00456         void getDirectoryYast( filesystem::DirContent & retlist,
00457                                const Pathname & dirname, bool dots = true ) const;
00458 
00459   public:
00460 
00472         MediaHandler ( const Url&       url_r,
00473                        const Pathname & attach_point_r,
00474                        const Pathname & urlpath_below_attachpoint_r,
00475                        const bool       does_download_r );
00476 
00481         virtual ~MediaHandler();
00482 
00483     public:
00484 
00485 
00487         //
00488         // MediaAccess interface. Does common checks and logging.
00489         // Invokes real action if necessary.
00490         //
00492 
00496         bool        downloads() const { return _does_download; }
00497 
00501         std::string protocol() const { return _url.getScheme(); }
00502 
00506         Url url() const { return _url; }
00507 
00518         void attach(bool next);
00519 
00523         virtual bool isAttached() const { return _mediaSource; }
00524 
00533         Pathname localRoot() const;
00534 
00540          Pathname localPath( const Pathname & pathname ) const;
00541 
00555         void disconnect();
00556 
00563         void release( const std::string & ejectDev = "" );
00564 
00573         void provideFile( Pathname filename ) const;
00574 
00586         void provideFileCopy( Pathname srcFilename, Pathname targetFilename) const;
00587 
00597         void provideDir( Pathname dirname ) const;
00598 
00608         void provideDirTree( Pathname dirname ) const;
00609 
00617         void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
00618 
00626         void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
00627 
00640         void releasePath( Pathname pathname ) const;
00641 
00642         /*
00643          * set a deltafile to be used in the next download
00644          */
00645         void setDeltafile( const Pathname &filename = Pathname()) const;
00646 
00647         /*
00648          * return the deltafile set with setDeltafile()
00649          */
00650         Pathname deltafile () const;
00651    
00652     public:
00653 
00667         void dirInfo( std::list<std::string> & retlist,
00668                       const Pathname & dirname, bool dots = true ) const;
00669 
00682         void dirInfo( filesystem::DirContent & retlist,
00683                       const Pathname & dirname, bool dots = true ) const;
00684 
00693         bool doesFileExist( const Pathname & filename ) const;
00694 
00698         virtual bool hasMoreDevices();
00699 
00708         virtual void
00709         getDetectedDevices(std::vector<std::string> & devices,
00710                            unsigned int & index) const;
00711 };
00712 
00714 
00715   } // namespace media
00716 } // namespace zypp
00717 
00718 
00719 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
00720 
00721