--
-- Each of the next_?? functions (where ?? is a type) essentially calls the
-- generator for the type, but adds a bit of housekeeping:
-- 	Updating global counters
--	Linking the generated module to the appropriate environments
--

type Environment is root; 

-- The environment of a module (workstation, enclave, etc.) is the
-- surrounding architecture. Needed to work around a compiler problem
-- (global functions do not elaborate modules as children of the
-- calling module. Error reported to Walt Mann 951220. SM

next_COTS_workstation : function( environ : Environment )  
	return COTSWorkstation is
-- Generates a new workstation on an arbitrarily chosen net.
    workstation : VAR COTSWorkstation;
begin
    COTS_workstation_number := $COTS_workstation_number + 1;
    -- Spread the workstations evenly among the LANs
    workstation := newCOTSWorkstation(newAddress(($COTS_workstation_number mod $lan_number)+1));
    -- make sure the environment sees events from the workstation
    link($workstation, environ);
    return $workstation;
end;

next_user : function  (environ : Environment) return User is
    u : User is newUser();
begin
    user_number := $user_number + 1;
    link(u, environ);
    return u;
end;

next_firewall : function(environ_ : Environment) return Firewall is

    fw : Firewall is newFirewall(newAddress($firewall_number+1));

begin
    firewall_number := $firewall_number + 1;
    link(fw, environ_);
    return fw;
end;

next_local_area_network : function(environ: Environment)
                          return LAN is
    local_area_network : LAN is newLAN($lan_number + 1);
begin
    lan_number := $lan_number + 1;
    link (local_area_network, environ);
    return local_area_network;
end;
