3
* Module to dynamically load libhal and libdbus and load all symbols
4
* which are needed by VirtualBox.
8
* Copyright (C) 2006-2007 Oracle Corporation
10
* This file is part of VirtualBox Open Source Edition (OSE), as
11
* available from http://www.virtualbox.org. This file is free software;
12
* you can redistribute it and/or modify it under the terms of the GNU
13
* General Public License (GPL) as published by the Free Software
14
* Foundation, in version 2 as it comes in the "COPYING" file of the
15
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
#include "vbox-libhal.h"
25
* Whether we have tried to load libdbus and libhal yet. This flag should only be set
26
* to "true" after we have either loaded both libraries and all symbols which we need,
27
* or failed to load something and unloaded and set back to zero pLibDBus and pLibHal.
29
static bool gCheckedForLibHal = false;
31
* Pointer to the libhal shared object. This should only be set once all needed libraries
32
* and symbols have been successfully loaded.
34
static RTLDRMOD ghLibHal = 0;
36
/** The following are the symbols which we need from libdbus and libhal. */
37
void (*gDBusErrorInit)(DBusError *);
38
DBusConnection *(*gDBusBusGet)(DBusBusType, DBusError *);
39
void (*gDBusErrorFree)(DBusError *);
40
void (*gDBusConnectionUnref)(DBusConnection *);
41
LibHalContext *(*gLibHalCtxNew)(void);
42
dbus_bool_t (*gLibHalCtxSetDBusConnection)(LibHalContext *, DBusConnection *);
43
dbus_bool_t (*gLibHalCtxInit)(LibHalContext *, DBusError *);
44
char **(*gLibHalFindDeviceStringMatch)(LibHalContext *, const char *, const char *, int *,
46
char *(*gLibHalDeviceGetPropertyString)(LibHalContext *, const char *, const char *, DBusError *);
47
void (*gLibHalFreeString)(char *);
48
void (*gLibHalFreeStringArray)(char **);
49
dbus_bool_t (*gLibHalCtxShutdown)(LibHalContext *, DBusError *);
50
dbus_bool_t (*gLibHalCtxFree)(LibHalContext *);
52
bool gLibHalCheckPresence(void)
56
if (ghLibHal != 0 && gCheckedForLibHal == true)
58
if (gCheckedForLibHal == true)
60
if (!RT_SUCCESS(RTLdrLoad(LIB_HAL, &hLibHal)))
64
if ( RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_error_init", (void **) &gDBusErrorInit))
65
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_bus_get", (void **) &gDBusBusGet))
66
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_error_free", (void **) &gDBusErrorFree))
67
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_connection_unref",
68
(void **) &gDBusConnectionUnref))
69
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_new", (void **) &gLibHalCtxNew))
70
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_set_dbus_connection",
71
(void **) &gLibHalCtxSetDBusConnection))
72
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_init", (void **) &gLibHalCtxInit))
73
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_manager_find_device_string_match",
74
(void **) &gLibHalFindDeviceStringMatch))
75
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_device_get_property_string",
76
(void **) &gLibHalDeviceGetPropertyString))
77
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string", (void **) &gLibHalFreeString))
78
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string_array",
79
(void **) &gLibHalFreeStringArray))
80
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_shutdown", (void **) &gLibHalCtxShutdown))
81
&& RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_free", (void **) &gLibHalCtxFree))
85
gCheckedForLibHal = true;
91
gCheckedForLibHal = true;