MSEventHandle SetupMSEvents (MSEventData eventData[], int32 numEvents, int32 reserved)
The MSEventData structure is defined in msgutils.h as follows:
The values you place in the MSEventData structures before calling this function control resource allocation, as described in the following paragraphs.
typedef struct MSEventData
{ char *name;
int32 (*handler)(MSEventData *eventData, void *userCo ntext);
void *userData;
int32 signal;
Item port;
Item msgItem;
Message *msgPtr;
MsgValueTypes *msgValues;
MSEventHandle backLink; } MSEventData;
If you provide a non-NULL name pointer the MSEventData describes a message port. If the name field is NULL it describes a signal. For message ports, the port is created using the name you provide; if you don't need a name just provide an empty string ("") for the name.
The handler field is a pointer to your function to handle events for the message port or signal. Every event must have a non-NULL handler pointer.
If you set the signal field to zero and the name field is NULL, SetupMSEvents()
will allocate a signal for you and store it in this field. If the signal field is non-zero and the name field is NULL the signal field is used as the signal(s) to be waited on for this event. If the name field is non-NULL (IE, this is a message event) any value already existing in the signal field is replaced with the port's signal mask during setup.
If you set the port field to zero and the name field is non-NULL, SetupMSEvents()
allocates a message port for you and store it in this field. If the port field is non-zero, it is assumed to be a message port item number for a port you allocated yourself. If the name field is NULL (IE, this is a signal event) the port field is ignored.
The remaining fields, (msgItem, msgPtr, msgValues, and backLink) are read-only fields from your point of view. When a message event arrives, the dispatcher fills in the msgItem, msgPtr, and msgValues fields before calling your handler function. Your handler can refer to these values when processing the message.
The MSEventData array can contain some elements for which you've allocated your own signal or port and other elements with zero values that request automatic allocation at setup time. The internals keep track of who allocated which resources and at cleanup time only automatically allocated resources are freed automatically.
CleanupMSEvents
, DispatchMSEvents