ReactOS 0.4.15-dev-7924-g5949c20
service.c
Go to the documentation of this file.
1/*
2 * ServiceMain function for qmgr running within svchost
3 *
4 * Copyright 2007 (C) Google (Roy Shea)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "windef.h"
22#include "winsvc.h"
23#include "qmgr.h"
24#include "wine/debug.h"
25
27
29
32
33static VOID
34UpdateStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
35{
36 status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
37 status.dwCurrentState = dwCurrentState;
38 if (dwCurrentState == SERVICE_START_PENDING)
39 status.dwControlsAccepted = 0;
40 else
41 status.dwControlsAccepted
44 status.dwWin32ExitCode = 0;
45 status.dwServiceSpecificExitCode = 0;
46 status.dwCheckPoint = 0;
47 status.dwWaitHint = dwWaitHint;
48
50 ERR("failed to set service status\n");
52 }
53}
54
55/* Handle incoming ControlService signals */
56static DWORD WINAPI
58{
59 switch (ctrl) {
62 TRACE("shutting down service\n");
65 break;
66 default:
67 FIXME("ignoring handle service ctrl %x\n", ctrl);
68 UpdateStatus(status.dwCurrentState, NO_ERROR, 0);
69 break;
70 }
71
72 return NO_ERROR;
73}
74
75/* Main thread of the service */
76static BOOL
78{
79 HRESULT hr;
80 DWORD dwReg;
81
82 TRACE("\n");
83
85 if (FAILED(hr))
86 return FALSE;
87
90 NULL);
91 if (FAILED(hr))
92 return FALSE;
93
94 hr = CoRegisterClassObject(&CLSID_BackgroundCopyManager,
96 CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &dwReg);
97 if (FAILED(hr))
98 return FALSE;
99
100 return TRUE;
101}
102
103/* Service entry point */
105ServiceMain(DWORD dwArgc, LPWSTR *lpszArgv)
106{
107 HANDLE fileTxThread;
108 static const WCHAR qmgr_nameW[] = {'B','I','T','S',0};
109 DWORD threadId;
110 TRACE("\n");
111
113 if (!stop_event) {
114 ERR("failed to create stop_event\n");
115 return;
116 }
117
119 if (!status_handle) {
120 ERR("failed to register handler: %u\n", GetLastError());
121 return;
122 }
123
125 if (!StartCount()) {
126 ERR("failed starting service thread\n");
128 return;
129 }
130
132 if (!globalMgr.jobEvent) {
133 ERR("Couldn't create event: error %d\n", GetLastError());
135 return;
136 }
137
138 fileTxThread = CreateThread(NULL, 0, fileTransfer, NULL, 0, &threadId);
139 if (!fileTxThread)
140 {
141 ERR("Failed starting file transfer thread\n");
143 return;
144 }
145
147
148 WaitForSingleObject(fileTxThread, INFINITE);
151 TRACE("service stopped\n");
152
154}
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static void WINAPI ServiceMain(DWORD argc, LPSTR *argv)
Definition: service.c:123
#define FIXME(fmt,...)
Definition: debug.h:111
#define ERR(fmt,...)
Definition: debug.h:110
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
HRESULT WINAPI CoRegisterClassObject(REFCLSID rclsid, LPUNKNOWN pUnk, DWORD dwClsContext, DWORD flags, LPDWORD lpdwRegister)
Definition: compobj.c:2897
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, LONG cAuthSvc, SOLE_AUTHENTICATION_SERVICE *asAuthSvc, void *pReserved1, DWORD dwAuthnLevel, DWORD dwImpLevel, void *pReserved2, DWORD dwCapabilities, void *pReserved3)
Definition: compobj.c:4122
DWORD WINAPI fileTransfer(void *param)
Definition: qmgr.c:148
BackgroundCopyManagerImpl globalMgr
Definition: qmgr.c:26
static BOOL StartCount(void)
Definition: service.c:77
static SERVICE_STATUS_HANDLE status_handle
Definition: service.c:30
static VOID UpdateStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
Definition: service.c:34
HANDLE stop_event
Definition: service.c:28
static DWORD WINAPI ServiceHandler(DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context)
Definition: service.c:57
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FAILED(hr)
Definition: intsafe.h:51
#define ctrl
Definition: input.c:1756
@ REGCLS_MULTIPLEUSE
Definition: objbase.h:393
@ COINIT_MULTITHREADED
Definition: objbase.h:279
ClassFactoryImpl BITS_ClassFactory
Definition: factory.c:88
#define RPC_C_AUTHN_LEVEL_NONE
Definition: rpcdce.h:146
#define RPC_C_IMP_LEVEL_IMPERSONATE
Definition: rpcdce.h:176
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:812
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
IClassFactory IClassFactory_iface
Definition: factory.c:26
Definition: http.c:7252
Definition: ps.c:97
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_ACCEPT_PAUSE_CONTINUE
Definition: winsvc.h:29
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184