VirtualBox

source: vbox/trunk/src/VBox/Main/linux/vbox-libhal.cpp@ 5528

Last change on this file since 5528 was 5368, checked in by vboxsync, 17 years ago

Attempt to fix libhal cdrom and floppy detection

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/** @file
2 *
3 * Module to dynamically load libhal and libdbus and load all symbols
4 * which are needed by VirtualBox.
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
9 *
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 as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "vbox-libhal.h"
20
21#include <iprt/err.h>
22#include <iprt/ldr.h>
23
24/**
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.
28 */
29static bool gCheckedForLibHal = false;
30/**
31 * Pointer to the libdbus shared object. This should only be set once all needed libraries
32 * and symbols have been successfully loaded.
33 */
34static RTLDRMOD ghLibDBus = 0;
35/**
36 * Pointer to the libhal shared object. This should only be set once all needed libraries
37 * and symbols have been successfully loaded.
38 */
39static RTLDRMOD ghLibHal = 0;
40
41/** The following are the symbols which we need from libdbus and libhal. */
42void (*gDBusErrorInit)(DBusError *);
43DBusConnection *(*gDBusBusGet)(DBusBusType, DBusError *);
44void (*gDBusErrorFree)(DBusError *);
45void (*gDBusConnectionUnref)(DBusConnection *);
46LibHalContext *(*gLibHalCtxNew)(void);
47dbus_bool_t (*gLibHalCtxSetDBusConnection)(LibHalContext *, DBusConnection *);
48dbus_bool_t (*gLibHalCtxInit)(LibHalContext *, DBusError *);
49char **(*gLibHalFindDeviceStringMatch)(LibHalContext *, const char *, const char *, int *,
50 DBusError *);
51char *(*gLibHalDeviceGetPropertyString)(LibHalContext *, const char *, const char *, DBusError *);
52void (*gLibHalFreeString)(char *);
53void (*gLibHalFreeStringArray)(char **);
54dbus_bool_t (*gLibHalCtxShutdown)(LibHalContext *, DBusError *);
55dbus_bool_t (*gLibHalCtxFree)(LibHalContext *);
56
57bool gLibHalCheckPresence(void)
58{
59 RTLDRMOD hLibDBus;
60 RTLDRMOD hLibHal;
61
62 if (ghLibDBus != 0 && ghLibHal != 0 && gCheckedForLibHal == true)
63 return true;
64 if (gCheckedForLibHal == true)
65 return false;
66 if (!RT_SUCCESS(RTLdrLoad(LIB_DBUS, &hLibDBus)))
67 return false;
68 if (!RT_SUCCESS(RTLdrLoad(LIB_HAL, &hLibHal)))
69 {
70 RTLdrClose(hLibDBus);
71 return false;
72 }
73 if ( RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_init", (void **) &gDBusErrorInit))
74 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get", (void **) &gDBusBusGet))
75 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_free", (void **) &gDBusErrorFree))
76 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_unref",
77 (void **) &gDBusConnectionUnref))
78 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_new", (void **) &gLibHalCtxNew))
79 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_set_dbus_connection",
80 (void **) &gLibHalCtxSetDBusConnection))
81 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_init", (void **) &gLibHalCtxInit))
82 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_manager_find_device_string_match",
83 (void **) &gLibHalFindDeviceStringMatch))
84 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_device_get_property_string",
85 (void **) &gLibHalDeviceGetPropertyString))
86 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string", (void **) &gLibHalFreeString))
87 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string_array",
88 (void **) &gLibHalFreeStringArray))
89 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_shutdown", (void **) &gLibHalCtxShutdown))
90 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_free", (void **) &gLibHalCtxFree))
91 )
92 {
93 ghLibDBus = hLibDBus;
94 ghLibHal = hLibHal;
95 gCheckedForLibHal = true;
96 return true;
97 }
98 else
99 {
100 RTLdrClose(hLibDBus);
101 RTLdrClose(hLibHal);
102 gCheckedForLibHal = true;
103 return false;
104 }
105}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette