AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
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(NULL), mCallback(NULL), mDevices(0)
38 {
39  mPciDevices = new KonaNotifier(PCIDeviceNotifierCallback, this);
40 }
41 
42 
44 {
45  Uninstall();
46 
47  delete mPciDevices;
48  mPciDevices = NULL;
49 }
50 
51 
52 AJAStatus AJAPnpImpl::Install (AJAPnpCallback callback, void* refCon, uint32_t devices)
53 {
54  mCallback = callback;
55  mRefCon = refCon;
56  mDevices = devices;
57 
58  if (!mCallback)
59  return AJA_STATUS_NULL; // NULL callback
60 
61  // MacOS only handles PCIe devices
62  if (mDevices & AJA_Pnp_PciVideoDevices) // PCIe devices requested?
63  if (mPciDevices) // DeviceNotifier or KonaNotifier exists?
64  if (mPciDevices->Install()) // DeviceNotifier/KonaNotifier install successful?
65  return AJA_STATUS_SUCCESS; // Success!
66 
67  return AJA_STATUS_FAIL; // Nothing installed
68 }
69 
70 
72 {
73  mCallback = NULL;
74  mRefCon = NULL;
75  mDevices = 0;
76  return AJA_STATUS_SUCCESS;
77 }
78 
79 
80 // static - translate a PCIDeviceNotifierCallback/message to a AJAPnpCallback/message
81 void PCIDeviceNotifierCallback (unsigned long message, void *refcon)
82 {
83 // PNPLOGS(AJA_DebugSeverity_Debug, "msg=" << HEX8(message));
84 
85  AJAPnpImpl* pnpObj = (AJAPnpImpl*) refcon;
86  if (pnpObj == NULL)
87  {
88  PNPLOGS(AJA_DebugSeverity_Error, "NULL refcon, msg=" << HEX8(message));
89  return;
90  }
91 
92  AJAPnpCallback callback = pnpObj->GetCallback();
93  if (callback == NULL)
94  {
95  PNPLOGS(AJA_DebugSeverity_Error, "NULL callback, msg=" << HEX8(message));
96  return;
97  }
98 
99  switch (message)
100  {
102  PNPLOGS(AJA_DebugSeverity_Info, "kAJADeviceInitialOpen, AJA_Pnp_DeviceAdded");
103  (callback)(AJA_Pnp_DeviceAdded, pnpObj->GetRefCon());
104  break;
105 
106  case kAJADeviceTerminate:
107  PNPLOGS(AJA_DebugSeverity_Info, "kAJADeviceTerminate, AJA_Pnp_DeviceRemoved");
108  (callback)(AJA_Pnp_DeviceRemoved, pnpObj->GetRefCon());
109  break;
110 
111  default:
112  break;
113  }
114 }
AJAPnpImpl::Uninstall
AJAStatus Uninstall(void)
Definition: pnpimpl.cpp:62
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:81
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
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
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