Troubleshooting
Problem
IBM Rational Rose RealTime does not directly support bitfields, but there is still a way of implementing them. This technote and its attached models demonstrate how to define and use bitfields in Rose RealTime.
Cause
The Rose RealTime C and C++ code generators do not support the syntax required to declare bitfields.
Resolving The Problem
In Rose RealTime it is possible to declare a struct with bitfield members by turning off code generation for the class and inserting the required definitions in a field not parsed by the code generator.
In the example models a class named "flags" has been created in which some bitfields are defined. A variable of type flags is declared, bitfield values set, a message is sent between two capsules, and the data printed out on the receiving side.
Open the class specification.
Select the C/C++ tab. Notice that the "GenerateClass" property does not have a checkmark next to it. There will be no actual "class" called "flags" generated by Rose RealTime, although there will be flags.h and flags.c/flags.cpp files created.
The struct called "flags" with the bitfield definitions will be generated because of the contents of the "HeaderPreface" property on the C/C++ tab. This is a "user" field or property that the code generator does not parse, but rather inserts directly into the generated C/C++ code.
Typically you want to document the various attributes of a class that may be used in your model, so "attributes" have been added on the Attributes tab. These attributes will be visible on class diagrams but are for information only as the flags class is not code generated by Rose RealTime.
Now select the "C++ TargetRTS" tab and notice that the "GenerateDescriptor" property is set to False, because there is not enough information supplied in the class for the code generator to create the descriptor.
Open the Main class diagram.
In the example model there are two capsules that will access the bitfields. A dependency has been drawn from each of the capsules to the flags class (struct). Note that on the C++ tab of these two Dependency Specifications, the KindInHeader is set to "inclusion" and the KindInImplementation is set to "none". This is because all the information about the flags "class" is in the header file. Any class using the "class" flags must include its header file, a forward reference in not sufficient. In fact a forward reference will specify flags as a class, not a struct, and result in a compile time error.
In the example models the bitfield struct is sent by reference. Recall that the GenerateDescriptor property had to be set to False for the "class" flags. This has several implications
- you cannot inject or observe (watch) the data in the Runtime View of Rose RealTime
- there is no encoding and decoding of the data, so message sends are more efficient
- the receiver of the data has a pointer to the private data of the sender, so concurrency issues come into play
Related Information
Historical Number
25933
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21134785