The getMessageList method retrieves a list of messages. It is used for two reasons:
When a reactive class is destroyed, its notifies its thread to cancel all events in the queue that are triggered for that reactive class. The thread iterates over the queue, using getMessageList to retrieve the data, and marks as canceled all events whose target is the reactive class.
RiCOSResult RiCOSMessageQueue_getMessageList(
RiCOSMessageQueue * const me, RiCList * l)
{
RiCList_removeAll(l);
if (me == NULL) return 0;
if (!RiCOSMessageQueue_isEmpty(me)) {
MSG_Q_INFO msgQInfo;
if (noData != me->m_State) {
RiCList_addTail(l,me->pmessage);
}
msgQInfo.taskIdListMax = 0;
msgQInfo.taskIdList = NULL;
/* do not care which tasks are waiting */
msgQInfo.msgListMax = 0;
msgQInfo.msgPtrList = NULL;
msgQInfo.msgLenList = NULL;
/* Do not care about message length. The
first call will retrieve the numMsgs data
member. */
if (OK == msgQInfoGet(me->hVxMQ, &msgQInfo)) {
if (msgQInfo.numMsgs > 0) {
int numMsgs = msgQInfo.numMsgs;
msgQInfo.msgListMax = numMsgs;
msgQInfo.msgPtrList = malloc(
(numMsgs+1)*sizeof(void*));
if (OK == msgQInfoGet(me->hVxMQ,&msgQInfo)) {
void *m;
int i;
for (i = 0; i < numMsgs; i++) {
m = *(void **)msgQInfo.msgPtrList[i];
RiCList_addTail(l,m);
}
}
free(msgQInfo.msgPtrList);
}
}
}
return 1;
}