Changeset 16528 in vbox for trunk/src/VBox/Main/linux
- Timestamp:
- Feb 5, 2009 2:53:27 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r16363 r16528 54 54 # include <errno.h> 55 55 #endif /* RT_OS_LINUX */ 56 #include <string> 57 #include <vector> 56 58 57 59 /******************************************************************************* … … 88 90 const char *pszKey, const char *pszValue, 89 91 RTMemAutoPtr <DBusMessage, VBoxDBusMessageUnref> *pMessage); 92 static int halFindDeviceStringMatchVector (DBusConnection *pConnection, 93 const char *pszKey, 94 const char *pszValue, 95 std::vector<std::string> *pMatches); 90 96 static int halGetPropertyStrings (DBusConnection *pConnection, 91 97 const char *pszUdi, size_t cKeys, 92 98 const char **papszKeys, char **papszValues, 93 99 RTMemAutoPtr <DBusMessage, VBoxDBusMessageUnref> *pMessage); 100 static int halGetPropertyStringsVector (DBusConnection *pConnection, 101 const char *pszUdi, size_t cProps, 102 const char **papszKeys, 103 std::vector<std::string> *pMatches, 104 bool *pfMatches, bool *pfSuccess); 94 105 static int getDriveInfoFromHal(DriveInfoList *pList, bool isDVD, 95 106 bool *pfSuccess); … … 128 139 // this is a good guess usually 129 140 if (validateDevice("/dev/cdrom", true)) 130 mDVDList.push_back (DriveInfo ("/dev/cdrom")); 141 try 142 { 143 mDVDList.push_back (DriveInfo ("/dev/cdrom")); 144 } 145 catch (std::bad_alloc) 146 { 147 rc = VERR_NO_MEMORY; 148 } 131 149 132 150 // check the mounted drives … … 178 196 sprintf(devName, "/dev/fd%d", i); 179 197 if (validateDevice(devName, false)) 180 mFloppyList.push_back (DriveInfo (devName)); 198 try 199 { 200 mFloppyList.push_back (DriveInfo (devName)); 201 } 202 catch (std::bad_alloc) 203 { 204 rc = VERR_NO_MEMORY; 205 } 181 206 } 182 207 } … … 431 456 if (validateDevice(pDrive, isDVD)) 432 457 { 433 pList->push_back (DriveInfo (pDrive)); 458 try 459 { 460 pList->push_back (DriveInfo (pDrive)); 461 } 462 catch (std::bad_alloc) 463 { 464 rc = VERR_NO_MEMORY; 465 } 434 466 success = true; 435 467 } … … 521 553 } 522 554 if (insert) 523 pList->push_back (DriveInfo (mnt_dev.get())); 555 try 556 { 557 pList->push_back (DriveInfo (mnt_dev.get())); 558 } 559 catch (std::bad_alloc) 560 { 561 rc = VERR_NO_MEMORY; 562 } 524 563 } 525 564 } … … 783 822 784 823 /** 824 * Find the UDIs of hal entries that contain Key=Value property and return the 825 * result on the end of a vector of std::string. 826 * @returns iprt status code. If a non-fatal error occurs, we return success 827 * but set *pfSuccess to false. 828 * @param pConnection an initialised connection DBus 829 * @param pszKey the property key 830 * @param pszValue the property value 831 * @param pMatches pointer to an array of std::string to append the 832 * results to. NOT optional. 833 * @param pfSuccess will be set to true if the operation succeeds 834 */ 835 /* static */ 836 int halFindDeviceStringMatchVector (DBusConnection *pConnection, 837 const char *pszKey, const char *pszValue, 838 std::vector<std::string> *pMatches, 839 bool *pfSuccess) 840 { 841 #if 0 842 AssertRequireReturn( VALID_PTR(pConnection) && VALID_PTR(pszKey) 843 && VALID_PTR(pszValue) && VALID_PTR (pMatches) 844 && (pfSuccess == NULL || VALID_PTR (pfSuccess)), 845 Valid pointers, VERR_INVALID_POINTER); 846 #endif 847 LogFlowFunc (("pConnection=%p, pszKey=%s, pszValue=%s, pMatches=%p, pfSuccess=%p\n", 848 pConnection, pszKey, pszValue, pMatches, pfSuccess)); 849 int rc = VINF_SUCCESS; /* We set this to failure on fatal errors. */ 850 bool halSuccess = true; /* We set this to false to abort the operation. */ 851 852 RTMemAutoPtr <DBusMessage, VBoxDBusMessageUnref> message, replyFind; 853 DBusMessageIter iterFind, iterUdis; 854 855 if (halSuccess && RT_SUCCESS (rc)) 856 { 857 rc = halFindDeviceStringMatch (pConnection, pszKey, pszValue, 858 &replyFind); 859 if (!replyFind) 860 halSuccess = false; 861 } 862 if (halSuccess && RT_SUCCESS (rc)) 863 { 864 dbus_message_iter_init (replyFind.get(), &iterFind); 865 if (dbus_message_iter_get_arg_type (&iterFind) != DBUS_TYPE_ARRAY) 866 halSuccess = false; 867 } 868 if (halSuccess && RT_SUCCESS (rc)) 869 dbus_message_iter_recurse (&iterFind, &iterUdis); 870 for (; halSuccess && RT_SUCCESS (rc) 871 && dbus_message_iter_get_arg_type (&iterUdis) == DBUS_TYPE_STRING; 872 dbus_message_iter_next(&iterUdis)) 873 { 874 /* Now get all properties from the iterator */ 875 const char *pszUdi; 876 dbus_message_iter_get_basic (&iterUdis, &pszUdi); 877 try 878 { 879 pMatches->push_back(pszUdi); 880 } 881 catch (std::bad_alloc) 882 { 883 rc = VERR_NO_MEMORY; 884 } 885 } 886 if (pfSuccess != NULL) 887 *pfSuccess = halSuccess; 888 LogFlow (("rc=%Rrc, halSuccess=%d\n", rc, halSuccess)); 889 return rc; 890 } 891 892 /** 785 893 * Read a set of string properties for a device. If some of the properties are 786 * not of type DBUS_TYPE_STRING then a NULL pointer will be returned for them. 894 * not of type DBUS_TYPE_STRING or do not exist then a NULL pointer will be 895 * returned for them. 787 896 * @returns iprt status code. If the operation failed for non-fatal reasons 788 897 * then we return success and leave pMessage untouched - reset it … … 878 987 879 988 /** 989 * Read a set of string properties for a device. If some properties do not 990 * exist or are not of type DBUS_TYPE_STRING, we will still fetch the others. 991 * @returns iprt status code. If the operation failed for non-fatal reasons 992 * then we return success and set *pfSuccess to false. 993 * @param pConnection an initialised connection DBus 994 * @param pszUdi the Udi of the device 995 * @param cProps the number of property values to look up 996 * @param papszKeys the keys of the properties to be looked up 997 * @param pMatches pointer to an empty array of std::string to append the 998 * results to. NOT optional. 999 * @param pfMatches pointer to an array of boolean values indicating 1000 * whether the respective property is a string. If this 1001 * is not supplied then all properties must be strings 1002 * for the operation to be considered successful 1003 * @param pfSuccess will be set to true if the operation succeeds 1004 */ 1005 /* static */ 1006 int halGetPropertyStringsVector (DBusConnection *pConnection, 1007 const char *pszUdi, size_t cProps, 1008 const char **papszKeys, 1009 std::vector<std::string> *pMatches, 1010 bool *pfMatches, bool *pfSuccess) 1011 { 1012 #if 0 1013 AssertRequireReturn( VALID_PTR (pConnection) && VALID_PTR (pszUdi) 1014 && VALID_PTR (papszKeys) && VALID_PTR (pMatches) 1015 && VALID_PTR (pfMatches) 1016 && (pfSuccess == NULL || VALID_PTR (pfSuccess)), 1017 Valid pointers, VERR_INVALID_POINTER); 1018 AssertRequireReturn(pMatches->empty()); 1019 #endif 1020 LogFlowFunc (("pConnection=%p, pszUdi=%s, cProps=%llu, papszKeys=%p, pMatches=%p, pfMatches=%p, pfSuccess=%p\n", 1021 pConnection, pszUdi, cProps, papszKeys, pMatches, pfMatches, pfSuccess)); 1022 RTMemAutoPtr <char *> values(cProps); 1023 RTMemAutoPtr <DBusMessage, VBoxDBusMessageUnref> message; 1024 bool halSuccess = true; 1025 int rc = halGetPropertyStrings (pConnection, pszUdi, cProps, papszKeys, 1026 values.get(), &message); 1027 if (!message) 1028 halSuccess = false; 1029 for (size_t i = 0; RT_SUCCESS(rc) && halSuccess && i < cProps; ++i) 1030 { 1031 bool fMatches = values[i] != NULL; 1032 if (pfMatches != NULL) 1033 pfMatches[i] = fMatches; 1034 else 1035 halSuccess = fMatches; 1036 try 1037 { 1038 pMatches->push_back(fMatches ? values[i] : ""); 1039 } 1040 catch (std::bad_alloc) 1041 { 1042 rc = VERR_NO_MEMORY; 1043 } 1044 } 1045 if (pfSuccess != NULL) 1046 *pfSuccess = halSuccess; 1047 #if 0 1048 if (RT_SUCCESS(rc) && halSuccess) 1049 { 1050 AssertEnsure (pMatches->size() == cProps, Right number of strings on success); 1051 AssertEnsureForEach (j, size_t, 0, cProps, 1052 (pfMatches == NULL) 1053 || (pfMatches[j] == true) 1054 || ((pfMatches[j] == false) && (pMatches[j].size() == 0)), 1055 On success invalid strings are empty); 1056 } 1057 #endif 1058 LogFlowFunc (("rc=%Rrc, halSuccess=%d\n", rc, halSuccess)); 1059 return rc; 1060 } 1061 1062 /** 880 1063 * Helper function to query the hal subsystem for information about drives 881 1064 * attached to the system. … … 943 1126 if ((pszProduct != NULL && pszProduct[0] != '\0')) 944 1127 description += pszProduct; 945 pList->push_back (DriveInfo (pszDevice, pszUdi, description)); 1128 try 1129 { 1130 pList->push_back (DriveInfo (pszDevice, pszUdi, description)); 1131 } 1132 catch (std::bad_alloc) 1133 { 1134 rc = VERR_NO_MEMORY; 1135 } 946 1136 } 947 1137 } … … 1021 1211 rc = getUSBInterfacesFromHal (&info.mInterfaces, pszUdi, &ifaceSuccess); 1022 1212 if (RT_SUCCESS(rc) && halSuccess && ifaceSuccess) 1023 pList->push_back (info); 1213 try 1214 { 1215 pList->push_back (info); 1216 } 1217 catch (std::bad_alloc) 1218 { 1219 rc = VERR_NO_MEMORY; 1220 } 1024 1221 } 1025 1222 } … … 1100 1297 &ifaceSuccess); 1101 1298 if (RT_SUCCESS(rc) && halSuccess && ifaceSuccess) 1102 pList->push_back (info); 1299 try 1300 { 1301 pList->push_back (info); 1302 } 1303 catch (std::bad_alloc) 1304 { 1305 rc = VERR_NO_MEMORY; 1306 } 1103 1307 } 1104 1308 } … … 1182 1386 && RTStrCmp (pszInfoSubsystem, "usb_device") != 0 /* Children of buses can also be devices. */ 1183 1387 && RTStrCmp (pszLinuxSubsystem, "usb_device") != 0) 1184 pList->push_back (pszSysfsPath); 1388 try 1389 { 1390 pList->push_back (pszSysfsPath); 1391 } 1392 catch (std::bad_alloc) 1393 { 1394 rc = VERR_NO_MEMORY; 1395 } 1185 1396 } 1186 1397 if (dbusError.HasName (DBUS_ERROR_NO_MEMORY))
Note:
See TracChangeset
for help on using the changeset viewer.