From 03a7a61269849ec0e0d4e67e43872af262964733 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Thu, 9 Feb 2006 14:30:19 +0000 Subject: [PATCH] Added reopen() function to change Url for a AccessId Added attachMediaNr() that attaches and verifies Added isDesiredMedia() using a specified verifier --- zypp/media/MediaManager.cc | 80 +++++++++++++++++++++++++++++++++++++++++++--- zypp/media/MediaManager.h | 39 ++++++++++++++++++++-- 2 files changed, 112 insertions(+), 7 deletions(-) diff --git a/zypp/media/MediaManager.cc b/zypp/media/MediaManager.cc index 474a803..a90068c 100644 --- a/zypp/media/MediaManager.cc +++ b/zypp/media/MediaManager.cc @@ -147,6 +147,33 @@ namespace zypp // --------------------------------------------------------------- void + MediaManager::reopen(MediaAccessId accessId, const Url &url, + const Pathname & preferred_attach_point) + { + MutexLock glock(g_Mutex); + + if( !m_impl->hasMediaAcc(accessId)) + { + ZYPP_THROW(MediaNotOpenException( + "Invalid media access id " + str::numstring(accessId) + )); + } + + MediaAccessRef accRef( new MediaAccess()); + + accRef->open(url, preferred_attach_point); + + // release and close the old one + m_impl->mediaAccMap[accessId]->close(); + + // assign new one + m_impl->mediaAccMap[accessId] = accRef; + + DBG << "Reopened media access id " << accessId << std::endl; + } + + // --------------------------------------------------------------- + void MediaManager::close(MediaAccessId accessId) { MutexLock glock(g_Mutex); @@ -199,13 +226,13 @@ namespace zypp // --------------------------------------------------------------- void - MediaManager::addVerifier(MediaAccessId accessId, - const MediaVerifierRef &ref) + MediaManager::addVerifier(MediaAccessId accessId, + const MediaVerifierRef &verifier) { MutexLock glock(g_Mutex); - if( !ref) - ZYPP_THROW(MediaException("Invalid (empty) verifier reference")); + if( !verifier) + ZYPP_THROW(MediaException("Invalid verifier reference")); if( !m_impl->hasMediaAcc(accessId)) { @@ -214,7 +241,7 @@ namespace zypp )); } - m_impl->mediaVfyMap[accessId] = ref; + m_impl->mediaVfyMap[accessId] = verifier; } // --------------------------------------------------------------- @@ -252,6 +279,24 @@ namespace zypp // --------------------------------------------------------------- void + MediaManager::attachMediaNr(MediaAccessId accessId, + MediaNr mediaNr, + bool eject) + { + MutexLock glock(g_Mutex); + + if( !m_impl->hasMediaAcc( accessId)) + { + ZYPP_THROW(MediaNotOpenException( + "Invalid media access id " + str::numstring(accessId) + )); + } + + // FIXME: implement it. + } + + // --------------------------------------------------------------- + void MediaManager::release(MediaAccessId accessId, bool eject) { MutexLock glock(g_Mutex); @@ -323,6 +368,31 @@ namespace zypp } // --------------------------------------------------------------- + bool + MediaManager::isDesiredMedia(MediaAccessId accessId, + MediaNr mediaNr, + const MediaVerifierRef &verifier) const + { + MutexLock glock(g_Mutex); + + if( !isAttached(accessId)) + return false; + + MediaVerifierRef v( verifier); + if( !v) + ZYPP_THROW(MediaException("Invalid verifier reference")); + + bool ok; + try { + ok = v->isDesiredMedia( + m_impl->mediaAccMap[accessId], mediaNr + ); + } + catch( ... ) { ok = false; } + return ok; + } + + // --------------------------------------------------------------- Pathname MediaManager::localRoot(MediaAccessId accessId) const { diff --git a/zypp/media/MediaManager.h b/zypp/media/MediaManager.h index 2d4690d..63b1b8f 100644 --- a/zypp/media/MediaManager.h +++ b/zypp/media/MediaManager.h @@ -128,6 +128,14 @@ namespace zypp open(const Url &url, const Pathname & preferred_attach_point = ""); /** + * Open new access handler with specifier url and attach + * point reusing the specified accessId. + */ + void + reopen(MediaAccessId accessId, const Url &url, + const Pathname & preferred_attach_point = ""); + + /** * close the media */ void @@ -157,7 +165,8 @@ namespace zypp * Add verifier for specified media id. */ void - addVerifier(MediaAccessId accessId, const MediaVerifierRef &ref); + addVerifier(MediaAccessId accessId, + const MediaVerifierRef &verifier); /** * Remove verifier for specified media id. @@ -167,13 +176,30 @@ namespace zypp public: /** - * attach the media using the concrete handler + * Attach the media using the concrete handler. */ void attach(MediaAccessId accessId, bool next = false); /** + * Attach the media if needed and verify, if desired + * media number is avaliable. If the access handler + * supports multiple drives (e.g. CD/DVD), all drives + * are verified. + * + * \throws MediaNotDesiredException if unable to find + * desired media in any drive. + * \throws FIXME if all drives are in use and no one + * was ejected. + */ + void + attachMediaNr(MediaAccessId accessId, MediaNr mediaNr, + bool eject = true); + + /** * Release the attached media and optionally eject. + * \throws exception if eject is true and media is + * shared. */ void release(MediaAccessId accessId, bool eject = false); @@ -210,6 +236,15 @@ namespace zypp isDesiredMedia(MediaAccessId accessId, MediaNr mediaNr) const; /** + * Ask the specified verifier if the attached + * media is the desired one or not. + * \return True if desired media is attached. + */ + bool + isDesiredMedia(MediaAccessId accessId, MediaNr mediaNr, + const MediaVerifierRef &verifier) const; + + /** * 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 even better -- 2.7.4