VirtualBox

Changeset 15465 in vbox for trunk/src/VBox/Main/linux


Ignore:
Timestamp:
Dec 14, 2008 2:31:14 PM (16 years ago)
Author:
vboxsync
Message:

Main and Devices, USB: use hal, DBus and sysfs on Linux if usbfs is not available. Currently disabled

Location:
trunk/src/VBox/Main/linux
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/linux/HostHardwareLinux.cpp

    r15401 r15465  
    7373static int getDVDInfoFromMTab(char *mountTable, DriveInfoList *pList);
    7474#ifdef VBOX_WITH_DBUS
    75 /* This must be extern to be used in the RTMemAutoPtr template */
     75/* These must be extern to be used in the RTMemAutoPtr template */
    7676extern void halShutdown (DBusConnection *pConnection);
     77extern void halShutdownPrivate (DBusConnection *pConnection);
    7778
    7879static int halInit(RTMemAutoPtr <DBusConnection, halShutdown> *pConnection);
     80static int halInitPrivate(RTMemAutoPtr <DBusConnection, halShutdownPrivate> *pConnection);
    7981static int halFindDeviceStringMatch (DBusConnection *pConnection,
    8082                                     const char *pszKey, const char *pszValue,
     
    222224#if defined RT_OS_LINUX && defined VBOX_WITH_DBUS
    223225    /** The connection to DBus */
    224     RTMemAutoPtr <DBusConnection, halShutdown> mConnection;
     226    RTMemAutoPtr <DBusConnection, halShutdownPrivate> mConnection;
    225227    /** Semaphore which is set when a device is hotplugged and reset when
    226228     * it is read. */
     
    237239    int rc = VINF_SUCCESS;
    238240
    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    }
    253262#endif /* defined RT_OS_LINUX && defined VBOX_WITH_DBUS */
    254263}
     
    265274}
    266275
    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()
     276int VBoxMainHotplugWaiter::Wait(unsigned cMillies)
    276277{
    277278    int rc = VINF_SUCCESS;
     
    282283    mContext->mTriggered = false;
    283284    mContext->mInterrupt = false;
     285    unsigned cRealMillies;
     286    if (cMillies != RT_INDEFINITE_WAIT)
     287        cRealMillies = cMillies;
     288    else
     289        cRealMillies = DBUS_POLL_TIMEOUT;
    284290    while (   RT_SUCCESS (rc) && connected && !mContext->mTriggered
    285291           && !mContext->mInterrupt)
     292    {
    286293        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    }
    288298    if (!connected)
    289299        rc = VERR_TRY_AGAIN;
     
    584594
    585595/**
     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 */
     601int 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/**
    586639 * Helper function for shutting down a connection to hal
    587640 * @param   pConnection  the connection handle
     
    600653                           "path='/org/freedesktop/Hal/Manager'",
    601654                           &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 */
     665void 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);
    602678    dbus_connection_unref (pConnection);
    603679    LogFlowFunc(("returning\n"));
  • trunk/src/VBox/Main/linux/vbox-dbus.cpp

    r15401 r15465  
    4242void (*dbus_error_init)(DBusError *);
    4343DBusConnection *(*dbus_bus_get)(DBusBusType, DBusError *);
     44DBusConnection *(*dbus_bus_get_private)(DBusBusType, DBusError *);
    4445void (*dbus_error_free)(DBusError *);
    4546void (*dbus_connection_unref)(DBusConnection *);
     47void (*dbus_connection_close)(DBusConnection *);
    4648void (*dbus_connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
    4749dbus_bool_t (*dbus_bus_name_has_owner)(DBusConnection *, const char *,
     
    7072dbus_bool_t (*dbus_connection_read_write_dispatch) (DBusConnection *, int);
    7173dbus_bool_t (*dbus_message_is_signal) (DBusMessage *, const char *, const char *);
     74DBusMessage *(*dbus_connection_pop_message)(DBusConnection *);
    7275
    7376bool VBoxDBusCheckPresence(void)
     
    8891        && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get",
    8992                                     (void **) &dbus_bus_get))
     93        && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_bus_get_private",
     94                                     (void **) &dbus_bus_get_private))
    9095        && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_error_free",
    9196                                     (void **) &dbus_error_free))
    9297        && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_unref",
    9398                                     (void **) &dbus_connection_unref))
     99        && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_close",
     100                                     (void **) &dbus_connection_close))
    94101        && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_set_exit_on_disconnect",
    95102                                     (void **) &dbus_connection_set_exit_on_disconnect))
     
    130137        && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_message_is_signal",
    131138                                     (void **) &dbus_message_is_signal))
     139        && RT_SUCCESS(RTLdrGetSymbol(hLibDBus, "dbus_connection_pop_message",
     140                                     (void **) &dbus_connection_pop_message))
    132141       )
    133142    {
Note: See TracChangeset for help on using the changeset viewer.

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