Changeset 15465 in vbox for trunk/src/VBox/Main/linux
- Timestamp:
- Dec 14, 2008 2:31:14 PM (16 years ago)
- Location:
- trunk/src/VBox/Main/linux
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r15401 r15465 73 73 static int getDVDInfoFromMTab(char *mountTable, DriveInfoList *pList); 74 74 #ifdef VBOX_WITH_DBUS 75 /* Th ismust be extern to be used in the RTMemAutoPtr template */75 /* These must be extern to be used in the RTMemAutoPtr template */ 76 76 extern void halShutdown (DBusConnection *pConnection); 77 extern void halShutdownPrivate (DBusConnection *pConnection); 77 78 78 79 static int halInit(RTMemAutoPtr <DBusConnection, halShutdown> *pConnection); 80 static int halInitPrivate(RTMemAutoPtr <DBusConnection, halShutdownPrivate> *pConnection); 79 81 static int halFindDeviceStringMatch (DBusConnection *pConnection, 80 82 const char *pszKey, const char *pszValue, … … 222 224 #if defined RT_OS_LINUX && defined VBOX_WITH_DBUS 223 225 /** The connection to DBus */ 224 RTMemAutoPtr <DBusConnection, halShutdown > mConnection;226 RTMemAutoPtr <DBusConnection, halShutdownPrivate> mConnection; 225 227 /** Semaphore which is set when a device is hotplugged and reset when 226 228 * it is read. */ … … 237 239 int rc = VINF_SUCCESS; 238 240 239 mContext = new Context; 240 for (unsigned i = 0; RT_SUCCESS(rc) && i < 5 && !mContext->mConnection; ++i) 241 { 242 rc = halInit (&mContext->mConnection); 243 } 244 if (!mContext->mConnection) 245 rc = VERR_NOT_SUPPORTED; 246 if ( RT_SUCCESS (rc) 247 && !dbus_connection_add_filter (mContext->mConnection.get(), 248 dbusFilterFunction, 249 &mContext->mTriggered, NULL)) 250 rc = VERR_NO_MEMORY; 251 if (RT_FAILURE (rc)) 252 mContext->mConnection.reset(); 241 if (VBoxDBusCheckPresence()) 242 { 243 mContext = new Context; 244 for (unsigned i = 0; RT_SUCCESS(rc) && i < 5 && !mContext->mConnection; ++i) 245 { 246 rc = halInitPrivate (&mContext->mConnection); 247 } 248 if (!mContext->mConnection) 249 rc = VERR_NOT_SUPPORTED; 250 DBusMessage *pMessage; 251 while ( RT_SUCCESS (rc) 252 && (pMessage = dbus_connection_pop_message (mContext->mConnection.get())) != NULL) 253 dbus_message_unref (pMessage); /* empty the message queue. */ 254 if ( RT_SUCCESS (rc) 255 && !dbus_connection_add_filter (mContext->mConnection.get(), 256 dbusFilterFunction, 257 &mContext->mTriggered, NULL)) 258 rc = VERR_NO_MEMORY; 259 if (RT_FAILURE (rc)) 260 mContext->mConnection.reset(); 261 } 253 262 #endif /* defined RT_OS_LINUX && defined VBOX_WITH_DBUS */ 254 263 } … … 265 274 } 266 275 267 /** 268 * Wait for a hotplug event. 269 * 270 * @returns VINF_SUCCESS if an event occurred or if Exit() was called. 271 * @returns VERR_TRY_AGAIN if something failed at the DBus level. 272 * @returns VERR_NOT_SUPPORTED if the service could not be contacted. 273 * @returns Possibly other iprt status codes otherwise. 274 */ 275 int VBoxMainHotplugWaiter::Wait() 276 int VBoxMainHotplugWaiter::Wait(unsigned cMillies) 276 277 { 277 278 int rc = VINF_SUCCESS; … … 282 283 mContext->mTriggered = false; 283 284 mContext->mInterrupt = false; 285 unsigned cRealMillies; 286 if (cMillies != RT_INDEFINITE_WAIT) 287 cRealMillies = cMillies; 288 else 289 cRealMillies = DBUS_POLL_TIMEOUT; 284 290 while ( RT_SUCCESS (rc) && connected && !mContext->mTriggered 285 291 && !mContext->mInterrupt) 292 { 286 293 connected = dbus_connection_read_write_dispatch (mContext->mConnection.get(), 287 DBUS_POLL_TIMEOUT); 294 cRealMillies); 295 if (cMillies != RT_INDEFINITE_WAIT) 296 mContext->mInterrupt = true; 297 } 288 298 if (!connected) 289 299 rc = VERR_TRY_AGAIN; … … 584 594 585 595 /** 596 * Helper function for setting up a private connection to hal 597 * @returns iprt status code 598 * @param pConnection where to store the connection handle 599 */ 600 /* static */ 601 int halInitPrivate (RTMemAutoPtr <DBusConnection, halShutdownPrivate> *pConnection) 602 { 603 AssertReturn(VALID_PTR (pConnection), VERR_INVALID_POINTER); 604 LogFlowFunc (("pConnection=%p\n", pConnection)); 605 int rc = VINF_SUCCESS; 606 bool halSuccess = true; 607 autoDBusError dbusError; 608 609 RTMemAutoPtr <DBusConnection, VBoxDBusConnectionUnref> dbusConnection; 610 dbusConnection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &dbusError.get()); 611 if (!dbusConnection) 612 halSuccess = false; 613 if (halSuccess) 614 { 615 dbus_connection_set_exit_on_disconnect (dbusConnection.get(), false); 616 halSuccess = dbus_bus_name_has_owner (dbusConnection.get(), 617 "org.freedesktop.Hal", &dbusError.get()); 618 } 619 if (halSuccess) 620 { 621 dbus_bus_add_match (dbusConnection.get(), 622 "type='signal'," 623 "interface='org.freedesktop.Hal.Manager'," 624 "sender='org.freedesktop.Hal'," 625 "path='/org/freedesktop/Hal/Manager'", 626 &dbusError.get()); 627 halSuccess = !dbusError.IsSet(); 628 } 629 if (dbusError.HasName (DBUS_ERROR_NO_MEMORY)) 630 rc = VERR_NO_MEMORY; 631 if (halSuccess) 632 *pConnection = dbusConnection.release(); 633 LogFlowFunc(("rc=%Rrc, (*pConnection).get()=%p\n", rc, (*pConnection).get())); 634 dbusError.FlowLog(); 635 return rc; 636 } 637 638 /** 586 639 * Helper function for shutting down a connection to hal 587 640 * @param pConnection the connection handle … … 600 653 "path='/org/freedesktop/Hal/Manager'", 601 654 &dbusError.get()); 655 dbus_connection_unref (pConnection); 656 LogFlowFunc(("returning\n")); 657 dbusError.FlowLog(); 658 } 659 660 /** 661 * Helper function for shutting down a connection to hal 662 * @param pConnection the connection handle 663 */ 664 /* static */ 665 void halShutdownPrivate (DBusConnection *pConnection) 666 { 667 AssertReturnVoid(VALID_PTR (pConnection)); 668 LogFlowFunc (("pConnection=%p\n", pConnection)); 669 autoDBusError dbusError; 670 671 dbus_bus_remove_match (pConnection, 672 "type='signal'," 673 "interface='org.freedesktop.Hal.Manager'," 674 "sender='org.freedesktop.Hal'," 675 "path='/org/freedesktop/Hal/Manager'", 676 &dbusError.get()); 677 dbus_connection_close (pConnection); 602 678 dbus_connection_unref (pConnection); 603 679 LogFlowFunc(("returning\n")); -
trunk/src/VBox/Main/linux/vbox-dbus.cpp
r15401 r15465 42 42 void (*dbus_error_init)(DBusError *); 43 43 DBusConnection *(*dbus_bus_get)(DBusBusType, DBusError *); 44 DBusConnection *(*dbus_bus_get_private)(DBusBusType, DBusError *); 44 45 void (*dbus_error_free)(DBusError *); 45 46 void (*dbus_connection_unref)(DBusConnection *); 47 void (*dbus_connection_close)(DBusConnection *); 46 48 void (*dbus_connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t); 47 49 dbus_bool_t (*dbus_bus_name_has_owner)(DBusConnection *, const char *, … … 70 72 dbus_bool_t (*dbus_connection_read_write_dispatch) (DBusConnection *, int); 71 73 dbus_bool_t (*dbus_message_is_signal) (DBusMessage *, const char *, const char *); 74 DBusMessage *(*dbus_connection_pop_message)(DBusConnection *); 72 75 73 76 bool VBoxDBusCheckPresence(void) … … 88 91 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get", 89 92 (void **) &dbus_bus_get)) 93 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get_private", 94 (void **) &dbus_bus_get_private)) 90 95 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_free", 91 96 (void **) &dbus_error_free)) 92 97 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_unref", 93 98 (void **) &dbus_connection_unref)) 99 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_close", 100 (void **) &dbus_connection_close)) 94 101 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_set_exit_on_disconnect", 95 102 (void **) &dbus_connection_set_exit_on_disconnect)) … … 130 137 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_is_signal", 131 138 (void **) &dbus_message_is_signal)) 139 && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_pop_message", 140 (void **) &dbus_connection_pop_message)) 132 141 ) 133 142 {
Note:
See TracChangeset
for help on using the changeset viewer.