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 kextName (
"com_aja_kext_ntv2");
387 static const std::string dextName (
"AJANTV2");
388 io_iterator_t notifyIterator_matched, notifyIterator_terminated;
392 kIOMatchedNotification,
393 IOServiceMatching(kextName.c_str ()),
396 ¬ifyIterator_matched);
398 if (ioReturn != kIOReturnSuccess)
400 DNFAIL(
KR(ioReturn) <<
" -- IOServiceAddMatchingNotification for 'kIOMatchedNotification' failed");
405 kIOMatchedNotification,
406 IOServiceNameMatching(dextName.c_str ()),
409 ¬ifyIterator_matched);
411 if (ioReturn != kIOReturnSuccess)
413 DNFAIL(
KR(ioReturn) <<
" -- IOServiceAddMatchingNotification for 'kIOMatchedNotification' failed");
419 kIOTerminatedNotification,
420 IOServiceMatching(kextName.c_str ()),
423 ¬ifyIterator_terminated);
424 if (ioReturn != kIOReturnSuccess)
426 DNFAIL(
KR(ioReturn) <<
" -- IOServiceAddMatchingNotification for 'kIOTerminatedNotification' failed");
431 kIOTerminatedNotification,
432 IOServiceNameMatching(dextName.c_str ()),
435 ¬ifyIterator_terminated);
436 if (ioReturn != kIOReturnSuccess)
438 DNFAIL(
KR(ioReturn) <<
" -- IOServiceAddMatchingNotification for 'kIOTerminatedNotification' failed");
458 case kIOReturnError:
return "kIOReturnError";
459 case kIOReturnNoMemory:
return "kIOReturnNoMemory";
460 case kIOReturnNoResources:
return "kIOReturnNoResources";
461 case kIOReturnIPCError:
return "kIOReturnIPCError";
462 case kIOReturnNoDevice:
return "kIOReturnNoDevice";
463 case kIOReturnNotPrivileged:
return "kIOReturnNotPrivileged";
464 case kIOReturnBadArgument:
return "kIOReturnBadArgument";
465 case kIOReturnLockedRead:
return "kIOReturnLockedRead";
466 case kIOReturnLockedWrite:
return "kIOReturnLockedWrite";
467 case kIOReturnExclusiveAccess:
return "kIOReturnExclusiveAccess";
468 case kIOReturnBadMessageID:
return "kIOReturnBadMessageID";
469 case kIOReturnUnsupported:
return "kIOReturnUnsupported";
470 case kIOReturnVMError:
return "kIOReturnVMError";
471 case kIOReturnInternalError:
return "kIOReturnInternalError";
472 case kIOReturnIOError:
return "kIOReturnIOError";
473 case kIOReturnCannotLock:
return "kIOReturnCannotLock";
474 case kIOReturnNotOpen:
return "kIOReturnNotOpen";
475 case kIOReturnNotReadable:
return "kIOReturnNotReadable";
476 case kIOReturnNotWritable:
return "kIOReturnNotWritable";
477 case kIOReturnNotAligned:
return "kIOReturnNotAligned";
478 case kIOReturnBadMedia:
return "kIOReturnBadMedia";
479 case kIOReturnStillOpen:
return "kIOReturnStillOpen";
480 case kIOReturnRLDError:
return "kIOReturnRLDError";
481 case kIOReturnDMAError:
return "kIOReturnDMAError";
482 case kIOReturnBusy:
return "kIOReturnBusy";
483 case kIOReturnTimeout:
return "kIOReturnTimeout";
484 case kIOReturnOffline:
return "kIOReturnOffline";
485 case kIOReturnNotReady:
return "kIOReturnNotReady";
486 case kIOReturnNotAttached:
return "kIOReturnNotAttached";
487 case kIOReturnNoChannels:
return "kIOReturnNoChannels";
488 case kIOReturnNoSpace:
return "kIOReturnNoSpace";
489 case kIOReturnPortExists:
return "kIOReturnPortExists";
490 case kIOReturnCannotWire:
return "kIOReturnCannotWire";
491 case kIOReturnNoInterrupt:
return "kIOReturnNoInterrupt";
492 case kIOReturnNoFrames:
return "kIOReturnNoFrames";
493 case kIOReturnMessageTooLarge:
return "kIOReturnMessageTooLarge";
494 case kIOReturnNotPermitted:
return "kIOReturnNotPermitted";
495 case kIOReturnNoPower:
return "kIOReturnNoPower";
496 case kIOReturnNoMedia:
return "kIOReturnNoMedia";
497 case kIOReturnUnformattedMedia:
return "kIOReturnUnformattedMedia";
498 case kIOReturnUnsupportedMode:
return "kIOReturnUnsupportedMode";
499 case kIOReturnUnderrun:
return "kIOReturnUnderrun";
500 case kIOReturnOverrun:
return "kIOReturnOverrun";
501 case kIOReturnDeviceError:
return "kIOReturnDeviceError";
502 case kIOReturnNoCompletion:
return "kIOReturnNoCompletion";
503 case kIOReturnAborted:
return "kIOReturnAborted";
504 case kIOReturnNoBandwidth:
return "kIOReturnNoBandwidth";
505 case kIOReturnNotResponding:
return "kIOReturnNotResponding";
506 case kIOReturnIsoTooOld:
return "kIOReturnIsoTooOld";
507 case kIOReturnIsoTooNew:
return "kIOReturnIsoTooNew";
508 case kIOReturnNotFound:
return "kIOReturnNotFound";
virtual void DeviceRemoved(io_iterator_t iterator)
virtual void DeviceAdded(io_iterator_t iterator)
Declares the AJADebug class.
#define kAJADeviceTerminate
std::list< io_object_t > m_deviceMatchList
Mac-specific class that notifies clients when AJA devices are attached/detached, etc.
#define kAJADeviceInitialOpen
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
virtual ~DeviceNotifier()
static std::string MessageTypeToStr(const natural_t messageType)
virtual CFMutableDictionaryRef CreateMatchingDictionary()
virtual bool Install(CFMutableDictionaryRef dict=NULL)
static void DeviceChangedCallback(DeviceNotifier *thisObject, io_service_t unitService, natural_t messageType, void *message)
static void DeviceAddedCallback(DeviceNotifier *thisObject, io_iterator_t iterator)
DeviceNotifier(DeviceClientCallback callback, void *refcon)
virtual bool Install(CFMutableDictionaryRef dict=NULL)
static void DeviceRemovedCallback(DeviceNotifier *thisObject, io_iterator_t iterator)
static const char * GetKernErrStr(const kern_return_t inError)
virtual void AddGeneralInterest(io_object_t service)
Private include file for all ajabase sources.
IONotificationPortRef m_notificationPort
std::list< io_object_t > m_deviceInterestList
void(* DeviceClientCallback)(unsigned long message, void *refcon)
Mac-specific device add/change/remove event notification callback function.
DeviceClientCallback m_clientCallback
CFMutableDictionaryRef m_matchingDictionary
virtual void DeviceChanged(io_service_t unitService, natural_t messageType, void *message)
Declares the MacOS-specific KonaNotifier and DeviceNotifier classes, which invoke a client-registered...
virtual void SetCallback(DeviceClientCallback callback, void *refcon)