Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenservice_main.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Remote Procedure Call service 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: /base/services/rpcss/service_main.c 00005 * PURPOSE: Service control code 00006 * COPYRIGHT: Copyright 2008 Ged Murphy <gedmurphy@reactos.org> 00007 * 00008 */ 00009 00010 #include "rpcss.h" 00011 00012 #define NDEBUG 00013 #include <debug.h> 00014 00015 extern BOOL RPCSS_Initialize(void); 00016 extern BOOL RPCSS_Shutdown(void); 00017 extern HANDLE exit_event; 00018 00019 static VOID WINAPI ServiceMain(DWORD, LPWSTR *); 00020 static WCHAR ServiceName[] = L"RpcSs"; 00021 SERVICE_TABLE_ENTRYW ServiceTable[] = 00022 { 00023 { ServiceName, ServiceMain }, 00024 { NULL, NULL } 00025 }; 00026 00027 static SERVICE_STATUS ServiceStatus; 00028 static SERVICE_STATUS_HANDLE ServiceStatusHandle; 00029 00030 DWORD WINAPI 00031 ServiceControlHandler(DWORD dwControl, 00032 DWORD dwEventType, 00033 LPVOID lpEventData, 00034 LPVOID lpContext) 00035 { 00036 switch (dwControl) 00037 { 00038 case SERVICE_CONTROL_SHUTDOWN: 00039 case SERVICE_CONTROL_STOP: 00040 SetEvent(exit_event); 00041 return NO_ERROR; 00042 00043 case SERVICE_CONTROL_INTERROGATE: 00044 return NO_ERROR; 00045 00046 default: 00047 return ERROR_CALL_NOT_IMPLEMENTED; 00048 } 00049 } 00050 00051 VOID WINAPI 00052 ServiceMain(DWORD argc, LPWSTR argv[]) 00053 { 00054 DWORD dwError; 00055 00056 ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName, 00057 ServiceControlHandler, 00058 NULL); 00059 if (!ServiceStatusHandle) 00060 { 00061 dwError = GetLastError(); 00062 DPRINT1("RegisterServiceCtrlHandlerW() failed! (Error %lu)\n", dwError); 00063 return; 00064 } 00065 00066 ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; 00067 ServiceStatus.dwCurrentState = SERVICE_START_PENDING; 00068 ServiceStatus.dwControlsAccepted = 0; 00069 ServiceStatus.dwWin32ExitCode = NO_ERROR; 00070 ServiceStatus.dwServiceSpecificExitCode = 0; 00071 ServiceStatus.dwCheckPoint = 0; 00072 ServiceStatus.dwWaitHint = 1000; 00073 SetServiceStatus(ServiceStatusHandle, &ServiceStatus); 00074 00075 if (RPCSS_Initialize()) 00076 { 00077 ServiceStatus.dwCurrentState = SERVICE_RUNNING; 00078 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; 00079 SetServiceStatus(ServiceStatusHandle, &ServiceStatus); 00080 00081 WaitForSingleObject(exit_event, INFINITE); 00082 00083 ServiceStatus.dwCurrentState = SERVICE_STOPPED; 00084 SetServiceStatus(ServiceStatusHandle, &ServiceStatus); 00085 RPCSS_Shutdown(); 00086 } 00087 } 00088 00089 int wmain(int argc, LPWSTR argv[]) 00090 { 00091 if (!StartServiceCtrlDispatcherW(ServiceTable)) 00092 { 00093 DPRINT1("StartServiceCtrlDispatcherW() failed\n"); 00094 return 1; 00095 } 00096 00097 return 0; 00098 } Generated on Fri May 25 2012 04:16:03 for ReactOS by
1.7.6.1
|