}
// --------------------------------------------------------------
- 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
{
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()
}
// --------------------------------------------------------------
- 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 : "");
}
// --------------------------------------------------------------
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()
// --------------------------------------------------------------
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);
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.
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);
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.
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;
operator bool_type() const;
+ std::string
+ getUDI() const;
+
/**
* \return The Volume drive's device file name.
*/