AJA NTV2 SDK  17.5.0.1492
NTV2 SDK 17.5.0.1492
pnpimpl.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
10 
11 void
12 CALLBACK SignaledAddRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
13 {
14  AJAPnpImpl *context = (AJAPnpImpl*)lpParam;
15  context->AddSignaled();
16 
17 }
18 
19 void
20 CALLBACK SignaledRemoveRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
21 {
22  AJAPnpImpl *context = (AJAPnpImpl*)lpParam;
23  context->RemoveSignaled();
24 
25 }
26 
27 AJAPnpImpl::AJAPnpImpl() : mRefCon(NULL), mCallback(NULL), mDevices(0), mAddEventHandle(NULL), mAddWaitHandle(NULL), mRemoveEventHandle(NULL), mRemoveWaitHandle(NULL)
28 {
29 }
30 
31 
33 {
34  Uninstall();
35 }
36 
37 
38 AJAStatus
39 AJAPnpImpl::Install(AJAPnpCallback callback, void* refCon, uint32_t devices)
40 {
41  mCallback = callback;
42  mRefCon = refCon;
43  mDevices = devices;
44 
45  if (!mCallback)
46  return AJA_STATUS_NULL; // NULL callback
47 
48  // Windows only handles PCIe devices
49  if (mDevices & AJA_Pnp_PciVideoDevices)
50  {
51  mAddEventHandle = CreateEventW(NULL, FALSE, FALSE, L"Global\\AJAPNPAddEvent");
52  if (!mAddEventHandle)
53  return AJA_STATUS_FAIL;
54  if (!RegisterWaitForSingleObject(&mAddWaitHandle, mAddEventHandle, (WAITORTIMERCALLBACK)&SignaledAddRoutine, this, INFINITE, NULL))
55  return AJA_STATUS_FAIL;
56 
57  mRemoveEventHandle = CreateEventW(NULL, FALSE, FALSE, L"Global\\AJAPNPRemoveEvent");
58  if (!mRemoveEventHandle)
59  return AJA_STATUS_FAIL;
60  if (!RegisterWaitForSingleObject(&mRemoveWaitHandle, mRemoveEventHandle, (WAITORTIMERCALLBACK)&SignaledRemoveRoutine, this, INFINITE, NULL))
61  return AJA_STATUS_FAIL;
62 
63  return AJA_STATUS_SUCCESS;
64  }
65  return AJA_STATUS_FAIL; // Nothing installed
66 }
67 
68 AJAStatus
70 {
71  mCallback = NULL;
72  mRefCon = NULL;
73  mDevices = 0;
74 
75  if(mAddWaitHandle != NULL)
76  {
77  UnregisterWait(mAddWaitHandle);
78  mAddWaitHandle = NULL;
79  }
80  if(mRemoveWaitHandle != NULL)
81  {
82  UnregisterWait(mRemoveWaitHandle);
83  mRemoveWaitHandle = NULL;
84  }
85 
86  return AJA_STATUS_SUCCESS;
87 }
88 
89 void
91 {
92  AJATime::Sleep(1000);
93  if (mCallback)
94  (*(mCallback))(AJA_Pnp_DeviceAdded, mRefCon);
95 
96  RegisterWaitForSingleObject(&mAddWaitHandle, mAddEventHandle, (WAITORTIMERCALLBACK)SignaledAddRoutine, this, INFINITE, NULL);
97 }
98 
99 void
101 {
102  if (mCallback)
103  (*(mCallback))(AJA_Pnp_DeviceRemoved, mRefCon);
104 
105  RegisterWaitForSingleObject(&mRemoveWaitHandle, mRemoveEventHandle, (WAITORTIMERCALLBACK)SignaledRemoveRoutine, this, INFINITE, NULL);
106 }
AJAPnpImpl::Uninstall
AJAStatus Uninstall(void)
Definition: pnpimpl.cpp:62
NULL
#define NULL
Definition: ntv2caption608types.h:19
SignaledRemoveRoutine
void CALLBACK SignaledRemoveRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
Definition: pnpimpl.cpp:20
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
systemtime.h
Declares the AJATime class.
SignaledAddRoutine
void CALLBACK SignaledAddRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
Definition: pnpimpl.cpp:12
AJA_Pnp_PciVideoDevices
@ AJA_Pnp_PciVideoDevices
Definition: pnp.h:16
pnpimpl.h
Declares the AJAPnpImpl class.
AJAStatus
AJAStatus
Definition: types.h:378
AJATime::Sleep
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
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
PVOID
void * PVOID
Definition: ajatypes.h:318
AJA_Pnp_DeviceRemoved
@ AJA_Pnp_DeviceRemoved
Definition: pnp.h:25
AJAPnpImpl
Definition: pnpimpl.h:13
AJAPnpImpl::AJAPnpImpl
AJAPnpImpl()
Definition: pnpimpl.cpp:20
AJA_STATUS_NULL
@ AJA_STATUS_NULL
Definition: types.h:387
AJAPnpImpl::AddSignaled
void AddSignaled(void)
Definition: pnpimpl.cpp:90
AJAPnpImpl::~AJAPnpImpl
virtual ~AJAPnpImpl(void)
Definition: pnpimpl.cpp:25
AJA_Pnp_DeviceAdded
@ AJA_Pnp_DeviceAdded
Definition: pnp.h:24
AJAPnpImpl::RemoveSignaled
void RemoveSignaled(void)
Definition: pnpimpl.cpp:100