VirtualBox

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

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

Corrected the style in the new dbus and libhal code in Main

  • 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.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 * 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 (*gDBusErrorInit)(DBusError *);
47DBusConnection *(*gDBusBusGet)(DBusBusType, DBusError *);
48void (*gDBusErrorFree)(DBusError *);
49void (*gDBusConnectionUnref)(DBusConnection *);
50LibHalContext *(*gLibHalCtxNew)(void);
51dbus_bool_t (*gLibHalCtxSetDBusConnection)(LibHalContext *, DBusConnection *);
52dbus_bool_t (*gLibHalCtxInit)(LibHalContext *, DBusError *);
53char **(*gLibHalFindDeviceByCapability)(LibHalContext *, const char *, int *, DBusError *);
54char *(*gLibHalDeviceGetPropertyString)(LibHalContext *, const char *, const char *, DBusError *);
55void (*gLibHalFreeString)(char *);
56void (*gLibHalFreeStringArray)(char **);
57dbus_bool_t (*gLibHalCtxShutdown)(LibHalContext *, DBusError *);
58dbus_bool_t (*gLibHalCtxFree)(LibHalContext *);
59
60bool gLibHalCheckPresence(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 **) &gDBusErrorInit))
77 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get", (void **) &gDBusBusGet))
78 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_free", (void **) &gDBusErrorFree))
79 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_unref",
80 (void **) &gDBusConnectionUnref))
81 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_new", (void **) &gLibHalCtxNew))
82 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_set_dbus_connection",
83 (void **) &gLibHalCtxSetDBusConnection))
84 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_init", (void **) &gLibHalCtxInit))
85 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_find_device_by_capability",
86 (void **) &gLibHalFindDeviceByCapability))
87 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_device_get_property_string",
88 (void **) &gLibHalDeviceGetPropertyString))
89 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string", (void **) &gLibHalFreeString))
90 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string_array",
91 (void **) &gLibHalFreeStringArray))
92 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_shutdown", (void **) &gLibHalCtxShutdown))
93 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_free", (void **) &gLibHalCtxFree))
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.

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