11 |
|
'FB.SQL.MONITOR.ReadEvent1_0', |
12 |
|
'FB.SQL.MONITOR.ReadFinishedEvent1_0' |
13 |
|
); |
14 |
< |
cDefaultTimeout = 1000; {seconds } |
14 |
> |
cDefaultTimeout = 10000; {milli seconds } |
15 |
|
|
16 |
|
type |
17 |
|
{Interprocess Communication Objects. All platform dependent IPC is abstracted |
21 |
|
|
22 |
|
TIpcCommon = class(TInterfacedObject) |
23 |
|
protected |
24 |
– |
class var FInitialiser: boolean; |
24 |
|
FSa : TSecurityAttributes; |
25 |
|
private |
26 |
|
Sd : TSecurityDescriptor; |
48 |
|
|
49 |
|
} |
50 |
|
|
51 |
< |
TSharedMemory = class(TIpcCommon,ISharedMemory) |
51 |
> |
ISharedMemoryExt = interface(ISharedMemory) |
52 |
> |
['{7449e122-61c0-4ea9-acf4-f0a420af14aa}'] |
53 |
> |
function IsInitialiser: boolean; |
54 |
> |
end; |
55 |
> |
|
56 |
> |
TSharedMemory = class(TIpcCommon,ISharedMemoryExt) |
57 |
|
private |
58 |
|
FBuffer: PByte; |
59 |
|
FLastAllocationSize: integer; |
60 |
|
FUnused: integer; |
61 |
|
FBufptr: PByte; |
62 |
|
FSharedBuffer: THandle; |
63 |
+ |
FInitialiser: boolean; |
64 |
|
procedure GetSharedMemory(MemSize: integer); |
65 |
|
public |
66 |
|
constructor Create(MemSize: integer); |
67 |
|
destructor Destroy; override; |
68 |
|
function Allocate(Size: integer): PByte; |
69 |
|
function GetLastAllocationSize: integer; |
70 |
+ |
function IsInitialiser: boolean; |
71 |
|
property LastAllocationSize: integer read GetLastAllocationSize; |
72 |
|
end; |
73 |
|
|
77 |
|
private |
78 |
|
FMutex: THandle; |
79 |
|
public |
80 |
< |
constructor Create(MutexName: string); |
80 |
> |
constructor Create(MutexName: string; IsInitialiser: boolean); |
81 |
|
destructor Destroy; override; |
82 |
|
procedure Lock; |
83 |
|
procedure Unlock; |
108 |
|
private |
109 |
|
FEvent: THandle; |
110 |
|
public |
111 |
< |
constructor Create(EventName: string); |
111 |
> |
constructor Create(EventName: string; IsInitialiser: boolean); |
112 |
|
destructor Destroy; override; |
113 |
|
procedure PassthroughGate; |
114 |
|
procedure Unlock; |
146 |
|
|
147 |
|
TMultilockGate = class(TIpcCommon, IMultilockGate) |
148 |
|
private |
149 |
< |
FSharedMemory: ISharedMemory; |
149 |
> |
FSharedMemory: ISharedMemoryExt; |
150 |
|
FOnGateTimeout: TNotifyEvent; |
151 |
|
FEvent: THandle; |
152 |
|
FLockCount: PInteger; |
153 |
|
FMutex: TMutex; |
154 |
|
public |
155 |
< |
constructor Create(EventName: string; sm: ISharedMemory); |
155 |
> |
constructor Create(EventName: string; sm: ISharedMemoryExt); |
156 |
|
destructor Destroy; override; |
157 |
|
procedure Lock; |
158 |
|
procedure Unlock; |
169 |
|
TIPCInterface = class(TIpcCommon, IIPCInterface) |
170 |
|
private |
171 |
|
FMaxBufferSize: integer; |
172 |
< |
FSharedMemory: ISharedMemory; |
172 |
> |
FSharedMemory: ISharedMemoryExt; |
173 |
|
FWriteLock: IMutex; |
174 |
|
FBuffer: PByte; |
175 |
|
FTraceDataType, |
265 |
|
Result := FLastAllocationSize; |
266 |
|
end; |
267 |
|
|
268 |
+ |
function TSharedMemory.IsInitialiser: boolean; |
269 |
+ |
begin |
270 |
+ |
Result := FInitialiser; |
271 |
+ |
end; |
272 |
+ |
|
273 |
|
{ TIpcCommon } |
274 |
|
|
275 |
|
function TIpcCommon.GetSa: PSecurityAttributes; |
292 |
|
|
293 |
|
{ TMutex } |
294 |
|
|
295 |
< |
constructor TMutex.Create(MutexName: string); |
295 |
> |
constructor TMutex.Create(MutexName: string; IsInitialiser: boolean); |
296 |
|
begin |
297 |
|
inherited Create; |
298 |
< |
if FInitialiser then |
298 |
> |
if IsInitialiser then |
299 |
|
FMutex := CreateMutex(sa, False, PChar(MutexName)) |
300 |
|
else |
301 |
|
FMutex := OpenMutex(MUTEX_ALL_ACCESS, False, PChar(MutexName)); |
325 |
|
end; |
326 |
|
|
327 |
|
{ TSingleLockGate } |
328 |
< |
constructor TSingleLockGate.Create(EventName: string); |
328 |
> |
constructor TSingleLockGate.Create(EventName: string; IsInitialiser: boolean); |
329 |
|
begin |
330 |
|
inherited Create; |
331 |
< |
if FInitialiser then |
331 |
> |
if IsInitialiser then |
332 |
|
FEvent := CreateEvent(sa, true, true, PAnsiChar(EventName)) |
333 |
|
else |
334 |
|
FEvent := OpenEvent(EVENT_ALL_ACCESS, true, PAnsiChar(EventName)); |
361 |
|
|
362 |
|
{ TMultilockGate } |
363 |
|
|
364 |
< |
constructor TMultilockGate.Create(EventName: string; sm: ISharedMemory); |
364 |
> |
constructor TMultilockGate.Create(EventName: string; sm: ISharedMemoryExt); |
365 |
|
begin |
366 |
|
inherited Create; |
367 |
|
FSharedMemory := sm; |
368 |
|
FLockCount := PInteger(FSharedMemory.Allocate(sizeof(FLockCount))); |
369 |
< |
FMutex := TMutex.Create(EventName + '.Mutex'); |
370 |
< |
if FInitialiser then |
369 |
> |
FMutex := TMutex.Create(EventName + '.Mutex',FSharedMemory.IsInitialiser); |
370 |
> |
if FSharedMemory.IsInitialiser then |
371 |
|
begin |
372 |
|
FEvent := CreateEvent(sa, true, true, PChar(EventName)); |
373 |
|
FLockCount^ := 0; |
396 |
|
Result := FOnGateTimeout; |
397 |
|
end; |
398 |
|
|
399 |
< |
procedure TMultilockGate.SetOnGateTimeout(AValue: TNotifyEvent); |
399 |
> |
procedure TMultilockGate.SetOnGateTimeout(aValue: TNotifyEvent); |
400 |
|
begin |
401 |
|
FOnGateTimeout := AValue; |
402 |
|
end; |
475 |
|
inherited Create; |
476 |
|
FSharedMemory := TSharedMemory.Create(cMonitorHookSize); |
477 |
|
|
478 |
< |
FWriteLock := TMutex.Create(PChar(MonitorHookNames[0])); |
479 |
< |
FDataAvailableEvent := TSingleLockGate.Create(MonitorHookNames[2]); |
480 |
< |
FWriterBusyEvent := TSingleLockGate.Create(MonitorHookNames[3]); |
478 |
> |
FWriteLock := TMutex.Create(PChar(MonitorHookNames[0]),FSharedMemory.IsInitialiser); |
479 |
> |
FDataAvailableEvent := TSingleLockGate.Create(MonitorHookNames[2],FSharedMemory.IsInitialiser); |
480 |
> |
FWriterBusyEvent := TSingleLockGate.Create(MonitorHookNames[3],FSharedMemory.IsInitialiser); |
481 |
|
FReadReadyEvent := TMultiLockGate.Create(MonitorHookNames[4],FSharedMemory); |
482 |
|
FReadReadyEvent.OnGateTimeout := HandleGateTimeout; |
483 |
|
FReadFinishedEvent := TMultiLockGate.Create(MonitorHookNames[5],FSharedMemory); |
485 |
|
|
486 |
|
FMonitorCount := PInteger(FSharedMemory.Allocate(sizeof(FMonitorCount))); |
487 |
|
|
488 |
< |
if FInitialiser then |
488 |
> |
if FSharedMemory.IsInitialiser then |
489 |
|
FMonitorCount^ := 0; |
490 |
|
FTraceDataType := PInteger(FSharedMemory.Allocate(sizeof(Integer))); |
491 |
|
FTimeStamp := PDateTime(FSharedMemory.Allocate(sizeof(TDateTime))); |
494 |
|
FBuffer := FSharedMemory.Allocate(0); //All remaining |
495 |
|
FMaxBufferSize := FSharedMemory.LastAllocationSize; |
496 |
|
|
497 |
< |
if FInitialiser then |
497 |
> |
if FSharedMemory.IsInitialiser then |
498 |
|
begin |
499 |
|
FBufferSize^ := 0; |
500 |
|
FDataAvailableEvent.Lock; |