Changeset 10893 in vbox
- Timestamp:
- Jul 25, 2008 3:19:25 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/darwin/iokit.cpp
r8579 r10893 29 29 *******************************************************************************/ 30 30 #define LOG_GROUP LOG_GROUP_MAIN 31 #ifdef STANDALONE_TESTCASE 32 # define VBOX_WITH_USB 33 #endif 31 34 32 35 #include <mach/mach.h> … … 48 51 #include <iprt/assert.h> 49 52 #include <iprt/thread.h> 53 #ifdef STANDALONE_TESTCASE 54 # include <iprt/initterm.h> 55 # include <iprt/stream.h> 56 #endif 50 57 51 58 #include "iokit.h" 59 60 /* A small hack... */ 61 #ifdef STANDALONE_TESTCASE 62 # define DarwinFreeUSBDeviceFromIOKit(a) do { } while (0) 63 #endif 52 64 53 65 … … 222 234 223 235 224 #if 1 /* dumping disabled */236 #if 1 && !defined(STANDALONE_TESTCASE) /* dumping disabled */ 225 237 # define DARWIN_IOKIT_LOG(a) Log(a) 226 238 # define DARWIN_IOKIT_LOG_FLUSH() do {} while (0) 227 239 # define DARWIN_IOKIT_DUMP_OBJ(o) do {} while (0) 228 240 #else 229 # if 0241 # if defined(STANDALONE_TESTCASE) 230 242 # include <iprt/stream.h> 231 # define DARWIN_IOKIT_LOG(a) RTPrintf a232 # define DARWIN_IOKIT_LOG_FLUSH() RTStrmFlush(g_pStdOut)243 # define DARWIN_IOKIT_LOG(a) RTPrintf a 244 # define DARWIN_IOKIT_LOG_FLUSH() RTStrmFlush(g_pStdOut) 233 245 # else 234 # define DARWIN_IOKIT_LOG(a) RTLogPrintf a235 # define DARWIN_IOKIT_LOG(a) RTLogFlush()246 # define DARWIN_IOKIT_LOG(a) RTLogPrintf a 247 # define DARWIN_IOKIT_LOG(a) RTLogFlush() 236 248 # endif 237 # define DARWIN_IOKIT_DUMP_OBJ(o) 249 # define DARWIN_IOKIT_DUMP_OBJ(o) darwinDumpObj(o) 238 250 239 251 /** … … 388 400 } 389 401 390 #endif 402 #endif /* helpers for dumping registry dictionaries */ 391 403 392 404 … … 804 816 while ((USBDevice = IOIteratorNext(USBDevices)) != 0) 805 817 { 806 //DARWIN_IOKIT_DUMP_OBJ(USBDevice);818 DARWIN_IOKIT_DUMP_OBJ(USBDevice); 807 819 808 820 /* … … 1193 1205 while ((DVDService = IOIteratorNext(DVDServices)) != 0) 1194 1206 { 1207 DARWIN_IOKIT_DUMP_OBJ(DVDService); 1208 1195 1209 /* 1196 1210 * Get the properties we use to identify the DVD drive. … … 1282 1296 } 1283 1297 1298 1299 /** 1300 * Enumerate the ethernet capable network devices returning a FIFO of them. 1301 * 1302 * @returns Pointer to the head. 1303 */ 1304 void *DarwinGetNetworkControllers(void) 1305 { 1306 /* 1307 * Create a matching dictionary for searching for ethernet controller 1308 * services in the IOKit. 1309 */ 1310 CFMutableDictionaryRef RefMatchingDict = IOServiceMatching("IOEthernetController"); 1311 AssertReturn(RefMatchingDict, NULL); 1312 1313 /* 1314 * Perform the search and get a collection of ethernet controller services. 1315 */ 1316 io_iterator_t EthNICServices = NULL; 1317 IOReturn rc = IOServiceGetMatchingServices(g_MasterPort, RefMatchingDict, &EthNICServices); 1318 AssertMsgReturn(rc == kIOReturnSuccess, ("rc=%d\n", rc), NULL); 1319 RefMatchingDict = NULL; /* the reference is consumed by IOServiceGetMatchingServices. */ 1320 1321 /* 1322 * Enumerate the ethernet controller services. 1323 */ 1324 // PDARWINDVD pHead = NULL; 1325 // PDARWINDVD pTail = NULL; 1326 unsigned i = 0; 1327 io_object_t EthNICService; 1328 while ((EthNICService = IOIteratorNext(EthNICServices)) != 0) 1329 { 1330 DARWIN_IOKIT_DUMP_OBJ(EthNICService); 1331 #if 0 1332 /* 1333 * Get the properties we use to identify the DVD drive. 1334 * 1335 * While there is a (weird 12 byte) GUID, it isn't persistent 1336 * accross boots. So, we have to use a combination of the 1337 * vendor name and product name properties with an optional 1338 * sequence number for identification. 1339 */ 1340 CFMutableDictionaryRef PropsRef = 0; 1341 kern_return_t krc = IORegistryEntryCreateCFProperties(EthNICService, &PropsRef, kCFAllocatorDefault, kNilOptions); 1342 if (krc == KERN_SUCCESS) 1343 { 1344 /* Get the Device Characteristics dictionary. */ 1345 CFDictionaryRef DevCharRef = (CFDictionaryRef)CFDictionaryGetValue(PropsRef, CFSTR(kIOPropertyDeviceCharacteristicsKey)); 1346 if (DevCharRef) 1347 { 1348 /* The vendor name. */ 1349 char szVendor[128]; 1350 char *pszVendor = &szVendor[0]; 1351 CFTypeRef ValueRef = CFDictionaryGetValue(DevCharRef, CFSTR(kIOPropertyVendorNameKey)); 1352 if ( ValueRef 1353 && CFGetTypeID(ValueRef) == CFStringGetTypeID() 1354 && CFStringGetCString((CFStringRef)ValueRef, szVendor, sizeof(szVendor), kCFStringEncodingUTF8)) 1355 pszVendor = RTStrStrip(szVendor); 1356 else 1357 *pszVendor = '\0'; 1358 1359 /* The product name. */ 1360 char szProduct[128]; 1361 char *pszProduct = &szProduct[0]; 1362 ValueRef = CFDictionaryGetValue(DevCharRef, CFSTR(kIOPropertyProductNameKey)); 1363 if ( ValueRef 1364 && CFGetTypeID(ValueRef) == CFStringGetTypeID() 1365 && CFStringGetCString((CFStringRef)ValueRef, szProduct, sizeof(szProduct), kCFStringEncodingUTF8)) 1366 pszProduct = RTStrStrip(szProduct); 1367 else 1368 *pszProduct = '\0'; 1369 1370 /* Construct the name and check for duplicates. */ 1371 char szName[256 + 32]; 1372 if (*pszVendor || *pszProduct) 1373 { 1374 if (*pszVendor && *pszProduct) 1375 RTStrPrintf(szName, sizeof(szName), "%s %s", pszVendor, pszProduct); 1376 else 1377 strcpy(szName, *pszVendor ? pszVendor : pszProduct); 1378 1379 for (PDARWINDVD pCur = pHead; pCur; pCur = pCur->pNext) 1380 { 1381 if (!strcmp(szName, pCur->szName)) 1382 { 1383 if (*pszVendor && *pszProduct) 1384 RTStrPrintf(szName, sizeof(szName), "%s %s (#%u)", pszVendor, pszProduct, i); 1385 else 1386 RTStrPrintf(szName, sizeof(szName), "%s %s (#%u)", *pszVendor ? pszVendor : pszProduct, i); 1387 break; 1388 } 1389 } 1390 } 1391 else 1392 RTStrPrintf(szName, sizeof(szName), "(#%u)", i); 1393 1394 /* Create the device. */ 1395 size_t cbName = strlen(szName) + 1; 1396 PDARWINDVD pNew = (PDARWINDVD)RTMemAlloc(RT_OFFSETOF(DARWINDVD, szName[cbName])); 1397 if (pNew) 1398 { 1399 pNew->pNext = NULL; 1400 memcpy(pNew->szName, szName, cbName); 1401 if (pTail) 1402 pTail = pTail->pNext = pNew; 1403 else 1404 pTail = pHead = pNew; 1405 } 1406 } 1407 CFRelease(PropsRef); 1408 } 1409 else 1410 AssertMsgFailed(("krc=%#x\n", krc)); 1411 1412 #endif 1413 IOObjectRelease(EthNICService); 1414 i++; 1415 } 1416 1417 IOObjectRelease(EthNICServices); 1418 1419 return NULL;//return pHead; 1420 } 1421 1422 #ifdef STANDALONE_TESTCASE 1423 /** 1424 * This file can optionally be compiled into a testcase, this is the main function. 1425 * To build: 1426 * g++ -I ../../../../include -D IN_RING3 iokit.cpp ../../../../out/darwin.x86/debug/lib/RuntimeR3.a ../../../../out/darwin.x86/debug/lib/SUPR3.a ../../../../out/darwin.x86/debug/lib/RuntimeR3.a ../../../../out/darwin.x86/debug/lib/VBox-kStuff.a ../../../../out/darwin.x86/debug/lib/RuntimeR3.a -framework CoreFoundation -framework IOKit -liconv -D STANDALONE_TESTCASE 1427 */ 1428 int main(int argc, char **argv) 1429 { 1430 RTR3Init(false); 1431 1432 DarwinGetNetworkControllers(); 1433 //DarwinGetDVDDrives(); 1434 1435 return 0; 1436 } 1437 #endif 1438 1439
Note:
See TracChangeset
for help on using the changeset viewer.