24 :
Exception(
_(
"Sorry, but this version of libzypp was built without HAL support."))
36 #ifndef NO_HAL // disables zypp's HAL dependency
46 #include <hal/libhal.h>
47 #include <hal/libhal-storage.h>
88 HalError() { dbus_error_init(&
error); }
89 ~HalError() { dbus_error_free(&
error); }
91 inline bool isSet()
const
93 return dbus_error_is_set(&
error);
96 inline HalException halException(
const std::string &msg = std::string())
const
98 if( isSet() &&
error.name != NULL &&
error.message != NULL) {
99 return HalException(
error.name,
error.message);
101 else if( !msg.empty()) {
102 return HalException(msg);
105 return HalException();
117 ZYPP_THROW(HalException(
_(
"HalContext not connected")));
127 ZYPP_THROW(HalException(
_(
"HalDrive not initialized")));
137 ZYPP_THROW(HalException(
_(
"HalVolume not initialized")));
149 if(!e_name.empty() && !e_msg.empty())
150 return str << msg() <<
": " << e_msg <<
" (" << e_name <<
")";
151 else if(!e_msg.empty())
152 return str << msg() <<
": " << e_msg;
191 libhal_drive_free(drv);
210 libhal_volume_free(vol);
216 HalContext_Impl::HalContext_Impl()
224 conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err.error);
226 conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err.error);
229 _(
"Unable to create dbus connection")
233 hctx = libhal_ctx_new();
237 dbus_connection_close(
conn);
238 dbus_connection_unref(
conn);
242 _(
"libhal_ctx_new: Can't create libhal context")
246 if( !libhal_ctx_set_dbus_connection(
hctx,
conn))
248 libhal_ctx_free(
hctx);
252 dbus_connection_close(
conn);
253 dbus_connection_unref(
conn);
257 _(
"libhal_set_dbus_connection: Can't set dbus connection")
261 if( !libhal_ctx_init(
hctx, &err.error))
263 libhal_ctx_free(
hctx);
267 dbus_connection_close(
conn);
268 dbus_connection_unref(
conn);
272 _(
"Unable to initalize HAL context -- hald not running?")
283 libhal_ctx_shutdown(
hctx, &err.error);
284 libhal_ctx_free(
hctx);
289 dbus_connection_close(
conn);
290 dbus_connection_unref(
conn);
328 if(
this == &context)
354 std::vector<std::string>
364 names = libhal_get_all_devices(
h_impl->hctx, &count, &err.error);
370 std::vector<std::string> ret(names, names + count);
371 libhal_free_string_array(names);
382 LibHalDrive *drv = libhal_drive_from_udi(
h_impl->hctx, udi.c_str());
396 LibHalVolume *vol = libhal_volume_from_udi(
h_impl->hctx, udi.c_str());
410 LibHalVolume *vol = libhal_volume_from_device_file(
h_impl->hctx,
411 device_file.c_str());
419 std::vector<std::string>
429 names = libhal_find_device_by_capability(
h_impl->hctx,
437 std::vector<std::string> ret(names, names + count);
438 libhal_free_string_array(names);
445 const std::string &key)
const
453 ret = libhal_device_get_property_bool (
h_impl->hctx,
467 const std::string &key)
const
475 ret = libhal_device_get_property_int (
h_impl->hctx,
489 const std::string &key)
const
497 ret = libhal_device_get_property_uint64(
h_impl->hctx,
511 const std::string &key)
const
519 ret = libhal_device_get_property_bool (
h_impl->hctx,
534 const std::string &key)
const
543 ptr = libhal_device_get_property_string(
h_impl->hctx,
562 const std::string &key,
571 ret = libhal_device_set_property_bool (
h_impl->hctx,
585 const std::string &key,
594 ret = libhal_device_set_property_int (
h_impl->hctx,
608 const std::string &key,
617 ret = libhal_device_set_property_uint64(
h_impl->hctx,
631 const std::string &key,
640 ret = libhal_device_set_property_double(
h_impl->hctx,
654 const std::string &key,
655 const std::string &value)
663 ret = libhal_device_set_property_string(
h_impl->hctx,
677 const std::string &key)
685 ret = libhal_device_remove_property(
h_impl->hctx,
755 const char *ptr = libhal_drive_get_udi(
d_impl->drv);
756 return std::string(ptr ? ptr :
"");
766 const char *ptr = libhal_drive_get_type_textual(
d_impl->drv);
767 return std::string(ptr ? ptr :
"");
777 return std::string(libhal_drive_get_device_file(
d_impl->drv));
787 return libhal_drive_get_device_major(
d_impl->drv);
797 return libhal_drive_get_device_minor(
d_impl->drv);
807 return libhal_drive_uses_removable_media(
d_impl->drv);
811 std::vector<std::string>
817 std::vector<std::string> ret;
818 LibHalDriveCdromCaps caps;
824 caps = libhal_drive_get_cdrom_caps(
d_impl->drv);
826 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDROM)
827 ret.push_back(
"cdrom");
828 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDR)
829 ret.push_back(
"cdr");
830 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDRW)
831 ret.push_back(
"cdrw");
832 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRAM)
833 ret.push_back(
"dvdram");
834 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDROM)
835 ret.push_back(
"dvd");
836 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR)
837 ret.push_back(
"dvdr");
838 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRW)
839 ret.push_back(
"dvdrw");
840 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR)
841 ret.push_back(
"dvdplusr");
842 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW)
843 ret.push_back(
"dvdplusrw");
844 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL)
845 ret.push_back(
"dvdplusrdl");
850 if( libhal_drive_get_type(
d_impl->drv) != LIBHAL_DRIVE_TYPE_CDROM)
860 LibHalPropertySet *props;
863 props = libhal_device_get_all_properties(
d_impl->hal->hctx,
871 std::string dvd(
"storage.cdrom.dvd");
872 std::string cd (
"storage.cdrom.cd");
874 LibHalPropertySetIterator it;
875 for(libhal_psi_init(&it, props);
876 libhal_psi_has_more(&it);
877 libhal_psi_next(&it))
879 if( libhal_psi_get_type(&it) == LIBHAL_PROPERTY_TYPE_BOOLEAN &&
880 libhal_psi_get_bool(&it))
882 key = libhal_psi_get_key(&it);
883 if( key.compare(0, cd.size(), cd) == 0)
885 ret.push_back(key.substr(
sizeof(
"storage.cdrom.")-1));
888 if( key.compare(0, dvd.size(), dvd) == 0)
890 ret.push_back(key.substr(
sizeof(
"storage.cdrom.")-1));
894 libhal_free_property_set(props);
901 std::vector<std::string>
910 names = libhal_drive_find_all_volumes(
d_impl->hal->hctx,
914 std::vector<std::string> ret;
915 ret.assign(names, names + count);
916 libhal_free_string_array(names);
979 const char *ptr = libhal_volume_get_udi(
v_impl->vol);
980 return std::string(ptr ? ptr :
"");
990 return std::string(libhal_volume_get_device_file(
v_impl->vol));
1000 return libhal_volume_get_device_major(
v_impl->vol);
1010 return libhal_volume_get_device_minor(
v_impl->vol);
1020 return libhal_volume_is_disc(
v_impl->vol);
1030 return libhal_volume_is_partition(
v_impl->vol);
1040 return libhal_volume_is_mounted(
v_impl->vol);
1050 return std::string( libhal_volume_get_fstype(
v_impl->vol));
1060 LibHalVolumeUsage usage( libhal_volume_get_fsusage(
v_impl->vol));
1064 case LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM:
1067 case LIBHAL_VOLUME_USAGE_PARTITION_TABLE:
1068 ret =
"partitiontable";
1070 case LIBHAL_VOLUME_USAGE_RAID_MEMBER:
1073 case LIBHAL_VOLUME_USAGE_CRYPTO:
1076 case LIBHAL_VOLUME_USAGE_UNKNOWN:
1089 return std::string( libhal_volume_get_mount_point(
v_impl->vol));
1119 class HalContext_Impl
1123 class HalVolume_Impl
1139 std::vector<std::string>
1141 {
return std::vector<std::string>(); }
1144 {
return HalDrive(); }
1147 {
return HalVolume(); }
1150 {
return HalVolume(); }
1151 std::vector<std::string>
1153 {
return std::vector<std::string>(); }
1178 {
return std::string(); }
1181 {
return std::string(); }
1184 {
return std::string(); }
1194 std::vector<std::string>
1196 {
return std::vector<std::string>(); }
1197 std::vector<std::string>
1199 {
return std::vector<std::string>(); }
1213 {
return std::string(); }
1216 {
return std::string(); }
1234 {
return std::string(); }
1237 {
return std::string(); }
1240 {
return std::string(); }
Hardware abstaction layer library wrapper.
bool getDevicePropertyBool(const std::string &udi, const std::string &key) const
std::vector< std::string > getCdromCapabilityNames() const
int32_t getDevicePropertyInt32(const std::string &udi, const std::string &key) const
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
std::string getMountPoint() const
Hardware abstaction layer storage drive object.
std::vector< std::string > getAllDevices() const
Retrieve UDI's of all devices.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
HalDrive getDriveFromUDI(const std::string &udi) const
Construct a HalDrive object for the specified UDI.
unsigned int getDeviceMinor() const
void setDevicePropertyString(const std::string &udi, const std::string &key, const std::string &value)
std::string getDevicePropertyString(const std::string &udi, const std::string &key) const
std::string getTypeName() const
zypp::RW_pointer< HalDrive_Impl >::unspecified_bool_type bool_type
zypp::RW_pointer< HalVolume_Impl > v_impl
uint64_t getDevicePropertyUInt64(const std::string &udi, const std::string &key) const
unsigned int getDeviceMajor() const
HalVolume & operator=(const HalVolume &volume)
std::string getUDI() const
Hardware abstaction layer exception.
Hardware abstaction layer storage volume object.
HalVolume getVolumeFromUDI(const std::string &udi) const
Construct a HalVolume object for the specified UDI.
void setDevicePropertyDouble(const std::string &udi, const std::string &key, double value)
HalDrive_Impl(const zypp::RW_pointer< HalContext_Impl > &r, LibHalDrive *d)
std::string getDeviceFile() const
void setDevicePropertyInt32(const std::string &udi, const std::string &key, int32_t value)
zypp::RW_pointer< HalContext_Impl > hal
HalContext(bool autoconnect=false)
std::string getFSType() const
std::string getFSUsage() const
std::vector< std::string > findDevicesByCapability(const std::string &capability) const
Retrieve UDI's of all devices with a capability.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
unsigned int getDeviceMajor() const
HalVolume getVolumeFromDeviceFile(const std::string &device_file) const
#define _(MSG)
Return translated text.
zypp::RW_pointer< HalDrive_Impl > d_impl
void setDevicePropertyUInt64(const std::string &udi, const std::string &key, uint64_t value)
bool usesRemovableMedia() const
HalContext & operator=(const HalContext &context)
Base class for Exception.
unsigned int getDeviceMinor() const
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
double getDevicePropertyDouble(const std::string &udi, const std::string &key) const
std::vector< std::string > findAllVolumes() const
Retrieve UDI's of all volumes of this drive.
std::string getUDI() const
void removeDeviceProperty(const std::string &udi, const std::string &key)
HalVolume_Impl(LibHalVolume *v=NULL)
void setDevicePropertyBool(const std::string &udi, const std::string &key, bool value)
std::string getDeviceFile() const
HalDrive & operator=(const HalDrive &drive)
zypp::RW_pointer< HalContext_Impl >::unspecified_bool_type bool_type