daemonapp.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. {
  2. $Id: header,v 1.1 2000/07/13 06:33:45 michael Exp $
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { System dependent service stuff }
  12. uses baseunix;
  13. { ---------------------------------------------------------------------
  14. TCustomDaemonApplication
  15. ---------------------------------------------------------------------}
  16. Const
  17. SERVICE_CONTROL_STOP = $00000001;
  18. SERVICE_CONTROL_PAUSE = $00000002;
  19. SERVICE_CONTROL_CONTINUE = $00000003;
  20. SERVICE_CONTROL_INTERROGATE = $00000004;
  21. SERVICE_CONTROL_SHUTDOWN = $00000005;
  22. function TCustomDaemonApplication.RunGUIloop(P: Pointer): integer;
  23. begin
  24. end;
  25. procedure TCustomDaemonApplication.SysInstallDaemon(Daemon: TCustomDaemon);
  26. begin
  27. end;
  28. procedure TCustomDaemonApplication.SysUnInstallDaemon(Daemon: TCustomDaemon);
  29. begin
  30. end;
  31. procedure TCustomDaemonApplication.SysStartUnInstallDaemons;
  32. begin
  33. end;
  34. procedure TCustomDaemonApplication.SysEndUnInstallDaemons;
  35. begin
  36. end;
  37. procedure TCustomDaemonApplication.SysStartInstallDaemons;
  38. begin
  39. end;
  40. procedure TCustomDaemonApplication.SysEndInstallDaemons;
  41. begin
  42. end;
  43. procedure TCustomDaemonApplication.SysStartRunDaemons;
  44. begin
  45. end;
  46. procedure TCustomDaemonApplication.SysEndRunDaemons;
  47. Var
  48. I : Integer;
  49. DC : TDaemonController;
  50. begin
  51. For I:=ComponentCount-1 downto 0 do
  52. If Components[i] is TDaemoncontroller then
  53. begin
  54. DC:=Components[i] as TDaemoncontroller;
  55. DC.Main(0,Nil); // Returns after starting thread.
  56. end;
  57. if Assigned(GUIMainLoop) then
  58. GuiMainLoop
  59. else
  60. // Simply wait till everything terminates.
  61. While Not Terminated do
  62. fpPause;
  63. end;
  64. procedure TCustomDaemonApplication.RemoveController(
  65. AController: TDaemonController);
  66. Var
  67. I : Integer;
  68. HC : Boolean;
  69. begin
  70. FreeAndNil(AController.FDaemon);
  71. AController.Free;
  72. end;
  73. { ---------------------------------------------------------------------
  74. TDaemonThread
  75. ---------------------------------------------------------------------}
  76. procedure TDaemonThread.StartServiceExecute;
  77. begin
  78. end;
  79. procedure TDaemonThread.CheckControlMessage(WaitForMessage : Boolean);
  80. begin
  81. end;
  82. { ---------------------------------------------------------------------
  83. TDaemonController
  84. ---------------------------------------------------------------------}
  85. procedure TDaemonController.StartService;
  86. begin
  87. Main(0,Nil);
  88. end;
  89. procedure TDaemonController.Main(Argc: DWord; Args: PPChar);
  90. Var
  91. T : TThread;
  92. begin
  93. FDaemon.Status:=csStartPending;
  94. Try
  95. T:=TDaemonThread.Create(FDaemon);
  96. T.FreeOnTerminate:=True;
  97. T.Resume;
  98. T.WaitFor;
  99. FDaemon.FThread:=Nil;
  100. except
  101. On E : Exception do
  102. FDaemon.Logmessage(Format(SErrDaemonStartFailed,[FDaemon.Definition.Name,E.Message]));
  103. end;
  104. end;
  105. procedure TDaemonController.Controller(ControlCode, EventType: DWord;
  106. EventData: Pointer);
  107. begin
  108. // Send control code to daemon thread.
  109. end;
  110. function TDaemonController.ReportStatus: Boolean;
  111. Var
  112. S : String;
  113. begin
  114. S:='';
  115. If Assigned(FDaemon) then
  116. With FDaemon do
  117. S:=Format(SDaemonStatus,[Definition.DisplayName,
  118. CurrentStatusNames[Status]]);
  119. Application.Logger.Info(S);
  120. end;
  121. Procedure TDaemonController.ThreadTerminated(Sender : TObject);
  122. begin
  123. end;
  124. { ---------------------------------------------------------------------
  125. Global initialization/Finalization
  126. ---------------------------------------------------------------------}
  127. Procedure DoShutDown(Sig : Longint; Info : PSigInfo; Context : PSigContext); cdecl;
  128. begin
  129. Application.StopDaemons(True);
  130. Application.Terminate;
  131. end;
  132. Procedure SysInitDaemonApp;
  133. Var
  134. old,new : SigactionRec;
  135. begin
  136. New.sa_handler:=@DoShutDown;
  137. fpSigaction(SIGQUIT,@New,@Old);
  138. fpSigaction(SIGTERM,@New,@Old);
  139. fpSigaction(SIGINT,@New,@Old);
  140. end;
  141. Procedure SysDoneDaemonApp;
  142. begin
  143. end;