8.4      Subprogram and Subprogram Group Access

(1)   Subprograms and subprogram groups can be made accessible to other components. Components can declare that they require access to subprograms and subprogram groups. Components may provide access to their subprograms and subprogram groups.  Subprogram access is used to model binding of a subprogram call (local or remote) to the subprogram instance being called. 

Syntax

-- The requires and provides subprogram access subclause
subprogram_access_spec ::=
    defining_subprogram_access_identifier :  
       ( provides |  requires ) subprogram access 
        [ subprogram_unique_component_classifier_reference 
        | subprogram_component_prototype_identifier ]
 
subprogram_access_refinement ::=
    defining_subprogram_access_identifier : refined to 
        ( provides |  requires ) subprogram access 
        [ subprogram_unique_component_classifier_reference 
        | subprogram_component_prototype_identifier ]
 
-- The requires and provides subprogram group access subclause
subprogram_group_access_spec ::=
    defining_subprogram_group_access_identifier :  
       ( provides |  requires ) subprogram group access 
        [ subprogram_group_unique_component_classifier_reference 
        | subprogram_group_component_prototype_identifier ]
 
subprogram_group_access_refinement ::=
    defining_subprogram_group_access_identifier : refined to 
        ( provides |  requires ) subprogram group access 
        [ subprogram_group_unique_component_classifier_reference 
        | subprogram_group_component_prototype_identifier ]

Naming Rules

(N1)     The defining identifier of a provides or requires subprogram or subprogram group access declaration must be unique within the namespace of the component type where the subcomponent access is declared. 

(N2)     The defining identifier of a provides or requires subprogram or subprogram group refinement must exist as a defining identifier of a provides or requires subprogram or subprogram group or an abstract feature in the namespace of the component type being extended.

(N3)     The component type identifier or component implementation name of a subprogram or subprogram group access classifier reference, if present, must exist in the package namespace. 

(N4)     The prototype identifier of a subprogram or subprogram group access classifier reference, if present, must exist in the namespace of the classifier that contains the access declaration.

Legality Rules

(L1)      If a subprogram access refers to a component classifier or a component prototype, then the category of the classifier or prototype must be subprogram.

(L2)      If a subprogram group access refers to a component classifier or a component prototype, then the category of the classifier or prototype must be subprogram group.

(L3)      An abstract feature can be refined into a subprogram access or a subprogram group access. In this case, the abstract feature must not have a direction specified.

(L4)      A subprogram or subprogram group access declaration that does not specify a component classifier reference is incomplete.  Such a reference can be added in a subprogram or subprogram group access refinement declaration.

(L5)      A subprogram or subprogram group access declaration may be refined by adding a property association. Inclusion of the component classifier reference is optional.

(L6)      A provides subprogram access cannot be refined to a requires subprogram access and a requires subprogram access cannot be refined to a provides subprogram access. Similarly, a provides subprogram group access cannot be refined to a requires subprogram group access and a requires subprogram group access cannot be refined to a provides subprogram group access.

Consistency Rules

(C1)A provides subprogram access feature indicates that a subprogram is made available to be referenced.  A project may enforce a consistency rule that a subprogram access connection connects this feature to directly a subprogram subcomponent, or indirectly via a requires subprogram (group) access or provides subprogram (group) access.

Standard Properties

-- Subprogram call rate for subprogram access
Subprogram_Call_Rate: Rate_Spec => [ Value_Range => 1.0 .. 1.0; Rate_Unit => PerDispatch; Rate_Distribution => Fixed; ]
Queue_Size: aadlinteger 0 .. Max_Queue_Size => 1 
Queue_Processing_Protocol: Supported_Queue_Processing_Protocols => FIFO 
Overflow_Handling_Protocol: enumeration (DropOldest, DropNewest, Error)
       => DropOldest 
Urgency: aadlinteger 0 .. Max_Urgency
 

Semantics

(2)   A required subprogram (group) access declaration indicates that a component requires access to a externally declared subprogram (group).  Required subprogram (group) accesses are resolved to subprogram (group) subcomponents through access connection declarations. 

(3)   A provides subprogram (group) access declaration indicates that a component provides access to a subprogram (group) subcomponent contained in the component.  Provided subprogram (group) accesses can be used to resolve required subprogram (group) accesses. 

(4)   A subprogram that is accessed by more than one component is shared and must be reentrant.  The shared subprogram may be called by multiple threads.  This may result in concurrent access to shared data components.

(5)   If a different thread provides access to a subprogram then the call is remote, i.e., executed by the thread with the provides subprogram access feature. Otherwise the call is a local call, i.e., executed by the calling thread. 

(6)   In case of a remote subprogram call, the requesting thread calls a local proxy that carries out the service request.  The proxy may marshall and unmarshall the parameters as necessary.  The execution time of the client proxy is determined by the Client_Subprogram_Execution_Time property.  The actual call results in communicating the subprogram execution request to the remote thread.  While the call is in progress, the calling thread is blocked.  Upon completion of the remote subprogram execution and return of results, the calling thread resumes execution by entering the ready state.  A semi-synchronous remote call may be supported where the calling thread may issue the call and wait for the result at a later time by calling Await_Result (see Section 5.4.8).  In this case the caller may issue multiple remote calls to be executed concurrently.

(7)   If the called subprogram raises events or event data and the subprogram call is a remote call, then the raised event in the subprogram is mapped to the corresponding event or event data port of the caller subprogram proxy.

(8)   Each provides subprogram access feature of a thread that represents an entrypoint to a remotely callable code sequence in the source text.  A request for execution of such a subprogram is a dispatch request to the thread containing the subprogram.  Requests for execution of subprograms may be queued if the thread is already executing a dispatch request.  A thread can have multiple subprogram entrypoints, expressed by multiple subprogram access feature declarations.  Only one of these subprograms may be executed per thread dispatch.  Queuing and queue servicing follows the semantics of event port queues.

(9)   Execution of subprogram calls may get blocked for two reasons.  A call may get blocked if the call is remote to a thread that services calls and it is currently executing a dispatch, or it may get blocked because the called subprogram operates in a shared data component. This is the case, if the called subprogram is a provides subprogram (group) access feature of a data component that itself has shared access, i.e., is an access method of a data object, or if a shared data component is accessible to the subprogram through a requires data access feature of the subprogram. In the former case the thread servicing the calls assures mutual exclusion, while other remote calls to subprograms of the thread are queued.  In the latter case, concurrent access to the data component is assured to be mutually exclusive according to the Concurrency_Control_Protocol property value and realized through the Get_Resource service call in the source text, while other mutually exclusive access attempts to shared data components are queued.

(10)  Call_Rate specifies the number of times per dispatch or per second at which a subprogram is called.

Examples

-- a remote procedure call from one thread to another thread

package RemoteCallExample

public

system  simple

end simple;

system implementation simple.impl

subcomponents

   A: process caller_P.i;

   B: process remote_P.i;

connections

   AtoB: subprogram access A.DoCalc -> B.DoCalc;

end simple.impl;

 

process remote_P

features

   DoCalc: provides subprogram access Calc;

end remote_P;

 

process implementation remote_P.i

subcomponents

   t1: thread Remote;

   -- other subcomponent declarations

connections

   t1conn: subprogram access t1.MyCalc -> DoCalc;

end remote_P.i;

 

thread Remote

features

   MyCalc: provides subprogram access Calc;

end Remote;

 

process caller_P

features

   DoCalc: requires subprogram access Calc;

end caller_P;

 

process implementation caller_P.i

subcomponents

   Q: thread caller;

connections

   calcconn: subprogram access DoCalc -> Q.MyCalc;

end caller_P.i;

 

thread caller

features

   MyCalc: requires subprogram access Calc;

end caller;

 

subprogram Calc

end Calc;

end RemoteCallExample;

 

-- A Printer Server Example

package PrinterServerExample

public

   process printers

   features

      printonServer: provides subprogram access print;

      mainPrinter: in event port;

      backupPrinter: in event port;

   end printers;

 

   process implementation printers.threaded

   subcomponents

      A : thread printer in modes ( modeA );

      B : thread printer in modes ( modeB );

connections

    printtoA: subprogram access A.print -> printonServer in modes (modeA);

    printtoB: subprogram access B.print -> printonServer in modes (modeB);

  modes

      modeA: initial mode;

      modeB: mode;

     modeA -[ backupPrinter ]-> modeB;

     modeB -[ mainPrinter ]-> modeA;

   end printers.threaded;

 

   thread printer

   features

      print : provides subprogram access print;

   end printer;

 

   subprogram print

   features

      filetoprint: in parameter file;

   end print;

 

   data file

   end file;

 

  process application

  features

    print: provides subprogram access print;

 

  system ApplicationSystem

  end ApplicationSystem;

 

  system implementation ApplicationSystem.default

  subcomponents

   app: process Application;

   printserver: process Printers.threaded

  connections

   appconn: subprogram access printserver.printonServer -> app.print;

  end ApplicationSystem.default;

end PrinterServerExample;