| 1890 | | # ifdef VBOX_USE_LIBHAL |
|---|
| | 1890 | # ifdef VBOX_WITH_LIBHAL /* Linux, load libhal statically */ |
|---|
| | 1891 | |
|---|
| | 1892 | /** Helper function for setting up a libhal context */ |
|---|
| | 1893 | bool 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 | */ |
|---|
| | 1938 | bool 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 | */ |
|---|
| | 2006 | bool 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 | |
|---|