UML and SysML to C++ - Opaque Behavior Code Generator Specification

This section describes the UML and SysML to C++ opaque behavior code generation.

This page discusses:

Glossary

Acronym Definition
SPO Software Production Operation
BL Behavior Layer
ML Middleware Layer
BSM Behavior-Specific Middleware
TSM Target-Specific Middleware

Referenced Documents

Document Internal Reference
Targeted Application Concept [1]
C++ Code Architecture Specification [2]
UML and SysML to C++ - Operation Specification [3]

General Concepts

Opaque behavior code generation is part of the components generation as presented in [1] is invoked during execution of UML to C++ operation as presented in [3].

This document focuses on the C++ code generation for the opaque behavior.

Supported Elements

Here is an exhaustive list of elements used by the code generator to produce the code with a summary of the purpose and impact.

Element Description
Opaque Behavior Element used as root entity to trigger the code generation.
Opaque Behavior.body Body of the opaque behavior, which is pasted into the generated file.
Opaque Behavior.language Language used to distinguish supported body language. C is the language used to produce a C file.

Code Generator Specification

This section is divided in 2 parts:

  • The generated files specification
  • The behavior specification

Files Specifications

Opaque behavior code is generated in a file named be as specified for all behaviors in [3].

<ClassName>_<behaviorName>.cpp

General requirements related to file content are described in [2].

The code generator supports the implementation of behavior of a class by using an opaque behavior defined as classifier behavior of the class.

In this context, the opaque behavior must implement three functions init, main, and term.

Each of these functions is invoked at different phases of the program execution.

Init function is invoked once during the init phase of the application.

Main function is invoked based on the executionType applied to it (a typical case is a periodic execution).

Term function is invoked once at the end of code execution.

Init main and term functions have a prefix composed of the name of the parent class and the name of the opaque behavior with an underscore.

Init main and term functions have an argument pointer to the parent class object.

void MyClass_MoOpaqueBehavior_init(MyClass\* self);
void MyClass_MoOpaqueBehavior_main(MyClass\* self);
void MyClass_MoOpaqueBehavior_term(MyClass\* self);

Example: Body section for a body, which is empty.

#include to the file <ClassName>_ift.h is generated.

A header section is generated following the first include let the user add specific includes or variables declaration in the generated files.

User header section start with comment BEG_USER_CODE(header) do not remove and finish with comment END_USER_CODE(header) do not remove.

Rationale: includes inserted in the user include section can be preserved between 2 generations of the same file.

/* BEG_USER_CODE(header) do not remove */
/* Add your includes here */
/* END_USER_CODE(header) do not remove */

Example: User include section.

Comment is inserted to inform that the user section starts.

Documentation is inserted if the opaque behavior has documentation attached.

A tag @generated_from is inserted to trace the original sysml entity.

/**
* Start of Opaque Behavior myOpaqueBehavior body section
* @generated from: opqueBehaviorId
*/

Example: Start of opaque behavior section

The opaque behavior body section starts with the comment BEG_USER_CODE(${opaque_behavior_id}) do not remove and finishes with END_USER_CODE(${opaque_behavior_id}) do not remove

If the opaque behavior body is not empty, its content is printed in the section.

/* BEG_USER_CODE(${opaque_behavior_id}) do not remove */

<opaque_behavior_content>

/* END_USER_CODE(${opaque_behavior_id}) do not remove */

Example: Body section for a body, which is not empty.

If the opaque behavior body is empty, a template is automatically created in the generated file.

/* BEG_USER_CODE(${opaque_behavior_id}) do not remove */

void <Class_Name>_<OpaqueBehavior_Name>_init(<Class_Name~~Rte_Instance~~>* self){
/* Add your init code here */
}
void <Class_Name>_<OpaqueBehavior_Name>_main(<Class_Name>* self){
/* Add your code here */
}
void <Class_Name>_<OpaqueBehavior_Name>_term(<Class_Name>* self){
/* Add your term code here */
}

/* END_USER_CODE(${opaque_behavior_id}) do not remove */

Example: Body section for a body, which is empty.

A final line is inserted to inform that the opaque behavior section is complete.

/* End of Opaque Behavior body section */

Example: End of opaque behavior section

Semantic Code Specifications

This section describes the behavior of the code generator depending on the UML/SysML element.

No specific behavior is expected depending on elements.