]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
zap the evil externs, and comment the lot
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Aug 2008 14:41:55 +0000 (14:41 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Aug 2008 14:41:55 +0000 (14:41 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10205 e03df62e-2008-0410-955e-edbf42e46eb7

win/win32service.cpp

index 0f8a2010806f8eac9edaf137c79d31a1412b4691..d364cd6ce9f05a78828df70bdb1c4fa847dbbd21 100644 (file)
  *
  * ---------------------------------------------------
  */\r
-\r
+#include "inspircd_config.h"\r
+#include "inspircd.h"\r
 #include <windows.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
 #include <stdio.h>\r
 \r
-extern int smain(int argc, char** argv);\r
-extern const char* dlerror();\r
-\r
 static SERVICE_STATUS_HANDLE serviceStatusHandle;\r
 static HANDLE hThreadEvent;\r
 static HANDLE killServiceEvent;\r
 static int serviceCurrentStatus;\r
 \r
-// This is used to define ChangeServiceConf2() as we can't link\r
-// directly against this symbol (see below where it is used)\r
+/** This is used to define ChangeServiceConf2() as we can't link\r
+ * directly against this symbol (see below where it is used)\r
+ */\r
 typedef BOOL (CALLBACK* SETSERVDESC)(SC_HANDLE,DWORD,LPVOID);\r
 \r
 /* A commandline parameter handler for service specific commandline parameters */\r
@@ -38,18 +37,20 @@ struct Commandline
        CommandlineParameterHandler Handler;\r
 };\r
 \r
+/* A function pointer for dynamic linking tricks */\r
+SETSERVDESC ChangeServiceConf;\r
 \r
-SETSERVDESC ChangeServiceConf;         // A function pointer for dynamic linking tricks\r
-\r
-\r
+/* Kills the service by setting an event which the other thread picks up and exits */\r
 void KillService()\r
 {\r
-       /* FIXME: This should set a flag in the mainloop for shutting down */\r
        SetEvent(hThreadEvent);\r
        Sleep(2000);\r
        SetEvent(killServiceEvent);\r
 }\r
 \r
+/** The main part of inspircd runs within this thread function. This allows the service part to run\r
+ * seperately on its own and to be able to kill the worker thread when its time to quit.\r
+ */\r
 DWORD WINAPI WorkerThread(LPDWORD param)\r
 {\r
        // *** REAL MAIN HERE ***\r
@@ -61,13 +62,16 @@ DWORD WINAPI WorkerThread(LPDWORD param)
        return 0;\r
 }\r
 \r
+/** Starts the worker thread above */\r
 void StartServiceThread()\r
 {\r
        DWORD dwd;\r
        CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)WorkerThread,NULL,0,&dwd);\r
 }\r
 \r
-\r
+/** This function updates the status of the service in the SCM\r
+ * (service control manager, the services.msc applet)\r
+ */\r
 BOOL UpdateSCMStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint)\r
 {\r
        BOOL success;\r
@@ -104,14 +108,14 @@ BOOL UpdateSCMStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServi
        return success;\r
 }\r
 \r
-\r
+/** This function is called by us when the service is being shut down or when it can't be started */\r
 void terminateService (int code, int wincode)\r
 {\r
        UpdateSCMStatus(SERVICE_STOPPED,wincode?wincode:ERROR_SERVICE_SPECIFIC_ERROR,(wincode)?0:code,0,0);\r
        return;\r
 }\r
 \r
-\r
+/** This callback is called by windows when the state of the service has been changed */\r
 VOID ServiceCtrlHandler (DWORD controlCode)\r
 {\r
        switch(controlCode)\r
@@ -131,7 +135,7 @@ VOID ServiceCtrlHandler (DWORD controlCode)
        UpdateSCMStatus(serviceCurrentStatus, NO_ERROR, 0, 0, 0);\r
 }\r
 \r
-\r
+/** This callback is called by windows when the service is started */\r
 VOID ServiceMain(DWORD argc, LPTSTR *argv)\r
 {\r
        BOOL success;\r
@@ -151,8 +155,8 @@ VOID ServiceMain(DWORD argc, LPTSTR *argv)
                return;\r
        }\r
 \r
-       killServiceEvent = CreateEvent(NULL,true,false,NULL);\r
-       hThreadEvent = CreateEvent(NULL,true,false,NULL);\r
+       killServiceEvent = CreateEvent(NULL, true, false, NULL);\r
+       hThreadEvent = CreateEvent(NULL, true, false, NULL);\r
 \r
        if (!killServiceEvent || !hThreadEvent)\r
        {\r
@@ -178,6 +182,7 @@ VOID ServiceMain(DWORD argc, LPTSTR *argv)
        WaitForSingleObject (killServiceEvent, INFINITE);\r
 }\r
 \r
+/** Install the windows service. This requires administrator privileges. */\r
 void InstallService()\r
 {\r
        SC_HANDLE myService, scm;\r
@@ -234,6 +239,7 @@ void InstallService()
        CloseServiceHandle(scm);\r
 }\r
 \r
+/** Remove the windows service. This requires administrator privileges. */\r
 void RemoveService()\r
 {\r
        SC_HANDLE myService, scm;\r
@@ -269,7 +275,7 @@ void RemoveService()
 /* In windows, our main() flows through here, before calling the 'real' main, smain() in inspircd.cpp */\r
 int main(int argc, char** argv)\r
 {\r
-\r
+       /* List of parameters and handlers */\r
        Commandline params[] = {\r
                { "--installservice", InstallService },\r
                { "--removeservice", RemoveService },\r