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 
00103     protected:
00107         const Url        _url;
00108 
00112         MediaAccessId    _parentId;
00113 
00121         friend class MediaAccess;
00122 
00129         bool             dependsOnParent(MediaAccessId parentId,
00130                                          bool exactIdMatch);
00131         bool             dependsOnParent();
00132 
00138         void             resetParentId();
00139 
00143         Pathname         attachPoint() const;
00144 
00150         void             setAttachPoint(const Pathname &path, bool temp);
00151 
00156         void             setAttachPoint(const AttachPointRef &ref);
00157 
00161         AttachPoint      attachPointHint() const;
00162 
00168         void             attachPointHint(const Pathname &path, bool temp);
00169 
00176         Pathname         createAttachPoint() const;
00183         Pathname         createAttachPoint(const Pathname &attach_root) const;
00184 
00189         void             removeAttachPoint();
00190 
00197         virtual bool     checkAttachPoint(const Pathname &apoint) const;
00198 
00207         static bool      checkAttachPoint(const Pathname &apoint,
00208                                           bool            empty_dir,
00209                                           bool            writeable);
00210 
00219         bool             isUseableAttachPoint(const Pathname &path,
00220                                               bool            mtab=true) const;
00221 
00226         std::string      mediaSourceName() const
00227         {
00228           return _mediaSource ? _mediaSource->name : "";
00229         }
00230 
00235         void             setMediaSource(const MediaSourceRef &ref);
00236 
00241         AttachedMedia
00242         findAttachedMedia(const MediaSourceRef &media) const;
00243 
00255         AttachedMedia    attachedMedia() const;
00256 
00261         bool             isSharedMedia() const;
00262 
00271         bool             checkAttached(bool matchMountFs) const;
00272 
00281         void             forceRelaseAllMedia(bool matchMountFs,
00282                                              bool autoMountedOny=true);
00283         void             forceRelaseAllMedia(const MediaSourceRef &ref,
00284                                              bool matchMountFs,
00285                                              bool autoMountedOnly=true);
00286         virtual bool     isAutoMountedMedia(const AttachedMedia &media);
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     public:
00643 
00657         void dirInfo( std::list<std::string> & retlist,
00658                       const Pathname & dirname, bool dots = true ) const;
00659 
00672         void dirInfo( filesystem::DirContent & retlist,
00673                       const Pathname & dirname, bool dots = true ) const;
00674 
00683         bool doesFileExist( const Pathname & filename ) const;
00684 
00688         virtual bool hasMoreDevices();
00689 
00698         virtual void
00699         getDetectedDevices(std::vector<std::string> & devices,
00700                            unsigned int & index) const;
00701 };
00702 
00704 
00705   } // namespace media
00706 } // namespace zypp
00707 
00708 
00709 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
00710 
00711 

doxygen