- Merge from trunk up to r45543
[reactos.git] / base / services / spoolsv / spoolsv.c
index 642d70a..98b890d 100644 (file)
 #define WIN32_NO_STATUS
 #include <windows.h>
 
-#define NDEBUG
-#include <debug.h>
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(spoolsv);
+
 
 /* GLOBALS ******************************************************************/
 
@@ -24,6 +26,35 @@ SERVICE_STATUS ServiceStatus;
 
 /* FUNCTIONS *****************************************************************/
 
+static VOID
+UpdateServiceStatus(DWORD dwState)
+{
+    ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+    ServiceStatus.dwCurrentState = dwState;
+
+    if (dwState == SERVICE_RUNNING)
+        ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
+    else if (dwState == SERVICE_PAUSED)
+        ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE;
+    else
+        ServiceStatus.dwControlsAccepted = 0;
+
+    ServiceStatus.dwWin32ExitCode = 0;
+    ServiceStatus.dwServiceSpecificExitCode = 0;
+    ServiceStatus.dwCheckPoint = 0;
+
+    if (dwState == SERVICE_START_PENDING ||
+        dwState == SERVICE_STOP_PENDING ||
+        dwState == SERVICE_PAUSE_PENDING ||
+        dwState == SERVICE_CONTINUE_PENDING)
+        ServiceStatus.dwWaitHint = 10000;
+    else
+        ServiceStatus.dwWaitHint = 0;
+
+    SetServiceStatus(ServiceStatusHandle,
+                     &ServiceStatus);
+}
+
 
 static DWORD WINAPI
 ServiceControlHandler(DWORD dwControl,
@@ -31,42 +62,61 @@ ServiceControlHandler(DWORD dwControl,
                       LPVOID lpEventData,
                       LPVOID lpContext)
 {
+    TRACE("ServiceControlHandler() called\n");
+
     switch (dwControl)
     {
         case SERVICE_CONTROL_STOP:
+            TRACE("  SERVICE_CONTROL_STOP received\n");
+            UpdateServiceStatus(SERVICE_STOPPED);
+            return ERROR_SUCCESS;
+
+        case SERVICE_CONTROL_PAUSE:
+            TRACE("  SERVICE_CONTROL_PAUSE received\n");
+            UpdateServiceStatus(SERVICE_PAUSED);
+            return ERROR_SUCCESS;
+
+        case SERVICE_CONTROL_CONTINUE:
+            TRACE("  SERVICE_CONTROL_CONTINUE received\n");
+            UpdateServiceStatus(SERVICE_RUNNING);
+            return ERROR_SUCCESS;
+
+        case SERVICE_CONTROL_INTERROGATE:
+            TRACE("  SERVICE_CONTROL_INTERROGATE received\n");
+            SetServiceStatus(ServiceStatusHandle,
+                             &ServiceStatus);
+            return ERROR_SUCCESS;
+
         case SERVICE_CONTROL_SHUTDOWN:
+            TRACE("  SERVICE_CONTROL_SHUTDOWN received\n");
+            UpdateServiceStatus(SERVICE_STOPPED);
             return ERROR_SUCCESS;
 
         default :
+            TRACE("  Control %lu received\n");
             return ERROR_CALL_NOT_IMPLEMENTED;
     }
 }
 
 
-
 static VOID CALLBACK
 ServiceMain(DWORD argc, LPTSTR *argv)
 {
     UNREFERENCED_PARAMETER(argc);
     UNREFERENCED_PARAMETER(argv);
 
-    DPRINT("ServiceMain() called\n");
+    TRACE("ServiceMain() called\n");
 
     ServiceStatusHandle = RegisterServiceCtrlHandlerExW(SERVICE_NAME,
                                                         ServiceControlHandler,
                                                         NULL);
 
-    /* Service is now running */
-    ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
-    ServiceStatus.dwServiceSpecificExitCode = 0;
-    ServiceStatus.dwWin32ExitCode = NO_ERROR;
-    ServiceStatus.dwWaitHint = 0;
-    ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
-    ServiceStatus.dwCheckPoint = 0;
-    ServiceStatus.dwCurrentState = SERVICE_RUNNING;
-    SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
-    
-    DPRINT("ServiceMain() done\n");
+    TRACE("Calling SetServiceStatus()\n");
+    UpdateServiceStatus(SERVICE_RUNNING);
+    TRACE("SetServiceStatus() called\n");
+
+
+    TRACE("ServiceMain() done\n");
 }
 
 
@@ -82,11 +132,11 @@ wmain(int argc, WCHAR *argv[])
     UNREFERENCED_PARAMETER(argc);
     UNREFERENCED_PARAMETER(argv);
 
-    DPRINT("Spoolsv: main() started\n");
+    TRACE("Spoolsv: main() started\n");
 
     StartServiceCtrlDispatcher(ServiceTable);
 
-    DPRINT("Spoolsv: main() done\n");
+    TRACE("Spoolsv: main() done\n");
 
     ExitThread(0);