Sync with trunk head (part 1 of 2)
[reactos.git] / dll / directx / ksuser / ksuser.c
1 /*
2 * KSUSER.DLL - ReactOS
3 *
4 * Copyright 2008 Magnus Olsen and Dmitry Chapyshev
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21
22 #include "ksuser.h"
23 #define NDEBUG
24 #include <debug.h>
25
26 NTSTATUS NTAPI KsiCreateObjectType( HANDLE hHandle, PVOID guidstr, PVOID Buffer, ULONG BufferSize, ACCESS_MASK DesiredAccess, PHANDLE phHandle);
27
28 NTSTATUS
29 NTAPI
30 KsiCreateObjectType( HANDLE hHandle,
31 PVOID IID,
32 PVOID Buffer,
33 ULONG BufferSize,
34 ACCESS_MASK DesiredAccess,
35 PHANDLE phHandle)
36 {
37 NTSTATUS Status;
38 ULONG Length;
39 ULONG TotalSize;
40 LPWSTR pStr;
41 UNICODE_STRING ObjectName;
42 OBJECT_ATTRIBUTES ObjectAttributes;
43 IO_STATUS_BLOCK IoStatusBlock;
44
45 Length = wcslen(IID);
46
47 TotalSize = (Length * sizeof(WCHAR)) + BufferSize + 4 * sizeof(WCHAR);
48
49 pStr = HeapAlloc(GetProcessHeap(), 0, TotalSize);
50 if (!pStr)
51 return STATUS_INSUFFICIENT_RESOURCES;
52 pStr[0] = L'\\';
53 wcscpy(&pStr[1], (LPWSTR)IID);
54 pStr[Length+1] = L'\\';
55 memcpy(&pStr[Length+2], Buffer, BufferSize);
56 pStr[Length+3+(BufferSize/sizeof(WCHAR))] = L'\0';
57
58 RtlInitUnicodeString(&ObjectName, pStr);
59 ObjectName.Length = ObjectName.MaximumLength = TotalSize;
60
61 InitializeObjectAttributes(&ObjectAttributes, &ObjectName, OBJ_CASE_INSENSITIVE, hHandle, NULL);
62
63 Status = NtCreateFile(phHandle, DesiredAccess, &ObjectAttributes, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, 0, 1, 0, NULL, 0);
64 HeapFree(GetProcessHeap(), 0, pStr);
65 if (!NT_SUCCESS(Status))
66 {
67 *phHandle = INVALID_HANDLE_VALUE;
68 Status = RtlNtStatusToDosError(Status);
69 }
70 return Status;
71 }
72
73 /*++
74 * @name KsCreateAllocator
75 * @implemented
76 * The function KsCreateAllocator creates a handle to an allocator for the given sink connection handle
77 *
78 * @param HANDLE ConnectionHandle
79 * Handle to the sink connection on which to create the allocator
80 *
81 * @param PKSALLOCATOR_FRAMING AllocatorFraming
82 * the input param we using to alloc our framing
83 *
84 * @param PHANDLE AllocatorHandle
85 * Our new handle that we have alloc
86 *
87 * @return
88 * Return NTSTATUS error code or sussess code.
89 *
90 * @remarks.
91 * none
92 *
93 *--*/
94 KSDDKAPI
95 DWORD
96 NTAPI
97 KsCreateAllocator(HANDLE ConnectionHandle,
98 PKSALLOCATOR_FRAMING AllocatorFraming,
99 PHANDLE AllocatorHandle)
100
101 {
102 return KsiCreateObjectType( ConnectionHandle,
103 KSSTRING_Allocator,
104 (PVOID) AllocatorFraming,
105 sizeof(KSALLOCATOR_FRAMING),
106 GENERIC_READ,
107 AllocatorHandle);
108 }
109
110 /*++
111 * @name KsCreateClock
112 * @implemented
113 *
114 * The function KsCreateClock creates handle to clock instance
115 *
116 * @param HANDLE ConnectionHandle
117 * Handle to use to create the clock
118 *
119 * @param PKSCLOCK_CREATE ClockCreate
120 * paramenter to use to create the clock
121 *
122 * @param PHANDLE ClockHandle
123 * The new handle
124 *
125 * @return
126 * Return NTSTATUS error code or sussess code.
127 *
128 * @remarks.
129 * none
130 *
131 *--*/
132 KSDDKAPI
133 DWORD
134 NTAPI
135 KsCreateClock(HANDLE ConnectionHandle,
136 PKSCLOCK_CREATE ClockCreate,
137 PHANDLE ClockHandle)
138 {
139 return KsiCreateObjectType( ConnectionHandle,
140 KSSTRING_Clock,
141 (PVOID) ClockCreate,
142 sizeof(KSCLOCK_CREATE),
143 GENERIC_READ,
144 ClockHandle);
145 }
146
147 /*++
148 * @name KsCreatePin
149 * @implemented
150 *
151 * The function KsCreatePin passes a connection request to device and create pin instance
152 *
153 * @param HANDLE FilterHandle
154 * handle of the filter initiating the create request
155 *
156 * @param PKSPIN_CONNECT Connect
157 * Pointer to a KSPIN_CONNECT structure that contains parameters for the requested connection.
158 * This should be followed in memory by a KSDATAFORMAT data structure, describing the data format
159 * requested for the connection.
160
161 * @param ACCESS_MASK DesiredAccess
162 * Desrided access
163 *
164 * @param PHANDLE ConnectionHandle
165 * connection handle passed
166 *
167 * @return
168 * Return NTSTATUS error code or sussess code.
169 *
170 * @remarks.
171 * The flag in PKSDATAFORMAT is not really document,
172 * to find it u need api mointor allot api and figout
173 * how it works, only flag I have found is the
174 * KSDATAFORMAT_ATTRIBUTES flag, it doing a Align
175 * of LONLONG size, it also round up it.
176 *
177 *--*/
178
179 KSDDKAPI
180 DWORD
181 NTAPI
182 KsCreatePin(HANDLE FilterHandle,
183 PKSPIN_CONNECT Connect,
184 ACCESS_MASK DesiredAccess,
185 PHANDLE ConnectionHandle)
186 {
187 ULONG BufferSize = sizeof(KSPIN_CONNECT);
188 PKSDATAFORMAT DataFormat = ((PKSDATAFORMAT) ((ULONG_PTR)Connect + sizeof(KSPIN_CONNECT)));
189
190 BufferSize += DataFormat->FormatSize;
191
192 return KsiCreateObjectType(FilterHandle,
193 KSSTRING_Pin,
194 Connect,
195 BufferSize,
196 DesiredAccess,
197 ConnectionHandle);
198
199 }
200
201 /*++
202 * @name KsCreateTopologyNode
203 * @implemented
204 *
205 * The function KsCreateTopologyNode creates a handle to a topology node instance
206 *
207 * @param HANDLE ParentHandle
208 * Handle to parent when want to use when we created the node on
209 *
210 *
211 * @param PKSNODE_CREATE NodeCreate
212 * topology node parameters to use when it is create
213 *
214 * @param ACCESS_MASK DesiredAccess
215 * Desrided access
216 *
217 * @param PHANDLE NodeHandle
218 * Location for the topology node handle
219 *
220 * @return
221 * Return NTSTATUS error code or sussess code.
222 *
223 * @remarks.
224 * none
225 *
226 *--*/
227 KSDDKAPI
228 DWORD
229 NTAPI
230 KsCreateTopologyNode(HANDLE ParentHandle,
231 PKSNODE_CREATE NodeCreate,
232 IN ACCESS_MASK DesiredAccess,
233 OUT PHANDLE NodeHandle)
234 {
235 return KsiCreateObjectType( ParentHandle,
236 KSSTRING_TopologyNode,
237 (PVOID) NodeCreate,
238 sizeof(KSNODE_CREATE),
239 DesiredAccess,
240 NodeHandle);
241 }
242
243
244 BOOL
245 APIENTRY
246 DllMain(HANDLE hModule, DWORD ulreason, LPVOID lpReserved)
247 {
248 switch (ulreason)
249 {
250 case DLL_PROCESS_ATTACH:
251 case DLL_THREAD_ATTACH:
252 case DLL_THREAD_DETACH:
253 case DLL_PROCESS_DETACH:
254 break;
255 }
256
257 return TRUE;
258 }