mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-24 05:39:09 +02:00
+ add support for passing EventType and EventData along to a daemons event handler, this is only useful for Windows and implemented in a way to be as backwards compatible as possible with the only exception being the virtual method TDaemonThread.HandleControlCode which now takes additional arguments
git-svn-id: trunk@46327 -
This commit is contained in:
parent
304ec430f2
commit
7be31033d7
packages/fcl-extra/src
@ -55,7 +55,8 @@ Type
|
||||
Function ShutDown : Boolean; virtual;
|
||||
Function Install : Boolean; virtual;
|
||||
Function UnInstall: boolean; virtual;
|
||||
Function HandleCustomCode(ACode : DWord) : Boolean; Virtual;
|
||||
Function HandleCustomCode(ACode : DWord) : Boolean; virtual;
|
||||
Function HandleCustomCode(ACode, AEventType : DWord; AEventData : Pointer) : Boolean; Virtual;
|
||||
procedure DoThreadTerminate(Sender: TObject);virtual;
|
||||
Public
|
||||
Procedure CheckControlMessages(Wait : Boolean);
|
||||
@ -74,6 +75,7 @@ Type
|
||||
|
||||
{ TDaemon }
|
||||
TCustomControlCodeEvent = Procedure(Sender : TCustomDaemon; ACode : DWord; Var Handled : Boolean) of object;
|
||||
TCustomControlCodeEvEvent = Procedure(Sender : TCustomDaemon; ACode, AEventType : DWord; AEventData : Pointer; Var Handled : Boolean) of object;
|
||||
|
||||
TDaemon = Class(TCustomDaemon)
|
||||
private
|
||||
@ -83,6 +85,7 @@ Type
|
||||
FBeforeUnInstall: TDaemonEvent;
|
||||
FOnContinue: TDaemonOKEvent;
|
||||
FOnCustomControl: TCustomControlCodeEvent;
|
||||
FOnCustomControlEvent: TCustomControlCodeEvEvent;
|
||||
FOnExecute: TDaemonEvent;
|
||||
FOnPause: TDaemonOKEvent;
|
||||
FOnShutDown: TDaemonEvent;
|
||||
@ -97,6 +100,7 @@ Type
|
||||
Function ShutDown : Boolean; override;
|
||||
Function Install : Boolean; override;
|
||||
Function UnInstall: boolean; override;
|
||||
Function HandleCustomCode(ACode, AEventType : DWord; AEventData : Pointer) : Boolean; override;
|
||||
Function HandleCustomCode(ACode : DWord) : Boolean; Override;
|
||||
Public
|
||||
Property Definition;
|
||||
@ -113,6 +117,7 @@ Type
|
||||
Property BeforeUnInstall : TDaemonEvent Read FBeforeUnInstall Write FBeforeUnInstall;
|
||||
Property AfterUnInstall : TDaemonEvent Read FAfterUnInstall Write FAfterUnInstall;
|
||||
Property OnControlCode : TCustomControlCodeEvent Read FOnCustomControl Write FOnCustomControl;
|
||||
Property OnControlCodeEvent : TCustomControlCodeEvEvent Read FOnCustomControlEvent Write FOnCustomControlEvent;
|
||||
end;
|
||||
|
||||
{ TDaemonController }
|
||||
@ -329,7 +334,7 @@ Type
|
||||
FDaemon : TCustomDaemon;
|
||||
Protected
|
||||
procedure StartServiceExecute; virtual;
|
||||
procedure HandleControlCode(ACode : DWord); virtual;
|
||||
procedure HandleControlCode(ACode, AEventType : DWord; AEventData: Pointer); virtual;
|
||||
Public
|
||||
Constructor Create(ADaemon : TCustomDaemon);
|
||||
Procedure Execute; override;
|
||||
@ -632,6 +637,15 @@ begin
|
||||
FAfterUnInstall(Self)
|
||||
end;
|
||||
|
||||
function TDaemon.HandleCustomCode(ACode, AEventType : DWord; AEventData : Pointer): Boolean;
|
||||
begin
|
||||
Result:=Assigned(FOnCustomControlEvent);
|
||||
If Result then
|
||||
FOnCustomControlEvent(Self,ACode,AEventType,AEventData,Result);
|
||||
If not Result then
|
||||
Result:=HandleCustomCode(ACode);
|
||||
end;
|
||||
|
||||
function TDaemon.HandleCustomCode(ACode: DWord): Boolean;
|
||||
begin
|
||||
Result:=Assigned(FOnCustomControl);
|
||||
@ -713,6 +727,11 @@ begin
|
||||
Result:=False
|
||||
end;
|
||||
|
||||
function TCustomDaemon.HandleCustomCode(ACode, AEventType: DWord; AEventData: Pointer): Boolean;
|
||||
begin
|
||||
Result:=HandleCustomCode(ACode);
|
||||
end;
|
||||
|
||||
procedure TCustomDaemon.DoThreadTerminate(Sender: TObject);
|
||||
begin
|
||||
Self.FThread := NIL;
|
||||
@ -1270,7 +1289,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaemonThread.HandleControlCode(ACode : DWord);
|
||||
procedure TDaemonThread.HandleControlCode(ACode, AEventType : DWord; AEventData : Pointer);
|
||||
|
||||
Var
|
||||
CS : TCurrentStatus;
|
||||
@ -1291,7 +1310,7 @@ begin
|
||||
SERVICE_CONTROL_INTERROGATE : OK:=InterrogateDaemon;
|
||||
else
|
||||
CC:=True;
|
||||
FDaemon.HandleCustomCode(ACode);
|
||||
FDaemon.HandleCustomCode(ACode, AEventType, AEventData);
|
||||
end;
|
||||
If not OK then
|
||||
FDaemon.Status:=CS;
|
||||
|
@ -180,7 +180,7 @@ procedure TDaemonController.Controller(ControlCode, EventType: DWord;
|
||||
|
||||
begin
|
||||
// Send control code to daemon thread.
|
||||
TDaemonThread(Daemon.DaemonThread).HandleControlCode(ControlCode);
|
||||
TDaemonThread(Daemon.DaemonThread).HandleControlCode(ControlCode, 0, Nil);
|
||||
end;
|
||||
|
||||
function TDaemonController.ReportStatus: Boolean;
|
||||
|
@ -445,6 +445,15 @@ end;
|
||||
TDaemonThread
|
||||
---------------------------------------------------------------------}
|
||||
|
||||
|
||||
type
|
||||
TMessageRec = record
|
||||
EventType: DWord;
|
||||
EventData: Pointer;
|
||||
end;
|
||||
PMessageRec = ^TMessageRec;
|
||||
|
||||
|
||||
procedure TDaemonThread.StartServiceExecute;
|
||||
|
||||
Var
|
||||
@ -475,8 +484,13 @@ begin
|
||||
begin
|
||||
If (Msg.hwnd<>0) or (Msg.Message<>CM_SERVICE_CONTROL_CODE) then
|
||||
DispatchMessage(Msg)
|
||||
else if (Msg.Message=CM_SERVICE_CONTROL_CODE) then
|
||||
begin
|
||||
HandleControlCode(Msg.wParam, PMessageRec(Msg.lParam)^.EventType, PMessageRec(Msg.lParam)^.EventData);
|
||||
System.Dispose(PMessageRec(Msg.lParam));
|
||||
end
|
||||
else
|
||||
HandleControlCode(Msg.wParam);
|
||||
HandleControlCode(Msg.wParam, 0, Nil);
|
||||
end;
|
||||
end;
|
||||
Until StopLoop;
|
||||
|
Loading…
Reference in New Issue
Block a user