From 2935063764f53e04d183ba38df918c24da41df23 Mon Sep 17 00:00:00 2001 From: Oliver Schinagl Date: Thu, 15 May 2008 13:58:39 +0000 Subject: Major rewrite of messageing component's 'get' function. Should work 'always' now. testing as always needed. --- matchblox/common/message_queue.c | 42 ++++++++++++++++++++++++++-------------- matchblox/common/message_queue.h | 8 +++++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/matchblox/common/message_queue.c b/matchblox/common/message_queue.c index ad28b6e..b294cee 100644 --- a/matchblox/common/message_queue.c +++ b/matchblox/common/message_queue.c @@ -18,8 +18,11 @@ */ #ifdef G_OS_WIN32 -#define WIN32_LEAN_AND_MEAN 1 + #define WIN32_LEAN_AND_MEAN 1 #include +#else + #define FALSE 0 + #define TRUE !FALSE #endif #include @@ -34,7 +37,6 @@ struct messageq_s messageq[MAX_MESSAGES]; static int messageq_index, messageq_serial; -static int messageq_last_free; void messageq_init(void) @@ -43,7 +45,6 @@ void messageq_init(void) messageq_index = 0; messageq_serial = 0; - messageq_last_free = 0; for( i = 0; i < MAX_MESSAGES; i++) { messageq[i].sender = 0; messageq[i].recipient = 0; @@ -72,21 +73,34 @@ static void msgfree(int index) { struct messageq_s *messageq_get(int recipient) { - int i; - + struct messageq_s *return_value; + int i, message_found; + + message_found = FALSE; i = messageq_index; - while (messageq[i].recipient != recipient && i != (messageq_index -1)) { - i = (i < MAX_MESSAGES -1) ? i +1 : 0; - } + do { + i = (i < MAX_MESSAGES -1) ? i +1 : 0; + if (messageq[i].recipient & recipient) { + message_found++; + printf("message[%d].recp = %d (messageq_index= %d)\n", i, messageq[i].recipient, messageq_index); + printf("Message found! %d\n", message_found); + } + } while ((i != (messageq_index)) && (!message_found)); /* - * We found the message for our recipient. We'll now set the recipient field to 0 since the recipient - * should know the message was for him, he asked for it. This is needed to prefent the above loop - * to find the same message again, since the message will stay alive in the system until its expired. + * We found the message for our recipient. We'll now substract the recipient field since the recipient + * should not look at this field. This is needed to so that multi-recipients can still read messages, and + * to make sure the loop above is able to end. Since the message will stay alive in the system until its expired, + * anybody (in that is a recepient) can still read it. */ - messageq[i].recipient = MESSAGE_NONE; - - return &messageq[i]; + if (message_found) { + messageq[i].recipient -= recipient; + return_value = &messageq[i]; + } else { + return_value = NULL; + } + + return return_value; } diff --git a/matchblox/common/message_queue.h b/matchblox/common/message_queue.h index 9fd1241..6261c6f 100644 --- a/matchblox/common/message_queue.h +++ b/matchblox/common/message_queue.h @@ -3,9 +3,11 @@ #define _CMESSAGE_QUEUE_H -#define MESSAGE_NONE 0x000000 -#define MESSAGE_MENU 0x001000 -#define MESSAGE_RENDERER 0x002000 +#define MESSAGE_READ 0x00000000 +#define MESSAGE_INPUT 0x00001000 +#define MESSAGE_MENU 0x00002000 +#define MESSAGE_RENDERER 0x00004000 +#define MESSAGE_OTHER 0x00008000 #define MESSAGE_WINDOW_SIZE 16 -- cgit v0.12