garlic_90ef4b6f/Examples/Messages/rci.adb

 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
with Ada.Text_IO;          use Ada.Text_IO;
with System.RPC;           use System.RPC;
with System.RPC.Stream_IO; use System.RPC.Stream_IO;
with Pure;                 use Pure;

package body RCI is

   task type Robot_Type is
      entry Start (I : Natural);
   end Robot_Type;

   task body Robot_Type is
      M : Message_Type;
      P : Natural;
      S : aliased Partition_Stream_Type;
   begin
      accept Start (I : Natural) do
         P := I;
      end Start;
      Ada.Text_IO.Put_Line ("Listen to" & P'Img);
      while M.Count < N_Counts loop
         Open (S, Any_Partition, In_Mode);
         Message_Type'Read  (S'Access, M);
         Ada.Text_IO.Put_Line ("Received message" & M.Value'Img &
                               " with count" & M.Count'Img);
         Close (S);
         M.Count := M.Count + 1;
         Open (S, Partition_ID (P), Out_Mode);
         Message_Type'Write (S'Access, M);
         Close (S);
      end loop;
   end Robot_Type;

   Robots : array (1 .. N_Robots) of Robot_Type;

   procedure Start (P : Natural) is
   begin
      for N in Robots'Range loop
         Robots (N).Start (P);
      end loop;
   end Start;

end RCI;