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 |
+ |
ISharedMemory = interface |
52 |
+ |
['{db77bdd4-233a-4c9c-9212-dd7945e2e57c}'] |
53 |
+ |
function IsInitialiser: boolean; |
54 |
+ |
function Allocate(Size: integer): PByte; |
55 |
+ |
function GetLastAllocationSize: integer; |
56 |
+ |
property LastAllocationSize: integer read GetLastAllocationSize; |
57 |
+ |
end; |
58 |
+ |
|
59 |
+ |
|
60 |
|
TSharedMemory = class(TIpcCommon,ISharedMemory) |
61 |
|
private |
62 |
|
FBuffer: PByte; |
64 |
|
FUnused: integer; |
65 |
|
FBufptr: PByte; |
66 |
|
FSharedBuffer: THandle; |
67 |
+ |
FInitialiser: boolean; |
68 |
|
procedure GetSharedMemory(MemSize: integer); |
69 |
|
public |
70 |
|
constructor Create(MemSize: integer); |
71 |
|
destructor Destroy; override; |
72 |
|
function Allocate(Size: integer): PByte; |
73 |
|
function GetLastAllocationSize: integer; |
74 |
+ |
function IsInitialiser: boolean; |
75 |
|
property LastAllocationSize: integer read GetLastAllocationSize; |
76 |
|
end; |
77 |
|
|
81 |
|
private |
82 |
|
FMutex: THandle; |
83 |
|
public |
84 |
< |
constructor Create(MutexName: string); |
84 |
> |
constructor Create(MutexName: string; IsInitialiser: boolean); |
85 |
|
destructor Destroy; override; |
86 |
|
procedure Lock; |
87 |
|
procedure Unlock; |
112 |
|
private |
113 |
|
FEvent: THandle; |
114 |
|
public |
115 |
< |
constructor Create(EventName: string); |
115 |
> |
constructor Create(EventName: string; IsInitialiser: boolean); |
116 |
|
destructor Destroy; override; |
117 |
|
procedure PassthroughGate; |
118 |
|
procedure Unlock; |
198 |
|
function GetReadFinishedEvent: IMultiLockGate; |
199 |
|
function GetWriteLock: IMutex; |
200 |
|
function GetMonitorCount: integer; |
191 |
– |
function GetSharedMemory: ISharedMemory; |
201 |
|
function GetMaxBufferSize: integer; |
202 |
|
property DataAvailableEvent: ISingleLockGate read GetDataAvailableEvent; |
203 |
|
property WriterBusyEvent: ISingleLockGate read GetWriterBusyEvent; |
205 |
|
property ReadFinishedEvent: IMultiLockGate read GetReadFinishedEvent; |
206 |
|
property WriteLock: IMutex read GetWriteLock; |
207 |
|
property MonitorCount: integer read GetMonitorCount; |
199 |
– |
property SharedMemory: ISharedMemory read GetSharedMemory; |
208 |
|
property MaxBufferSize: integer read GetMaxBufferSize; |
209 |
|
end; |
210 |
|
|
267 |
|
Result := FLastAllocationSize; |
268 |
|
end; |
269 |
|
|
270 |
+ |
function TSharedMemory.IsInitialiser: boolean; |
271 |
+ |
begin |
272 |
+ |
Result := FInitialiser; |
273 |
+ |
end; |
274 |
+ |
|
275 |
|
{ TIpcCommon } |
276 |
|
|
277 |
|
function TIpcCommon.GetSa: PSecurityAttributes; |
294 |
|
|
295 |
|
{ TMutex } |
296 |
|
|
297 |
< |
constructor TMutex.Create(MutexName: string); |
297 |
> |
constructor TMutex.Create(MutexName: string; IsInitialiser: boolean); |
298 |
|
begin |
299 |
|
inherited Create; |
300 |
< |
if FInitialiser then |
300 |
> |
if IsInitialiser then |
301 |
|
FMutex := CreateMutex(sa, False, PChar(MutexName)) |
302 |
|
else |
303 |
|
FMutex := OpenMutex(MUTEX_ALL_ACCESS, False, PChar(MutexName)); |
327 |
|
end; |
328 |
|
|
329 |
|
{ TSingleLockGate } |
330 |
< |
constructor TSingleLockGate.Create(EventName: string); |
330 |
> |
constructor TSingleLockGate.Create(EventName: string; IsInitialiser: boolean); |
331 |
|
begin |
332 |
|
inherited Create; |
333 |
< |
if FInitialiser then |
333 |
> |
if IsInitialiser then |
334 |
|
FEvent := CreateEvent(sa, true, true, PAnsiChar(EventName)) |
335 |
|
else |
336 |
|
FEvent := OpenEvent(EVENT_ALL_ACCESS, true, PAnsiChar(EventName)); |
368 |
|
inherited Create; |
369 |
|
FSharedMemory := sm; |
370 |
|
FLockCount := PInteger(FSharedMemory.Allocate(sizeof(FLockCount))); |
371 |
< |
FMutex := TMutex.Create(EventName + '.Mutex'); |
372 |
< |
if FInitialiser then |
371 |
> |
FMutex := TMutex.Create(EventName + '.Mutex',FSharedMemory.IsInitialiser); |
372 |
> |
if FSharedMemory.IsInitialiser then |
373 |
|
begin |
374 |
|
FEvent := CreateEvent(sa, true, true, PChar(EventName)); |
375 |
|
FLockCount^ := 0; |
398 |
|
Result := FOnGateTimeout; |
399 |
|
end; |
400 |
|
|
401 |
< |
procedure TMultilockGate.SetOnGateTimeout(AValue: TNotifyEvent); |
401 |
> |
procedure TMultilockGate.SetOnGateTimeout(aValue: TNotifyEvent); |
402 |
|
begin |
403 |
|
FOnGateTimeout := AValue; |
404 |
|
end; |
456 |
|
Result := FMonitorCount^ |
457 |
|
end; |
458 |
|
|
446 |
– |
function TIPCInterface.GetSharedMemory: ISharedMemory; |
447 |
– |
begin |
448 |
– |
Result := FSharedMemory; |
449 |
– |
end; |
450 |
– |
|
459 |
|
function TIPCInterface.GetMaxBufferSize: integer; |
460 |
|
begin |
461 |
|
Result := FMaxBufferSize; |
472 |
|
inherited Create; |
473 |
|
FSharedMemory := TSharedMemory.Create(cMonitorHookSize); |
474 |
|
|
475 |
< |
FWriteLock := TMutex.Create(PChar(MonitorHookNames[0])); |
476 |
< |
FDataAvailableEvent := TSingleLockGate.Create(MonitorHookNames[2]); |
477 |
< |
FWriterBusyEvent := TSingleLockGate.Create(MonitorHookNames[3]); |
475 |
> |
FWriteLock := TMutex.Create(PChar(MonitorHookNames[0]),FSharedMemory.IsInitialiser); |
476 |
> |
FDataAvailableEvent := TSingleLockGate.Create(MonitorHookNames[2],FSharedMemory.IsInitialiser); |
477 |
> |
FWriterBusyEvent := TSingleLockGate.Create(MonitorHookNames[3],FSharedMemory.IsInitialiser); |
478 |
|
FReadReadyEvent := TMultiLockGate.Create(MonitorHookNames[4],FSharedMemory); |
479 |
|
FReadReadyEvent.OnGateTimeout := HandleGateTimeout; |
480 |
|
FReadFinishedEvent := TMultiLockGate.Create(MonitorHookNames[5],FSharedMemory); |
482 |
|
|
483 |
|
FMonitorCount := PInteger(FSharedMemory.Allocate(sizeof(FMonitorCount))); |
484 |
|
|
485 |
< |
if FInitialiser then |
485 |
> |
if FSharedMemory.IsInitialiser then |
486 |
|
FMonitorCount^ := 0; |
487 |
|
FTraceDataType := PInteger(FSharedMemory.Allocate(sizeof(Integer))); |
488 |
|
FTimeStamp := PDateTime(FSharedMemory.Allocate(sizeof(TDateTime))); |
491 |
|
FBuffer := FSharedMemory.Allocate(0); //All remaining |
492 |
|
FMaxBufferSize := FSharedMemory.LastAllocationSize; |
493 |
|
|
494 |
< |
if FInitialiser then |
494 |
> |
if FSharedMemory.IsInitialiser then |
495 |
|
begin |
496 |
|
FBufferSize^ := 0; |
497 |
|
FDataAvailableEvent.Lock; |