ReactOS 0.4.16-dev-136-g52192f1
pincontrol.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS BDA Proxy
4 * FILE: dll/directx/bdaplgin/pincontrol.cpp
5 * PURPOSE: ClassFactory interface
6 *
7 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8 */
9
10#include "precomp.h"
11
12#ifndef _MSC_VER
13const GUID KSPROPSETID_BdaPinControl = {0x0ded49d5, 0xa8b7, 0x4d5d, {0x97, 0xa1, 0x12, 0xb0, 0xc1, 0x95, 0x87, 0x4d}};
14const GUID IID_IBDA_PinControl = {0x0DED49D5, 0xA8B7, 0x4d5d, {0x97, 0xA1, 0x12, 0xB0, 0xC1, 0x95, 0x87, 0x4D}};
15const GUID IID_IPin = {0x56a86891, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
16#endif
17
18
20{
21public:
23
25 {
27 return m_Ref;
28 }
30 {
32 if (!m_Ref)
33 {
34 delete this;
35 return 0;
36 }
37 return m_Ref;
38 }
39 // IBDA_PinControl methods
43
44
45 CBDAPinControl(HANDLE hFile, IBDA_NetworkProvider * pProvider, IPin * pConnectedPin, ULONG RegistrationCtx) : m_Ref(0), m_Handle(hFile), m_pProvider(pProvider), m_pConnectedPin(pConnectedPin), m_RegistrationCtx(RegistrationCtx){};
47 {
48 //m_pConnectedPin->Release();
49 //m_pProvider->Release();
50 };
51
52protected:
58};
59
63 IN REFIID refiid,
65{
66 *Output = NULL;
67 if (IsEqualGUID(refiid, IID_IUnknown))
68 {
69 *Output = PVOID(this);
70 reinterpret_cast<IUnknown*>(*Output)->AddRef();
71 return NOERROR;
72 }
74 {
75 *Output = (IBDA_PinControl*)(this);
76 reinterpret_cast<IBDA_PinControl*>(*Output)->AddRef();
77 return NOERROR;
78 }
80 return E_NOINTERFACE;
81}
82//-------------------------------------------------------------------
83// IBDA_PinControl methods
84//
88{
91 HRESULT hr;
92
93 // setup request
97
98 // perform request
100
101#ifdef BDAPLGIN_TRACE
102 WCHAR Buffer[100];
103 swprintf(Buffer, L"CBDAPinControl::GetPinID: hr %lx pulPinID %lu BytesReturned %lx\n", hr, *pulPinID, BytesReturned);
105#endif
106
107 return hr;
108}
109
113{
116 HRESULT hr;
117
118 // setup request
122
123 // perform request
125
126#ifdef BDAPLGIN_TRACE
127 WCHAR Buffer[100];
128 swprintf(Buffer, L"CBDAPinControl::GetPinType: hr %lx pulPinType %lu BytesReturned %lx\n", hr, *pulPinType, BytesReturned);
130#endif
131
132 return hr;
133}
134
138{
139#ifdef BDAPLGIN_TRACE
140 OutputDebugStringW(L"CBDAPinControl::RegistrationContext\n");
141#endif
142
143 if (!pulRegistrationCtx)
144 {
145 // invalid argument
146 return E_POINTER;
147 }
148
150 {
151 // is registered
152 *pulRegistrationCtx = m_RegistrationCtx;
153 return NOERROR;
154 }
155
156 //pin not registered
157 return E_FAIL;
158}
159
160//-------------------------------------------------------------------
163 IFilterGraph * pGraph,
164 IBDA_NetworkProvider ** pOutNetworkProvider)
165{
166 IEnumFilters *pEnumFilters = NULL;
167 IBaseFilter * ppFilter[1];
168 IBDA_NetworkProvider * pNetworkProvider = NULL;
169 HRESULT hr;
170
171 // get IEnumFilters interface
172 hr = pGraph->EnumFilters(&pEnumFilters);
173
174 if (FAILED(hr))
175 {
176 //clean up
177 *pOutNetworkProvider = NULL;
178 return hr;
179 }
180
181 while(pEnumFilters->Next(1, ppFilter, NULL) == S_OK)
182 {
183 // check if that filter supports the IBDA_NetworkProvider interface
184 hr = ppFilter[0]->QueryInterface(IID_IBDA_NetworkProvider, (void**)&pNetworkProvider);
185
186 // release IBaseFilter
187 ppFilter[0]->Release();
188
189 if (SUCCEEDED(hr))
190 break;
191 }
192
193 // release IEnumFilters interface
194 pEnumFilters->Release();
195
196 //store result
197 *pOutNetworkProvider = pNetworkProvider;
198
199 if (pNetworkProvider)
200 return S_OK;
201 else
202 return E_FAIL;
203}
204
207 HANDLE hPin,
208 IBDA_NetworkProvider *pNetworkProvider,
209 IPin * pConnectedPin,
210 ULONG RegistrationCtx,
211 IUnknown * pUnkOuter,
212 REFIID riid,
213 LPVOID * ppv)
214{
215 CBDAPinControl * handler = new CBDAPinControl(hPin, pNetworkProvider, pConnectedPin, RegistrationCtx);
216
217#ifdef BDAPLGIN_TRACE
218 OutputDebugStringW(L"CBDAPinControl_fnConstructor\n");
219#endif
220
221 if (!handler)
222 return E_OUTOFMEMORY;
223
224 if (FAILED(handler->QueryInterface(riid, ppv)))
225 {
226 /* not supported */
227 delete handler;
228 return E_NOINTERFACE;
229 }
230
231 return NOERROR;
232}
233
235WINAPI
237 IUnknown * pUnkOuter,
238 REFIID riid,
239 LPVOID * ppv)
240{
241 IPin * pConnectedPin = NULL;
242 IBDA_NetworkProvider * pNetworkProvider = NULL;
244 HRESULT hr;
245 IKsObject * pObject = NULL;
246 IPin * pPin = NULL;
248 PIN_INFO PinInfo;
249 FILTER_INFO FilterInfo;
250 ULONG RegistrationCtx = 0;
251
252 if (!pUnkOuter)
253 return E_POINTER;
254
255 OutputDebugStringW(L"CBDAPinControl_fnConstructor\n");
256 //DebugBreak();
257
258 // query for IKsObject interface
259 hr = pUnkOuter->QueryInterface(IID_IKsObject, (void**)&pObject);
260
261 if (FAILED(hr))
262 return hr;
263
264 // query for IPin interface
265 hr = pObject->QueryInterface(IID_IPin, (void**)&pPin);
266
267 if (FAILED(hr))
268 {
269 //clean up
270 pObject->Release();
271 return hr;
272 }
273
274 // get pin info
275 hr = pPin->QueryPinInfo(&PinInfo);
276
277 if (FAILED(hr))
278 {
279 //clean up
280 pObject->Release();
281 pPin->Release();
282 return hr;
283 }
284
285 if (!PinInfo.pFilter)
286 {
287 //clean up
288 pObject->Release();
289 pPin->Release();
290 return hr;
291 }
292
293 // sanity checks
294 assert(PinInfo.pFilter != NULL);
295
296 // query filter info
297 hr = PinInfo.pFilter->QueryFilterInfo(&FilterInfo);
298
299 // sanity check
300 assert(FilterInfo.pGraph != NULL);
301
302 // get network provider interface
303 hr = GetNetworkProviderFromGraph(FilterInfo.pGraph, &pNetworkProvider);
304
305 if (SUCCEEDED(hr))
306 {
307 if (PinInfo.dir == PINDIR_OUTPUT)
308 {
309 // get connected pin handle
310 hr = pPin->ConnectedTo(&pConnectedPin);
311 if (SUCCEEDED(hr))
312 {
313 // get file handle
314 hFile = pObject->KsGetObjectHandle();
315 if (hFile)
316 {
317 hr = CBDAPinControl_RealConstructor(hFile, pNetworkProvider, pConnectedPin, 0, pUnkOuter, riid, ppv);
318 if (SUCCEEDED(hr))
319 {
320 // set to null to prevent releasing
321 pNetworkProvider = NULL;
322 pConnectedPin = NULL;
323 }
324 }
325 else
326 {
327 // expected file handle
329 }
330 }
331 }
332 else
333 {
334 // get IUnknown from base filter
335 hr = PinInfo.pFilter->QueryInterface(IID_IUnknown, (void**)&pUnknown);
336 if (SUCCEEDED(hr))
337 {
338 // register device filter
339 OutputDebugStringW(L"CBDAPinControl_fnConstructor registering device filter with network provider\n");
340 hr = pNetworkProvider->RegisterDeviceFilter(pUnknown, &RegistrationCtx);
341 if (SUCCEEDED(hr))
342 {
343 // get file handle
344 hFile = pObject->KsGetObjectHandle();
345 if (hFile)
346 {
347 hr = CBDAPinControl_RealConstructor(hFile, pNetworkProvider, NULL, RegistrationCtx, pUnkOuter, riid, ppv);
348 if (SUCCEEDED(hr))
349 {
350 // set to null to prevent releasing
351 pNetworkProvider = NULL;
352 }
353 }
354 else
355 {
356 // expected file handle
358 }
359 }
360 else
361 {
362 WCHAR Buffer[100];
363 swprintf(Buffer, L"CBDAPinControl_fnConstructor failed to register filter with %lx\n", hr);
365 }
366 }
367 }
368 }
369
370 // release IFilterGraph interface
371 FilterInfo.pGraph->Release();
372
373 // release IBaseFilter interface
374 PinInfo.pFilter->Release();
375
376 // release IPin
377 pPin->Release();
378
379 // release IKsObject
380 pObject->Release();
381
382
383 if (pNetworkProvider)
384 {
385 // release network provider
386 pNetworkProvider->Release();
387 }
388
389 if (pConnectedPin)
390 {
391 // release connected pin
392 pConnectedPin->Release();
393 }
394
395 if (pUnknown)
396 {
397 // release filter
398 pUnknown->Release();
399 }
400
401 return hr;
402}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
@ PINDIR_OUTPUT
Definition: axcore.idl:42
#define STDMETHODIMP
Definition: basetyps.h:43
@ KSPROPERTY_BDA_PIN_TYPE
Definition: bdamedia.h:195
@ KSPROPERTY_BDA_PIN_ID
Definition: bdamedia.h:194
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
Definition: bufpool.h:45
CBDAPinControl(HANDLE hFile, IBDA_NetworkProvider *pProvider, IPin *pConnectedPin, ULONG RegistrationCtx)
Definition: pincontrol.cpp:45
HRESULT STDMETHODCALLTYPE GetPinType(ULONG *pulPinType)
Definition: pincontrol.cpp:112
HRESULT STDMETHODCALLTYPE RegistrationContext(ULONG *pulRegistrationCtx)
Definition: pincontrol.cpp:137
HRESULT STDMETHODCALLTYPE GetPinID(ULONG *pulPinID)
Definition: pincontrol.cpp:87
STDMETHODIMP_(ULONG) AddRef()
Definition: pincontrol.cpp:24
virtual ~CBDAPinControl()
Definition: pincontrol.cpp:46
STDMETHODIMP_(ULONG) Release()
Definition: pincontrol.cpp:29
IPin * m_pConnectedPin
Definition: pincontrol.cpp:56
ULONG m_RegistrationCtx
Definition: pincontrol.cpp:57
IBDA_NetworkProvider * m_pProvider
Definition: pincontrol.cpp:55
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: pincontrol.cpp:62
virtual ULONG Release(__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
Definition: fxobject.hpp:853
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__in FxQueryInterfaceParams *Params)
Definition: fxobject.cpp:255
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
const GUID IID_IKsObject
const GUID IID_IBDA_NetworkProvider
#define NULL
Definition: types.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
#define swprintf
Definition: precomp.h:40
#define assert(x)
Definition: debug.h:53
_In_ PUNKNOWN pUnknown
Definition: drmk.h:76
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
FxObject * pObject
FxWmiProvider * pProvider
Definition: fxwmiapi.cpp:54
void WINAPI SHIM_OBJ_NAME() OutputDebugStringW(LPCWSTR lpOutputString)
Definition: ignoredbgout.c:23
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT RegisterDeviceFilter([in] IUnknown *pUnkFilterControl, [in, out] ULONG *ppvRegisitrationContext)
HRESULT Next([in] ULONG cFilters, [out] IBaseFilter **ppFilter, [out] ULONG *pcFetched)
HRESULT EnumFilters([out] IEnumFilters **ppEnum)
Definition: axcore.idl:92
HRESULT QueryPinInfo([out] PIN_INFO *pInfo)
HRESULT ConnectedTo([out] IPin **pPin)
ULONG AddRef()
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
KSDDKAPI HRESULT WINAPI KsSynchronousDeviceControl(HANDLE Handle, ULONG IoControl, PVOID InBuffer, ULONG InLength, PVOID OutBuffer, ULONG OutLength, PULONG BytesReturned)
Definition: ksproxy.cpp:34
_In_ HANDLE hFile
Definition: mswsock.h:90
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
const GUID KSPROPSETID_BdaPinControl
Definition: pincontrol.cpp:13
HRESULT GetNetworkProviderFromGraph(IFilterGraph *pGraph, IBDA_NetworkProvider **pOutNetworkProvider)
Definition: pincontrol.cpp:162
HRESULT WINAPI CBDAPinControl_fnConstructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
Definition: pincontrol.cpp:236
const GUID IID_IBDA_PinControl
Definition: pincontrol.cpp:14
HRESULT CBDAPinControl_RealConstructor(HANDLE hPin, IBDA_NetworkProvider *pNetworkProvider, IPin *pConnectedPin, ULONG RegistrationCtx, IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
Definition: pincontrol.cpp:206
const GUID IID_IPin
Definition: pincontrol.cpp:15
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
@ Output
Definition: arc.h:85
HRESULT hr
Definition: shlfolder.c:183
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesReturned
Definition: wdfiotarget.h:1052
void WINAPI DebugBreak(void)
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
#define NOERROR
Definition: winerror.h:2354
#define E_UNEXPECTED
Definition: winerror.h:2456
#define E_POINTER
Definition: winerror.h:2365
__wchar_t WCHAR
Definition: xmlstorage.h:180