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

MediaHandler Class Reference

Abstract base class for 'physical' MediaHandler like MediaCD, etc. More...

#include <MediaHandler.h>

Inheritance diagram for MediaHandler:

MediaCD MediaCIFS MediaCurl MediaDIR MediaDISK MediaNFS MediaSMB List of all members.

Public Types

typedef MediaError Error

Public Member Functions

 MediaHandler (const Url &url_r, const Pathname &attach_point_r, const bool attachPoint_is_mediaroot_r, const bool does_download_r)
virtual ~MediaHandler ()
Url::Protocol protocol () const
Url url () const
PMError attach (bool next)
bool isAttached () const
const PathnamelocalRoot () const
Pathname localPath (const Pathname &pathname) const
PMError disconnect ()
PMError release (bool eject=false)
PMError provideFile (Pathname filename) const
PMError provideFileCopy (Pathname srcFilename, Pathname targetFilename) const
PMError provideDir (Pathname dirname) const
PMError releaseFile (const Pathname &filename) const
PMError releaseDir (const Pathname &dirname) const
PMError releasePath (Pathname pathname) const
PMError dirInfo (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
PMError dirInfo (PathInfo::dircontent &retlist, const Pathname &dirname, bool dots=true) const

Protected Member Functions

const PathnameattachPoint () const
virtual PMError attachTo (bool next=false)=0
virtual PMError disconnectFrom ()
virtual PMError releaseFrom (bool eject)=0
virtual void forceEject ()
virtual PMError getFile (const Pathname &filename) const=0
virtual PMError getFileCopy (const Pathname &srcFilename, const Pathname &targetFilename) const
virtual PMError getDir (const Pathname &dirname) const=0
virtual PMError getDirInfo (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const=0
virtual PMError getDirInfo (PathInfo::dircontent &retlist, const Pathname &dirname, bool dots=true) const=0
PMError getDirectoryYast (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
PMError getDirectoryYast (PathInfo::dircontent &retlist, const Pathname &dirname, bool dots=true) const

Protected Attributes

const Url _url

Private Attributes

Pathname _attachPoint
bool _tmp_attachPoint
bool _attachPoint_is_mediaroot
Pathname _localRoot
bool _does_download
bool _isAttached

Friends

std::ostream & operator<< (std::ostream &str, const MediaHandler &obj)

Detailed Description

Abstract base class for 'physical' MediaHandler like MediaCD, etc.

Handles the requests forwarded by MediaAccess. The public interface contains nonvirtual methods, which should do common sanitychecks and logging. For the real action they call virtual methods overloaded by the concrete handler.


Member Typedef Documentation

typedef MediaError MediaHandler::Error
 

default error class


Constructor & Destructor Documentation

MediaHandler::MediaHandler const Url url_r,
const Pathname attach_point_r,
const bool  attachPoint_is_mediaroot_r,
const bool  does_download_r
 

If the concrete media handler provides a nonempty attach_point, it must be an existing directory.

On an empty attach_point, MediaHandler will create a temporay directory, which will be erased from destructor.

On any error, the attach_point is set to an empty Pathname, which should lead to E_bad_attachpoint.

MediaHandler::~MediaHandler  )  [virtual]
 

Contolling MediaAccess takes care, that attached media is released prior to deleting this.


Member Function Documentation

PMError MediaHandler::attach bool  next  ) 
 

Use concrete handler to attach the media.

Parameters:
next try next available device in turn until end of device list is reached (for media which are accessible through multiple devices like cdroms).

const Pathname& MediaHandler::attachPoint  )  const [inline, protected]
 

Attachpoint to use

virtual PMError MediaHandler::attachTo bool  next = false  )  [protected, pure virtual]
 

Call concrete handler to attach the media.

Asserted that not already attached, and attachPoint is a directory.

Parameters:
next try next available device in turn until end of device list is reached (for media which are accessible through multiple devices like cdroms).

PMError MediaHandler::dirInfo PathInfo::dircontent retlist,
const Pathname dirname,
bool  dots = true
const
 

Basically the same as dirInfo above. The content is returned as PathInfo::dircontent, which includes name and filetype of each directory entry. Retrieving the filetype usg. requires an additional ::stat call for each entry, thus it's more expensive than a simple readdir.

Caution: This is not supported by all media types. Be prepared to handle E_not_supported_by_media.

PMError MediaHandler::dirInfo std::list< std::string > &  retlist,
const Pathname dirname,
bool  dots = true
const
 

Return content of directory on media via retlist. If dots is false entries starting with '.' are not reported.

The request is forwarded to the concrete handler, which may atempt to retieve the content e.g. via 'readdir'

Caution: This is not supported by all media types. Be prepared to handle E_not_supported_by_media.

PMError MediaHandler::disconnect  ) 
 

Use concrete handler to isconnect media.

This is useful for media which e.g. holds open a connection to a server like FTP. After calling disconnect() the media object still is valid and files are present.

After calling disconnect() it's not possible to call provideFile() or provideDir() anymore.

virtual PMError MediaHandler::disconnectFrom  )  [inline, protected, virtual]
 

Call concrete handler to disconnect media.

Asserted that media is attached.

This is useful for media which e.g. holds open a connection to a server like FTP. After calling disconnect() the media object still is valid and files are present.

After calling disconnect() it's not possible to call provideFile() or provideDir() anymore.

Reimplemented in MediaCurl.

virtual void MediaHandler::forceEject  )  [inline, protected, virtual]
 

Call concrete handler to physically eject the media (i.e. CD-ROM) in case the media is not attached..

Asserted that media is not attached.

Reimplemented in MediaCD.

PMError MediaHandler::getDir const Pathname dirname  )  const [protected, pure virtual]
 

Call concrete handler to provide directory content (not recursive!) below attach point.

Return E_not_supported_by_media if media does not support retrieval of directory content.

Default implementation provided, that returns whether a directory is located at '_localRoot + dirname'.

Asserted that media is attached.

PMError MediaHandler::getDirectoryYast PathInfo::dircontent retlist,
const Pathname dirname,
bool  dots = true
const [protected]
 

Retrieve and if available scan dirname/directory.yast.

Asserted that media is attached.

PMError MediaHandler::getDirectoryYast std::list< std::string > &  retlist,
const Pathname dirname,
bool  dots = true
const [protected]
 

Retrieve and if available scan dirname/directory.yast.

Asserted that media is attached.

PMError MediaHandler::getDirInfo PathInfo::dircontent retlist,
const Pathname dirname,
bool  dots = true
const [protected, pure virtual]
 

Basically the same as getDirInfo above. The content list is returned as PathInfo::dircontent, which includes name and filetype of each directory entry. Retrieving the filetype usg. requires an additional ::stat call for each entry, thus it's more expensive than a simple readdir.

Asserted that media is attached and retlist is empty.

PMError MediaHandler::getDirInfo std::list< std::string > &  retlist,
const Pathname dirname,
bool  dots = true
const [protected, pure virtual]
 

Call concrete handler to provide a content list of directory on media via retlist. If dots is false entries starting with '.' are not reported.

Return E_not_supported_by_media if media does not support retrieval of directory content.

Default implementation provided, that returns the content of a directory at '_localRoot + dirnname' retrieved via 'readdir'.

Asserted that media is attached and retlist is empty.

PMError MediaHandler::getFile const Pathname filename  )  const [protected, pure virtual]
 

Call concrete handler to provide file below attach point.

Default implementation provided, that returns whether a file is located at '_localRoot + filename'.

Asserted that media is attached.

PMError MediaHandler::getFileCopy const Pathname srcFilename,
const Pathname targetFilename
const [protected, virtual]
 

Call concrete handler to provide a file under a different place in the file system (usually not under attach point) as a copy. Media must be attached before by callee.

Default implementation provided that calls getFile(srcFilename) and copies the result around.

Reimplemented in MediaCurl.

bool MediaHandler::isAttached  )  const [inline]
 

True if media is attached.

Pathname MediaHandler::localPath const Pathname pathname  )  const [inline]
 

Files provided will be available at 'localPath(filename)'.

Returns empty pathname if E_bad_attachpoint

const Pathname& MediaHandler::localRoot  )  const [inline]
 

Return the local directory that corresponds to medias url, no matter if media isAttached or not. Files requested will be available at 'localRoot() + filename' or better 'localPath( filename )'.

Returns empty pathname if E_bad_attachpoint

Url::Protocol MediaHandler::protocol  )  const [inline]
 

Protocol hint for MediaAccess.

PMError MediaHandler::provideDir Pathname  dirname  )  const
 

Use concrete handler to provide directory denoted by path below 'localRoot' (not recursive!). dirname is interpreted relative to the attached url and a path prefix is preserved.

PMError MediaHandler::provideFile Pathname  filename  )  const
 

Use concrete handler to provide file denoted by path below 'localRoot'. Filename is interpreted relative to the attached url and a path prefix is preserved.

PMError MediaHandler::provideFileCopy Pathname  srcFilename,
Pathname  targetFilename
const
 

Call concrete handler to provide a copy of a file under a different place in the file system (usually not under attach point) as a copy. Media must be attached before by callee.

Parameters:
srcFilename Filename of source file on the media
targetFilename Filename for the target in the file system

PMError MediaHandler::release bool  eject = false  ) 
 

Use concrete handler to release the media.

Parameters:
eject if true, physically eject the media * (i.e. CD-ROM)

PMError MediaHandler::releaseDir const Pathname dirname  )  const [inline]
 

Remove directory tree below localRoot IFF handler downloads files to the local filesystem. Never remove anything from media.

PMError MediaHandler::releaseFile const Pathname filename  )  const [inline]
 

Remove filename below localRoot IFF handler downloads files to the local filesystem. Never remove anything from media.

virtual PMError MediaHandler::releaseFrom bool  eject  )  [protected, pure virtual]
 

Call concrete handler to release the media. If eject is true, physically eject the media (i.e. CD-ROM).

Asserted that media is attached.

PMError MediaHandler::releasePath Pathname  pathname  )  const
 

Remove pathname below localRoot IFF handler downloads files to the local filesystem. Never remove anything from media.

If pathname denotes a directory it is recursively removed. If pathname is empty or '/' everything below the localRoot is recursively removed. If pathname denotes a file it is unlinked.

Url MediaHandler::url  )  const [inline]
 

Url used.


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  str,
const MediaHandler obj
[friend]
 


Member Data Documentation

Pathname MediaHandler::_attachPoint [private]
 

this is where the media will be actually "mounted" all files are provided 'below' this directory.

bool MediaHandler::_attachPoint_is_mediaroot [private]
 

True if the medias root dir will be attached to _attachPoint (e.g. CD). If so, filenames are relative to '_attachPoint + _url.getPath()'.

If not (e.g. DIR, NFS) filenames are relative to '_attachPoint'.

bool MediaHandler::_does_download [private]
 

True if concrete handler downloads files to the local filesystem. If true releaseFile/Dir will delete them.

bool MediaHandler::_isAttached [private]
 

True, if media is attached.

Pathname MediaHandler::_localRoot [private]
 

Dependent on _attachPoint_is_mediaroot either _attachPoint or '_attachPoint + _url.getPath()'.

bool MediaHandler::_tmp_attachPoint [private]
 

If a default attach point was created, it has to be removed on destuction.

const Url MediaHandler::_url [protected]
 

Url to handle


The documentation for this class was generated from the following files:
Generated on Fri Nov 9 14:30:32 2007 for yast2-packagemanager by doxygen 1.3.6