Changeset 15057 in vbox for trunk/src/VBox/Main/linux
- Timestamp:
- Dec 5, 2008 9:47:30 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 40443
- Location:
- trunk/src/VBox/Main/linux
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r14992 r15057 49 49 # include <linux/cdrom.h> 50 50 # ifdef VBOX_WITH_DBUS 51 # include <dbus/dbus.h> 52 /* These are defined by the dbus headers and by VBox header files. */ 53 # undef TRUE 54 # undef FALSE 51 # include <vbox-dbus.h> 55 52 # endif 56 53 # include <errno.h> … … 77 74 #ifdef VBOX_WITH_DBUS 78 75 static int halInit(DBusConnection **ppConnection); 76 /* This must be extern to be used in the RTMemAutoPtr template */ 77 extern void halShutdown (DBusConnection *pConnection); 79 78 static int halFindDeviceStringMatch (DBusConnection *pConnection, 80 79 const char *pszKey, const char *pszValue, … … 103 102 #if defined(RT_OS_LINUX) 104 103 #ifdef VBOX_WITH_DBUS 105 if (RT_SUCCESS (rc) && (!success || testing()))104 if (RT_SUCCESS (rc) && VBoxDBusCheckPresence() && (!success || testing())) 106 105 rc = getDriveInfoFromHal(&mDVDList, true /* isDVD */, &success); 107 106 #endif /* VBOX_WITH_DBUS defined */ … … 153 152 #if defined(RT_OS_LINUX) 154 153 #ifdef VBOX_WITH_DBUS 155 if (RT_SUCCESS (rc) && (!success || testing()))154 if (RT_SUCCESS (rc) && VBoxDBusCheckPresence() && (!success || testing())) 156 155 rc = getDriveInfoFromHal(&mFloppyList, false /* isDVD */, &success); 157 156 #endif /* VBOX_WITH_DBUS defined */ … … 403 402 ~autoDBusError () 404 403 { 405 if ( dbus_error_is_set (&mError))404 if (IsSet()) 406 405 dbus_error_free (&mError); 407 406 } 408 407 DBusError &get () { return mError; } 409 bool IsSet () { return dbus_error_is_set (&mError); } 408 bool IsSet () 409 { 410 Assert ((mError.name == NULL) == (mError.message == NULL)); 411 return (mError.name != NULL); 412 } 410 413 bool HasName (const char *pszName) 411 414 { 412 return dbus_error_has_name (&mError, pszName); 415 Assert ((mError.name == NULL) == (mError.message == NULL)); 416 return (RTStrCmp (mError.name, pszName) == 0); 413 417 } 414 418 void FlowLog () … … 449 453 "interface='org.freedesktop.Hal.Manager'," 450 454 "sender='org.freedesktop.Hal'," 451 "path='/org/freedesktop/Hal/Manager'", &dbusError.get()); 455 "path='/org/freedesktop/Hal/Manager'", 456 &dbusError.get()); 452 457 halSuccess = !dbusError.IsSet(); 453 458 } … … 458 463 dbusError.FlowLog(); 459 464 return rc; 465 } 466 467 /** 468 * Helper function for shutting down a connection to hal 469 * @param pConnection the connection handle 470 */ 471 /* static */ 472 void halShutdown (DBusConnection *pConnection) 473 { 474 AssertReturnVoid(VALID_PTR (pConnection)); 475 LogFlowFunc (("pConnection=%p\n", pConnection)); 476 autoDBusError dbusError; 477 478 dbus_bus_remove_match (pConnection, 479 "type='signal'," 480 "interface='org.freedesktop.Hal.Manager'," 481 "sender='org.freedesktop.Hal'," 482 "path='/org/freedesktop/Hal/Manager'", 483 &dbusError.get()); 484 dbus_connection_unref (pConnection); 485 LogFlowFunc(("returning\n")); 486 dbusError.FlowLog(); 460 487 } 461 488 … … 624 651 625 652 rc = halInit (&pConnection); 626 RTMemAutoPtr <DBusConnection, dbus_connection_unref> dbusConnection;653 RTMemAutoPtr <DBusConnection, halShutdown> dbusConnection; 627 654 dbusConnection = pConnection; 628 655 if (!dbusConnection) -
trunk/src/VBox/Main/linux/vbox-dbus.cpp
r15022 r15057 1 1 /** @file 2 2 * 3 * Module to dynamically load lib hal and libdbus and load all symbols3 * Module to dynamically load libdbus and load all symbols 4 4 * which are needed by VirtualBox. 5 5 */ 6 6 7 7 /* 8 * Copyright (C) 200 6-2007Sun Microsystems, Inc.8 * Copyright (C) 2008 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 */ 22 22 23 #include "vbox- libhal.h"23 #include "vbox-dbus.h" 24 24 25 25 #include <iprt/err.h> … … 27 27 28 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. 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. 32 33 */ 33 static bool gCheckedForLib Hal= false;34 static bool gCheckedForLibDBus = false; 34 35 /** 35 * Pointer to the lib hal shared object. This should only be set once all needed libraries36 * and symbols have been successfully loaded.36 * Pointer to the libdbus-1 shared object. This should only be set once all 37 * needed libraries and symbols have been successfully loaded. 37 38 */ 38 static RTLDRMOD ghLib Hal = 0;39 static RTLDRMOD ghLibDBus = NULL; 39 40 40 /** The following are the symbols which we need from libdbus and libhal. */ 41 void (*gDBusErrorInit)(DBusError *); 42 DBusConnection *(*gDBusBusGet)(DBusBusType, DBusError *); 43 void (*gDBusErrorFree)(DBusError *); 44 void (*gDBusConnectionUnref)(DBusConnection *); 45 LibHalContext *(*gLibHalCtxNew)(void); 46 dbus_bool_t (*gLibHalCtxSetDBusConnection)(LibHalContext *, DBusConnection *); 47 dbus_bool_t (*gLibHalCtxInit)(LibHalContext *, DBusError *); 48 char **(*gLibHalFindDeviceStringMatch)(LibHalContext *, const char *, const char *, int *, 49 DBusError *); 50 char *(*gLibHalDeviceGetPropertyString)(LibHalContext *, const char *, const char *, DBusError *); 51 void (*gLibHalFreeString)(char *); 52 void (*gLibHalFreeStringArray)(char **); 53 dbus_bool_t (*gLibHalCtxShutdown)(LibHalContext *, DBusError *); 54 dbus_bool_t (*gLibHalCtxFree)(LibHalContext *); 41 /** The following are the symbols which we need from libdbus. */ 42 void (*dbus_error_init)(DBusError *); 43 DBusConnection *(*dbus_bus_get)(DBusBusType, DBusError *); 44 void (*dbus_error_free)(DBusError *); 45 void (*dbus_connection_unref)(DBusConnection *); 46 void (*dbus_connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t); 47 dbus_bool_t (*dbus_bus_name_has_owner)(DBusConnection *, const char *, 48 DBusError *); 49 void (*dbus_bus_add_match)(DBusConnection *, const char *, DBusError *); 50 void (*dbus_bus_remove_match)(DBusConnection *, const char *, DBusError *); 51 void (*dbus_message_unref)(DBusMessage *); 52 DBusMessage* (*dbus_message_new_method_call)(const char *, const char *, 53 const char *, const char *); 54 void (*dbus_message_iter_init_append)(DBusMessage *, DBusMessageIter *); 55 dbus_bool_t (*dbus_message_iter_append_basic)(DBusMessageIter *, int, 56 const void *); 57 DBusMessage * (*dbus_connection_send_with_reply_and_block)(DBusConnection *, 58 DBusMessage *, int, 59 DBusError *error); 60 dbus_bool_t (*dbus_message_iter_init) (DBusMessage *, DBusMessageIter *); 61 int (*dbus_message_iter_get_arg_type) (DBusMessageIter *); 62 int (*dbus_message_iter_get_element_type) (DBusMessageIter *); 63 void (*dbus_message_iter_recurse) (DBusMessageIter *, DBusMessageIter *); 64 void (*dbus_message_iter_get_basic) (DBusMessageIter *, void *); 65 dbus_bool_t (*dbus_message_iter_next) (DBusMessageIter *); 55 66 56 bool gLibHalCheckPresence(void)67 bool VBoxDBusCheckPresence(void) 57 68 { 58 RTLDRMOD hLib Hal;69 RTLDRMOD hLibDBus; 59 70 60 if (ghLib Hal != 0 && gCheckedForLibHal== true)71 if (ghLibDBus != 0 && gCheckedForLibDBus == true) 61 72 return true; 62 if (gCheckedForLib Hal== true)73 if (gCheckedForLibDBus == true) 63 74 return false; 64 if (!RT_SUCCESS(RTLdrLoad(LIB_HAL, &hLibHal))) 75 if ( !RT_SUCCESS(RTLdrLoad(LIB_DBUS_1_3, &hLibDBus)) 76 && !RT_SUCCESS(RTLdrLoad(LIB_DBUS_1_2, &hLibDBus))) 65 77 { 66 78 return false; 67 79 } 68 if ( RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_error_init", (void **) &gDBusErrorInit)) 69 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_bus_get", (void **) &gDBusBusGet)) 70 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_error_free", (void **) &gDBusErrorFree)) 71 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_connection_unref", 72 (void **) &gDBusConnectionUnref)) 73 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_new", (void **) &gLibHalCtxNew)) 74 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_set_dbus_connection", 75 (void **) &gLibHalCtxSetDBusConnection)) 76 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_init", (void **) &gLibHalCtxInit)) 77 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_manager_find_device_string_match", 78 (void **) &gLibHalFindDeviceStringMatch)) 79 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_device_get_property_string", 80 (void **) &gLibHalDeviceGetPropertyString)) 81 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string", (void **) &gLibHalFreeString)) 82 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string_array", 83 (void **) &gLibHalFreeStringArray)) 84 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_shutdown", (void **) &gLibHalCtxShutdown)) 85 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_free", (void **) &gLibHalCtxFree)) 80 if ( RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_init", 81 (void **) &dbus_error_init)) 82 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get", 83 (void **) &dbus_bus_get)) 84 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_free", 85 (void **) &dbus_error_free)) 86 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_unref", 87 (void **) &dbus_connection_unref)) 88 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_set_exit_on_disconnect", 89 (void **) &dbus_connection_set_exit_on_disconnect)) 90 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_name_has_owner", 91 (void **) &dbus_bus_name_has_owner)) 92 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_add_match", 93 (void **) &dbus_bus_add_match)) 94 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_remove_match", 95 (void **) &dbus_bus_remove_match)) 96 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_unref", 97 (void **) &dbus_message_unref)) 98 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_new_method_call", 99 (void **) &dbus_message_new_method_call)) 100 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_init_append", 101 (void **) &dbus_message_iter_init_append)) 102 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_append_basic", 103 (void **) &dbus_message_iter_append_basic)) 104 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_send_with_reply_and_block", 105 (void **) &dbus_connection_send_with_reply_and_block)) 106 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_init", 107 (void **) &dbus_message_iter_init)) 108 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_get_arg_type", 109 (void **) &dbus_message_iter_get_arg_type)) 110 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_get_element_type", 111 (void **) &dbus_message_iter_get_element_type)) 112 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_recurse", 113 (void **) &dbus_message_iter_recurse)) 114 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_get_basic", 115 (void **) &dbus_message_iter_get_basic)) 116 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_iter_next", 117 (void **) &dbus_message_iter_next)) 86 118 ) 87 119 { 88 ghLib Hal = hLibHal;89 gCheckedForLib Hal= true;120 ghLibDBus = hLibDBus; 121 gCheckedForLibDBus = true; 90 122 return true; 91 123 } 92 124 else 93 125 { 94 RTLdrClose(hLib Hal);95 gCheckedForLib Hal= true;126 RTLdrClose(hLibDBus); 127 gCheckedForLibDBus = true; 96 128 return false; 97 129 } 98 130 } 131
Note:
See TracChangeset
for help on using the changeset viewer.