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