ReactOS  0.4.13-dev-464-g6b95727
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 IUnregisterPhysicalConnection
29 {
30 public:
32 
34  {
36  return m_Ref;
37  }
39  {
41 
42  if (!m_Ref)
43  {
44  delete this;
45  return 0;
46  }
47  return m_Ref;
48  }
50 
52 
54 
55 protected:
57 
58 };
59 
61 NTAPI
63  IN REFIID refiid,
64  OUT PVOID* Output)
65 {
67 
68  if (IsEqualGUIDAligned(refiid, IID_IUnregisterPhysicalConnection) ||
70  {
71  *Output = PVOID(PUNKNOWN(this));
72 
73  PUNKNOWN(*Output)->AddRef();
74  return STATUS_SUCCESS;
75  }
76 
78  {
79  DPRINT1("CUnregisterPhysicalConnection::QueryInterface no interface!!! iface %S\n", GuidString.Buffer);
81  }
82 
83  return STATUS_UNSUCCESSFUL;
84 }
85 
86 static
90  IN PUNKNOWN FromUnknown,
91  IN PUNICODE_STRING FromString,
92  IN ULONG FromPin,
93  IN PUNKNOWN ToUnknown,
95  IN ULONG ToPin)
96 {
99 }
100 
101 NTSTATUS
102 NTAPI
103 CUnregisterPhysicalConnection::UnregisterPhysicalConnection(
105  IN PUNKNOWN FromUnknown,
106  IN ULONG FromPin,
107  IN PUNKNOWN ToUnknown,
108  IN ULONG ToPin)
109 {
110  if (!DeviceObject || !FromUnknown || !ToUnknown)
112 
113  return UnRegisterConnection(DeviceObject, FromUnknown, NULL, FromPin, ToUnknown, NULL, ToPin);
114 }
115 
116 NTSTATUS
117 NTAPI
118 CUnregisterPhysicalConnection::UnregisterPhysicalConnectionToExternal(
120  IN PUNKNOWN FromUnknown,
121  IN ULONG FromPin,
123  IN ULONG ToPin)
124 {
125  if (!DeviceObject || !FromUnknown || !ToString)
127 
128  return UnRegisterConnection(DeviceObject, FromUnknown, NULL, FromPin, NULL, ToString, ToPin);
129 }
130 
131 NTSTATUS
132 NTAPI
133 CUnregisterPhysicalConnection::UnregisterPhysicalConnectionFromExternal(
135  IN PUNICODE_STRING FromString,
136  IN ULONG FromPin,
137  IN PUNKNOWN ToUnknown,
138  IN ULONG ToPin)
139 {
140  if (!DeviceObject || !FromString || !ToUnknown)
142 
143  return UnRegisterConnection(DeviceObject, NULL, FromString, FromPin, ToUnknown, NULL, ToPin);
144 }
145 
146 NTSTATUS
147 NTAPI
149  OUT PUNREGISTERPHYSICALCONNECTION *OutConnection)
150 {
151 
153 
154  if (!new_ptr)
156 
157  new_ptr->AddRef();
158  *OutConnection = (PUNREGISTERPHYSICALCONNECTION)new_ptr;
159  return STATUS_SUCCESS;
160 }
161 
162 NTSTATUS
165  IN PUNKNOWN FromUnknown,
166  IN PUNICODE_STRING FromString,
167  IN ULONG FromPin,
168  IN PUNKNOWN ToUnknown,
170  IN ULONG ToPin)
171 {
172  PSUBDEVICE_DESCRIPTOR FromSubDeviceDescriptor = NULL, ToSubDeviceDescriptor = NULL;
173  PSYMBOLICLINK_ENTRY SymEntry;
174  ISubdevice * FromSubDevice = NULL, *ToSubDevice = NULL;
176  PPHYSICAL_CONNECTION_ENTRY FromEntry = NULL, ToEntry = NULL;
177 
178  if (FromUnknown)
179  {
180  Status = FromUnknown->QueryInterface(IID_ISubdevice, (PVOID*)&FromSubDevice);
181  if (!NT_SUCCESS(Status))
182  goto cleanup;
183 
184  Status = FromSubDevice->GetDescriptor(&FromSubDeviceDescriptor);
185  if (!NT_SUCCESS(Status))
186  goto cleanup;
187 
188  if (IsListEmpty(&FromSubDeviceDescriptor->SymbolicLinkList))
189  {
191  goto cleanup;
192  }
193 
195  FromString = &SymEntry->SymbolicLink;
196  }
197 
198 
199  if (ToUnknown)
200  {
201  Status = ToUnknown->QueryInterface(IID_ISubdevice, (PVOID*)&ToSubDevice);
202  if (!NT_SUCCESS(Status))
203  goto cleanup;
204 
205  Status = ToSubDevice->GetDescriptor(&ToSubDeviceDescriptor);
206  if (!NT_SUCCESS(Status))
207  goto cleanup;
208 
209  if (IsListEmpty(&ToSubDeviceDescriptor->SymbolicLinkList))
210  {
212  goto cleanup;
213  }
214 
215 
216  SymEntry = (PSYMBOLICLINK_ENTRY)CONTAINING_RECORD(ToSubDeviceDescriptor->SymbolicLinkList.Flink, SYMBOLICLINK_ENTRY, Entry);
217  ToString = &SymEntry->SymbolicLink;
218 
219  }
220 
221  if (FromSubDeviceDescriptor)
222  {
224  if (!FromEntry)
225  {
227  goto cleanup;
228  }
229  }
230 
231  if (ToSubDeviceDescriptor)
232  {
233  ToEntry = (PPHYSICAL_CONNECTION_ENTRY)AllocateItem(NonPagedPool, sizeof(PHYSICAL_CONNECTION_ENTRY) + FromString->MaximumLength + sizeof(WCHAR), TAG_PORTCLASS);
234  if (!ToEntry)
235  {
237  goto cleanup;
238  }
239  }
240 
241  if (FromSubDeviceDescriptor)
242  {
243  FromEntry->FromPin = FromPin;
244  FromEntry->Connection.Pin = ToPin;
245  FromEntry->Connection.Size = sizeof(KSPIN_PHYSICALCONNECTION) + ToString->MaximumLength + sizeof(WCHAR);
246  RtlMoveMemory(&FromEntry->Connection.SymbolicLinkName, ToString->Buffer, ToString->MaximumLength);
247  FromEntry->Connection.SymbolicLinkName[ToString->Length / sizeof(WCHAR)] = UNICODE_NULL;
248 
249  InsertTailList(&FromSubDeviceDescriptor->PhysicalConnectionList, &FromEntry->Entry);
250  }
251 
252 
253  if (ToSubDeviceDescriptor)
254  {
255  ToEntry->FromPin = ToPin;
256  ToEntry->Connection.Pin = FromPin;
257  ToEntry->Connection.Size = sizeof(KSPIN_PHYSICALCONNECTION) + FromString->MaximumLength + sizeof(WCHAR);
258  RtlMoveMemory(&ToEntry->Connection.SymbolicLinkName, FromString->Buffer, FromString->MaximumLength);
259  ToEntry->Connection.SymbolicLinkName[FromString->Length / sizeof(WCHAR)] = UNICODE_NULL;
260 
261  InsertTailList(&ToSubDeviceDescriptor->PhysicalConnectionList, &ToEntry->Entry);
262 
263  }
264 
265  return STATUS_SUCCESS;
266 
267 cleanup:
268 
269  if (FromSubDevice)
270  FromSubDevice->Release();
271 
272  if (ToSubDevice)
273  ToSubDevice->Release();
274 
275  if (FromEntry)
276  FreeItem(FromEntry, TAG_PORTCLASS);
277 
278  if (ToEntry)
279  FreeItem(ToEntry, TAG_PORTCLASS);
280 
281  return Status;
282 }
283 
284 NTSTATUS
285 NTAPI
288  IN PUNKNOWN FromUnknown,
289  IN ULONG FromPin,
290  IN PUNKNOWN ToUnknown,
291  IN ULONG ToPin)
292 {
293  DPRINT("PcRegisterPhysicalConnection\n");
295 
296  if (!DeviceObject || !FromUnknown || !ToUnknown)
298 
299  return RegisterConnection(DeviceObject, FromUnknown, NULL, FromPin, ToUnknown, NULL, ToPin);
300 }
301 
302 NTSTATUS
303 NTAPI
306  IN PUNICODE_STRING FromString,
307  IN ULONG FromPin,
308  IN PUNKNOWN ToUnknown,
309  IN ULONG ToPin)
310 {
312 
313  if (!DeviceObject || !FromString || !ToUnknown)
315 
316  return RegisterConnection(DeviceObject, NULL, FromString, FromPin, ToUnknown, NULL, ToPin);
317 }
318 
319 NTSTATUS
320 NTAPI
323  IN PUNKNOWN FromUnknown,
324  IN ULONG FromPin,
326  IN ULONG ToPin)
327 {
329 
330  if (!DeviceObject || !FromUnknown || !ToString)
332 
333  return RegisterConnection(DeviceObject, FromUnknown, NULL, FromPin, NULL, ToString, ToPin);
334 }
NTSTATUS NTAPI PcRegisterPhysicalConnectionFromExternal(IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING FromString, IN ULONG FromPin, IN PUNKNOWN ToUnknown, IN ULONG ToPin)
Definition: connection.cpp:304
static PWSTR GuidString
Definition: apphelp.c:91
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define IN
Definition: typedefs.h:38
#define REFIID
Definition: guiddef.h:113
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ BOOLEAN Release
Definition: classpnp.h:929
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: connection.cpp:62
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:163
#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:286
#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:53
LONG NTSTATUS
Definition: precomp.h:26
#define InsertTailList(ListHead, Entry)
WCHAR SymbolicLinkName[1]
Definition: ks.h:688
#define NTSYSAPI
Definition: ntoskrnl.h:14
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:263
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
CUnregisterPhysicalConnection(IUnknown *OuterUnknown)
Definition: connection.cpp:51
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
long LONG
Definition: pedump.c:60
#define STDMETHODIMP
Definition: basetyps.h:43
unsigned char BOOLEAN
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1869
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
STDMETHODIMP_(ULONG) Release()
Definition: connection.cpp:38
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
__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:1869
#define InterlockedDecrement
Definition: armddk.h:52
Definition: arc.h:85
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
LIST_ENTRY PhysicalConnectionList
Definition: interfaces.hpp:220
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
Definition: interfaces.hpp:179
#define InterlockedIncrement
Definition: armddk.h:53
NTSTATUS NTAPI PcRegisterPhysicalConnectionToExternal(IN PDEVICE_OBJECT DeviceObject, IN PUNKNOWN FromUnknown, IN ULONG FromPin, IN PUNICODE_STRING ToString, IN ULONG ToPin)
Definition: connection.cpp:321
LIST_ENTRY Entry
Definition: interfaces.hpp:181
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:90
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING SymbolicLink
Definition: interfaces.hpp:176
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
char * cleanup(char *str)
Definition: wpickclick.c:99
NTSTATUS NTAPI NewIUnregisterPhysicalConnection(OUT PUNREGISTERPHYSICALCONNECTION *OutConnection)
Definition: connection.cpp:148
return STATUS_SUCCESS
Definition: btrfs.c:2777
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:88
base of all file and directory entries
Definition: entries.h:82
STDMETHODIMP_(ULONG) AddRef()
Definition: connection.cpp:33
LIST_ENTRY SymbolicLinkList
Definition: interfaces.hpp:219