agpl_1.0.0_b5da3320/src/agpl-generic_messenger.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 

--  This class allows for a kind of "signaling" between an emitter and several
--  consumers.

--  Since there's no selectable signals for registration, it should not be used
--  for heavy traffic, I suppose.

with Ada.Containers.Indefinite_Doubly_Linked_Lists;

generic
   type Signal_Kind is (<>);
   type Message_Data (<>) is limited private;
package Agpl.Generic_Messenger is

   pragma Preelaborate;

   type Object is abstract tagged null record;

   procedure Signal (This : in out Object;
                     Kind : in     Signal_Kind;
                     Data : in     Message_Data) is abstract;
   --  The emitter calls this function to notify all overriden descendents.
   --  A bidirectional communication must then ensue by means of @This@

   package Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists (Object'Class);

   type Manager is tagged private;

   procedure Add_Listener (This : in out Manager; X : Object'Class);

   procedure Signal (This : in out Manager;
                     Kind : in     Signal_Kind;
                     Data : in     Message_Data);
   --  Will propagate the signal to all its managed objects.

private

   type Manager is tagged record
      Objects : Lists.List;
   end record;

end Agpl.Generic_Messenger;