Figure 10.1:
The Code View
Although the Concurrency View is a platform-specific model which fully specifies the system in terms of the run-time entities supported by the RCM Virtual Machine, some further transformation steps have to be taken to obtain code ready for deployment: first source code generation and then compilation. All of the source code generated from the Concurrency View is currently in Ada 2005. In this tutorial, we chose to consider the source code as yet another instance of a platform-specific view, at the same level as the Concurrency and the Analysis View. This conceptual decision places emphasis on the following facts:
The code is automatically generated in the Ada 2005
programming
language in conformance to the Ravenscar Profile restrictions. The
extent of automation is 100% for the Interface View and the Concurrency
View, while the code from the Functional Model may be either generated,
in part, for models produced with the ETH FWProfile or else
incorporated in the form of prefabricated code components which however
need to be asserted to comply with the RCM restrictions and must also
have an Interface View description of them.
Figure 10.2 shows a Threaded VMLC, The OPCS represents its functional code. The OBCS and the THREAD represent its structural, or concurrent, side. The THREAD and the OBCS can be factored out in artefacts (called "archetypes") reusable across all VMLC instances of that type.
Figure 10.2: Breakdown of a threaded VMLC with archetype and OPCS
Consider the Distributed Toy Example discussed in the Concurrency View. Figure 10.3 below shows the architecture of the generated code for that example.
Figure 10.3: Architecture of the generated source
code
The source code is (currently) placed under three directories respectively named: Common, Lib, N1 (for the 1st node in the system topology) as follows:
encloses the code which implements all the types specified in the model and all of their instances:
In the absence of fully-automated code generation capabilities from the Functional View, the designer needs to implement all the methods specified in the Functional View by directly editing the source code in Common/Classes. The HRT-UML/RCM methodology forbids modifications in any other directories.
encloses the prefabricated archetypes which the HRT-UML/RCM transformation and code generation engines need to build up the VMLC which populate the Concurrency View The generated code which is recurrent across implementations is factored into reusable basic entities like Request Descriptor, Thread and OBCS: VMLC are formed from suitable aggregations of those archetypal components.
represents the product of the automated generation of the application-specific parts of the software system (targeted for node N1 as identified in the Deployment View) and encloses
01 procedure Read_And_Write (This : in out POS) is
02 --Invoked required interfaces--
03 --+ This.Read : 1 invocation
04 --+ This.Write : 1 invocation
05 --+ C.Compute : 1 invocation
06 Res : Boolean := False;
07 begin
08 --#BlockStart number=3
09 --id=RCMoperation@eb77b0{file:/path_to_my_model/
10 --my_model.rcm#//@rootPackage/@ownedMember.11/@ownedOperation.2
11 -- User-defined code here --
12 declare
13 R : Integer := This.Read;
14 begin
15 This.C.Compute (R);
16 This.Write (R);
17 end;
18 --#BlockEnd number=3
19 end Read_And_Write;
Code fragment 10.1: The copde for the Read_And_Write operation in common/classes/poss.adb
Code fragment 10.1 is a sample implementation for the method Read_And_Write found in Common/Classes/poss.adb. The generated code includes comments which help the user provide an implementation conformant with the functional specification. By way of example, the comments on lines 2-5 advise the designer that Read_And_Write was designed to invoke methods Read, Write and Compute exactly once. The other comments are needed by the generation facility to preserve the user-defined implementation when the code is regenerated.
The final source code is generated in such a way that
the designer need not concern themselves about the
infrastructure which realizes the concurrent behaviour to be obtained
at run time. Three abstraction levels are crossed in the generation of
the final source code: the Functional View (the most abstract); the
Interface and the Concurrency Views (more specialized). Consider method
Compute: it is specified by the designer in the Functional View as a
provided method. In the Interface View, it is designated as a provided
method of the GNC APLC. In the Concurrency View it appears as a
provided method of the GNC VMLC. In all those views method Compute
always provide one and the same signature, but with different semantic
specializations. For this reason, the designer may content themselves
with assuming that the command at line 15 in code fragment 10.1 should
be a direct invocation of the Compute method specified in the
Functional View while in actual fact, before getting there, the
execution of it will first travel across the overriding layers added up
by the code generation process to realize the concurrency semantics
specified in the Interface View for that method.
The final version of this Tutorial (to be released by
the end of the project) will contain, in annex, a representative sample
of the source code automatically generated from the model for the
examples discussed in this document.