VirtualBox

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

Last change on this file since 3940 was 3940, checked in by vboxsync, 18 years ago

Export to OSE.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 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.215389.xyz. 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 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#include "vbox-libhal.h"
24
25#include <iprt/err.h>
26#include <iprt/ldr.h>
27
28/**
29 * Whether we have tried to load libdbus and libhal yet. This flag should only be set
30 * to "true" after we have either loaded both libraries and all symbols which we need,
31 * or failed to load something and unloaded and set back to zero pLibDBus and pLibHal.
32 */
33static bool gCheckedForLibHal = false;
34/**
35 * Pointer to the libdbus shared object. This should only be set once all needed libraries
36 * and symbols have been successfully loaded.
37 */
38static RTLDRMOD ghLibDBus = 0;
39/**
40 * Pointer to the libhal shared object. This should only be set once all needed libraries
41 * and symbols have been successfully loaded.
42 */
43static RTLDRMOD ghLibHal = 0;
44
45/** The following are the symbols which we need from libdbus and libhal. */
46void (*DBusErrorInit)(DBusError *);
47DBusConnection *(*DBusBusGet)(DBusBusType, DBusError *);
48void (*DBusErrorFree)(DBusError *);
49void (*DBusConnectionUnref)(DBusConnection *);
50LibHalContext *(*LibHalCtxNew)(void);
51dbus_bool_t (*LibHalCtxSetDBusConnection)(LibHalContext *, DBusConnection *);
52dbus_bool_t (*LibHalCtxInit)(LibHalContext *, DBusError *);
53char **(*LibHalFindDeviceByCapability)(LibHalContext *, const char *, int *, DBusError *);
54char *(*LibHalDeviceGetPropertyString)(LibHalContext *, const char *, const char *, DBusError *);
55void (*LibHalFreeString)(char *);
56void (*LibHalFreeStringArray)(char **);
57dbus_bool_t (*LibHalCtxShutdown)(LibHalContext *, DBusError *);
58dbus_bool_t (*LibHalCtxFree)(LibHalContext *);
59
60bool LibHalCheckPresence(void)
61{
62 RTLDRMOD hLibDBus;
63 RTLDRMOD hLibHal;
64
65 if (ghLibDBus != 0 && ghLibHal != 0 && gCheckedForLibHal == true)
66 return true;
67 if (gCheckedForLibHal == true)
68 return false;
69 if (!RT_SUCCESS(RTLdrLoad(LIB_DBUS, &hLibDBus)))
70 return false;
71 if (!RT_SUCCESS(RTLdrLoad(LIB_HAL, &hLibHal)))
72 {
73 RTLdrClose(hLibDBus);
74 return false;
75 }
76 if ( RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_init", (void **) &DBusErrorInit))
77 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get", (void **) &DBusBusGet))
78 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_free", (void **) &DBusErrorFree))
79 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_unref",
80 (void **) &DBusConnectionUnref))
81 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_new", (void **) &LibHalCtxNew))
82 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_set_dbus_connection",
83 (void **) &LibHalCtxSetDBusConnection))
84 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_init", (void **) &LibHalCtxInit))
85 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_find_device_by_capability",
86 (void **) &LibHalFindDeviceByCapability))
87 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_device_get_property_string",
88 (void **) &LibHalDeviceGetPropertyString))
89 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string", (void **) &LibHalFreeString))
90 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string_array",
91 (void **) &LibHalFreeStringArray))
92 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_shutdown", (void **) &LibHalCtxShutdown))
93 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_free", (void **) &LibHalCtxFree))
94 )
95 {
96 ghLibDBus = hLibDBus;
97 ghLibHal = hLibHal;
98 gCheckedForLibHal = true;
99 return true;
100 }
101 else
102 {
103 RTLdrClose(hLibDBus);
104 RTLdrClose(hLibHal);
105 gCheckedForLibHal = true;
106 return false;
107 }
108}
Note: See TracBrowser for help on using the repository browser.

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