1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: base/services/shsvcs/thmsvc.c
5 * PURPOSE: Themes service
6 * PROGRAMMER: Giannis Adamopoulos
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <windows.h>
12 #include <wine/debug.h>
13
14 WINE_DEFAULT_DEBUG_CHANNEL(shsvcs);
15
16 /* GLOBALS ******************************************************************/
17
18 static WCHAR ServiceName[] = L"Themes";
19
20 SERVICE_STATUS_HANDLE ServiceStatusHandle;
21 SERVICE_STATUS ServiceStatus;
22
23
24 /* FUNCTIONS *****************************************************************/
25
26 HANDLE StartEvent, StopEvent;
27
28 static VOID
UpdateServiceStatus(DWORD dwState)29 UpdateServiceStatus(DWORD dwState)
30 {
31 ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
32 ServiceStatus.dwCurrentState = dwState;
33
34 if (dwState == SERVICE_RUNNING)
35 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
36 else if (dwState == SERVICE_PAUSED)
37 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE;
38 else
39 ServiceStatus.dwControlsAccepted = 0;
40
41 ServiceStatus.dwWin32ExitCode = 0;
42 ServiceStatus.dwServiceSpecificExitCode = 0;
43 ServiceStatus.dwCheckPoint = 0;
44
45 if (dwState == SERVICE_START_PENDING ||
46 dwState == SERVICE_STOP_PENDING ||
47 dwState == SERVICE_PAUSE_PENDING ||
48 dwState == SERVICE_CONTINUE_PENDING)
49 ServiceStatus.dwWaitHint = 10000;
50 else
51 ServiceStatus.dwWaitHint = 0;
52
53 SetServiceStatus(ServiceStatusHandle,
54 &ServiceStatus);
55 }
56
57
58 static DWORD WINAPI
ServiceControlHandler(DWORD dwControl,DWORD dwEventType,LPVOID lpEventData,LPVOID lpContext)59 ServiceControlHandler(DWORD dwControl,
60 DWORD dwEventType,
61 LPVOID lpEventData,
62 LPVOID lpContext)
63 {
64 TRACE("ServiceControlHandler() called\n");
65
66 switch (dwControl)
67 {
68 case SERVICE_CONTROL_STOP:
69 TRACE(" SERVICE_CONTROL_STOP received\n");
70
71 /* Signal the theme server in winlogon to remove theme hooks */
72 ResetEvent(StartEvent);
73 SetEvent(StopEvent);
74 UpdateServiceStatus(SERVICE_STOPPED);
75 return ERROR_SUCCESS;
76
77 case SERVICE_CONTROL_PAUSE:
78 TRACE(" SERVICE_CONTROL_PAUSE received\n");
79 UpdateServiceStatus(SERVICE_PAUSED);
80 return ERROR_SUCCESS;
81
82 case SERVICE_CONTROL_CONTINUE:
83 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
84 UpdateServiceStatus(SERVICE_RUNNING);
85 return ERROR_SUCCESS;
86
87 case SERVICE_CONTROL_INTERROGATE:
88 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
89 SetServiceStatus(ServiceStatusHandle,
90 &ServiceStatus);
91 return ERROR_SUCCESS;
92
93 case SERVICE_CONTROL_SHUTDOWN:
94 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
95 UpdateServiceStatus(SERVICE_STOPPED);
96 return ERROR_SUCCESS;
97
98 default :
99 TRACE(" Control %lu received\n");
100 return ERROR_CALL_NOT_IMPLEMENTED;
101 }
102 }
103
104 VOID
105 WINAPI
ThemeServiceMain(DWORD argc,LPTSTR * argv)106 ThemeServiceMain(DWORD argc, LPTSTR *argv)
107 {
108 UNREFERENCED_PARAMETER(argc);
109 UNREFERENCED_PARAMETER(argv);
110
111 ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
112 ServiceControlHandler,
113 NULL);
114 if (!ServiceStatusHandle)
115 {
116 ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
117 return;
118 }
119
120 StartEvent = CreateEventW(NULL, TRUE, FALSE, L"Global\\ThemeStartEvent");
121 StopEvent = CreateEventW(NULL, TRUE, FALSE, L"Global\\ThemeStopEvent");
122
123 UpdateServiceStatus(SERVICE_RUNNING);
124
125 /* Signal the theme server in winlogon to install theme hooks */
126 ResetEvent(StopEvent);
127 SetEvent(StartEvent);
128 }
129
130 /* EOF */
131