libzypp  17.12.0
HalContext.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include "zypp/base/Gettext.h"
16 namespace zypp
17 {
18  namespace target
20  {
21  namespace hal
23  {
25  : zypp::Exception(_("Hal Exception"))
26  {}
27  HalException::HalException(const std::string &msg_r)
28  : zypp::Exception(_("Hal Exception"))
29  , e_name()
30  , e_msg(msg_r)
31  {}
32  HalException::HalException(const std::string &err_name, const std::string &err_msg)
33  : zypp::Exception(_("Hal Exception"))
34  , e_name(err_name)
35  , e_msg(err_msg)
36  {}
38  : Exception(_("Sorry, but this version of libzypp was built without HAL support."))
39  {}
41  } // namespace hal
44  } // namespace target
47 } // namespace zypp
49 
50 #ifndef NO_HAL // disables zypp's HAL dependency
51 
53 #include "zypp/thread/Mutex.h"
54 #include "zypp/thread/MutexLock.h"
55 #include "zypp/base/NonCopyable.h"
56 #include "zypp/base/Logger.h"
57 #include "zypp/base/String.h"
58 #include "zypp/base/Gettext.h"
59 
60 #include <hal/libhal.h>
61 #include <hal/libhal-storage.h>
62 
63 #include <iostream>
64 
65 using namespace std;
66 
68 namespace zypp
69 {
70  namespace target
72  {
73  namespace hal
75  {
76 
77  using zypp::thread::Mutex;
79 
81  namespace // anonymous
82  {
83 
84 
86  // STATIC
90  static Mutex g_Mutex;
91 
92 
94 
97  class HalError
98  {
99  public:
100  DBusError error;
101 
102  HalError() { dbus_error_init(&error); }
103  ~HalError() { dbus_error_free(&error); }
104 
105  inline bool isSet() const
106  {
107  return dbus_error_is_set(&error);
108  }
109 
110  inline HalException halException(const std::string &msg = std::string()) const
111  {
112  if( isSet() && error.name != NULL && error.message != NULL) {
113  return HalException(error.name, error.message);
114  }
115  else if( !msg.empty()) {
116  return HalException(msg);
117  }
118  else {
119  return HalException();
120  }
121  }
122  };
123 
124 
125  // -----------------------------------------------------------
126  inline void
127  VERIFY_CONTEXT(const zypp::RW_pointer<HalContext_Impl> &h)
128  {
129  if( !h)
130  {
131  ZYPP_THROW(HalException(_("HalContext not connected")));
132  }
133  }
134 
135  // -----------------------------------------------------------
136  inline void
137  VERIFY_DRIVE(const zypp::RW_pointer<HalDrive_Impl> &d)
138  {
139  if( !d)
140  {
141  ZYPP_THROW(HalException(_("HalDrive not initialized")));
142  }
143  }
144 
145  // -----------------------------------------------------------
146  inline void
147  VERIFY_VOLUME(const zypp::RW_pointer<HalVolume_Impl> &v)
148  {
149  if( !v)
150  {
151  ZYPP_THROW(HalException(_("HalVolume not initialized")));
152  }
153  }
154 
156  } // anonymous
158 
160  std::ostream &
161  HalException::dumpOn( std::ostream & str ) const
162  {
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;
167  else
168  return str << msg();
169  }
170 
173  {
174  public:
175  HalContext_Impl();
176  ~HalContext_Impl();
177 
178  DBusConnection *conn;
179  LibHalContext *hctx;
180  bool pcon; // private connection
181  };
182 
183 
186  {
187  public:
189  LibHalDrive *drv;
190 
192  : hal(), drv(NULL)
193  {
194  }
195 
197  LibHalDrive *d)
198  : hal(r), drv(d)
199  {
200  }
201 
203  {
204  if( drv)
205  libhal_drive_free(drv);
206  }
207  };
208 
209 
212  {
213  public:
214  LibHalVolume *vol;
215 
216  HalVolume_Impl(LibHalVolume *v=NULL)
217  : vol(v)
218  {
219  }
220 
222  {
223  if( vol)
224  libhal_volume_free(vol);
225  }
226  };
227 
228 
230  HalContext_Impl::HalContext_Impl()
231  : conn(NULL)
232  , hctx(NULL)
233  , pcon(false) // we allways use shared connections at the moment
234  {
235  HalError err;
236 
237  if( pcon)
238  conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err.error);
239  else
240  conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err.error);
241  if( !conn) {
242  ZYPP_THROW(err.halException(
243  _("Unable to create dbus connection")
244  ));
245  }
246 
247  hctx = libhal_ctx_new();
248  if( !hctx)
249  {
250  if( pcon)
251  dbus_connection_close(conn);
252  dbus_connection_unref(conn);
253  conn = NULL;
254 
256  _("libhal_ctx_new: Can't create libhal context")
257  ));
258  }
259 
260  if( !libhal_ctx_set_dbus_connection(hctx, conn))
261  {
262  libhal_ctx_free(hctx);
263  hctx = NULL;
264 
265  if( pcon)
266  dbus_connection_close(conn);
267  dbus_connection_unref(conn);
268  conn = NULL;
269 
271  _("libhal_set_dbus_connection: Can't set dbus connection")
272  ));
273  }
274 
275  if( !libhal_ctx_init(hctx, &err.error))
276  {
277  libhal_ctx_free(hctx);
278  hctx = NULL;
279 
280  if( pcon)
281  dbus_connection_close(conn);
282  dbus_connection_unref(conn);
283  conn = NULL;
284 
285  ZYPP_THROW(err.halException(
286  _("Unable to initalize HAL context -- hald not running?")
287  ));
288  }
289  }
290 
291  // -------------------------------------------------------------
293  {
294  if( hctx)
295  {
296  HalError err;
297  libhal_ctx_shutdown(hctx, &err.error);
298  libhal_ctx_free( hctx);
299  }
300  if( conn)
301  {
302  if( pcon)
303  dbus_connection_close(conn);
304  dbus_connection_unref(conn);
305  }
306  }
307 
308 
310  HalContext::HalContext(bool autoconnect)
311  : h_impl( NULL)
312  {
313  MutexLock lock(g_Mutex);
314 
315  if( autoconnect)
316  h_impl.reset( new HalContext_Impl());
317  }
318 
319  // -------------------------------------------------------------
321  : h_impl( NULL)
322  {
323  MutexLock lock(g_Mutex);
324 
326  }
327 
328  // -------------------------------------------------------------
330  {
331  MutexLock lock(g_Mutex);
332 
333  h_impl.reset();
334  }
335 
336  // --------------------------------------------------------------
337  HalContext &
339  {
340  MutexLock lock(g_Mutex);
341 
342  if( this == &context)
343  return *this;
344 
346  return *this;
347  }
348 
349  // --------------------------------------------------------------
350  HalContext::operator HalContext::bool_type() const
351  {
352  MutexLock lock(g_Mutex);
353 
354  return h_impl;
355  }
356 
357  // --------------------------------------------------------------
358  void
360  {
361  MutexLock lock(g_Mutex);
362 
363  if( !h_impl)
364  h_impl.reset( new HalContext_Impl());
365  }
366 
367  // --------------------------------------------------------------
368  std::vector<std::string>
370  {
371  MutexLock lock(g_Mutex);
372  VERIFY_CONTEXT(h_impl);
373 
374  HalError err;
375  char **names;
376  int count = 0;
377 
378  names = libhal_get_all_devices( h_impl->hctx, &count, &err.error);
379  if( !names)
380  {
381  ZYPP_THROW(err.halException());
382  }
383 
384  std::vector<std::string> ret(names, names + count);
385  libhal_free_string_array(names);
386  return ret;
387  }
388 
389  // --------------------------------------------------------------
390  HalDrive
391  HalContext::getDriveFromUDI(const std::string &udi) const
392  {
393  MutexLock lock(g_Mutex);
394  VERIFY_CONTEXT(h_impl);
395 
396  LibHalDrive *drv = libhal_drive_from_udi(h_impl->hctx, udi.c_str());
397  if( drv != NULL)
398  return HalDrive(new HalDrive_Impl( h_impl, drv));
399  else
400  return HalDrive();
401  }
402 
403  // --------------------------------------------------------------
404  HalVolume
405  HalContext::getVolumeFromUDI(const std::string &udi) const
406  {
407  MutexLock lock(g_Mutex);
408  VERIFY_CONTEXT(h_impl);
409 
410  LibHalVolume *vol = libhal_volume_from_udi(h_impl->hctx, udi.c_str());
411  if( vol)
412  return HalVolume( new HalVolume_Impl(vol));
413  else
414  return HalVolume();
415  }
416 
417  // --------------------------------------------------------------
418  HalVolume
419  HalContext::getVolumeFromDeviceFile(const std::string &device_file) const
420  {
421  MutexLock lock(g_Mutex);
422  VERIFY_CONTEXT(h_impl);
423 
424  LibHalVolume *vol = libhal_volume_from_device_file(h_impl->hctx,
425  device_file.c_str());
426  if( vol)
427  return HalVolume( new HalVolume_Impl(vol));
428  else
429  return HalVolume();
430  }
431 
432  // --------------------------------------------------------------
433  std::vector<std::string>
434  HalContext::findDevicesByCapability(const std::string &capability) const
435  {
436  MutexLock lock(g_Mutex);
437  VERIFY_CONTEXT(h_impl);
438 
439  HalError err;
440  char **names;
441  int count = 0;
442 
443  names = libhal_find_device_by_capability(h_impl->hctx,
444  capability.c_str(),
445  &count, &err.error);
446  if( !names)
447  {
448  ZYPP_THROW(err.halException());
449  }
450 
451  std::vector<std::string> ret(names, names + count);
452  libhal_free_string_array(names);
453  return ret;
454  }
455 
456  // --------------------------------------------------------------
457  bool
458  HalContext::getDevicePropertyBool (const std::string &udi,
459  const std::string &key) const
460  {
461  MutexLock lock(g_Mutex);
462  VERIFY_CONTEXT(h_impl);
463 
464  HalError err;
465  dbus_bool_t ret;
466 
467  ret = libhal_device_get_property_bool (h_impl->hctx,
468  udi.c_str(),
469  key.c_str(),
470  &err.error);
471  if( err.isSet())
472  {
473  ZYPP_THROW(err.halException());
474  }
475  return ret;
476  }
477 
478  // --------------------------------------------------------------
479  int32_t
480  HalContext::getDevicePropertyInt32 (const std::string &udi,
481  const std::string &key) const
482  {
483  MutexLock lock(g_Mutex);
484  VERIFY_CONTEXT(h_impl);
485 
486  HalError err;
487  dbus_int32_t ret;
488 
489  ret = libhal_device_get_property_int (h_impl->hctx,
490  udi.c_str(),
491  key.c_str(),
492  &err.error);
493  if( err.isSet())
494  {
495  ZYPP_THROW(err.halException());
496  }
497  return ret;
498  }
499 
500  // --------------------------------------------------------------
501  uint64_t
502  HalContext::getDevicePropertyUInt64(const std::string &udi,
503  const std::string &key) const
504  {
505  MutexLock lock(g_Mutex);
506  VERIFY_CONTEXT(h_impl);
507 
508  HalError err;
509  dbus_uint64_t ret;
510 
511  ret = libhal_device_get_property_uint64(h_impl->hctx,
512  udi.c_str(),
513  key.c_str(),
514  &err.error);
515  if( err.isSet())
516  {
517  ZYPP_THROW(err.halException());
518  }
519  return ret;
520  }
521 
522  // --------------------------------------------------------------
523  double
524  HalContext::getDevicePropertyDouble(const std::string &udi,
525  const std::string &key) const
526  {
527  MutexLock lock(g_Mutex);
528  VERIFY_CONTEXT(h_impl);
529 
530  HalError err;
531  double ret;
532 
533  ret = libhal_device_get_property_bool (h_impl->hctx,
534  udi.c_str(),
535  key.c_str(),
536  &err.error);
537  if( err.isSet())
538  {
539  ZYPP_THROW(err.halException());
540  }
541  return ret;
542  }
543 
544 
545  // --------------------------------------------------------------
546  std::string
547  HalContext::getDevicePropertyString(const std::string &udi,
548  const std::string &key) const
549  {
550  MutexLock lock(g_Mutex);
551  VERIFY_CONTEXT(h_impl);
552 
553  HalError err;
554  std::string ret;
555  char *ptr;
556 
557  ptr = libhal_device_get_property_string(h_impl->hctx,
558  udi.c_str(),
559  key.c_str(),
560  &err.error);
561  if( err.isSet())
562  {
563  ZYPP_THROW(err.halException());
564  }
565  if( ptr != NULL)
566  {
567  ret = ptr;
568  free(ptr);
569  }
570  return ret;
571  }
572 
573  // --------------------------------------------------------------
574  void
575  HalContext::setDevicePropertyBool (const std::string &udi,
576  const std::string &key,
577  bool value)
578  {
579  MutexLock lock(g_Mutex);
580  VERIFY_CONTEXT(h_impl);
581 
582  HalError err;
583  dbus_bool_t ret;
584 
585  ret = libhal_device_set_property_bool (h_impl->hctx,
586  udi.c_str(),
587  key.c_str(),
588  value ? 1 : 0,
589  &err.error);
590  if( !ret)
591  {
592  ZYPP_THROW(err.halException());
593  }
594  }
595 
596  // --------------------------------------------------------------
597  void
598  HalContext::setDevicePropertyInt32 (const std::string &udi,
599  const std::string &key,
600  int32_t value)
601  {
602  MutexLock lock(g_Mutex);
603  VERIFY_CONTEXT(h_impl);
604 
605  HalError err;
606  dbus_bool_t ret;
607 
608  ret = libhal_device_set_property_int (h_impl->hctx,
609  udi.c_str(),
610  key.c_str(),
611  value,
612  &err.error);
613  if( !ret)
614  {
615  ZYPP_THROW(err.halException());
616  }
617  }
618 
619  // --------------------------------------------------------------
620  void
621  HalContext::setDevicePropertyUInt64(const std::string &udi,
622  const std::string &key,
623  uint64_t value)
624  {
625  MutexLock lock(g_Mutex);
626  VERIFY_CONTEXT(h_impl);
627 
628  HalError err;
629  dbus_bool_t ret;
630 
631  ret = libhal_device_set_property_uint64(h_impl->hctx,
632  udi.c_str(),
633  key.c_str(),
634  value,
635  &err.error);
636  if( !ret)
637  {
638  ZYPP_THROW(err.halException());
639  }
640  }
641 
642  // --------------------------------------------------------------
643  void
644  HalContext::setDevicePropertyDouble(const std::string &udi,
645  const std::string &key,
646  double value)
647  {
648  MutexLock lock(g_Mutex);
649  VERIFY_CONTEXT(h_impl);
650 
651  HalError err;
652  dbus_bool_t ret;
653 
654  ret = libhal_device_set_property_double(h_impl->hctx,
655  udi.c_str(),
656  key.c_str(),
657  value,
658  &err.error);
659  if( !ret)
660  {
661  ZYPP_THROW(err.halException());
662  }
663  }
664 
665  // --------------------------------------------------------------
666  void
667  HalContext::setDevicePropertyString(const std::string &udi,
668  const std::string &key,
669  const std::string &value)
670  {
671  MutexLock lock(g_Mutex);
672  VERIFY_CONTEXT(h_impl);
673 
674  HalError err;
675  dbus_bool_t ret;
676 
677  ret = libhal_device_set_property_string(h_impl->hctx,
678  udi.c_str(),
679  key.c_str(),
680  value.c_str(),
681  &err.error);
682  if( !ret)
683  {
684  ZYPP_THROW(err.halException());
685  }
686  }
687 
688  // --------------------------------------------------------------
689  void
690  HalContext::removeDeviceProperty(const std::string &udi,
691  const std::string &key)
692  {
693  MutexLock lock(g_Mutex);
694  VERIFY_CONTEXT(h_impl);
695 
696  HalError err;
697  dbus_bool_t ret;
698 
699  ret = libhal_device_remove_property(h_impl->hctx,
700  udi.c_str(),
701  key.c_str(),
702  &err.error);
703  if( !ret)
704  {
705  ZYPP_THROW(err.halException());
706  }
707  }
708 
711  : d_impl( NULL)
712  {
713  }
714 
715  // --------------------------------------------------------------
717  : d_impl( NULL)
718  {
719  MutexLock lock(g_Mutex);
720 
721  d_impl.reset(impl);
722  }
723 
724  // --------------------------------------------------------------
726  : d_impl( NULL)
727  {
728  MutexLock lock(g_Mutex);
729 
731  }
732 
733  // --------------------------------------------------------------
735  {
736  MutexLock lock(g_Mutex);
737 
738  d_impl.reset();
739  }
740 
741  // --------------------------------------------------------------
742  HalDrive &
744  {
745  MutexLock lock(g_Mutex);
746 
747  if( this == &drive)
748  return *this;
749 
751  return *this;
752  }
753 
754  // --------------------------------------------------------------
755  HalDrive::operator HalDrive::bool_type() const
756  {
757  MutexLock lock(g_Mutex);
758 
759  return d_impl;
760  }
761 
762  // --------------------------------------------------------------
763  std::string
765  {
766  MutexLock lock(g_Mutex);
767  VERIFY_DRIVE(d_impl);
768 
769  const char *ptr = libhal_drive_get_udi(d_impl->drv);
770  return std::string(ptr ? ptr : "");
771  }
772 
773  // --------------------------------------------------------------
774  std::string
776  {
777  MutexLock lock(g_Mutex);
778  VERIFY_DRIVE(d_impl);
779 
780  const char *ptr = libhal_drive_get_type_textual(d_impl->drv);
781  return std::string(ptr ? ptr : "");
782  }
783 
784  // --------------------------------------------------------------
785  std::string
787  {
788  MutexLock lock(g_Mutex);
789  VERIFY_DRIVE(d_impl);
790 
791  return std::string(libhal_drive_get_device_file(d_impl->drv));
792  }
793 
794  // --------------------------------------------------------------
795  unsigned int
797  {
798  MutexLock lock(g_Mutex);
799  VERIFY_DRIVE(d_impl);
800 
801  return libhal_drive_get_device_major(d_impl->drv);
802  }
803 
804  // --------------------------------------------------------------
805  unsigned int
807  {
808  MutexLock lock(g_Mutex);
809  VERIFY_DRIVE(d_impl);
810 
811  return libhal_drive_get_device_minor(d_impl->drv);
812  }
813 
814  // --------------------------------------------------------------
815  bool
817  {
818  MutexLock lock(g_Mutex);
819  VERIFY_DRIVE(d_impl);
820 
821  return libhal_drive_uses_removable_media(d_impl->drv);
822  }
823 
824  // --------------------------------------------------------------
825  std::vector<std::string>
827  {
828  MutexLock lock(g_Mutex);
829  VERIFY_DRIVE(d_impl);
830 
831  std::vector<std::string> ret;
832  LibHalDriveCdromCaps caps;
833 
834  /*
835  ** FIXME: there is no textual variant :-(
836  ** using property key names...
837  */
838  caps = libhal_drive_get_cdrom_caps(d_impl->drv);
839 
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");
860 
861  return ret;
862 
863 #if 0
864  if( libhal_drive_get_type(d_impl->drv) != LIBHAL_DRIVE_TYPE_CDROM)
865  ZYPP_THROW(HalException(_("Not a CDROM drive")));
866 
867  /*
868  ** FIXME: we use property keys matching
869  ** "storage.cdrom.cd*"
870  ** "storage.cdrom.dvd*"
871  ** but this may print other bool keys,
872  ** that are not CDROM caps.
873  */
874  LibHalPropertySet *props;
875  HalError err;
876 
877  props = libhal_device_get_all_properties(d_impl->hal->hctx,
878  getUDI().c_str(),
879  &err.error);
880  if( !props)
881  ZYPP_THROW(err.halException());
882 
883  std::vector<std::string> ret(1, getTypeName());
884  std::string key;
885  std::string dvd("storage.cdrom.dvd");
886  std::string cd ("storage.cdrom.cd");
887 
888  LibHalPropertySetIterator it;
889  for(libhal_psi_init(&it, props);
890  libhal_psi_has_more(&it);
891  libhal_psi_next(&it))
892  {
893  if( libhal_psi_get_type(&it) == LIBHAL_PROPERTY_TYPE_BOOLEAN &&
894  libhal_psi_get_bool(&it))
895  {
896  key = libhal_psi_get_key(&it);
897  if( key.compare(0, cd.size(), cd) == 0)
898  {
899  ret.push_back(key.substr(sizeof("storage.cdrom.")-1));
900  }
901  else
902  if( key.compare(0, dvd.size(), dvd) == 0)
903  {
904  ret.push_back(key.substr(sizeof("storage.cdrom.")-1));
905  }
906  }
907  }
908  libhal_free_property_set(props);
909 
910  return ret;
911 #endif
912  }
913 
914  // --------------------------------------------------------------
915  std::vector<std::string>
917  {
918  MutexLock lock(g_Mutex);
919  VERIFY_DRIVE(d_impl);
920 
921  char **names;
922  int count = 0;
923 
924  names = libhal_drive_find_all_volumes(d_impl->hal->hctx,
925  d_impl->drv,
926  &count);
927 
928  std::vector<std::string> ret;
929  ret.assign(names, names + count);
930  libhal_free_string_array(names);
931  return ret;
932  }
933 
934 
937  : v_impl( NULL)
938  {}
939 
941  : v_impl( NULL)
942  {
943  MutexLock lock(g_Mutex);
944 
945  v_impl.reset(impl);
946  }
947 
948  // --------------------------------------------------------------
950  : v_impl( NULL)
951  {
952  MutexLock lock(g_Mutex);
953 
955  }
956 
957  // --------------------------------------------------------------
959  {
960  MutexLock lock(g_Mutex);
961 
962  v_impl.reset();
963  }
964 
965  // --------------------------------------------------------------
966  HalVolume &
968  {
969  MutexLock lock(g_Mutex);
970 
971  if( this == &volume)
972  return *this;
973 
975  return *this;
976  }
977 
978  // --------------------------------------------------------------
979  HalVolume::operator HalVolume::bool_type() const
980  {
981  MutexLock lock(g_Mutex);
982 
983  return v_impl;
984  }
985 
986  // --------------------------------------------------------------
987  std::string
989  {
990  MutexLock lock(g_Mutex);
991  VERIFY_VOLUME(v_impl);
992 
993  const char *ptr = libhal_volume_get_udi(v_impl->vol);
994  return std::string(ptr ? ptr : "");
995  }
996 
997  // --------------------------------------------------------------
998  std::string
1000  {
1001  MutexLock lock(g_Mutex);
1002  VERIFY_VOLUME(v_impl);
1003 
1004  return std::string(libhal_volume_get_device_file(v_impl->vol));
1005  }
1006 
1007  // --------------------------------------------------------------
1008  unsigned int
1010  {
1011  MutexLock lock(g_Mutex);
1012  VERIFY_VOLUME(v_impl);
1013 
1014  return libhal_volume_get_device_major(v_impl->vol);
1015  }
1016 
1017  // --------------------------------------------------------------
1018  unsigned int
1020  {
1021  MutexLock lock(g_Mutex);
1022  VERIFY_VOLUME(v_impl);
1023 
1024  return libhal_volume_get_device_minor(v_impl->vol);
1025  }
1026 
1027  // --------------------------------------------------------------
1028  bool
1030  {
1031  MutexLock lock(g_Mutex);
1032  VERIFY_VOLUME(v_impl);
1033 
1034  return libhal_volume_is_disc(v_impl->vol);
1035  }
1036 
1037  // --------------------------------------------------------------
1038  bool
1040  {
1041  MutexLock lock(g_Mutex);
1042  VERIFY_VOLUME(v_impl);
1043 
1044  return libhal_volume_is_partition(v_impl->vol);
1045  }
1046 
1047  // --------------------------------------------------------------
1048  bool
1050  {
1051  MutexLock lock(g_Mutex);
1052  VERIFY_VOLUME(v_impl);
1053 
1054  return libhal_volume_is_mounted(v_impl->vol);
1055  }
1056 
1057  // --------------------------------------------------------------
1058  std::string
1060  {
1061  MutexLock lock(g_Mutex);
1062  VERIFY_VOLUME(v_impl);
1063 
1064  return std::string( libhal_volume_get_fstype(v_impl->vol));
1065  }
1066 
1067  // --------------------------------------------------------------
1068  std::string
1070  {
1071  MutexLock lock(g_Mutex);
1072  VERIFY_VOLUME(v_impl);
1073 
1074  LibHalVolumeUsage usage( libhal_volume_get_fsusage(v_impl->vol));
1075  std::string ret;
1076  switch( usage)
1077  {
1078  case LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM:
1079  ret = "filesystem";
1080  break;
1081  case LIBHAL_VOLUME_USAGE_PARTITION_TABLE:
1082  ret = "partitiontable";
1083  break;
1084  case LIBHAL_VOLUME_USAGE_RAID_MEMBER:
1085  return "raid";
1086  break;
1087  case LIBHAL_VOLUME_USAGE_CRYPTO:
1088  ret = "crypto";
1089  break;
1090  case LIBHAL_VOLUME_USAGE_UNKNOWN:
1091  default:
1092  break;
1093  }
1094  return ret;
1095  }
1096 
1097  // --------------------------------------------------------------
1098  std::string
1100  {
1101  VERIFY_VOLUME(v_impl);
1102 
1103  return std::string( libhal_volume_get_mount_point(v_impl->vol));
1104  }
1105 
1106 
1108  } // namespace hal
1111  } // namespace target
1114 } // namespace zypp
1116 #else // NO_HAL
1119 namespace zypp
1120 {
1121  namespace target
1123  {
1124  namespace hal
1126  {
1127 
1128  std::ostream &
1129  HalException::dumpOn( std::ostream & str ) const
1130  { return str; }
1131 
1132  // --------------------------------------------------------------
1133  class HalContext_Impl
1134  {};
1135  class HalDrive_Impl
1136  {};
1137  class HalVolume_Impl
1138  {};
1139 
1140  // --------------------------------------------------------------
1142  { ZYPP_THROW( NoHalException() ); }
1144  {}
1145  HalContext &
1146  HalContext::operator=(const HalContext &)
1147  { return *this; }
1148  HalContext::operator HalContext::bool_type() const
1149  { return 0; }
1150  void
1152  {}
1153  std::vector<std::string>
1155  { return std::vector<std::string>(); }
1156  HalDrive
1157  HalContext::getDriveFromUDI(const std::string &) const
1158  { return HalDrive(); }
1159  HalVolume
1160  HalContext::getVolumeFromUDI(const std::string &) const
1161  { return HalVolume(); }
1162  HalVolume
1163  HalContext::getVolumeFromDeviceFile(const std::string &) const
1164  { return HalVolume(); }
1165  std::vector<std::string>
1166  HalContext::findDevicesByCapability(const std::string &) const
1167  { return std::vector<std::string>(); }
1168  bool
1169  HalContext::getDevicePropertyBool(const std::string &, const std::string &) const
1170  { return false; }
1171  void
1172  HalContext::setDevicePropertyBool (const std::string &, const std::string &, bool value)
1173  {}
1174  void
1175  HalContext::removeDeviceProperty(const std::string &, const std::string &)
1176  {}
1177  std::string
1178  HalContext::getDevicePropertyString(const std::string &, const std::string &) const
1179  { return ""; }
1180  // --------------------------------------------------------------
1182  { ZYPP_THROW( NoHalException() ); }
1184  {}
1185  HalDrive &
1186  HalDrive::operator=(const HalDrive &)
1187  { return *this; }
1188  HalDrive::operator HalDrive::bool_type() const
1189  { return 0; }
1190  std::string
1191  HalDrive::getUDI() const
1192  { return std::string(); }
1193  std::string
1194  HalDrive::getTypeName() const
1195  { return std::string(); }
1196  std::string
1197  HalDrive::getDeviceFile() const
1198  { return std::string(); }
1199  unsigned int
1200  HalDrive::getDeviceMinor() const
1201  { return 0; }
1202  unsigned int
1203  HalDrive::getDeviceMajor() const
1204  { return 0; }
1205  bool
1207  { return false; }
1208  std::vector<std::string>
1210  { return std::vector<std::string>(); }
1211  std::vector<std::string>
1212  HalDrive::findAllVolumes() const
1213  { return std::vector<std::string>(); }
1214 
1215  // --------------------------------------------------------------
1217  { ZYPP_THROW( NoHalException() ); }
1219  {}
1220  HalVolume &
1221  HalVolume::operator=(const HalVolume &)
1222  { return *this; }
1223  HalVolume::operator HalVolume::bool_type() const
1224  { return 0; }
1225  std::string
1226  HalVolume::getUDI() const
1227  { return std::string(); }
1228  std::string
1229  HalVolume::getDeviceFile() const
1230  { return std::string(); }
1231  unsigned int
1233  { return 0; }
1234  unsigned int
1236  { return 0; }
1237  bool
1238  HalVolume::isDisc() const
1239  { return false; }
1240  bool
1241  HalVolume::isPartition() const
1242  { return false; }
1243  bool
1244  HalVolume::isMounted() const
1245  { return false; }
1246  std::string
1247  HalVolume::getFSType() const
1248  { return std::string(); }
1249  std::string
1250  HalVolume::getFSUsage() const
1251  { return std::string(); }
1252  std::string
1253  HalVolume::getMountPoint() const
1254  { return std::string(); }
1255 
1257  } // namespace hal
1260  } // namespace target
1263 } // namespace zypp
1265 #endif // NO_HAL
1266 
1267 /*
1268 ** vim: set ts=2 sts=2 sw=2 ai et:
1269 */
Hardware abstaction layer library wrapper.
HalVolume getVolumeFromUDI(const std::string &udi) const
Construct a HalVolume object for the specified UDI.
Definition: HalContext.cc:405
Interface to gettext.
std::vector< std::string > findAllVolumes() const
Retrieve UDI&#39;s of all volumes of this drive.
Definition: HalContext.cc:916
std::string getDevicePropertyString(const std::string &udi, const std::string &key) const
Definition: HalContext.cc:547
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
Hardware abstaction layer storage drive object.
Definition: HalContext.h:177
void setDevicePropertyString(const std::string &udi, const std::string &key, const std::string &value)
Definition: HalContext.cc:667
zypp::RW_pointer< HalDrive_Impl >::unspecified_bool_type bool_type
Definition: HalContext.h:181
std::string getDeviceFile() const
Definition: HalContext.cc:786
zypp::RW_pointer< HalVolume_Impl > v_impl
Definition: HalContext.h:328
std::ostream & dumpOn(std::ostream &str, const zypp::shared_ptr< void > &obj)
Definition: PtrTypes.h:151
String related utilities and Regular expression matching.
Definition: Arch.h:344
DBusError error
Definition: HalContext.cc:100
HalVolume & operator=(const HalVolume &volume)
Definition: HalContext.cc:967
int32_t getDevicePropertyInt32(const std::string &udi, const std::string &key) const
Definition: HalContext.cc:480
Hardware abstaction layer exception.
Definition: HalException.h:37
Hardware abstaction layer storage volume object.
Definition: HalContext.h:260
unsigned int getDeviceMajor() const
Definition: HalContext.cc:796
std::string getTypeName() const
Definition: HalContext.cc:775
HalVolume getVolumeFromDeviceFile(const std::string &device_file) const
Definition: HalContext.cc:419
HalException()
Default constructor.
Definition: HalContext.cc:24
void setDevicePropertyDouble(const std::string &udi, const std::string &key, double value)
Definition: HalContext.cc:644
std::string getFSType() const
Definition: HalContext.cc:1059
HalDrive_Impl(const zypp::RW_pointer< HalContext_Impl > &r, LibHalDrive *d)
Definition: HalContext.cc:196
unsigned int getDeviceMinor() const
Definition: HalContext.cc:1019
void setDevicePropertyInt32(const std::string &udi, const std::string &key, int32_t value)
Definition: HalContext.cc:598
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
Definition: HalContext.cc:161
std::string getUDI() const
Definition: HalContext.cc:764
std::string getFSUsage() const
Definition: HalContext.cc:1069
zypp::RW_pointer< HalContext_Impl > hal
Definition: HalContext.cc:188
std::string getUDI() const
Definition: HalContext.cc:988
HalContext(bool autoconnect=false)
Definition: HalContext.cc:310
std::string getDeviceFile() const
Definition: HalContext.cc:999
#define _(MSG)
Definition: Gettext.h:37
std::vector< std::string > getCdromCapabilityNames() const
Definition: HalContext.cc:826
zypp::RW_pointer< HalDrive_Impl > d_impl
Definition: HalContext.h:248
void setDevicePropertyUInt64(const std::string &udi, const std::string &key, uint64_t value)
Definition: HalContext.cc:621
std::vector< std::string > getAllDevices() const
Retrieve UDI&#39;s of all devices.
Definition: HalContext.cc:369
bool usesRemovableMedia() const
Definition: HalContext.cc:816
HalDrive getDriveFromUDI(const std::string &udi) const
Construct a HalDrive object for the specified UDI.
Definition: HalContext.cc:391
double getDevicePropertyDouble(const std::string &udi, const std::string &key) const
Definition: HalContext.cc:524
A recursive Mutex.
Definition: Mutex.h:35
std::string getMountPoint() const
Definition: HalContext.cc:1099
HalContext & operator=(const HalContext &context)
Definition: HalContext.cc:338
Base class for Exception.
Definition: Exception.h:145
Hardware abstaction layer library wrapper.
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:285
zypp::RW_pointer< HalVolume_Impl >::unspecified_bool_type bool_type
Definition: HalContext.h:264
zypp::RW_pointer< HalContext_Impl > h_impl
Definition: HalContext.h:165
uint64_t getDevicePropertyUInt64(const std::string &udi, const std::string &key) const
Definition: HalContext.cc:502
bool getDevicePropertyBool(const std::string &udi, const std::string &key) const
Definition: HalContext.cc:458
void removeDeviceProperty(const std::string &udi, const std::string &key)
Definition: HalContext.cc:690
unsigned int getDeviceMajor() const
Definition: HalContext.cc:1009
HalVolume_Impl(LibHalVolume *v=NULL)
Definition: HalContext.cc:216
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
void setDevicePropertyBool(const std::string &udi, const std::string &key, bool value)
Definition: HalContext.cc:575
unsigned int getDeviceMinor() const
Definition: HalContext.cc:806
std::vector< std::string > findDevicesByCapability(const std::string &capability) const
Retrieve UDI&#39;s of all devices with a capability.
Definition: HalContext.cc:434
HalDrive & operator=(const HalDrive &drive)
Definition: HalContext.cc:743
zypp::RW_pointer< HalContext_Impl >::unspecified_bool_type bool_type
Definition: HalContext.h:61