Changeset 2917 in vbox for trunk/src/VBox/Main
- Timestamp:
- May 29, 2007 2:17:19 PM (18 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostDVDDriveImpl.cpp
r1 r2917 52 52 } 53 53 54 /** 55 * Initializes the host object. 56 * 57 * @returns COM result indicator 58 * @param driveName name of the drive 59 * @param driveDescription human readable description of the drive 60 */ 61 HRESULT HostDVDDrive::init (INPTR BSTR driveName, INPTR BSTR driveDescription) 62 { 63 ComAssertRet (driveName, E_INVALIDARG); 64 ComAssertRet (driveDescription, E_INVALIDARG); 65 66 AutoLock lock(this); 67 mDriveName = driveName; 68 mDriveDescription = driveDescription; 69 setReady(true); 70 return S_OK; 71 } 72 54 73 // IHostDVDDrive properties 55 74 ///////////////////////////////////////////////////////////////////////////// … … 70 89 return S_OK; 71 90 } 91 92 /** 93 * Returns the description of the host drive 94 * 95 * @returns COM status code 96 * @param driveDescription address of result pointer 97 */ 98 STDMETHODIMP HostDVDDrive::COMGETTER(Description) (BSTR *driveDescription) 99 { 100 if (!driveDescription) 101 return E_POINTER; 102 AutoLock lock(this); 103 CHECK_READY(); 104 mDriveDescription.cloneTo(driveDescription); 105 return S_OK; 106 } -
trunk/src/VBox/Main/HostImpl.cpp
r2805 r2917 31 31 #define _LINUX_BYTEORDER_GENERIC_H 32 32 #include <linux/cdrom.h> 33 #ifdef VBOX_USE_LIBHAL 34 # include <libhal.h> 35 /* These are defined by libhal.h and by VBox header files. */ 36 # undef TRUE 37 # undef FALSE 38 #endif 33 39 #include <errno.h> 34 40 #endif /* __LINUX __ */ … … 190 196 delete[] hostDrives; 191 197 #elif defined(__LINUX__) 192 // On Linux, the situation is much more complex. There is no simple API so 193 // we will take a more creative approach. As there is only a heuristical 194 // approach on Linux, we'll allow the user to specify a list of host CDROMs 195 // using and an environment variable. 198 #ifdef VBOX_USE_LIBHAL 199 if (!getDVDInfoFromHal(list)) /* Playing with #defines in this way is nasty, I know. */ 200 #endif /* USE_LIBHAL defined */ 201 // On Linux without hal, the situation is much more complex. We will take a 202 // heuristical approach and also allow the user to specify a list of host 203 // CDROMs using an environment variable. 196 204 // The general strategy is to try some known device names and see of they 197 205 // exist. At last, we'll enumerate the /etc/fstab file (luckily there's an 198 206 // API to parse it) for CDROM devices. Ok, let's start! 199 207 200 if (getenv("VBOX_CDROM")) 201 { 202 char *cdromEnv = strdupa(getenv("VBOX_CDROM")); 203 char *cdromDrive; 204 cdromDrive = strtok(cdromEnv, ":"); 205 while (cdromDrive) 206 { 207 if (validateDevice(cdromDrive, true)) 208 { 209 if (getenv("VBOX_CDROM")) 210 { 211 char *cdromEnv = strdupa(getenv("VBOX_CDROM")); 212 char *cdromDrive; 213 cdromDrive = strtok(cdromEnv, ":"); 214 while (cdromDrive) 208 215 { 209 ComObjPtr <HostDVDDrive> hostDVDDriveObj; 210 hostDVDDriveObj.createObject(); 211 hostDVDDriveObj->init (Bstr (cdromDrive)); 212 list.push_back (hostDVDDriveObj); 216 if (validateDevice(cdromDrive, true)) 217 { 218 ComObjPtr <HostDVDDrive> hostDVDDriveObj; 219 hostDVDDriveObj.createObject(); 220 hostDVDDriveObj->init (Bstr (cdromDrive)); 221 list.push_back (hostDVDDriveObj); 222 } 223 cdromDrive = strtok(NULL, ":"); 213 224 } 214 cdromDrive = strtok(NULL, ":"); 215 } 216 } 217 else 218 { 219 // this is a good guess usually 220 if (validateDevice("/dev/cdrom", true)) 221 { 222 ComObjPtr <HostDVDDrive> hostDVDDriveObj; 223 hostDVDDriveObj.createObject(); 224 hostDVDDriveObj->init (Bstr ("/dev/cdrom")); 225 list.push_back (hostDVDDriveObj); 226 } 227 228 // check the mounted drives 229 parseMountTable((char*)"/etc/mtab", list); 230 231 // check the drives that can be mounted 232 parseMountTable((char*)"/etc/fstab", list); 225 } 226 else 227 { 228 // this is a good guess usually 229 if (validateDevice("/dev/cdrom", true)) 230 { 231 ComObjPtr <HostDVDDrive> hostDVDDriveObj; 232 hostDVDDriveObj.createObject(); 233 hostDVDDriveObj->init (Bstr ("/dev/cdrom")); 234 list.push_back (hostDVDDriveObj); 235 } 236 237 // check the mounted drives 238 parseMountTable((char*)"/etc/mtab", list); 239 240 // check the drives that can be mounted 241 parseMountTable((char*)"/etc/fstab", list); 242 } 233 243 } 234 244 #elif defined(__DARWIN__) … … 1380 1390 1381 1391 #ifdef __LINUX__ 1392 # ifdef VBOX_USE_LIBHAL 1393 /** 1394 * Helper function to query the hal subsystem for information about DVD drives attached to the 1395 * system. 1396 * 1397 * @returns true if at least one drive was found, false otherwise 1398 * @retval list drives found will be attached to this list 1399 */ 1400 bool Host::getDVDInfoFromHal(std::list <ComObjPtr <HostDVDDrive> > &list) 1401 { 1402 bool halSuccess = false; 1403 DBusError dbusError; 1404 dbus_error_init (&dbusError); 1405 DBusConnection *dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbusError); 1406 if (dbusConnection != 0) 1407 { 1408 LibHalContext *halContext = libhal_ctx_new(); 1409 if (halContext != 0) 1410 { 1411 if (libhal_ctx_set_dbus_connection (halContext, dbusConnection)) 1412 { 1413 if (libhal_ctx_init(halContext, &dbusError)) 1414 { 1415 int numDevices; 1416 char **halDevices = libhal_find_device_by_capability(halContext, 1417 "storage.cdrom", &numDevices, &dbusError); 1418 if (halDevices != 0) 1419 { 1420 for (int i = 0; i < numDevices; i++) 1421 { 1422 char *devNode = libhal_device_get_property_string(halContext, 1423 halDevices[i], "block.device", &dbusError); 1424 if (devNode != 0) 1425 { 1426 if (validateDevice(devNode, true)) 1427 { 1428 char description[256]; 1429 char *vendor, *product; 1430 /* We have at least one hit, so operation successful :) */ 1431 halSuccess = true; 1432 vendor = libhal_device_get_property_string(halContext, 1433 halDevices[i], "info.vendor", &dbusError); 1434 product = libhal_device_get_property_string(halContext, 1435 halDevices[i], "info.product", &dbusError); 1436 if ((product != 0)) 1437 { 1438 if (vendor != 0 && vendor[0] != 0) 1439 { 1440 RTStrPrintf(description, sizeof(description), 1441 "%s %s (%s)", vendor, product, devNode); 1442 } 1443 else 1444 { 1445 RTStrPrintf(description, sizeof(description), 1446 "%s (%s)", product, devNode); 1447 } 1448 ComObjPtr <HostDVDDrive> hostDVDDriveObj; 1449 hostDVDDriveObj.createObject(); 1450 hostDVDDriveObj->init (Bstr (devNode), Bstr (description)); 1451 list.push_back (hostDVDDriveObj); 1452 } 1453 else 1454 { 1455 ComObjPtr <HostDVDDrive> hostDVDDriveObj; 1456 hostDVDDriveObj.createObject(); 1457 hostDVDDriveObj->init (Bstr (devNode)); 1458 list.push_back (hostDVDDriveObj); 1459 } 1460 } 1461 else 1462 { 1463 LogRel(("Host::COMGETTER(DVDDrives): failed to validate the block device %s as a DVD drive\n")); 1464 } 1465 libhal_free_string(devNode); 1466 } 1467 else 1468 { 1469 LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n", 1470 halDevices[i], dbusError.name, dbusError.message)); 1471 dbus_error_free(&dbusError); 1472 } 1473 } 1474 libhal_free_string_array(halDevices); 1475 } 1476 else 1477 { 1478 LogRel(("Host::COMGETTER(DVDDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1479 dbus_error_free(&dbusError); 1480 } 1481 if (!libhal_ctx_shutdown(halContext, &dbusError)) /* what now? */ 1482 { 1483 LogRel(("Host::COMGETTER(DVDDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1484 dbus_error_free(&dbusError); 1485 } 1486 } 1487 else 1488 { 1489 LogRel(("Host::COMGETTER(DVDDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1490 dbus_error_free(&dbusError); 1491 } 1492 libhal_ctx_free(halContext); 1493 } 1494 else 1495 { 1496 LogRel(("Host::COMGETTER(DVDDrives): failed to set libhal connection to dbus.\n")); 1497 } 1498 } 1499 else 1500 { 1501 LogRel(("Host::COMGETTER(DVDDrives): failed to get a libhal context - out of memory?\n")); 1502 } 1503 dbus_connection_unref(dbusConnection); 1504 } 1505 else 1506 { 1507 LogRel(("Host::COMGETTER(DVDDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message)); 1508 dbus_error_free(&dbusError); 1509 } 1510 return halSuccess; 1511 } 1512 # endif /* VBOX_USE_HAL defined */ 1513 1382 1514 /** 1383 1515 * Helper function to parse the given mount file and add found entries -
trunk/src/VBox/Main/Makefile.kmk
r2754 r2917 153 153 $(PATH_LIB)/VBoxCOM$(VBOX_SUFF_LIB) 154 154 endif 155 ifdef VBOX_WITH_LIBHAL 156 VBoxSVC_CXXFLAGS += \ 157 $(LIB_HAL_CFLAGS) 158 VBoxSVC_LIBS += \ 159 $(LIB_HAL_LIBS) 160 VBoxSVC_DEFS += \ 161 VBOX_USE_LIBHAL 162 endif 163 155 164 VBoxSVC_SOURCES = \ 156 165 Logging.cpp \ -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r2674 r2917 3499 3499 <desc>Returns the platform device identifier.</desc> 3500 3500 </attribute> 3501 <attribute name="description" type="wstring" readonly="yes"> 3502 <desc>Returns a human readable description for the drive.</desc> 3503 </attribute> 3501 3504 3502 3505 </interface> -
trunk/src/VBox/Main/include/HostDVDDriveImpl.h
r1 r2917 50 50 // public initializer/uninitializer for internal purposes only 51 51 HRESULT init (INPTR BSTR driveName); 52 HRESULT init (INPTR BSTR driveName, INPTR BSTR driveDescription); 52 53 53 54 // IHostDVDDrive properties 54 55 STDMETHOD(COMGETTER(Name)) (BSTR *driveName); 56 STDMETHOD(COMGETTER(Description)) (BSTR *driveDescription); 55 57 56 58 // public methods for internal purposes only … … 64 66 65 67 Bstr mDriveName; 68 Bstr mDriveDescription; 66 69 }; 67 70 -
trunk/src/VBox/Main/include/HostImpl.h
r2333 r2917 131 131 132 132 #ifdef __LINUX__ 133 # ifdef VBOX_USE_LIBHAL 134 bool getDVDInfoFromHal(std::list <ComObjPtr <HostDVDDrive> > &list); 135 # endif 133 136 void parseMountTable(char *mountTable, std::list <ComObjPtr <HostDVDDrive> > &list); 134 137 bool validateDevice(const char *deviceNode, bool isCDROM);
Note:
See TracChangeset
for help on using the changeset viewer.