ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/FBEvents.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/FBEvents.pas (file contents):
Revision 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
Revision 47 by tony, Mon Jan 9 15:31:51 2017 UTC

# Line 79 | Line 79 | type
79    private
80      FEvents: TStringList;
81      FAttachment: IAttachment;
82 +    FEventCounts: TEventCounts;
83    protected
84      FEventBuffer: PChar;
85      FEventBufferLen: integer;
# Line 90 | Line 91 | type
91      procedure CancelEvents(Force: boolean = false); virtual;
92      procedure EventSignaled;
93      function GetIEvents: IEvents; virtual; abstract;
94 +    procedure ProcessEventCounts;
95    public
96      constructor Create(DBAttachment: IAttachment; aMonitor: IActivityMonitor; Events: TStrings);
97      destructor Destroy; override;
# Line 101 | Line 103 | type
103      procedure Cancel;
104      function ExtractEventCounts: TEventCounts;
105      function GetAttachment: IAttachment;
106 +    procedure AsyncWaitForEvent(EventHandler: TEventHandler); virtual; abstract;
107    end;
108  
109  
# Line 154 | Line 157 | end;
157   procedure TFBEvents.EventSignaled;
158   var Handler: TEventHandler;
159   begin
160 +  Handler := nil;
161    FCriticalSection.Enter;
162    try
163      if not FInWaitState then Exit;
164      FInWaitState := false;
165 +    ProcessEventCounts;
166      if assigned(FEventHandler)  then
167      begin
168        Handler := FEventHandler;
169        FEventHandler := nil;
170      end;
171    finally
172 <    FCriticalSection.Leave
172 >    FCriticalSection.Leave;
173 >  end;
174 >  if assigned(Handler) then
175 >    Handler(GetIEvents);
176 > end;
177 >
178 > procedure TFBEvents.ProcessEventCounts;
179 > var P: PISC_LONG;
180 >    EventCountList: array[0..19] of ISC_LONG;
181 >    i: integer;
182 >    j: integer;
183 > begin
184 >  SetLength(FEventCounts,0);
185 >  if FResultBuffer = nil then Exit;
186 >
187 >  FillChar(EventCountList,sizeof(EventCountList),0);
188 >
189 >  with FirebirdClientAPI do
190 >     isc_event_counts( @EventCountList, FEventBufferLen, FEventBuffer, FResultBuffer);
191 >  j := 0;
192 >  P := EventCountList;
193 >  for i := 0 to FEvents.Count - 1 do
194 >  begin
195 >    if EventCountList[i] <> 0 then
196 >    begin
197 >      Inc(j);
198 >      SetLength(FEventCounts,j);
199 >      FEventCounts[j-1].EventName := FEvents[i];
200 >      FEventCounts[j-1].Count := P^;
201 >      Inc(P);
202 > //      writeln('Event: ',FEventCounts[j-1].EventName,' Count = ',FEventCounts[j-1].Count);
203 >    end;
204    end;
169  Handler(GetIEvents);
205   end;
206  
207   constructor TFBEvents.Create(DBAttachment: IAttachment;
# Line 231 | Line 266 | begin
266   end;
267  
268   function TFBEvents.ExtractEventCounts: TEventCounts;
234 var EventCountList, P: PISC_LONG;
235    i: integer;
236    j: integer;
269   begin
270 <  SetLength(Result,0);
239 <  if FResultBuffer = nil then Exit;
240 <
241 <  GetMem(EventCountList,sizeof(ISC_LONG)*FEvents.Count);
242 <  try
243 <    with FirebirdClientAPI do
244 <       isc_event_counts( EventCountList, FEventBufferLen, FEventBuffer, FResultBuffer);
245 <    j := 0;
246 <    P := EventCountList;
247 <    for i := 0 to FEvents.Count - 1 do
248 <    begin
249 <      if EventCountList[i] > 0 then
250 <      begin
251 <        Inc(j);
252 <        SetLength(Result,j);
253 <        Result[j-1].EventName := FEvents[i];
254 <        Result[j-1].Count := P^;
255 <        Inc(P);
256 <      end;
257 <    end;
258 <  finally
259 <    FreeMem(EventCountList);
260 <  end;
270 >  Result := FEventCounts;
271   end;
272  
273   function TFBEvents.GetAttachment: IAttachment;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines