/usr/lib/lazarus/0.9.30.4/lcl/asyncprocess.pp is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | {
/***************************************************************************
AsyncProcess.pp
---------------
Initial Revision : Tue Dec 06 09:00:00 CET 2005
***************************************************************************/
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
unit AsyncProcess;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Process, LCLProc, FileUtil, InterfaceBase, LCLIntf, UTF8Process;
type
{ TAsyncProcess }
TAsyncProcess = class(TProcessUTF8)
private
FPipeHandler: PPipeEventHandler;
FProcessHandler: PProcessEventHandler;
FOnReadData: TNotifyEvent;
FOnTerminate: TNotifyEvent;
protected
function GetNumBytesAvailable: dword;
procedure HandlePipeInput(AData: PtrInt; AReasons: TPipeReasons);
procedure HandleProcessTermination(AData: PtrInt; AReason: TChildExitReason; AInfo: dword);
procedure UnhookPipeHandle;
procedure UnhookProcessHandle;
public
procedure Execute; override;
destructor Destroy; override;
property NumBytesAvailable: dword read GetNumBytesAvailable;
published
property OnReadData: TNotifyEvent read FOnReadData write FOnReadData;// You must read all the data in this event. Otherwise it is called again.
property OnTerminate: TNotifyEvent read FOnTerminate write FOnTerminate;
end;
procedure Register;
implementation
function TAsyncProcess.GetNumBytesAvailable: dword;
begin
if not (poUsePipes in Options) then
Result := 0
else
Result := Output.NumBytesAvailable;
end;
destructor TAsyncProcess.Destroy;
begin
UnhookProcessHandle;
UnhookPipeHandle;
inherited;
end;
procedure TAsyncProcess.UnhookProcessHandle;
begin
if FProcessHandler <> nil then
RemoveProcessEventHandler(FProcessHandler);
end;
procedure TAsyncProcess.UnhookPipeHandle;
begin
if FPipeHandler <> nil then
RemovePipeEventHandler(FPipeHandler);
end;
procedure TAsyncProcess.HandlePipeInput(AData: PtrInt; AReasons: TPipeReasons);
begin
if prBroken in AReasons then
UnhookPipeHandle;
if prDataAvailable in AReasons then
if FOnReadData <> nil then
FOnReadData(Self);
end;
procedure TAsyncProcess.HandleProcessTermination(AData: PtrInt; AReason: TChildExitReason; AInfo: dword);
begin
UnhookProcessHandle;
UnhookPipeHandle;
if FOnTerminate <> nil then
FOnTerminate(Self);
end;
procedure TAsyncProcess.Execute;
begin
inherited Execute;
if poUsePipes in Options then
FPipeHandler := AddPipeEventHandler(Output.Handle, @HandlePipeInput, 0);
FProcessHandler := AddProcessEventHandler(ProcessHandle, @HandleProcessTermination, 0);
end;
procedure Register;
begin
RegisterComponents('System',[TAsyncProcess]);
end;
end.
|