RiCGEN_BY_X() or CGEN_BY_X()
The RiCGEN_BY_X()
statement
generates
an event and sends it to an instance while identifying the sender
of the event.
RiCGEN_BY_X()
has
the same effect
as CGEN_BY_X()
. Either statement can be useful for
sending events from within global functions.
RiCGEN_BY_X()
uses
the RiCReactive_genBySender()
framework
routine to send the event because it identifies a particular object
as the sender of the event.
For example, to send
a fault()
event
to a Furnace[1]
instance while identifying the sender
of the event as Room[2]
, use:
RiCGEN_BY_X(Furnace[1], fault(), Room[2], Room);
The last argument, in this case Room
,
identifies the type of the sender.
Use GEN_BY_X
only in special cases when you know which
AOMAnimationItem
is sending the message because Rhapsody® cannot
determine the reason without assistance. For example, you can create an application with some GUI
classes, GUI1
and GUI2
, and some classes that do things,
Huey
and Louey
. You create all the classes in Rhapsody , so the
animation shows instances of all four.
Associate some GUI with classes GUI1
and GUI2
.
Because GUIs are more easily created with MFC wizards than with Rhapsody , use
the wizards. The constructor of GUI1
constructs a modeless dialog with some
buttons.
Configure each of the buttons to generate an event. For example:
void myDialog::OnButtonXPushed() {
myHuey->GEN(E);
}
This configuration works, except the
animation
does not know where the event came from. Instead, you might use GEN_BY_GUI
in
this way:
void myDialog::OnButtonXPushed() {
myHuey->GEN_BY_GUI
The animation output window displays the following message:
event E generated by GUI
If the class myDialog
had
a method GUI1
*myOwner
that pointed to the instance of GUI1
to
which it belongs, you could write:
void myDialog::OnButtonXPushed() {
myHuey->GEN_BY_X(E,myOwner);
}
In this case, the animation (output
window, event
queue, and sequence diagrams) would display E
as
coming from the correct GUI1
object. This approach
is especially useful if the GUI and its dialogs are test harnesses
that create some real classes that are not yet written.
The definition of RiCGEN_BY_X()
is
as follows:
#define RiCGEN_BY_X(INSTANCE,EVENT,SENDER,theClass) \
{ \
if ((INSTANCE) != NULL) { \
RiCReactive * reactive = &((INSTANCE)->ric_reactive);\
RiCEvent * event = &(RiC_Create_##EVENT->ric_event); \
RiCReactive_genBySender(reactive, event, \
aomX2Item(SENDER,aomc##theClass)); \
} \
}