AJA NTV2 SDK  18.0.0.2717
NTV2 SDK 18.0.0.2717
pnpimpl.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
9 #include "ajabase/system/debug.h"
10 #include "devicenotifier.h" // For now use NTV2 DeviceNotifier facility
11 #include <sstream>
12 #include <iostream>
13 #include <iomanip>
14 
15 
16 using namespace std;
17 
18 // Logging Macros
19 
20 #define HEX2(__x__) "0x" << hex << setw(2) << setfill('0') << (0x00FF & uint16_t(__x__)) << dec
21 #define HEX4(__x__) "0x" << hex << setw(4) << setfill('0') << (0xFFFF & uint16_t(__x__)) << dec
22 #define HEX8(__x__) "0x" << hex << setw(8) << setfill('0') << (0xFFFFFFFF & uint32_t(__x__)) << dec
23 #define HEX16(__x__) "0x" << hex << setw(16) << setfill('0') << uint64_t(__x__) << dec
24 #define KR(_kr_) "kernErr=" << HEX8(_kr_) << "(" << ::GetKernErrStr(_kr_) << ")"
25 #define INST(__p__) "Ins-" << hex << setw(16) << setfill('0') << uint64_t(__p__) << dec
26 #define THRD(__t__) "Thr-" << hex << setw(16) << setfill('0') << uint64_t(__t__) << dec
27 
28 #define PNPLOGS(__lvl__, __x__) AJA_sREPORT(AJA_DebugUnit_PnP, (__lvl__), __func__ << ": " << __x__)
29 
30 
31 // static
32 bool sOnline = false;
33 void PCIDeviceNotifierCallback (unsigned long message, void *refcon);
34 
35 
36 
37 AJAPnpImpl::AJAPnpImpl() : mRefCon(nullptr), mCallback(nullptr), mDevices(0), mPciDevices(nullptr)
38 {
39 }
40 
41 
43 {
44  Uninstall();
45 }
46 
47 
48 AJAStatus AJAPnpImpl::Install (AJAPnpCallback callback, void* refCon, uint32_t deviceKinds)
49 {
50  mCallback = callback;
51  mRefCon = refCon;
52  mDevices = deviceKinds;
53 
54  if (!mCallback)
55  {PNPLOGS(AJA_DebugSeverity_Error, "NULL callback specified"); return AJA_STATUS_NULL;}
56 
57  // MacOS only handles PCIe devices
58  size_t numFails(0);
59  if (mDevices & AJA_Pnp_PciVideoDevices) // PCIe devices requested?
60  {
61  if (!mPciDevices)
62  mPciDevices = new KonaNotifier(PCIDeviceNotifierCallback, this);
63  if (mPciDevices) // DeviceNotifier or KonaNotifier exists?
64  if (!mPciDevices->Install()) // DeviceNotifier/KonaNotifier install successful?
65  numFails++;
66  }
67  if (mDevices & AJA_Pnp_UsbSerialDevices)// USB/serial devices?
68  { // TBD
69  PNPLOGS(AJA_DebugSeverity_Warning, "USB/Serial devices requested but unsupported");
70  }
71  if (mDevices & AJA_Pnp_FireWireDevices) // FireWire devices?
72  { // Retired long ago
73  PNPLOGS(AJA_DebugSeverity_Warning, "FireWire devices requested but unsupported");
74  }
75  if (numFails)
76  Uninstall();
77  return numFails ? AJA_STATUS_FAIL : AJA_STATUS_SUCCESS;
78 }
79 
80 
82 {
83  mCallback = NULL;
84  mRefCon = NULL;
85  mDevices = 0;
86  if (mPciDevices)
87  {
88  mPciDevices->Uninstall();
89  delete mPciDevices;
90  mPciDevices = nullptr;
91  }
92  return AJA_STATUS_SUCCESS;
93 }
94 
95 
96 // static - translate a PCIDeviceNotifierCallback/message to a AJAPnpCallback/message
97 void PCIDeviceNotifierCallback (unsigned long message, void *refcon)
98 {
99 // PNPLOGS(AJA_DebugSeverity_Debug, "msg=" << HEX8(message));
100 
101  AJAPnpImpl* pnpObj = (AJAPnpImpl*) refcon;
102  if (!pnpObj)
103  {
104  PNPLOGS(AJA_DebugSeverity_Error, "NULL refcon, msg=" << HEX8(message));
105  return;
106  }
107 
108  AJAPnpCallback callback = pnpObj->GetCallback();
109  if (!callback)
110  {
111  PNPLOGS(AJA_DebugSeverity_Error, "NULL callback, msg=" << HEX8(message));
112  return;
113  }
114 
115  switch (message)
116  {
118  PNPLOGS(AJA_DebugSeverity_Info, "kAJADeviceInitialOpen, AJA_Pnp_DeviceAdded");
119  (callback)(AJA_Pnp_DeviceAdded, pnpObj->GetRefCon());
120  break;
121 
122  case kAJADeviceTerminate:
123  PNPLOGS(AJA_DebugSeverity_Info, "kAJADeviceTerminate, AJA_Pnp_DeviceRemoved");
124  (callback)(AJA_Pnp_DeviceRemoved, pnpObj->GetRefCon());
125  break;
126 
127  default:
128  break;
129  }
130 }
AJAPnpImpl::Uninstall
AJAStatus Uninstall(void)
Definition: pnpimpl.cpp:62
AJA_Pnp_UsbSerialDevices
@ AJA_Pnp_UsbSerialDevices
Definition: pnp.h:17
AJA_DebugSeverity_Warning
@ AJA_DebugSeverity_Warning
Definition: debugshare.h:29
NULL
#define NULL
Definition: ntv2caption608types.h:19
AJA_STATUS_SUCCESS
@ AJA_STATUS_SUCCESS
Definition: types.h:381
AJAPnpCallback
void(* AJAPnpCallback)(AJAPnpMessage inMessage, void *inRefCon)
If installed (see AJAPnp::Install) in an AJAPnp instance, this function is called when an AJA device ...
Definition: pnp.h:39
AJA_DebugSeverity_Error
@ AJA_DebugSeverity_Error
Definition: debugshare.h:28
KonaNotifier
Subclass of DeviceNotifier that notifies clients when Kona/Corvid/Io/TTap devices are attached/detach...
Definition: devicenotifier.h:87
PCIDeviceNotifierCallback
void PCIDeviceNotifierCallback(unsigned long message, void *refcon)
Definition: pnpimpl.cpp:97
AJA_Pnp_PciVideoDevices
@ AJA_Pnp_PciVideoDevices
Definition: pnp.h:16
kAJADeviceInitialOpen
#define kAJADeviceInitialOpen
Definition: devicenotifier.h:20
devicenotifier.h
Declares the MacOS-specific KonaNotifier and DeviceNotifier classes, which invoke a client-registered...
DeviceNotifier::Install
virtual bool Install(CFMutableDictionaryRef dict=NULL)
Definition: devicenotifier.cpp:86
AJAStatus
AJAStatus
Definition: types.h:378
AJA_STATUS_FAIL
@ AJA_STATUS_FAIL
Definition: types.h:382
AJAPnpImpl::Install
AJAStatus Install(AJAPnpCallback callback, void *refCon, uint32_t devices)
Definition: pnpimpl.cpp:32
AJA_Pnp_FireWireDevices
@ AJA_Pnp_FireWireDevices
Definition: pnp.h:18
PNPLOGS
#define PNPLOGS(__lvl__, __x__)
Definition: pnpimpl.cpp:28
HEX8
#define HEX8(__x__)
Definition: pnpimpl.cpp:22
AJA_Pnp_DeviceRemoved
@ AJA_Pnp_DeviceRemoved
Definition: pnp.h:25
kAJADeviceTerminate
#define kAJADeviceTerminate
Definition: devicenotifier.h:21
DeviceNotifier::Uninstall
virtual void Uninstall()
Definition: devicenotifier.cpp:156
sOnline
bool sOnline
Definition: pnpimpl.cpp:32
AJAPnpImpl
Definition: pnpimpl.h:13
AJA_DebugSeverity_Info
@ AJA_DebugSeverity_Info
Definition: debugshare.h:31
AJAPnpImpl::AJAPnpImpl
AJAPnpImpl()
Definition: pnpimpl.cpp:20
AJA_STATUS_NULL
@ AJA_STATUS_NULL
Definition: types.h:387
common.h
Private include file for all ajabase sources.
pnpimpl.h
Declares the AJAPnpImpl class.
AJAPnpImpl::GetCallback
AJAPnpCallback GetCallback(void) const
Definition: pnpimpl.h:22
std
Definition: json.hpp:5362
AJAPnpImpl::~AJAPnpImpl
virtual ~AJAPnpImpl(void)
Definition: pnpimpl.cpp:25
AJA_Pnp_DeviceAdded
@ AJA_Pnp_DeviceAdded
Definition: pnp.h:24
debug.h
Declares the AJADebug class.
AJAPnpImpl::GetRefCon
void * GetRefCon(void) const
Definition: pnpimpl.h:23