1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS BDA Proxy
4  * FILE:            dll/directx/msvidctl/tuningspace_container.cpp
5  * PURPOSE:         ITuningSpaceContainer interface
6  *
7  * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 #define _FORCENAMELESSUNION
10 #include "precomp.h"
11 
12 
13 class CTuningSpaceContainer : public ITuningSpaceContainer
14 {
15 public:
16 
17     STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
18 
19     STDMETHODIMP_(ULONG) AddRef()
20     {
21         InterlockedIncrement(&m_Ref);
22         return m_Ref;
23     }
24     STDMETHODIMP_(ULONG) Release()
25     {
26         InterlockedDecrement(&m_Ref);
27         if (!m_Ref)
28         {
29             OutputDebugStringW(L"CTuningSpaceContainer::Release : delete\n");
30             //delete this;
31             return 0;
32         }
33         return m_Ref;
34     }
35 
36      // IDispatch methods
37      HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT *pctinfo);
38      HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo);
39      HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId);
40      HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
41 
42      //ITuningSpaceContainer methods
43      HRESULT STDMETHODCALLTYPE get_Count(long *Count);
44      HRESULT STDMETHODCALLTYPE get__NewEnum(IEnumVARIANT **NewEnum);
45      HRESULT STDMETHODCALLTYPE get_Item(VARIANT varIndex, ITuningSpace **TuningSpace);
46      HRESULT STDMETHODCALLTYPE put_Item(VARIANT varIndex, ITuningSpace *TuningSpace);
47      HRESULT STDMETHODCALLTYPE TuningSpacesForCLSID(BSTR SpaceCLSID, ITuningSpaces **NewColl);
48      HRESULT STDMETHODCALLTYPE _TuningSpacesForCLSID(REFCLSID SpaceCLSID, ITuningSpaces **NewColl);
49      HRESULT STDMETHODCALLTYPE TuningSpacesForName(BSTR Name, ITuningSpaces **NewColl);
50      HRESULT STDMETHODCALLTYPE FindID(ITuningSpace *TuningSpace, long *ID);
51      HRESULT STDMETHODCALLTYPE Add(ITuningSpace *TuningSpace, VARIANT *NewIndex);
52      HRESULT STDMETHODCALLTYPE get_EnumTuningSpaces(IEnumTuningSpaces **ppEnum);
53      HRESULT STDMETHODCALLTYPE Remove(VARIANT Index);
54      HRESULT STDMETHODCALLTYPE get_MaxCount(long *MaxCount);
55      HRESULT STDMETHODCALLTYPE put_MaxCount(long MaxCount);
56 
57     CTuningSpaceContainer() : m_Ref(0){};
58 
59     virtual ~CTuningSpaceContainer(){};
60 
61 protected:
62     LONG m_Ref;
63 
64 };
65 
66 HRESULT
67 STDMETHODCALLTYPE
68 CTuningSpaceContainer::QueryInterface(
69     IN  REFIID refiid,
70     OUT PVOID* Output)
71 {
72     if (IsEqualGUID(refiid, IID_IUnknown))
73     {
74         *Output = PVOID(this);
75         reinterpret_cast<IUnknown*>(*Output)->AddRef();
76         return NOERROR;
77     }
78 
79     if (IsEqualGUID(refiid, IID_ITuningSpaceContainer))
80     {
81         *Output = (ITuningSpaceContainer*)this;
82         reinterpret_cast<ITuningSpaceContainer*>(*Output)->AddRef();
83         return NOERROR;
84     }
85 
86     WCHAR Buffer[MAX_PATH];
87     LPOLESTR lpstr;
88     StringFromCLSID(refiid, &lpstr);
89     swprintf(Buffer, L"CTuningSpaceContainer::QueryInterface: NoInterface for %s", lpstr);
90     OutputDebugStringW(Buffer);
91     CoTaskMemFree(lpstr);
92 
93 
94     return E_NOINTERFACE;
95 }
96 
97 //-------------------------------------------------------------------
98 // IDispatch methods
99 //
100 HRESULT
101 STDMETHODCALLTYPE
102 CTuningSpaceContainer::GetTypeInfoCount(UINT *pctinfo)
103 {
104     OutputDebugStringW(L"CTuningSpaceContainer::GetTypeInfoCount : NotImplemented\n");
105     return E_NOTIMPL;
106 }
107 
108 HRESULT
109 STDMETHODCALLTYPE
110 CTuningSpaceContainer::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
111 {
112     OutputDebugStringW(L"CTuningSpaceContainer::GetTypeInfo : NotImplemented\n");
113     return E_NOTIMPL;
114 }
115 HRESULT
116 STDMETHODCALLTYPE
117 CTuningSpaceContainer::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
118 {
119     OutputDebugStringW(L"CTuningSpaceContainer::GetIDsOfNames : NotImplemented\n");
120     return E_NOTIMPL;
121 }
122 HRESULT
123 STDMETHODCALLTYPE
124 CTuningSpaceContainer::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
125 {
126     OutputDebugStringW(L"CTuningSpaceContainer::Invoke : NotImplemented\n");
127     return E_NOTIMPL;
128 }
129 
130 //-------------------------------------------------------------------
131 // ITuningSpaceContainer methods
132 //
133 
134 HRESULT
135 STDMETHODCALLTYPE
136 CTuningSpaceContainer::get_Count(long *Count)
137 {
138     OutputDebugStringW(L"CTuningSpaceContainer::get_Count : NotImplemented\n");
139     return E_NOTIMPL;
140 }
141 HRESULT
142 STDMETHODCALLTYPE
143 CTuningSpaceContainer::get__NewEnum(IEnumVARIANT **NewEnum)
144 {
145     OutputDebugStringW(L"CTuningSpaceContainer::get__NewEnum : NotImplemented\n");
146     return E_NOTIMPL;
147 }
148 
149 HRESULT
150 STDMETHODCALLTYPE
151 CTuningSpaceContainer::get_Item(VARIANT varIndex, ITuningSpace **TuningSpace)
152 {
153 #ifdef MSVIDCTL_TRACE
154     WCHAR Buffer[100];
155 	swprintf(Buffer, L"CTuningSpaceContainer::get_Item : type %x value %s stub\n", varIndex.vt, varIndex.bstrVal);
156     OutputDebugStringW(Buffer);
157 #endif
158 
159     return CTuningSpace_fnConstructor(NULL, IID_ITuningSpace, (void**)TuningSpace);
160 }
161 HRESULT
162 STDMETHODCALLTYPE
163 CTuningSpaceContainer::put_Item(VARIANT varIndex, ITuningSpace *TuningSpace)
164 {
165     OutputDebugStringW(L"CTuningSpaceContainer::put_Item : NotImplemented\n");
166     return E_NOTIMPL;
167 }
168 
169 HRESULT
170 STDMETHODCALLTYPE
171 CTuningSpaceContainer::TuningSpacesForCLSID(BSTR SpaceCLSID, ITuningSpaces **NewColl)
172 {
173     OutputDebugStringW(L"CTuningSpaceContainer::TuningSpacesForCLSID : NotImplemented\n");
174     return E_NOTIMPL;
175 }
176 HRESULT
177 STDMETHODCALLTYPE
178 CTuningSpaceContainer::_TuningSpacesForCLSID(REFCLSID SpaceCLSID, ITuningSpaces **NewColl)
179 {
180     OutputDebugStringW(L"CTuningSpaceContainer::_TuningSpacesForCLSID : NotImplemented\n");
181     return E_NOTIMPL;
182 }
183 
184 HRESULT
185 STDMETHODCALLTYPE
186 CTuningSpaceContainer::TuningSpacesForName(BSTR Name, ITuningSpaces **NewColl)
187 {
188     OutputDebugStringW(L"CTuningSpaceContainer::TuningSpacesForName : NotImplemented\n");
189     return E_NOTIMPL;
190 }
191 
192 HRESULT
193 STDMETHODCALLTYPE
194 CTuningSpaceContainer::FindID(ITuningSpace *TuningSpace, long *ID)
195 {
196     OutputDebugStringW(L"CTuningSpaceContainer::FindID : NotImplemented\n");
197     return E_NOTIMPL;
198 }
199 
200 HRESULT
201 STDMETHODCALLTYPE
202 CTuningSpaceContainer::Add(ITuningSpace *TuningSpace, VARIANT *NewIndex)
203 {
204     OutputDebugStringW(L"CTuningSpaceContainer::Add : stub\n");
205     TuningSpace->AddRef();
206     NewIndex->vt = VT_BSTR;
207     InterlockedIncrement(&m_Ref);
208     return TuningSpace->get_FriendlyName(&NewIndex->bstrVal);
209 }
210 HRESULT
211 STDMETHODCALLTYPE
212 CTuningSpaceContainer::get_EnumTuningSpaces(IEnumTuningSpaces **ppEnum)
213 {
214     OutputDebugStringW(L"CTuningSpaceContainer::get_EnumTuningSpaces : stub\n");
215     return CEnumTuningSpaces_fnConstructor(NULL, IID_IEnumTuningSpaces, (void**)ppEnum);
216 }
217 
218 HRESULT
219 STDMETHODCALLTYPE
220 CTuningSpaceContainer::Remove(VARIANT Index)
221 {
222     OutputDebugStringW(L"CTuningSpaceContainer::Remove: NotImplemented\n");
223     return E_NOTIMPL;
224 }
225 
226 HRESULT
227 STDMETHODCALLTYPE
228 CTuningSpaceContainer::get_MaxCount(long *MaxCount)
229 {
230     OutputDebugStringW(L"CTuningSpaceContainer::get_MaxCount : NotImplemented\n");
231     return E_NOTIMPL;
232 }
233 
234 HRESULT
235 STDMETHODCALLTYPE
236 CTuningSpaceContainer::put_MaxCount(long MaxCount)
237 {
238     OutputDebugStringW(L"CTuningSpaceContainer::put_MaxCount : NotImplemented\n");
239     return E_NOTIMPL;
240 }
241 
242 
243 HRESULT
244 WINAPI
245 CTuningSpaceContainer_fnConstructor(
246     IUnknown *pUnknown,
247     REFIID riid,
248     LPVOID * ppv)
249 {
250     // construct device control
251     CTuningSpaceContainer * provider = new CTuningSpaceContainer();
252 
253 #ifdef MSVIDCTL_TRACE
254     WCHAR Buffer[MAX_PATH];
255     LPOLESTR lpstr;
256     StringFromCLSID(riid, &lpstr);
257     swprintf(Buffer, L"CTuningSpaceContainer_fnConstructor riid %s pUnknown %p\n", lpstr, pUnknown);
258     OutputDebugStringW(Buffer);
259 #endif
260 
261     if (!provider)
262         return E_OUTOFMEMORY;
263 
264     if (FAILED(provider->QueryInterface(riid, ppv)))
265     {
266         /* not supported */
267         delete provider;
268         return E_NOINTERFACE;
269     }
270 
271     return NOERROR;
272 }