60 |
|
{ } |
61 |
|
{************************************************************************} |
62 |
|
unit FB25Events; |
63 |
+ |
{$IFDEF MSWINDOWS} |
64 |
+ |
{$DEFINE WINDOWS} |
65 |
+ |
{$ENDIF} |
66 |
|
|
67 |
|
{$IFDEF FPC} |
68 |
< |
{$mode objfpc}{$H+} |
68 |
> |
{$mode delphi} |
69 |
|
{$interfaces COM} |
70 |
|
{$ENDIF} |
71 |
|
|
93 |
|
public |
94 |
|
constructor Create(aOwner: TFB25Events); |
95 |
|
destructor Destroy; override; |
96 |
< |
procedure eventCallbackFunction(length: short; updated: PChar); |
96 |
> |
procedure eventCallbackFunction(length: short; updated: PAnsiChar); |
97 |
|
procedure WaitForEvent; |
98 |
|
procedure CancelWait; |
99 |
|
end; |
106 |
|
FDBHandle: TISC_DB_HANDLE; |
107 |
|
FEventHandlerThread: TObject; |
108 |
|
FAsyncEventCallback: TEventhandlerInterface; |
109 |
+ |
FFirebird25ClientAPI: TFB25ClientAPI; |
110 |
|
protected |
111 |
|
procedure CancelEvents(Force: boolean = false); override; |
112 |
|
function GetIEvents: IEvents; override; |
115 |
|
destructor Destroy; override; |
116 |
|
|
117 |
|
{IEvents} |
118 |
< |
procedure WaitForEvent; |
118 |
> |
procedure WaitForEvent; override; |
119 |
|
procedure AsyncWaitForEvent(EventHandler: TEventHandler); override; |
120 |
|
end; |
121 |
|
|
154 |
|
constructor TEventHandlerThread.Create(Owner: TFB25Events; |
155 |
|
EventHandler: TEventhandlerInterface); |
156 |
|
begin |
157 |
< |
inherited Create(true); |
157 |
> |
inherited Create(false); |
158 |
|
FOwner := Owner; |
159 |
|
FEventHandler := EventHandler; |
160 |
|
FreeOnTerminate := true; |
157 |
– |
Start; |
161 |
|
end; |
162 |
|
|
163 |
|
procedure TEventHandlerThread.Terminate; |
168 |
|
|
169 |
|
{This procedure is used for the event call back - note the cdecl } |
170 |
|
|
171 |
< |
procedure IBEventCallback( ptr: pointer; length: short; updated: PChar); cdecl; |
171 |
> |
procedure IBEventCallback( ptr: pointer; length: short; updated: PAnsiChar); cdecl; |
172 |
|
begin |
173 |
|
if (ptr = nil) or (length = 0) or (updated = nil) then |
174 |
|
Exit; |
217 |
|
end; |
218 |
|
|
219 |
|
procedure TEventhandlerInterface.eventCallbackFunction(length: short; |
220 |
< |
updated: PChar); |
220 |
> |
updated: PAnsiChar); |
221 |
|
begin |
222 |
|
FOwner.FCriticalSection.Enter; |
223 |
|
try |
261 |
|
FCriticalSection.Enter; |
262 |
|
try |
263 |
|
if not FInWaitState then Exit; |
264 |
< |
with Firebird25ClientAPI do |
264 |
> |
with FFirebird25ClientAPI do |
265 |
|
if (Call(isc_Cancel_events( StatusVector, @FDBHandle, @FEventID),false) > 0) and not Force then |
266 |
|
IBDatabaseError; |
267 |
|
|
281 |
|
begin |
282 |
|
inherited Create(DBAttachment,DBAttachment,Events); |
283 |
|
FDBHandle := DBAttachment.Handle; |
284 |
+ |
FFirebird25ClientAPI := DBAttachment.Firebird25ClientAPI; |
285 |
+ |
OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError; |
286 |
|
FAsyncEventCallback := TEventhandlerInterface.Create(self); |
287 |
|
FEventHandlerThread := TEventHandlerThread.Create(self,FAsyncEventCallback); |
288 |
|
end; |
307 |
|
|
308 |
|
FEventHandler := EventHandler; |
309 |
|
callback := @IBEventCallback; |
310 |
< |
with Firebird25ClientAPI do |
310 |
> |
with FFirebird25ClientAPI do |
311 |
|
Call(isc_que_events( StatusVector, @FDBHandle, @FEventID, FEventBufferLen, |
312 |
|
FEventBuffer, TISC_CALLBACK(callback), PVoid(FAsyncEventCallback))); |
313 |
|
FInWaitState := true; |
323 |
|
|
324 |
|
FInWaitState := true; |
325 |
|
try |
326 |
< |
with Firebird25ClientAPI do |
326 |
> |
with FFirebird25ClientAPI do |
327 |
|
Call(isc_wait_for_event(StatusVector,@FDBHandle, FEventBufferlen,FEventBuffer,FResultBuffer)); |
328 |
|
finally |
329 |
|
FInWaitState := false; |