ReactOS  0.4.12-dev-708-g95ed44e
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
13 const GUID KSPROPSETID_BdaPinControl = {0x0ded49d5, 0xa8b7, 0x4d5d, {0x97, 0xa1, 0x12, 0xb0, 0xc1, 0x95, 0x87, 0x4d}};
14 const GUID IID_IBDA_PinControl = {0x0DED49D5, 0xA8B7, 0x4d5d, {0x97, 0xA1, 0x12, 0xB0, 0xC1, 0x95, 0x87, 0x4D}};
15 const GUID IID_IPin = {0x56a86891, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}};
16 #endif
17 
18 
20 {
21 public:
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){};
46  virtual ~CBDAPinControl()
47  {
48  //m_pConnectedPin->Release();
49  //m_pProvider->Release();
50  };
51 
52 protected:
53  LONG m_Ref;
58 };
59 
60 HRESULT
63  IN REFIID refiid,
64  OUT PVOID* Output)
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  }
73  if (IsEqualGUID(refiid, IID_IBDA_PinControl))
74  {
75  *Output = (IBDA_PinControl*)(this);
76  reinterpret_cast<IBDA_PinControl*>(*Output)->AddRef();
77  return NOERROR;
78  }
79 DebugBreak();
80  return E_NOINTERFACE;
81 }
82 //-------------------------------------------------------------------
83 // IBDA_PinControl methods
84 //
85 HRESULT
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 
110 HRESULT
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 
135 HRESULT
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 
149  if (m_RegistrationCtx)
150  {
151  // is registered
152  *pulRegistrationCtx = m_RegistrationCtx;
153  return NOERROR;
154  }
155 
156  //pin not registered
157  return E_FAIL;
158 }
159 
160 //-------------------------------------------------------------------
161 HRESULT
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 
205 HRESULT
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 
234 HRESULT
235 WINAPI
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;
247  IUnknown * pUnknown = 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
328  hr = E_UNEXPECTED;
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
357  hr = E_UNEXPECTED;
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 }
HRESULT STDMETHODCALLTYPE GetPinType(ULONG *pulPinType)
Definition: pincontrol.cpp:112
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
#define IN
Definition: typedefs.h:38
#define REFIID
Definition: guiddef.h:113
CBDAPinControl(HANDLE hFile, IBDA_NetworkProvider *pProvider, IPin *pConnectedPin, ULONG RegistrationCtx)
Definition: pincontrol.cpp:45
#define E_NOINTERFACE
Definition: winerror.h:2364
HRESULT hr
Definition: shlfolder.c:183
#define NOERROR
Definition: winerror.h:2354
const GUID IID_IKsObject
__wchar_t WCHAR
Definition: xmlstorage.h:180
REFIID riid
Definition: precomp.h:44
virtual ~CBDAPinControl()
Definition: pincontrol.cpp:46
const GUID IID_IBDA_PinControl
Definition: pincontrol.cpp:14
HRESULT STDMETHODCALLTYPE RegistrationContext(ULONG *pulRegistrationCtx)
Definition: pincontrol.cpp:137
const GUID KSPROPSETID_BdaPinControl
Definition: pincontrol.cpp:13
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define assert(x)
Definition: debug.h:53
KSDDKAPI HRESULT WINAPI KsSynchronousDeviceControl(HANDLE Handle, ULONG IoControl, PVOID InBuffer, ULONG InLength, PVOID OutBuffer, ULONG OutLength, PULONG BytesReturned)
Definition: ksproxy.cpp:34
HRESULT RegisterDeviceFilter([in] IUnknown *pUnkFilterControl, [in, out] ULONG *ppvRegisitrationContext)
#define E_FAIL
Definition: ddrawi.h:102
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
void WINAPI SHIM_OBJ_NAME() OutputDebugStringW(LPCWSTR lpOutputString)
Definition: ignoredbgout.c:23
STDMETHODIMP_(ULONG) AddRef()
Definition: pincontrol.cpp:24
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
long LONG
Definition: pedump.c:60
#define STDMETHODIMP
Definition: basetyps.h:43
ULONG Release()
void WINAPI DebugBreak(void)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
_In_ PUNKNOWN pUnknown
Definition: drmk.h:76
IBDA_NetworkProvider * m_pProvider
Definition: pincontrol.cpp:55
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
nsrefcnt Release()
ULONG AddRef()
STDMETHODIMP_(ULONG) Release()
Definition: pincontrol.cpp:29
HRESULT CBDAPinControl_RealConstructor(HANDLE hPin, IBDA_NetworkProvider *pNetworkProvider, IPin *pConnectedPin, ULONG RegistrationCtx, IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
Definition: pincontrol.cpp:206
static const WCHAR L[]
Definition: oid.c:1250
#define InterlockedDecrement
Definition: armddk.h:52
Definition: arc.h:85
_In_ HANDLE hFile
Definition: mswsock.h:90
#define WINAPI
Definition: msvc.h:20
_In_ DWORD Property
Definition: setupapi.h:1545
HRESULT STDMETHODCALLTYPE GetPinID(ULONG *pulPinID)
Definition: pincontrol.cpp:87
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
HRESULT Next([in] ULONG cFilters, [out] IBaseFilter **ppFilter, [out] ULONG *pcFetched)
Definition: axcore.idl:91
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
IPin * m_pConnectedPin
Definition: pincontrol.cpp:56
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
#define E_UNEXPECTED
Definition: winerror.h:2456
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define OUT
Definition: typedefs.h:39
const GUID IID_IBDA_NetworkProvider
unsigned int ULONG
Definition: retypes.h:1
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7782
HRESULT EnumFilters([out] IEnumFilters **ppEnum)
#define E_POINTER
Definition: winerror.h:2365
nsresult QueryInterface(nsIIDRef riid, void **result)
ULONG m_RegistrationCtx
Definition: pincontrol.cpp:57
const GUID IID_IPin
Definition: pincontrol.cpp:15
HRESULT WINAPI CBDAPinControl_fnConstructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
Definition: pincontrol.cpp:236
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: pincontrol.cpp:62
HRESULT GetNetworkProviderFromGraph(IFilterGraph *pGraph, IBDA_NetworkProvider **pOutNetworkProvider)
Definition: pincontrol.cpp:162
#define SUCCEEDED(hr)
Definition: intsafe.h:57