else if ( user == media::MediaChangeReport::EJECT )
{
DBG << "Eject: try to release" << endl;
- try
- {
- //zypp::SourceManager::sourceManager()->releaseAllSources();
- }
- catch (const zypp::Exception& excpt_r)
- {
- ZYPP_CAUGHT(excpt_r);
- ERR << "Failed to release all sources" << endl;
- }
+ media_mgr.releaseAll();
media_mgr.release (media, true); // one more release needed for eject
- // FIXME: this will not work, probably
}
else if ( user == media::MediaChangeReport::RETRY ||
user == media::MediaChangeReport::CHANGE_URL )
else if ( user == media::MediaChangeReport::EJECT )
{
DBG << "Eject: try to release" << endl;
- try
- {
- //zypp::SourceManager::sourceManager()->releaseAllSources();
- }
- catch (const zypp::Exception& excpt_r)
- {
- ZYPP_CAUGHT(excpt_r);
- ERR << "Failed to release all sources" << endl;
- }
+ media_mgr.releaseAll();
media_mgr.release (media, true); // one more release needed for eject
- // FIXME: this will not work, probably
}
else if ( user == media::MediaChangeReport::RETRY ||
user == media::MediaChangeReport::CHANGE_URL )
else if (user == media::MediaChangeReport::EJECT)
{
DBG << "Eject: try to release" << endl;
- try
- {
- //! \todo do we need replacement for this at all?
- // zypp::SourceManager::sourceManager()->releaseAllSources();
- }
- catch (const zypp::Exception& excpt_r)
- {
- ZYPP_CAUGHT(excpt_r);
- ERR << "Failed to release all sources" << endl;
- }
+ media_mgr.releaseAll();
media_mgr.release (_media, true); // one more release needed for eject
- // FIXME: this will not work, probably
}
else if (user == media::MediaChangeReport::RETRY ||
user == media::MediaChangeReport::CHANGE_URL)
ref.handler->release(eject);
}
+ // ---------------------------------------------------------------
+ void
+ MediaManager::releaseAll()
+ {
+ MutexLock glock(g_Mutex);
+
+ MIL << "Releasing all attached media" << std::endl;
+
+ ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
+ for( ; m != m_impl->mediaMap.end(); ++m)
+ {
+ if( m->second.handler->dependsOnParent())
+ continue;
+
+ try
+ {
+ if(m->second.handler->isAttached())
+ {
+ DBG << "Releasing media id " << m->first << std::endl;
+ m->second.desired = false;
+ m->second.handler->release(false);
+ }
+ else
+ {
+ DBG << "Media id " << m->first << " not attached " << std::endl;
+ }
+ }
+ catch(const MediaException & e)
+ {
+ ZYPP_CAUGHT(e);
+ ERR << "Failed to release media id " << m->first << std::endl;
+ }
+ }
+
+ MIL << "Exit" << std::endl;
+ }
+
// ---------------------------------------------------------------
void
MediaManager::disconnect(MediaAccessId accessId)