Ada Source Code for Chiron Original Dispatcher (2
artists, 2 events)
--- Ada source for Chiron interface generated by make_ada.pl
--- Original Dispatcher Version
--- Name: disp.a
--- Created on: Thu Oct 14 10:23:07 EDT 1999
--- Number of artists: 2
--- Number of events: 2
--- Configuration: 11 10
package disp is
number_of_artists: constant natural := 2;
number_of_events: constant natural := 2;
type a_id_type is (
art1,
art2);
type e_kind is (
e1,
e2);
subtype list_size is natural range 0..2;
subtype i_range is natural range 1..3;
function choose return boolean;
function choose return e_kind;
task dispatcher is
entry register_event (a_id : a_id_type; event_kind : e_kind);
entry unregister_event (a_id : a_id_type; event_kind : e_kind);
entry notify_artists (event : e_kind);
end dispatcher;
task a1 is
entry start_artist;
entry notify_client_event(event: e_kind);
entry terminate_artist;
end a1;
task a2 is
entry start_artist;
entry notify_client_event(event: e_kind);
entry terminate_artist;
end a2;
task adt_wrapper is
entry start_wrapper;
end adt_wrapper;
task artist_manager is
entry start_manager;
entry a1_registered;
entry a2_registered;
end artist_manager;
task client_init;
end disp;
package body disp is
function choose return boolean is
begin
return true;
end choose;
function choose return e_kind is
begin
return e1;
end choose;
task body dispatcher is
e1_lst: array(1..number_of_artists) of a_id_type;
e2_lst: array(1..number_of_artists) of a_id_type;
e1_sz : list_size := 0;
e2_sz : list_size := 0;
i : i_range;
begin
loop
select
accept register_event (a_id : a_id_type; event_kind : e_kind) do
case event_kind is
when e1 =>
i := 1;
loop
if i > e1_sz then
e1_sz := e1_sz + 1;
e1_lst(i) := a_id;
exit;
end if;
if e1_lst(i) = a_id then
exit;
end if;
i := i + 1;
end loop;
when e2 =>
i := 1;
loop
if i > e2_sz then
e2_sz := e2_sz + 1;
e2_lst(i) := a_id;
exit;
end if;
if e2_lst(i) = a_id then
exit;
end if;
i := i + 1;
end loop;
end case;
end register_event;
or
accept unregister_event (a_id : a_id_type; event_kind : e_kind) do
case event_kind is
when e1 =>
if e1_sz = 0 then
null;
else
i := 1;
while i <= e1_sz loop
if e1_lst(i) = a_id then
while i < e1_sz loop
e1_lst(i) := e1_lst(i+1);
i := i + 1;
end loop;
e1_sz := e1_sz - 1;
end if;
i := i + 1;
end loop;
end if;
when e2 =>
if e2_sz = 0 then
null;
else
i := 1;
while i <= e2_sz loop
if e2_lst(i) = a_id then
while i < e2_sz loop
e2_lst(i) := e2_lst(i+1);
i := i + 1;
end loop;
e2_sz := e2_sz - 1;
end if;
i := i + 1;
end loop;
end if;
end case;
end unregister_event;
or
accept notify_artists (event : e_kind) do
case event is
when e1 =>
for i in 1 .. e1_sz loop
case e1_lst(i) is
when art1 =>
a1.notify_client_event(e1);
when art2 =>
a2.notify_client_event(e1);
end case;
end loop;
when e2 =>
for i in 1 .. e2_sz loop
case e2_lst(i) is
when art1 =>
a1.notify_client_event(e2);
when art2 =>
a2.notify_client_event(e2);
end case;
end loop;
end case;
end notify_artists;
or terminate;
end select;
end loop;
end dispatcher;
task body a1 is
notify_event : e_kind;
begin
accept start_artist;
dispatcher.register_event(art1, e1);
dispatcher.register_event(art1, e2);
artist_manager.a1_registered;
loop
select
accept notify_client_event(event: e_kind) do
notify_event := event;
end notify_client_event;
or
accept terminate_artist do
dispatcher.unregister_event(art1, e1);
dispatcher.unregister_event(art1, e2);
end terminate_artist;
exit;
end select;
end loop;
end a1;
task body a2 is
notify_event : e_kind;
begin
accept start_artist;
dispatcher.register_event(art2, e1);
artist_manager.a2_registered;
loop
select
accept notify_client_event(event: e_kind) do
notify_event := event;
end notify_client_event;
or
accept terminate_artist do
dispatcher.unregister_event(art2, e1);
end terminate_artist;
exit;
end select;
end loop;
end a2;
task body adt_wrapper is
begin
accept start_wrapper;
loop
dispatcher.notify_artists(choose);
end loop;
end adt_wrapper;
task body artist_manager is
begin
accept start_manager do
a1.start_artist;
a2.start_artist;
accept a1_registered;
accept a2_registered;
end start_manager;
while choose loop
null;
end loop;
a1.terminate_artist;
a2.terminate_artist;
end artist_manager;
task body client_init is
begin
artist_manager.start_manager;
adt_wrapper.start_wrapper;
end client_init;
end disp;
Back to Chiron Original Dispatcher (2
artists, 2 events)