Author: cwittich Date: Fri Mar 20 16:43:43 2009 New Revision: 40133
URL: http://svn.reactos.org/svn/reactos?rev=40133&view=rev Log: -allow to stop the service -listen for rpc calls
Modified: trunk/reactos/base/services/wlansvc/wlansvc.c
Modified: trunk/reactos/base/services/wlansvc/wlansvc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/wlansvc/wlans... ============================================================================== --- trunk/reactos/base/services/wlansvc/wlansvc.c [iso-8859-1] (original) +++ trunk/reactos/base/services/wlansvc/wlansvc.c [iso-8859-1] Fri Mar 20 16:43:43 2009 @@ -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,34 +70,62 @@ { switch (dwControl) { + case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP: - case SERVICE_CONTROL_SHUTDOWN: - return ERROR_SUCCESS; - - default : + 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[])