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; |
116 |
|
|
117 |
|
{IEvents} |
118 |
|
procedure WaitForEvent; |
119 |
< |
procedure AsyncWaitForEvent(EventHandler: TEventHandler); |
119 |
> |
procedure AsyncWaitForEvent(EventHandler: TEventHandler); override; |
120 |
|
end; |
121 |
|
|
122 |
|
implementation |
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; |
198 |
|
{$ENDIF} |
199 |
|
inherited Create; |
200 |
|
{$IFDEF WINDOWS} |
201 |
< |
FEventHandler := CreateEvent(PSa,false,true,nil); |
201 |
> |
FEventHandler := CreateEvent(PSa,false,false,nil); |
202 |
|
{$ELSE} |
203 |
|
CreateGuid(GUID); |
204 |
|
FEventWaiting := TEventObject.Create(PSa,false,false,GUIDToString(GUID)); |
217 |
|
end; |
218 |
|
|
219 |
|
procedure TEventhandlerInterface.eventCallbackFunction(length: short; |
220 |
< |
updated: PChar); |
220 |
> |
updated: PAnsiChar); |
221 |
|
begin |
222 |
|
FOwner.FCriticalSection.Enter; |
223 |
|
try |
224 |
|
if FOwner.FResultBuffer <> nil then |
225 |
|
Move(updated[0], FOwner.FResultBuffer[0], length); |
223 |
– |
{$IFDEF WINDOWS} |
224 |
– |
SetEvent(FEventHandler); |
225 |
– |
{$ELSE} |
226 |
– |
FEventWaiting.SetEvent; |
227 |
– |
{$ENDIF} |
226 |
|
finally |
227 |
|
FOwner.FCriticalSection.Leave |
228 |
|
end; |
229 |
+ |
// writeln('Set Event'); |
230 |
+ |
{$IFDEF WINDOWS} |
231 |
+ |
SetEvent(FEventHandler); |
232 |
+ |
{$ELSE} |
233 |
+ |
FEventWaiting.SetEvent; |
234 |
+ |
{$ENDIF} |
235 |
|
end; |
236 |
|
|
237 |
|
procedure TEventhandlerInterface.WaitForEvent; |
241 |
|
{$ELSE} |
242 |
|
FEventWaiting.WaitFor(INFINITE); |
243 |
|
{$ENDIF} |
244 |
+ |
// writeln('Event Wait Ends'); |
245 |
|
end; |
246 |
|
|
247 |
|
procedure TEventhandlerInterface.CancelWait; |
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; |
305 |
|
if FInWaitState then |
306 |
|
IBError(ibxeInEventWait,[nil]); |
307 |
|
|
301 |
– |
CreateEventBlock; |
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 |
< |
CreateEventBlock; |
321 |
< |
with Firebird25ClientAPI do |
326 |
> |
with FFirebird25ClientAPI do |
327 |
|
Call(isc_wait_for_event(StatusVector,@FDBHandle, FEventBufferlen,FEventBuffer,FResultBuffer)); |
328 |
|
finally |
329 |
|
FInWaitState := false; |