| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
-/** \file zypp/media/Hal.cc
+/** \file zypp/target/hal/HalContext.cc
*
* \brief Hardware abstaction layer library wrapper implementation.
*/
-#ifndef FAKE_HAL // disables zypp's HAL dependency
+#include <zypp/target/hal/HalException.h>
+//////////////////////////////////////////////////////////////////////
+namespace zypp
+{ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+ namespace target
+ { //////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////
+ namespace hal
+ { ////////////////////////////////////////////////////////////////
+ NoHalException::NoHalException()
+ : Exception(_("Sorry, but this version of libzypp was built without HAL support."))
+ {}
+ ////////////////////////////////////////////////////////////////
+ } // namespace hal
+ //////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////
+ } // namespace target
+ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+} // namespace zypp
+//////////////////////////////////////////////////////////////////////
+
+#ifndef NO_HAL // disables zypp's HAL dependency
#include <zypp/target/hal/HalContext.h>
#include <zypp/thread/Mutex.h>
#include <zypp/thread/MutexLock.h>
#include <zypp/base/NonCopyable.h>
#include <zypp/base/Logger.h>
+#include <zypp/base/String.h>
+#include <zypp/base/Gettext.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus-glib.h>
#include <hal/libhal.h>
#include <hal/libhal-storage.h>
return dbus_error_is_set(&error);
}
- inline HalException halException() const
+ inline HalException halException(const std::string &msg = std::string()) const
{
- if( error.name != NULL && error.message != NULL) {
+ if( isSet() && error.name != NULL && error.message != NULL) {
return HalException(error.name, error.message);
- } else {
+ }
+ else if( !msg.empty()) {
+ return HalException(msg);
+ }
+ else {
return HalException();
}
}
{
if( !h)
{
- ZYPP_THROW(HalException("HalContext not connected"));
+ ZYPP_THROW(HalException(_("HalContext not connected")));
}
}
{
if( !d)
{
- ZYPP_THROW(HalException("HalDrive not initialized"));
+ ZYPP_THROW(HalException(_("HalDrive not initialized")));
}
}
{
if( !v)
{
- ZYPP_THROW(HalException("HalVolume not initialized"));
+ ZYPP_THROW(HalException(_("HalVolume not initialized")));
}
}
{
if(!e_name.empty() && !e_msg.empty())
return str << msg() << ": " << e_msg << " (" << e_name << ")";
+ else if(!e_msg.empty())
+ return str << msg() << ": " << e_msg;
else
return str << msg();
}
class HalContext_Impl
{
public:
- HalContext_Impl(bool monitorable = false);
+ HalContext_Impl();
~HalContext_Impl();
DBusConnection *conn;
LibHalContext *hctx;
+ bool pcon; // private connection
};
////////////////////////////////////////////////////////////////
- HalContext_Impl::HalContext_Impl(bool monitorable)
+ HalContext_Impl::HalContext_Impl()
: conn(NULL)
, hctx(NULL)
+ , pcon(false) // we allways use shared connections at the moment
{
HalError err;
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err.error);
+ if( pcon)
+ conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err.error);
+ else
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err.error);
if( !conn) {
- ZYPP_THROW(err.halException());
+ ZYPP_THROW(err.halException(
+ _("Unable to create dbus connection")
+ ));
}
- if( monitorable)
- dbus_connection_setup_with_g_main(conn, NULL);
-
hctx = libhal_ctx_new();
if( !hctx)
{
- dbus_connection_disconnect(conn);
+ if( pcon)
+ dbus_connection_close(conn);
dbus_connection_unref(conn);
conn = NULL;
ZYPP_THROW(HalException(
- "libhal_ctx_new: Can't create libhal context"
+ _("libhal_ctx_new: Can't create libhal context")
));
}
libhal_ctx_free(hctx);
hctx = NULL;
- dbus_connection_disconnect(conn);
+ if( pcon)
+ dbus_connection_close(conn);
dbus_connection_unref(conn);
conn = NULL;
ZYPP_THROW(HalException(
- "libhal_set_dbus_connection: Can't set dbus connection"
+ _("libhal_set_dbus_connection: Can't set dbus connection")
));
}
libhal_ctx_free(hctx);
hctx = NULL;
- dbus_connection_disconnect(conn);
+ if( pcon)
+ dbus_connection_close(conn);
dbus_connection_unref(conn);
conn = NULL;
- ZYPP_THROW(err.halException());
+ ZYPP_THROW(err.halException(
+ _("Unable to initalize HAL context -- hald not running?")
+ ));
}
}
}
if( conn)
{
- dbus_connection_close(conn);
+ if( pcon)
+ dbus_connection_close(conn);
dbus_connection_unref(conn);
}
}
}
// -------------------------------------------------------------
- HalContext::HalContext(bool autoconnect, bool monitorable)
- : h_impl( NULL)
- {
- MutexLock lock(g_Mutex);
-
- if( autoconnect)
- h_impl.reset( new HalContext_Impl(monitorable));
- }
-
- // -------------------------------------------------------------
HalContext::~HalContext()
{
MutexLock lock(g_Mutex);
#if 0
if( libhal_drive_get_type(d_impl->drv) != LIBHAL_DRIVE_TYPE_CDROM)
- ZYPP_THROW(HalException("Not a CDROM drive"));
+ ZYPP_THROW(HalException(_("Not a CDROM drive")));
/*
** FIXME: we use property keys matching
////////////////////////////////////////////////////////////////////
} // namespace zypp
//////////////////////////////////////////////////////////////////////
-#else // FAKE_HAL
+#else // NO_HAL
#include <zypp/target/hal/HalContext.h>
#include <zypp/target/hal/HalException.h>
namespace zypp
// --------------------------------------------------------------
HalContext::HalContext(bool)
- {}
+ { ZYPP_THROW( NoHalException() ); }
HalContext::~HalContext()
{}
HalContext &
{ return ""; }
// --------------------------------------------------------------
HalDrive::HalDrive()
- {}
+ { ZYPP_THROW( NoHalException() ); }
HalDrive::~HalDrive()
{}
HalDrive &
// --------------------------------------------------------------
HalVolume::HalVolume()
- {}
+ { ZYPP_THROW( NoHalException() ); }
HalVolume::~HalVolume()
{}
HalVolume &
////////////////////////////////////////////////////////////////////
} // namespace zypp
//////////////////////////////////////////////////////////////////////
-#endif // FAKE_HAL
+#endif // NO_HAL
/*
** vim: set ts=2 sts=2 sw=2 ai et: