13 #include <IOKit/IOCFPlugIn.h>
22 static const char *
GetKernErrStr (
const kern_return_t inError);
27 #define HEX2(__x__) "0x" << hex << setw(2) << setfill('0') << (0x00FF & uint16_t(__x__)) << dec
28 #define HEX4(__x__) "0x" << hex << setw(4) << setfill('0') << (0xFFFF & uint16_t(__x__)) << dec
29 #define HEX8(__x__) "0x" << hex << setw(8) << setfill('0') << (0xFFFFFFFF & uint32_t(__x__)) << dec
30 #define HEX16(__x__) "0x" << hex << setw(16) << setfill('0') << uint64_t(__x__) << dec
31 #define KR(_kr_) "kernErr=" << HEX8(_kr_) << "(" << ::GetKernErrStr(_kr_) << ")"
32 #define INST(__p__) "Ins-" << hex << setw(16) << setfill('0') << uint64_t(__p__) << dec
33 #define THRD(__t__) "Thr-" << hex << setw(16) << setfill('0') << uint64_t(__t__) << dec
35 #define DNDB(__lvl__, __x__) AJA_sREPORT(AJA_DebugUnit_PnP, (__lvl__), INST(this) << ": " << AJAFUNC << ": " << __x__)
36 #define DNFAIL(__x__) DNDB(AJA_DebugSeverity_Error, __x__)
37 #define DNWARN(__x__) DNDB(AJA_DebugSeverity_Warning, __x__)
38 #define DNNOTE(__x__) DNDB(AJA_DebugSeverity_Notice, __x__)
39 #define DNINFO(__x__) DNDB(AJA_DebugSeverity_Info, __x__)
40 #define DNDBG(__x__) DNDB(AJA_DebugSeverity_Debug, __x__)
50 m_clientCallback (callback),
52 m_notificationPort (
NULL),
53 m_matchingDictionary (
NULL)
101 DNFAIL(
"NULL matchingDictionary");
106 mach_port_t masterPort;
107 IOReturn ioReturn = ::IOMasterPort (MACH_PORT_NULL, &masterPort);
108 if (kIOReturnSuccess != ioReturn)
110 DNFAIL(
KR(ioReturn) <<
" -- IOMasterPort failed");
118 DNFAIL(
"IONotificationPortCreate failed");
125 CFRunLoopSourceRef runLoopSource = ::IONotificationPortGetRunLoopSource (
m_notificationPort);
126 CFRunLoopAddSource (CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
132 io_iterator_t iterator;
134 kIOMatchedNotification,
139 if (kIOReturnSuccess != ioReturn)
141 DNFAIL(
KR(ioReturn) <<
" -- IOServiceAddMatchingNotification failed");
161 list<io_object_t>::iterator p;
163 IOObjectRelease (*p);
168 IOObjectRelease (*p);
173 CFRunLoopSourceRef runLoopSource = IONotificationPortGetRunLoopSource (
m_notificationPort);
174 CFRunLoopRemoveSource (CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
195 CFMutableDictionaryRef matchingDictionary = CFDictionaryCreateMutable ( kCFAllocatorDefault,
197 &kCFTypeDictionaryKeyCallBacks,
198 &kCFTypeDictionaryValueCallBacks);
200 CFDictionaryAddValue (matchingDictionary, CFSTR(
"IOProviderClass"), deviceDriverName);
201 return matchingDictionary;
224 bool deviceFound =
false;
227 IOIteratorReset(iterator);
228 for ( ;(service = IOIteratorNext(iterator)); IOObjectRelease(service))
257 bool deviceFound =
false;
260 IOIteratorReset(iterator);
261 for ( ;(service = IOIteratorNext(iterator)); IOObjectRelease(service))
277 io_object_t notifier;
287 if (kIOReturnSuccess != ioReturn)
289 DNFAIL(
KR(ioReturn) <<
" -- IOServiceAddInterestNotification failed");
302 thisObject->
DeviceChanged (unitService, messageType, message);
329 case kIOMessageServiceIsTerminated: oss <<
"kIOMessageServiceIsTerminated";
break;
330 case kIOMessageServiceIsSuspended: oss <<
"kIOMessageServiceIsSuspended";
break;
331 case kIOMessageServiceIsResumed: oss <<
"kIOMessageServiceIsResumed";
break;
332 case kIOMessageServiceIsRequestingClose: oss <<
"kIOMessageServiceIsRequestingClose";
break;
334 case kIOMessageServiceIsAttemptingOpen: oss <<
"kIOMessageServiceIsAttemptingOpen";
break;
335 case kIOMessageServiceWasClosed: oss <<
"kIOMessageServiceWasClosed";
break;
336 case kIOMessageServiceBusyStateChange: oss <<
"kIOMessageServiceBusyStateChange";
break;
337 case kIOMessageCanDevicePowerOff: oss <<
"kIOMessageCanDevicePowerOff";
break;
338 case kIOMessageDeviceWillPowerOff: oss <<
"kIOMessageDeviceWillPowerOff";
break;
339 case kIOMessageDeviceWillNotPowerOff: oss <<
"kIOMessageDeviceWillPowerOff";
break;
340 case kIOMessageDeviceHasPoweredOn: oss <<
"kIOMessageDeviceHasPoweredOn";
break;
341 case kIOMessageCanSystemPowerOff: oss <<
"kIOMessageCanSystemPowerOff";
break;
342 case kIOMessageSystemWillPowerOff: oss <<
"kIOMessageSystemWillPowerOff";
break;
343 case kIOMessageSystemWillNotPowerOff: oss <<
"kIOMessageSystemWillNotPowerOff";
break;
344 case kIOMessageCanSystemSleep: oss <<
"kIOMessageCanSystemSleep";
break;
345 case kIOMessageSystemWillSleep: oss <<
"kIOMessageSystemWillSleep";
break;
346 case kIOMessageSystemWillNotSleep: oss <<
"kIOMessageSystemWillNotSleep";
break;
347 case kIOMessageSystemHasPoweredOn: oss <<
"kIOMessageSystemHasPoweredOn";
break;
348 default: oss <<
"msgType=0x" << hex << setw(4) << setfill(
'0') << messageType;
break;
358 (
void) matchingDictionary;
362 mach_port_t masterPort;
363 IOReturn ioReturn = ::IOMasterPort (MACH_PORT_NULL, &masterPort);
364 if (kIOReturnSuccess != ioReturn)
366 DNFAIL(
KR(ioReturn) <<
" -- IOMasterPort failed");
374 DNFAIL(
"IONotificationPortCreate failed");
381 CFRunLoopSourceRef runLoopSource = ::IONotificationPortGetRunLoopSource (
m_notificationPort);
382 ::CFRunLoopAddSource (::CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
386 static const std::string driverName (
"com_aja_iokit_ntv2");
387 io_iterator_t notifyIterator_matched, notifyIterator_terminated;
391 kIOMatchedNotification,
392 IOServiceMatching(driverName.c_str ()),
395 ¬ifyIterator_matched);
397 if (ioReturn != kIOReturnSuccess)
399 DNFAIL(
KR(ioReturn) <<
" -- IOServiceAddMatchingNotification for 'kIOMatchedNotification' failed");
405 kIOTerminatedNotification,
406 IOServiceMatching(driverName.c_str ()),
409 ¬ifyIterator_terminated);
410 if (ioReturn != kIOReturnSuccess)
412 DNFAIL(
KR(ioReturn) <<
" -- IOServiceAddMatchingNotification for 'kIOTerminatedNotification' failed");
432 case kIOReturnError:
return "kIOReturnError";
433 case kIOReturnNoMemory:
return "kIOReturnNoMemory";
434 case kIOReturnNoResources:
return "kIOReturnNoResources";
435 case kIOReturnIPCError:
return "kIOReturnIPCError";
436 case kIOReturnNoDevice:
return "kIOReturnNoDevice";
437 case kIOReturnNotPrivileged:
return "kIOReturnNotPrivileged";
438 case kIOReturnBadArgument:
return "kIOReturnBadArgument";
439 case kIOReturnLockedRead:
return "kIOReturnLockedRead";
440 case kIOReturnLockedWrite:
return "kIOReturnLockedWrite";
441 case kIOReturnExclusiveAccess:
return "kIOReturnExclusiveAccess";
442 case kIOReturnBadMessageID:
return "kIOReturnBadMessageID";
443 case kIOReturnUnsupported:
return "kIOReturnUnsupported";
444 case kIOReturnVMError:
return "kIOReturnVMError";
445 case kIOReturnInternalError:
return "kIOReturnInternalError";
446 case kIOReturnIOError:
return "kIOReturnIOError";
447 case kIOReturnCannotLock:
return "kIOReturnCannotLock";
448 case kIOReturnNotOpen:
return "kIOReturnNotOpen";
449 case kIOReturnNotReadable:
return "kIOReturnNotReadable";
450 case kIOReturnNotWritable:
return "kIOReturnNotWritable";
451 case kIOReturnNotAligned:
return "kIOReturnNotAligned";
452 case kIOReturnBadMedia:
return "kIOReturnBadMedia";
453 case kIOReturnStillOpen:
return "kIOReturnStillOpen";
454 case kIOReturnRLDError:
return "kIOReturnRLDError";
455 case kIOReturnDMAError:
return "kIOReturnDMAError";
456 case kIOReturnBusy:
return "kIOReturnBusy";
457 case kIOReturnTimeout:
return "kIOReturnTimeout";
458 case kIOReturnOffline:
return "kIOReturnOffline";
459 case kIOReturnNotReady:
return "kIOReturnNotReady";
460 case kIOReturnNotAttached:
return "kIOReturnNotAttached";
461 case kIOReturnNoChannels:
return "kIOReturnNoChannels";
462 case kIOReturnNoSpace:
return "kIOReturnNoSpace";
463 case kIOReturnPortExists:
return "kIOReturnPortExists";
464 case kIOReturnCannotWire:
return "kIOReturnCannotWire";
465 case kIOReturnNoInterrupt:
return "kIOReturnNoInterrupt";
466 case kIOReturnNoFrames:
return "kIOReturnNoFrames";
467 case kIOReturnMessageTooLarge:
return "kIOReturnMessageTooLarge";
468 case kIOReturnNotPermitted:
return "kIOReturnNotPermitted";
469 case kIOReturnNoPower:
return "kIOReturnNoPower";
470 case kIOReturnNoMedia:
return "kIOReturnNoMedia";
471 case kIOReturnUnformattedMedia:
return "kIOReturnUnformattedMedia";
472 case kIOReturnUnsupportedMode:
return "kIOReturnUnsupportedMode";
473 case kIOReturnUnderrun:
return "kIOReturnUnderrun";
474 case kIOReturnOverrun:
return "kIOReturnOverrun";
475 case kIOReturnDeviceError:
return "kIOReturnDeviceError";
476 case kIOReturnNoCompletion:
return "kIOReturnNoCompletion";
477 case kIOReturnAborted:
return "kIOReturnAborted";
478 case kIOReturnNoBandwidth:
return "kIOReturnNoBandwidth";
479 case kIOReturnNotResponding:
return "kIOReturnNotResponding";
480 case kIOReturnIsoTooOld:
return "kIOReturnIsoTooOld";
481 case kIOReturnIsoTooNew:
return "kIOReturnIsoTooNew";
482 case kIOReturnNotFound:
return "kIOReturnNotFound";