00001
00002
00003
00004
00005
00006
00007
00008
00013 #include <zypp/target/hal/HalException.h>
00015 namespace zypp
00016 {
00017
00018 namespace target
00019 {
00020
00021 namespace hal
00022 {
00023 NoHalException::NoHalException()
00024 : Exception(_("Sorry, but this version of libzypp was built without HAL support."))
00025 {}
00027 }
00030 }
00033 }
00035
00036 #ifndef NO_HAL // disables zypp's HAL dependency
00037
00038 #include <zypp/target/hal/HalContext.h>
00039 #include <zypp/thread/Mutex.h>
00040 #include <zypp/thread/MutexLock.h>
00041 #include <zypp/base/NonCopyable.h>
00042 #include <zypp/base/Logger.h>
00043 #include <zypp/base/String.h>
00044 #include <zypp/base/Gettext.h>
00045
00046 #include <hal/libhal.h>
00047 #include <hal/libhal-storage.h>
00048
00049 #include <iostream>
00050
00051 using namespace std;
00052
00054 namespace zypp
00055 {
00056
00057 namespace target
00058 {
00059
00060 namespace hal
00061 {
00062
00063 using zypp::thread::Mutex;
00064 using zypp::thread::MutexLock;
00065
00067 namespace
00068 {
00069
00070
00072
00076 static Mutex g_Mutex;
00077
00078
00080
00083 class HalError
00084 {
00085 public:
00086 DBusError error;
00087
00088 HalError() { dbus_error_init(&error); }
00089 ~HalError() { dbus_error_free(&error); }
00090
00091 inline bool isSet() const
00092 {
00093 return dbus_error_is_set(&error);
00094 }
00095
00096 inline HalException halException(const std::string &msg = std::string()) const
00097 {
00098 if( isSet() && error.name != NULL && error.message != NULL) {
00099 return HalException(error.name, error.message);
00100 }
00101 else if( !msg.empty()) {
00102 return HalException(msg);
00103 }
00104 else {
00105 return HalException();
00106 }
00107 }
00108 };
00109
00110
00111
00112 inline void
00113 VERIFY_CONTEXT(const zypp::RW_pointer<HalContext_Impl> &h)
00114 {
00115 if( !h)
00116 {
00117 ZYPP_THROW(HalException(_("HalContext not connected")));
00118 }
00119 }
00120
00121
00122 inline void
00123 VERIFY_DRIVE(const zypp::RW_pointer<HalDrive_Impl> &d)
00124 {
00125 if( !d)
00126 {
00127 ZYPP_THROW(HalException(_("HalDrive not initialized")));
00128 }
00129 }
00130
00131
00132 inline void
00133 VERIFY_VOLUME(const zypp::RW_pointer<HalVolume_Impl> &v)
00134 {
00135 if( !v)
00136 {
00137 ZYPP_THROW(HalException(_("HalVolume not initialized")));
00138 }
00139 }
00140
00142 }
00144
00146 std::ostream &
00147 HalException::dumpOn( std::ostream & str ) const
00148 {
00149 if(!e_name.empty() && !e_msg.empty())
00150 return str << msg() << ": " << e_msg << " (" << e_name << ")";
00151 else if(!e_msg.empty())
00152 return str << msg() << ": " << e_msg;
00153 else
00154 return str << msg();
00155 }
00156
00158 class HalContext_Impl
00159 {
00160 public:
00161 HalContext_Impl();
00162 ~HalContext_Impl();
00163
00164 DBusConnection *conn;
00165 LibHalContext *hctx;
00166 bool pcon;
00167 };
00168
00169
00171 class HalDrive_Impl
00172 {
00173 public:
00174 zypp::RW_pointer<HalContext_Impl> hal;
00175 LibHalDrive *drv;
00176
00177 HalDrive_Impl()
00178 : hal(), drv(NULL)
00179 {
00180 }
00181
00182 HalDrive_Impl(const zypp::RW_pointer<HalContext_Impl> &r,
00183 LibHalDrive *d)
00184 : hal(r), drv(d)
00185 {
00186 }
00187
00188 ~HalDrive_Impl()
00189 {
00190 if( drv)
00191 libhal_drive_free(drv);
00192 }
00193 };
00194
00195
00197 class HalVolume_Impl
00198 {
00199 public:
00200 LibHalVolume *vol;
00201
00202 HalVolume_Impl(LibHalVolume *v=NULL)
00203 : vol(v)
00204 {
00205 }
00206
00207 ~HalVolume_Impl()
00208 {
00209 if( vol)
00210 libhal_volume_free(vol);
00211 }
00212 };
00213
00214
00216 HalContext_Impl::HalContext_Impl()
00217 : conn(NULL)
00218 , hctx(NULL)
00219 , pcon(false)
00220 {
00221 HalError err;
00222
00223 if( pcon)
00224 conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err.error);
00225 else
00226 conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err.error);
00227 if( !conn) {
00228 ZYPP_THROW(err.halException(
00229 _("Unable to create dbus connection")
00230 ));
00231 }
00232
00233 hctx = libhal_ctx_new();
00234 if( !hctx)
00235 {
00236 if( pcon)
00237 dbus_connection_close(conn);
00238 dbus_connection_unref(conn);
00239 conn = NULL;
00240
00241 ZYPP_THROW(HalException(
00242 _("libhal_ctx_new: Can't create libhal context")
00243 ));
00244 }
00245
00246 if( !libhal_ctx_set_dbus_connection(hctx, conn))
00247 {
00248 libhal_ctx_free(hctx);
00249 hctx = NULL;
00250
00251 if( pcon)
00252 dbus_connection_close(conn);
00253 dbus_connection_unref(conn);
00254 conn = NULL;
00255
00256 ZYPP_THROW(HalException(
00257 _("libhal_set_dbus_connection: Can't set dbus connection")
00258 ));
00259 }
00260
00261 if( !libhal_ctx_init(hctx, &err.error))
00262 {
00263 libhal_ctx_free(hctx);
00264 hctx = NULL;
00265
00266 if( pcon)
00267 dbus_connection_close(conn);
00268 dbus_connection_unref(conn);
00269 conn = NULL;
00270
00271 ZYPP_THROW(err.halException(
00272 _("Unable to initalize HAL context -- hald not running?")
00273 ));
00274 }
00275 }
00276
00277
00278 HalContext_Impl::~HalContext_Impl()
00279 {
00280 if( hctx)
00281 {
00282 HalError err;
00283 libhal_ctx_shutdown(hctx, &err.error);
00284 libhal_ctx_free( hctx);
00285 }
00286 if( conn)
00287 {
00288 if( pcon)
00289 dbus_connection_close(conn);
00290 dbus_connection_unref(conn);
00291 }
00292 }
00293
00294
00296 HalContext::HalContext(bool autoconnect)
00297 : h_impl( NULL)
00298 {
00299 MutexLock lock(g_Mutex);
00300
00301 if( autoconnect)
00302 h_impl.reset( new HalContext_Impl());
00303 }
00304
00305
00306 HalContext::HalContext(const HalContext &context)
00307 : h_impl( NULL)
00308 {
00309 MutexLock lock(g_Mutex);
00310
00311 zypp::RW_pointer<HalContext_Impl>(context.h_impl).swap(h_impl);
00312 }
00313
00314
00315 HalContext::~HalContext()
00316 {
00317 MutexLock lock(g_Mutex);
00318
00319 h_impl.reset();
00320 }
00321
00322
00323 HalContext &
00324 HalContext::operator=(const HalContext &context)
00325 {
00326 MutexLock lock(g_Mutex);
00327
00328 if( this == &context)
00329 return *this;
00330
00331 zypp::RW_pointer<HalContext_Impl>(context.h_impl).swap(h_impl);
00332 return *this;
00333 }
00334
00335
00336 HalContext::operator HalContext::bool_type() const
00337 {
00338 MutexLock lock(g_Mutex);
00339
00340 return h_impl;
00341 }
00342
00343
00344 void
00345 HalContext::connect()
00346 {
00347 MutexLock lock(g_Mutex);
00348
00349 if( !h_impl)
00350 h_impl.reset( new HalContext_Impl());
00351 }
00352
00353
00354 std::vector<std::string>
00355 HalContext::getAllDevices() const
00356 {
00357 MutexLock lock(g_Mutex);
00358 VERIFY_CONTEXT(h_impl);
00359
00360 HalError err;
00361 char **names;
00362 int count = 0;
00363
00364 names = libhal_get_all_devices( h_impl->hctx, &count, &err.error);
00365 if( !names)
00366 {
00367 ZYPP_THROW(err.halException());
00368 }
00369
00370 std::vector<std::string> ret(names, names + count);
00371 libhal_free_string_array(names);
00372 return ret;
00373 }
00374
00375
00376 HalDrive
00377 HalContext::getDriveFromUDI(const std::string &udi) const
00378 {
00379 MutexLock lock(g_Mutex);
00380 VERIFY_CONTEXT(h_impl);
00381
00382 LibHalDrive *drv = libhal_drive_from_udi(h_impl->hctx, udi.c_str());
00383 if( drv != NULL)
00384 return HalDrive(new HalDrive_Impl( h_impl, drv));
00385 else
00386 return HalDrive();
00387 }
00388
00389
00390 HalVolume
00391 HalContext::getVolumeFromUDI(const std::string &udi) const
00392 {
00393 MutexLock lock(g_Mutex);
00394 VERIFY_CONTEXT(h_impl);
00395
00396 LibHalVolume *vol = libhal_volume_from_udi(h_impl->hctx, udi.c_str());
00397 if( vol)
00398 return HalVolume( new HalVolume_Impl(vol));
00399 else
00400 return HalVolume();
00401 }
00402
00403
00404 HalVolume
00405 HalContext::getVolumeFromDeviceFile(const std::string &device_file) const
00406 {
00407 MutexLock lock(g_Mutex);
00408 VERIFY_CONTEXT(h_impl);
00409
00410 LibHalVolume *vol = libhal_volume_from_device_file(h_impl->hctx,
00411 device_file.c_str());
00412 if( vol)
00413 return HalVolume( new HalVolume_Impl(vol));
00414 else
00415 return HalVolume();
00416 }
00417
00418
00419 std::vector<std::string>
00420 HalContext::findDevicesByCapability(const std::string &capability) const
00421 {
00422 MutexLock lock(g_Mutex);
00423 VERIFY_CONTEXT(h_impl);
00424
00425 HalError err;
00426 char **names;
00427 int count = 0;
00428
00429 names = libhal_find_device_by_capability(h_impl->hctx,
00430 capability.c_str(),
00431 &count, &err.error);
00432 if( !names)
00433 {
00434 ZYPP_THROW(err.halException());
00435 }
00436
00437 std::vector<std::string> ret(names, names + count);
00438 libhal_free_string_array(names);
00439 return ret;
00440 }
00441
00442
00443 bool
00444 HalContext::getDevicePropertyBool (const std::string &udi,
00445 const std::string &key) const
00446 {
00447 MutexLock lock(g_Mutex);
00448 VERIFY_CONTEXT(h_impl);
00449
00450 HalError err;
00451 dbus_bool_t ret;
00452
00453 ret = libhal_device_get_property_bool (h_impl->hctx,
00454 udi.c_str(),
00455 key.c_str(),
00456 &err.error);
00457 if( err.isSet())
00458 {
00459 ZYPP_THROW(err.halException());
00460 }
00461 return ret;
00462 }
00463
00464
00465 int32_t
00466 HalContext::getDevicePropertyInt32 (const std::string &udi,
00467 const std::string &key) const
00468 {
00469 MutexLock lock(g_Mutex);
00470 VERIFY_CONTEXT(h_impl);
00471
00472 HalError err;
00473 dbus_int32_t ret;
00474
00475 ret = libhal_device_get_property_int (h_impl->hctx,
00476 udi.c_str(),
00477 key.c_str(),
00478 &err.error);
00479 if( err.isSet())
00480 {
00481 ZYPP_THROW(err.halException());
00482 }
00483 return ret;
00484 }
00485
00486
00487 uint64_t
00488 HalContext::getDevicePropertyUInt64(const std::string &udi,
00489 const std::string &key) const
00490 {
00491 MutexLock lock(g_Mutex);
00492 VERIFY_CONTEXT(h_impl);
00493
00494 HalError err;
00495 dbus_uint64_t ret;
00496
00497 ret = libhal_device_get_property_uint64(h_impl->hctx,
00498 udi.c_str(),
00499 key.c_str(),
00500 &err.error);
00501 if( err.isSet())
00502 {
00503 ZYPP_THROW(err.halException());
00504 }
00505 return ret;
00506 }
00507
00508
00509 double
00510 HalContext::getDevicePropertyDouble(const std::string &udi,
00511 const std::string &key) const
00512 {
00513 MutexLock lock(g_Mutex);
00514 VERIFY_CONTEXT(h_impl);
00515
00516 HalError err;
00517 double ret;
00518
00519 ret = libhal_device_get_property_bool (h_impl->hctx,
00520 udi.c_str(),
00521 key.c_str(),
00522 &err.error);
00523 if( err.isSet())
00524 {
00525 ZYPP_THROW(err.halException());
00526 }
00527 return ret;
00528 }
00529
00530
00531
00532 std::string
00533 HalContext::getDevicePropertyString(const std::string &udi,
00534 const std::string &key) const
00535 {
00536 MutexLock lock(g_Mutex);
00537 VERIFY_CONTEXT(h_impl);
00538
00539 HalError err;
00540 std::string ret;
00541 char *ptr;
00542
00543 ptr = libhal_device_get_property_string(h_impl->hctx,
00544 udi.c_str(),
00545 key.c_str(),
00546 &err.error);
00547 if( err.isSet())
00548 {
00549 ZYPP_THROW(err.halException());
00550 }
00551 if( ptr != NULL)
00552 {
00553 ret = ptr;
00554 free(ptr);
00555 }
00556 return ret;
00557 }
00558
00559
00560 void
00561 HalContext::setDevicePropertyBool (const std::string &udi,
00562 const std::string &key,
00563 bool value)
00564 {
00565 MutexLock lock(g_Mutex);
00566 VERIFY_CONTEXT(h_impl);
00567
00568 HalError err;
00569 dbus_bool_t ret;
00570
00571 ret = libhal_device_set_property_bool (h_impl->hctx,
00572 udi.c_str(),
00573 key.c_str(),
00574 value ? 1 : 0,
00575 &err.error);
00576 if( !ret)
00577 {
00578 ZYPP_THROW(err.halException());
00579 }
00580 }
00581
00582
00583 void
00584 HalContext::setDevicePropertyInt32 (const std::string &udi,
00585 const std::string &key,
00586 int32_t value)
00587 {
00588 MutexLock lock(g_Mutex);
00589 VERIFY_CONTEXT(h_impl);
00590
00591 HalError err;
00592 dbus_bool_t ret;
00593
00594 ret = libhal_device_set_property_int (h_impl->hctx,
00595 udi.c_str(),
00596 key.c_str(),
00597 value,
00598 &err.error);
00599 if( !ret)
00600 {
00601 ZYPP_THROW(err.halException());
00602 }
00603 }
00604
00605
00606 void
00607 HalContext::setDevicePropertyUInt64(const std::string &udi,
00608 const std::string &key,
00609 uint64_t value)
00610 {
00611 MutexLock lock(g_Mutex);
00612 VERIFY_CONTEXT(h_impl);
00613
00614 HalError err;
00615 dbus_bool_t ret;
00616
00617 ret = libhal_device_set_property_uint64(h_impl->hctx,
00618 udi.c_str(),
00619 key.c_str(),
00620 value,
00621 &err.error);
00622 if( !ret)
00623 {
00624 ZYPP_THROW(err.halException());
00625 }
00626 }
00627
00628
00629 void
00630 HalContext::setDevicePropertyDouble(const std::string &udi,
00631 const std::string &key,
00632 double value)
00633 {
00634 MutexLock lock(g_Mutex);
00635 VERIFY_CONTEXT(h_impl);
00636
00637 HalError err;
00638 dbus_bool_t ret;
00639
00640 ret = libhal_device_set_property_double(h_impl->hctx,
00641 udi.c_str(),
00642 key.c_str(),
00643 value,
00644 &err.error);
00645 if( !ret)
00646 {
00647 ZYPP_THROW(err.halException());
00648 }
00649 }
00650
00651
00652 void
00653 HalContext::setDevicePropertyString(const std::string &udi,
00654 const std::string &key,
00655 const std::string &value)
00656 {
00657 MutexLock lock(g_Mutex);
00658 VERIFY_CONTEXT(h_impl);
00659
00660 HalError err;
00661 dbus_bool_t ret;
00662
00663 ret = libhal_device_set_property_string(h_impl->hctx,
00664 udi.c_str(),
00665 key.c_str(),
00666 value.c_str(),
00667 &err.error);
00668 if( !ret)
00669 {
00670 ZYPP_THROW(err.halException());
00671 }
00672 }
00673
00674
00675 void
00676 HalContext::removeDeviceProperty(const std::string &udi,
00677 const std::string &key)
00678 {
00679 MutexLock lock(g_Mutex);
00680 VERIFY_CONTEXT(h_impl);
00681
00682 HalError err;
00683 dbus_bool_t ret;
00684
00685 ret = libhal_device_remove_property(h_impl->hctx,
00686 udi.c_str(),
00687 key.c_str(),
00688 &err.error);
00689 if( !ret)
00690 {
00691 ZYPP_THROW(err.halException());
00692 }
00693 }
00694
00696 HalDrive::HalDrive()
00697 : d_impl( NULL)
00698 {
00699 }
00700
00701
00702 HalDrive::HalDrive(HalDrive_Impl *impl)
00703 : d_impl( NULL)
00704 {
00705 MutexLock lock(g_Mutex);
00706
00707 d_impl.reset(impl);
00708 }
00709
00710
00711 HalDrive::HalDrive(const HalDrive &drive)
00712 : d_impl( NULL)
00713 {
00714 MutexLock lock(g_Mutex);
00715
00716 zypp::RW_pointer<HalDrive_Impl>(drive.d_impl).swap(d_impl);
00717 }
00718
00719
00720 HalDrive::~HalDrive()
00721 {
00722 MutexLock lock(g_Mutex);
00723
00724 d_impl.reset();
00725 }
00726
00727
00728 HalDrive &
00729 HalDrive::operator=(const HalDrive &drive)
00730 {
00731 MutexLock lock(g_Mutex);
00732
00733 if( this == &drive)
00734 return *this;
00735
00736 zypp::RW_pointer<HalDrive_Impl>(drive.d_impl).swap(d_impl);
00737 return *this;
00738 }
00739
00740
00741 HalDrive::operator HalDrive::bool_type() const
00742 {
00743 MutexLock lock(g_Mutex);
00744
00745 return d_impl;
00746 }
00747
00748
00749 std::string
00750 HalDrive::getUDI() const
00751 {
00752 MutexLock lock(g_Mutex);
00753 VERIFY_DRIVE(d_impl);
00754
00755 const char *ptr = libhal_drive_get_udi(d_impl->drv);
00756 return std::string(ptr ? ptr : "");
00757 }
00758
00759
00760 std::string
00761 HalDrive::getTypeName() const
00762 {
00763 MutexLock lock(g_Mutex);
00764 VERIFY_DRIVE(d_impl);
00765
00766 const char *ptr = libhal_drive_get_type_textual(d_impl->drv);
00767 return std::string(ptr ? ptr : "");
00768 }
00769
00770
00771 std::string
00772 HalDrive::getDeviceFile() const
00773 {
00774 MutexLock lock(g_Mutex);
00775 VERIFY_DRIVE(d_impl);
00776
00777 return std::string(libhal_drive_get_device_file(d_impl->drv));
00778 }
00779
00780
00781 unsigned int
00782 HalDrive::getDeviceMajor() const
00783 {
00784 MutexLock lock(g_Mutex);
00785 VERIFY_DRIVE(d_impl);
00786
00787 return libhal_drive_get_device_major(d_impl->drv);
00788 }
00789
00790
00791 unsigned int
00792 HalDrive::getDeviceMinor() const
00793 {
00794 MutexLock lock(g_Mutex);
00795 VERIFY_DRIVE(d_impl);
00796
00797 return libhal_drive_get_device_minor(d_impl->drv);
00798 }
00799
00800
00801 bool
00802 HalDrive::usesRemovableMedia() const
00803 {
00804 MutexLock lock(g_Mutex);
00805 VERIFY_DRIVE(d_impl);
00806
00807 return libhal_drive_uses_removable_media(d_impl->drv);
00808 }
00809
00810
00811 std::vector<std::string>
00812 HalDrive::getCdromCapabilityNames() const
00813 {
00814 MutexLock lock(g_Mutex);
00815 VERIFY_DRIVE(d_impl);
00816
00817 std::vector<std::string> ret;
00818 LibHalDriveCdromCaps caps;
00819
00820
00821
00822
00823
00824 caps = libhal_drive_get_cdrom_caps(d_impl->drv);
00825
00826 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDROM)
00827 ret.push_back("cdrom");
00828 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDR)
00829 ret.push_back("cdr");
00830 if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDRW)
00831 ret.push_back("cdrw");
00832 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRAM)
00833 ret.push_back("dvdram");
00834 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDROM)
00835 ret.push_back("dvd");
00836 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR)
00837 ret.push_back("dvdr");
00838 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRW)
00839 ret.push_back("dvdrw");
00840 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR)
00841 ret.push_back("dvdplusr");
00842 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW)
00843 ret.push_back("dvdplusrw");
00844 if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL)
00845 ret.push_back("dvdplusrdl");
00846
00847 return ret;
00848
00849 #if 0
00850 if( libhal_drive_get_type(d_impl->drv) != LIBHAL_DRIVE_TYPE_CDROM)
00851 ZYPP_THROW(HalException(_("Not a CDROM drive")));
00852
00853
00854
00855
00856
00857
00858
00859
00860 LibHalPropertySet *props;
00861 HalError err;
00862
00863 props = libhal_device_get_all_properties(d_impl->hal->hctx,
00864 getUDI().c_str(),
00865 &err.error);
00866 if( !props)
00867 ZYPP_THROW(err.halException());
00868
00869 std::vector<std::string> ret(1, getTypeName());
00870 std::string key;
00871 std::string dvd("storage.cdrom.dvd");
00872 std::string cd ("storage.cdrom.cd");
00873
00874 LibHalPropertySetIterator it;
00875 for(libhal_psi_init(&it, props);
00876 libhal_psi_has_more(&it);
00877 libhal_psi_next(&it))
00878 {
00879 if( libhal_psi_get_type(&it) == LIBHAL_PROPERTY_TYPE_BOOLEAN &&
00880 libhal_psi_get_bool(&it))
00881 {
00882 key = libhal_psi_get_key(&it);
00883 if( key.compare(0, cd.size(), cd) == 0)
00884 {
00885 ret.push_back(key.substr(sizeof("storage.cdrom.")-1));
00886 }
00887 else
00888 if( key.compare(0, dvd.size(), dvd) == 0)
00889 {
00890 ret.push_back(key.substr(sizeof("storage.cdrom.")-1));
00891 }
00892 }
00893 }
00894 libhal_free_property_set(props);
00895
00896 return ret;
00897 #endif
00898 }
00899
00900
00901 std::vector<std::string>
00902 HalDrive::findAllVolumes() const
00903 {
00904 MutexLock lock(g_Mutex);
00905 VERIFY_DRIVE(d_impl);
00906
00907 char **names;
00908 int count = 0;
00909
00910 names = libhal_drive_find_all_volumes(d_impl->hal->hctx,
00911 d_impl->drv,
00912 &count);
00913
00914 std::vector<std::string> ret;
00915 ret.assign(names, names + count);
00916 libhal_free_string_array(names);
00917 return ret;
00918 }
00919
00920
00922 HalVolume::HalVolume()
00923 : v_impl( NULL)
00924 {}
00925
00926 HalVolume::HalVolume(HalVolume_Impl *impl)
00927 : v_impl( NULL)
00928 {
00929 MutexLock lock(g_Mutex);
00930
00931 v_impl.reset(impl);
00932 }
00933
00934
00935 HalVolume::HalVolume(const HalVolume &volume)
00936 : v_impl( NULL)
00937 {
00938 MutexLock lock(g_Mutex);
00939
00940 zypp::RW_pointer<HalVolume_Impl>(volume.v_impl).swap(v_impl);
00941 }
00942
00943
00944 HalVolume::~HalVolume()
00945 {
00946 MutexLock lock(g_Mutex);
00947
00948 v_impl.reset();
00949 }
00950
00951
00952 HalVolume &
00953 HalVolume::operator=(const HalVolume &volume)
00954 {
00955 MutexLock lock(g_Mutex);
00956
00957 if( this == &volume)
00958 return *this;
00959
00960 zypp::RW_pointer<HalVolume_Impl>(volume.v_impl).swap(v_impl);
00961 return *this;
00962 }
00963
00964
00965 HalVolume::operator HalVolume::bool_type() const
00966 {
00967 MutexLock lock(g_Mutex);
00968
00969 return v_impl;
00970 }
00971
00972
00973 std::string
00974 HalVolume::getUDI() const
00975 {
00976 MutexLock lock(g_Mutex);
00977 VERIFY_VOLUME(v_impl);
00978
00979 const char *ptr = libhal_volume_get_udi(v_impl->vol);
00980 return std::string(ptr ? ptr : "");
00981 }
00982
00983
00984 std::string
00985 HalVolume::getDeviceFile() const
00986 {
00987 MutexLock lock(g_Mutex);
00988 VERIFY_VOLUME(v_impl);
00989
00990 return std::string(libhal_volume_get_device_file(v_impl->vol));
00991 }
00992
00993
00994 unsigned int
00995 HalVolume::getDeviceMajor() const
00996 {
00997 MutexLock lock(g_Mutex);
00998 VERIFY_VOLUME(v_impl);
00999
01000 return libhal_volume_get_device_major(v_impl->vol);
01001 }
01002
01003
01004 unsigned int
01005 HalVolume::getDeviceMinor() const
01006 {
01007 MutexLock lock(g_Mutex);
01008 VERIFY_VOLUME(v_impl);
01009
01010 return libhal_volume_get_device_minor(v_impl->vol);
01011 }
01012
01013
01014 bool
01015 HalVolume::isDisc() const
01016 {
01017 MutexLock lock(g_Mutex);
01018 VERIFY_VOLUME(v_impl);
01019
01020 return libhal_volume_is_disc(v_impl->vol);
01021 }
01022
01023
01024 bool
01025 HalVolume::isPartition() const
01026 {
01027 MutexLock lock(g_Mutex);
01028 VERIFY_VOLUME(v_impl);
01029
01030 return libhal_volume_is_partition(v_impl->vol);
01031 }
01032
01033
01034 bool
01035 HalVolume::isMounted() const
01036 {
01037 MutexLock lock(g_Mutex);
01038 VERIFY_VOLUME(v_impl);
01039
01040 return libhal_volume_is_mounted(v_impl->vol);
01041 }
01042
01043
01044 std::string
01045 HalVolume::getFSType() const
01046 {
01047 MutexLock lock(g_Mutex);
01048 VERIFY_VOLUME(v_impl);
01049
01050 return std::string( libhal_volume_get_fstype(v_impl->vol));
01051 }
01052
01053
01054 std::string
01055 HalVolume::getFSUsage() const
01056 {
01057 MutexLock lock(g_Mutex);
01058 VERIFY_VOLUME(v_impl);
01059
01060 LibHalVolumeUsage usage( libhal_volume_get_fsusage(v_impl->vol));
01061 std::string ret;
01062 switch( usage)
01063 {
01064 case LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM:
01065 ret = "filesystem";
01066 break;
01067 case LIBHAL_VOLUME_USAGE_PARTITION_TABLE:
01068 ret = "partitiontable";
01069 break;
01070 case LIBHAL_VOLUME_USAGE_RAID_MEMBER:
01071 return "raid";
01072 break;
01073 case LIBHAL_VOLUME_USAGE_CRYPTO:
01074 ret = "crypto";
01075 break;
01076 case LIBHAL_VOLUME_USAGE_UNKNOWN:
01077 default:
01078 break;
01079 }
01080 return ret;
01081 }
01082
01083
01084 std::string
01085 HalVolume::getMountPoint() const
01086 {
01087 VERIFY_VOLUME(v_impl);
01088
01089 return std::string( libhal_volume_get_mount_point(v_impl->vol));
01090 }
01091
01092
01094 }
01097 }
01100 }
01102 #else // NO_HAL
01103 #include <zypp/target/hal/HalContext.h>
01104 #include <zypp/target/hal/HalException.h>
01105 namespace zypp
01106 {
01107
01108 namespace target
01109 {
01110
01111 namespace hal
01112 {
01113
01114 std::ostream &
01115 HalException::dumpOn( std::ostream & str ) const
01116 { return str; }
01117
01118
01119 class HalContext_Impl
01120 {};
01121 class HalDrive_Impl
01122 {};
01123 class HalVolume_Impl
01124 {};
01125
01126
01127 HalContext::HalContext(bool)
01128 { ZYPP_THROW( NoHalException() ); }
01129 HalContext::~HalContext()
01130 {}
01131 HalContext &
01132 HalContext::operator=(const HalContext &)
01133 { return *this; }
01134 HalContext::operator HalContext::bool_type() const
01135 { return 0; }
01136 void
01137 HalContext::connect()
01138 {}
01139 std::vector<std::string>
01140 HalContext::getAllDevices() const
01141 { return std::vector<std::string>(); }
01142 HalDrive
01143 HalContext::getDriveFromUDI(const std::string &) const
01144 { return HalDrive(); }
01145 HalVolume
01146 HalContext::getVolumeFromUDI(const std::string &) const
01147 { return HalVolume(); }
01148 HalVolume
01149 HalContext::getVolumeFromDeviceFile(const std::string &) const
01150 { return HalVolume(); }
01151 std::vector<std::string>
01152 HalContext::findDevicesByCapability(const std::string &) const
01153 { return std::vector<std::string>(); }
01154 bool
01155 HalContext::getDevicePropertyBool(const std::string &, const std::string &) const
01156 { return false; }
01157 void
01158 HalContext::setDevicePropertyBool (const std::string &, const std::string &, bool value)
01159 {}
01160 void
01161 HalContext::removeDeviceProperty(const std::string &, const std::string &)
01162 {}
01163 std::string
01164 HalContext::getDevicePropertyString(const std::string &, const std::string &) const
01165 { return ""; }
01166
01167 HalDrive::HalDrive()
01168 { ZYPP_THROW( NoHalException() ); }
01169 HalDrive::~HalDrive()
01170 {}
01171 HalDrive &
01172 HalDrive::operator=(const HalDrive &)
01173 { return *this; }
01174 HalDrive::operator HalDrive::bool_type() const
01175 { return 0; }
01176 std::string
01177 HalDrive::getUDI() const
01178 { return std::string(); }
01179 std::string
01180 HalDrive::getTypeName() const
01181 { return std::string(); }
01182 std::string
01183 HalDrive::getDeviceFile() const
01184 { return std::string(); }
01185 unsigned int
01186 HalDrive::getDeviceMinor() const
01187 { return 0; }
01188 unsigned int
01189 HalDrive::getDeviceMajor() const
01190 { return 0; }
01191 bool
01192 HalDrive::usesRemovableMedia() const
01193 { return false; }
01194 std::vector<std::string>
01195 HalDrive::getCdromCapabilityNames() const
01196 { return std::vector<std::string>(); }
01197 std::vector<std::string>
01198 HalDrive::findAllVolumes() const
01199 { return std::vector<std::string>(); }
01200
01201
01202 HalVolume::HalVolume()
01203 { ZYPP_THROW( NoHalException() ); }
01204 HalVolume::~HalVolume()
01205 {}
01206 HalVolume &
01207 HalVolume::operator=(const HalVolume &)
01208 { return *this; }
01209 HalVolume::operator HalVolume::bool_type() const
01210 { return 0; }
01211 std::string
01212 HalVolume::getUDI() const
01213 { return std::string(); }
01214 std::string
01215 HalVolume::getDeviceFile() const
01216 { return std::string(); }
01217 unsigned int
01218 HalVolume::getDeviceMinor() const
01219 { return 0; }
01220 unsigned int
01221 HalVolume::getDeviceMajor() const
01222 { return 0; }
01223 bool
01224 HalVolume::isDisc() const
01225 { return false; }
01226 bool
01227 HalVolume::isPartition() const
01228 { return false; }
01229 bool
01230 HalVolume::isMounted() const
01231 { return false; }
01232 std::string
01233 HalVolume::getFSType() const
01234 { return std::string(); }
01235 std::string
01236 HalVolume::getFSUsage() const
01237 { return std::string(); }
01238 std::string
01239 HalVolume::getMountPoint() const
01240 { return std::string(); }
01241
01243 }
01246 }
01249 }
01251 #endif // NO_HAL
01252
01253
01254
01255