VirtualBox

source: vbox/trunk/src/VBox/Main/linux/vbox-dbus.cpp@ 16111

Last change on this file since 16111 was 16006, checked in by vboxsync, 16 years ago

Main: attempt to fix symbol conflicts with dynamically loaded libdbus-1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/** @file
2 *
3 * Module to dynamically load libdbus and load all symbols
4 * which are needed by VirtualBox.
5 */
6
7/*
8 * Copyright (C) 2008 Sun Microsystems, Inc.
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 (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.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#include "vbox-dbus.h"
24
25#include <iprt/err.h>
26#include <iprt/ldr.h>
27
28/**
29 * Whether we have tried to load libdbus-1 yet. This flag should only be set
30 * to "true" after we have either loaded the library and all symbols which we
31 * need, or failed to load something and unloaded and set back to zero
32 * pLibDBus.
33 */
34static bool gCheckedForLibDBus = false;
35/**
36 * Pointer to the libdbus-1 shared object. This should only be set once all
37 * needed libraries and symbols have been successfully loaded.
38 */
39static RTLDRMOD ghLibDBus = NULL;
40
41/** The following are the symbols which we need from libdbus. */
42void (*vbox_dbus_error_init)(DBusError *);
43DBusConnection *(*vbox_dbus_bus_get)(DBusBusType, DBusError *);
44DBusConnection *(*vbox_dbus_bus_get_private)(DBusBusType, DBusError *);
45void (*vbox_dbus_error_free)(DBusError *);
46void (*vbox_dbus_connection_unref)(DBusConnection *);
47void (*vbox_dbus_connection_close)(DBusConnection *);
48void (*vbox_dbus_connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
49dbus_bool_t (*vbox_dbus_bus_name_has_owner)(DBusConnection *, const char *,
50 DBusError *);
51void (*vbox_dbus_bus_add_match)(DBusConnection *, const char *, DBusError *);
52void (*vbox_dbus_bus_remove_match)(DBusConnection *, const char *, DBusError *);
53void (*vbox_dbus_message_unref)(DBusMessage *);
54DBusMessage* (*vbox_dbus_message_new_method_call)(const char *, const char *,
55 const char *, const char *);
56void (*vbox_dbus_message_iter_init_append)(DBusMessage *, DBusMessageIter *);
57dbus_bool_t (*vbox_dbus_message_iter_append_basic)(DBusMessageIter *, int,
58 const void *);
59DBusMessage * (*vbox_dbus_connection_send_with_reply_and_block)(DBusConnection *,
60 DBusMessage *, int,
61 DBusError *error);
62dbus_bool_t (*vbox_dbus_message_iter_init) (DBusMessage *, DBusMessageIter *);
63int (*vbox_dbus_message_iter_get_arg_type) (DBusMessageIter *);
64int (*vbox_dbus_message_iter_get_element_type) (DBusMessageIter *);
65void (*vbox_dbus_message_iter_recurse) (DBusMessageIter *, DBusMessageIter *);
66void (*vbox_dbus_message_iter_get_basic) (DBusMessageIter *, void *);
67dbus_bool_t (*vbox_dbus_message_iter_next) (DBusMessageIter *);
68dbus_bool_t (*vbox_dbus_connection_add_filter) (DBusConnection *, DBusHandleMessageFunction,
69 void *, DBusFreeFunction);
70void (*vbox_dbus_connection_remove_filter) (DBusConnection *, DBusHandleMessageFunction,
71 void *);
72dbus_bool_t (*vbox_dbus_connection_read_write_dispatch) (DBusConnection *, int);
73dbus_bool_t (*vbox_dbus_message_is_signal) (DBusMessage *, const char *, const char *);
74DBusMessage *(*vbox_dbus_connection_pop_message)(DBusConnection *);
75
76bool VBoxDBusCheckPresence(void)
77{
78 RTLDRMOD hLibDBus;
79
80 if (ghLibDBus != 0 && gCheckedForLibDBus == true)
81 return true;
82 if (gCheckedForLibDBus == true)
83 return false;
84 if ( !RT_SUCCESS(RTLdrLoad(LIB_DBUS_1_3, &hLibDBus))
85 && !RT_SUCCESS(RTLdrLoad(LIB_DBUS_1_2, &hLibDBus)))
86 {
87 return false;
88 }
89 if ( RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_init",
90 (void **) &vbox_dbus_error_init))
91 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get",
92 (void **) &vbox_dbus_bus_get))
93 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get_private",
94 (void **) &vbox_dbus_bus_get_private))
95 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_free",
96 (void **) &vbox_dbus_error_free))
97 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_unref",
98 (void **) &vbox_dbus_connection_unref))
99 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_close",
100 (void **) &vbox_dbus_connection_close))
101 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_set_exit_on_disconnect",
102 (void **) &vbox_dbus_connection_set_exit_on_disconnect))
103 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_name_has_owner",
104 (void **) &vbox_dbus_bus_name_has_owner))
105 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_add_match",
106 (void **) &vbox_dbus_bus_add_match))
107 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_remove_match",
108 (void **) &vbox_dbus_bus_remove_match))
109 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_unref",
110 (void **) &vbox_dbus_message_unref))
111 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_new_method_call",
112 (void **) &vbox_dbus_message_new_method_call))
113 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_init_append",
114 (void **) &vbox_dbus_message_iter_init_append))
115 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_append_basic",
116 (void **) &vbox_dbus_message_iter_append_basic))
117 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_send_with_reply_and_block",
118 (void **) &vbox_dbus_connection_send_with_reply_and_block))
119 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_init",
120 (void **) &vbox_dbus_message_iter_init))
121 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_get_arg_type",
122 (void **) &vbox_dbus_message_iter_get_arg_type))
123 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_get_element_type",
124 (void **) &vbox_dbus_message_iter_get_element_type))
125 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_recurse",
126 (void **) &vbox_dbus_message_iter_recurse))
127 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_get_basic",
128 (void **) &vbox_dbus_message_iter_get_basic))
129 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_next",
130 (void **) &vbox_dbus_message_iter_next))
131 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_add_filter",
132 (void **) &vbox_dbus_connection_add_filter))
133 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_remove_filter",
134 (void **) &vbox_dbus_connection_remove_filter))
135 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_read_write_dispatch",
136 (void **) &vbox_dbus_connection_read_write_dispatch))
137 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_is_signal",
138 (void **) &vbox_dbus_message_is_signal))
139 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_pop_message",
140 (void **) &vbox_dbus_connection_pop_message))
141 )
142 {
143 ghLibDBus = hLibDBus;
144 gCheckedForLibDBus = true;
145 return true;
146 }
147 else
148 {
149 RTLdrClose(hLibDBus);
150 gCheckedForLibDBus = true;
151 return false;
152 }
153}
154
155void VBoxDBusConnectionUnref(DBusConnection *pConnection)
156{
157 dbus_connection_unref(pConnection);
158}
159
160void VBoxDBusMessageUnref(DBusMessage *pMessage)
161{
162 dbus_message_unref(pMessage);
163}
164
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