- Implemented getUDI(), getTypeName(), getCdromCapabilityNames()
authorMarius Tomaschewski <mt@suse.de>
Tue, 14 Feb 2006 13:33:12 +0000 (13:33 +0000)
committerMarius Tomaschewski <mt@suse.de>
Tue, 14 Feb 2006 13:33:12 +0000 (13:33 +0000)
zypp/target/hal/HalContext.cc
zypp/target/hal/HalContext.h

index f8ebeda..3a5641c 100644 (file)
@@ -331,30 +331,6 @@ namespace zypp
       }
 
       // --------------------------------------------------------------
-      std::vector<std::string>
-      HalContext::findDevicesByCapability(const std::string &capability) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError   err;
-        char     **names;
-        int        count = 0;
-
-        names = libhal_find_device_by_capability(h_impl->hctx,
-                                                 capability.c_str(),
-                                                 &count, &err.error);
-        if( !names)
-        {
-          ZYPP_THROW(HalException(err.toString()));
-        }
-
-        std::vector<std::string> ret(names, names + count);
-        libhal_free_string_array(names);
-        return ret;
-      }
-
-      // --------------------------------------------------------------
       HalDrive
       HalContext::getDriveFromUDI(const std::string &udi) const
       {
@@ -382,6 +358,30 @@ namespace zypp
           return HalVolume();
       }
 
+      // --------------------------------------------------------------
+      std::vector<std::string>
+      HalContext::findDevicesByCapability(const std::string &capability) const
+      {
+        MutexLock  lock(g_Mutex);
+        VERIFY_CONTEXT(h_impl);
+
+        HalError   err;
+        char     **names;
+        int        count = 0;
+
+        names = libhal_find_device_by_capability(h_impl->hctx,
+                                                 capability.c_str(),
+                                                 &count, &err.error);
+        if( !names)
+        {
+          ZYPP_THROW(HalException(err.toString()));
+        }
+
+        std::vector<std::string> ret(names, names + count);
+        libhal_free_string_array(names);
+        return ret;
+      }
+
 
       ////////////////////////////////////////////////////////////////
       HalDrive::HalDrive()
@@ -436,33 +436,25 @@ namespace zypp
       }
 
       // --------------------------------------------------------------
-      std::vector<std::string>
-      HalDrive::findAllVolumes() const
+      std::string
+      HalDrive::getUDI() const
       {
         MutexLock  lock(g_Mutex);
         VERIFY_DRIVE(d_impl);
 
-        char     **names;
-        int        count = 0;
-
-        names = libhal_drive_find_all_volumes(d_impl->hal->hctx,
-                                              d_impl->drv,
-                                              &count);
-
-        std::vector<std::string> ret;
-        ret.assign(names, names + count);
-        libhal_free_string_array(names);
-        return ret;
+        const char *ptr = libhal_drive_get_udi(d_impl->drv);
+        return std::string(ptr ? ptr : "");
       }
 
       // --------------------------------------------------------------
-      bool
-      HalDrive::usesRemovableMedia() const
+      std::string
+      HalDrive::getTypeName() const
       {
         MutexLock  lock(g_Mutex);
         VERIFY_DRIVE(d_impl);
 
-        return libhal_drive_uses_removable_media(d_impl->drv);
+        const char *ptr = libhal_drive_get_type_textual(d_impl->drv);
+        return std::string(ptr ? ptr : "");
       }
 
       // --------------------------------------------------------------
@@ -495,6 +487,126 @@ namespace zypp
         return libhal_drive_get_device_minor(d_impl->drv);
       }
 
+      // --------------------------------------------------------------
+      bool
+      HalDrive::usesRemovableMedia() const
+      {
+        MutexLock  lock(g_Mutex);
+        VERIFY_DRIVE(d_impl);
+
+        return libhal_drive_uses_removable_media(d_impl->drv);
+      }
+
+      // --------------------------------------------------------------
+      std::vector<std::string>
+      HalDrive::getCdromCapabilityNames() const
+      {
+        MutexLock  lock(g_Mutex);
+        VERIFY_DRIVE(d_impl);
+
+        std::vector<std::string> ret;
+        LibHalDriveCdromCaps     caps;
+
+        /*
+        ** FIXME: there is no textual variant :-(
+        **        using property key names...
+        */
+        caps = libhal_drive_get_cdrom_caps(d_impl->drv);
+
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDROM)
+          ret.push_back("cdrom");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDR)
+          ret.push_back("cdr");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDRW)
+          ret.push_back("cdrw");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRAM)
+          ret.push_back("dvdram");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDROM)
+          ret.push_back("dvd");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR)
+          ret.push_back("dvdr");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRW)
+          ret.push_back("dvdrw");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR)
+          ret.push_back("dvdplusr");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW)
+          ret.push_back("dvdplusrw");
+        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL)
+          ret.push_back("dvdplusrdl");
+
+        return ret;
+
+#if 0
+        if( libhal_drive_get_type(d_impl->drv) != LIBHAL_DRIVE_TYPE_CDROM)
+          ZYPP_THROW(HalException("Not a CDROM drive"));
+
+        /*
+        ** FIXME: we use property keys matching
+        **          "storage.cdrom.cd*"
+        **          "storage.cdrom.dvd*"
+        ** but this may print other bool keys,
+        ** that are not CDROM caps.
+        */
+        LibHalPropertySet         *props;
+        HalError                   err;
+
+        props = libhal_device_get_all_properties(d_impl->hal->hctx,
+                                                 getUDI().c_str(),
+                                                 &err.error);
+        if( !props)
+          ZYPP_THROW(HalException(err.toString()));
+
+        std::vector<std::string>   ret(1, getTypeName());
+        std::string                key;
+        std::string                dvd("storage.cdrom.dvd");
+        std::string                cd ("storage.cdrom.cd");
+
+        LibHalPropertySetIterator  it;
+        for(libhal_psi_init(&it, props);
+            libhal_psi_has_more(&it);
+            libhal_psi_next(&it))
+        {
+          if( libhal_psi_get_type(&it) == LIBHAL_PROPERTY_TYPE_BOOLEAN &&
+              libhal_psi_get_bool(&it))
+          {
+            key = libhal_psi_get_key(&it);
+            if( key.compare(0, cd.size(), cd) == 0)
+            {
+              ret.push_back(key.substr(sizeof("storage.cdrom.")-1));
+            }
+            else
+            if( key.compare(0, dvd.size(), dvd) == 0)
+            {
+              ret.push_back(key.substr(sizeof("storage.cdrom.")-1));
+            }
+          }
+        }
+        libhal_free_property_set(props);
+
+        return ret;
+#endif
+      }
+
+      // --------------------------------------------------------------
+      std::vector<std::string>
+      HalDrive::findAllVolumes() const
+      {
+        MutexLock  lock(g_Mutex);
+        VERIFY_DRIVE(d_impl);
+
+        char     **names;
+        int        count = 0;
+
+        names = libhal_drive_find_all_volumes(d_impl->hal->hctx,
+                                              d_impl->drv,
+                                              &count);
+
+        std::vector<std::string> ret;
+        ret.assign(names, names + count);
+        libhal_free_string_array(names);
+        return ret;
+      }
+
 
       ////////////////////////////////////////////////////////////////
       HalVolume::HalVolume()
@@ -548,6 +660,17 @@ namespace zypp
 
       // --------------------------------------------------------------
       std::string
+      HalVolume::getUDI() const
+      {
+        MutexLock  lock(g_Mutex);
+        VERIFY_VOLUME(v_impl);
+
+        const char *ptr = libhal_volume_get_udi(v_impl->vol);
+        return std::string(ptr ? ptr : "");
+      }
+
+      // --------------------------------------------------------------
+      std::string
       HalVolume::getDeviceFile() const
       {
         MutexLock  lock(g_Mutex);
index ebda1ac..1443cde 100644 (file)
@@ -88,14 +88,6 @@ namespace zypp
         getAllDevices() const;
 
         /**
-         * Retrieve UDI's of all devices with a capability.
-         * \param  The \p capability name
-         * \return Vector with device UDI's.
-         */
-        std::vector<std::string>
-        findDevicesByCapability(const std::string &capability) const;
-
-        /**
          * Construct a HalDrive object for the specified UDI.
          * \param  The \p udi of the drive.
          * \return The HalDrive object.
@@ -111,6 +103,14 @@ namespace zypp
         HalVolume
         getVolumeFromUDI(const std::string &udi) const;
 
+        /**
+         * Retrieve UDI's of all devices with a capability.
+         * \param  The \p capability name
+         * \return Vector with device UDI's.
+         */
+        std::vector<std::string>
+        findDevicesByCapability(const std::string &capability) const;
+
       private:
         //friend HalMonitor;
         HalContext(bool,bool);
@@ -142,12 +142,11 @@ namespace zypp
 
         operator bool_type() const;
 
-        /**
-         * Retrieve UDI's of all volumes of this drive.
-         * \return Vector with volume UDI's.
-         */
-        std::vector<std::string>
-        findAllVolumes() const;
+        std::string
+        getUDI() const;
+
+        std::string
+        getTypeName() const;
 
         /**
          * \return The drive's device file name.
@@ -173,6 +172,27 @@ namespace zypp
         bool
         usesRemovableMedia() const;
 
+        /*
+        ** Returns the media type names supported by the drive.
+        **
+        ** Since hal does not implement a textual form here, we
+        ** are using the drive type and property names from
+        ** "storage.cdrom.*" namespace:
+        **   cdrom, cdr, cdrw, dvd, dvdr, dvdrw, dvdram,
+        **   dvdplusr, dvdplusrw, dvdplusrdl
+        **
+        ** FIXME: Should we provide own LibHalDriveCdromCaps?
+        */
+        std::vector<std::string>
+        getCdromCapabilityNames() const;
+
+        /**
+         * Retrieve UDI's of all volumes of this drive.
+         * \return Vector with volume UDI's.
+         */
+        std::vector<std::string>
+        findAllVolumes() const;
+
       private:
         friend class HalContext;
 
@@ -205,6 +225,9 @@ namespace zypp
 
         operator bool_type() const;
 
+        std::string
+        getUDI() const;
+
         /**
          * \return The Volume drive's device file name.
          */