lace.events: Fix bugs.

This commit is contained in:
Rod Kay
2024-10-30 11:39:32 +11:00
parent 2a17b624c1
commit c70aec24f2
10 changed files with 93 additions and 35 deletions

View File

@@ -72,6 +72,11 @@ is
Sequence : in sequence_Id)
is
begin
if not Self.sequence_Id_Map.contains (from_Subject)
then
Self.sequence_Id_Map.insert (from_Subject, 0);
end if;
Self.Responses.receive (Self, the_Event, from_Subject);
end receive;
@@ -146,6 +151,11 @@ is
begin
my_Responses.Element (from_Subject).delete (to_Kind);
if my_Responses.Element (from_Subject).is_Empty
then
Self.sequence_Id_Map.delete (from_Subject);
end if;
if Observer.Logger /= null
then
Observer.Logger.log_rid_Response (the_Response,

View File

@@ -140,4 +140,5 @@ private
sequence_Id_Map : Containers.name_Map_of_sequence_Id; -- Contains the next expected sequence ID from each subject.
end record;
end lace.event.make_Observer;

View File

@@ -4,6 +4,8 @@ with
system.RPC,
ada.unchecked_Deallocation;
with ada.Text_IO; use ada.Text_IO;
package body lace.event.make_Subject
is
@@ -88,7 +90,7 @@ is
of_Kind : in Event.Kind)
is
begin
Self.safe_Observers.rid (the_Observer, of_Kind);
Self.safe_Observers.rid (the_Observer, of_Kind, Self.sequence_Id_Map);
if Subject.Logger /= null
then
@@ -297,7 +299,7 @@ is
use event_Observer_Vectors,
event_kind_Maps_of_event_observers;
Cursor : constant event_kind_Maps_of_event_observers.Cursor := the_Observers.find (of_Kind);
Cursor : constant event_kind_Maps_of_event_observers.Cursor := the_Observers.find (of_Kind);
the_event_Observers : event_Observer_Vector_view;
begin
if has_Element (Cursor)
@@ -314,12 +316,39 @@ is
procedure rid (the_Observer : in Observer.view;
of_Kind : in Event.Kind)
procedure rid (the_Observer : in Observer.view;
of_Kind : in Event.Kind;
sequence_Id_Map : in out Containers.safe_sequence_Id_Map)
is
the_event_Observers : event_Observer_Vector renames the_Observers.Element (of_Kind).all;
begin
the_event_Observers.delete (the_event_Observers.find_Index (the_Observer));
declare
Found : Boolean := False;
begin
for each_of_the_event_Observers of the_Observers
loop
declare
the_event_Observers : event_Observer_Vector renames each_of_the_event_Observers.all;
begin
for each_Observer of the_event_Observers
loop
if each_Observer = the_Observer
then
Found := True;
exit;
end if;
end loop;
end;
end loop;
if not Found
then
sequence_Id_Map.rid (the_Observer.Name);
end if;
end;
end rid;
@@ -347,7 +376,7 @@ is
function observer_Count return Natural
function observer_Count return Natural -- TODO: This is wrong.
is
use event_kind_Maps_of_event_observers;

View File

@@ -121,8 +121,9 @@ private
procedure add (the_Observer : in Observer.view;
of_Kind : in Event.Kind);
procedure rid (the_Observer : in Observer.view;
of_Kind : in Event.Kind);
procedure rid (the_Observer : in Observer.view;
of_Kind : in Event.Kind;
sequence_Id_Map : in out Containers.safe_sequence_Id_Map);
function fetch_Observers (of_Kind : in Event.Kind) return Subject.Observer_views;
function observer_Count return Natural;

View File

@@ -42,7 +42,7 @@ is
procedure get_Next (Id : out event.sequence_Id;
for_Name : in String);
procedure decrement (for_Name : in String);
procedure decrement (for_Name : in String); -- TODO: Rid.
private
the_Map : name_Map_of_sequence_Id;

View File

@@ -136,6 +136,11 @@ is
begin
if Self.Responses.contains (subject_Name.all)
then
if not Self.sequence_Id_Map.contains (subject_Name.all)
then
Self.sequence_Id_Map.insert (subject_Name.all, 0);
end if;
Sorter.sort (the_Events);
actuate (Self.Responses.Element (subject_Name.all),
the_Events,