a20c3129af57b833ada5d5d3174c3aeb2d25ed9e
[reactos.git] / reactos / 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 NTSTATUS
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 NTSTATUS
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)Connect) + ((ULONG)sizeof(KSPIN_CONNECT)) ) );
189
190 if (DataFormat->Flags & KSDATAFORMAT_ATTRIBUTES)
191 {
192 BufferSize += (ROUND_UP(DataFormat->FormatSize,sizeof(LONGLONG)) + DataFormat->FormatSize);
193 }
194
195 return KsiCreateObjectType(FilterHandle,
196 KSSTRING_Pin,
197 Connect,
198 BufferSize,
199 DesiredAccess,
200 ConnectionHandle);
201
202 }
203
204 /*++
205 * @name KsCreateTopologyNode
206 * @implemented
207 *
208 * The function KsCreateTopologyNode creates a handle to a topology node instance
209 *
210 * @param HANDLE ParentHandle
211 * Handle to parent when want to use when we created the node on
212 *
213 *
214 * @param PKSNODE_CREATE NodeCreate
215 * topology node parameters to use when it is create
216 *
217 * @param ACCESS_MASK DesiredAccess
218 * Desrided access
219 *
220 * @param PHANDLE NodeHandle
221 * Location for the topology node handle
222 *
223 * @return
224 * Return NTSTATUS error code or sussess code.
225 *
226 * @remarks.
227 * none
228 *
229 *--*/
230 KSDDKAPI
231 NTSTATUS
232 NTAPI
233 KsCreateTopologyNode(HANDLE ParentHandle,
234 PKSNODE_CREATE NodeCreate,
235 IN ACCESS_MASK DesiredAccess,
236 OUT PHANDLE NodeHandle)
237 {
238 return KsiCreateObjectType( ParentHandle,
239 KSSTRING_TopologyNode,
240 (PVOID) NodeCreate,
241 sizeof(KSNODE_CREATE),
242 DesiredAccess,
243 NodeHandle);
244 }
245
246
247 BOOL
248 APIENTRY
249 DllMain(HANDLE hModule, DWORD ulreason, LPVOID lpReserved)
250 {
251 switch (ulreason)
252 {
253 case DLL_PROCESS_ATTACH:
254 case DLL_THREAD_ATTACH:
255 case DLL_THREAD_DETACH:
256 case DLL_PROCESS_DETACH:
257 break;
258 }
259
260 return TRUE;
261 }