Specifying external function with AnimSerializeOperation property
The AnimSerializeOperation
property specifies the name of an external
function used to animate all attributes and arguments that are of that type.
About this task
Compare with Specifying external function with AnimUnserializeOperation property.
IBM® Engineering Systems Design Rhapsody® can animate (display) the values of simple types and one-dimensional arrays without any problem. To display the current values of such attributes during an animation session, open the Features window for the instance.
However, if you want to animate a more complex type, such as a date, the type must
be converted to a string (char *
) forRhapsody to
display it. This conversion is done by writing a global function, an instrumentation
function, that takes one argument of the type you want to display, and returns a char
*
. You must disable animation of the instrumentation function itself (using the
Animate
and AnimateArguments
properties for the function).
For example, you can have a type tDate
, defined as follows:
typedef struct date {
int day;
int month;
int year; } %s;
You can have an object with an attribute count of type int
, and
an attribute date of type tDate
. The object can have an initializer with the
following body:
me->date.month = 5;
me->date.day = 12;
me->date.year = 2000;
If you want to animate the date attribute, the
AnimSerializeOperation
property for date must be set to the name of a function that
converts the type tDate
to char *
. For example, you can set the
property to a function named showDate
. This function name must be entered without
any parentheses. It must take an attribute of type tDate
and return a char
*
. The Animate
and AnimateArguments
properties for the
showDate
function must be set to Cleared
.
The implementation of the showDate
function might be as
follows:
showDate(tDate aDate) {
char* buff;
buff = (char*) malloc(sizeof(char) * 20);
sprintf(buff,"%d %d %d",
aDate.month,aDate.day,aDate.year);
return buff;
}
When you run this model with animation, instances of this object display a value of 5 12 2000 for the date attribute in the browser.
If the showDate
function is defined in the same class that the
attribute belongs to and the function is not static, the AnimSerializeOperation
property value is like the following example:
myReal->showDate
This value shows that the function is called from the
serializeAttributes
function, located in the class
OMAnimated<classname>
.
showDate
function must allocate memory for the returned
string with the malloc/alloc/calloc
function in C, or the new
operator in C++. Otherwise, the system shuts down.The default for this property is an empty string.