mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-06 09:19:03 +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
@ -55,7 +55,8 @@ Type
|
|||||||
Function ShutDown : Boolean; virtual;
|
Function ShutDown : Boolean; virtual;
|
||||||
Function Install : Boolean; virtual;
|
Function Install : Boolean; virtual;
|
||||||
Function UnInstall: 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;
|
procedure DoThreadTerminate(Sender: TObject);virtual;
|
||||||
Public
|
Public
|
||||||
Procedure CheckControlMessages(Wait : Boolean);
|
Procedure CheckControlMessages(Wait : Boolean);
|
||||||
@ -74,6 +75,7 @@ Type
|
|||||||
|
|
||||||
{ TDaemon }
|
{ TDaemon }
|
||||||
TCustomControlCodeEvent = Procedure(Sender : TCustomDaemon; ACode : DWord; Var Handled : Boolean) of object;
|
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)
|
TDaemon = Class(TCustomDaemon)
|
||||||
private
|
private
|
||||||
@ -83,6 +85,7 @@ Type
|
|||||||
FBeforeUnInstall: TDaemonEvent;
|
FBeforeUnInstall: TDaemonEvent;
|
||||||
FOnContinue: TDaemonOKEvent;
|
FOnContinue: TDaemonOKEvent;
|
||||||
FOnCustomControl: TCustomControlCodeEvent;
|
FOnCustomControl: TCustomControlCodeEvent;
|
||||||
|
FOnCustomControlEvent: TCustomControlCodeEvEvent;
|
||||||
FOnExecute: TDaemonEvent;
|
FOnExecute: TDaemonEvent;
|
||||||
FOnPause: TDaemonOKEvent;
|
FOnPause: TDaemonOKEvent;
|
||||||
FOnShutDown: TDaemonEvent;
|
FOnShutDown: TDaemonEvent;
|
||||||
@ -97,6 +100,7 @@ Type
|
|||||||
Function ShutDown : Boolean; override;
|
Function ShutDown : Boolean; override;
|
||||||
Function Install : Boolean; override;
|
Function Install : Boolean; override;
|
||||||
Function UnInstall: boolean; override;
|
Function UnInstall: boolean; override;
|
||||||
|
Function HandleCustomCode(ACode, AEventType : DWord; AEventData : Pointer) : Boolean; override;
|
||||||
Function HandleCustomCode(ACode : DWord) : Boolean; Override;
|
Function HandleCustomCode(ACode : DWord) : Boolean; Override;
|
||||||
Public
|
Public
|
||||||
Property Definition;
|
Property Definition;
|
||||||
@ -113,6 +117,7 @@ Type
|
|||||||
Property BeforeUnInstall : TDaemonEvent Read FBeforeUnInstall Write FBeforeUnInstall;
|
Property BeforeUnInstall : TDaemonEvent Read FBeforeUnInstall Write FBeforeUnInstall;
|
||||||
Property AfterUnInstall : TDaemonEvent Read FAfterUnInstall Write FAfterUnInstall;
|
Property AfterUnInstall : TDaemonEvent Read FAfterUnInstall Write FAfterUnInstall;
|
||||||
Property OnControlCode : TCustomControlCodeEvent Read FOnCustomControl Write FOnCustomControl;
|
Property OnControlCode : TCustomControlCodeEvent Read FOnCustomControl Write FOnCustomControl;
|
||||||
|
Property OnControlCodeEvent : TCustomControlCodeEvEvent Read FOnCustomControlEvent Write FOnCustomControlEvent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDaemonController }
|
{ TDaemonController }
|
||||||
@ -329,7 +334,7 @@ Type
|
|||||||
FDaemon : TCustomDaemon;
|
FDaemon : TCustomDaemon;
|
||||||
Protected
|
Protected
|
||||||
procedure StartServiceExecute; virtual;
|
procedure StartServiceExecute; virtual;
|
||||||
procedure HandleControlCode(ACode : DWord); virtual;
|
procedure HandleControlCode(ACode, AEventType : DWord; AEventData: Pointer); virtual;
|
||||||
Public
|
Public
|
||||||
Constructor Create(ADaemon : TCustomDaemon);
|
Constructor Create(ADaemon : TCustomDaemon);
|
||||||
Procedure Execute; override;
|
Procedure Execute; override;
|
||||||
@ -632,6 +637,15 @@ begin
|
|||||||
FAfterUnInstall(Self)
|
FAfterUnInstall(Self)
|
||||||
end;
|
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;
|
function TDaemon.HandleCustomCode(ACode: DWord): Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=Assigned(FOnCustomControl);
|
Result:=Assigned(FOnCustomControl);
|
||||||
@ -713,6 +727,11 @@ begin
|
|||||||
Result:=False
|
Result:=False
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomDaemon.HandleCustomCode(ACode, AEventType: DWord; AEventData: Pointer): Boolean;
|
||||||
|
begin
|
||||||
|
Result:=HandleCustomCode(ACode);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomDaemon.DoThreadTerminate(Sender: TObject);
|
procedure TCustomDaemon.DoThreadTerminate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Self.FThread := NIL;
|
Self.FThread := NIL;
|
||||||
@ -1270,7 +1289,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TDaemonThread.HandleControlCode(ACode : DWord);
|
procedure TDaemonThread.HandleControlCode(ACode, AEventType : DWord; AEventData : Pointer);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
CS : TCurrentStatus;
|
CS : TCurrentStatus;
|
||||||
@ -1291,7 +1310,7 @@ begin
|
|||||||
SERVICE_CONTROL_INTERROGATE : OK:=InterrogateDaemon;
|
SERVICE_CONTROL_INTERROGATE : OK:=InterrogateDaemon;
|
||||||
else
|
else
|
||||||
CC:=True;
|
CC:=True;
|
||||||
FDaemon.HandleCustomCode(ACode);
|
FDaemon.HandleCustomCode(ACode, AEventType, AEventData);
|
||||||
end;
|
end;
|
||||||
If not OK then
|
If not OK then
|
||||||
FDaemon.Status:=CS;
|
FDaemon.Status:=CS;
|
||||||
|
@ -180,7 +180,7 @@ procedure TDaemonController.Controller(ControlCode, EventType: DWord;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
// Send control code to daemon thread.
|
// Send control code to daemon thread.
|
||||||
TDaemonThread(Daemon.DaemonThread).HandleControlCode(ControlCode);
|
TDaemonThread(Daemon.DaemonThread).HandleControlCode(ControlCode, 0, Nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDaemonController.ReportStatus: Boolean;
|
function TDaemonController.ReportStatus: Boolean;
|
||||||
|
@ -445,6 +445,15 @@ end;
|
|||||||
TDaemonThread
|
TDaemonThread
|
||||||
---------------------------------------------------------------------}
|
---------------------------------------------------------------------}
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
TMessageRec = record
|
||||||
|
EventType: DWord;
|
||||||
|
EventData: Pointer;
|
||||||
|
end;
|
||||||
|
PMessageRec = ^TMessageRec;
|
||||||
|
|
||||||
|
|
||||||
procedure TDaemonThread.StartServiceExecute;
|
procedure TDaemonThread.StartServiceExecute;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
@ -475,8 +484,13 @@ begin
|
|||||||
begin
|
begin
|
||||||
If (Msg.hwnd<>0) or (Msg.Message<>CM_SERVICE_CONTROL_CODE) then
|
If (Msg.hwnd<>0) or (Msg.Message<>CM_SERVICE_CONTROL_CODE) then
|
||||||
DispatchMessage(Msg)
|
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
|
else
|
||||||
HandleControlCode(Msg.wParam);
|
HandleControlCode(Msg.wParam, 0, Nil);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Until StopLoop;
|
Until StopLoop;
|
||||||
|
Loading…
Reference in New Issue
Block a user