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         void             forceRelaseAllMedia(const MediaSourceRef &ref,
00283                                              bool matchMountFs);
00284 
00285     protected:
00286 
00288         //
00289         // Real action interface to be overloaded by concrete handler.
00290         //
00292 
00305         virtual void attachTo(bool next = false) = 0;
00306 
00322         virtual void disconnectFrom() { return; }
00323 
00336         virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
00337 
00344         virtual void forceEject( const std::string & device ) {}
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 
00560         void release( const std::string & ejectDev = "" );
00561 
00570         void provideFile( Pathname filename ) const;
00571 
00583         void provideFileCopy( Pathname srcFilename, Pathname targetFilename) const;
00584 
00594         void provideDir( Pathname dirname ) const;
00595 
00605         void provideDirTree( Pathname dirname ) const;
00606 
00614         void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
00615 
00623         void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
00624 
00637         void releasePath( Pathname pathname ) const;
00638 
00639     public:
00640 
00654         void dirInfo( std::list<std::string> & retlist,
00655                       const Pathname & dirname, bool dots = true ) const;
00656 
00669         void dirInfo( filesystem::DirContent & retlist,
00670                       const Pathname & dirname, bool dots = true ) const;
00671 
00680         bool doesFileExist( const Pathname & filename ) const;
00681 
00685         virtual bool hasMoreDevices();
00686 
00695         virtual void
00696         getDetectedDevices(std::vector<std::string> & devices,
00697                            unsigned int & index) const;
00698 };
00699 
00701 
00702   } // namespace media
00703 } // namespace zypp
00704 
00705 
00706 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
00707 
00708 
Generated on Fri Mar 2 09:45:52 2012 for libzypp by  doxygen 1.6.3