Generating parts and ports
Introduction
Objecteering C++
Developer provides a system used to generate C++ code for part and ports. Parts
and ports are UML 2.0 features designed to represent limited connexions in
component architecture, as well as their integration through the connection of
predefined plugs.

Figure 61-b. Modeling parts and ports
Modeling a class with connection ports
Some classes can
publish or require certain information, declared by an interface. In the
example proviced in Figure 61-b above, the "Camera" class publishes an
"iVision" interface as a provided interface. Thus, the camera publishes
all this information to this channel. The "Arm" class publishes an
"iControl" interface to obtain the information necessary for its use by
a normalized channel.
To create a generatable
port on a class, simply create a port, name it and then specify required or
provided interfaces, represented by lollipops. A single port can simultaneously
have provided and required interfaces, as in the "Brain" example
shown in Figure 61-c below.
Note: Don’t forget to specify interfaces to type the plug by double-clicking on the lollipop.

Figure 61-c. The "Provided interface edition" window
Using generated code in a class with ports
Internally,
every port is a class, which is automatically generated and does not appear in
the model. The name of this class is normalized through the concatenation of
the class name, the port name and the "Port" keyword.
|
Class |
Port |
C++ name of the port |
|
Brain |
Cmd |
BrainCmdPort |
|
Camera |
|
CameraVisPort |
|
Arm |
Ctrl |
ArmCtrlPort |
Every operation on
the connection point must therefore be carried out using this port. This
generated class is the access point to interfaces.
The port class
provides access to provided and required interfaces. To retrieve the interface,
an accessor is automatically created from "get", the
"Required" or "Provided" keyword and the type of the
interface. For example, the "CameraVisPort" class contains an
accessor named "getProvidedIVision ()". Using these accessors, the
class does not know the linked element. This system provides important
separation of issues.
For example, if
the brain takes the information from the vision device through the "Command"
port, and in order to call the "move" command via the same port, a
method must contains the following code:
Void Brain::move
() {
// Retrieving the command port
BrainCmdPort *cmdPort = getCmdPort ();
// getting the required plug
IVision vision = cmdPort->getRequiredIVision
();
Data d = vision.getData ();
// getting the provided plug
ICommand command =
cmdPort->getProvidedIControl ();
Command.move (d);
}
Creating an internal structure for part/port integration
In a part/port
model, a class will instanciate all classes for component assembly within its
internal structure, and you, as the user, need simply connect them. However, these
elements must be coherent with the static model. For this reason, Objecteering
C++ Developer contains a wizard to help you to create this model.
To create an
internal structure model, create an integration class. In the internal
structure, simply create parts and set their type to instanciated classes. Next,
launch the "Complete internal structure model" command. This command
will complete the model by creating attributes in the class to refer to instances,
by adding ports and provided/required interfaces relative to the static model
of these classes, and by keeping the model consistent.
Once all these elements
are instanciated, you should simply connect the elements in order to initialize
the parts. When the class containing an internal structure is generated, this will
automatically lead to generation of the instanciation and connection code. This
means that you can concentrate on business code instead of integration code, which
is totally generated.

Figure 61-d. Running the "Complete internal structure model" command
Note: The "Complete internal structure model" command can also update the internal structure model. If you change the static model of a class containing ports, for example by adding a new lollipop, the launch of this command will update those internal structures which use it.