ReactOS  0.4.15-dev-4869-g35a816a
connection.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/connection.c
5  * PURPOSE: portcls physical connection registration
6  * PROGRAMMER: Johannes Anderwald
7  */
8 
9 #include "private.hpp"
10 
11 #ifndef YDEBUG
12 #define NDEBUG
13 #endif
14 
15 #include <debug.h>
16 
17 extern
18 "C"
20 BOOLEAN
21 NTAPI
25 );
26 
27 
28 class CUnregisterPhysicalConnection : public CUnknownImpl<IUnregisterPhysicalConnection>
29 {
30 public:
32 
34 
36 
38 };
39 
41 NTAPI
43  IN REFIID refiid,
44  OUT PVOID* Output)
45 {
47 
48  if (IsEqualGUIDAligned(refiid, IID_IUnregisterPhysicalConnection) ||
50  {
51  *Output = PVOID(PUNKNOWN(this));
52 
53  PUNKNOWN(*Output)->AddRef();
54  return STATUS_SUCCESS;
55  }
56 
58  {
59  DPRINT1("CUnregisterPhysicalConnection::QueryInterface no interface!!! iface %S\n", GuidString.Buffer);
61  }
62 
63  return STATUS_UNSUCCESSFUL;
64 }
65 
66 static
70  IN PUNKNOWN FromUnknown,
71  IN PUNICODE_STRING FromString,
72  IN ULONG FromPin,
73  IN PUNKNOWN ToUnknown,
75  IN ULONG ToPin)
76 {
79 }
80 
82 NTAPI
83 CUnregisterPhysicalConnection::UnregisterPhysicalConnection(
85  IN PUNKNOWN FromUnknown,
86  IN ULONG FromPin,
87  IN PUNKNOWN ToUnknown,
88  IN ULONG ToPin)
89 {
90  if (!DeviceObject || !FromUnknown || !ToUnknown)
92 
93  return UnRegisterConnection(DeviceObject, FromUnknown, NULL, FromPin, ToUnknown, NULL, ToPin);
94 }
95 
97 NTAPI
98 CUnregisterPhysicalConnection::UnregisterPhysicalConnectionToExternal(
100  IN PUNKNOWN FromUnknown,
101  IN ULONG FromPin,
103  IN ULONG ToPin)
104 {
105  if (!DeviceObject || !FromUnknown || !ToString)
107 
108  return UnRegisterConnection(DeviceObject, FromUnknown, NULL, FromPin, NULL, ToString, ToPin);
109 }
110 
111 NTSTATUS
112 NTAPI
113 CUnregisterPhysicalConnection::UnregisterPhysicalConnectionFromExternal(
115  IN PUNICODE_STRING FromString,
116  IN ULONG FromPin,
117  IN PUNKNOWN ToUnknown,
118  IN ULONG ToPin)
119 {
120  if (!DeviceObject || !FromString || !ToUnknown)
122 
123  return UnRegisterConnection(DeviceObject, NULL, FromString, FromPin, ToUnknown, NULL, ToPin);
124 }
125 
126 NTSTATUS
127 NTAPI
129  OUT PUNREGISTERPHYSICALCONNECTION *OutConnection)
130 {
131 
133 
134  if (!new_ptr)
136 
137  new_ptr->AddRef();
138  *OutConnection = (PUNREGISTERPHYSICALCONNECTION)new_ptr;
139  return STATUS_SUCCESS;
140 }
141 
142 NTSTATUS
145  IN PUNKNOWN FromUnknown,
146  IN PUNICODE_STRING FromString,
147  IN ULONG FromPin,
148  IN PUNKNOWN ToUnknown,
150  IN ULONG ToPin)
151 {
152  PSUBDEVICE_DESCRIPTOR FromSubDeviceDescriptor = NULL, ToSubDeviceDescriptor = NULL;
153  PSYMBOLICLINK_ENTRY SymEntry;
154  ISubdevice * FromSubDevice = NULL, *ToSubDevice = NULL;
156  PPHYSICAL_CONNECTION_ENTRY FromEntry = NULL, ToEntry = NULL;
157 
158  if (FromUnknown)
159  {
160  Status = FromUnknown->QueryInterface(IID_ISubdevice, (PVOID*)&FromSubDevice);
161  if (!NT_SUCCESS(Status))
162  goto cleanup;
163 
164  Status = FromSubDevice->GetDescriptor(&FromSubDeviceDescriptor);
165  if (!NT_SUCCESS(Status))
166  goto cleanup;
167 
168  if (IsListEmpty(&FromSubDeviceDescriptor->SymbolicLinkList))
169  {
171  goto cleanup;
172  }
173 
175  FromString = &SymEntry->SymbolicLink;
176  }
177 
178 
179  if (ToUnknown)
180  {
181  Status = ToUnknown->QueryInterface(IID_ISubdevice, (PVOID*)&ToSubDevice);
182  if (!NT_SUCCESS(Status))
183  goto cleanup;
184 
185  Status = ToSubDevice->GetDescriptor(&ToSubDeviceDescriptor);
186  if (!NT_SUCCESS(Status))
187  goto cleanup;
188 
189  if (IsListEmpty(&ToSubDeviceDescriptor->SymbolicLinkList))
190  {
192  goto cleanup;
193  }
194 
195 
196  SymEntry = (PSYMBOLICLINK_ENTRY)CONTAINING_RECORD(ToSubDeviceDescriptor->SymbolicLinkList.Flink, SYMBOLICLINK_ENTRY, Entry);
197  ToString = &SymEntry->SymbolicLink;
198 
199  }
200 
201  if (FromSubDeviceDescriptor)
202  {
204  if (!FromEntry)
205  {
207  goto cleanup;
208  }
209  }
210 
211  if (ToSubDeviceDescriptor)
212  {
213  ToEntry = (PPHYSICAL_CONNECTION_ENTRY)AllocateItem(NonPagedPool, sizeof(PHYSICAL_CONNECTION_ENTRY) + FromString->MaximumLength + sizeof(WCHAR), TAG_PORTCLASS);
214  if (!ToEntry)
215  {
217  goto cleanup;
218  }
219  }
220 
221  if (FromSubDeviceDescriptor)
222  {
223  FromEntry->FromPin = FromPin;
224  FromEntry->Connection.Pin = ToPin;
225  FromEntry->Connection.Size = sizeof(KSPIN_PHYSICALCONNECTION) + ToString->MaximumLength + sizeof(WCHAR);
226  RtlMoveMemory(&FromEntry->Connection.SymbolicLinkName, ToString->Buffer, ToString->MaximumLength);
227  FromEntry->Connection.SymbolicLinkName[ToString->Length / sizeof(WCHAR)] = UNICODE_NULL;
228 
229  InsertTailList(&FromSubDeviceDescriptor->PhysicalConnectionList, &FromEntry->Entry);
230  }
231 
232 
233  if (ToSubDeviceDescriptor)
234  {
235  ToEntry->FromPin = ToPin;
236  ToEntry->Connection.Pin = FromPin;
237  ToEntry->Connection.Size = sizeof(KSPIN_PHYSICALCONNECTION) + FromString->MaximumLength + sizeof(WCHAR);
238  RtlMoveMemory(&ToEntry->Connection.SymbolicLinkName, FromString->Buffer, FromString->MaximumLength);
239  ToEntry->Connection.SymbolicLinkName[FromString->Length / sizeof(WCHAR)] = UNICODE_NULL;
240 
241  InsertTailList(&ToSubDeviceDescriptor->PhysicalConnectionList, &ToEntry->Entry);
242 
243  }
244 
245  return STATUS_SUCCESS;
246 
247 cleanup:
248 
249  if (FromSubDevice)
250  FromSubDevice->Release();
251 
252  if (ToSubDevice)
253  ToSubDevice->Release();
254 
255  if (FromEntry)
256  FreeItem(FromEntry, TAG_PORTCLASS);
257 
258  if (ToEntry)
259  FreeItem(ToEntry, TAG_PORTCLASS);
260 
261  return Status;
262 }
263 
264 NTSTATUS
265 NTAPI
268  IN PUNKNOWN FromUnknown,
269  IN ULONG FromPin,
270  IN PUNKNOWN ToUnknown,
271  IN ULONG ToPin)
272 {
273  DPRINT("PcRegisterPhysicalConnection\n");
275 
276  if (!DeviceObject || !FromUnknown || !ToUnknown)
278 
279  return RegisterConnection(DeviceObject, FromUnknown, NULL, FromPin, ToUnknown, NULL, ToPin);
280 }
281 
282 NTSTATUS
283 NTAPI
286  IN PUNICODE_STRING FromString,
287  IN ULONG FromPin,
288  IN PUNKNOWN ToUnknown,
289  IN ULONG ToPin)
290 {
292 
293  if (!DeviceObject || !FromString || !ToUnknown)
295 
296  return RegisterConnection(DeviceObject, NULL, FromString, FromPin, ToUnknown, NULL, ToPin);
297 }
298 
299 NTSTATUS
300 NTAPI
303  IN PUNKNOWN FromUnknown,
304  IN ULONG FromPin,
306  IN ULONG ToPin)
307 {
309 
310  if (!DeviceObject || !FromUnknown || !ToString)
312 
313  return RegisterConnection(DeviceObject, FromUnknown, NULL, FromPin, NULL, ToString, ToPin);
314 }
NTSTATUS NTAPI PcRegisterPhysicalConnectionFromExternal(IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING FromString, IN ULONG FromPin, IN PUNKNOWN ToUnknown, IN ULONG ToPin)
Definition: connection.cpp:284
static PWSTR GuidString
Definition: apphelp.c:93
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define IN
Definition: typedefs.h:39
#define REFIID
Definition: guiddef.h:118
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: connection.cpp:42
NTSTATUS RegisterConnection(IN OUT PDEVICE_OBJECT DeviceObject, IN PUNKNOWN FromUnknown, IN PUNICODE_STRING FromString, IN ULONG FromPin, IN PUNKNOWN ToUnknown, IN PUNICODE_STRING ToString, IN ULONG ToPin)
Definition: connection.cpp:143
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
NTSTATUS NTAPI PcRegisterPhysicalConnection(IN PDEVICE_OBJECT DeviceObject, IN PUNKNOWN FromUnknown, IN ULONG FromPin, IN PUNKNOWN ToUnknown, IN ULONG ToPin)
Definition: connection.cpp:266
#define TAG_PORTCLASS
Definition: private.hpp:24
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
virtual ~CUnregisterPhysicalConnection()
Definition: connection.cpp:37
LONG NTSTATUS
Definition: precomp.h:26
#define InsertTailList(ListHead, Entry)
WCHAR SymbolicLinkName[1]
Definition: ks.h:658
#define NTSYSAPI
Definition: ntoskrnl.h:12
struct SYMBOLICLINK_ENTRY * PSYMBOLICLINK_ENTRY
Definition: interfaces.hpp:173
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235
CUnregisterPhysicalConnection(IUnknown *OuterUnknown)
Definition: connection.cpp:35
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define UNICODE_NULL
#define STDMETHODIMP
Definition: basetyps.h:43
unsigned char BOOLEAN
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1868
void * PVOID
Definition: retypes.h:9
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
KSPIN_PHYSICALCONNECTION Connection
Definition: interfaces.hpp:183
IUnregisterPhysicalConnection * PUNREGISTERPHYSICALCONNECTION
Definition: portcls.h:675
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
const GUID IID_IUnknown
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
struct PHYSICAL_CONNECTION_ENTRY * PPHYSICAL_CONNECTION_ENTRY
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
ULONG AddRef()
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG FromPin
Definition: interfaces.hpp:182
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1868
Definition: arc.h:85
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
LIST_ENTRY PhysicalConnectionList
Definition: interfaces.hpp:220
Definition: interfaces.hpp:179
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
NTSTATUS NTAPI PcRegisterPhysicalConnectionToExternal(IN PDEVICE_OBJECT DeviceObject, IN PUNKNOWN FromUnknown, IN ULONG FromPin, IN PUNICODE_STRING ToString, IN ULONG ToPin)
Definition: connection.cpp:301
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
#define NULL
Definition: types.h:112
LIST_ENTRY Entry
Definition: interfaces.hpp:181
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING SymbolicLink
Definition: interfaces.hpp:176
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:115
char * cleanup(char *str)
Definition: wpickclick.c:99
NTSTATUS NTAPI NewIUnregisterPhysicalConnection(OUT PUNREGISTERPHYSICALCONNECTION *OutConnection)
Definition: connection.cpp:128
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
std::string ToString(XMLHandle node)
Definition: xml2sdb.cpp:59
static NTSTATUS UnRegisterConnection(IN OUT PDEVICE_OBJECT DeviceObject, IN PUNKNOWN FromUnknown, IN PUNICODE_STRING FromString, IN ULONG FromPin, IN PUNKNOWN ToUnknown, IN PUNICODE_STRING ToString, IN ULONG ToPin)
Definition: connection.cpp:68
base of all file and directory entries
Definition: entries.h:82
LIST_ENTRY SymbolicLinkList
Definition: interfaces.hpp:219