-allow to stop the service

-listen for rpc calls

svn path=/trunk/; revision=40133
This commit is contained in:
Christoph von Wittich
2009-03-20 13:43:43 +00:00
parent f82ac0fc93
commit 893ccc059d
+75 -9
View File
@@ -10,8 +10,9 @@
#define WIN32_NO_STATUS
#include <windows.h>
#include "wlansvc_s.h"
#define NDEBUG
//#define NDEBUG
#include <debug.h>
/* GLOBALS ******************************************************************/
@@ -19,10 +20,47 @@
#define SERVICE_NAME L"WLAN Service"
SERVICE_STATUS_HANDLE ServiceStatusHandle;
SERVICE_STATUS SvcStatus;
/* FUNCTIONS *****************************************************************/
static DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
{
RPC_STATUS Status;
Status = RpcServerUseProtseqEpW(L"ncalrpc", 20, L"wlansvc", NULL);
if (Status != RPC_S_OK)
{
DPRINT("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
return 0;
}
Status = RpcServerRegisterIf(wlansvc_interface_v1_0_s_ifspec, NULL, NULL);
if (Status != RPC_S_OK)
{
DPRINT("RpcServerRegisterIf() failed (Status %lx)\n", Status);
return 0;
}
Status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, 0);
if (Status != RPC_S_OK)
{
DPRINT("RpcServerListen() failed (Status %lx)\n", Status);
}
DPRINT("RpcServerListen finished\n");
return 0;
}
static void UpdateServiceStatus(HANDLE hServiceStatus, DWORD NewStatus, DWORD Increment)
{
if (Increment > 0)
SvcStatus.dwCheckPoint += Increment;
else
SvcStatus.dwCheckPoint = 0;
SvcStatus.dwCurrentState = NewStatus;
SetServiceStatus(hServiceStatus, &SvcStatus);
}
static DWORD WINAPI
ServiceControlHandler(DWORD dwControl,
@@ -32,35 +70,63 @@ ServiceControlHandler(DWORD dwControl,
{
switch (dwControl)
{
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
return ERROR_SUCCESS;
default :
case SERVICE_CONTROL_STOP:
UpdateServiceStatus(ServiceStatusHandle, SERVICE_STOP_PENDING, 1);
RpcMgmtStopServerListening(NULL);
break;
case SERVICE_CONTROL_INTERROGATE:
return NO_ERROR;
default:
return ERROR_CALL_NOT_IMPLEMENTED;
}
return NO_ERROR;
}
static VOID CALLBACK
ServiceMain(DWORD argc, LPWSTR *argv)
{
HANDLE hThread;
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
DPRINT("ServiceMain() called\n");
SvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
SvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
SvcStatus.dwCheckPoint = 0;
SvcStatus.dwWin32ExitCode = 0;
SvcStatus.dwServiceSpecificExitCode = 0;
SvcStatus.dwWaitHint = 4000;
ServiceStatusHandle = RegisterServiceCtrlHandlerExW(SERVICE_NAME,
ServiceControlHandler,
NULL);
UpdateServiceStatus(ServiceStatusHandle, SERVICE_RUNNING, 0);
hThread = CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)
RpcThreadRoutine,
NULL,
0,
NULL);
if (!hThread)
DPRINT("Can't create RpcThread\n");
else
{
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
UpdateServiceStatus(ServiceStatusHandle, SERVICE_STOPPED, 0);
DPRINT("ServiceMain() done\n");
}
int
wmain(int argc, WCHAR *argv[])
{