3 * Copyright (C) 2005 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/umpnpmgr/umpnpmgr.c
24 * PURPOSE: User-mode Plug and Play manager
25 * PROGRAMMER: Eric Kohl
28 /* INCLUDES *****************************************************************/
30 #define NTOS_MODE_USER
32 #include <ntos/ntpnp.h>
33 #include <ddk/wdmguid.h>
49 /* GLOBALS ******************************************************************/
52 ServiceMain(DWORD argc
, LPTSTR
*argv
);
54 static SERVICE_TABLE_ENTRY ServiceTable
[2] =
56 {_T("PlugPlay"), ServiceMain
},
61 /* FUNCTIONS *****************************************************************/
64 RpcServerThread(LPVOID lpParameter
)
68 DPRINT("RpcServerThread() called\n");
70 Status
= RpcServerUseProtseqEpW(L
"ncacn_np",
73 NULL
); // Security descriptor
74 if (Status
!= RPC_S_OK
)
76 DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status
);
80 Status
= RpcServerRegisterIf(pnp_v1_0_s_ifspec
,
83 if (Status
!= RPC_S_OK
)
85 DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status
);
89 Status
= RpcServerListen(1,
92 if (Status
!= RPC_S_OK
)
94 DPRINT1("RpcServerListen() failed (Status %lx)\n", Status
);
98 DPRINT("RpcServerThread() done\n");
104 void __RPC_FAR
* __RPC_USER
midl_user_allocate(size_t len
)
106 return GlobalAlloc(GPTR
, len
);
110 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
116 //WORD PNP_GetVersion(RPC_BINDING_HANDLE BindingHandle)
117 WORD
PNP_GetVersion(handle_t BindingHandle
)
124 PnpEventThread(LPVOID lpParameter
)
126 PPLUGPLAY_EVENT_BLOCK PnpEvent
;
129 RPC_STATUS RpcStatus
;
131 PnpEventSize
= 0x1000;
132 PnpEvent
= HeapAlloc(GetProcessHeap(), 0, PnpEventSize
);
133 if (PnpEvent
== NULL
)
134 return ERROR_OUTOFMEMORY
;
138 DPRINT("Calling NtGetPlugPlayEvent()\n");
140 /* Wait for the next pnp event */
141 Status
= NtGetPlugPlayEvent(0, 0, PnpEvent
, PnpEventSize
);
142 /* Resize the buffer for the PnP event if it's too small. */
143 if (Status
== STATUS_BUFFER_TOO_SMALL
)
145 PnpEventSize
+= 0x400;
146 PnpEvent
= HeapReAlloc(GetProcessHeap(), 0, PnpEvent
, PnpEventSize
);
147 if (PnpEvent
== NULL
)
148 return ERROR_OUTOFMEMORY
;
151 if (!NT_SUCCESS(Status
))
153 DPRINT("NtPlugPlayEvent() failed (Status %lx)\n", Status
);
157 DPRINT("Received PnP Event\n");
158 if (UuidEqual(&PnpEvent
->EventGuid
, (UUID
*)&GUID_DEVICE_ARRIVAL
, &RpcStatus
))
160 DPRINT1("Device arrival event: %S\n", PnpEvent
->TargetDevice
.DeviceIds
);
164 DPRINT1("Unknown event\n");
167 /* FIXME: Process the pnp event */
169 /* Dequeue the current pnp event and signal the next one */
170 NtPlugPlayControl(PLUGPLAY_USER_RESPONSE
, NULL
, 0);
173 HeapFree(GetProcessHeap(), 0, PnpEvent
);
175 return ERROR_SUCCESS
;
180 ServiceMain(DWORD argc
, LPTSTR
*argv
)
185 DPRINT("ServiceMain() called\n");
187 hThread
= CreateThread(NULL
,
194 CloseHandle(hThread
);
196 hThread
= CreateThread(NULL
,
203 CloseHandle(hThread
);
205 DPRINT("ServiceMain() done\n");
210 main(int argc
, char *argv
[])
212 DPRINT("Umpnpmgr: main() started\n");
214 StartServiceCtrlDispatcher(ServiceTable
);
216 DPRINT("Umpnpmgr: main() done\n");