I'm trying to get a couple of task
s to be able to call each other, but I don't seem very good with this limited with
thing..
I have a spec sctrain-trains.ads
limited with SCTrain.Stations;
with SCTrain.Travellers, SCTrain.Tracks, Ada.Strings.Unbounded;
use SCTrain.Travellers, SCTrain.Tracks, Ada.Strings.Unbounded;
package SCTrain.Trains is
type my_station_access_t is access all Stations.Station;
task type Train is
entry Start(leaving: my_station_access_t; arriving: my_station_access_t);
end Train;
end SCTrain.Trains;
and its .adb
with SCTrain.Stations;
use SCTrain.Stations;
package body SCTrain.Trains is
task body Train is
destination: my_station_access_t;
begin
accept Start(leaving: my_station_access_t; arriving: my_station_access_t) do
destination := arriving;
end Start;
destination.Gogo(1);
end Train;
end SCTrain.Trains;
I found in the documents I've been reading that with
ing the "circular" package in the body would allow smooth executions, but apparently I still have an invalid prefix in selected component "destination"
because dereference must not be of an incomplete type (RM 3.10.1)
, and those errors stay there even without the with
and use
in the package body.
I'm sure I'm missing something, possibly something very basic, and I'd really love to know what that is. The problem I'm trying to solve is that the Train needs a signal from the Station to be allowed to leave and still able to communicate its arrival time afterwards.
I'm using the latest GNAT-GPL.
Thank you very much.
edit: adding Station
's code
limited with SCTrain.Trains;
with Ada.Calendar, Ada.Strings.Unbounded, Ada.Text_IO;
use Ada.Calendar, Ada.Strings.Unbounded, Ada.Text_IO;
package SCTrain.Stations is
task type Station is
entry Gogo(name_d : Integer := 0);
end Station;
end SCTrain.Stations;
and the body:
with SCTrain.Trains;
use SCTrain.Trains;
package body SCTrain.Stations is
task body Station is
name : Integer;
begin
accept Gogo (name_d : Integer := 0) do
name := name_d;
Put_Line("Station " & Integer'Image(name) & " is alive");
end Gogo;
end Station;
end SCTrain.Stations;