However, an object is considered reactive if it satisfies any one of the following conditions:
If an object is reactive, an instance of an RiCReactive object is embedded by value in the structure for the object as a data member. For example:
typedef struct Furnace Furnace;
struct Furnace {
RiCReactive ric_reactive;
/* attributes of Furnace */
};
RiCReactive is an abstract data type provided by the IBM® Rational® Rhapsody® Developer for C framework to define the event‑handling behavior of reactive objects.
For every reactive object, an additional struct is defined in the implementation file to hold pointers to functions that are defined as part of the statechart implementation. These pointers are passed to the reactive member of an object type:
static const RiCReactive_Vtbl Furnace_reactiveVtbl = {
rootState_dispatchEvent,
rootState_entDef,
ROOT_STATE_SERIALIZE_STATES(rootState_serializeStates),
/* Violation of MISRA Rule 45 (Required): */
/* 'Type casting to or from pointers shall not be used.' */
/* The following cast is justified and is */
/* for Rational Rhapsody auto-generated code use only. */
(RiCObjectDestroyMethod) Furnace_Destroy,
NULL,
NULL,
NULL,
(RiCObjectCleanupMethod) Furnace_Cleanup,
(RiCObjectFreeMethod) FreeInstance
};
Note the following:
The dispatchEvent(), entDef(), and serializeState() functions are implemented in the handle closer files defined in the framework (RiCHdlCls.c). You can define functions to perform similar tasks and link them to your project through the virtual function table, if wanted. However, this topic is beyond the scope of this subject.
Initialization of a reactive object and the statechart that it drives are accomplished as part of the initialization function for the object. For example, the following initializer for the Furnace object in the HomeHeatingSystem calls RiCReactive_init() to initialize the reactive object, then calls initStatechart() to initialize the statechart for the object:
void Furnace_Init(Furnace* const me, RiCTask * p_task) {
RiCReactive_init(&me->ric_reactive, (void*)me,
p_task, &Furnace_reactiveVtbl);
/* relation initialization loop */
initStatechart(me);
}
The RiCReactive_init() and initStatechart() functions are defined in the Rational Rhapsody framework.
The second parameter to the initializer, p_task, is a pointer to the task, with the associated event queue, from which the reactive object processes events. If the reactive object is sequential, this task is the system thread; if the reactive object is active, this task is the thread of the object. See Active objects and concurrency for more information.