*
* ---------------------------------------------------
*/\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
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
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
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
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
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
WaitForSingleObject (killServiceEvent, INFINITE);\r
}\r
\r
+/** Install the windows service. This requires administrator privileges. */\r
void InstallService()\r
{\r
SC_HANDLE myService, scm;\r
CloseServiceHandle(scm);\r
}\r
\r
+/** Remove the windows service. This requires administrator privileges. */\r
void RemoveService()\r
{\r
SC_HANDLE myService, scm;\r
/* 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