close(); // !!! make sure handler gets properly deleted.
}
+AttachedMedia
+MediaAccess::attachedMedia() const
+{
+ return _handler ? _handler->attachedMedia()
+ : AttachedMedia();
+}
+
// open URL
void
MediaAccess::open (const Url& url, const Pathname & preferred_attach_point)
#include "zypp/PathInfo.h"
#include "zypp/media/MediaException.h"
+#include "zypp/media/MediaSource.h"
+
#include "zypp/Url.h"
#include "zypp/base/Logger.h"
**/
MediaHandler * _handler;
+ friend class MediaManager;
+ AttachedMedia attachedMedia() const;
+
public:
/**
#include "zypp/ExternalProgram.h"
#include "zypp/media/Mount.h"
#include "zypp/media/MediaCD.h"
+#include "zypp/media/MediaManager.h"
#include "zypp/Url.h"
#include <cstring> // strerror
//
void MediaCD::attachTo(bool next)
{
+ DBG << "next " << next << " last " << _lastdev << endl;
+ if (next && _lastdev == -1)
+ ZYPP_THROW(MediaNotSupportedException(url()));
+
Mount mount;
string mountpoint = attachPoint().asString();
bool mountsucceeded = false;
int count = 0;
-
- DBG << "next " << next << " last " << _lastdev << " lastdevice " << _mounteddevice << endl;
-
- if (next && _lastdev == -1)
- ZYPP_THROW(MediaNotSupportedException(url()));
-
+
string options = _url.getQueryParam("mountoptions");
if (options.empty())
{
DBG << "skip" << endl;
continue;
}
-
+ PathInfo dev_info( *it);
+ if( !dev_info.isBlk())
+ {
+ DBG << "skip " << *it << " - is not a block device" << endl;
+ continue;
+ }
+
+ MediaSourceRef media( new MediaSource(
+ "cdrom", *it, dev_info.major(), dev_info.minor()
+ ));
+
+ AttachedMedia ret( findAttachedMedia( media));
+
+ if( ret.attachPoint &&
+ ret.mediaSource &&
+ !ret.attachPoint->empty() &&
+ media->equals( *ret.mediaSource))
+ {
+ DBG << "Using a shared media "
+ << ret.mediaSource->name
+ << " attached on "
+ << ret.attachPoint->path
+ << endl;
+ removeAttachPoint();
+ setAttachPoint(ret.attachPoint);
+ _mediaSource = ret.mediaSource;
+ _lastdev = count;
+ mountsucceeded = true;
+ break;
+ }
+ // FIXME: hmm... we may also
+ // - check against hal/mtab if still mounted
+ // - if !ret, check if already mounted (e.g.
+ // by automounter) and reuse (!temp) ?
+
// close tray
closeTray( *it );
; ++fsit)
{
try {
+ // FIXME: verify, if this mountpoint isn't already in use.
+ if( mountpoint.empty() || mountpoint == "/")
+ {
+ mountpoint = createAttachPoint().asString();
+ setAttachPoint( mountpoint, true);
+ if( mountpoint.empty())
+ {
+ ZYPP_THROW( MediaBadAttachPointException(url()));
+ }
+ }
+
mount.mount (*it, mountpoint.c_str(), *fsit, options);
- _mounteddevice = *it;
+
_lastdev = count;
+ _mediaSource = media;
mountsucceeded = true;
}
catch (const MediaException & excpt_r)
if (!mountsucceeded)
{
- _mounteddevice.erase();
_lastdev = -1;
ZYPP_THROW(MediaMountException(_url.asString(), mountpoint, "Mounting media failed"));
}
//
void MediaCD::releaseFrom( bool eject )
{
- if (_mounteddevice.empty()) // no device mounted
+ DBG << "Release CD ... use count = "
+ << _mediaSource.use_count()
+ << (_mediaSource.unique() ? ", unique" : ", not unique")
+ << std::endl;
+
+ // check if a device is mounted
+ if ( !_mediaSource)
{
if (eject) // eject wanted -> eject all devices
{
}
ZYPP_THROW(MediaNotAttachedException(url()));
}
-
- Mount mount;
- mount.umount(attachPoint().asString());
-
- // eject device
- if (eject)
+ else
+ if( _mediaSource.unique())
{
- openTray( _mounteddevice );
- }
+ Mount mount;
+ mount.umount(attachPoint().asString());
- _mounteddevice.erase();
+ // eject device
+ if (eject)
+ {
+ openTray( _mediaSource->name );
+ }
+ }
+
+ _mediaSource.reset();
}
///////////////////////////////////////////////////////////////////
//
void MediaCD::forceEject()
{
- if ( _mounteddevice.empty() ) { // no device mounted
+ if ( !_mediaSource) { // no device mounted
for ( DeviceList::iterator it = _devices.begin(); it != _devices.end(); ++it ) {
if ( openTray( *it ) )
break; // on 1st success
} // namespace media
} // namespace zypp
+// vim: set ts=8 sts=2 sw=2 ai noet:
#define ZYPP_MEDIA_MEDIACD_H
#include "zypp/media/MediaHandler.h"
+#include "zypp/media/MediaManager.h"
namespace zypp {
namespace media {
private:
- unsigned long _mountflags;
-
typedef std::list<std::string> DeviceList;
/** list of devices to try to mount */
DeviceList _devices;
- /** which device has been mounted */
- std::string _mounteddevice;
-
/** number of last successful mounted device in list */
- int _lastdev;
-
+ int _lastdev;
+
static bool openTray( const std::string & device_r );
static bool closeTray( const std::string & device_r );
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
#include "zypp/media/MediaHandler.h"
+#include "zypp/media/MediaManager.h"
using namespace std;
namespace zypp {
namespace media {
+
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : MediaHandler
const Pathname & attach_point_r,
const Pathname & urlpath_below_attachpoint_r,
const bool does_download_r )
- : _attachPoint( attach_point_r )
- , _tmp_attachPoint( false )
+ : _attachPoint( new AttachPoint())
+ , _relativeRoot( urlpath_below_attachpoint_r)
, _does_download( does_download_r )
, _isAttached( false )
, _url( url_r )
{
- if ( _attachPoint.empty() ) {
- ///////////////////////////////////////////////////////////////////
- // provide a default attachpoint
- ///////////////////////////////////////////////////////////////////
-
- Pathname aroot;
- PathInfo adir;
- const char * defmounts[] = { "/var/adm/mount", "/var/tmp", /**/NULL/**/ };
- for ( const char ** def = defmounts; *def; ++def ) {
- adir( *def );
- if ( adir.isDir() && adir.userMayRWX() ) {
- aroot = adir.path();
- break;
- }
- }
- if ( aroot.empty() ) {
- ERR << "Create attach point: Can't find a writable directory to create an attach point" << endl;
- return;
- }
-
- Pathname abase( aroot + "AP_" );
- Pathname apoint;
-
- for ( unsigned i = 1; i < 1000; ++i ) {
- adir( Pathname::extend( abase, str::hexstring( i ) ) );
- if ( ! adir.isExist() && mkdir( adir.path() ) == 0 ) {
- apoint = adir.path();
- break;
- }
- }
-
- if ( apoint.empty() ) {
- ERR << "Unable to create an attach point below " << aroot << endl;
- return;
- }
-
- // success
- _attachPoint = apoint;
- _tmp_attachPoint = true;
- MIL << "Created default attach point " << _attachPoint << endl;
-
- } else {
+ if ( !attach_point_r.empty() ) {
///////////////////////////////////////////////////////////////////
// check if provided attachpoint is usable.
///////////////////////////////////////////////////////////////////
- PathInfo adir( _attachPoint );
- if ( !adir.isDir() ) {
+
+ PathInfo adir( attach_point_r );
+ // FIXME: verify if attach_point_r isn't a mountpoint of other device
+ if ( attach_point_r.asString() == "/" || !adir.isDir() ) {
ERR << "Provided attach point is not a directory: " << adir << endl;
- _attachPoint = Pathname();
}
-
- }
-
- ///////////////////////////////////////////////////////////////////
- // must init _localRoot after _attachPoint is determined.
- ///////////////////////////////////////////////////////////////////
-
- if ( !_attachPoint.empty() ) {
- _localRoot = _attachPoint + urlpath_below_attachpoint_r;
+ else {
+ setAttachPoint( attach_point_r, false);
+ }
}
}
//
MediaHandler::~MediaHandler()
{
+ removeAttachPoint();
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : MediaHandler::removeAttachPoint
+// METHOD TYPE : void
+//
+// DESCRIPTION :
+//
+void
+MediaHandler::removeAttachPoint()
+{
if ( _isAttached ) {
INT << "MediaHandler deleted with media attached." << endl;
return; // no cleanup if media still mounted!
}
- if ( _tmp_attachPoint ) {
- int res = recursive_rmdir( _attachPoint );
+ if ( _attachPoint.unique() &&
+ _attachPoint->temp &&
+ !_attachPoint->path.empty())
+ {
+ int res = recursive_rmdir( _attachPoint->path );
if ( res == 0 ) {
- MIL << "Deleted default attach point " << _attachPoint << endl;
+ MIL << "Deleted default attach point " << _attachPoint->path << endl;
} else {
- ERR << "Failed to Delete default attach point " << _attachPoint
+ ERR << "Failed to Delete default attach point " << _attachPoint->path
<< " errno(" << res << ")" << endl;
}
}
}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : MediaHandler::attachPoint
+// METHOD TYPE : Pathname
+//
+// DESCRIPTION :
+//
+Pathname
+MediaHandler::attachPoint() const
+{
+ return _attachPoint->path;
+}
+
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : MediaHandler::attachPoint
+// METHOD TYPE :
+//
+// DESCRIPTION :
+//
+void
+MediaHandler::setAttachPoint(const Pathname &path, bool temporary)
+{
+ _localRoot = Pathname();
+
+ _attachPoint.reset( new AttachPoint(path, temporary));
+
+ if( !_attachPoint->path.empty())
+ _localRoot = _attachPoint->path + _relativeRoot;
+}
+
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : MediaHandler::attachPoint
+// METHOD TYPE :
+//
+// DESCRIPTION :
+//
+void
+MediaHandler::setAttachPoint(const AttachPointRef &ref)
+{
+ _localRoot = Pathname();
+
+ if( ref)
+ AttachPointRef(ref).swap(_attachPoint);
+ else
+ _attachPoint.reset( new AttachPoint());
+
+ if( !_attachPoint->path.empty())
+ _localRoot = _attachPoint->path + _relativeRoot;
+}
+
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : MediaHandler::findAttachedMedia
+// METHOD TYPE : AttachedMedia
+//
+// DESCRIPTION :
+//
+AttachedMedia
+MediaHandler::findAttachedMedia(const MediaSourceRef &media) const
+{
+ return MediaManager().findAttachedMedia(media);
+}
+
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : MediaHandler::attach
+// METHOD TYPE : Pathname
+//
+// DESCRIPTION :
+//
+Pathname
+MediaHandler::createAttachPoint() const
+{
+ /////////////////////////////////////////////////////////////////
+ // provide a default (temporary) attachpoint
+ /////////////////////////////////////////////////////////////////
+ const char * defmounts[] = {
+ "/var/adm/mount", "/var/tmp", /**/NULL/**/
+ };
+
+ Pathname aroot;
+ PathInfo adir;
+ for ( const char ** def = defmounts; *def; ++def ) {
+ adir( *def );
+ if ( adir.isDir() && adir.userMayRWX() ) {
+ aroot = adir.path();
+ break;
+ }
+ }
+ if ( aroot.empty() ) {
+ ERR << "Create attach point: Can't find a writable directory to create an attach point" << std::endl;
+ return aroot;
+ }
+
+ Pathname abase( aroot + "AP_" );
+ Pathname apoint;
+ for ( unsigned i = 1; i < 1000; ++i ) {
+ adir( Pathname::extend( abase, str::hexstring( i ) ) );
+ if ( ! adir.isExist() && mkdir( adir.path() ) == 0 ) {
+ apoint = adir.path();
+ break;
+ }
+ }
+ if ( apoint.empty() ) {
+ ERR << "Unable to create an attach point below " << aroot << std::endl;
+ } else {
+ MIL << "Created default attach point " << apoint << std::endl;
+ }
+ return apoint;
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+// METHOD NAME : MediaHandler::attachedMedia
+// METHOD TYPE : AttachedMedia
+//
+// DESCRIPTION :
+//
+AttachedMedia
+MediaHandler::attachedMedia() const
+{
+ if ( _isAttached && _mediaSource && _attachPoint)
+ return AttachedMedia(_mediaSource, _attachPoint);
+ else
+ return AttachedMedia();
+}
+
+
///////////////////////////////////////////////////////////////////
//
//
if ( _isAttached )
return;
- if ( _attachPoint.empty() ) {
+/**
+ if ( _attachPoint->empty() ) {
ERR << "Bad Attachpoint" << endl;
ZYPP_THROW( MediaBadAttachPointException(url()));
}
+*/
attachTo( next ); // pass to concrete handler
_isAttached = true;
//
void MediaHandler::releasePath( Pathname pathname ) const
{
- if ( ! _does_download || _attachPoint.empty() )
+ if ( ! _does_download || _attachPoint->empty() )
return;
PathInfo info( localPath( pathname ) );
#include "zypp/Pathname.h"
#include "zypp/PathInfo.h"
+#include "zypp/base/PtrTypes.h"
#include "zypp/Url.h"
-#include "zypp/media/MediaAccess.h"
+#include "zypp/media/MediaSource.h"
+#include "zypp/media/MediaException.h"
namespace zypp {
namespace media {
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : MediaHandler
typedef shared_ptr<const MediaHandler> constPtr;
private:
+ /**
+ * MediaAccess (MediaManager) needs access to the
+ * attachedMedia() function to deliver a shared
+ * media source and its attach point to other
+ * media handler instances.
+ */
+ friend class MediaAccess;
+
+ /**
+ * Returns the attached media. Used by MediaManager
+ * to find other handlers using the same source.
+ */
+ AttachedMedia attachedMedia() const;
/**
* this is where the media will be actually "mounted"
* all files are provided 'below' this directory.
**/
- Pathname _attachPoint;
+ AttachPointRef _attachPoint;
/**
- * If a default attach point was created, it has to be
- * removed on destuction.
- **/
- bool _tmp_attachPoint;
+ * The relative root directory of the data on the media.
+ * See also _localRoot and urlpath_below_attachpoint_r
+ * constructor argument.
+ */
+ Pathname _relativeRoot;
/**
* The local directory that corresponds to the media url.
* With NFS it's the '_attachPoint', as the directory on the
- * server is mounted. With CD/DVD it's 'attach point+_url.path()'
+ * server is mounted. With CD/DVD it's 'attach point+_relativeRoot'
* because the CDs root directory is mounted. And with CIFS
* it's '_url.path() without the shares name'.
**/
bool _isAttached;
protected:
+ // FIXME: private...?
+ /**
+ * The attached media source.
+ */
+ MediaSourceRef _mediaSource;
/**
* Url to handle
const Url _url;
/**
- * Attachpoint to use
+ * Return the currently used attach point.
**/
- const Pathname & attachPoint() const { return _attachPoint; }
+ Pathname attachPoint() const;
+
+ /**
+ * Set a new attach point and update localRoot.
+ */
+ void setAttachPoint(const Pathname &path, bool _temporary);
+
+ /**
+ * Set a (shared) attach point and update localRoot.
+ */
+ void setAttachPoint(const AttachPointRef &ref);
+
+ /**
+ * Try to create a default / temporary attach point.
+ * \return The name of the new attach point or empty path name.
+ */
+ Pathname createAttachPoint() const;
+
+ /**
+ * Remove unused attach point.
+ */
+ void removeAttachPoint();
+
+ /**
+ * Ask the media manager if specified media source
+ * is already attached.
+ */
+ AttachedMedia
+ findAttachedMedia(const MediaSourceRef &media) const;
protected:
/**
* Call concrete handler to release the media.
- * If eject is true, physically eject the media (i.e. CD-ROM).
+ *
+ * If eject is true, and the media is used in one handler
+ * instance only, physically eject the media (i.e. CD-ROM).
*
* Asserted that media is attached.
*
public:
+
///////////////////////////////////////////////////////////////////
//
// MediaAccess interface. Does common checks and logging.
*/
#include <zypp/media/MediaException.h>
#include <zypp/media/MediaManager.h>
-//#include <zypp/media/Mount.h>
+#include <zypp/media/Mount.h>
//#include <zypp/media/Hal.h>
#include <zypp/thread/Mutex.h>
#include <zypp/thread/MutexLock.h>
//////////////////////////////////////////////////////////////////
- // ---------------------------------------------------------------
+ //////////////////////////////////////////////////////////////////
class MediaManager::Impl
{
private:
- /*
time_t mtab_mtime;
MountEntries mtab_table;
- */
MediaId last_mediaid;
public:
MediaAccMap mediaAccMap;
Impl()
- : /* mtab_mtime(0)
- , */ last_mediaid(0)
+ : mtab_mtime(0)
+ , last_mediaid(0)
{}
~Impl()
MediaId
nextMediaId()
{
- return last_mediaid++;
+ return ++last_mediaid;
}
bool hasMediaAcc(MediaId mediaId) const
return mediaVfyMap.find(mediaId) != mediaVfyMap.end();
}
- /*
MountEntries
getMountEntries()
{
}
return mtab_table;
}
- */
};
- // ---------------------------------------------------------------
+ //////////////////////////////////////////////////////////////////
// STATIC
zypp::RW_pointer<MediaManager::Impl> MediaManager::m_impl(NULL);
- // ---------------------------------------------------------------
+ //////////////////////////////////////////////////////////////////
MediaManager::MediaManager()
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl)
{
m_impl.reset( new MediaManager::Impl());
MediaId
MediaManager::open(const Url &url, const Pathname &preferred_attach_point)
{
- MutexLock lock(g_Mutex);
-
- // check if we already have this url
- MediaAccMap::const_iterator a(m_impl->mediaAccMap.begin());
- for( ; a != m_impl->mediaAccMap.end(); ++a)
- {
- // FIXME: not sufficient. each handler should provide
- // method to compare its type of media url
- // and MediaAccess to choose right handler...
- if( a->second->url().asString() == url.asString())
- {
- return a->first;
- }
- }
+ MutexLock glock(g_Mutex);
// create new access handler for it
MediaAccessRef accRef( new MediaAccess());
MediaId nextId = m_impl->nextMediaId();
m_impl->mediaAccMap[nextId] = accRef;
-
+ DBG << "Opened new media access using id " << nextId << std::endl;
return nextId;
}
void
MediaManager::close(MediaId mediaId)
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
ZYPP_THROW(MediaException("Invalid media id"));
bool
MediaManager::isOpen(MediaId mediaId) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
return m_impl->hasMediaAcc( mediaId);
}
std::string
MediaManager::protocol(MediaId mediaId) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( m_impl->hasMediaAcc( mediaId))
return m_impl->mediaAccMap[mediaId]->protocol();
Url
MediaManager::url(MediaId mediaId) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( m_impl->hasMediaAcc( mediaId))
return m_impl->mediaAccMap[mediaId]->url();
void
MediaManager::addVerifier(MediaId mediaId, const MediaVerifierRef &ref)
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !ref)
ZYPP_THROW(MediaException("Invalid (empty) verifier reference"));
void
MediaManager::delVerifier(MediaId mediaId)
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
ZYPP_THROW(MediaException("Invalid media id"));
void
MediaManager::attach(MediaId mediaId, bool next)
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
void
MediaManager::release(MediaId mediaId, bool eject)
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
void
MediaManager::disconnect(MediaId mediaId)
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
bool
MediaManager::isAttached(MediaId mediaId) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
bool
MediaManager::isDesiredMedia(MediaId mediaId, MediaNr mediaNr) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !isAttached(mediaId))
return false;
Pathname
MediaManager::localRoot(MediaId mediaId) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
MediaManager::localPath(MediaId mediaId,
const Pathname & pathname) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
const Pathname &filename,
bool cached, bool checkonly) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !isDesiredMedia(mediaId, mediaNr))
{
MediaNr mediaNr,
const Pathname & dirname ) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !isDesiredMedia(mediaId, mediaNr))
{
MediaNr mediaNr,
const Pathname & dirname ) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !isDesiredMedia(mediaId, mediaNr))
{
MediaManager::releaseFile(MediaId mediaId,
const Pathname & filename) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
MediaManager::releaseDir(MediaId mediaId,
const Pathname & dirname) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
MediaManager::releasePath(MediaId mediaId,
const Pathname & pathname) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
std::list<std::string> & retlist,
const Pathname & dirname, bool dots) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
filesystem::DirContent & retlist,
const Pathname & dirname, bool dots) const
{
- MutexLock lock(g_Mutex);
+ MutexLock glock(g_Mutex);
if( !m_impl->hasMediaAcc( mediaId))
{
m_impl->mediaAccMap[mediaId]->dirInfo(retlist, dirname, dots);
}
+
+ // ---------------------------------------------------------------
+ AttachedMedia
+ MediaManager::findAttachedMedia(const MediaSourceRef &media) const
+ {
+ MutexLock glock(g_Mutex);
+
+ if( !media || media->type.empty())
+ return AttachedMedia();
+
+ MediaAccMap::const_iterator a(m_impl->mediaAccMap.begin());
+ for( ; a != m_impl->mediaAccMap.end(); ++a)
+ {
+ if( !a->second->isAttached())
+ continue;
+
+ AttachedMedia ret = a->second->attachedMedia();
+ if( ret.mediaSource && ret.mediaSource->equals( *media))
+ return ret;
+ }
+ return AttachedMedia();
+ }
+
+
//////////////////////////////////////////////////////////////////
} // namespace media
////////////////////////////////////////////////////////////////////
#ifndef ZYPP_MEDIA_MEDIAMANAGER_H
#define ZYPP_MEDIA_MEDIAMANAGER_H
-#include "zypp/media/MediaAccess.h"
-#include "zypp/base/NonCopyable.h"
-#include "zypp/base/PtrTypes.h"
-#include "zypp/Pathname.h"
-#include "zypp/Url.h"
+#include <zypp/media/MediaAccess.h>
+
+#include <zypp/base/NonCopyable.h>
+#include <zypp/base/PtrTypes.h>
+#include <zypp/Pathname.h>
+#include <zypp/Url.h>
+
+#include <list>
//////////////////////////////////////////////////////////////////////
namespace media
{ //////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
typedef unsigned int MediaId;
typedef unsigned int MediaNr;
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : MediaVerifierBase
{}
/*
- ** Check if the specified attached media contains
- ** the desired media number (e.g. SLES10 CD1). Always return true.
+ ** Don't check if the specified attached media contains
+ ** the desired media number. Always return true.
*/
virtual bool
isDesiredMedia(const MediaAccessRef &ref, MediaNr mediaNr)
filesystem::DirContent & retlist,
const Pathname & dirname, bool dots = true ) const;
+
+ private:
+ friend class MediaHandler;
+
+ AttachedMedia
+ findAttachedMedia(const MediaSourceRef &media) const;
+
private:
class Impl;
static zypp::RW_pointer<MediaManager::Impl> m_impl;
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/MediaSource.h
+ *
+ */
+#ifndef ZYPP_MEDIA_MEDIASOURCE_H
+#define ZYPP_MEDIA_MEDIASOURCE_H
+
+#include "zypp/Pathname.h"
+#include "zypp/base/String.h"
+#include "zypp/base/PtrTypes.h"
+
+
+namespace zypp {
+ namespace media {
+
+
+ ///////////////////////////////////////////////////////////////////
+ /**
+ * Media source internally used by MediaManager and MediaHandler.
+ */
+ class MediaSource
+ {
+ public:
+ MediaSource(const std::string &_type, const std::string &_name,
+ unsigned int _maj=0, unsigned int _min=0)
+ : maj_nr(_maj)
+ , min_nr(_min)
+ , type(_type)
+ , name(_name)
+ {}
+
+ MediaSource()
+ : maj_nr(0)
+ , min_nr(0)
+ {}
+
+ virtual
+ ~MediaSource()
+ {}
+
+ /**
+ * Check if the both sources are equal.
+ */
+ virtual bool equals(const MediaSource &src) const
+ {
+ if( type == src.type)
+ {
+ if( maj_nr == 0)
+ return name == src.name;
+ else
+ return maj_nr == src.maj_nr &&
+ min_nr == src.min_nr;
+ }
+ return false;
+ }
+
+ /**
+ * Return media source as string for debuging purposes.
+ */
+ virtual std::string asString() const
+ {
+ return type + ":" + name + "(" +
+ str::numstring(maj_nr) + "," +
+ str::numstring(min_nr) + ")";
+ }
+
+ unsigned int maj_nr; //!< A major number if source is a device.
+ unsigned int min_nr; //!< A minor number if source is a device.
+ std::string type; //!< A media handler specific source type.
+ std::string name; //!< A media handler specific source name.
+ };
+
+
+ ///////////////////////////////////////////////////////////////////
+ /**
+ * Attach point of a media source.
+ */
+ class AttachPoint
+ {
+ public:
+ AttachPoint(const Pathname &_path=Pathname(),
+ bool _temp=true)
+ : path(_path)
+ , temp(_temp)
+ {}
+
+ bool empty() const { return path.empty(); }
+
+ Pathname path; //!< The path name (mount point).
+ bool temp; //!< If it was created temporary.
+ };
+
+
+ ///////////////////////////////////////////////////////////////////
+ typedef zypp::RW_pointer<MediaSource> MediaSourceRef;
+ typedef zypp::RW_pointer<AttachPoint> AttachPointRef;
+
+
+ ///////////////////////////////////////////////////////////////////
+ /**
+ * A simple structure containing references
+ * to a media source and its attach point.
+ */
+ struct AttachedMedia
+ {
+ AttachedMedia()
+ {}
+
+ AttachedMedia(const MediaSourceRef &_mediaSource,
+ const AttachPointRef &_attachPoint)
+ : mediaSource( _mediaSource)
+ , attachPoint( _attachPoint)
+ {}
+
+ MediaSourceRef mediaSource;
+ AttachPointRef attachPoint;
+ };
+
+
+ } // namespace media
+} // namespace zypp
+
+
+#endif // ZYPP_MEDIA_MEDIASOURCE_H
+