[BDAPLGIN]
[reactos.git] / reactos / dll / directx / bdaplgin / controlnode.cpp
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS BDA Proxy
4 * FILE: dll/directx/bdaplgin/controlnode.cpp
5 * PURPOSE: ControlNode interface
6 *
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
8 */
9
10 #include "precomp.h"
11
12 #ifndef _MSC_VER
13 const GUID IID_IKsPropertySet = {0x31efac30, 0x515c, 0x11d0, {0xa9,0xaa, 0x00,0xaa,0x00,0x61,0xbe,0x93}};
14 #endif
15
16 class CControlNode : public IUnknown
17 {
18 public:
19 STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
20
21 STDMETHODIMP_(ULONG) AddRef()
22 {
23 InterlockedIncrement(&m_Ref);
24 return m_Ref;
25 }
26 STDMETHODIMP_(ULONG) Release()
27 {
28 InterlockedDecrement(&m_Ref);
29 if (!m_Ref)
30 {
31 delete this;
32 return 0;
33 }
34 return m_Ref;
35 }
36
37 CControlNode(HANDLE hFile, ULONG NodeType, ULONG PinId) : m_Ref(0), m_hFile(hFile), m_NodeType(NodeType), m_PinId(PinId){};
38 virtual ~CControlNode(){};
39
40 protected:
41 LONG m_Ref;
42 HANDLE m_hFile;
43 ULONG m_NodeType;
44 ULONG m_PinId;
45 };
46
47 HRESULT
48 STDMETHODCALLTYPE
49 CControlNode::QueryInterface(
50 IN REFIID refiid,
51 OUT PVOID* Output)
52 {
53 *Output = NULL;
54
55 if (IsEqualGUID(refiid, IID_IUnknown))
56 {
57 *Output = PVOID(this);
58 reinterpret_cast<IUnknown*>(*Output)->AddRef();
59 return NOERROR;
60 }
61 else if(IsEqualGUID(refiid, IID_IBDA_FrequencyFilter))
62 {
63 return CBDAFrequencyFilter_fnConstructor(m_hFile, m_NodeType, refiid, Output);
64 }
65 else if(IsEqualGUID(refiid, IID_IBDA_SignalStatistics))
66 {
67 return CBDASignalStatistics_fnConstructor(m_hFile, m_NodeType, refiid, Output);
68 }
69 else if(IsEqualGUID(refiid, IID_IBDA_LNBInfo))
70 {
71 return CBDALNBInfo_fnConstructor(m_hFile, m_NodeType, refiid, Output);
72 }
73 else if(IsEqualGUID(refiid, IID_IBDA_DigitalDemodulator))
74 {
75 return CBDADigitalDemodulator_fnConstructor(m_hFile, m_NodeType, refiid, Output);
76 }
77 #ifdef BDAPLGIN_TRACE
78 WCHAR Buffer[MAX_PATH];
79 LPOLESTR lpstr;
80 StringFromCLSID(refiid, &lpstr);
81 swprintf(Buffer, L"CControlNode::QueryInterface: NoInterface for %s", lpstr);
82 OutputDebugStringW(Buffer);
83 CoTaskMemFree(lpstr);
84 #endif
85
86 return E_NOINTERFACE;
87 }
88
89
90 HRESULT
91 WINAPI
92 CControlNode_fnConstructor(
93 IBaseFilter * pFilter,
94 ULONG NodeType,
95 ULONG PinId,
96 REFIID riid,
97 LPVOID * ppv)
98 {
99 WCHAR Buffer[100];
100 HRESULT hr;
101 IPin * pPin = NULL;
102 IKsObject * pObject = NULL;
103 HANDLE hFile = INVALID_HANDLE_VALUE;
104
105 // store pin id
106 swprintf(Buffer, L"%u", PinId);
107
108 // try find target pin
109 hr = pFilter->FindPin(Buffer, &pPin);
110
111 if (FAILED(hr))
112 {
113 #ifdef BDAPLGIN_TRACE
114 swprintf(Buffer, L"CControlNode_fnConstructor failed find pin %lu with %lx\n", PinId, hr);
115 OutputDebugStringW(Buffer);
116 #endif
117 return hr;
118 }
119
120 // query IKsObject interface
121 hr = pPin->QueryInterface(IID_IKsObject, (void**)&pObject);
122
123 #ifdef BDAPLGIN_TRACE
124 swprintf(Buffer, L"CControlNode_fnConstructor get IID_IKsObject status %lx\n", hr);
125 OutputDebugStringW(Buffer);
126 #endif
127
128 if (SUCCEEDED(hr))
129 {
130 // get pin handle
131 hFile = pObject->KsGetObjectHandle();
132 // release IKsObject interface
133 pObject->Release();
134 }
135 // release IPin interface
136 pPin->Release();
137
138 // construct device control
139 CControlNode * handler = new CControlNode(hFile, NodeType, PinId);
140
141 #ifdef BDAPLGIN_TRACE
142 OutputDebugStringW(L"CControlNode_fnConstructor\n");
143 #endif
144
145 if (!handler)
146 return E_OUTOFMEMORY;
147
148 if (FAILED(handler->QueryInterface(riid, ppv)))
149 {
150 /* not supported */
151 delete handler;
152 return E_NOINTERFACE;
153 }
154
155 return NOERROR;
156 }