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; |
115 |
|
|
116 |
|
{IEvents} |
117 |
|
procedure WaitForEvent; |
118 |
< |
procedure AsyncWaitForEvent(EventHandler: TEventHandler); |
118 |
> |
procedure AsyncWaitForEvent(EventHandler: TEventHandler); override; |
119 |
|
end; |
120 |
|
|
121 |
|
implementation |
153 |
|
constructor TEventHandlerThread.Create(Owner: TFB25Events; |
154 |
|
EventHandler: TEventhandlerInterface); |
155 |
|
begin |
156 |
< |
inherited Create(true); |
156 |
> |
inherited Create(false); |
157 |
|
FOwner := Owner; |
158 |
|
FEventHandler := EventHandler; |
159 |
|
FreeOnTerminate := true; |
157 |
– |
Start; |
160 |
|
end; |
161 |
|
|
162 |
|
procedure TEventHandlerThread.Terminate; |
167 |
|
|
168 |
|
{This procedure is used for the event call back - note the cdecl } |
169 |
|
|
170 |
< |
procedure IBEventCallback( ptr: pointer; length: short; updated: PChar); cdecl; |
170 |
> |
procedure IBEventCallback( ptr: pointer; length: short; updated: PAnsiChar); cdecl; |
171 |
|
begin |
172 |
|
if (ptr = nil) or (length = 0) or (updated = nil) then |
173 |
|
Exit; |
197 |
|
{$ENDIF} |
198 |
|
inherited Create; |
199 |
|
{$IFDEF WINDOWS} |
200 |
< |
FEventHandler := CreateEvent(PSa,false,true,nil); |
200 |
> |
FEventHandler := CreateEvent(PSa,false,false,nil); |
201 |
|
{$ELSE} |
202 |
|
CreateGuid(GUID); |
203 |
|
FEventWaiting := TEventObject.Create(PSa,false,false,GUIDToString(GUID)); |
216 |
|
end; |
217 |
|
|
218 |
|
procedure TEventhandlerInterface.eventCallbackFunction(length: short; |
219 |
< |
updated: PChar); |
219 |
> |
updated: PAnsiChar); |
220 |
|
begin |
221 |
|
FOwner.FCriticalSection.Enter; |
222 |
|
try |
223 |
|
if FOwner.FResultBuffer <> nil then |
224 |
|
Move(updated[0], FOwner.FResultBuffer[0], length); |
223 |
– |
{$IFDEF WINDOWS} |
224 |
– |
SetEvent(FEventHandler); |
225 |
– |
{$ELSE} |
226 |
– |
FEventWaiting.SetEvent; |
227 |
– |
{$ENDIF} |
225 |
|
finally |
226 |
|
FOwner.FCriticalSection.Leave |
227 |
|
end; |
228 |
+ |
// writeln('Set Event'); |
229 |
+ |
{$IFDEF WINDOWS} |
230 |
+ |
SetEvent(FEventHandler); |
231 |
+ |
{$ELSE} |
232 |
+ |
FEventWaiting.SetEvent; |
233 |
+ |
{$ENDIF} |
234 |
|
end; |
235 |
|
|
236 |
|
procedure TEventhandlerInterface.WaitForEvent; |
240 |
|
{$ELSE} |
241 |
|
FEventWaiting.WaitFor(INFINITE); |
242 |
|
{$ENDIF} |
243 |
+ |
// writeln('Event Wait Ends'); |
244 |
|
end; |
245 |
|
|
246 |
|
procedure TEventhandlerInterface.CancelWait; |
302 |
|
if FInWaitState then |
303 |
|
IBError(ibxeInEventWait,[nil]); |
304 |
|
|
301 |
– |
CreateEventBlock; |
305 |
|
FEventHandler := EventHandler; |
306 |
|
callback := @IBEventCallback; |
307 |
|
with Firebird25ClientAPI do |
320 |
|
|
321 |
|
FInWaitState := true; |
322 |
|
try |
320 |
– |
CreateEventBlock; |
323 |
|
with Firebird25ClientAPI do |
324 |
|
Call(isc_wait_for_event(StatusVector,@FDBHandle, FEventBufferlen,FEventBuffer,FResultBuffer)); |
325 |
|
finally |