- getDetectedDevices added (fate #120298)
authorJan Kupec <jkupec@suse.cz>
Thu, 13 Mar 2008 10:32:34 +0000 (10:32 +0000)
committerJan Kupec <jkupec@suse.cz>
Thu, 13 Mar 2008 10:32:34 +0000 (10:32 +0000)
zypp/media/MediaAccess.cc
zypp/media/MediaAccess.h
zypp/media/MediaCD.cc
zypp/media/MediaCD.h
zypp/media/MediaHandler.cc
zypp/media/MediaHandler.h
zypp/media/MediaManager.cc
zypp/media/MediaManager.h

index a4db75d..797de5e 100644 (file)
@@ -235,6 +235,22 @@ bool MediaAccess::hasMoreDevices() const
 }
 
 
+void
+MediaAccess::getDetectedDevices(std::vector<std::string> & devices,
+                                unsigned int & index) const
+{
+  if (_handler)
+  {
+    _handler->getDetectedDevices(devices, index);
+    return;
+  }
+
+  if (!devices.empty())
+    devices.clear();
+  index = 0;
+}
+
+
 // local directory that corresponds to medias url
 // If media is not open an empty pathname.
 Pathname
index 4c80856..0090210 100644 (file)
@@ -170,6 +170,19 @@ namespace zypp {
        bool isAttached() const;
         
         bool hasMoreDevices() const;
+        
+        /**
+         * Fill in a vector of detected ejectable devices and the index of the
+         * currently attached device within the vector. The contents of the vector
+         * are the device names (/dev/cdrom and such).
+         * 
+         * \param devices  vector to load with the device names
+         * \param index    index of the currently used device in the devices vector
+         */
+        virtual void
+        getDetectedDevices(std::vector<std::string> & devices,
+                           unsigned int & index) const;
+
 
        /**
         * Return the local directory that corresponds to medias url,
index 4becfdb..ccda8d8 100644 (file)
@@ -216,7 +216,7 @@ namespace zypp {
   //  METHOD TYPE : MediaCD::DeviceList
   //
   MediaCD::DeviceList
-  MediaCD::detectDevices(bool supportingDVD)
+  MediaCD::detectDevices(bool supportingDVD) const
   {
     using namespace zypp::target::hal;
 
@@ -828,6 +828,43 @@ namespace zypp {
     return (unsigned) _lastdev_tried < _devices.size() - 1;
   }
 
+  void
+  MediaCD::getDetectedDevices(std::vector<std::string> & devices,
+                              unsigned int & index) const
+  {
+    index = 0;
+    if (!devices.empty())
+      devices.clear();
+
+    for (DeviceList::const_iterator it = _devices.begin();
+         it != _devices.end(); ++it)
+      devices.push_back(it->name);
+
+    if (_lastdev >= 0)
+      index = _lastdev;
+
+    // try to detect again if _devices are empty (maybe this method will be
+    // called before _devices get actually filled)
+    if (devices.empty())
+    {
+      DBG << "no device list so far, trying to detect" << endl;
+
+      DeviceList detected(
+        detectDevices(_url.getScheme() == "dvd" ? true : false));
+
+      for (DeviceList::const_iterator it = detected.begin();
+           it != detected.end(); ++it)
+        devices.push_back(it->name);
+
+      // don't know which one is in use in this case
+      index = 0;
+    }
+
+    MIL << "got " << devices.size() << " detected devices, current: "
+        << (index < devices.size() ? devices[index] : "<none>")
+        << "(" << index << ")" << endl;
+  }
+
 
   } // namespace media
 } // namespace zypp
index f6cc8e8..647f511 100644 (file)
@@ -40,7 +40,7 @@ namespace zypp {
         static bool openTray( const std::string & device_r );
         static bool closeTray( const std::string & device_r );
 
-       DeviceList  detectDevices(bool supportingDVD);
+       DeviceList  detectDevices(bool supportingDVD) const;
 
       protected:
 
@@ -60,6 +60,10 @@ namespace zypp {
         
         virtual bool hasMoreDevices();
 
+        virtual void
+        getDetectedDevices(std::vector<std::string> & devices,
+                           unsigned int & index) const;
+
       public:
 
         MediaCD( const Url &      url_r,
index 464e565..7ea9b70 100644 (file)
@@ -1383,6 +1383,18 @@ bool MediaHandler::hasMoreDevices()
   return false;
 }
 
+void MediaHandler::getDetectedDevices(std::vector<std::string> & devices,
+                                      unsigned int & index) const
+{
+  // clear the vector by default
+  if (!devices.empty())
+    devices.clear();
+  index = 0;
+
+  DBG << "No devices for this medium" << endl;
+}
+
+
   } // namespace media
 } // namespace zypp
 // vim: set ts=8 sts=2 sw=2 ai noet:
index 9fb8a27..6a5ce99 100644 (file)
@@ -685,6 +685,18 @@ class MediaHandler {
          * Check if the media has one more device available for attach(true). 
          */
         virtual bool hasMoreDevices();
+        
+        /**
+         * Fill in a vector of detected ejectable devices and the index of the
+         * currently attached device within the vector. The contents of the vector
+         * are the device names (/dev/cdrom and such).
+         * 
+         * \param devices  vector to load with the device names
+         * \param index    index of the currently used device in the devices vector
+         */
+        virtual void
+        getDetectedDevices(std::vector<std::string> & devices,
+                           unsigned int & index) const;
 };
 
 ///////////////////////////////////////////////////////////////////
index 85a3406..067dccf 100644 (file)
@@ -989,7 +989,9 @@ namespace zypp
                                      std::vector<std::string> & devices,
                                      unsigned int & index) const
     {
-      //! \todo implementation
+      MutexLock glock(g_Mutex);
+      ManagedMedia &ref( m_impl->findMM(accessId));
+      return ref.handler->getDetectedDevices(devices, index);
     }
 
     // ---------------------------------------------------------------
index c3313d6..60c473e 100644 (file)
@@ -804,9 +804,13 @@ namespace zypp
                          const Pathname & filename ) const;
 
       /**
-       * Fill in a vector of detected devices and the index of the currently
-       * attached device within the vector. The contents of the vector
+       * Fill in a vector of detected ejectable devices and the index of the
+       * currently attached device within the vector. The contents of the vector
        * are the device names (/dev/cdrom and such).
+       * 
+       * \param accessId Medium id.
+       * \param devices  vector to load with the device names
+       * \param index    index of the currently used device in the devices vector
        */
       void
       getDetectedDevices(MediaAccessId accessId,