5d71d5355d2eba0cf9b638da88e55b5e585f818d
[reactos.git] / reactos / dll / directx / ksproxy / enumpins.cpp
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Network Provider for MPEG2 based networks
4 * FILE: dll/directx/msdvbnp/enumpins.cpp
5 * PURPOSE: IEnumPins interface
6 *
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
8 */
9 #include "precomp.h"
10
11 class CEnumPins : public IEnumPins
12 {
13 public:
14 STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
15
16 STDMETHODIMP_(ULONG) AddRef()
17 {
18 InterlockedIncrement(&m_Ref);
19 return m_Ref;
20 }
21 STDMETHODIMP_(ULONG) Release()
22 {
23 InterlockedDecrement(&m_Ref);
24 if (!m_Ref)
25 {
26 delete this;
27 return 0;
28 }
29 return m_Ref;
30 }
31
32
33 HRESULT STDMETHODCALLTYPE Next(ULONG cPins, IPin **ppPins, ULONG *pcFetched);
34 HRESULT STDMETHODCALLTYPE Skip(ULONG cPins);
35 HRESULT STDMETHODCALLTYPE Reset();
36 HRESULT STDMETHODCALLTYPE Clone(IEnumPins **ppEnum);
37
38 CEnumPins(std::vector<IPin*> Pins) : m_Ref(0), m_Pins(Pins), m_Index(0){};
39 virtual ~CEnumPins(){};
40
41 protected:
42 LONG m_Ref;
43 std::vector<IPin*> m_Pins;
44 ULONG m_Index;
45 };
46
47 HRESULT
48 STDMETHODCALLTYPE
49 CEnumPins::QueryInterface(
50 IN REFIID refiid,
51 OUT PVOID* Output)
52 {
53 *Output = NULL;
54 if (IsEqualGUID(refiid, IID_IUnknown))
55 {
56 *Output = PVOID(this);
57 reinterpret_cast<IUnknown*>(*Output)->AddRef();
58 return NOERROR;
59 }
60 if (IsEqualGUID(refiid, IID_IEnumPins))
61 {
62 *Output = (IEnumPins*)(this);
63 reinterpret_cast<IEnumPins*>(*Output)->AddRef();
64 return NOERROR;
65 }
66
67 WCHAR Buffer[MAX_PATH];
68 LPOLESTR lpstr;
69 StringFromCLSID(refiid, &lpstr);
70 swprintf(Buffer, L"CEnumPins::QueryInterface: NoInterface for %s\n", lpstr);
71 OutputDebugStringW(Buffer);
72 CoTaskMemFree(lpstr);
73
74 return E_NOINTERFACE;
75 }
76
77 HRESULT
78 STDMETHODCALLTYPE
79 CEnumPins::Next(
80 ULONG cPins,
81 IPin **ppPins,
82 ULONG *pcFetched)
83 {
84 ULONG i = 0;
85
86 if (!ppPins)
87 return E_POINTER;
88
89 if (cPins > 1 && !pcFetched)
90 return E_INVALIDARG;
91
92 WCHAR Buffer[MAX_PATH];
93 swprintf(Buffer, L"CEnumPins::Next: this %p m_Index %lx cPins %u\n", this, m_Index, cPins);
94 OutputDebugStringW(Buffer);
95
96 while(i < cPins)
97 {
98 if (m_Index + i >= m_Pins.size())
99 break;
100
101 ppPins[i] = m_Pins[m_Index + i];
102 m_Pins[m_Index + i]->AddRef();
103
104 i++;
105 }
106
107 if (pcFetched)
108 {
109 *pcFetched = i;
110 }
111
112 m_Index += i;
113 OutputDebugStringW(L"CEnumPins::Next: done\n");
114 if (i < cPins)
115 return S_FALSE;
116 else
117 return S_OK;
118 }
119
120 HRESULT
121 STDMETHODCALLTYPE
122 CEnumPins::Skip(
123 ULONG cPins)
124 {
125 if (cPins + m_Index >= m_Pins.size())
126 {
127 return S_FALSE;
128 }
129
130 m_Index += cPins;
131 return S_OK;
132 }
133
134 HRESULT
135 STDMETHODCALLTYPE
136 CEnumPins::Reset()
137 {
138 m_Index = 0;
139 return S_OK;
140 }
141
142 HRESULT
143 STDMETHODCALLTYPE
144 CEnumPins::Clone(
145 IEnumPins **ppEnum)
146 {
147 OutputDebugStringW(L"CEnumPins::Clone : NotImplemented\n");
148 return E_NOTIMPL;
149 }
150
151 HRESULT
152 WINAPI
153 CEnumPins_fnConstructor(
154 std::vector<IPin*> Pins,
155 REFIID riid,
156 LPVOID * ppv)
157 {
158 CEnumPins * handler = new CEnumPins(Pins);
159
160 #ifdef MSDVBNP_TRACE
161 WCHAR Buffer[MAX_PATH];
162 LPOLESTR lpstr;
163 StringFromCLSID(riid, &lpstr);
164 swprintf(Buffer, L"CEnumPins_fnConstructor riid %s pUnknown %p\n", lpstr, pUnknown);
165 OutputDebugStringW(Buffer);
166 #endif
167
168 if (!handler)
169 return E_OUTOFMEMORY;
170
171 if (FAILED(handler->QueryInterface(riid, ppv)))
172 {
173 /* not supported */
174 delete handler;
175 return E_NOINTERFACE;
176 }
177
178 return NOERROR;
179 }