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