Next: Remote Access to Class Wide Types (RACW), Previous: Regular Remote Subprograms (RCI), Up: Pragma Remote_Call_Interface
In the following example, several mirroring banks offer their services through the same database. Each bank registers a reference to each of its services with a central bank. A client of the central bank requests a service from one of the mirroring banks. To satisfy requests, the RCI unit RASBank defines Balance_Type, a remote access to subprogram. (Recall that an access type declared in a remote unit has to be either remote access to subprogram or remote access to class wide type).
Note that to obtain a remote access to subprogram, the subprogram that delivers the remote access must be remote itself. Therefore, MirrorBank is a RCI library unit.
with Types; use Types;
package RASBank is
pragma Remote_Call_Interface;
type Balance_Type is access function
(Customer : in Customer_Type;
Password : in Password_Type)
return Integer;
procedure Register
(Balance : in Balance_Type);
function Get_Balance
return Balance_Type;
-- [...] Other services
end RASBank;
In the code below, a mirroring bank registers its services to the central bank.
with Types; use Types;
package MirrorBank is
pragma Remote_Call_Interface;
function Balance
(Customer : in Customer_Type;
Password : in Password_Type)
return Integer;
-- [...] Other services
end MirrorBank;
with RASBank, Types; use RASBank, Types;
package body MirrorBank is
function Balance
(Customer : in Customer_Type;
Password : in Password_Type)
return Integer is
begin
return Something;
end Balance;
begin
-- Register a dynamically bound remote subprogram (Balance)
-- through a statically bound remote subprogram (Register)
Register (Balance'Access);
-- [...] Register other services
end MirrorBank;
In the code below, a central bank client asks for a mirroring bank and calls the Balance service of this bank by dereferencing a remote access type.
with Types; use Types;
with RASBank; use RASBank;
procedure BankClient is
B : Integer;
C : Customer_Type := "rich";
P : Password_Type := "xxxx";
begin
-- Through a statically bound remote subprogram (Get_Balance), get
-- a dynamically bound remote subprogram. Dereference it to
-- perform a dynamic invocation.
B := Get_Balance.all (C, P);
end BankClient;