ReactOS 0.4.15-dev-7928-g68a8619
service_group.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/backpln/portcls/service_group.cpp
5 * PURPOSE: ServiceGroup object implementation
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9#include "private.hpp"
10
11#define NDEBUG
12#include <debug.h>
13
14VOID
17 IN struct _KDPC *Dpc,
21 );
22
23typedef struct
24{
28
29class CServiceGroup : public CUnknownImpl<IServiceGroup>
30{
31public:
33
35 CServiceGroup(IUnknown * OuterUnknown);
36 virtual ~CServiceGroup() {}
37
38protected:
39
41
46
48};
49
50//---------------------------------------------------------------
51// IUnknown methods
52//
53
57 IN REFIID refiid,
59{
61
62 if (IsEqualGUIDAligned(refiid, IID_IServiceGroup) ||
63 IsEqualGUIDAligned(refiid, IID_IServiceSink) ||
65 {
66 *Output = PVOID(PSERVICEGROUP(this));
67 PUNKNOWN(*Output)->AddRef();
68 return STATUS_SUCCESS;
69 }
70
72 {
73 DPRINT1("CServiceGroup::QueryInterface no interface!!! iface %S\n", GuidString.Buffer);
75 }
76
78}
79//---------------------------------------------------------------
80// IServiceSink methods
81//
82
84{
85 // initialize dpc
87
88 // set highest importance
90
91 // initialize service group list lock
93
94 // initialize service group list
96}
97
98VOID
100CServiceGroup::RequestService()
101{
103
104 DPRINT("CServiceGroup::RequestService() Dpc at Level %u\n", KeGetCurrentIrql());
105
107 {
109
110 // no due time
111 DueTime.QuadPart = 0LL;
112
113 // delayed service requested
115 }
116 else
117 {
118 // check current irql
120 {
121 //insert dpc to queue
123 }
124 else
125 {
126 // raise irql to dispatch level to make dpc fire immediately
128 // insert dpc to queue
130 // lower irql to old level
132 }
133 }
134}
135
136//---------------------------------------------------------------
137// IServiceGroup methods
138//
139
141NTAPI
142CServiceGroup::AddMember(
143 IN PSERVICESINK pServiceSink)
144{
146 KIRQL OldLevel;
147
148 // sanity check
150
151 // allocate service sink entry
153 if (!Entry)
154 {
155 // out of memory
157 }
158
159 // initialize service sink entry
160 Entry->pServiceSink = pServiceSink;
161 // increment reference count
162 pServiceSink->AddRef();
163
164 // acquire service group list lock
165 KeAcquireSpinLock(&m_Lock, &OldLevel);
166
167 // insert into service sink list
169
170 // release service group list lock
171 KeReleaseSpinLock(&m_Lock, OldLevel);
172
173 return STATUS_SUCCESS;
174}
175
176VOID
177NTAPI
178CServiceGroup::RemoveMember(
179 IN PSERVICESINK pServiceSink)
180{
181 PLIST_ENTRY CurEntry;
183 KIRQL OldLevel;
184
185 // sanity check
187
188 // acquire service group list lock
189 KeAcquireSpinLock(&m_Lock, &OldLevel);
190
191 // grab first entry
192 CurEntry = m_ServiceSinkHead.Flink;
193
194 // loop list until the passed entry is found
195 while (CurEntry != &m_ServiceSinkHead)
196 {
197 // grab entry
199
200 // check if it matches the passed entry
201 if (Entry->pServiceSink == pServiceSink)
202 {
203 // remove entry from list
205
206 // release service sink reference
207 pServiceSink->Release();
208
209 // free service sink entry
211
212 // leave loop
213 break;
214 }
215 // move to next entry
216 CurEntry = CurEntry->Flink;
217 }
218
219 // release service group list lock
220 KeReleaseSpinLock(&m_Lock, OldLevel);
221
222}
223
224VOID
225NTAPI
227 IN struct _KDPC *Dpc,
231 )
232{
233 PLIST_ENTRY CurEntry;
236
237 // acquire service group list lock
239
240 // grab first entry
241 CurEntry = This->m_ServiceSinkHead.Flink;
242
243 // loop the list and call the attached service sink/group
244 while (CurEntry != &This->m_ServiceSinkHead)
245 {
246 //grab current entry
248
249 // call service sink/group
250 Entry->pServiceSink->RequestService();
251
252 // move to next entry
253 CurEntry = CurEntry->Flink;
254 }
255
256 // release service group list lock
258}
259
260VOID
261NTAPI
262CServiceGroup::SupportDelayedService()
263{
265
266 // initialize the timer
268
269 // use the timer to perform service requests
271}
272
273VOID
274NTAPI
275CServiceGroup::RequestDelayedService(
276 IN ULONGLONG ullDelay)
277{
279
280 // sanity check
283
284 DueTime.QuadPart = ullDelay;
285
286 // set the timer
288}
289
290VOID
291NTAPI
292CServiceGroup::CancelDelayedService()
293{
296
297 // cancel the timer
299}
300
302NTAPI
304 OUT PSERVICEGROUP* OutServiceGroup,
305 IN PUNKNOWN OuterUnknown OPTIONAL)
306{
309
310 DPRINT("PcNewServiceGroup entered\n");
311
312 //FIXME support aggregation
313 PC_ASSERT(OuterUnknown == NULL);
314
315 // allocate a service group object
316 This = new(NonPagedPool, TAG_PORTCLASS)CServiceGroup(OuterUnknown);
317
318 if (!This)
319 {
320 // out of memory
322 }
323
324 // request IServiceSink interface
325 Status = This->QueryInterface(IID_IServiceSink, (PVOID*)OutServiceGroup);
326
327 if (!NT_SUCCESS(Status))
328 {
329 // failed to acquire service sink interface
330 delete This;
331 return Status;
332 }
333
334 // done
335 return Status;
336}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define STDMETHODIMP
Definition: basetyps.h:43
const GUID IID_IUnknown
virtual ~CServiceGroup()
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
friend VOID NTAPI IServiceGroupDpc(IN struct _KDPC *Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
KSPIN_LOCK m_Lock
LIST_ENTRY m_ServiceSinkHead
CServiceGroup(IUnknown *OuterUnknown)
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
VOID NTAPI KeSetImportanceDpc(IN PKDPC Dpc, IN KDPC_IMPORTANCE Importance)
Definition: dpc.c:958
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:25
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
ULONG AddRef()
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
static PWSTR GuidString
Definition: apphelp.c:93
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
IServiceSink * PSERVICESINK
Definition: portcls.h:569
IServiceGroup * PSERVICEGROUP
Definition: portcls.h:614
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
#define PC_ASSERT_IRQL(x)
Definition: private.hpp:30
#define TAG_PORTCLASS
Definition: private.hpp:24
#define PC_ASSERT(exp)
Definition: private.hpp:26
#define REFIID
Definition: guiddef.h:118
@ Output
Definition: arc.h:85
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
VOID NTAPI IServiceGroupDpc(IN struct _KDPC *Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
NTSTATUS NTAPI PcNewServiceGroup(OUT PSERVICEGROUP *OutServiceGroup, IN PUNKNOWN OuterUnknown OPTIONAL)
struct GROUP_ENTRY * PGROUP_ENTRY
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
base of all file and directory entries
Definition: entries.h:83
Entry(ENTRY_TYPE etype)
Definition: entries.cpp:35
LIST_ENTRY Entry
IN PSERVICESINK pServiceSink
Definition: ketypes.h:699
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define LL
Definition: tui.h:167
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
@ HighImportance
Definition: ketypes.h:695
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:688
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:687
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:689