AJA NTV2 SDK  17.1.1.1245
NTV2 SDK 17.1.1.1245
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 
46  mAddEventHandle = CreateEventW(NULL, FALSE, FALSE, L"Global\\AJAPNPAddEvent");
47  RegisterWaitForSingleObject(&mAddWaitHandle, mAddEventHandle, (WAITORTIMERCALLBACK)&SignaledAddRoutine, this, INFINITE, NULL);
48 
49  mRemoveEventHandle = CreateEventW(NULL, FALSE, FALSE, L"Global\\AJAPNPRemoveEvent");
50  RegisterWaitForSingleObject(&mRemoveWaitHandle, mRemoveEventHandle, (WAITORTIMERCALLBACK)&SignaledRemoveRoutine, this, INFINITE, NULL);
51 
52  return AJA_STATUS_SUCCESS;
53 }
54 
55 AJAStatus
57 {
58  mCallback = NULL;
59  mRefCon = NULL;
60  mDevices = 0;
61 
62  if(mAddWaitHandle != NULL)
63  {
64  UnregisterWait(mAddWaitHandle);
65  mAddWaitHandle = NULL;
66  }
67  if(mRemoveWaitHandle != NULL)
68  {
69  UnregisterWait(mRemoveWaitHandle);
70  mRemoveWaitHandle = NULL;
71  }
72 
73  return AJA_STATUS_SUCCESS;
74 }
75 
78 {
79  return mCallback;
80 }
81 
82 void*
84 {
85  return mRefCon;
86 }
87 
88 uint32_t
90 {
91  return mDevices;
92 }
93 
94 void
96 {
97  AJATime::Sleep(1000);
98  if (mCallback)
99  (*(mCallback))(AJA_Pnp_DeviceAdded, mRefCon);
100 
101  RegisterWaitForSingleObject(&mAddWaitHandle, mAddEventHandle, (WAITORTIMERCALLBACK)SignaledAddRoutine, this, INFINITE, NULL);
102 }
103 
104 void
106 {
107  if (mCallback)
108  (*(mCallback))(AJA_Pnp_DeviceRemoved, mRefCon);
109 
110  RegisterWaitForSingleObject(&mRemoveWaitHandle, mRemoveEventHandle, (WAITORTIMERCALLBACK)SignaledRemoveRoutine, this, INFINITE, NULL);
111 }
AJAPnpImpl::Uninstall
AJAStatus Uninstall(void)
Definition: pnpimpl.cpp:57
AJAPnpImpl::GetPnpDevices
uint32_t GetPnpDevices()
Definition: pnpimpl.cpp:94
AJAPnpImpl::GetRefCon
void * GetRefCon()
Definition: pnpimpl.cpp:87
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
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
AJAPnpImpl::Install
AJAStatus Install(AJAPnpCallback callback, void *refCon, uint32_t devices)
Definition: pnpimpl.cpp:32
PVOID
void * PVOID
Definition: ajatypes.h:316
AJA_Pnp_DeviceRemoved
@ AJA_Pnp_DeviceRemoved
Definition: pnp.h:25
AJAPnpImpl::AddSignaled
void AddSignaled()
Definition: pnpimpl.cpp:95
AJAPnpImpl
Definition: pnpimpl.h:13
AJAPnpImpl::AJAPnpImpl
AJAPnpImpl()
Definition: pnpimpl.cpp:20
AJAPnpImpl::RemoveSignaled
void RemoveSignaled()
Definition: pnpimpl.cpp:105
AJAPnpImpl::~AJAPnpImpl
virtual ~AJAPnpImpl(void)
Definition: pnpimpl.cpp:25
AJA_Pnp_DeviceAdded
@ AJA_Pnp_DeviceAdded
Definition: pnp.h:24
AJAPnpImpl::GetCallback
AJAPnpCallback GetCallback()
Definition: pnpimpl.cpp:80