Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

MediaHandler.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:        MediaHandler.h
00014 
00015    Author:      Klaus Kaempf <kkaempf@suse.de>
00016    Maintainer:  Klaus Kaempf <kkaempf@suse.de>
00017 
00018    Purpose:     Abstract base class for 'physical' MediaHandler
00019                 like MediaCD, MediaDIR, ...
00020 
00021 /-*/
00022 #ifndef MediaHandler_h
00023 #define MediaHandler_h
00024 
00025 #include <iosfwd>
00026 #include <string>
00027 #include <list>
00028 
00029 #include <y2util/Pathname.h>
00030 #include <y2util/PathInfo.h>
00031 #include <y2util/Url.h>
00032 
00033 #include <y2pm/MediaAccess.h>
00034 
00036 //
00037 //      CLASS NAME : MediaHandler
00046 class MediaHandler {
00047     friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
00048 
00049     public:
00050 
00054         typedef MediaError Error;
00055 
00056     private:
00057 
00062         Pathname _attachPoint;
00063 
00068         bool _tmp_attachPoint;
00069 
00077         Pathname _localRoot;
00078 
00083         bool _does_download;
00084 
00088         bool _isAttached;
00089 
00090     protected:
00091 
00095         const Url _url;
00096 
00100         const Pathname & attachPoint() const { return _attachPoint; }
00101 
00102     protected:
00103 
00105         //
00106         // Real action interface to be overloaded by concrete handler.
00107         //
00109 
00119         virtual PMError attachTo(bool next = false) = 0;
00120 
00133         virtual PMError disconnectFrom() { return Error::E_ok; }
00134 
00141         virtual PMError releaseFrom( bool eject ) = 0;
00142 
00149         virtual void forceEject() {}
00150 
00159         virtual PMError getFile( const Pathname & filename ) const = 0;
00160 
00169         virtual PMError getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename ) const;
00170                          
00171 
00184         virtual PMError getDir( const Pathname & dirname, bool recurse_r ) const = 0;
00185 
00198         virtual PMError getDirInfo( std::list<std::string> & retlist,
00199                                     const Pathname & dirname, bool dots = true ) const = 0;
00200 
00209         virtual PMError getDirInfo( PathInfo::dircontent & retlist,
00210                                     const Pathname & dirname, bool dots = true ) const = 0;
00211 
00212   protected:
00213 
00219         PMError getDirectoryYast( std::list<std::string> & retlist,
00220                                   const Pathname & dirname, bool dots = true ) const;
00221 
00227         PMError getDirectoryYast( PathInfo::dircontent & retlist,
00228                                   const Pathname & dirname, bool dots = true ) const;
00229 
00230   public:
00231 
00243         MediaHandler ( const Url&       url_r,
00244                        const Pathname & attach_point_r,
00245                        const Pathname & urlpath_below_attachpoint_r,
00246                        const bool       does_download_r );
00247 
00252         virtual ~MediaHandler();
00253 
00254     public:
00255 
00257         //
00258         // MediaAccess interface. Does common checks and logging.
00259         // Invokes real action if necessary.
00260         //
00262 
00266         Url::Protocol protocol() const { return _url.protocol(); }
00267 
00271         Url url() const { return _url; }
00272 
00280         PMError attach(bool next);
00281 
00285         bool isAttached() const { return _isAttached; }
00286 
00295         const Pathname & localRoot() const { return _localRoot; }
00296 
00302          Pathname localPath( const Pathname & pathname ) const;
00303 
00314         PMError disconnect();
00315 
00320         PMError release( bool eject = false );
00321 
00327         PMError provideFile( Pathname filename ) const;
00328     
00337         PMError provideFileCopy( Pathname srcFilename, Pathname targetFilename) const;
00338     
00345         PMError provideDir( Pathname dirname ) const;
00346 
00353         PMError provideDirTree( Pathname dirname ) const;
00354 
00359         PMError releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
00360 
00365         PMError releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
00366 
00376         PMError releasePath( Pathname pathname ) const;
00377 
00378     public:
00379 
00390         PMError dirInfo( std::list<std::string> & retlist,
00391                          const Pathname & dirname, bool dots = true ) const;
00392 
00402         PMError dirInfo( PathInfo::dircontent & retlist,
00403                          const Pathname & dirname, bool dots = true ) const;
00404 };
00405 
00407 
00408 #define MEDIA_HANDLER_API                                               \
00409     protected:                                                          \
00410         virtual PMError attachTo (bool next = false);                   \
00411         virtual PMError releaseFrom( bool eject );                      \
00412         virtual PMError getFile( const Pathname & filename ) const;     \
00413         virtual PMError getDir( const Pathname & dirname, bool recurse_r ) const;       \
00414         virtual PMError getDirInfo( std::list<std::string> & retlist,   \
00415                                     const Pathname & dirname, bool dots = true ) const; \
00416         virtual PMError getDirInfo( PathInfo::dircontent & retlist,     \
00417                                     const Pathname & dirname, bool dots = true ) const;
00418 
00419 
00420 #endif // MediaHandler_h
00421 

Generated on Mon Sep 12 21:52:12 2005 for yast2-packagemanager by  doxygen 1.4.4