DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400 Tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400 Tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ B T

⟦f40686511⟧ TextFile

    Length: 8116 (0x1fb4)
    Types: TextFile
    Names: »B«

Derivation

└─⟦149519bd4⟧ Bits:30000546 8mm tape, Rational 1000, !projects 93-07-13
    └─ ⟦124ff5788⟧ »DATA« 
        └─⟦this⟧ 
└─⟦a7d1ea751⟧ Bits:30000550 8mm tape, Rational 1000, !users!projects 94_04_11
    └─ ⟦129cab021⟧ »DATA« 
        └─⟦6d381756c⟧ 
└─⟦f64eaa120⟧ Bits:30000752 8mm tape, Rational 1000, !projects 93 02 16
    └─ ⟦6f12a12be⟧ »DATA« 
        └─⟦6d381756c⟧ 
└─⟦2f6cfab89⟧ Bits:30000547 8mm tape, Rational 1000, !projects 94-01-04
    └─ ⟦d65440be7⟧ »DATA« 
        └─⟦6d381756c⟧ 
            └─⟦this⟧ 
└─⟦f64eaa120⟧ Bits:30000752 8mm tape, Rational 1000, !projects 93 02 16
    └─ ⟦6f12a12be⟧ »DATA« 
        └─⟦this⟧ 

TextFile

with Calendar;
with String_Map_Generic;
package body Connection_Manager_Generic is
    use Calendar; -- operators everywhere


    task Manager is
        entry Close_All_Connections;
        entry Shutdown;
        entry Close_Connection (Destination : String);
        entry Operate (Object : Object_Id;
                       Parms : in out Operate_Parameters;
                       Errors : in out Simple_Status.Condition);
    end Manager;

    task body Manager is

        Operating : Boolean := True;
        Duration_To_Next_Timeout : Duration := 0.0;

        subtype Connection_Id is Natural range 0 .. Max_Connections;
        Null_Connection_Id : constant Connection_Id := 0;

        type Connection_Info is
            record
                Handle : Connection_Handle;
                Last_Use : Calendar.Time;
                Idle_Timeout : Duration;
                In_Use : Boolean;
            end record;

        package Smap is new String_Map_Generic
                               (Size => 101, Range_Type => Connection_Id);
        Map : Smap.Map;
        type Connection_Array is array (Connection_Id) of Connection_Info;
        Connections : Connection_Array;

        procedure Next_Interval_Setup is
            -- find shortest timeout interval
            Timeout_Time : Calendar.Time;
            Timeout_Duration : Duration;
        begin
            Duration_To_Next_Timeout := Duration'Large;
            for I in Connections'Range loop
                if Connections (I).In_Use and then
                   Connections (I).Idle_Timeout < Duration'Large then
                    Timeout_Time := Calendar."+" (Connections (I).Last_Use,
                                                  Connections (I).Idle_Timeout);
                    Timeout_Duration := Calendar."-"
                                           (Timeout_Time, Calendar.Clock);
                    -- *** need to handle constraint error for the above
                    if Timeout_Duration < Duration_To_Next_Timeout then
                        Duration_To_Next_Timeout := Timeout_Duration;
                    end if;
                end if;
            end loop;
        end Next_Interval_Setup;

        procedure Do_Operate (Object : Object_Id;
                              Parms : in out Operate_Parameters;
                              Errors : in out Simple_Status.Condition) is
            Destination : constant String := Get_Destination (Object);
            Cid : Connection_Id := Null_Connection_Id;
            Free_Cell : Connection_Id := Null_Connection_Id;  
            Found : Boolean;
        begin
            Smap.Find (Map, Destination, Cid, Found);
            -- search connections for one:
            if not Found then
                Cid := Null_Connection_Id;
                for I in Connections'First + 1 .. Connections'Last loop
                    if Connections (I).In_Use = False then
                        Cid := I;
                        exit;
                    end if;
                end loop;
                -- allocate a new connection id
                if Cid = Null_Connection_Id then
                    -- none available
                    Simple_Status.Create_Condition
                       (Errors, "No_Connections_Available");
                    return;
                else
                    -- form connection
                    Open (Destination, Object, Connections (Cid).Handle,
                          Connections (Cid).Idle_Timeout, Errors);
                    if Simple_Status.Error (Errors) then
                        return;
                    end if;
                    Connections (Cid).In_Use := True;
                    Connections (Cid).Last_Use := Calendar.Clock;
                    Smap.Define (Map, Destination, Cid);
                    Next_Interval_Setup;
                end if;
            end if;

            -- Now, do the operation
            Operate (Connections (Cid).Handle, Parms, Errors);
            Connections (Cid).Last_Use := Calendar.Clock;
        end Do_Operate;

        procedure Close_Connection (Cid : Connection_Id) is
            Errors : Simple_Status.Condition;
            Iter : Smap.Iterator;
        begin
            if Connections (Cid).In_Use then
                Close (Connections (Cid).Handle, Errors);
                Connections (Cid).In_Use := False;
                -- remove any map entries that point to it.
                Smap.Init (Iter, Map);
                while not Smap.Done (Iter) loop
                    if Smap.Eval (Map, Smap.Value (Iter)) = Cid then
                        Smap.Undefine (Map, Smap.Value (Iter));
                        Next_Interval_Setup;
                    end if;
                    Smap.Next (Iter);
                end loop;
            end if;
        end Close_Connection;

        procedure Do_Close_Connection (Destination : String) is
            Found : Boolean;
            Cid : Connection_Id;
        begin  
            Smap.Find (Map, Destination, Cid, Found);
            if Found then
                Close_Connection (Cid);
            end if;
        end Do_Close_Connection;


        procedure Do_Close_All_Connections is
        begin
            for I in Connections'Range loop
                if Connections (I).In_Use then
                    Close_Connection (I);
                end if;
            end loop;
            --  Remove any entries from map
            Smap.Make_Empty (Map);
            Next_Interval_Setup;
        end Do_Close_All_Connections;

    begin
        Smap.Initialize (Map);
        Next_Interval_Setup;
        while Operating loop  
            while Operating loop
                begin
                    select
                        accept Close_All_Connections do
                            Do_Close_All_Connections;
                        end Close_All_Connections;
                    or
                        accept Shutdown do
                            Operating := False;
                        end Shutdown;  
                    or
                        accept Close_Connection (Destination : String) do
                            Do_Close_Connection (Destination);
                        end Close_Connection;
                    or
                        accept Operate (Object : Object_Id;
                                        Parms : in out Operate_Parameters;
                                        Errors : in out
                                           Simple_Status.Condition) do
                            Do_Operate (Object, Parms, Errors);
                        end Operate;
                    or
                        delay Duration_To_Next_Timeout;
                        -- loop over connections and close'em
                        for I in Connections'Range loop
                            if Connections (I).In_Use and then
                               Calendar."+" (Connections (I).Last_Use,
                                             Connections (I).Idle_Timeout) <
                               Calendar.Clock then
                                -- time out has occurred
                                Close_Connection (I);
                            end if;

                        end loop;
                    end select;
                exception
                    when others =>
                        null;
                end;
            end loop;
        end loop;
    end Manager;

    procedure Operate (Object : Object_Id;
                       Parms : in out Operate_Parameters;
                       Errors : in out Simple_Status.Condition) is
    begin
        Manager.Operate (Object, Parms, Errors);
    end Operate;

    procedure Close_Connection (Destination : String) is
    begin
        Manager.Close_Connection (Destination);
    end Close_Connection;


    procedure Close_All_Connections is
    begin
        Manager.Close_All_Connections;
    end Close_All_Connections;

    procedure Shutdown is
    begin
        Manager.Shutdown;
    end Shutdown;
end Connection_Manager_Generic;