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 | #ifndef ____H_VBOX_DBUS
|
---|
24 | #define ____H_VBOX_DBUS
|
---|
25 |
|
---|
26 | #include <stdint.h>
|
---|
27 |
|
---|
28 | #define LIB_DBUS_1_2 "libdbus-1.so.2" /* This should be compatible */
|
---|
29 | #define LIB_DBUS_1_3 "libdbus-1.so.3"
|
---|
30 |
|
---|
31 | /** Types and defines from the dbus header files which we need. These are
|
---|
32 | * taken more or less verbatim from the DBus public interface header files. */
|
---|
33 | struct DBusError
|
---|
34 | {
|
---|
35 | const char *name;
|
---|
36 | const char *message;
|
---|
37 | unsigned int dummy1 : 1;
|
---|
38 | unsigned int dummy2 : 1;
|
---|
39 | unsigned int dummy3 : 1;
|
---|
40 | unsigned int dummy4 : 1;
|
---|
41 | unsigned int dummy5 : 1;
|
---|
42 | void *padding1;
|
---|
43 | };
|
---|
44 | struct DBusConnection;
|
---|
45 | typedef struct DBusConnection DBusConnection;
|
---|
46 | typedef uint32_t dbus_bool_t;
|
---|
47 | typedef uint32_t dbus_uint32_t;
|
---|
48 | typedef enum { DBUS_BUS_SESSON, DBUS_BUS_SYSTEM, DBUS_BUS_STARTER } DBusBusType;
|
---|
49 | struct DBusMessage;
|
---|
50 | typedef struct DBusMessage DBusMessage;
|
---|
51 | struct DBusMessageIter
|
---|
52 | {
|
---|
53 | void *dummy1;
|
---|
54 | void *dummy2;
|
---|
55 | dbus_uint32_t dummy3;
|
---|
56 | int dummy4;
|
---|
57 | int dummy5;
|
---|
58 | int dummy6;
|
---|
59 | int dummy7;
|
---|
60 | int dummy8;
|
---|
61 | int dummy9;
|
---|
62 | int dummy10;
|
---|
63 | int dummy11;
|
---|
64 | int pad1;
|
---|
65 | int pad2;
|
---|
66 | void *pad3;
|
---|
67 | };
|
---|
68 | typedef struct DBusMessageIter DBusMessageIter;
|
---|
69 |
|
---|
70 | #define DBUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory"
|
---|
71 | #define DBUS_TYPE_INVALID ((int) '\0')
|
---|
72 | #define DBUS_TYPE_STRING ((int) 's')
|
---|
73 | #define DBUS_TYPE_ARRAY ((int) 'a')
|
---|
74 | #define DBUS_TYPE_DICT_ENTRY ((int) 'e')
|
---|
75 |
|
---|
76 | typedef enum
|
---|
77 | {
|
---|
78 | DBUS_HANDLER_RESULT_HANDLED,
|
---|
79 | DBUS_HANDLER_RESULT_NOT_YET_HANDLED,
|
---|
80 | DBUS_HANDLER_RESULT_NEED_MEMORY
|
---|
81 | } DBusHandlerResult;
|
---|
82 |
|
---|
83 | typedef DBusHandlerResult (*DBusHandleMessageFunction) (DBusConnection *,
|
---|
84 | DBusMessage *, void *);
|
---|
85 | typedef void (*DBusFreeFunction) (void *);
|
---|
86 |
|
---|
87 | /** The following are the symbols which we need from libdbus-1. */
|
---|
88 | extern void (*vbox_dbus_error_init)(DBusError *);
|
---|
89 | inline void dbus_error_init(DBusError *error)
|
---|
90 | { vbox_dbus_error_init(error); }
|
---|
91 | extern DBusConnection *(*vbox_dbus_bus_get)(DBusBusType, DBusError *);
|
---|
92 | inline DBusConnection *dbus_bus_get(DBusBusType type, DBusError *error)
|
---|
93 | { return vbox_dbus_bus_get(type, error); }
|
---|
94 | extern DBusConnection *(*vbox_dbus_bus_get_private)(DBusBusType, DBusError *);
|
---|
95 | inline DBusConnection *dbus_bus_get_private(DBusBusType type, DBusError *error)
|
---|
96 | { return vbox_dbus_bus_get_private(type, error); }
|
---|
97 | extern void (*vbox_dbus_error_free)(DBusError *);
|
---|
98 | inline void dbus_error_free(DBusError *error)
|
---|
99 | { vbox_dbus_error_free(error); }
|
---|
100 | extern void (*vbox_dbus_connection_unref)(DBusConnection *);
|
---|
101 | inline void dbus_connection_unref(DBusConnection *connection)
|
---|
102 | { vbox_dbus_connection_unref(connection); }
|
---|
103 | extern void (*vbox_dbus_connection_close)(DBusConnection *);
|
---|
104 | inline void dbus_connection_close(DBusConnection *connection)
|
---|
105 | { vbox_dbus_connection_close(connection); }
|
---|
106 | extern void (*vbox_dbus_connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
|
---|
107 | inline void dbus_connection_set_exit_on_disconnect(DBusConnection *connection, dbus_bool_t boolean)
|
---|
108 | { vbox_dbus_connection_set_exit_on_disconnect(connection, boolean); }
|
---|
109 | extern dbus_bool_t (*vbox_dbus_bus_name_has_owner)(DBusConnection *, const char *,
|
---|
110 | DBusError *);
|
---|
111 | inline dbus_bool_t dbus_bus_name_has_owner(DBusConnection *connection, const char *string,
|
---|
112 | DBusError *error)
|
---|
113 | { return vbox_dbus_bus_name_has_owner(connection, string, error); }
|
---|
114 | extern void (*vbox_dbus_bus_add_match)(DBusConnection *, const char *, DBusError *);
|
---|
115 | inline void dbus_bus_add_match(DBusConnection *connection, const char *string, DBusError *error)
|
---|
116 | { vbox_dbus_bus_add_match(connection, string, error); }
|
---|
117 | extern void (*vbox_dbus_bus_remove_match)(DBusConnection *, const char *, DBusError *);
|
---|
118 | inline void dbus_bus_remove_match(DBusConnection *connection, const char *string, DBusError *error)
|
---|
119 | { vbox_dbus_bus_remove_match(connection, string, error); }
|
---|
120 | extern void (*vbox_dbus_message_unref)(DBusMessage *);
|
---|
121 | inline void dbus_message_unref(DBusMessage *message)
|
---|
122 | { vbox_dbus_message_unref(message); }
|
---|
123 | extern DBusMessage* (*vbox_dbus_message_new_method_call)(const char *, const char *,
|
---|
124 | const char *, const char *);
|
---|
125 | inline DBusMessage* dbus_message_new_method_call(const char *string1, const char *string2,
|
---|
126 | const char *string3, const char *string4)
|
---|
127 | { return vbox_dbus_message_new_method_call(string1, string2, string3, string4); }
|
---|
128 | extern void (*vbox_dbus_message_iter_init_append)(DBusMessage *, DBusMessageIter *);
|
---|
129 | inline void dbus_message_iter_init_append(DBusMessage *message, DBusMessageIter *iter)
|
---|
130 | { vbox_dbus_message_iter_init_append(message, iter); }
|
---|
131 | extern dbus_bool_t (*vbox_dbus_message_iter_append_basic)(DBusMessageIter *, int,
|
---|
132 | const void *);
|
---|
133 | inline dbus_bool_t dbus_message_iter_append_basic(DBusMessageIter *iter, int val,
|
---|
134 | const void *string)
|
---|
135 | { return vbox_dbus_message_iter_append_basic(iter, val, string); }
|
---|
136 | extern DBusMessage * (*vbox_dbus_connection_send_with_reply_and_block)(DBusConnection *,
|
---|
137 | DBusMessage *, int,
|
---|
138 | DBusError *error);
|
---|
139 | inline DBusMessage * dbus_connection_send_with_reply_and_block(DBusConnection *connection,
|
---|
140 | DBusMessage *message, int val,
|
---|
141 | DBusError *error)
|
---|
142 | { return vbox_dbus_connection_send_with_reply_and_block(connection, message, val, error); }
|
---|
143 | extern dbus_bool_t (*vbox_dbus_message_iter_init) (DBusMessage *, DBusMessageIter *);
|
---|
144 | inline dbus_bool_t dbus_message_iter_init(DBusMessage *message, DBusMessageIter *iter)
|
---|
145 | { return vbox_dbus_message_iter_init(message, iter); }
|
---|
146 | extern int (*vbox_dbus_message_iter_get_arg_type) (DBusMessageIter *);
|
---|
147 | inline int dbus_message_iter_get_arg_type(DBusMessageIter *iter)
|
---|
148 | { return vbox_dbus_message_iter_get_arg_type(iter); }
|
---|
149 | extern int (*vbox_dbus_message_iter_get_element_type) (DBusMessageIter *);
|
---|
150 | inline int dbus_message_iter_get_element_type(DBusMessageIter *iter)
|
---|
151 | { return vbox_dbus_message_iter_get_element_type(iter); }
|
---|
152 | extern void (*vbox_dbus_message_iter_recurse) (DBusMessageIter *, DBusMessageIter *);
|
---|
153 | inline void dbus_message_iter_recurse(DBusMessageIter *iter1, DBusMessageIter *iter2)
|
---|
154 | { vbox_dbus_message_iter_recurse(iter1, iter2); }
|
---|
155 | extern void (*vbox_dbus_message_iter_get_basic) (DBusMessageIter *, void *);
|
---|
156 | inline void dbus_message_iter_get_basic(DBusMessageIter *iter, void *pvoid)
|
---|
157 | { vbox_dbus_message_iter_get_basic(iter, pvoid); }
|
---|
158 | extern dbus_bool_t (*vbox_dbus_message_iter_next) (DBusMessageIter *);
|
---|
159 | inline dbus_bool_t dbus_message_iter_next(DBusMessageIter *iter)
|
---|
160 | { return vbox_dbus_message_iter_next(iter); }
|
---|
161 | extern dbus_bool_t (*vbox_dbus_connection_add_filter) (DBusConnection *, DBusHandleMessageFunction,
|
---|
162 | void *, DBusFreeFunction);
|
---|
163 | inline dbus_bool_t dbus_connection_add_filter(DBusConnection *connection,
|
---|
164 | DBusHandleMessageFunction function1,
|
---|
165 | void *pvoid, DBusFreeFunction function2)
|
---|
166 | { return vbox_dbus_connection_add_filter(connection, function1, pvoid, function2); }
|
---|
167 | extern void (*vbox_dbus_connection_remove_filter) (DBusConnection *, DBusHandleMessageFunction,
|
---|
168 | void *);
|
---|
169 | inline void dbus_connection_remove_filter(DBusConnection *connection,
|
---|
170 | DBusHandleMessageFunction function, void *pvoid)
|
---|
171 | { vbox_dbus_connection_remove_filter(connection, function, pvoid); }
|
---|
172 | extern dbus_bool_t (*vbox_dbus_connection_read_write_dispatch) (DBusConnection *, int);
|
---|
173 | inline dbus_bool_t dbus_connection_read_write_dispatch(DBusConnection *connection, int val)
|
---|
174 | { return vbox_dbus_connection_read_write_dispatch(connection, val); }
|
---|
175 | extern dbus_bool_t (*vbox_dbus_message_is_signal) (DBusMessage *, const char *, const char *);
|
---|
176 | inline dbus_bool_t dbus_message_is_signal(DBusMessage *message, const char *string1, const char *string2)
|
---|
177 | { return vbox_dbus_message_is_signal(message, string1, string2); }
|
---|
178 | extern DBusMessage *(*vbox_dbus_connection_pop_message)(DBusConnection *);
|
---|
179 | inline DBusMessage *dbus_connection_pop_message(DBusConnection *connection)
|
---|
180 | { return vbox_dbus_connection_pop_message(connection); }
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Checks whether libdbus is present and if so loads all symbols we need. This
|
---|
184 | * should be called before making any calls to libdbus if that library is being
|
---|
185 | * loaded at runtime.
|
---|
186 | * @returns true if libdbus was found, false otherwise.
|
---|
187 | */
|
---|
188 | extern bool VBoxDBusCheckPresence(void);
|
---|
189 | /** Wrapper around dbus_connection_unref. We need this to use it as a free
|
---|
190 | * function in auto pointers, as a function pointer won't wash here. */
|
---|
191 | extern void VBoxDBusConnectionUnref(DBusConnection *pConnection);
|
---|
192 | /** Wrapper around dbus_message_unref. We need this to use it as a free
|
---|
193 | * function in auto pointers, as a function pointer won't wash here. */
|
---|
194 | extern void VBoxDBusMessageUnref(DBusMessage *pMessage);
|
---|
195 |
|
---|
196 | #endif /* ____H_VBOX_DBUS not defined */
|
---|
197 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|
198 |
|
---|