Changeset 3376 in vbox for trunk/src/VBox/Main
- Timestamp:
- Jul 3, 2007 8:21:03 AM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 22574
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/darwin/iokit.cpp
r2981 r3376 28 28 * Header Files * 29 29 *******************************************************************************/ 30 #define LOG_GROUP LOG_GROUP_MAIN 31 30 32 #include <mach/mach.h> 31 33 #include <Carbon/Carbon.h> … … 39 41 #endif 40 42 43 #include <VBox/log.h> 41 44 #include <iprt/mem.h> 42 45 #include <iprt/string.h> … … 186 189 return false; 187 190 } 191 192 193 #if 1 /* dumping disabled */ 194 # define DARWIN_IOKIT_LOG(a) Log(a) 195 # define DARWIN_IOKIT_LOG_FLUSH() do {} while (0) 196 # define DARWIN_IOKIT_DUMP_OBJ(o) do {} while (0) 197 #else 198 # if 0 199 # include <iprt/stream.h> 200 # define DARWIN_IOKIT_LOG(a) RTPrintf a 201 # define DARWIN_IOKIT_LOG_FLUSH() RTStrmFlush(g_pStdOut) 202 # else 203 # define DARWIN_IOKIT_LOG(a) RTLogPrintf a 204 # define DARWIN_IOKIT_LOG(a) RTLogFlush() 205 # endif 206 # define DARWIN_IOKIT_DUMP_OBJ(o) darwinDumpObj(o) 207 208 /** 209 * Callback for dumping a dictionary key. 210 * 211 * @param pvKey The key name. 212 * @param pvValue The key value 213 * @param pvUser The recursion depth. 214 */ 215 static void darwinDumpDictCallback(const void *pvKey, const void *pvValue, void *pvUser) 216 { 217 /* display the key name. */ 218 char *pszKey = (char *)RTMemTmpAlloc(1024); 219 if (!CFStringGetCString((CFStringRef)pvKey, pszKey, 1024, kCFStringEncodingUTF8)) 220 strcpy(pszKey, "CFStringGetCString failure"); 221 DARWIN_IOKIT_LOG(("%+*s%s", (int)(uintptr_t)pvUser, "", pszKey)); 222 RTMemTmpFree(pszKey); 223 224 /* display the value type */ 225 CFTypeID Type = CFGetTypeID(pvValue); 226 DARWIN_IOKIT_LOG((" [%d-", Type)); 227 228 /* display the value */ 229 if (Type == CFDictionaryGetTypeID()) 230 { 231 DARWIN_IOKIT_LOG(("dictionary] =\n" 232 "%-*s{\n", (int)(uintptr_t)pvUser, "")); 233 CFDictionaryApplyFunction((CFDictionaryRef)pvValue, darwinDumpDictCallback, (void *)((uintptr_t)pvUser + 4)); 234 DARWIN_IOKIT_LOG(("%-*s}\n", (int)(uintptr_t)pvUser, "")); 235 } 236 else if (Type == CFNumberGetTypeID()) 237 { 238 union 239 { 240 SInt8 s8; 241 SInt16 s16; 242 SInt32 s32; 243 SInt64 s64; 244 Float32 rf32; 245 Float64 rd64; 246 char ch; 247 short s; 248 int i; 249 long l; 250 long long ll; 251 float rf; 252 double rd; 253 CFIndex iCF; 254 } u; 255 memset(&u, 0, sizeof(u)); 256 CFNumberType NumType = CFNumberGetType((CFNumberRef)pvValue); 257 if (CFNumberGetValue((CFNumberRef)pvValue, NumType, &u)) 258 { 259 switch (CFNumberGetType((CFNumberRef)pvValue)) 260 { 261 case kCFNumberSInt8Type: DARWIN_IOKIT_LOG(("SInt8] = %RI8 (%#RX8)\n", NumType, u.s8, u.s8)); break; 262 case kCFNumberSInt16Type: DARWIN_IOKIT_LOG(("SInt16] = %RI16 (%#RX16)\n", NumType, u.s16, u.s16)); break; 263 case kCFNumberSInt32Type: DARWIN_IOKIT_LOG(("SInt32] = %RI32 (%#RX32)\n", NumType, u.s32, u.s32)); break; 264 case kCFNumberSInt64Type: DARWIN_IOKIT_LOG(("SInt64] = %RI64 (%#RX64)\n", NumType, u.s64, u.s64)); break; 265 case kCFNumberFloat32Type: DARWIN_IOKIT_LOG(("float32] = %#lx\n", NumType, u.l)); break; 266 case kCFNumberFloat64Type: DARWIN_IOKIT_LOG(("float64] = %#llx\n", NumType, u.ll)); break; 267 case kCFNumberFloatType: DARWIN_IOKIT_LOG(("float] = %#lx\n", NumType, u.l)); break; 268 case kCFNumberDoubleType: DARWIN_IOKIT_LOG(("double] = %#llx\n", NumType, u.ll)); break; 269 case kCFNumberCharType: DARWIN_IOKIT_LOG(("char] = %hhd (%hhx)\n", NumType, u.ch, u.ch)); break; 270 case kCFNumberShortType: DARWIN_IOKIT_LOG(("short] = %hd (%hx)\n", NumType, u.s, u.s)); break; 271 case kCFNumberIntType: DARWIN_IOKIT_LOG(("int] = %d (%#x)\n", NumType, u.i, u.i)); break; 272 case kCFNumberLongType: DARWIN_IOKIT_LOG(("long] = %ld (%#lx)\n", NumType, u.l, u.l)); break; 273 case kCFNumberLongLongType: DARWIN_IOKIT_LOG(("long long] = %lld (%#llx)\n", NumType, u.ll, u.ll)); break; 274 case kCFNumberCFIndexType: DARWIN_IOKIT_LOG(("CFIndex] = %lld (%#llx)\n", NumType, (long long)u.iCF, (long long)u.iCF)); break; 275 break; 276 default: DARWIN_IOKIT_LOG(("%d?] = %lld (%llx)\n", NumType, u.ll, u.ll)); break; 277 } 278 } 279 else 280 DARWIN_IOKIT_LOG(("number] = CFNumberGetValue failed\n")); 281 } 282 else if (Type == CFBooleanGetTypeID()) 283 DARWIN_IOKIT_LOG(("boolean] = %RTbool\n", CFBooleanGetValue((CFBooleanRef)pvValue))); 284 else if (Type == CFStringGetTypeID()) 285 { 286 DARWIN_IOKIT_LOG(("string] = ")); 287 char *pszValue = (char *)RTMemTmpAlloc(16*_1K); 288 if (!CFStringGetCString((CFStringRef)pvValue, pszValue, 16*_1K, kCFStringEncodingUTF8)) 289 strcpy(pszValue, "CFStringGetCString failure"); 290 DARWIN_IOKIT_LOG(("\"%s\"\n", pszValue)); 291 RTMemTmpFree(pszValue); 292 } 293 else 294 DARWIN_IOKIT_LOG(("??] = %p\n", pvValue)); 295 } 296 297 298 /** 299 * Dumps a dictionary to the log. 300 * 301 * @param DictRef The dictionary to dump. 302 */ 303 static void darwinDumpDict(CFMutableDictionaryRef DictRef, unsigned cIndents) 304 { 305 CFDictionaryApplyFunction(DictRef, darwinDumpDictCallback, (void *)(uintptr_t)cIndents); 306 DARWIN_IOKIT_LOG_FLUSH(); 307 } 308 309 310 /** 311 * Dumps an I/O kit registry object and all it children. 312 * @param Object The object to dump. 313 * @param cIndents The number of indents to use. 314 */ 315 static void darwinDumpObjInt(io_object_t Object, unsigned cIndents) 316 { 317 static io_string_t s_szPath; 318 kern_return_t krc = IORegistryEntryGetPath(Object, kIOServicePlane, s_szPath); 319 if (krc != KERN_SUCCESS) 320 strcpy(s_szPath, "IORegistryEntryGetPath failed"); 321 DARWIN_IOKIT_LOG(("Dumping %p - %s:\n", (const void *)Object, s_szPath)); 322 323 CFMutableDictionaryRef PropsRef = 0; 324 krc = IORegistryEntryCreateCFProperties(Object, &PropsRef, kCFAllocatorDefault, kNilOptions); 325 if (krc == KERN_SUCCESS) 326 { 327 darwinDumpDict(PropsRef, cIndents + 4); 328 CFRelease(PropsRef); 329 } 330 331 /* 332 * Children. 333 */ 334 io_iterator_t Children; 335 krc = IORegistryEntryGetChildIterator(Object, kIOServicePlane, &Children); 336 if (krc == KERN_SUCCESS) 337 { 338 io_object_t Child; 339 while ((Child = IOIteratorNext(Children))) 340 { 341 darwinDumpObjInt(Child, cIndents + 4); 342 IOObjectRelease(Child); 343 } 344 IOObjectRelease(Children); 345 } 346 else 347 DARWIN_IOKIT_LOG(("IORegistryEntryGetChildIterator -> %#x\n", krc)); 348 } 349 350 /** 351 * Dumps an I/O kit registry object and all it children. 352 * @param Object The object to dump. 353 */ 354 static void darwinDumpObj(io_object_t Object) 355 { 356 darwinDumpObjInt(Object, 0); 357 } 358 359 #endif 188 360 189 361 … … 221 393 io_object_t Object; 222 394 while ((Object = IOIteratorNext(pIterator))) 395 { 396 DARWIN_IOKIT_DUMP_OBJ(Object); 223 397 IOObjectRelease(Object); 224 } 225 226 227 /** 228 * Callback for the two attach notifications. 398 } 399 } 400 401 402 /** 403 * Callback for the 1st attach notification. 229 404 * 230 405 * @param pvNotify Our data. 231 406 * @param NotifyIterator The notification iterator. 232 407 */ 233 static void darwinUSBAttachNotification(void *pvNotify, io_iterator_t NotifyIterator) 234 { 408 static void darwinUSBAttachNotification1(void *pvNotify, io_iterator_t NotifyIterator) 409 { 410 DARWIN_IOKIT_LOG(("USB Attach Notification1\n")); 235 411 NOREF(pvNotify); //PDARWINUSBNOTIFY pNotify = (PDARWINUSBNOTIFY)pvNotify; 236 412 darwinDrainIterator(NotifyIterator); … … 239 415 240 416 /** 241 * Callback for the detach notifications.417 * Callback for the 2nd attach notification. 242 418 * 243 419 * @param pvNotify Our data. 244 420 * @param NotifyIterator The notification iterator. 245 421 */ 422 static void darwinUSBAttachNotification2(void *pvNotify, io_iterator_t NotifyIterator) 423 { 424 DARWIN_IOKIT_LOG(("USB Attach Notification2\n")); 425 NOREF(pvNotify); //PDARWINUSBNOTIFY pNotify = (PDARWINUSBNOTIFY)pvNotify; 426 darwinDrainIterator(NotifyIterator); 427 } 428 429 430 /** 431 * Callback for the detach notifications. 432 * 433 * @param pvNotify Our data. 434 * @param NotifyIterator The notification iterator. 435 */ 246 436 static void darwinUSBDetachNotification(void *pvNotify, io_iterator_t NotifyIterator) 247 437 { 438 DARWIN_IOKIT_LOG(("USB Detach Notification\n")); 248 439 NOREF(pvNotify); //PDARWINUSBNOTIFY pNotify = (PDARWINUSBNOTIFY)pvNotify; 249 440 darwinDrainIterator(NotifyIterator); … … 289 480 kIOPublishNotification, 290 481 IOServiceMatching(kIOUSBDeviceClassName), 291 darwinUSBAttachNotification ,482 darwinUSBAttachNotification1, 292 483 pNotify, 293 484 &pNotify->AttachIterator); … … 298 489 kIOMatchedNotification, 299 490 IOServiceMatching(kIOUSBDeviceClassName), 300 darwinUSBAttachNotification ,491 darwinUSBAttachNotification2, 301 492 pNotify, 302 493 &pNotify->AttachIterator2); … … 365 556 { 366 557 AssertReturn(darwinOpenMasterPort(), NULL); 558 //DARWIN_IOKIT_LOG(("DarwinGetUSBDevices\n")); 367 559 368 560 /* … … 389 581 while ((USBDevice = IOIteratorNext(USBDevices)) != 0) 390 582 { 583 //DARWIN_IOKIT_DUMP_OBJ(USBDevice); 584 391 585 /* 392 586 * Query the device properties from the registry. … … 501 695 502 696 IOObjectRelease(USBDevices); 697 //DARWIN_IOKIT_LOG_FLUSH(); 503 698 504 699 /*
Note:
See TracChangeset
for help on using the changeset viewer.