Ada Source Code for Chiron Decomposed Dispatcher (2 artists, 2 events)


--- Ada source for Chiron interface generated by make_ada.pl

--- Name:              disp.a
--- Created on:        Wed Oct 13 12:03:02 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 dispatch_e1 is
    entry register_e1 (a_id : a_id_type);
    entry unregister_e1 (a_id : a_id_type);
    entry notify_e1;
  end dispatch_e1;

  task dispatch_e2 is
    entry register_e2 (a_id : a_id_type);
    entry unregister_e2 (a_id : a_id_type);
    entry notify_e2;
  end dispatch_e2;

  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
      
    begin
      loop
        select

          accept register_event (a_id : a_id_type; event_kind : e_kind) do
            case event_kind is
              when e1 => dispatch_e1.register_e1(a_id);
              when e2 => dispatch_e2.register_e2(a_id);
            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 => dispatch_e1.unregister_e1(a_id);
              when e2 => dispatch_e2.unregister_e2(a_id);
            end case;
          end unregister_event;
  
          or
  
          accept notify_artists (event : e_kind) do
            case event is
              when e1 => dispatch_e1.notify_e1;
              when e2 => dispatch_e2.notify_e2;
            end case;
          end notify_artists;
  
          or
  
          terminate;
  
        end select;
      end loop;
    end dispatcher;


  task body dispatch_e1 is
      
    e1_lst       : array(1..number_of_artists) of a_id_type;
    e1_sz        : list_size := 0;
    i            : i_range;

    begin
      loop
        select

          accept register_e1 (a_id : a_id_type) do
            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;
          end register_e1;

          or
	    
          accept unregister_e1 (a_id : a_id_type) do
            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;
          end unregister_e1;
	    
          or
	    
          accept notify_e1 do
            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;
          end notify_e1;
	    
          or

          terminate;
	    
        end select;
      end loop;
    end dispatch_e1;
   

  task body dispatch_e2 is
      
    e2_lst       : array(1..number_of_artists) of a_id_type;
    e2_sz        : list_size := 0;
    i            : i_range;

    begin
      loop
        select

          accept register_e2 (a_id : a_id_type) do
            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 register_e2;

          or
	    
          accept unregister_e2 (a_id : a_id_type) do
            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 unregister_e2;
	    
          or
	    
          accept notify_e2 do
            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 notify_e2;
	    
          or

          terminate;
	    
        end select;
      end loop;
    end dispatch_e2;
   

  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 Decomposed Dispatcher (2 artists, 2 events)