1 /*++
2 
3 Copyright (c) Microsoft Corporation.  All rights reserved.
4 
5 Module Name:
6 
7     FxIoTargetRemoteUm.hpp
8 
9 Abstract:
10 
11     User-mode specific definitions of FxIoTargetRemote
12 
13 Author:
14 
15 
16 Environment:
17 
18     User mode only
19 
20 Revision History:
21 
22 --*/
23 
24 #pragma once
25 
26 class FxIoTargetRemoteNotificationCallback :
27                     public FxGlobalsStump,
28                     public IWudfTargetCallbackDeviceChange
29 {
30 private:
31 
32     LONG m_cRefs;
33 
34     FxIoTargetRemote* m_RemoteTarget;
35 
36 public:
37 
FxIoTargetRemoteNotificationCallback(PFX_DRIVER_GLOBALS FxDriverGlobals,FxIoTargetRemote * Target)38     FxIoTargetRemoteNotificationCallback(
39         PFX_DRIVER_GLOBALS FxDriverGlobals,
40         FxIoTargetRemote* Target
41         ) :
42         FxGlobalsStump(FxDriverGlobals),
43         m_RemoteTarget(Target),
44         m_cRefs(1)
45     {
46     }
47 
~FxIoTargetRemoteNotificationCallback()48     ~FxIoTargetRemoteNotificationCallback() {};
49 
50     WUDF_TARGET_CONTEXT
GetRegistrationId(VOID)51     GetRegistrationId(
52         VOID
53         )
54     {
55         return m_RemoteTarget->m_TargetNotifyHandle;
56     }
57 
58     BOOL
59     __stdcall
60     OnQueryRemove(
61         _In_ WUDF_TARGET_CONTEXT RegistrationID
62         );
63 
64     VOID
65     __stdcall
66     OnRemoveCanceled(
67         _In_ WUDF_TARGET_CONTEXT RegistrationID
68         );
69 
70     VOID
71     __stdcall
72     OnRemoveComplete(
73         _In_ WUDF_TARGET_CONTEXT RegistrationID
74         );
75 
76     VOID
77     __stdcall
78     OnCustomEvent(
79         _In_ WUDF_TARGET_CONTEXT  RegistrationID,
80         _In_ REFGUID Event,
81         _In_reads_bytes_(DataSize) BYTE * Data,
82         _In_ DWORD DataSize,
83         _In_ DWORD NameBufferOffset
84         );
85 
86     HRESULT
87     __stdcall
QueryInterface(__in const IID & iid,__out void ** ppv)88     QueryInterface(
89         __in  const IID& iid,
90         __out void ** ppv
91         )
92     {
93         if (NULL == ppv) {
94             return E_INVALIDARG;
95         }
96 
97         *ppv = NULL;
98 
99         if ( iid == IID_IUnknown) {
100             *ppv = static_cast<IUnknown *> (this);
101         }
102         else if ( iid == IID_IWudfTargetCallbackDeviceChange) {
103             *ppv = static_cast<IWudfTargetCallbackDeviceChange *> (this);
104         }
105         else {
106             return E_INVALIDARG;
107         }
108 
109         this->AddRef();
110         return S_OK;
111     }
112 
113     ULONG
114     __stdcall
AddRef()115     AddRef(
116         )
117     {
118         LONG cRefs = InterlockedIncrement( &m_cRefs );
119         return cRefs;
120     }
121 
122     ULONG
123     __stdcall
Release()124     Release(
125         )
126     {
127         LONG cRefs = InterlockedDecrement( &m_cRefs );
128         if (0 == cRefs) {
129             //
130             // The lifetime of this object is controlled by FxIoTargetRemote
131             // object (the container object), and not by this ref count. This
132             // method is implemented just to satisfy the interface implemetation
133             // requirement.
134             //
135             DO_NOTHING();
136         }
137 
138         return cRefs;
139     }
140 };
141 
142