VirtualBox

Changeset 14722 in vbox


Ignore:
Timestamp:
Nov 27, 2008 5:11:36 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
40035
Message:

Main: use statically linked libhal on Linux

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/HostImpl.cpp

    r14715 r14722  
    3535# define _LINUX_BYTEORDER_GENERIC_H
    3636# include <linux/cdrom.h>
    37 # ifdef VBOX_USE_LIBHAL
    38 // # include <libhal.h>
    39 // /* These are defined by libhal.h and by VBox header files. */
    40 // # undef TRUE
    41 // # undef FALSE
    42 #  include "vbox-libhal.h"
     37# ifdef VBOX_WITH_LIBHAL
     38#  include <libhal.h>
     39/* These are defined by libhal.h and by VBox header files. */
     40#  undef TRUE
     41#  undef FALSE
    4342# endif
    4443# include <errno.h>
     
    6867# include <sys/mnttab.h>
    6968# include <sys/mntent.h>
     69/* Dynamic loading of libhal on Solaris hosts */
    7070# ifdef VBOX_USE_LIBHAL
    7171#  include "vbox-libhal.h"
     
    360360
    361361#elif defined(RT_OS_LINUX)
    362 #ifdef VBOX_USE_LIBHAL
     362#ifdef VBOX_WITH_LIBHAL
    363363    if (!getDVDInfoFromHal(list)) /* Playing with #defines in this way is nasty, I know. */
    364 #endif /* USE_LIBHAL defined */
     364#endif /* VBOX_WITH_LIBHAL defined */
    365365    // On Linux without hal, the situation is much more complex. We will take a
    366366    // heuristical approach and also allow the user to specify a list of host
     
    468468    delete[] hostDrives;
    469469#elif defined(RT_OS_LINUX)
    470 #ifdef VBOX_USE_LIBHAL
     470#ifdef VBOX_WITH_LIBHAL
    471471    if (!getFloppyInfoFromHal(list)) /* Playing with #defines in this way is nasty, I know. */
    472 #endif /* USE_LIBHAL defined */
     472#endif /* VBOX_WITH_LIBHAL defined */
    473473    // As with the CDROMs, on Linux we have to take a multi-level approach
    474474    // involving parsing the mount tables. As this is not bulletproof, we'll
     
    18881888
    18891889#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
    1890 # ifdef VBOX_USE_LIBHAL
     1890# ifdef VBOX_WITH_LIBHAL  /* Linux, load libhal statically */
     1891
     1892/** Helper function for setting up a libhal context */
     1893bool hostInitLibHal(DBusConnection **pDBusConnection,
     1894                    LibHalContext **pLibHalContext)
     1895{
     1896    bool halSuccess = true;
     1897    DBusError dbusError;
     1898
     1899    dbus_error_init (&dbusError);
     1900    DBusConnection *dbusConnection;
     1901    LibHalContext *libhalContext;
     1902    dbusConnection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbusError);
     1903    if (dbusConnection == NULL)
     1904        halSuccess = false;
     1905    if (dbusConnection == NULL && !dbus_error_is_set (&dbusError))
     1906        LogRelFunc (("Unresolved error getting DBus connection.\n"));
     1907    if (halSuccess)
     1908    {
     1909        libhalContext = libhal_ctx_new();
     1910        if (libhalContext == NULL)
     1911            halSuccess = false;
     1912    }
     1913    if (   halSuccess
     1914        && !libhal_ctx_set_dbus_connection (libhalContext, dbusConnection))
     1915        halSuccess = false;
     1916    if (   halSuccess
     1917        && !libhal_ctx_init (libhalContext, &dbusError))
     1918    {
     1919        halSuccess = false;
     1920        if (!dbus_error_is_set (&dbusError))
     1921            LogRelFunc (("Unresolved error initialising the libhal context.\n"));
     1922    }
     1923    if (halSuccess)
     1924    {
     1925        *pDBusConnection = dbusConnection;
     1926        *pLibHalContext = libhalContext;
     1927    }
     1928    return halSuccess;
     1929}
     1930
     1931/**
     1932 * Helper function to query the hal subsystem for information about DVD drives attached to the
     1933 * system.
     1934 *
     1935 * @returns true if information was successfully obtained, false otherwise
     1936 * @retval  list drives found will be attached to this list
     1937 */
     1938bool Host::getDVDInfoFromHal(std::list <ComObjPtr <HostDVDDrive> > &list)
     1939{
     1940    DBusConnection *dbusConnection;
     1941    LibHalContext *libhalContext;
     1942    int numDevices = 0;
     1943    char **halDevices = NULL;
     1944    bool halSuccess = hostInitLibHal (&dbusConnection, &libhalContext);
     1945    if (halSuccess)
     1946        halDevices = libhal_manager_find_device_string_match(libhalContext,
     1947                                                "storage.drive_type", "cdrom",
     1948                                                &numDevices, NULL);
     1949    /* Hal is installed and working, so if no devices are reported, assume
     1950       that there are none. */
     1951    for (int i = 0; halSuccess && i < numDevices; ++i)
     1952    {
     1953        char *devNode = libhal_device_get_property_string(libhalContext,
     1954                                halDevices[i], "block.device", NULL);
     1955        Utf8Str description;
     1956        char *vendor = NULL, *product = NULL;
     1957        if (devNode != NULL)
     1958        {
     1959            vendor = libhal_device_get_property_string(libhalContext,
     1960                            halDevices[i], "info.vendor", NULL);
     1961            product =  libhal_device_get_property_string(libhalContext,
     1962                            halDevices[i], "info.product", NULL);
     1963            if ((product != 0 && product[0] != 0))
     1964            {
     1965                if ((vendor != 0) && (vendor[0] != 0))
     1966                    description = Utf8StrFmt ("%s %s",
     1967                                              vendor, product);
     1968                else
     1969                    description = product;
     1970            }
     1971            ComObjPtr <HostDVDDrive> hostDVDDriveObj;
     1972            hostDVDDriveObj.createObject();
     1973            if (!description.isNull ())
     1974                hostDVDDriveObj->init (Bstr (devNode),
     1975                                       Bstr (halDevices[i]),
     1976                                       Bstr (description));
     1977            else
     1978                hostDVDDriveObj->init (Bstr (devNode),
     1979                                       Bstr (halDevices[i]));
     1980            list.push_back (hostDVDDriveObj);
     1981            if (vendor != NULL)
     1982                libhal_free_string(vendor);
     1983            if (product != NULL)
     1984                libhal_free_string(product);
     1985            libhal_free_string(devNode);
     1986        }
     1987    }
     1988    if (halDevices != NULL)
     1989        libhal_free_string_array(halDevices);
     1990    if (halSuccess)
     1991        libhal_ctx_shutdown (libhalContext, NULL);
     1992    if (libhalContext != NULL)
     1993        libhal_ctx_free (libhalContext);
     1994    if (dbusConnection != NULL)
     1995        dbus_connection_unref (dbusConnection);
     1996    return halSuccess;
     1997}
     1998
     1999/**
     2000 * Helper function to query the hal subsystem for information about floppy drives attached to the
     2001 * system.
     2002 *
     2003 * @returns true if information was successfully obtained, false otherwise
     2004 * @retval  list drives found will be attached to this list
     2005 */
     2006bool Host::getFloppyInfoFromHal(std::list <ComObjPtr <HostFloppyDrive> > &list)
     2007{
     2008    DBusConnection *dbusConnection;
     2009    LibHalContext *libhalContext;
     2010    int numDevices = 0;
     2011    char **halDevices = NULL;
     2012    bool halSuccess = hostInitLibHal (&dbusConnection, &libhalContext);
     2013    if (halSuccess)
     2014        halDevices = libhal_manager_find_device_string_match(libhalContext,
     2015                                                "storage.drive_type", "floppy",
     2016                                                &numDevices, NULL);
     2017    /* Hal is installed and working, so if no devices are reported, assume
     2018       that there are none. */
     2019    for (int i = 0; halSuccess && i < numDevices; ++i)
     2020    {
     2021        char *devNode = libhal_device_get_property_string(libhalContext,
     2022                                halDevices[i], "block.device", NULL);
     2023        Utf8Str description;
     2024        char *vendor = NULL, *product = NULL;
     2025        if (devNode != NULL)
     2026        {
     2027            vendor = libhal_device_get_property_string(libhalContext,
     2028                            halDevices[i], "info.vendor", NULL);
     2029            product =  libhal_device_get_property_string(libhalContext,
     2030                            halDevices[i], "info.product", NULL);
     2031            if ((product != 0 && product[0] != 0))
     2032            {
     2033                if ((vendor != 0) && (vendor[0] != 0))
     2034                    description = Utf8StrFmt ("%s %s",
     2035                                              vendor, product);
     2036                else
     2037                    description = product;
     2038            }
     2039            ComObjPtr <HostFloppyDrive> hostFloppyDriveObj;
     2040            hostFloppyDriveObj.createObject();
     2041            if (!description.isNull ())
     2042                hostFloppyDriveObj->init (Bstr (devNode),
     2043                                          Bstr (halDevices[i]),
     2044                                          Bstr (description));
     2045            else
     2046                hostFloppyDriveObj->init (Bstr (devNode),
     2047                                          Bstr (halDevices[i]));
     2048            list.push_back (hostFloppyDriveObj);
     2049            if (vendor != NULL)
     2050                libhal_free_string(vendor);
     2051            if (product != NULL)
     2052                libhal_free_string(product);
     2053            libhal_free_string(devNode);
     2054        }
     2055    }
     2056    if (halDevices != NULL)
     2057        libhal_free_string_array(halDevices);
     2058    if (halSuccess)
     2059        libhal_ctx_shutdown (libhalContext, NULL);
     2060    if (libhalContext != NULL)
     2061        libhal_ctx_free (libhalContext);
     2062    if (dbusConnection != NULL)
     2063        dbus_connection_unref (dbusConnection);
     2064    return halSuccess;
     2065}
     2066
     2067# elif defined VBOX_USE_LIBHAL  /* Solaris hosts, loading libhal at runtime */
     2068
    18912069/**
    18922070 * Helper function to query the hal subsystem for information about DVD drives attached to the
  • trunk/src/VBox/Main/Makefile.kmk

    r14714 r14722  
    198198        $(if $(VBOX_WITH_RESOURCE_USAGE_API),VBOX_WITH_RESOURCE_USAGE_API,) \
    199199        $(if $(VBOX_WITH_PDM_ASYNC_COMPLETION),VBOX_WITH_PDM_ASYNC_COMPLETION,) \
     200        $(if $(VBOX_WITH_LIBHAL),VBOX_WITH_LIBHAL,) \
    200201        $(if $(VBOX_USB_WITH_SYSFS),VBOX_USB_WITH_SYSFS,)
    201202
     
    301302        win/VBoxSVC.rc
    302303
    303 VBoxSVC_SOURCES.linux = \
    304         linux/vbox-libhal.cpp
    305 
    306304VBoxSVC_SOURCES.solaris = \
    307305        linux/vbox-libhal.cpp \
  • trunk/src/VBox/Main/include/HostImpl.h

    r14524 r14722  
    133133
    134134#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
    135 # ifdef VBOX_USE_LIBHAL
     135# if defined(VBOX_WITH_LIBHAL) || defined(VBOX_USE_LIBHAL)
    136136    bool getDVDInfoFromHal(std::list <ComObjPtr <HostDVDDrive> > &list);
    137137    bool getFloppyInfoFromHal(std::list <ComObjPtr <HostFloppyDrive> > &list);
Note: See TracChangeset for help on using the changeset viewer.

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