cd0ffe274bb45c90994a407f64cca99c333738f9
[reactos.git] / reactos / drivers / ksfilter / ks / deviceinterface.c
1 #include "priv.h"
2
3 NTSTATUS
4 KspSetDeviceInterfacesState(
5 IN PLIST_ENTRY ListHead,
6 IN BOOL Enable)
7 {
8 NTSTATUS Status = STATUS_SUCCESS;
9 PLIST_ENTRY Entry;
10 PSYMBOLIC_LINK_ENTRY SymEntry;
11
12
13 Entry = ListHead->Flink;
14 while(Entry != ListHead)
15 {
16 /* fetch symbolic link entry */
17 SymEntry = (PSYMBOLIC_LINK_ENTRY)CONTAINING_RECORD(Entry, SYMBOLIC_LINK_ENTRY, Entry);
18 /* set device interface state */
19 Status = IoSetDeviceInterfaceState(&SymEntry->SymbolicLink, Enable);
20
21 DPRINT("KspSetDeviceInterfacesState SymbolicLink '%S' Status %lx\n", SymEntry->SymbolicLink.Buffer, Status, Enable);
22
23 /* check for success */
24 if (!NT_SUCCESS(Status))
25 return Status;
26 /* get next entry */
27 Entry = Entry->Flink;
28 }
29 /* return result */
30 return Status;
31 }
32
33 NTSTATUS
34 KspFreeDeviceInterfaces(
35 IN PLIST_ENTRY ListHead)
36 {
37 PLIST_ENTRY Entry;
38 PSYMBOLIC_LINK_ENTRY SymEntry;
39
40 while(!IsListEmpty(ListHead))
41 {
42 /* remove first entry */
43 Entry = RemoveHeadList(ListHead);
44
45 /* fetch symbolic link entry */
46 SymEntry = (PSYMBOLIC_LINK_ENTRY)CONTAINING_RECORD(Entry, SYMBOLIC_LINK_ENTRY, Entry);
47
48 /* free device interface string */
49 RtlFreeUnicodeString(&SymEntry->SymbolicLink);
50 /* free entry item */
51 FreeItem(Entry);
52 }
53
54 return STATUS_SUCCESS;
55 }
56
57 NTSTATUS
58 KspRegisterDeviceInterfaces(
59 IN PDEVICE_OBJECT PhysicalDeviceObject,
60 IN ULONG CategoriesCount,
61 IN GUID const*Categories,
62 IN PUNICODE_STRING ReferenceString,
63 OUT PLIST_ENTRY SymbolicLinkList)
64 {
65 ULONG Index;
66 NTSTATUS Status = STATUS_SUCCESS;
67 PSYMBOLIC_LINK_ENTRY SymEntry;
68
69 for(Index = 0; Index < CategoriesCount; Index++)
70 {
71 /* allocate a symbolic link entry */
72 SymEntry = AllocateItem(NonPagedPool, sizeof(SYMBOLIC_LINK_ENTRY));
73 /* check for success */
74 if (!SymEntry)
75 return STATUS_INSUFFICIENT_RESOURCES;
76
77 /* now register device interface */
78 Status = IoRegisterDeviceInterface(PhysicalDeviceObject,
79 &Categories[Index],
80 ReferenceString,
81 &SymEntry->SymbolicLink);
82
83 if (!NT_SUCCESS(Status))
84 {
85 DPRINT1("Failed to register device interface %x\n", Status);
86
87 /* free entry */
88 FreeItem(SymEntry);
89
90 /* return result */
91 return Status;
92 }
93 /* insert symbolic link entry */
94 InsertTailList(SymbolicLinkList, &SymEntry->Entry);
95 }
96
97 /* return result */
98 return Status;
99 }
100
101 NTSTATUS
102 KspSetFilterFactoriesState(
103 IN PKSIDEVICE_HEADER DeviceHeader,
104 IN BOOLEAN NewState)
105 {
106 PCREATE_ITEM_ENTRY CreateEntry;
107 PLIST_ENTRY Entry;
108 NTSTATUS Status = STATUS_SUCCESS;
109
110 /* grab first device interface */
111 Entry = DeviceHeader->ItemList.Flink;
112 while(Entry != &DeviceHeader->ItemList && Status == STATUS_SUCCESS)
113 {
114 /* grab create entry */
115 CreateEntry = CONTAINING_RECORD(Entry, CREATE_ITEM_ENTRY, Entry);
116
117 /* sanity check */
118 ASSERT(CreateEntry->CreateItem);
119
120 if (CreateEntry->CreateItem->Create == IKsFilterFactory_Create)
121 {
122 /* found our own filterfactory */
123 Status = KsFilterFactorySetDeviceClassesState((PKSFILTERFACTORY)CreateEntry->CreateItem->Context, NewState);
124 }
125
126 Entry = Entry->Flink;
127 }
128
129 /* store result */
130 return Status;
131 }