ReactOS 0.4.15-dev-5836-g942b022
service.c File Reference
#include "windef.h"
#include "winsvc.h"
#include "qmgr.h"
#include "wine/debug.h"
Include dependency graph for service.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (qmgr)
 
static VOID UpdateStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
 
static DWORD WINAPI ServiceHandler (DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context)
 
static BOOL StartCount (void)
 
VOID WINAPI ServiceMain (DWORD dwArgc, LPWSTR *lpszArgv)
 

Variables

HANDLE stop_event = NULL
 
static SERVICE_STATUS_HANDLE status_handle
 
static SERVICE_STATUS status
 

Function Documentation

◆ ServiceHandler()

static DWORD WINAPI ServiceHandler ( DWORD  ctrl,
DWORD  event_type,
LPVOID  event_data,
LPVOID  context 
)
static

Definition at line 57 of file service.c.

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}
#define FIXME(fmt,...)
Definition: debug.h:111
#define NO_ERROR
Definition: dderror.h:5
static VOID UpdateStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
Definition: service.c:34
HANDLE stop_event
Definition: service.c:28
#define ctrl
Definition: input.c:1756
#define TRACE(s)
Definition: solgame.cpp:4
Definition: ps.c:97
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36

Referenced by InitIdtVector(), and ServiceMain().

◆ ServiceMain()

VOID WINAPI ServiceMain ( DWORD  dwArgc,
LPWSTR lpszArgv 
)

Definition at line 105 of file service.c.

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}
#define ERR(fmt,...)
Definition: debug.h:110
#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
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
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 DWORD WINAPI ServiceHandler(DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context)
Definition: service.c:57
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:812
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
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ StartCount()

static BOOL StartCount ( void  )
static

Definition at line 77 of file service.c.

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}
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
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
#define FAILED(hr)
Definition: intsafe.h:51
@ 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
HRESULT hr
Definition: shlfolder.c:183
IClassFactory IClassFactory_iface
Definition: factory.c:26

Referenced by ServiceMain().

◆ UpdateStatus()

static VOID UpdateStatus ( DWORD  dwCurrentState,
DWORD  dwWin32ExitCode,
DWORD  dwWaitHint 
)
static

Definition at line 34 of file service.c.

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}
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_ACCEPT_PAUSE_CONTINUE
Definition: winsvc.h:29
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962

Referenced by ServiceHandler(), and ServiceMain().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( qmgr  )

Variable Documentation

◆ status

Definition at line 31 of file service.c.

◆ status_handle

SERVICE_STATUS_HANDLE status_handle
static

Definition at line 30 of file service.c.

Referenced by ServiceMain(), and UpdateStatus().

◆ stop_event

HANDLE stop_event = NULL

Definition at line 28 of file service.c.

Referenced by ServiceHandler(), ServiceMain(), and UpdateStatus().