Event constructors and destructors

Constructors and destructors are defined for the event in the package specification file. For example:

/* Constructors and destructors: */
ev1 * RiC_Create_ev1();
void ev1_Init(ev1* const me);
void ev1_Cleanup(ev1* const me);
void RiC_Destroy_ev1(ev1* const me);

The names of event create and destroy operations have a slightly different pattern than names of event initialize and cleanup operations:

The implementation of the event constructors and destructors is generated in the implementation file for the package. For example:

ev1 * RiC_Create_ev1() {
   ev1* me = (ev1*) malloc(sizeof(ev1));
   ev1_Init(me);
   return me;
}

With dynamically allocated events, the creator function allocates memory for the event and initializes it through the event initializer:

void ev1_Init(ev1* const me) {
   RiCEvent_init(&me->ric_event, ev1_Default_id, NULL);
   me->ric_event.lId = ev1_Default_id;
}
void ev1_Cleanup(ev1* const me) {
   RiCEvent_cleanup(&me->ric_event);
}
void RiCDestroy_ev1(ev1* const me) {
   ev1_Cleanup(me);
   free(me);
}
Note: It is possible to statically allocate a block of memory for events at the start of run time, rather than using dynamic memory allocation during run time. See Static allocation of events for more information.

See Sending events for information about generating and sending events.


Feedback