Last update: 26 Sep 99 / 08:04
This package implments a server which recevies commands from a socket connection. Upon opening a connection a a so called agent task will be started. The agent task operates on the abstract Agent datatype. The procedure create binds the agent type and the server type together.
type Object( Port : Positive ) is abstract tagged private; type Reference is access all Object' Class;
procedure Initialize( O : in Reference; Port: in Integer := 0 ); procedure Finalize( O : in Reference );
function Create( O : in Object ) return Agent.Reference is abstract; procedure Delete( A : Agent.Object'Class ) is abstract;
Type - Object
This is the server object. As descriminant the port number is specified where the input is received from.
Type - Reference
This type is used to reference all derived instances of the ASCL.SV.Server Class.
Method - Initialize
The instance is not already initialized.
The instance is initialized. The main dispatching task is running an listening on the specified port.
This procedure initialitzes an instance of the server.
Method - Create
The server instance is initialized.
This function has to be defined within the agent defintion. If returns a new agent for the server specitfied by the Object Type.
The port number is given as part of the Object type. An attempt should be made to make this less system dependant. TCP/IP is so commonly used, that the understanding of port number will be the same in most of the sytem environements.
The server package depends on the socket package from....This should be incorperated into the ASCL.
The following example shows how to implement a server which simply replies to every input: First of all a new data type Object is defined which represents the data needed per session and a Data Type Factory is defined which contains the additionaly needed server data is defined. The package specification contains additionaly the extentsions required by the abstract types of the Server and the Agent class.
*** Reply.ads ***
with ASCL.SV.Agent; with ASCL.SV.Server; use ASCL.SV;
with Ada.Streams; use Ada.Streams;
package Reply is
type Object is new Agent.Object with null record;
type Factory is new Server.Object with null record;
procedure Initialize( O : in out Object ); procedure Finalize( O : in out Object );
function Process( O : in Object; Data : in Stream_Element_Array ) return Stream_Element_Array;
function Create( O : in Factory ) return Agent.Reference;
The implementation of the package is shown below. The function create returns on every call a new instance of the Agent type and the function process implements the data processing part of the agent.
*** Reply.adb ***
with Ada.Text_IO; use Ada.Text_IO;
package body Reply is
procedure Initialize( O : in out Object ) is begin Put_Line( "Agent Initialize"); end Initialize;
procedure Finalize( O : in out Object ) is begin Put_Line("Finalize"); end Finalize;
function Create( O : in Factory ) return Agent.Reference is Result : Agent.Reference := new Object; begin return Result; end Create;
function Process( O : in Object; Data : in Stream_Element_Array ) return Stream_Element_Array is begin return Data; end Process;
with Server; use Server;
*** Test.adb ***
procedure Test is P : Server.Reference := new Reply.Factory( 3000 ); begin
Initialize( P );
loop delay 20.0; end loop;
Finalize( P );