38 :
Exception(
_(
"Sorry, but this version of libzypp was built without HAL support."))
50 #ifndef NO_HAL // disables zypp's HAL dependency 60 #include <hal/libhal.h> 61 #include <hal/libhal-storage.h> 102 HalError() { dbus_error_init(&
error); }
103 ~HalError() { dbus_error_free(&
error); }
105 inline bool isSet()
const 107 return dbus_error_is_set(&
error);
110 inline HalException halException(
const std::string &msg = std::string())
const 112 if( isSet() &&
error.name != NULL &&
error.message != NULL) {
113 return HalException(
error.name,
error.message);
115 else if( !msg.empty()) {
116 return HalException(msg);
119 return HalException();
131 ZYPP_THROW(HalException(
_(
"HalContext not connected")));
141 ZYPP_THROW(HalException(
_(
"HalDrive not initialized")));
151 ZYPP_THROW(HalException(
_(
"HalVolume not initialized")));
163 if(!e_name.empty() && !e_msg.empty())
164 return str << msg() <<
": " << e_msg <<
" (" << e_name <<
")";
165 else if(!e_msg.empty())
166 return str << msg() <<
": " << e_msg;
205 libhal_drive_free(drv);
224 libhal_volume_free(vol);
230 HalContext_Impl::HalContext_Impl()
238 conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err.error);
240 conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err.error);
243 _(
"Unable to create dbus connection")
247 hctx = libhal_ctx_new();
251 dbus_connection_close(
conn);
252 dbus_connection_unref(
conn);
256 _(
"libhal_ctx_new: Can't create libhal context")
260 if( !libhal_ctx_set_dbus_connection(
hctx,
conn))
262 libhal_ctx_free(
hctx);
266 dbus_connection_close(
conn);
267 dbus_connection_unref(
conn);
271 _(
"libhal_set_dbus_connection: Can't set dbus connection")
275 if( !libhal_ctx_init(
hctx, &err.error))
277 libhal_ctx_free(
hctx);
281 dbus_connection_close(
conn);
282 dbus_connection_unref(
conn);
286 _(
"Unable to initalize HAL context -- hald not running?")
297 libhal_ctx_shutdown(
hctx, &err.error);
298 libhal_ctx_free(
hctx);
303 dbus_connection_close(
conn);
304 dbus_connection_unref(
conn);
342 if(
this == &context)
368 std::vector<std::string>
378 names = libhal_get_all_devices(
h_impl->hctx, &count, &err.error);
384 std::vector<std::string> ret(names, names + count);
385 libhal_free_string_array(names);
396 LibHalDrive *drv = libhal_drive_from_udi(
h_impl->hctx, udi.c_str());
410 LibHalVolume *vol = libhal_volume_from_udi(
h_impl->hctx, udi.c_str());
424 LibHalVolume *vol = libhal_volume_from_device_file(
h_impl->hctx,
425 device_file.c_str());
433 std::vector<std::string>
443 names = libhal_find_device_by_capability(
h_impl->hctx,
451 std::vector<std::string> ret(names, names + count);
452 libhal_free_string_array(names);
459 const std::string &key)
const 467 ret = libhal_device_get_property_bool (
h_impl->hctx,
481 const std::string &key)
const 489 ret = libhal_device_get_property_int (
h_impl->hctx,
503 const std::string &key)
const 511 ret = libhal_device_get_property_uint64(
h_impl->hctx,
525 const std::string &key)
const 533 ret = libhal_device_get_property_bool (
h_impl->hctx,
548 const std::string &key)
const 557 ptr = libhal_device_get_property_string(
h_impl->hctx,
576 const std::string &key,
585 ret = libhal_device_set_property_bool (
h_impl->hctx,
599 const std::string &key,
608 ret = libhal_device_set_property_int (
h_impl->hctx,
622 const std::string &key,
631 ret = libhal_device_set_property_uint64(
h_impl->hctx,
645 const std::string &key,
654 ret = libhal_device_set_property_double(
h_impl->hctx,
668 const std::string &key,
669 const std::string &value)
677 ret = libhal_device_set_property_string(
h_impl->hctx,
691 const std::string &key)
699 ret = libhal_device_remove_property(
h_impl->hctx,
769 const char *ptr = libhal_drive_get_udi(
d_impl->drv);
770 return std::string(ptr ? ptr :
"");
780 const char *ptr = libhal_drive_get_type_textual(
d_impl->drv);
781 return std::string(ptr ? ptr :
"");
791 return std::string(libhal_drive_get_device_file(
d_impl->drv));
801 return libhal_drive_get_device_major(
d_impl->drv);
811 return libhal_drive_get_device_minor(
d_impl->drv);
821 return libhal_drive_uses_removable_media(
d_impl->drv);
825 std::vector<std::string>
831 std::vector<std::string> ret;
832 LibHalDriveCdromCaps caps;
838 caps = libhal_drive_get_cdrom_caps(
d_impl->drv);
840 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDROM)
841 ret.push_back(
"cdrom");
842 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDR)
843 ret.push_back(
"cdr");
844 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDRW)
845 ret.push_back(
"cdrw");
846 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRAM)
847 ret.push_back(
"dvdram");
848 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDROM)
849 ret.push_back(
"dvd");
850 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR)
851 ret.push_back(
"dvdr");
852 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRW)
853 ret.push_back(
"dvdrw");
854 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR)
855 ret.push_back(
"dvdplusr");
856 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW)
857 ret.push_back(
"dvdplusrw");
858 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL)
859 ret.push_back(
"dvdplusrdl");
864 if( libhal_drive_get_type(
d_impl->drv) != LIBHAL_DRIVE_TYPE_CDROM)
874 LibHalPropertySet *props;
877 props = libhal_device_get_all_properties(
d_impl->hal->hctx,
885 std::string dvd(
"storage.cdrom.dvd");
886 std::string cd (
"storage.cdrom.cd");
888 LibHalPropertySetIterator it;
889 for(libhal_psi_init(&it, props);
890 libhal_psi_has_more(&it);
891 libhal_psi_next(&it))
893 if( libhal_psi_get_type(&it) == LIBHAL_PROPERTY_TYPE_BOOLEAN &&
894 libhal_psi_get_bool(&it))
896 key = libhal_psi_get_key(&it);
897 if( key.compare(0, cd.size(), cd) == 0)
899 ret.push_back(key.substr(
sizeof(
"storage.cdrom.")-1));
902 if( key.compare(0, dvd.size(), dvd) == 0)
904 ret.push_back(key.substr(
sizeof(
"storage.cdrom.")-1));
908 libhal_free_property_set(props);
915 std::vector<std::string>
924 names = libhal_drive_find_all_volumes(
d_impl->hal->hctx,
928 std::vector<std::string> ret;
929 ret.assign(names, names + count);
930 libhal_free_string_array(names);
993 const char *ptr = libhal_volume_get_udi(
v_impl->vol);
994 return std::string(ptr ? ptr :
"");
1004 return std::string(libhal_volume_get_device_file(
v_impl->vol));
1014 return libhal_volume_get_device_major(
v_impl->vol);
1024 return libhal_volume_get_device_minor(
v_impl->vol);
1034 return libhal_volume_is_disc(
v_impl->vol);
1044 return libhal_volume_is_partition(
v_impl->vol);
1054 return libhal_volume_is_mounted(
v_impl->vol);
1064 return std::string( libhal_volume_get_fstype(
v_impl->vol));
1074 LibHalVolumeUsage usage( libhal_volume_get_fsusage(
v_impl->vol));
1078 case LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM:
1081 case LIBHAL_VOLUME_USAGE_PARTITION_TABLE:
1082 ret =
"partitiontable";
1084 case LIBHAL_VOLUME_USAGE_RAID_MEMBER:
1087 case LIBHAL_VOLUME_USAGE_CRYPTO:
1090 case LIBHAL_VOLUME_USAGE_UNKNOWN:
1103 return std::string( libhal_volume_get_mount_point(
v_impl->vol));
1133 class HalContext_Impl
1137 class HalVolume_Impl
1153 std::vector<std::string>
1155 {
return std::vector<std::string>(); }
1158 {
return HalDrive(); }
1161 {
return HalVolume(); }
1164 {
return HalVolume(); }
1165 std::vector<std::string>
1167 {
return std::vector<std::string>(); }
1192 {
return std::string(); }
1195 {
return std::string(); }
1198 {
return std::string(); }
1208 std::vector<std::string>
1210 {
return std::vector<std::string>(); }
1211 std::vector<std::string>
1213 {
return std::vector<std::string>(); }
1227 {
return std::string(); }
1230 {
return std::string(); }
1248 {
return std::string(); }
1251 {
return std::string(); }
1254 {
return std::string(); }
Hardware abstaction layer library wrapper.
HalVolume getVolumeFromUDI(const std::string &udi) const
Construct a HalVolume object for the specified UDI.
std::vector< std::string > findAllVolumes() const
Retrieve UDI's of all volumes of this drive.
std::string getDevicePropertyString(const std::string &udi, const std::string &key) const
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Hardware abstaction layer storage drive object.
void setDevicePropertyString(const std::string &udi, const std::string &key, const std::string &value)
zypp::RW_pointer< HalDrive_Impl >::unspecified_bool_type bool_type
std::string getDeviceFile() const
zypp::RW_pointer< HalVolume_Impl > v_impl
std::ostream & dumpOn(std::ostream &str, const zypp::shared_ptr< void > &obj)
String related utilities and Regular expression matching.
HalVolume & operator=(const HalVolume &volume)
int32_t getDevicePropertyInt32(const std::string &udi, const std::string &key) const
Hardware abstaction layer exception.
Hardware abstaction layer storage volume object.
unsigned int getDeviceMajor() const
std::string getTypeName() const
HalVolume getVolumeFromDeviceFile(const std::string &device_file) const
HalException()
Default constructor.
void setDevicePropertyDouble(const std::string &udi, const std::string &key, double value)
std::string getFSType() const
HalDrive_Impl(const zypp::RW_pointer< HalContext_Impl > &r, LibHalDrive *d)
unsigned int getDeviceMinor() const
void setDevicePropertyInt32(const std::string &udi, const std::string &key, int32_t value)
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
std::string getUDI() const
std::string getFSUsage() const
zypp::RW_pointer< HalContext_Impl > hal
std::string getUDI() const
HalContext(bool autoconnect=false)
std::string getDeviceFile() const
std::vector< std::string > getCdromCapabilityNames() const
zypp::RW_pointer< HalDrive_Impl > d_impl
void setDevicePropertyUInt64(const std::string &udi, const std::string &key, uint64_t value)
std::vector< std::string > getAllDevices() const
Retrieve UDI's of all devices.
bool usesRemovableMedia() const
HalDrive getDriveFromUDI(const std::string &udi) const
Construct a HalDrive object for the specified UDI.
double getDevicePropertyDouble(const std::string &udi, const std::string &key) const
std::string getMountPoint() const
HalContext & operator=(const HalContext &context)
Base class for Exception.
Hardware abstaction layer library wrapper.
Wrapper for const correct access via Smart pointer types.
zypp::RW_pointer< HalVolume_Impl >::unspecified_bool_type bool_type
zypp::RW_pointer< HalContext_Impl > h_impl
uint64_t getDevicePropertyUInt64(const std::string &udi, const std::string &key) const
bool getDevicePropertyBool(const std::string &udi, const std::string &key) const
void removeDeviceProperty(const std::string &udi, const std::string &key)
unsigned int getDeviceMajor() const
HalVolume_Impl(LibHalVolume *v=NULL)
Easy-to use interface to the ZYPP dependency resolver.
void setDevicePropertyBool(const std::string &udi, const std::string &key, bool value)
unsigned int getDeviceMinor() const
std::vector< std::string > findDevicesByCapability(const std::string &capability) const
Retrieve UDI's of all devices with a capability.
HalDrive & operator=(const HalDrive &drive)
zypp::RW_pointer< HalContext_Impl >::unspecified_bool_type bool_type