Prev | Up | ____ | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


E.4.2 Example of Use of a Remote Access-to-Class-Wide Type

Examples
(1)
Example of using a remote access-to-class-wide type to achieve dynamic binding across active partitions:
(2)
       package Tapes is
          pragma Pure(Tapes);
          type Tape is abstract tagged limited private;
          -- Primitive dispatching operations where
          -- Tape is controlling operand
          procedure Copy (From, To : access Tape; Num_Recs : in Natural) is abstract;
          procedure Rewind (T : access Tape) is abstract;
          -- More operations
       private
          type Tape is ...
       end Tapes;
(3)
       with Tapes;
       package Name_Server is
          pragma Remote_Call_Interface;
          -- Dynamic binding to remote operations is achieved
          -- using the access-to-limited-class-wide type Tape_Ptr
          type Tape_Ptr is access all Tapes.Tape'Class;
          -- The following statically bound remote operations
          -- allow for a name-server capability in this example
          function  Find     (Name : String) return Tape_Ptr;
          procedure Register (Name : in String; T : in Tape_Ptr);
          procedure Remove   (T : in Tape_Ptr);
          -- More operations
       end Name_Server;
(4)
       package Tape_Driver is
         -- Declarations are not shown, they are irrelevant here
       end Tape_Driver;
(5)
       with Tapes, Name_Server;
       package body Tape_Driver is
          type New_Tape is new Tapes.Tape with ...
          procedure Copy
           (From, To : access New_Tape; Num_Recs: in Natural) is
          begin
            . . .
          end Copy;
          procedure Rewind (T : access New_Tape) is
          begin
             . . .
          end Rewind;
          -- Objects remotely accessible through use
          -- of Name_Server operations
          Tape1, Tape2 : aliased New_Tape;
       begin
          Name_Server.Register ("NINE-TRACK",  Tape1'Access);
          Name_Server.Register ("SEVEN-TRACK", Tape2'Access);
       end Tape_Driver;
(6)
       with Tapes, Name_Server;
       -- Tape_Driver is not needed and thus not mentioned in the with_clause
       procedure Tape_Client is
          T1, T2 : Name_Server.Tape_Ptr;
       begin
          T1 := Name_Server.Find ("NINE-TRACK");
          T2 := Name_Server.Find ("SEVEN-TRACK");
          Tapes.Rewind (T1);
          Tapes.Rewind (T2);
          Tapes.Copy (T1, T2, 3);
       end Tape_Client;
(7)
Notes on the example:
(8)
(blank)
(9)
(10)
(11)
(12)
(13)

Prev | Up | ____ | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12