Modelio C++ Designer provides a system used to generate C++ code for part and ports. Parts and ports are UML 2 features designed to represent limited connexions in component architecture, as well as their integration through the connection of predefined plugs.
Modeling parts and ports
Some classes can publish or require certain information, declared by an interface. In the example provided in the figure 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 generable 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 below.
Note: Don’t forget to specify interfaces to type the plug by selecting the lollipop and clicking on the UML properties.
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 | Vis | 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 contain the following code:
1Void Brain::move () {
2 // Retrieving the command port
3 BrainCmdPort *cmdPort = getCmdPort ();
4
5 // getting the required plug
6 IVision vision = cmdPort->getRequiredIVision ();
7 Data d = vision.getData ();
8
9 // getting the provided plug
10 ICommand command = cmdPort->getProvidedIControl ();
11 Command.move (d);
12}
In a part/port model, a class will instanciate all classes for component assembly within its internal structure, and you, the user, just have to connect them. However, these elements must be coherent with the static model. For this reason, Modelio C++ Designer 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.
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.